org.springframework.cloud.deployer.spi.core.AppDeploymentRequest Java Examples

The following examples show how to use org.springframework.cloud.deployer.spi.core.AppDeploymentRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskLauncherIT.java    From spring-cloud-deployer-yarn with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskTimestampAsHdfsResourceNotExist() throws Exception {
	assertThat(context.containsBean("taskLauncher"), is(true));
	assertThat(context.getBean("taskLauncher"), instanceOf(YarnTaskLauncher.class));
	TaskLauncher deployer = context.getBean("taskLauncher", TaskLauncher.class);

	@SuppressWarnings("resource")
	HdfsResourceLoader resourceLoader = new HdfsResourceLoader(getConfiguration());
	resourceLoader.setHandleNoprefix(true);
	Resource resource = resourceLoader.getResource("hdfs:/dataflow/artifacts/cache/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec.jar");

	AppDefinition definition = new AppDefinition("timestamp-task", null);
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

	Exception deployException = null;

	try {
		deployer.launch(request);
	} catch (Exception e) {
		deployException = e;
	}
	assertThat("Expected deploy exception", deployException, notNullValue());
}
 
Example #2
Source File: LocalAppDeployerEnvironmentIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
@Test
// was triggered by GH-50 and subsequently GH-55
public void testNoStdoutStderrOnInheritLoggingAndNoNPEOnGetAttributes() {
	Map<String, String> properties = new HashMap<>();
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.singletonMap(LocalDeployerProperties.INHERIT_LOGGING, "true"));

	AppDeployer deployer = appDeployer();
	String deploymentId = deployer.deploy(request);
	AppStatus appStatus = deployer.status(deploymentId);
	assertTrue(appStatus.getInstances().size() > 0);
	for (Entry<String, AppInstanceStatus> instanceStatusEntry : appStatus.getInstances().entrySet()) {
		Map<String, String> attributes = instanceStatusEntry.getValue().getAttributes();
		assertFalse(attributes.containsKey("stdout"));
		assertFalse(attributes.containsKey("stderr"));
	}
	deployer.undeploy(deploymentId);
}
 
Example #3
Source File: AbstractTaskLauncherIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #4
Source File: DefaultStreamServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
public ArgumentCaptor<StreamDeploymentRequest> testStreamDeploy(Map<String, String> deploymentProperties) {
	appDeploymentRequestCreator = mock(AppDeploymentRequestCreator.class);
	skipperStreamDeployer = mock(SkipperStreamDeployer.class);
	streamDefinitionRepository = mock(StreamDefinitionRepository.class);

	this.defaultStreamService = new DefaultStreamService(streamDefinitionRepository,
			this.skipperStreamDeployer, this.appDeploymentRequestCreator,
			this.streamValidationService, this.auditRecordService, new DefaultStreamDefinitionService());

	StreamDefinition streamDefinition = new StreamDefinition("test1", "time | log");

	when(streamDefinitionRepository.findById(streamDefinition.getName())).thenReturn(Optional.of(streamDefinition));

	List<AppDeploymentRequest> appDeploymentRequests = Arrays.asList(mock(AppDeploymentRequest.class));
	when(appDeploymentRequestCreator.createRequests(streamDefinition, new HashMap<>()))
			.thenReturn(appDeploymentRequests);

	this.defaultStreamService.deployStream(streamDefinition1.getName(), deploymentProperties);

	ArgumentCaptor<StreamDeploymentRequest> argumentCaptor = ArgumentCaptor.forClass(StreamDeploymentRequest.class);
	verify(skipperStreamDeployer, times(1)).deployStream(argumentCaptor.capture());

	return argumentCaptor;
}
 
Example #5
Source File: KubernetesAppDeployerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void deployWithEnvironmentWithMultipleCommaDelimitedValue() throws Exception {
	AppDefinition definition = new AppDefinition("app-test", null);
	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.environmentVariables",
			"JAVA_TOOL_OPTIONS='thing1,thing2',OPTS='thing3, thing4'");

	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);

	deployer = new KubernetesAppDeployer(bindDeployerProperties(), null);
	PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);

	assertThat(podSpec.getContainers().get(0).getEnv())
			.contains(
				new EnvVar("JAVA_TOOL_OPTIONS", "thing1,thing2", null),
				new EnvVar("OPTS", "thing3, thing4", null));
}
 
