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

The following examples show how to use org.springframework.cloud.deployer.spi.app.DeploymentState. 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: SkipperStreamDeployerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testStateOfUndefinedUndeployedStream() {

	AppRegistryService appRegistryService = mock(AppRegistryService.class);
	SkipperClient skipperClient = mock(SkipperClient.class);
	StreamDefinitionRepository streamDefinitionRepository = mock(StreamDefinitionRepository.class);

	SkipperStreamDeployer skipperStreamDeployer = new SkipperStreamDeployer(skipperClient,
			streamDefinitionRepository, appRegistryService, mock(ForkJoinPool.class), new DefaultStreamDefinitionService());

	StreamDefinition streamDefinition = new StreamDefinition("foo", "foo|bar");

	// Stream is defined
	when(streamDefinitionRepository.findById(streamDefinition.getName())).thenReturn(Optional.ofNullable(null));

	// Stream is undeployed
	when(skipperClient.status(eq(streamDefinition.getName()))).thenThrow(new ReleaseNotFoundException(""));

	Map<StreamDefinition, DeploymentState> state = skipperStreamDeployer.streamsStates(Arrays.asList(streamDefinition));

	assertThat(state).isNotNull();
	assertThat(state.size()).isEqualTo(1);
	assertThat(state.get(streamDefinition).equals(DeploymentState.undeployed));
}
 
Example #2
Source File: SkipperStreamDeployer.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private DeploymentState getStreamDeploymentState(String streamName) {
	DeploymentState state = null;
	try {
		Info info = this.skipperClient.status(streamName);
		if (info.getStatus().getPlatformStatus() == null) {
			return getDeploymentStateFromStatusInfo(info);
		}
		List<AppStatus> appStatusList = deserializeAppStatus(info.getStatus().getPlatformStatus());
		Set<DeploymentState> deploymentStateList = appStatusList.stream().map(AppStatus::getState)
				.collect(Collectors.toSet());
		state = StreamDeployerUtil.aggregateState(deploymentStateList);
	}
	catch (ReleaseNotFoundException e) {
		// a defined stream but unknown to skipper is considered to be in an undeployed state
		if (streamDefinitionExists(streamName)) {
			state = DeploymentState.undeployed;
		}
	}
	return state;
}
 
Example #3
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 #4
Source File: SkipperStreamDeployer.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public Map<StreamDefinition, DeploymentState> streamsStates(List<StreamDefinition> streamDefinitions) {
	Map<String, StreamDefinition> nameToDefinition = new HashMap<>();
	Map<StreamDefinition, DeploymentState> states = new HashMap<>();
	List<String> streamNamesList = new ArrayList<>();
	streamDefinitions.stream().forEach(sd -> {
		streamNamesList.add(sd.getName());
		nameToDefinition.put(sd.getName(), sd);
	});
	String[] streamNames = streamNamesList.toArray(new String[0]);
	Map<String, Map<String, DeploymentState>> statuses = this.skipperClient.states(streamNames);
	for (Map.Entry<String, StreamDefinition> entry: nameToDefinition.entrySet()) {
		String streamName = entry.getKey();
		if (statuses != null && statuses.containsKey(streamName) && !statuses.get(streamName).isEmpty()) {
			states.put(nameToDefinition.get(streamName),
					StreamDeployerUtil.aggregateState(new HashSet<>(statuses.get(streamName).values())));
		}
		else {
			states.put(nameToDefinition.get(streamName), DeploymentState.undeployed);
		}
	}
	return states;
}
 
Example #5
Source File: KubernetesAppInstanceStatus.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
/**
 * Maps Kubernetes phases/states onto Spring Cloud Deployer states
 */
private DeploymentState mapState() {
	logger.debug(String.format("%s - Phase [ %s ]", pod.getMetadata().getName(), pod.getStatus().getPhase()));
	logger.debug(String.format("%s - ContainerStatus [ %s ]", pod.getMetadata().getName(), containerStatus));
	switch (pod.getStatus().getPhase()) {

	case "Pending":
		return DeploymentState.deploying;

	// We only report a module as running if the container is also ready to service requests.
	// We also implement the Readiness check as part of the container to ensure ready means
	// that the module is up and running and not only that the JVM has been created and the
	// Spring module is still starting up
	case "Running":
		// we assume we only have one container
		return runningPhaseDeploymentStateResolver.resolve(containerStatus);
	case "Failed":
		return DeploymentState.failed;

	case "Unknown":
		return DeploymentState.unknown;

	default:
		return DeploymentState.unknown;
	}
}
 
