private long launchTask(LaunchRequest request) { log.info(String.format("Launching Task %s", request.getTaskName())); return taskOperations.launch(request.getTaskName(), request.getDeploymentProperties(), request.getCommandlineArguments()); }
private boolean serverIsAcceptingNewTasks() { boolean availableForNewTasks = false; try { CurrentTaskExecutionsResource taskExecutionsResource = taskOperations.currentTaskExecutions(); availableForNewTasks = taskExecutionsResource.getRunningExecutionCount() < taskExecutionsResource.getMaximumTaskExecutions(); if (!availableForNewTasks) { log.warn(String.format("Data Flow server has reached its concurrent task execution limit: (%d)", taskExecutionsResource.getMaximumTaskExecutions())); } } // If cannot connect to Data Flow server, log the exception and return false so the poller will back off. catch( Exception e) { log.error(e.getMessage(), e); } finally { return availableForNewTasks; } }
@CliCommand(value = TASK_EXECUTION_CLEANUP, help = "Clean up any platform specific resources linked to a task " + "execution") public String cleanup(@CliOption(key = { "", "id" }, help = "the task execution id", mandatory = true) long id) { taskOperations().cleanup(id); return String.format("Request to clean up resources for task execution %s has been submitted", id); }
@CliCommand(value = EXECUTION_LIST, help = "List created task executions filtered by taskName") public Table executionListByName(@CliOption(key = "name", help = "the task name to be used as a filter", optionContext = "existing-task disable-string-converter") String name) { final PagedResources<TaskExecutionResource> tasks; if (name == null) { tasks = taskOperations().executionList(); } else { tasks = taskOperations().executionListByTaskName(name); } LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("taskName", "Task Name"); headers.put("executionId", "ID"); headers.put("startTime", "Start Time"); headers.put("endTime", "End Time"); headers.put("exitCode", "Exit Code"); final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers)); return DataFlowTables.applyStyle(builder).build(); }
@CliCommand(value = LIST, help = "List created tasks") public Table list() { final PagedResources<TaskDefinitionResource> tasks = taskOperations().list(); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", "Task Name"); headers.put("dslText", "Task Definition"); headers.put("status", "Task Status"); final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers)); return DataFlowTables.applyStyle(builder).build(); }
@CliCommand(value = CREATE, help = "Create a new task definition") public String create( @CliOption(mandatory = true, key = { "", "name" }, help = "the name to give to the task") String name, @CliOption(mandatory = true, key = { "definition" }, help = "a task definition, using the DSL (e.g. " + "\"timestamp --format=YYYY\")", optionContext = "disable-string-converter completion-task") String dsl) { this.taskOperations().create(name, dsl); return String.format("Created new task '%s'", name); }
@CliCommand(value = DESTROY, help = "Destroy an existing task") public String destroy( @CliOption(key = { "", "name" }, help = "the name of the task to destroy", mandatory = true, optionContext = "existing-task disable-string-converter") String name) { taskOperations().destroy(name); return String.format("Destroyed task '%s'", name); }
@CliCommand(value = DESTROY_TASK_ALL, help = "Destroy all existing tasks") public String destroyAll( @CliOption(key = "force", help = "bypass confirmation prompt", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean force) { if (force || "y".equalsIgnoreCase(userInput.promptWithOptions("Really destroy all tasks?", "n", "y", "n"))) { taskOperations().destroyAll(); return String.format("All tasks destroyed"); } else { return ""; } }
@CliCommand(value = EXECUTION_LIST, help = "List created task executions filtered by taskName") public Table executionListByName(@CliOption(key = "name", help = "the task name to be used as a filter", optionContext = "existing-task disable-string-converter") String name) { final PagedResources<TaskExecutionResource> tasks; if (name == null) { tasks = taskOperations().executionList(); } else { tasks = taskOperations().executionListByTaskName(name); } LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("taskName", "Task Name"); headers.put("executionId", "ID"); headers.put("startTime", "Start Time"); headers.put("endTime", "End Time"); headers.put("exitCode", "Exit Code"); final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers)); return DataFlowTables.applyStyle(builder).build(); }
@CliCommand(value = LIST, help = "List created tasks") public Table list() { final PagedResources<TaskDefinitionResource> tasks = taskOperations().list(); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", "Task Name"); headers.put("dslText", "Task Definition"); headers.put("status", "Task Status"); final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers)); return DataFlowTables.applyStyle(builder).build(); }
@CliCommand(value = CREATE, help = "Create a new task definition") public String create( @CliOption(mandatory = true, key = { "", "name" }, help = "the name to give to the task") String name, @CliOption(mandatory = true, key = { "definition" }, help = "a task definition, using the DSL (e.g. " + "\"timestamp --format=YYYY\")", optionContext = "disable-string-converter completion-task") String dsl) { this.taskOperations().create(name, dsl); return String.format("Created new task '%s'", name); }
@CliCommand(value = DESTROY, help = "Destroy an existing task") public String destroy( @CliOption(key = { "", "name" }, help = "the name of the task to destroy", mandatory = true, optionContext = "existing-task disable-string-converter") String name) { taskOperations().destroy(name); return String.format("Destroyed task '%s'", name); }
@CliCommand(value = LAUNCH, help = "Launch a previously created task") public String launch( @CliOption(key = { "", "name" }, help = "the name of the task to launch", mandatory = true, optionContext = "existing-task disable-string-converter") String name, @CliOption(key = { PROPERTIES_OPTION }, help = "the properties for this launch") String properties, @CliOption(key = { PROPERTIES_FILE_OPTION }, help = "the properties for this launch (as a File)") File propertiesFile, @CliOption(key = { ARGUMENTS_OPTION }, help = "the commandline arguments for this launch") String arguments, @CliOption(key = { PLATFORM_NAME}, help = "the platform name to use for this launch", unspecifiedDefaultValue = "default") String platformName) throws IOException { int which = Assertions.atMostOneOf(PROPERTIES_OPTION, properties, PROPERTIES_FILE_OPTION, propertiesFile); Map<String, String> propertiesToUse = DeploymentPropertiesUtils.parseDeploymentProperties(properties, propertiesFile, which); List<String> argumentsToUse = new ArrayList<String>(); if (StringUtils.hasText(arguments)) { argumentsToUse.add(arguments); } DeploymentPropertiesUtils.validateDeploymentProperties(propertiesToUse); if (StringUtils.hasText(platformName)) { propertiesToUse.put("spring.cloud.dataflow.task.platformName", platformName); } taskOperations().launch(name, propertiesToUse, argumentsToUse); return String.format("Launched task '%s'", name); }
@CliCommand(value = TASK_EXECUTION_CURRENT, help = "Display count of currently executin tasks and related information") public Table currentExecutions() { CurrentTaskExecutionsResource taskExecutionsResource = taskOperations().currentTaskExecutions(); TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>(); modelBuilder.addRow().addValue("Current Running Tasks").addValue(taskExecutionsResource.getRunningExecutionCount()); modelBuilder.addRow().addValue("Maximum Concurrent Executions").addValue(taskExecutionsResource .getMaximumTaskExecutions()); TableBuilder builder = new TableBuilder(modelBuilder.build()); DataFlowTables.applyStyle(builder); return builder.build(); }
break; case "task": taskOperations().list().forEach(tdf -> completions.add(new Completion(tdf.getName()))); break; case "counter":
@CliCommand(value = TASK_EXECUTION_CLEANUP, help = "Clean up any platform specific resources linked to a task " + "execution") public String cleanup(@CliOption(key = { "", "id" }, help = "the task execution id", mandatory = true) long id) { taskOperations().cleanup(id); return String.format("Request to clean up resources for task execution %s has been submitted", id); }
@CliCommand(value = LAUNCH, help = "Launch a previously created task") public String launch( @CliOption(key = { "", "name" }, help = "the name of the task to launch", mandatory = true, optionContext = "existing-task disable-string-converter") String name, @CliOption(key = { PROPERTIES_OPTION }, help = "the properties for this launch", mandatory = false) String properties, @CliOption(key = { PROPERTIES_FILE_OPTION }, help = "the properties for this launch (as a File)", mandatory = false) File propertiesFile, @CliOption(key = { ARGUMENTS_OPTION }, help = "the commandline arguments for this launch", mandatory = false) String arguments) throws IOException { int which = Assertions.atMostOneOf(PROPERTIES_OPTION, properties, PROPERTIES_FILE_OPTION, propertiesFile); Map<String, String> propertiesToUse = DeploymentPropertiesUtils.parseDeploymentProperties(properties, propertiesFile, which); List<String> argumentsToUse = new ArrayList<String>(); if (StringUtils.hasText(arguments)) { argumentsToUse.add(arguments); } DeploymentPropertiesUtils.validateDeploymentProperties(propertiesToUse); taskOperations().launch(name, propertiesToUse, argumentsToUse); return String.format("Launched task '%s'", name); }
@CliCommand(value = TASK_EXECUTION_CURRENT, help = "Display count of currently executin tasks and related information") public Table currentExecutions() { CurrentTaskExecutionsResource taskExecutionsResource = taskOperations().currentTaskExecutions(); TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>(); modelBuilder.addRow().addValue("Current Running Tasks").addValue(taskExecutionsResource.getRunningExecutionCount()); modelBuilder.addRow().addValue("Maximum Concurrent Executions").addValue(taskExecutionsResource .getMaximumTaskExecutions()); TableBuilder builder = new TableBuilder(modelBuilder.build()); DataFlowTables.applyStyle(builder); return builder.build(); }
break; case "task": taskOperations().list().forEach(tdf -> completions.add(new Completion(tdf.getName()))); break; case "counter":
/** * Executes the task as specified by the taskName with the associated * properties and arguments. * @param contribution mutable state to be passed back to update the current step execution * @param chunkContext contains the task-execution-id used by the listener. * @return Repeat status of FINISHED. */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { String tmpTaskName = this.taskName.substring(0, this.taskName.lastIndexOf('_')); List<String> args = this.arguments; ExecutionContext stepExecutionContext = chunkContext.getStepContext().getStepExecution(). getExecutionContext(); if(stepExecutionContext.containsKey("task-arguments")) { args = (List<String>) stepExecutionContext.get("task-arguments"); } long executionId = this.taskOperations.launch(tmpTaskName, this.properties, args); stepExecutionContext.put("task-execution-id", executionId); stepExecutionContext.put("task-arguments", args); waitForTaskToComplete(executionId); return RepeatStatus.FINISHED; }