org.springframework.cloud.deployer.spi.test.Timeout Java Examples

The following examples show how to use org.springframework.cloud.deployer.spi.test.Timeout. 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: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testGoodDeploymentWithLoadBalancer() {
	log.info("Testing {}...", "GoodDeploymentWithLoadBalancer");
	KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties();
	deployProperties.setCreateLoadBalancer(true);
	deployProperties.setMinutesToWaitForLoadBalancer(1);
	ContainerFactory containerFactory = new DefaultContainerFactory(deployProperties);
	KubernetesAppDeployer lbAppDeployer = new KubernetesAppDeployer(deployProperties, kubernetesClient,
			containerFactory);

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

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

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	lbAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #2
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 #3
Source File: LocalAppDeployerEnvironmentIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToCallShutdownOnUndeploy() {
	Map<String, String> properties = new HashMap<>();
	// disable shutdown endpoint
	properties.put("endpoints.shutdown.enabled", "false");
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

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

	String deploymentId = appDeployer().deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(deployed))), 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));
}
 
Example #4
Source File: LocalAppDeployerIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToCallShutdownOnUndeploy() {
	Map<String, String> properties = new HashMap<>();
	// disable shutdown endpoint
	properties.put("endpoints.shutdown.enabled", "false");
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

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

	String deploymentId = appDeployer().deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(deployed))), 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));
}
 
Example #5
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 #6
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceWithMultiplePorts() {
	log.info("Testing {}...", "ServiceWithMultiplePorts");
	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource,
			Collections.singletonMap("spring.cloud.deployer.kubernetes.servicePorts", "8080,9090"));

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

	List<ServicePort> servicePorts = kubernetesClient.services().withName(request.getDefinition().getName()).get()
			.getSpec().getPorts();

	assertThat(servicePorts, is(notNullValue()));
	assertThat(servicePorts.size(), is(2));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getPort().equals(8080)));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getName().equals("port-8080")));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getPort().equals(9090)));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getName().equals("port-9090")));

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #7
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultServicePortOverride() {
	log.info("Testing {}...", "DefaultServicePortOverride");
	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), Collections.singletonMap("server.port", "9090"));
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

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

	List<ServicePort> servicePorts = kubernetesClient.services().withName(request.getDefinition().getName()).get()
			.getSpec().getPorts();

	assertThat(servicePorts, is(notNullValue()));
	assertThat(servicePorts.size(), is(1));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getPort().equals(9090)));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getName().equals("port-9090")));

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #8
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultServicePort() {
	log.info("Testing {}...", "DefaultServicePort");
	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), kubernetesClient);

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

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

	List<ServicePort> servicePorts = kubernetesClient.services().withName(request.getDefinition().getName()).get()
			.getSpec().getPorts();

	assertThat(servicePorts, is(notNullValue()));
	assertThat(servicePorts.size(), is(1));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getPort().equals(8080)));
	assertTrue(servicePorts.stream().anyMatch(o -> o.getName().equals("port-8080")));

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #9
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleContainersInPod() {
	log.info("Testing {}...", "MultipleContainersInPod");

	KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties();

	KubernetesAppDeployer kubernetesAppDeployer = Mockito.spy(new KubernetesAppDeployer(deployProperties,
			kubernetesClient, new DefaultContainerFactory(deployProperties)));

	AppDefinition definition = new AppDefinition(randomName(), Collections.singletonMap("server.port", "9090"));
	Resource resource = testApplication();

	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

	doAnswer((Answer<PodSpec>) invocationOnMock -> {
		PodSpec podSpec = (PodSpec) invocationOnMock.callRealMethod();

		Container container = new ContainerBuilder().withName("asecondcontainer")
				.withImage(resource.getURI().getSchemeSpecificPart()).build();

		podSpec.getContainers().add(container);

		return podSpec;
	}).when(kubernetesAppDeployer).createPodSpec(Mockito.any(AppDeploymentRequest.class));

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

	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #10
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeploymentLabels() {
	Map<String, String> props = Collections.singletonMap("spring.cloud.deployer.kubernetes.deploymentLabels",
			"label1:value1,label2:value2");

	AppDefinition definition = new AppDefinition(randomName(), null);
	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, testApplication(), props);

	KubernetesAppDeployer deployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(),
			kubernetesClient);

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

	String deploymentId = deployer.deploy(appDeploymentRequest);

	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	
	
	Map<String, String> selector = Collections.singletonMap(SPRING_APP_KEY, deploymentId);

	List<Deployment> deployments = kubernetesClient.apps().deployments().withLabels(selector).list().getItems();

	Map<String, String> specLabels = deployments.get(0).getSpec().getTemplate().getMetadata().getLabels();

	assertTrue("Label 'label1' not found in deployment spec", specLabels.containsKey("label1"));
	assertEquals("Unexpected value for label1", "value1", specLabels.get("label1"));
	assertTrue("Label 'label2' not found in deployment spec", specLabels.containsKey("label2"));
	assertEquals("Unexpected value for label1", "value2", specLabels.get("label2"));

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	appDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #11
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeploymentServiceAccountName() {
	log.info("Testing {}...", "DeploymentServiceAccountName");

	ServiceAccount deploymentServiceAccount = new ServiceAccountBuilder().withNewMetadata().withName("appsa")
			.endMetadata().build();

	this.kubernetesClient.serviceAccounts().create(deploymentServiceAccount);

	String serviceAccountName = deploymentServiceAccount.getMetadata().getName();

	KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties();
	deployProperties.setDeploymentServiceAccountName(serviceAccountName);

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

	AppDefinition definition = new AppDefinition(randomName(), null);
	AppDeploymentRequest request = new AppDeploymentRequest(definition, testApplication());

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

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	appDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.serviceAccounts().delete(deploymentServiceAccount);
}
 
