org.springframework.cloud.deployer.spi.app.AppInstanceStatus Java Examples

The following examples show how to use org.springframework.cloud.deployer.spi.app.AppInstanceStatus. 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: MarathonAppDeployer.java    From spring-cloud-deployer-mesos with Apache License 2.0 6 votes vote down vote up
private AppInstanceStatus buildInstanceStatus(String id) throws MarathonException {
	App appInstance = marathon.getApp(id).getApp();
	logger.debug("Deployment " + id + " has " + appInstance.getTasksRunning() + "/" + appInstance.getInstances() + " tasks running");
	if (appInstance.getTasks() != null) {
		// there should only be one task for this type of deployment
		MarathonAppInstanceStatus status = null;
		for (Task task : appInstance.getTasks()) {
			if (status == null) {
				status = MarathonAppInstanceStatus.up(appInstance, task);
			}
		}
		if (status == null) {
			status = MarathonAppInstanceStatus.down(appInstance);
		}
		return status;
	}
	else {
		return MarathonAppInstanceStatus.down(appInstance);
	}
}
 
Example #2
Source File: RuntimeStreamsControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private AppInstanceStatus instance(String id, String guid, String appName) {
	return new AppInstanceStatus() {
		@Override
		public String getId() {
			return id;
		}

		@Override
		public DeploymentState getState() {
			return DeploymentState.deployed;
		}

		@Override
		public Map<String, String> getAttributes() {
			Map<String, String> attributes = new HashMap<>();
			attributes.put(StreamRuntimePropertyKeys.ATTRIBUTE_SKIPPER_APPLICATION_NAME, appName);
			if (guid != null) {
				attributes.put(StreamRuntimePropertyKeys.ATTRIBUTE_GUID, guid);
			}
			return attributes;
		}
	};
}
 
Example #3
Source File: SkipperStreamDeployer.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
public static List<AppStatus> deserializeAppStatus(String platformStatus) {
	try {
		if (platformStatus != null) {
			ObjectMapper mapper = new ObjectMapper();
			mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
			mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
			SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
			resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
			module.setAbstractTypes(resolver);
			mapper.registerModule(module);
			TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
			};
			return mapper.readValue(platformStatus, typeRef);
		}
		return new ArrayList<>();
	}
	catch (Exception e) {
		logger.error("Could not parse Skipper Platform Status JSON [" + platformStatus + "]. " +
				"Exception message = " + e.getMessage());
		return new ArrayList<>();
	}
}
 
Example #4
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 #5
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 #6
Source File: Status.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
@JsonIgnore
public String getPlatformStatusPrettyPrint() {
	List<AppStatus> appStatusList = getAppStatusList();
	StringBuffer statusMsg = new StringBuffer();

	for (AppStatus appStatus : appStatusList) {
		statusMsg.append("[" + appStatus.getDeploymentId() + "]");
		if (appStatus.getInstances().isEmpty()) {
			statusMsg.append(", State = [" + appStatus.getState() + "]\n");
		}
		else {
			statusMsg.append(", State = [");
			for (AppInstanceStatus appInstanceStatus : appStatus.getInstances().values()) {
				statusMsg.append(appInstanceStatus.getId() + "=" + appInstanceStatus.getState() + "\n");
			}
			statusMsg.setLength(statusMsg.length() - 1);
			statusMsg.append("]\n");
		}
	}
	return statusMsg.toString();
}
 
Example #7
Source File: Status.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
@JsonIgnore
public List<AppStatus> getAppStatusList() {
	try {
		ObjectMapper mapper = new ObjectMapper();
		mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
		SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
		resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
		module.setAbstractTypes(resolver);
		mapper.registerModule(module);
		TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
		};
		if (this.platformStatus != null) {
			return mapper.readValue(this.platformStatus, typeRef);
		}
		return new ArrayList<AppStatus>();
	}
	catch (Exception e) {
		throw new IllegalArgumentException("Could not parse Skipper Platfrom Status JSON:" + platformStatus, e);
	}
}
 
Example #8
Source File: RuntimeAppsController.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
protected AppStatusResource instantiateResource(AppStatus entity) {
	AppStatusResource resource = new AppStatusResource(entity.getDeploymentId(), entity.getState().name());
	List<AppInstanceStatusResource> instanceStatusResources = new ArrayList<>();
	InstanceAssembler instanceAssembler = new InstanceAssembler(entity);
	List<AppInstanceStatus> instanceStatuses = new ArrayList<>(entity.getInstances().values());
	Collections.sort(instanceStatuses, INSTANCE_SORTER);
	for (AppInstanceStatus appInstanceStatus : instanceStatuses) {
		instanceStatusResources.add(instanceAssembler.toResource(appInstanceStatus));
	}
	resource.setInstances(new Resources<>(instanceStatusResources));
	return resource;
}
 