Example #6
Source File: DockerCommandBuilderTests.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpringApplicationJSON() throws Exception {
	LocalDeployerProperties properties = new LocalDeployerProperties();
	LocalAppDeployer deployer = new LocalAppDeployer(properties);
	AppDefinition definition = new AppDefinition("foo", Collections.singletonMap("foo","bar"));
	Resource resource = new DockerResource("foo/bar");
	Map<String, String> deploymentProperties = new HashMap<>();
	deploymentProperties.put(LocalDeployerProperties.DEBUG_PORT, "9999");
	deploymentProperties.put(LocalDeployerProperties.DEBUG_SUSPEND, "y");
	deploymentProperties.put(LocalDeployerProperties.INHERIT_LOGGING, "true");
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);
	ProcessBuilder builder = deployer.buildProcessBuilder(request, request.getDefinition().getProperties(), Optional.of(1), "foo" );

	String SAJ = LocalDeployerUtils.isWindows() ? "SPRING_APPLICATION_JSON={\\\"foo\\\":\\\"bar\\\"}" : "SPRING_APPLICATION_JSON={\"foo\":\"bar\"}";
	assertThat(builder.command(), hasItems("-e", SAJ));

}
 
Example #7
Source File: KubernetesAppDeployerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigMapKeyRefGlobalFromYaml() throws Exception {
	AppDefinition definition = new AppDefinition("app-test", null);
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null);

	deployer = new KubernetesAppDeployer(bindDeployerProperties(), null);
	PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);

	List<EnvVar> envVars = podSpec.getContainers().get(0).getEnv();

	assertEquals("Invalid number of env vars", 3, envVars.size());

	EnvVar configMapKeyRefEnvVar = envVars.get(1);
	assertEquals("Unexpected env var name", "MY_ENV", configMapKeyRefEnvVar.getName());
	ConfigMapKeySelector configMapKeySelector = configMapKeyRefEnvVar.getValueFrom().getConfigMapKeyRef();
	assertEquals("Unexpected config map name", "myConfigMap", configMapKeySelector.getName());
	assertEquals("Unexpected config map data key", "envName", configMapKeySelector.getKey());
}
 
Example #8
Source File: LocalTaskLauncherIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
@Test
public void testAppLogRetrieval() {
	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);

	String launchId1 = taskLauncher().launch(request);

	Timeout timeout = deploymentTimeout();

	assertThat(launchId1, eventually(hasStatusThat(
			Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause));
	String logContent = taskLauncher().getLog(launchId1);
	assertThat(logContent, containsString("Starting DeployerIntegrationTestApplication"));
}
 
Example #9
Source File: AbstractCloudFoundryDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
/**
 * Always delete downloaded files for static http resources. Conditionally delete maven resources.
 * @param appDeploymentRequest
 */
protected void deleteLocalApplicationResourceFile(AppDeploymentRequest appDeploymentRequest) {

	try {

		Optional<File> fileToDelete = fileToDelete(appDeploymentRequest.getResource());
		if (fileToDelete.isPresent()) {
			File applicationFile = fileToDelete.get();

			logger.info("Free Disk Space = {} bytes, Total Disk Space = {} bytes",
					applicationFile.getFreeSpace(),
					applicationFile.getTotalSpace());


			boolean deleted = deleteFileOrDirectory(applicationFile);
			logger.info((deleted) ? "Successfully deleted the application resource: " + applicationFile.getCanonicalPath() :
					"Could not delete the application resource: " + applicationFile.getCanonicalPath());
		}

	} catch(IOException e){
		logger.warn("Exception deleting the application resource after successful CF push request."
				+ " This could cause increase in disk space usage. Exception message: " + e.getMessage());
	}
}
 
Example #10
Source File: DefaultContainerFactoryTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void createWithContainerCommand() {
	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
			kubernetesDeployerProperties);

	AppDefinition definition = new AppDefinition("app-test", null);
	Resource resource = getResource();
	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.containerCommand",
			"echo arg1 'arg2'");
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
			resource, props);

	ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest);
	Container container = defaultContainerFactory.create(containerConfiguration);
	assertNotNull(container);
	assertThat(container.getCommand()).containsExactly("echo", "arg1", "arg2");
}
 
Example #11
Source File: DefaultContainerFactoryTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void createWithPorts() {
	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
			kubernetesDeployerProperties);

	AppDefinition definition = new AppDefinition("app-test", null);
	Resource resource = getResource();
	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.containerPorts",
			"8081, 8082, 65535");
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
			resource, props);

	ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest);
	Container container = defaultContainerFactory.create(containerConfiguration);
	assertNotNull(container);
	List<ContainerPort> containerPorts = container.getPorts();
	assertNotNull(containerPorts);
	assertTrue("There should be three ports set", containerPorts.size() == 3);
	assertTrue(8081 == containerPorts.get(0).getContainerPort());
	assertTrue(8082 == containerPorts.get(1).getContainerPort());
	assertTrue(65535 == containerPorts.get(2).getContainerPort());
}
 
