org.springframework.cloud.deployer.spi.task.TaskStatus Java Examples

The following examples show how to use org.springframework.cloud.deployer.spi.task.TaskStatus. 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: AbstractCloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
protected TaskStatus toTaskStatus(GetTaskResponse response) {
	switch (response.getState()) {
	case SUCCEEDED:
		return new TaskStatus(response.getId(), LaunchState.complete, null);
	case RUNNING:
		return new TaskStatus(response.getId(), LaunchState.running, null);
	case PENDING:
		return new TaskStatus(response.getId(), LaunchState.launching, null);
	case CANCELING:
		return new TaskStatus(response.getId(), LaunchState.cancelled, null);
	case FAILED:
		return new TaskStatus(response.getId(), LaunchState.failed, null);
	default:
		throw new IllegalStateException(String.format("Unsupported CF task state %s", response.getState()));
	}
}
 
Example #2
Source File: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
private TaskStatus buildPodStatus(String id) {
	Pod pod = getPodByName(id);
	if (pod == null) {
		return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
	}

	PodStatus podStatus = pod.getStatus();
	if (podStatus == null) {
		return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
	}

	String phase = podStatus.getPhase();

	switch (phase) {
	case "Pending":
		return new TaskStatus(id, LaunchState.launching, new HashMap<>());
	case "Failed":
		return new TaskStatus(id, LaunchState.failed, new HashMap<>());
	case "Succeeded":
		return new TaskStatus(id, LaunchState.complete, new HashMap<>());
	default:
		return new TaskStatus(id, LaunchState.running, new HashMap<>());
	}
}
 
Example #3
Source File: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
@Override
public String launch(AppDeploymentRequest request) {
	String appId = createDeploymentId(request);
	TaskStatus status = status(appId);

	if (!status.getState().equals(LaunchState.unknown)) {
		throw new IllegalStateException("Task " + appId + " already exists with a state of " + status);
	}

	if (this.maxConcurrentExecutionsReached()) {
		throw new IllegalStateException(
			String.format("Cannot launch task %s. The maximum concurrent task executions is at its limit [%d].",
				request.getDefinition().getName(), this.getMaximumConcurrentTasks())
		);
	}

	logPossibleDownloadResourceMessage(request.getResource());
	try {
		launch(appId, request);
		return appId;
	} catch (RuntimeException e) {
		logger.error(e.getMessage(), e);
		throw e;
	}
}
 
Example #4
Source File: DefaultTaskExecutionServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void testUpgradeDueToDeploymentPropsChangeForCloudFoundrySucceedsIfNotReallyRunning() throws IOException {
	this.launcherRepository.delete(this.launcher);
	this.launcherRepository.save(new Launcher("default", "Cloud Foundry", taskLauncher));
	initializeSuccessfulRegistry(appRegistry);
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps/foo-task"));
	manifest.setTaskDeploymentRequest(request);
	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
	this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
	this.taskRepository.updateExternalExecutionId(myTask.getExecutionId(), "abc");
	when(this.taskLauncher.launch(any())).thenReturn("abc");
	when(this.taskLauncher.status("abc")).thenReturn(new TaskStatus("abc", LaunchState.failed, new HashMap<>()));
	this.taskExecutionService.executeTask(TASK_NAME_ORIG, new HashMap<>(), new LinkedList<>());
	verify(this.taskLauncher).destroy(TASK_NAME_ORIG);
}
 
Example #5
Source File: DefaultTaskExecutionServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void testUpgradeDueToDeploymentPropsChangeForCloudFoundryFailsWhenAlreadyRunning() throws IOException {
	this.launcherRepository.delete(this.launcher);
	this.launcherRepository.save(new Launcher("default", "Cloud Foundry", taskLauncher));
	initializeSuccessfulRegistry(appRegistry);
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps/foo-task"));
	manifest.setTaskDeploymentRequest(request);
	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
	this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
	this.taskRepository.updateExternalExecutionId(myTask.getExecutionId(), "abc");
	when(this.taskLauncher.launch(any())).thenReturn("abc");
	when(this.taskLauncher.status("abc")).thenReturn(new TaskStatus("abc", LaunchState.running,new HashMap<>()));
	thrown.expect(IllegalStateException.class);
	thrown.expectMessage("Unable to update application due to currently running applications");
	this.taskExecutionService.executeTask(TASK_NAME_ORIG, new HashMap<>(), new LinkedList<>());
}
 