Example #6
Source File: StreamControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuplicateDeploy() throws Exception {
	repository.save(new StreamDefinition("myStream", "time | log"));

	mockMvc.perform(post("/streams/deployments/myStream")
			.accept(MediaType.APPLICATION_JSON)).andDo(print())
			.andExpect(status().isCreated());

	ArgumentCaptor<UploadRequest> uploadRequestCaptor = ArgumentCaptor.forClass(UploadRequest.class);
	verify(skipperClient, times(1)).upload(uploadRequestCaptor.capture());

	Package pkg = SkipperPackageUtils.loadPackageFromBytes(uploadRequestCaptor);
	assertNotNull(findChildPackageByName(pkg, "log"));
	assertNotNull(findChildPackageByName(pkg, "time"));

	streamStatusInfo.getStatus().setPlatformStatusAsAppStatusList(Arrays.asList(
			AppStatus.of("myStream.time-v1").generalState(DeploymentState.deploying).build(),
			AppStatus.of("myStream.log-v1").generalState(DeploymentState.deployed).build()));

	// Attempt to deploy already deployed stream
	mockMvc.perform(post("/streams/deployments/myStream")
			.accept(MediaType.APPLICATION_JSON)).andDo(print())
			.andExpect(status().isConflict());
}
 
Example #7
Source File: StreamDeploymentController.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * Request deployment of an existing stream definition.
 * @param name the name of an existing stream definition (required)
 * @return The stream deployment
 */
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.CREATED)
public StreamDeploymentResource info(@PathVariable("name") String name) {
	StreamDefinition streamDefinition = this.repository.findById(name)
			.orElseThrow(() -> new NoSuchStreamDefinitionException(name));
	StreamDeployment streamDeployment = this.streamService.info(name);
	Map<StreamDefinition, DeploymentState> streamDeploymentStates = this.streamService
			.state(Arrays.asList(streamDefinition));
	DeploymentState deploymentState = streamDeploymentStates.get(streamDefinition);
	String status = "";
	if (deploymentState != null) {
		final DeploymentStateResource deploymentStateResource = ControllerUtils.mapState(deploymentState);
		status = deploymentStateResource.getKey();
	}
	return new Assembler(streamDefinition.getDslText(), streamDefinition.getDescription(), status)
			.toModel(streamDeployment);
}
 
Example #8
Source File: LocalAppDeployer.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
@Override
public DeploymentState getState() {
	Integer exit = getProcessExitValue(process);
	// TODO: consider using exit code mapper concept from batch
	if (exit != null) {
		return DeploymentState.failed;
	}
	if (port < 1) {
		// Support case where user passed in zero or negative port indicating fully random
		// chosen by OS. In this case we simply return deployed if process is up.
		// Also we can't even try http check as we would not know port to connect to.
		return DeploymentState.deployed;
	}
	try {
		HttpURLConnection urlConnection = (HttpURLConnection) baseUrl.openConnection();
		urlConnection.setConnectTimeout(100);
		urlConnection.connect();
		urlConnection.disconnect();
		return DeploymentState.deployed;
	}
	catch (IOException e) {
		return DeploymentState.deploying;
	}
}
 
Example #9
Source File: PredicateRunningPhaseDeploymentStateResolver.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
public DeploymentState resolve(ContainerStatus containerStatus) {

		Stream<Predicate<ContainerStatus>> conditionsStream = Stream.of(conditions);
		Boolean allConditionsMet = conditionsStream.reduce((x, y) -> x.and(y)).get().test(containerStatus);

		if (allConditionsMet) {
			logger.debug("deployment state is " + resolvedState.name());
			return this.resolvedState;
		}
		else {
			Stream<ContainerStatusCondition> report = Stream.of(conditions);
			report.filter(c -> {
				boolean result= false;
				try {
					result = c.test(containerStatus);
				}
				catch (NullPointerException e) {

				}
				return !result;

			}).forEach(c -> logger.debug(c + " is not satisfied"));

		}
		return null;
	}
 
Example #10
Source File: SkipperStreamDeployerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testStateOfDefinedUndeployedStream() {

	AppRegistryService appRegistryService = mock(AppRegistryService.class);
	SkipperClient skipperClient = mock(SkipperClient.class);
	StreamDefinitionRepository streamDefinitionRepository = mock(StreamDefinitionRepository.class);

	SkipperStreamDeployer skipperStreamDeployer = new SkipperStreamDeployer(skipperClient,
			streamDefinitionRepository, appRegistryService, mock(ForkJoinPool.class), new DefaultStreamDefinitionService());

	StreamDefinition streamDefinition = new StreamDefinition("foo", "foo|bar");

	// Stream is defined
	when(streamDefinitionRepository.findById(streamDefinition.getName())).thenReturn(Optional.of(streamDefinition));

	// Stream is undeployed
	when(skipperClient.status(eq(streamDefinition.getName()))).thenThrow(new ReleaseNotFoundException(""));

	Map<StreamDefinition, DeploymentState> state = skipperStreamDeployer.streamsStates(Arrays.asList(streamDefinition));

	assertThat(state).isNotNull();
	assertThat(state.size()).isEqualTo(1);
	assertThat(state).containsKeys(streamDefinition);
	assertThat(state.get(streamDefinition)).isEqualTo(DeploymentState.undeployed);
}
 