Example #12
Source File: TickTock.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
private static AppDeploymentRequest createAppDeploymentRequest(String app, String stream) {
	MavenResource resource = new MavenResource.Builder()
			.artifactId(app)
			.groupId("org.springframework.cloud.stream.app")
			.version("1.0.0.BUILD-SNAPSHOT")
			.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("server.port", "0");
	if (app.contains("-source-")) {
		properties.put("spring.cloud.stream.bindings.output.destination", stream);
	}
	else {
		properties.put("spring.cloud.stream.bindings.input.destination", stream);
		properties.put("spring.cloud.stream.bindings.input.group", "default");
	}
	AppDefinition definition = new AppDefinition(app, properties);
	Map<String, String> deploymentProperties = new HashMap<>();
	deploymentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, stream);
	/*
	 * This will allow output to be logged to the output of the process that started
	 * the application.
	 */
	deploymentProperties.put(LocalDeployerProperties.INHERIT_LOGGING, "true");
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);
	return request;
}
 
Example #13
Source File: KubernetesAppDeployerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigMapKeyRef() {
	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.configMapKeyRefs",
			"[{envVarName: 'MY_ENV', configMapName: 'myConfigMap', dataKey: 'envName'}]");

	AppDefinition definition = new AppDefinition("app-test", null);
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);

	deployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), null);
	PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);

	List<EnvVar> envVars = podSpec.getContainers().get(0).getEnv();

	assertEquals("Invalid number of env vars", 2, envVars.size());

	EnvVar configMapKeyRefEnvVar = envVars.get(0);
	assertEquals("Unexpected env var name", "MY_ENV", configMapKeyRefEnvVar.getName());
	ConfigMapKeySelector configMapKeySelector = configMapKeyRefEnvVar.getValueFrom().getConfigMapKeyRef();
	assertEquals("Unexpected config map name", "myConfigMap", configMapKeySelector.getName());
	assertEquals("Unexpected config map data key", "envName", configMapKeySelector.getKey());
}
 
Example #14
Source File: KubernetesAppDeployerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testPodSecurityContextFromYaml() throws Exception {
	AppDefinition definition = new AppDefinition("app-test", null);
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null);

	deployer = new KubernetesAppDeployer(bindDeployerProperties(), null);
	PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);

	PodSecurityContext podSecurityContext = podSpec.getSecurityContext();

	assertNotNull("Pod security context should not be null", podSecurityContext);

	assertEquals("Unexpected run as user", Long.valueOf("65534"), podSecurityContext.getRunAsUser());
	assertEquals("Unexpected fs group", Long.valueOf("65534"), podSecurityContext.getFsGroup());
}
 
Example #15
Source File: DefaultTaskJobServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestart() throws Exception {
	this.taskJobService.restartJobExecution(1L);
	final ArgumentCaptor<AppDeploymentRequest> argument = ArgumentCaptor.forClass(AppDeploymentRequest.class);
	verify(this.taskLauncher, times(1)).launch(argument.capture());
	AppDeploymentRequest appDeploymentRequest = argument.getAllValues().get(0);
	assertTrue(appDeploymentRequest.getCommandlineArguments().contains("identifying.param(string)=testparam"));
}
 