Example #12
Source File: LocalAppDeployerIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Test
public void testUseDefaultDeployerProperties()  throws IOException {

	LocalDeployerProperties localDeployerProperties = new LocalDeployerProperties();
	Path tmpPath = new File(System.getProperty("java.io.tmpdir")).toPath();
	Path customWorkDirRoot = tmpPath.resolve("test-default-directory");
	localDeployerProperties.setWorkingDirectoriesRoot(customWorkDirRoot.toFile().getAbsolutePath());

	// Create a new LocalAppDeployer using a working directory that is different from the default value.
	AppDeployer appDeployer = new LocalAppDeployer(localDeployerProperties);

	List<Path> beforeDirs = getBeforePaths(customWorkDirRoot);

	Map<String, String> properties = new HashMap<>();
	properties.put("server.port", "0");
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);


	// Deploy
	String deploymentId = appDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			appDeployer,
			Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));
	timeout = undeploymentTimeout();
	// Undeploy
	appDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			appDeployer,
			Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	List<Path> afterDirs = getAfterPaths(customWorkDirRoot);
	assertThat("Additional working directory not created", afterDirs.size(), CoreMatchers.is(beforeDirs.size()+1));

}
 
Example #13
Source File: LocalAppDeployerIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Test
public void testZeroPortReportsDeployed() throws IOException {
	Map<String, String> properties = new HashMap<>();
	properties.put("server.port", "0");
	Path tmpPath = new File(System.getProperty("java.io.tmpdir")).toPath();
	Path customWorkDirRoot = tmpPath.resolve("spring-cloud-deployer-app-workdir");
	Map<String, String> deploymentProperties = new HashMap<>();
	deploymentProperties.put(LocalDeployerProperties.PREFIX + ".working-directories-root", customWorkDirRoot.toFile().getAbsolutePath());

	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);

	List<Path> beforeDirs = getBeforePaths(customWorkDirRoot);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = appDeployer().deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(deployed))), 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));


	List<Path> afterDirs = getAfterPaths(customWorkDirRoot);
	assertThat("Additional working directory not created", afterDirs.size(), CoreMatchers.is(beforeDirs.size()+1));
}
 
Example #14
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedDeploymentWithLoadBalancer() {
	log.info("Testing {}...", "FailedDeploymentWithLoadBalancer");
	KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties();
	deployProperties.setCreateLoadBalancer(true);
	deployProperties.setLivenessProbePeriod(10);
	deployProperties.setMaxTerminatedErrorRestarts(1);
	deployProperties.setMaxCrashLoopBackOffRestarts(1);
	ContainerFactory containerFactory = new DefaultContainerFactory(deployProperties);
	KubernetesAppDeployer lbAppDeployer = new KubernetesAppDeployer(deployProperties, kubernetesClient,
			containerFactory);

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

	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.livenessProbePath", "/invalidpath");
	props.put("spring.cloud.deployer.kubernetes.livenessProbeDelay", "1");
	props.put("spring.cloud.deployer.kubernetes.livenessProbePeriod", "1");

	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props);

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

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	lbAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
 
Example #15
Source File: LocalAppDeployerIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppLogRetrieval() {
	Map<String, String> properties = new HashMap<>();
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = appDeployer().deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));
	String logContent = appDeployer().getLog(deploymentId);
	assertThat(logContent, containsString("Starting DeployerIntegrationTestApplication"));
}
 
Example #16
Source File: CloudFoundryTaskLauncherIntegrationTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
protected Timeout undeploymentTimeout() {
	return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier));
}
 
