public HelixTaskFactory(Optional<ContainerMetrics> containerMetrics, Path clusterConfPath, Config sysConfig) { this.containerMetrics = containerMetrics; if (this.containerMetrics.isPresent()) { this.newTasksCounter = Optional .of(this.containerMetrics.get().getCounter(GOBBLIN_CLUSTER_NEW_HELIX_TASK_COUNTER)); } else { this.newTasksCounter = Optional.absent(); } launcher = new SingleTaskLauncher(new GobblinProcessBuilder(), new SystemPropertiesWrapper(), clusterConfPath, sysConfig); }
SingleHelixTask(final SingleTaskLauncher launcher, final Map<String, String> configMap) throws IOException { this.jobName = configMap.get(ConfigurationKeys.JOB_NAME_KEY); this.jobId = configMap.get(ConfigurationKeys.JOB_ID_KEY); final Path workUnitFilePath = Paths.get(configMap.get(GobblinClusterConfigurationKeys.WORK_UNIT_FILE_PATH)); logger.info(String .format("Launching a single task process. job name: %s. job id: %s", this.jobName, this.jobId)); this.taskProcess = launcher.launch(this.jobId, workUnitFilePath); }
@Test public void testLaunch() throws Exception { final SystemPropertiesWrapper propertiesWrapper = mock(SystemPropertiesWrapper.class); when(propertiesWrapper.getJavaHome()).thenReturn(JAVAHOME); when(propertiesWrapper.getJavaClassPath()).thenReturn(TEST_CLASS_PATH); final GobblinProcessBuilder processBuilder = mock(GobblinProcessBuilder.class); final Process mockProcess = mock(Process.class); when(processBuilder.start(any())).thenReturn(mockProcess); final Path clusterConfPath = Paths.get(CLUSTER_CONFIG_CONF_PATH); final SingleTaskLauncher launcher = new SingleTaskLauncher(processBuilder, propertiesWrapper, clusterConfPath, ConfigFactory.empty()); final Path workUnitPath = Paths.get(WORK_UNIT_PATH); final Process process = launcher.launch(JOB_ID, workUnitPath); final List<String> expectedInput = new ArrayList<>(Arrays .asList("/javahome/bin/java", "-cp", TEST_CLASS_PATH, "org.apache.gobblin.cluster.SingleTaskRunnerMain", "--cluster_config_file_path", CLUSTER_CONFIG_CONF_PATH, "--job_id", JOB_ID, "--work_unit_file_path", WORK_UNIT_PATH)); verify(processBuilder).start(expectedInput); assertThat(process).isEqualTo(mockProcess); } }
@Test public void successTaskProcessShouldResultInCompletedStatus() throws IOException, InterruptedException { when(this.mockProcess.waitFor()).thenReturn(0); final TaskResult result = createAndRunTask(); assertThat(result.getStatus()).isEqualTo(TaskResult.Status.COMPLETED); final Path expectedPath = Paths.get(WORK_UNIT_FILE_PATH); verify(this.mockLauncher).launch(JOB_ID, expectedPath); verify(this.mockProcess).waitFor(); }
public HelixTaskFactory(Optional<ContainerMetrics> containerMetrics, Path clusterConfPath, Config sysConfig) { this.containerMetrics = containerMetrics; if (this.containerMetrics.isPresent()) { this.newTasksCounter = Optional .of(this.containerMetrics.get().getCounter(GOBBLIN_CLUSTER_NEW_HELIX_TASK_COUNTER)); } else { this.newTasksCounter = Optional.absent(); } launcher = new SingleTaskLauncher(new GobblinProcessBuilder(), new SystemPropertiesWrapper(), clusterConfPath, sysConfig); }
private TaskResult createAndRunTask() throws IOException { when(this.mockLauncher.launch(any(), any())).thenReturn(this.mockProcess); final ImmutableMap<String, String> configMap = ImmutableMap .of("job.name", "testJob", "job.id", JOB_ID, "gobblin.cluster.work.unit.file.path", WORK_UNIT_FILE_PATH); this.task = new SingleHelixTask(this.mockLauncher, configMap); return this.task.run(); } }
SingleHelixTask(final SingleTaskLauncher launcher, final Map<String, String> configMap) throws IOException { this.jobName = configMap.get(ConfigurationKeys.JOB_NAME_KEY); this.jobId = configMap.get(ConfigurationKeys.JOB_ID_KEY); final Path workUnitFilePath = Paths.get(configMap.get(GobblinClusterConfigurationKeys.WORK_UNIT_FILE_PATH)); logger.info(String .format("Launching a single task process. job name: %s. job id: %s", this.jobName, this.jobId)); this.taskProcess = launcher.launch(this.jobId, workUnitFilePath); }