Example #16
Source File: KubernetesAppDeployerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testPodAntiAffinityGlobalProperty() {
	AppDefinition definition = new AppDefinition("app-test", null);
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null);

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();

	LabelSelector labelSelector = new LabelSelector();
	labelSelector.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder()
			.withKey("app")
			.withOperator("In")
			.withValues("store")
			.build()));
	PodAffinityTerm podAffinityTerm = new PodAffinityTerm(labelSelector, null, "kubernetes.io/hostname");
	LabelSelector labelSelector2 = new LabelSelector();
	labelSelector2.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder()
			.withKey("security")
			.withOperator("In")
			.withValues("s2")
			.build()));
	PodAffinityTerm podAffinityTerm2 = new PodAffinityTerm(labelSelector2, null, "failure-domain.beta.kubernetes.io/zone");
	WeightedPodAffinityTerm weightedPodAffinityTerm = new WeightedPodAffinityTerm(podAffinityTerm2, 100);
	PodAntiAffinity podAntiAffinity = new AffinityBuilder()
			.withNewPodAntiAffinity()
			.withRequiredDuringSchedulingIgnoredDuringExecution(podAffinityTerm)
			.withPreferredDuringSchedulingIgnoredDuringExecution(weightedPodAffinityTerm)
			.endPodAntiAffinity()
			.buildPodAntiAffinity();

	kubernetesDeployerProperties.setPodAntiAffinity(podAntiAffinity);

	deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null);
	PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);

	PodAntiAffinity podAntiAffinityTest = podSpec.getAffinity().getPodAntiAffinity();
	assertNotNull("Pod anti-affinity should not be null", podAntiAffinityTest);
	assertNotNull("RequiredDuringSchedulingIgnoredDuringExecution should not be null", podAntiAffinityTest.getRequiredDuringSchedulingIgnoredDuringExecution());
	assertEquals("PreferredDuringSchedulingIgnoredDuringExecution should have one element", 1, podAntiAffinityTest.getPreferredDuringSchedulingIgnoredDuringExecution().size());
}
 
Example #17
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testScaleDeployment() {
	log.info("Testing {}...", "ScaleDeployment");
	KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties();

	ContainerFactory containerFactory = new DefaultContainerFactory(deployProperties);
	KubernetesAppDeployer appDeployer = new KubernetesAppDeployer(deployProperties, kubernetesClient,
			containerFactory);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();

	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.emptyMap());

	log.info("Deploying {}...", request.getDefinition().getName());
	Timeout timeout = deploymentTimeout();
	String deploymentId = appDeployer.deploy(request);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));
	assertThat(deploymentId, eventually(appInstanceCount(is(1))));

	log.info("Scale Up {}...", request.getDefinition().getName());
	appDeployer.scale(new AppScaleRequest(deploymentId, 3));
	assertThat(deploymentId, eventually(appInstanceCount(is(3)), timeout.maxAttempts, timeout.pause));

	log.info("Scale Down {}...", request.getDefinition().getName());
	appDeployer.scale(new AppScaleRequest(deploymentId, 1));
	assertThat(deploymentId, eventually(appInstanceCount(is(1)), timeout.maxAttempts, timeout.pause));

	appDeployer.undeploy(deploymentId);
}
 
Example #18
Source File: AbstractAppDeployerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 5 votes vote down vote up
/**
 * Tests support for instance count support and individual instance status report.
 */
@Test
public void testMultipleInstancesDeploymentAndPartialState() {
	Map<String, String> appProperties = new HashMap<>();
	appProperties.put("matchInstances", "1"); // Only instance n°1 will kill itself
	appProperties.put("killDelay", "0");
	AppDefinition definition = new AppDefinition(randomName(), appProperties);
	Resource resource = testApplication();

	Map<String, String> deploymentProperties = new HashMap<>();
	deploymentProperties.put(AppDeployer.COUNT_PROPERTY_KEY, "3");
	deploymentProperties.put(AppDeployer.INDEXED_PROPERTY_KEY, "true");
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);

	log.info("Deploying {}...", request.getDefinition().getName());

	String deploymentId = appDeployer().deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(partial))), timeout.maxAttempts, timeout.pause));

	// Assert individual instance state
	// Note we can't rely on instances order, neither on their id indicating their ordinal number
	List<DeploymentState> individualStates = new ArrayList<>();
	for (AppInstanceStatus status : appDeployer().status(deploymentId).getInstances().values()) {
		individualStates.add(status.getState());
	}
	assertThat(individualStates, containsInAnyOrder(
			is(deployed),
			is(deployed),
			is(failed)
	));

	log.info("Undeploying {}...", deploymentId);

	timeout = undeploymentTimeout();
	appDeployer().undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #19
Source File: ChronosTaskLauncher.java    From spring-cloud-deployer-mesos with Apache License 2.0 5 votes vote down vote up
protected Map<String, String> createSpringApplicationJson(AppDeploymentRequest request) {
	String value = "{}";
	try {
		value = new ObjectMapper().writeValueAsString(
				Optional.ofNullable(request.getDefinition().getProperties())
						.orElse(Collections.emptyMap()));
	} catch (JsonProcessingException e) {}
	Map<String, String> springApp = new HashMap<>();
	if (!"{}".equals(value)) {
		springApp.put("name", "SPRING_APPLICATION_JSON");
		springApp.put("value", value);
	}
	return springApp;
}
 