Example #17
Source File: KubernetesTaskLauncherWithJobIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testJobAnnotations() {
	log.info("Testing {}...", "JobAnnotations");

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setCreateJob(true);

	KubernetesTaskLauncher kubernetesTaskLauncher = new KubernetesTaskLauncher(kubernetesDeployerProperties,
			new KubernetesTaskLauncherProperties(), kubernetesClient);

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

	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource,
			Collections.singletonMap("spring.cloud.deployer.kubernetes.jobAnnotations",
					"key1:val1,key2:val2,key3:val31:val32"));

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

	String launchId = kubernetesTaskLauncher.launch(request);
	Timeout timeout = deploymentTimeout();

	assertThat(launchId, eventually(hasStatusThat(
			Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.launching))), timeout.maxAttempts,
			timeout.pause));

	String taskName = request.getDefinition().getName();

	log.info("Checking Job spec annotations of {}...", taskName);

	List<Job> jobs = kubernetesClient.batch().jobs().withLabel("task-name", taskName).list().getItems();

	assertThat(jobs.size(), is(1));

	Map<String, String> jobAnnotations = jobs.get(0).getMetadata().getAnnotations();
	assertFalse(jobAnnotations.isEmpty());
	assertTrue(jobAnnotations.size() == 3);
	assertTrue(jobAnnotations.containsKey("key1"));
	assertTrue(jobAnnotations.get("key1").equals("val1"));
	assertTrue(jobAnnotations.containsKey("key2"));
	assertTrue(jobAnnotations.get("key2").equals("val2"));
	assertTrue(jobAnnotations.containsKey("key3"));
	assertTrue(jobAnnotations.get("key3").equals("val31:val32"));

	log.info("Checking Pod spec annotations of {}...", taskName);

	List<Pod> pods = kubernetesClient.pods().withLabel("task-name", taskName).list().getItems();

	assertThat(pods.size(), is(1));

	Map<String, String> podAnnotations = pods.get(0).getMetadata().getAnnotations();
	assertFalse(podAnnotations.isEmpty());
	assertTrue(podAnnotations.size() == 3);
	assertTrue(podAnnotations.containsKey("key1"));
	assertTrue(podAnnotations.get("key1").equals("val1"));
	assertTrue(podAnnotations.containsKey("key2"));
	assertTrue(podAnnotations.get("key2").equals("val2"));
	assertTrue(podAnnotations.containsKey("key3"));
	assertTrue(podAnnotations.get("key3").equals("val31:val32"));

	log.info("Destroying {}...", taskName);

	timeout = undeploymentTimeout();
	kubernetesTaskLauncher.destroy(taskName);

	assertThat(taskName, eventually(hasStatusThat(
			Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.unknown))), timeout.maxAttempts,
			timeout.pause));
}
 
Example #18
Source File: KubernetesTaskLauncherIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Override
protected Timeout deploymentTimeout() {
	return new Timeout(20, 5000);
}
 
Example #19
Source File: KubernetesTaskLauncherIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testJobPodAnnotation() {
	log.info("Testing {}...", "JobPodAnnotation");

	KubernetesTaskLauncher kubernetesTaskLauncher = new KubernetesTaskLauncher(new KubernetesDeployerProperties(),
			new KubernetesTaskLauncherProperties(), kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource,
			Collections.singletonMap("spring.cloud.deployer.kubernetes.jobAnnotations", "key1:val1,key2:val2,key3:val31:val32"));

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

	String launchId = kubernetesTaskLauncher.launch(request);
	Timeout timeout = deploymentTimeout();

	assertThat(launchId, eventually(hasStatusThat(
			Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.running))), timeout.maxAttempts,
			timeout.pause));

	String taskName = request.getDefinition().getName();

	log.info("Checking job pod spec annotations of {}...", taskName);

	List<Pod> pods = kubernetesClient.pods().withLabel("task-name", taskName).list().getItems();

	assertThat(pods.size(), is(1));

	Pod pod = pods.get(0);

	assertTrue(pod.getSpec().getContainers().get(0).getPorts().isEmpty());

	Map<String, String> annotations = pod.getMetadata().getAnnotations();

	assertTrue(annotations.containsKey("key1"));
	assertTrue(annotations.get("key1").equals("val1"));
	assertTrue(annotations.containsKey("key2"));
	assertTrue(annotations.get("key2").equals("val2"));
	assertTrue(annotations.containsKey("key3"));
	assertTrue(annotations.get("key3").equals("val31:val32"));

	log.info("Destroying {}...", taskName);

	timeout = undeploymentTimeout();
	kubernetesTaskLauncher.destroy(taskName);

	assertThat(taskName, eventually(hasStatusThat(
			Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.unknown))), timeout.maxAttempts,
			timeout.pause));
}
 