Example #9
Source File: ReleaseControllerTests.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Test
public void testMutableAttributesAppInstanceStatus() {
	// Test AppStatus with general State set
	AppStatus appStatusWithGeneralState = AppStatus.of("id666").generalState(DeploymentState.deployed).build();
	AppStatus appStatusCopy = DefaultReleaseManager.copyStatus(appStatusWithGeneralState);

	assertThat(appStatusCopy.getState()).isNotNull();
	assertThat(appStatusCopy.getState()).isEqualTo(appStatusWithGeneralState.getState());

	assertThat(appStatusWithGeneralState.getInstances().size()).isEqualTo(0);
	assertThat(appStatusCopy.getInstances().size()).isEqualTo(0);

	// Test AppStatus with instances
	AppStatus appStatusWithInstances = AppStatus.of("id666").generalState(null)
			.with(new AppInstanceStatus() {
				@Override
				public String getId() {
					return "instance666";
				}

				@Override
				public DeploymentState getState() {
					return DeploymentState.deployed;
				}

				@Override
				public Map<String, String> getAttributes() {
					return Collections.singletonMap("key1", "value1");
				}
			}).build();

	appStatusCopy = DefaultReleaseManager.copyStatus(appStatusWithInstances);
	appStatusCopy.getInstances().get("instance666").getAttributes().put("key2", "value2");

	assertThat(appStatusWithInstances.getInstances().get("instance666").getAttributes().size()).isEqualTo(1);
	assertThat(appStatusCopy.getInstances().get("instance666").getAttributes().size()).isEqualTo(2);
	assertThat(appStatusCopy.getInstances().get("instance666").getAttributes().get("key2")).isEqualTo("value2");

}
 
Example #10
Source File: RuntimeAppsController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
protected AppStatusResource instantiateModel(AppStatus entity) {
	AppStatusResource resource = new AppStatusResource(entity.getDeploymentId(),
			ControllerUtils.mapState(entity.getState()).getKey());
	List<AppInstanceStatusResource> instanceStatusResources = new ArrayList<>();
	RuntimeAppInstanceController.InstanceAssembler instanceAssembler = new RuntimeAppInstanceController.InstanceAssembler(
			entity);
	List<AppInstanceStatus> instanceStatuses = new ArrayList<>(entity.getInstances().values());
	Collections.sort(instanceStatuses, INSTANCE_SORTER);
	for (AppInstanceStatus appInstanceStatus : instanceStatuses) {
		instanceStatusResources.add(instanceAssembler.toModel(appInstanceStatus));
	}
	resource.setInstances(new CollectionModel<>(instanceStatusResources));
	return resource;
}
 
Example #11
Source File: RuntimeAppInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/{instanceId}")
public AppInstanceStatusResource display(@PathVariable String appId, @PathVariable String instanceId) {
	AppStatus status = streamDeployer.getAppStatus(appId);
	if (status.getState().equals(DeploymentState.unknown)) {
		throw new NoSuchAppException(appId);
	}
	AppInstanceStatus appInstanceStatus = status.getInstances().get(instanceId);
	if (appInstanceStatus == null) {
		throw new NoSuchAppInstanceException(instanceId);
	}
	return new RuntimeAppInstanceController.InstanceAssembler(status).toModel(appInstanceStatus);
}
 
Example #12
Source File: RuntimeAppInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@RequestMapping
public PagedModel<AppInstanceStatusResource> list(Pageable pageable, @PathVariable String appId,
		PagedResourcesAssembler<AppInstanceStatus> assembler) {
	AppStatus status = streamDeployer.getAppStatus(appId);
	if (status.getState().equals(DeploymentState.unknown)) {
		throw new NoSuchAppException(appId);
	}
	List<AppInstanceStatus> appInstanceStatuses = new ArrayList<>(status.getInstances().values());
	Collections.sort(appInstanceStatuses, RuntimeAppInstanceController.INSTANCE_SORTER);
	return assembler.toModel(new PageImpl<>(appInstanceStatuses, pageable,
			appInstanceStatuses.size()), new RuntimeAppInstanceController.InstanceAssembler(status));
}
 
