/** * Construct a {@code DataFlowAppDefinition}. * * @param registeredAppName name of application in registry * @param label label used for application * @param properties app properties; may be {@code null} */ protected DataFlowAppDefinition(String registeredAppName, String label, Map<String, String> properties) { Assert.notNull(registeredAppName, "registeredAppName must not be null"); Assert.notNull(label, "label must not be null"); this.registeredAppName = registeredAppName; this.appDefinition = new AppDefinition(label, properties); }
/** * Construct a {@code DataFlowAppDefinition}. * * @param registeredAppName name of application in registry * @param label label used for application * @param applicationType the application type if already determined * @param properties app properties; may be {@code null} */ protected DataFlowAppDefinition(String registeredAppName, String label, ApplicationType applicationType, Map<String, String> properties) { Assert.notNull(registeredAppName, "registeredAppName must not be null"); Assert.notNull(applicationType, "applicationType must not be null"); Assert.notNull(label, "label must not be null"); this.registeredAppName = registeredAppName; this.applicationType = applicationType; this.appDefinition = new AppDefinition(label, properties); }
/** * Return a new app definition where definition-time and deploy-time properties have been * merged and short form parameters have been expanded to their long form (amongst the * whitelisted supported properties of the app) if applicable. */ /* default */ AppDefinition mergeAndExpandAppProperties(StreamAppDefinition original, Resource metadataResource, Map<String, String> appDeployTimeProperties) { Map<String, String> merged = new HashMap<>(original.getProperties()); merged.putAll(appDeployTimeProperties); merged = this.whitelistProperties.qualifyProperties(merged, metadataResource); merged.putIfAbsent(StreamPropertyKeys.METRICS_PROPERTIES, "spring.application.name,spring.application.index," + "spring.cloud.application.*,spring.cloud.dataflow.*"); merged.putIfAbsent(StreamPropertyKeys.METRICS_TRIGGER_INCLUDES, "integration**"); return new AppDefinition(original.getName(), merged); }
/** * Return a new app definition where definition-time and deploy-time properties have been * merged and short form parameters have been expanded to their long form (amongst the * whitelisted supported properties of the app) if applicable. */ /* default */ AppDefinition mergeAndExpandAppProperties(StreamAppDefinition original, Resource metadataResource, Map<String, String> appDeployTimeProperties) { Map<String, String> merged = new HashMap<>(original.getProperties()); merged.putAll(appDeployTimeProperties); merged = this.whitelistProperties.qualifyProperties(merged, metadataResource); merged.putIfAbsent(StreamPropertyKeys.METRICS_PROPERTIES, "spring.application.name,spring.application.index," + "spring.cloud.application.*,spring.cloud.dataflow.*"); merged.putIfAbsent(StreamPropertyKeys.METRICS_TRIGGER_INCLUDES, "integration**"); return new AppDefinition(original.getName(), merged); }
private void launchTask(TaskLaunchRequest taskLaunchRequest) { Assert.notNull(this.taskLauncher, "TaskLauncher has not been initialized"); logger.info("Launching Task for the following uri " + taskLaunchRequest.getUri()); Resource resource = this.resourceLoader.getResource(taskLaunchRequest.getUri()); AppDefinition definition = new AppDefinition(taskLaunchRequest.getApplicationName(), taskLaunchRequest.getEnvironmentProperties()); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, taskLaunchRequest.getDeploymentProperties(), taskLaunchRequest.getCommandlineArguments()); this.taskLauncher.launch(request); }
public ApplicationDefinition(String name, String dslText) { super(); this.name = name; this.dslText = dslText; // ApplicationParser AppNode applicationNode = new ApplicationParser(name, dslText).parse(); Map<String, String> properties = new HashMap<>(); if (applicationNode.hasArguments()) { for (ArgumentNode argumentNode : applicationNode.getArguments()) { properties.put(argumentNode.getName(), argumentNode.getValue()); } } setRegisteredAppName(applicationNode.getName()); this.appDefinition = new AppDefinition(name, properties); }
@Test public void testInvalidCronExpression() { final String INVALID_EXPRESSION = "BAD"; String definitionName = randomName(); String scheduleName = scheduleName() + definitionName; Map<String, String> properties = new HashMap<>(getSchedulerProperties()); properties.put(SchedulerPropertyKeys.CRON_EXPRESSION, INVALID_EXPRESSION); AppDefinition definition = new AppDefinition(definitionName, properties); ScheduleRequest request = new ScheduleRequest(definition, properties, getDeploymentProperties(), getCommandLineArgs(), scheduleName, testApplication()); this.expectedException.expect(CreateScheduleException.class); taskScheduler().schedule(request); }
/** * Tests that command line args can be passed in. */ @Test public void testCommandLineArgs() { Map<String, String> properties = new HashMap<>(); properties.put("killDelay", "1000"); AppDefinition definition = new AppDefinition(randomName(), properties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.<String, String>emptyMap(), Collections.singletonList("--exitCode=0")); log.info("Launching {}...", request.getDefinition().getName()); String deploymentId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(complete))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
public TaskDefinition(String name, String dsl) { this.taskName = name; this.dslText = dsl; Map<String, String> properties = new LinkedHashMap<>(); TaskNode taskNode = new TaskParser(name, dsl, true, true).parse(); if (taskNode.isComposed()) { setRegisteredAppName(name); } else { TaskAppNode singleTaskApp = taskNode.getTaskApp(); setRegisteredAppName(singleTaskApp.getName()); if (singleTaskApp.hasArguments()) { for (ArgumentNode argumentNode : singleTaskApp.getArguments()) { properties.put(argumentNode.getName(), argumentNode.getValue()); } } } properties.put(SPRING_CLOUD_TASK_NAME, name); this.appDefinition = new AppDefinition(name, properties); }
@Test public void testSimpleLaunch() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "0"); appProperties.put("exitCode", "0"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
/** * Tests that command line args can be passed in. */ @Test public void testCommandLineArgs() { Map<String, String> properties = new HashMap<>(); properties.put("killDelay", "1000"); AppDefinition definition = new AppDefinition(randomName(), properties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.<String, String>emptyMap(), Collections.singletonList("--exitCode=0")); log.info("Launching {}...", request.getDefinition().getName()); String deploymentId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(complete))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
@Test public void testErrorExit() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "0"); appProperties.put("exitCode", "1"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.failed))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
@Test public void testSimpleLaunch() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "0"); appProperties.put("exitCode", "0"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
@Test public void testErrorExit() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "0"); appProperties.put("exitCode", "1"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.failed))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
private ScheduleRequest createScheduleRequest(String scheduleName, String definitionName) { AppDefinition definition = new AppDefinition(definitionName, getAppProperties()); return new ScheduleRequest(definition, getSchedulerProperties(), getDeploymentProperties(), getCommandLineArgs(), scheduleName, testApplication()); }
@PostLoad public void initialize() { Map<String, String> properties = new HashMap<>(); TaskNode taskNode = new TaskParser(this.taskName, this.dslText, true, true).parse(); if (taskNode.isComposed()) { setRegisteredAppName(this.taskName); } else { TaskAppNode singleTaskApp = taskNode.getTaskApp(); setRegisteredAppName(singleTaskApp.getName()); if (singleTaskApp.hasArguments()) { for (ArgumentNode argumentNode : singleTaskApp.getArguments()) { properties.put(argumentNode.getName(), argumentNode.getValue()); } } } properties.put(SPRING_CLOUD_TASK_NAME, this.taskName); this.appDefinition = new AppDefinition(this.taskName, properties); }
@Test public void testReLaunch() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "0"); appProperties.put("exitCode", "0"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause)); log.info("Re-Launching {}...", request.getDefinition().getName()); String newLaunchId = taskLauncher().launch(request); assertThat(newLaunchId, not(is(launchId))); timeout = deploymentTimeout(); assertThat(newLaunchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
@Test public void testFailedDeployment() { Map<String, String> properties = new HashMap<>(); properties.put("killDelay", "0"); AppDefinition definition = new AppDefinition(randomName(), properties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, properties); log.info("Deploying {}...", request.getDefinition().getName()); String deploymentId = appDeployer().deploy(request); Timeout timeout = deploymentTimeout(); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(failed))), timeout.maxAttempts, timeout.pause)); log.info("Undeploying {}...", deploymentId); timeout = undeploymentTimeout(); appDeployer().undeploy(deploymentId); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause)); }
@Test public void testSimpleCancel() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "-1"); appProperties.put("exitCode", "0"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.running))), timeout.maxAttempts, timeout.pause)); log.info("Cancelling {}...", request.getDefinition().getName()); taskLauncher().cancel(launchId); timeout = undeploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.cancelled))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
@Test public void testSimpleCancel() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "-1"); appProperties.put("exitCode", "0"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.running))), timeout.maxAttempts, timeout.pause)); log.info("Cancelling {}...", request.getDefinition().getName()); taskLauncher().cancel(launchId); timeout = undeploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.cancelled))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }