Java Code Examples for org.springframework.cloud.deployer.spi.app.AppDeployer#status()

The following examples show how to use org.springframework.cloud.deployer.spi.app.AppDeployer#status() . 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: HealthCheckStep.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
public boolean isHealthy(Release replacingRelease) {
	AppDeployerData replacingAppDeployerData = this.appDeployerDataRepository
			.findByReleaseNameAndReleaseVersionRequired(
					replacingRelease.getName(), replacingRelease.getVersion());
	Map<String, String> appNamesAndDeploymentIds = (replacingAppDeployerData!= null) ?
			replacingAppDeployerData.getDeploymentDataAsMap() : Collections.EMPTY_MAP;
	AppDeployer appDeployer = this.deployerRepository
			.findByNameRequired(replacingRelease.getPlatformName())
			.getAppDeployer();
	logger.debug("Getting status for apps in replacing release {}-v{}", replacingRelease.getName(),
			replacingRelease.getVersion());
	for (Map.Entry<String, String> appNameAndDeploymentId : appNamesAndDeploymentIds.entrySet()) {
		AppStatus status = appDeployer.status(appNameAndDeploymentId.getValue());
		if (status.getState() == DeploymentState.deployed) {
			return true;
		}
	}
	return false;
}
 
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: LocalAppDeployerIntegrationTests.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 4
Source File: DeleteStep.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
public Release delete(Release release, AppDeployerData existingAppDeployerData,
		List<String> applicationNamesToDelete) {
	AppDeployer appDeployer = this.deployerRepository.findByNameRequired(release.getPlatformName())
			.getAppDeployer();

	Map<String, String> appNamesAndDeploymentIds = (existingAppDeployerData!= null) ?
			existingAppDeployerData.getDeploymentDataAsMap() : Collections.EMPTY_MAP;

	for (Map.Entry<String, String> appNameAndDeploymentId : appNamesAndDeploymentIds.entrySet()) {
		if (applicationNamesToDelete.contains(appNameAndDeploymentId.getKey())) {
			AppStatus appStatus = appDeployer.status(appNameAndDeploymentId.getValue());
			if (appStatus.getState().equals(DeploymentState.deployed)) {
				appDeployer.undeploy(appNameAndDeploymentId.getValue());
			}
			else {
				logger.warn("For Release name {}, did not undeploy existing app {} as its status is not "
						+ "'deployed'.", release.getName(), appNameAndDeploymentId.getKey());
			}
		}
	}

	Status deletedStatus = new Status();
	deletedStatus.setStatusCode(StatusCode.DELETED);
	release.getInfo().setStatus(deletedStatus);
	release.getInfo().setDescription("Delete complete");
	this.releaseRepository.save(release);
	return release;
}
 
Example 5
Source File: LocalAppDeployerEnvironmentIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Test
public void testInDebugModeWithSuspended() throws Exception {
	Map<String, String> properties = new HashMap<>();
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	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);

	AppDeployer deployer = appDeployer();
	String deploymentId = deployer.deploy(request);
	Thread.sleep(5000);
	AppStatus appStatus = deployer.status(deploymentId);
	if (resource instanceof DockerResource) {
		try {
			String containerId = getCommandOutput("docker ps -q --filter ancestor="+ TESTAPP_DOCKER_IMAGE_NAME);
			String logOutput = getCommandOutput("docker logs "+ containerId);
			assertTrue(logOutput.contains("Listening for transport dt_socket at address: 9999"));
		} catch (IOException e) {
		}
	}
	else {
		assertEquals("deploying", appStatus.toString());
	}

	deployer.undeploy(deploymentId);
}
 
Example 6
Source File: LocalAppDeployerIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Test
public void testInDebugModeWithSuspended() throws Exception {
	Map<String, String> properties = new HashMap<>();
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	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);

	AppDeployer deployer = appDeployer();
	String deploymentId = deployer.deploy(request);
	Thread.sleep(5000);
	AppStatus appStatus = deployer.status(deploymentId);
	if (resource instanceof DockerResource) {
		try {
			String containerId = getCommandOutput("docker ps -q --filter ancestor="+ TESTAPP_DOCKER_IMAGE_NAME);
			String logOutput = getCommandOutput("docker logs "+ containerId);
			assertTrue(logOutput.contains("Listening for transport dt_socket at address: 9999"));
		} catch (IOException e) {
		}
	}
	else {
		assertEquals("deploying", appStatus.toString());
	}

	deployer.undeploy(deploymentId);
}
 
Example 7
Source File: LocalAppDeployerIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Test
public void testInDebugModeWithSuspendedUseCamelCase() throws Exception {
	Map<String, String> properties = new HashMap<>();
	AppDefinition definition = new AppDefinition(randomName(), properties);
	Resource resource = testApplication();
	Map<String, String> deploymentProperties = new HashMap<>();
	deploymentProperties.put(LocalDeployerProperties.PREFIX + ".debugPort", "8888");
	deploymentProperties.put(LocalDeployerProperties.PREFIX + ".debugSuspend", "y");
	deploymentProperties.put(LocalDeployerProperties.PREFIX + ".inheritLogging", "true");
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);

	AppDeployer deployer = appDeployer();
	String deploymentId = deployer.deploy(request);
	Thread.sleep(5000);
	AppStatus appStatus = deployer.status(deploymentId);
	if (resource instanceof DockerResource) {
		try {
			String containerId = getCommandOutput("docker ps -q --filter ancestor="+ TESTAPP_DOCKER_IMAGE_NAME);
			String logOutput = getCommandOutput("docker logs "+ containerId);
			assertTrue(logOutput.contains("Listening for transport dt_socket at address: 8888"));
		} catch (IOException e) {
		}
	}
	else {
		assertEquals("deploying", appStatus.toString());
	}

	deployer.undeploy(deploymentId);
}
 