Example #13
Source File: ReleaseServiceTests.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Test
public void testStatus() throws InterruptedException, IOException {
	String releaseName = "logrelease";
	InstallRequest installRequest = new InstallRequest();
	installRequest.setInstallProperties(createInstallProperties(releaseName));
	PackageIdentifier packageIdentifier = new PackageIdentifier();
	packageIdentifier.setPackageName("log");
	packageIdentifier.setPackageVersion("1.0.0");
	installRequest.setPackageIdentifier(packageIdentifier);
	Release release = install(installRequest);
	installRequest.setPackageIdentifier(packageIdentifier);
	assertThat(release).isNotNull();
	assertThat(release.getPkg().getMetadata().getVersion()).isEqualTo("1.0.0");

	Info info = this.releaseService.status(releaseName);
	assertThat(info).isNotNull();

	List<AppStatus> appStatuses = info.getStatus().getAppStatusList();
	assertThat(appStatuses).isNotNull();
	assertThat(appStatuses.size()).isEqualTo(1);

	AppStatus appStatus = appStatuses.iterator().next();
	assertThat(appStatus.getDeploymentId()).isEqualTo("logrelease.log-v1");
	assertThat(appStatus.getState()).isEqualTo(DeploymentState.deployed);
	assertThat(appStatus.getInstances().size()).isEqualTo(1);

	AppInstanceStatus appInstanceState = appStatus.getInstances().values().iterator().next();
	assertThat(appInstanceState.getAttributes().get(DefaultReleaseManager.SKIPPER_RELEASE_NAME_ATTRIBUTE)).isEqualTo("logrelease");
	assertThat(appInstanceState.getAttributes().get(DefaultReleaseManager.SKIPPER_RELEASE_VERSION_ATTRIBUTE)).isEqualTo("1");
	assertThat(appInstanceState.getAttributes().get(DefaultReleaseManager.SKIPPER_APPLICATION_NAME_ATTRIBUTE)).isEqualTo("log");
}
 
Example #14
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 #15
Source File: RuntimeAppsController.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/{instanceId}")
public AppInstanceStatusResource display(@PathVariable String appId, @PathVariable String instanceId) {
	AppStatus status = appDeployer.status(appId);
	if (status != null) {
		AppInstanceStatus appInstanceStatus = status.getInstances().get(instanceId);
		if (appInstanceStatus == null) {
			throw new ResourceNotFoundException();
		}
		return new InstanceAssembler(status).toResource(appInstanceStatus);
	}
	throw new ResourceNotFoundException();
}
 
Example #16
Source File: RuntimeAppsController.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@RequestMapping
public PagedResources<AppInstanceStatusResource> list(@PathVariable String appId,
		PagedResourcesAssembler<AppInstanceStatus> assembler) {
	AppStatus status = appDeployer.status(appId);
	if (status != null) {
		List<AppInstanceStatus> appInstanceStatuses = new ArrayList<>(status.getInstances().values());
		Collections.sort(appInstanceStatuses, INSTANCE_SORTER);
		return assembler.toResource(new PageImpl<>(appInstanceStatuses), new InstanceAssembler(status));
	}
	throw new ResourceNotFoundException();
}
 