Example #20
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
public Timeout getScheduleTimeout() {
	return scheduleTimeout;
}
 
Example #21
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
public void setScheduleTimeout(Timeout scheduleTimeout) {
	this.scheduleTimeout = scheduleTimeout;
}
 
Example #22
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
public Timeout getUnScheduleTimeout() {
	return unScheduleTimeout;
}
 
Example #23
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
public void setUnScheduleTimeout(Timeout unScheduleTimeout) {
	this.unScheduleTimeout = unScheduleTimeout;
}
 
Example #24
Source File: MesosAppDeployerIntegrationTests.java    From spring-cloud-deployer-mesos with Apache License 2.0 4 votes vote down vote up
@Override
protected Timeout deploymentTimeout() {
	return new Timeout(36, 10000);
}
 
Example #25
Source File: ChronosTaskLauncherIntegrationTests.java    From spring-cloud-deployer-mesos with Apache License 2.0 4 votes vote down vote up
@Override
protected org.springframework.cloud.deployer.spi.test.Timeout deploymentTimeout() {
	return new Timeout(30, 5000);
}
 
Example #26
Source File: CloudFoundryTaskLauncherIntegrationTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
protected Timeout deploymentTimeout() {
	return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier));
}
 
Example #27
Source File: CloudFoundryAppDeployerIntegrationTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
protected Timeout deploymentTimeout() {
	return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier));
}
 
Example #28
Source File: LocalTaskLauncherIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 4 votes vote down vote up
private void basicLaunchAndValidation(AppDefinition definition, Map<String, String> deploymentProperties) {
	List<String> commandLineArgs = new ArrayList<>(1);
	// Test to ensure no issues parsing server.port command line arg.
	commandLineArgs.add(LocalTaskLauncher.SERVER_PORT_KEY_COMMAND_LINE_ARG + SocketUtils.findAvailableTcpPort(LocalTaskLauncher.DEFAULT_SERVER_PORT));

	AppDeploymentRequest request = new AppDeploymentRequest(definition, this.testApplication(), deploymentProperties, commandLineArgs);


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

	String launchId = this.taskLauncher().launch(request);
	assertThat(taskLauncher.getRunningTaskExecutionCount(), eventually(is(1)));
	Timeout timeout = this.deploymentTimeout();

	Assert.assertThat(launchId, EventuallyMatcher.eventually(this.hasStatusThat(Matchers.hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause));

	this.taskLauncher().destroy(definition.getName());
	assertThat(taskLauncher.getRunningTaskExecutionCount(), eventually(is(0)));
}
 
Example #29
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testScaleStatefulSet() {
	log.info("Testing {}...", "ScaleStatefulSet");
	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();

	Map<String, String> props = new HashMap<>();
	props.put(KubernetesAppDeployer.COUNT_PROPERTY_KEY, "3");
	props.put(KubernetesAppDeployer.INDEXED_PROPERTY_KEY, "true");

	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props);

	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(3))));

	// Ensure that a StatefulSet is deployed
	Map<String, String> selector = Collections.singletonMap(SPRING_APP_KEY, deploymentId);
	List<StatefulSet> statefulSets = kubernetesClient.apps().statefulSets().withLabels(selector).list().getItems();
	assertNotNull(statefulSets);
	assertEquals(1, statefulSets.size());
	StatefulSet statefulSet = statefulSets.get(0);
	StatefulSetSpec statefulSetSpec = statefulSet.getSpec();
	Assertions.assertThat(statefulSetSpec.getPodManagementPolicy()).isEqualTo("Parallel");
	Assertions.assertThat(statefulSetSpec.getReplicas()).isEqualTo(3);
	Assertions.assertThat(statefulSetSpec.getServiceName()).isEqualTo(deploymentId);
	Assertions.assertThat(statefulSet.getMetadata().getName()).isEqualTo(deploymentId);

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

	statefulSets = kubernetesClient.apps().statefulSets().withLabels(selector).list().getItems();
	assertEquals(1, statefulSets.size());
	statefulSetSpec = statefulSets.get(0).getSpec();
	Assertions.assertThat(statefulSetSpec.getReplicas()).isEqualTo(1);
	Assertions.assertThat(statefulSetSpec.getServiceName()).isEqualTo(deploymentId);
	Assertions.assertThat(statefulSet.getMetadata().getName()).isEqualTo(deploymentId);

	appDeployer.undeploy(deploymentId);
}
 
Example #30
Source File: CloudFoundryAppDeployerIntegrationTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
protected Timeout undeploymentTimeout() {
	return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier));
}