Example #20
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * Stages the application specified in the {@link ScheduleRequest} on the CF server.
 * @param scheduleRequest {@link ScheduleRequest} containing the information required to schedule a task.
 * @return the command string for the scheduled task.
 */
private String stageTask(ScheduleRequest scheduleRequest) {
	logger.debug(String.format("Staging Task: ",
			scheduleRequest.getDefinition().getName()));
	AppDeploymentRequest request = new AppDeploymentRequest(
			scheduleRequest.getDefinition(),
			scheduleRequest.getResource(),
			scheduleRequest.getDeploymentProperties(),
			scheduleRequest.getCommandlineArguments());
	SummaryApplicationResponse response = taskLauncher.stage(request);
	return taskLauncher.getCommand(response, request);
}
 
Example #21
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void stageTaskWithNonExistentApplicationBindingThreeServices() throws IOException {
	setupTaskWithNonExistentApplicationBindingThreeServices(this.resource);
	AppDeploymentRequest request = deploymentRequest(this.resource,
			Collections.singletonMap(CloudFoundryDeploymentProperties.SERVICES_PROPERTY_KEY,
					"test-service-instance-1,test-service-instance-2,test-service-instance-3"));

	SummaryApplicationResponse response = this.launcher.stage(request);
	assertThat(response.getId(), equalTo("test-application-id"));
	assertThat(response.getDetectedStartCommand(), equalTo("test-command"));
}
 
Example #22
Source File: ChronosTaskLauncher.java    From spring-cloud-deployer-mesos with Apache License 2.0 5 votes vote down vote up
protected List<String> createCommandArgs(AppDeploymentRequest request) {
	List<String> cmdArgs = new LinkedList<String>();
	// add provided command line args
	cmdArgs.addAll(request.getCommandlineArguments());
	logger.debug("Using command args: " + cmdArgs);
	return cmdArgs;
}
 
Example #23
Source File: AppDeploymentRequestFactory.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an {@link AppDeploymentRequest}.
 *
 * @param applicationSpec the Spring Cloud Deployer application spec
 * @param releaseName the release name
 * @param version the release version
 * @return a created AppDeploymentRequest
 */
public AppDeploymentRequest createAppDeploymentRequest(SpringCloudDeployerApplicationManifest applicationSpec, String releaseName,
		String version) {
	SpringCloudDeployerApplicationSpec spec = applicationSpec.getSpec();
	Map<String, String> applicationProperties = new TreeMap<>();
	if (spec.getApplicationProperties() != null) {
		applicationProperties.putAll(spec.getApplicationProperties());
	}
	// we need to keep group name same for consumer groups not getting broken, but
	// app name needs to differentiate as otherwise it may result same deployment id and
	// failure on a deployer.
	AppDefinition appDefinition = new AppDefinition(applicationSpec.getApplicationName() + "-v" + version,
			applicationProperties);
	Resource resource;
	try {
		resource = delegatingResourceLoader.getResource(getResourceLocation(spec.getResource(), spec.getVersion()));
	}
	catch (Exception e) {
		throw new SkipperException(
				"Could not load Resource " + spec.getResource() + ". Message = " + e.getMessage(), e);
	}

	Map<String, String> deploymentProperties = new TreeMap<>();
	if (spec.getDeploymentProperties() != null) {
		deploymentProperties.putAll(spec.getDeploymentProperties());
	}
	if (!deploymentProperties.containsKey(AppDeployer.GROUP_PROPERTY_KEY)) {
		logger.debug("Defaulting spring.cloud.deployer.group=" + releaseName);
		deploymentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, releaseName);
	}
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(appDefinition, resource,
			deploymentProperties);
	return appDeploymentRequest;
}
 
Example #24
Source File: KubernetesAppDeployerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void deployWithNodeSelectorGlobalProperty() throws Exception {
	AppDefinition definition = new AppDefinition("app-test", null);
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null);

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setNodeSelector("disktype:ssd, os:qnx");

	deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null);
	PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);

	assertThat(podSpec.getNodeSelector()).containsOnly(entry("disktype", "ssd"), entry("os", "qnx"));
}
 
Example #25
Source File: KubernetesAppDeployerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testInvalidDeploymentLabelDelimiter() {
	Map<String, String> props = Collections.singletonMap("spring.cloud.deployer.kubernetes.deploymentLabels",
			"label1|value1");

	AppDefinition definition = new AppDefinition("app-test", null);
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);
	this.deploymentPropertiesResolver.getDeploymentLabels(appDeploymentRequest.getDeploymentProperties());
}
 