Example #17
Source File: DefaultReleaseManager.java    From spring-cloud-skipper with Apache License 2.0 4 votes vote down vote up
public Release status(Release release) {
	if (release.getInfo().getStatus().getStatusCode().equals(StatusCode.DELETED)) {
		return release;
	}
	AppDeployer appDeployer = this.deployerRepository.findByNameRequired(release.getPlatformName())
			.getAppDeployer();

	AppDeployerData appDeployerData = this.appDeployerDataRepository
			.findByReleaseNameAndReleaseVersion(release.getName(), release.getVersion());
	if (appDeployerData == null) {
		logger.warn(String.format("Could not get status for release %s-v%s.  No app deployer data found.",
				release.getName(), release.getVersion()));
		return release;
	}
	List<String> deploymentIds = appDeployerData.getDeploymentIds();
	logger.debug("Getting status for {} using deploymentIds {}", release,
			StringUtils.collectionToCommaDelimitedString(deploymentIds));

	if (!deploymentIds.isEmpty()) {
		// mainly track deployed and unknown statuses. for any other
		// combination, get more details from instances.
		int deployedCount = 0;
		int unknownCount = 0;
		Map<String, DeploymentState> deploymentStateMap = new HashMap<>();
		logger.debug("Used appDeployer {}", appDeployer);
		if (appDeployer instanceof MultiStateAppDeployer) {
			MultiStateAppDeployer multiStateAppDeployer = (MultiStateAppDeployer) appDeployer;
			logger.debug("Calling multiStateAppDeployer states {}", deploymentIds);
			deploymentStateMap = multiStateAppDeployer.states(StringUtils.toStringArray(deploymentIds));
			logger.debug("Calling multiStateAppDeployer states end {}", deploymentIds);
		}
		List<AppStatus> appStatusList = new ArrayList<>();
		// Key = app name, value = deploymentId
		Map<String, String> appNameDeploymentIdMap = appDeployerData.getDeploymentDataAsMap();

		for (Map.Entry<String, String> nameDeploymentId : appNameDeploymentIdMap.entrySet()) {
			String appName = nameDeploymentId.getKey();
			String deploymentId = nameDeploymentId.getValue();
			// Copy the status to allow instance attribute mutation.
			logger.debug("Calling appDeployer status {}", deploymentId);
			AppStatus appStatus = copyStatus(appDeployer.status(deploymentId));
			logger.debug("Calling appDeployer status end {} {}", deploymentId, appStatus.getState());
			Collection<AppInstanceStatus> instanceStatuses = appStatus.getInstances().values();
			for (AppInstanceStatus instanceStatus : instanceStatuses) {
				instanceStatus.getAttributes().put(SKIPPER_APPLICATION_NAME_ATTRIBUTE, appName);
				instanceStatus.getAttributes().put(SKIPPER_RELEASE_NAME_ATTRIBUTE, release.getName());
				instanceStatus.getAttributes().put(SKIPPER_RELEASE_VERSION_ATTRIBUTE, "" + release.getVersion());
			}
			if (appStatus.getState().equals(DeploymentState.failed) ||
					appStatus.getState().equals(DeploymentState.error)) {
				// check if we have 'early' status computed via multiStateAppDeployer
				if (deploymentStateMap.containsKey(deploymentId)) {
					appStatus = AppStatus.of(deploymentId).generalState(deploymentStateMap.get(deploymentId))
							.build();
					logger.debug("Set from deploymentStateMap {} {}", deploymentId, appStatus.getState());
				}
			}
			logger.debug("App Deployer for deploymentId {} gives status {}", deploymentId, appStatus);
			appStatusList.add(appStatus);

			switch (appStatus.getState()) {
			case deployed:
				deployedCount++;
				break;
			case unknown:
				unknownCount++;
				break;
			case deploying:
			case undeployed:
			case partial:
			case failed:
			case error:
			default:
				break;
			}
		}
		release.getInfo().getStatus().setPlatformStatusAsAppStatusList(appStatusList);
	}
	return release;
}
 
Example #18
Source File: LocalAppDeployerEnvironmentIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 4 votes vote down vote up
@Test
public void testEnvVariablesInheritedViaEnvEndpointNoSaj() {
	if (useDocker) {
		// would not expect to be able to check anything on docker
		return;
	}
	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));

	Map<String, AppInstanceStatus> instances = appDeployer().status(deploymentId).getInstances();
	String url = null;
	if (instances.size() == 1) {
		url = instances.entrySet().iterator().next().getValue().getAttributes().get("url");
	}
	String env = null;
	if (url != null) {
		RestTemplate template = new RestTemplate();
		env = template.getForObject(url + "/actuator/env", String.class);
	}

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

	timeout = undeploymentTimeout();
	appDeployer().undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	assertThat(url, notNullValue());
	if (LocalDeployerUtils.isWindows()) {
		// windows is weird, we may still get Path or PATH
		assertThat(env, anyOf(containsString("\"Path\""), containsString("\"PATH\"")));
	}
	else {
		assertThat(env, containsString("\"PATH\""));
		// we're not using SAJ so it's i.e.
		// INSTANCE_INDEX not instance.index
		assertThat(env, containsString("\"INSTANCE_INDEX\""));
		assertThat(env, containsString("\"SPRING_APPLICATION_INDEX\""));
		assertThat(env, containsString("\"SPRING_CLOUD_APPLICATION_GUID\""));
	}
}
 