Example #6
Source File: AbstractTaskLauncherIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #7
Source File: AbstractTaskLauncherIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #8
Source File: AbstractTaskLauncherIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #9
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 #10
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 #11
Source File: AbstractTaskLauncherIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: AbstractCloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<TaskStatus> getStatus(String id) {
	return requestGetTask(id)
			.map(this::toTaskStatus)
			.onErrorResume(isNotFoundError(), t -> {
				logger.debug("Task for id={} does not exist", id);
				return Mono.just(new TaskStatus(id, LaunchState.unknown, null));
			})
			.transform(statusRetry(id))
			.onErrorReturn(createErrorTaskStatus(id));
}
 
Example #13
Source File: AbstractCloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * Lookup the current status based on task id.
 *
 * @param id taskId as returned from the {@link TaskLauncher#launch(AppDeploymentRequest)}
 * @return the current task status
 */
@Override
public TaskStatus status(String id) {
	try {
		return getStatus(id)
				.doOnSuccess(v -> logger.info("Successfully computed status [{}] for id={}", v, id))
				.doOnError(logError(String.format("Failed to compute status for %s", id)))
				.block(Duration.ofMillis(this.deploymentProperties.getStatusTimeout()));
	}
	catch (Exception timeoutDueToBlock) {
		logger.error("Caught exception while querying for status of id={}", id, timeoutDueToBlock);
		return createErrorTaskStatus(id);
	}
}
 
Example #14
Source File: LocalTaskLauncher.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Override
public TaskStatus status(String id) {
	TaskInstance instance = running.get(id);
	if (instance != null) {
		return new TaskStatus(id, instance.getState(), instance.getAttributes());
	}
	return new TaskStatus(id, LaunchState.unknown, null);
}
 
Example #15
Source File: ChronosTaskLauncher.java    From spring-cloud-deployer-mesos with Apache License 2.0 5 votes vote down vote up
protected TaskStatus buildTaskStatus(ChronosTaskLauncherProperties properties, String id, Job job, String csv) {
	if (job == null) {
		return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
	}
	String last = null;
	String state= null;
	if (StringUtils.hasText(csv)) {
		List<String> csvLines = Arrays.asList(csv.split("\\r?\\n"));
		for (String line : csvLines) {
			if (line.startsWith("node")) {
				List<String> values = Arrays.asList(line.split("\\s*,\\s*"));
				if (values.size() >= 4) {
					if (id.equals(values.get(1))) {
						last = values.get(2);
						state = values.get(3);
						break;
					}
				}
			}
		}
	}
	if ("running".equals(state)) {
		return new TaskStatus(id, LaunchState.running, new HashMap<>());
	}
	if ("queued".equals(state)) {
		return new TaskStatus(id, LaunchState.launching, new HashMap<>());
	}
	if ("success".equals(last)) {
		return new TaskStatus(id, LaunchState.complete, new HashMap<>());
	}
	else {
		// TODO: state == idle could indicate cancelled?
		return new TaskStatus(id, LaunchState.failed, new HashMap<>());
	}
}
 
Example #16
Source File: YarnTaskLauncher.java    From spring-cloud-deployer-yarn with Apache License 2.0 5 votes vote down vote up
@Override
public TaskStatus status(String id) {
	logger.info("Status request for module {}", id);
	DeploymentKey key = new DeploymentKey(id);

	Collection<CloudAppInstanceInfo> instances = yarnCloudAppService.getInstances(CloudAppType.TASK);
	for (CloudAppInstanceInfo instance : instances) {
		if (instance.getApplicationId().equals(key.applicationId)) {
			if (instance.getState() == "RUNNING") {
				return new TaskStatus(id, LaunchState.running, null);
			}
		}
	}
	return new TaskStatus(id, LaunchState.unknown, null);
}
 
Example #17
Source File: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
TaskStatus buildTaskStatus(String id) {

		if(properties.isCreateJob()){
			Job job = getJob(id);

			if (job == null) {
				return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
			}

			JobStatus jobStatus = job.getStatus();

			if (jobStatus == null) {
				return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
			}

			boolean failed = jobStatus.getFailed() != null && jobStatus.getFailed() > 0;
			boolean succeeded = jobStatus.getSucceeded() != null && jobStatus.getSucceeded() > 0;
			if (failed) {
				return new TaskStatus(id, LaunchState.failed, new HashMap<>());
			}
			if (succeeded) {
				return new TaskStatus(id, LaunchState.complete, new HashMap<>());
			}
			return new TaskStatus(id, LaunchState.launching, new HashMap<>());

		} else {
			return buildPodStatus(id);
		}
	}
 
Example #18
Source File: TaskConfiguration.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Override
public TaskStatus status(String id) {
	return new TaskStatus(LAUNCH_ID, this.state, null);
}
 
Example #19
Source File: TaskSinkConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Override
public TaskStatus status(String id) {
	String taskLaunchId = LAUNCH_ID;
	TaskStatus taskStatus = new TaskStatus(taskLaunchId, state, null);
	return taskStatus;
}
 
Example #20
Source File: DefaultTaskExecutionServiceTransactionTests.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public TaskStatus status(String id) {
	return null;
}
 
Example #21
Source File: AbstractCloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private TaskStatus createErrorTaskStatus(String id) {
	return new TaskStatus(id, LaunchState.error, null);
}
 
Example #22
Source File: UnsupportedVersionTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
public TaskStatus status(String id) {
	throw failure();
}
 
Example #23
Source File: AbstractTaskLauncherIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
@Override
public TaskStatus status(String id) {
	return wrapped.status(id);
}
 
Example #24
Source File: AbstractTaskLauncherIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
@Test
public void testNonExistentAppsStatus() {
	assertThat(randomName(), hasStatusThat(
			Matchers.<TaskStatus>hasProperty("state", is(LaunchState.unknown))));
}
 
Example #25
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 #26
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 #27
Source File: LocalTaskLauncherIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 2 votes vote down vote up
@Test
public void testDeleteHistoryOnReLaunch() {
	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 launchId2 = taskLauncher().launch(request);

	assertThat(launchId2, not(is(launchId1)));

	timeout = deploymentTimeout();

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

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

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

	assertThat(launchId3, not(is(launchId1)));
	assertThat(launchId3, not(is(launchId2)));

	timeout = deploymentTimeout();

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

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

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

	taskLauncher().destroy(definition.getName());
}
 
Example #28
Source File: KubernetesTaskLauncherIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 2 votes vote down vote up
@Test
public void testDeploymentLabels() {
	log.info("Testing {}...", "deploymentLabels");

	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.deploymentLabels", "label1:value1,label2:value2"));

	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 labels 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> labels = pod.getMetadata().getLabels();

	assertTrue(labels.containsKey("label1"));
	assertTrue(labels.get("label1").equals("value1"));
	assertTrue(labels.containsKey("label2"));
	assertTrue(labels.get("label2").equals("value2"));

	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 #29
Source File: KubernetesTaskLauncherWithJobIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 2 votes vote down vote up
@Test
public void testJobSpecProperties() {
	log.info("Testing {}...", "JobSpecProperties");

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

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

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	Map<String, String> appRequest = new HashMap<>();
	appRequest.put("spring.cloud.deployer.kubernetes.restartPolicy", "OnFailure");
	appRequest.put("spring.cloud.deployer.kubernetes.backoffLimit", "5");
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, appRequest);

	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 of {}...", taskName);

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

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

	Job job = jobs.get(0);
	assertThat(job.getSpec().getBackoffLimit(), is(5));

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

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

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

	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));
}