Example 8
Source File: AppDeployerIT.java    From spring-cloud-deployer-yarn with Apache License 2.0 4 votes vote down vote up
@Test
public void testSmokeDeployer() throws Exception {
	assertThat(context.containsBean("appDeployer"), is(true));
	assertThat(context.getBean("appDeployer"), instanceOf(YarnAppDeployer.class));
	AppDeployer deployer = context.getBean("appDeployer", AppDeployer.class);
	YarnCloudAppService yarnCloudAppService = context.getBean(YarnCloudAppService.class);

	MavenProperties m2Properties = new MavenProperties();
	Map<String, RemoteRepository> remoteRepositories = new HashMap<>();
	remoteRepositories.put("default", new RemoteRepository("https://repo.spring.io/libs-snapshot-local"));
	m2Properties.setRemoteRepositories(remoteRepositories);

	MavenResource timeResource = new MavenResource.Builder(m2Properties)
			.artifactId("time-source")
			.groupId(GROUP_ID)
			.version(artifactVersion)
			.extension("jar")
			.classifier("exec")
			.build();

	MavenResource logResource = new MavenResource.Builder(m2Properties)
			.artifactId("log-sink")
			.groupId(GROUP_ID)
			.version(artifactVersion)
			.extension("jar")
			.classifier("exec")
			.build();

	Map<String, String> timeProperties = new HashMap<>();
	timeProperties.put("spring.cloud.stream.bindings.output.destination", "ticktock.0");
	AppDefinition timeDefinition = new AppDefinition("time", timeProperties);
	Map<String, String> timeEnvironmentProperties = new HashMap<>();
	timeEnvironmentProperties.put(AppDeployer.COUNT_PROPERTY_KEY, "1");
	timeEnvironmentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, "ticktock");
	AppDeploymentRequest timeRequest = new AppDeploymentRequest(timeDefinition, timeResource, timeEnvironmentProperties);

	Map<String, String> logProperties = new HashMap<>();
	logProperties.put("spring.cloud.stream.bindings.input.destination", "ticktock.0");
	logProperties.put("expression", "new String(payload + ' hello')");
	AppDefinition logDefinition = new AppDefinition("log", logProperties);
	Map<String, String> logEnvironmentProperties = new HashMap<>();
	logEnvironmentProperties.put(AppDeployer.COUNT_PROPERTY_KEY, "1");
	logEnvironmentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, "ticktock");
	AppDeploymentRequest logRequest = new AppDeploymentRequest(logDefinition, logResource, logEnvironmentProperties);


	String timeId = deployer.deploy(timeRequest);
	assertThat(timeId, notNullValue());
	String logId = deployer.deploy(logRequest);
	assertThat(logId, notNullValue());

	ApplicationId applicationId = assertWaitApp(2, TimeUnit.MINUTES, yarnCloudAppService);
	assertWaitFileContent(2, TimeUnit.MINUTES, applicationId, "Started TimeSourceApplication");
	assertThat(deployer.status(timeId).getState(), is(DeploymentState.deployed));
	assertWaitFileContent(1, TimeUnit.MINUTES, applicationId, "Started LogSinkApplication");
	assertThat(deployer.status(logId).getState(), is(DeploymentState.deployed));
	assertWaitFileContent(1, TimeUnit.MINUTES, applicationId, "hello");

	for (int i = 0; i < 10; i++) {
		deployer.status(timeId);
		deployer.status(logId);
	}
	deployer.undeploy(timeId);
	for (int i = 0; i < 500; i++) {
		deployer.status(timeId);
		deployer.status(logId);
	}
	deployer.undeploy(logId);
	for (int i = 0; i < 500; i++) {
		deployer.status(timeId);
		deployer.status(logId);
	}

	assertWaitFileContent(2, TimeUnit.MINUTES, applicationId, "stopped outbound.ticktock.0");
	assertWaitFileContent(2, TimeUnit.MINUTES, applicationId, "stopped inbound.ticktock.0");

	List<Resource> resources = ContainerLogUtils.queryContainerLogs(
			getYarnCluster(), applicationId);

	assertThat(resources, notNullValue());
	assertThat(resources.size(), is(6));

	for (Resource res : resources) {
		File file = res.getFile();
		String content = ContainerLogUtils.getFileContent(file);
		if (file.getName().endsWith("stdout")) {
			assertThat(file.length(), greaterThan(0l));
		} else if (file.getName().endsWith("Container.stderr")) {
			assertThat("stderr with content: " + content, file.length(), is(0l));
		}
	}
}
 
Example 9
Source File: Deployer.java    From spring-cloud-cli with Apache License 2.0 4 votes vote down vote up
private AppStatus getAppStatus(AppDeployer deployer, String id) {
	AppStatus appStatus = deployer.status(id);
	this.deployed.put(id, appStatus.getState());
	return appStatus;
}