Example #19
Source File: LocalAppDeployerIntegrationTests.java    From spring-cloud-deployer-local with Apache License 2.0 4 votes vote down vote up
@Test
public void testEnvVariablesInheritedViaEnvEndpoint() {
	if (useDocker) {
		// would not expect to be able to check anything on docker
		return;
	}
	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));

	Map<String, AppInstanceStatus> instances = appDeployer().status(deploymentId).getInstances();
	String url = null;
	if (instances.size() == 1) {
		url = instances.entrySet().iterator().next().getValue().getAttributes().get("url");
	}
	String env = null;
	if (url != null) {
		RestTemplate template = new RestTemplate();
		env = template.getForObject(url + "/actuator/env", String.class);
	}

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

	timeout = undeploymentTimeout();
	appDeployer().undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	assertThat(url, notNullValue());
	if (LocalDeployerUtils.isWindows()) {
		// windows is weird, we may still get Path or PATH
		assertThat(env, anyOf(containsString("\"Path\""), containsString("\"PATH\"")));
	}
	else {
		assertThat(env, containsString("\"PATH\""));
		// we're defaulting to SAJ so it's i.e.
		// instance.index not INSTANCE_INDEX
		assertThat(env, containsString("\"instance.index\""));
		assertThat(env, containsString("\"spring.application.index\""));
		assertThat(env, containsString("\"spring.cloud.application.guid\""));
		assertThat(env, containsString("\"spring.cloud.stream.instanceIndex\""));
	}
}
 
Example #20
Source File: RuntimeAppsController.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
@Override
protected AppInstanceStatusResource instantiateResource(AppInstanceStatus entity) {
	return new AppInstanceStatusResource(entity.getId(), entity.getState().name(), entity.getAttributes());
}
 
Example #21
Source File: RuntimeAppInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(AppInstanceStatus i1, AppInstanceStatus i2) {
	return i1.getId().compareTo(i2.getId());
}
 
Example #22
Source File: RuntimeAppsController.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
@Override
public AppInstanceStatusResource toResource(AppInstanceStatus entity) {
	return createResourceWithId("/" + entity.getId(), entity, owningApp.getDeploymentId().toString());
}
 
Example #23
Source File: RuntimeAppInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public AppInstanceStatusResource toModel(AppInstanceStatus entity) {
	return createModelWithId("/" + entity.getId(), entity, owningApp.getDeploymentId());
}
 
Example #24
Source File: RuntimeAppInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
protected AppInstanceStatusResource instantiateModel(AppInstanceStatus entity) {
	return new AppInstanceStatusResource(entity.getId(), ControllerUtils.mapState(entity.getState()).getKey(),
			entity.getAttributes());
}
 
Example #25
Source File: RuntimeStreamsController.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
private String getAppInstanceGuid(AppInstanceStatus instance) {
	return instance.getAttributes().containsKey(StreamRuntimePropertyKeys.ATTRIBUTE_GUID) ?
			instance.getAttributes().get(StreamRuntimePropertyKeys.ATTRIBUTE_GUID) : instance.getId();
}
 
Example #26
Source File: RuntimeAppsController.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(AppInstanceStatus i1, AppInstanceStatus i2) {
	return i1.getId().compareTo(i2.getId());
}
 
Example #27
Source File: AbstractAppDeployerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 2 votes vote down vote up
protected void doTestScale(Boolean indexed) {
	final int DESIRED_COUNT = 3;

	Map<String, String> deploymentProperties =
		Collections.singletonMap(AppDeployer.INDEXED_PROPERTY_KEY, indexed.toString());

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

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

	String deploymentId = appDeployer().deploy(request);

	Timeout timeout = deploymentTimeout();

	assertThat(deploymentId, eventually(hasStatusThat(
		Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	log.info("Scaling {} to {} instances...", request.getDefinition().getName(), DESIRED_COUNT);

	appDeployer().scale(new AppScaleRequest(deploymentId, DESIRED_COUNT));

	assertThat(deploymentId, eventually(hasStatusThat(
		Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	assertThat(deploymentId, eventually(appInstanceCount(is(DESIRED_COUNT)), timeout.maxAttempts, timeout.pause));

	List<DeploymentState> individualStates = new ArrayList<>();
	for (AppInstanceStatus status : appDeployer().status(deploymentId).getInstances().values()) {
		individualStates.add(status.getState());
	}

	assertThat(individualStates, everyItem(is(deployed)));

	log.info("Scaling {} from {} to 1 instance...", request.getDefinition().getName(), DESIRED_COUNT);

	appDeployer().scale(new AppScaleRequest(deploymentId, 1));

	assertThat(deploymentId, eventually(hasStatusThat(
		Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	assertThat(deploymentId, eventually(appInstanceCount(is(1)), 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));
}