Example #11
Source File: CloudFoundryAppInstanceStatus.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Override
public DeploymentState getState() {
	if (instanceDetail == null) {
		return DeploymentState.failed;
	}
	switch (instanceDetail.getState()) {
		case "STARTING":
		case "DOWN":
			return DeploymentState.deploying;
		case "CRASHED":
			return DeploymentState.failed;
		// Seems the client incorrectly reports apps as FLAPPING when they are
		// obviously fine. Mapping as RUNNING for now
		case "FLAPPING":
		case "RUNNING":
			return DeploymentState.deployed;
		case "UNKNOWN":
			return DeploymentState.unknown;
		default:
			throw new IllegalStateException("Unsupported CF state: " + instanceDetail.getState());
	}
}
 
Example #12
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfUnknownApplicationIsUnknown() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("UNKNOWN").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.unknown));
}
 
Example #13
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfStartingApplicationIsDeploying() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("STARTING").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deploying));
}
 
Example #14
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 #15
Source File: StreamDefinitionController.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public StreamDefinitionResource instantiateModel(StreamDefinition streamDefinition) {
	final StreamDefinition originalStreamDefinition = new StreamDefinition(streamDefinition.getName(), streamDefinition.getOriginalDslText());
	final StreamDefinitionResource resource = new StreamDefinitionResource(streamDefinition.getName(),
			StreamDefinitionServiceUtils.sanitizeStreamDefinition(streamDefinition.getName(),
					streamDefinitionService.getAppDefinitions(streamDefinition)),
			StreamDefinitionServiceUtils.sanitizeStreamDefinition(originalStreamDefinition.getName(),
					streamDefinitionService.getAppDefinitions(originalStreamDefinition)), originalStreamDefinition.getDescription());
	DeploymentState deploymentState = streamDeploymentStates.get(streamDefinition);
	if (deploymentState != null) {
		final DeploymentStateResource deploymentStateResource = ControllerUtils
				.mapState(deploymentState);
		resource.setStatus(deploymentStateResource.getKey());
		resource.setStatusDescription(deploymentStateResource.getDescription());
	}
	return resource;
}
 
Example #16
Source File: ReleaseService.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
/**
 * Return the current statuses of the releases.
 *
 * @param releaseNames array of release names
 * @return The latest state of the release as stored in the database
 */
@Transactional
public Mono<Map<String, Map<String, DeploymentState>>> states(String[] releaseNames) {
	return Flux.fromArray(releaseNames)
		.flatMap(releaseName -> Mono.justOrEmpty(this.releaseRepository.findTopByNameOrderByVersionDesc(releaseName)))
		.collectMultimap(release -> {
			String kind = ManifestUtils.resolveKind(release.getManifest().getData());
			return this.releaseManagerFactory.getReleaseManager(kind);
		}, release -> release)
		.flatMap(m -> {
			return Flux.fromIterable(m.entrySet())
				.flatMap(e -> e.getKey().deploymentState(new ArrayList<>(e.getValue())))
				.reduce((to, from) -> {
					to.putAll(from);
					return to;
				});
		});
}
 
Example #17
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfRunningApplicationIsDeployed() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("RUNNING").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deployed));
	assertThat(status.getInstances().get("test-application-0").toString(),
		equalTo("CloudFoundryAppInstanceStatus[test-application-0 : deployed]"));
	assertThat(status.getInstances().get("test-application-0").getAttributes(),
		equalTo(Collections.singletonMap("guid", "test-application:0")));
}
 
Example #18
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfFlappingApplicationIsDeployed() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("FLAPPING").index("1").build())
		.build()));

	AppStatus status = deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deployed));
}
 
Example #19
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfDownApplicationIsDeploying() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("DOWN").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deploying));
}
 
Example #20
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfCrashedApplicationIsFailed() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("CRASHED").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.failed));
}
 
Example #21
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 #22
Source File: AbstractAssertReleaseDeployedTest.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
protected boolean allAppsDeployed(List<AppStatus> appStatusList) {
	boolean allDeployed = true;
	for (AppStatus appStatus : appStatusList) {
		if (appStatus.getState() != DeploymentState.deployed) {
			allDeployed = false;
			break;
		}
	}
	return allDeployed;
}
 