Example #26
Source File: DefaultContainerFactoryTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void createCustomReadinessPortFromAppRequest() {
	int defaultPort = 8080;
	int readinessPort = 8090;

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
			kubernetesDeployerProperties);

	AppDefinition definition = new AppDefinition("app-test", null);
	Resource resource = getResource();
	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.readinessProbePort", Integer.toString(readinessPort));
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
			resource, props);

	ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest)
			.withHostNetwork(true)
			.withExternalPort(defaultPort);
	Container container = defaultContainerFactory.create(containerConfiguration);
	assertNotNull(container);

	List<ContainerPort> containerPorts = container.getPorts();
	assertNotNull(containerPorts);

	assertTrue("Only two container ports should be set", containerPorts.size() == 2);
	assertTrue(8080 == containerPorts.get(0).getContainerPort());
	assertTrue(8080 == containerPorts.get(0).getHostPort());
	assertTrue(8090 == containerPorts.get(1).getContainerPort());
	assertTrue(8090 == containerPorts.get(1).getHostPort());
	assertTrue(8090 == container.getReadinessProbe().getHttpGet().getPort().getIntVal());
}
 
Example #27
Source File: StreamDeploymentRequest.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
public StreamDeploymentRequest(String streamName, String dslText, List<AppDeploymentRequest> appDeploymentRequests,
		Map<String, String> streamDeployerProperties) {
	Assert.hasText(streamName, "stream name is required");
	Assert.hasText(dslText, "dslText is required");
	Assert.notNull(appDeploymentRequests, "appDeploymentRequests can not be null");
	Assert.notNull(streamDeployerProperties, "streamDeployerProperties can not be null");
	this.streamName = streamName;
	this.dslText = dslText;
	this.appDeploymentRequests = appDeploymentRequests;
	this.streamDeployerProperties = streamDeployerProperties;
}
 
Example #28
Source File: DefaultContainerFactoryTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void createCustomReadinessPortFromProperties() {
	int defaultPort = 8080;
	int readinessPort = 8090;

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setReadinessProbePort(readinessPort);
	DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
			kubernetesDeployerProperties);

	AppDefinition definition = new AppDefinition("app-test", null);
	Resource resource = getResource();
	Map<String, String> props = new HashMap<>();
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
			resource, props);

	ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest)
			.withHostNetwork(true)
			.withExternalPort(defaultPort);
	Container container = defaultContainerFactory.create(containerConfiguration);
	assertNotNull(container);

	List<ContainerPort> containerPorts = container.getPorts();
	assertNotNull(containerPorts);

	assertTrue("Only two container ports should be set", containerPorts.size() == 2);
	assertTrue(8080 == containerPorts.get(0).getContainerPort());
	assertTrue(8080 == containerPorts.get(0).getHostPort());
	assertTrue(8090 == containerPorts.get(1).getContainerPort());
	assertTrue(8090 == containerPorts.get(1).getHostPort());
	assertTrue(8090 == container.getReadinessProbe().getHttpGet().getPort().getIntVal());
}
 
Example #29
Source File: DefaultTaskExecutionServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext
public void executeComposedTaskWithEnabledUserAccessToken2() {
	initializeSuccessfulRegistry(appRegistry);

	final List<String> arguments = new ArrayList<>();
	arguments.add("--dataflow-server-use-user-access-token =  true");
	AppDeploymentRequest request = getAppDeploymentRequestForToken(
			prepareEnvironmentForTokenTests(this.taskSaveService,
			this.taskLauncher, this.appRegistry), arguments,
			this.taskExecutionService, this.taskLauncher);
	assertTrue("Should contain the property 'dataflow-server-access-token'",
		request.getDefinition().getProperties().containsKey("dataflow-server-access-token"));
	assertEquals("foo-bar-123-token", request.getDefinition().getProperties().get("dataflow-server-access-token"));
}
 
Example #30
Source File: ConsulBinderTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the jar execution command.
 * @param jarPath the jar path
 * @param request the request
 * @return the string[]
 */
protected String[] buildJarExecutionCommand(String jarPath,
		AppDeploymentRequest request) {

	ArrayList<String> commands = new ArrayList<>();
	commands.add(super.getLocalDeployerProperties().getJavaCmd());
	commands.add("-cp");
	commands.add(request.getDefinition().getProperties().get("classpath"));
	commands.add(request.getDefinition().getProperties().get("main"));
	commands.addAll(request.getCommandlineArguments());

	return commands.toArray(new String[commands.size()]);
}