public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler( new SamzaUncaughtExceptionHandler(() -> { log.info("Exiting process now."); System.exit(1);
public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler( new SamzaUncaughtExceptionHandler(() -> { log.info("Exiting process now."); System.exit(1); })); String containerId = System.getenv(ShellCommandConfig.ENV_CONTAINER_ID()); log.info(String.format("Got container ID: %s", containerId)); System.out.println(String.format("Container ID: %s", containerId)); String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL()); log.info(String.format("Got coordinator URL: %s", coordinatorUrl)); System.out.println(String.format("Coordinator URL: %s", coordinatorUrl)); int delay = new Random().nextInt(SamzaContainer.DEFAULT_READ_JOBMODEL_DELAY_MS()) + 1; JobModel jobModel = SamzaContainer.readJobModel(coordinatorUrl, delay); Config config = jobModel.getConfig(); JobConfig jobConfig = new JobConfig(config); if (jobConfig.getName().isEmpty()) { throw new SamzaException("can not find the job name"); } String jobName = jobConfig.getName().get(); String jobId = jobConfig.getJobId(); MDC.put("containerName", "samza-container-" + containerId); MDC.put("jobName", jobName); MDC.put("jobId", jobId); ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(ApplicationUtil.fromConfig(config), config); run(appDesc, containerId, jobModel, config); System.exit(0); }
public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler( new SamzaUncaughtExceptionHandler(() -> { log.info("Exiting process now."); System.exit(1); })); String containerId = System.getenv(ShellCommandConfig.ENV_CONTAINER_ID()); log.info(String.format("Got container ID: %s", containerId)); System.out.println(String.format("Container ID: %s", containerId)); String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL()); log.info(String.format("Got coordinator URL: %s", coordinatorUrl)); System.out.println(String.format("Coordinator URL: %s", coordinatorUrl)); int delay = new Random().nextInt(SamzaContainer.DEFAULT_READ_JOBMODEL_DELAY_MS()) + 1; JobModel jobModel = SamzaContainer.readJobModel(coordinatorUrl, delay); Config config = jobModel.getConfig(); JobConfig jobConfig = new JobConfig(config); if (jobConfig.getName().isEmpty()) { throw new SamzaException("can not find the job name"); } String jobName = jobConfig.getName().get(); String jobId = jobConfig.getJobId(); MDC.put("containerName", "samza-container-" + containerId); MDC.put("jobName", jobName); MDC.put("jobId", jobId); ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(ApplicationUtil.fromConfig(config), config); run(appDesc, containerId, jobModel, config); System.exit(0); }
public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler( new SamzaUncaughtExceptionHandler(() -> { log.info("Exiting process now."); System.exit(1); })); String containerId = System.getenv(ShellCommandConfig.ENV_CONTAINER_ID()); log.info(String.format("Got container ID: %s", containerId)); System.out.println(String.format("Container ID: %s", containerId)); String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL()); log.info(String.format("Got coordinator URL: %s", coordinatorUrl)); System.out.println(String.format("Coordinator URL: %s", coordinatorUrl)); int delay = new Random().nextInt(SamzaContainer.DEFAULT_READ_JOBMODEL_DELAY_MS()) + 1; JobModel jobModel = SamzaContainer.readJobModel(coordinatorUrl, delay); Config config = jobModel.getConfig(); JobConfig jobConfig = new JobConfig(config); if (jobConfig.getName().isEmpty()) { throw new SamzaException("can not find the job name"); } String jobName = jobConfig.getName().get(); String jobId = jobConfig.getJobId(); MDC.put("containerName", "samza-container-" + containerId); MDC.put("jobName", jobName); MDC.put("jobId", jobId); ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(ApplicationUtil.fromConfig(config), config); run(appDesc, containerId, jobModel, config); System.exit(0); }
public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler( new SamzaUncaughtExceptionHandler(() -> { log.info("Exiting process now."); System.exit(1); })); String containerId = System.getenv(ShellCommandConfig.ENV_CONTAINER_ID()); log.info(String.format("Got container ID: %s", containerId)); System.out.println(String.format("Container ID: %s", containerId)); String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL()); log.info(String.format("Got coordinator URL: %s", coordinatorUrl)); System.out.println(String.format("Coordinator URL: %s", coordinatorUrl)); int delay = new Random().nextInt(SamzaContainer.DEFAULT_READ_JOBMODEL_DELAY_MS()) + 1; JobModel jobModel = SamzaContainer.readJobModel(coordinatorUrl, delay); Config config = jobModel.getConfig(); JobConfig jobConfig = new JobConfig(config); if (jobConfig.getName().isEmpty()) { throw new SamzaException("can not find the job name"); } String jobName = jobConfig.getName().get(); String jobId = jobConfig.getJobId(); MDC.put("containerName", "samza-container-" + containerId); MDC.put("jobName", jobName); MDC.put("jobId", jobId); ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(ApplicationUtil.fromConfig(config), config); run(appDesc, containerId, jobModel, config); System.exit(0); }
@Test public void testExceptionHandler() { final AtomicBoolean exitCalled = new AtomicBoolean(false); Thread.UncaughtExceptionHandler exceptionHandler = new SamzaUncaughtExceptionHandler(() -> exitCalled.getAndSet(true)); exceptionHandler.uncaughtException(Thread.currentThread(), new SamzaException()); assertTrue(exitCalled.get()); } }