Example #23
Source File: PredicateRunningPhaseDeploymentStateResolver.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
ContainerReady(KubernetesDeployerProperties properties) {
	super(properties, DeploymentState.deployed, new ContainerStatusCondition("container ready") {
		@Override
		public boolean test(ContainerStatus containerStatus) {
			return containerStatus.getReady();
		}
	});
}
 
Example #24
Source File: KubernetesAppDeployer.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public String deploy(AppDeploymentRequest request) {
	String appId = createDeploymentId(request);
	logger.debug(String.format("Deploying app: %s", appId));

	try {
		AppStatus status = status(appId);

		if (!status.getState().equals(DeploymentState.unknown)) {
			throw new IllegalStateException(String.format("App '%s' is already deployed", appId));
		}

		String indexedProperty = request.getDeploymentProperties().get(INDEXED_PROPERTY_KEY);
		boolean indexed = (indexedProperty != null) ? Boolean.valueOf(indexedProperty) : false;
		logPossibleDownloadResourceMessage(request.getResource());

		createService(request);
		if (indexed) {
			createStatefulSet(request);
		}
		else {
			createDeployment(request);
		}
		return appId;
	}
	catch (RuntimeException e) {
		logger.error(e.getMessage(), e);
		throw e;
	}
}
 
Example #25
Source File: CompositeDeploymentStateResolver.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public DeploymentState resolve(ContainerStatus containerStatus) {
	for (RunningPhaseDeploymentStateResolver resolver: delegates) {
		DeploymentState deploymentState = resolver.resolve(containerStatus);
		if (deploymentState != null) {
			return deploymentState;
		}
	}
	return null;
}
 
Example #26
Source File: YarnAppDeployer.java    From spring-cloud-deployer-yarn with Apache License 2.0 5 votes vote down vote up
public InstanceStatus(String id, boolean deployed, Map<String, String> attributes) {
	this.id = id;
	this.state = deployed ? DeploymentState.deployed : DeploymentState.unknown;
	if (attributes != null) {
		this.attributes.putAll(attributes);
	}
}
 
Example #27
Source File: StreamDeployerUtil.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Aggregate the set of app states into a single state for a stream.
 *
 * @param states set of states for apps of a stream
 * @return the stream state based on app states
 */
public static DeploymentState aggregateState(Set<DeploymentState> states) {
	if (states.size() == 1) {
		DeploymentState state = states.iterator().next();
		logger.debug("aggregateState: Deployment State Set Size = 1.  Deployment State " + state);
		// a stream which is known to the stream definition streamDefinitionRepository
		// but unknown to deployers is undeployed
		if (state == null || state == DeploymentState.unknown) {
			logger.debug("aggregateState: Returning " + DeploymentState.undeployed);
			return DeploymentState.undeployed;
		}
		else {
			logger.debug("aggregateState: Returning " + state);
			return state;
		}
	}
	DeploymentState result = DeploymentState.partial;
	if (states.isEmpty() || states.contains(DeploymentState.error)) {
		logger.debug("aggregateState: Returning " + DeploymentState.error);
		result = DeploymentState.error;
	}
	else if (states.contains(DeploymentState.deployed) && states.contains(DeploymentState.failed)) {
		logger.debug("aggregateState: Returning " + DeploymentState.partial);
		result = DeploymentState.partial;
	}
	else if (states.contains(DeploymentState.failed)) {
		logger.debug("aggregateState: Returning " + DeploymentState.failed);
		result = DeploymentState.failed;
	}
	else if (states.contains(DeploymentState.deploying)) {
		logger.debug("aggregateState: Returning " + DeploymentState.deploying);
		result = DeploymentState.deploying;
	}

	logger.debug("aggregateState: Returning " + DeploymentState.partial);
	return result;
}
 
Example #28
Source File: DefaultSkipperClient.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Map<String, DeploymentState>> states(String... releaseNames) {
	ParameterizedTypeReference<Map<String, Map<String, DeploymentState>>> typeReference =
			new ParameterizedTypeReference<Map<String, Map<String, DeploymentState>>>() { };

	UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUri + "/release/states");
	builder.queryParam("names", StringUtils.arrayToCommaDelimitedString(releaseNames));

	ResponseEntity<Map<String, Map<String, DeploymentState>>> responseEntity =
			restTemplate.exchange(builder.toUriString(),
					HttpMethod.GET,
					null,
					typeReference);
	return responseEntity.getBody();
}
 
Example #29
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 #30
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private DeploymentState mapShallowAppState(ApplicationSummary applicationSummary) {
	if (applicationSummary.getRunningInstances().equals(applicationSummary.getInstances())) {
		return DeploymentState.deployed;
	}
	else if (applicationSummary.getInstances() > 0) {
		return DeploymentState.partial;
	} else {
		return DeploymentState.undeployed;
	}
}