org.cloudfoundry.operations.applications.ApplicationManifest Java Examples

The following examples show how to use org.cloudfoundry.operations.applications.ApplicationManifest. 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: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
private Mono<Void> pushApplication(String name, AppDeploymentRequest request) {
	if (!pushTaskAppsEnabled()) {
		return Mono.empty();
	}

	return requestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.path(getApplication(request))
			.docker(Docker.builder().image(getDockerImage(request)).build())
			.buildpack(buildpack(request))
			.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
			.disk(diskQuota(request))
			.environmentVariables(getEnvironmentVariables(name, request))
			.healthCheckType(ApplicationHealthCheck.NONE)
			.memory(memory(request))
			.name(name)
			.noRoute(true)
			.services(servicesToBind(request))
			.build())
		.stagingTimeout(this.deploymentProperties.getStagingTimeout())
		.startupTimeout(this.deploymentProperties.getStartupTimeout())
		.build());
}
 
Example #2
Source File: CloudFoundryDeleteStep.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
public Release delete(Release release, AppDeployerData existingAppDeployerData,
		List<String> applicationNamesToDelete) {
	ApplicationManifest applicationManifest = CloudFoundryApplicationManifestUtils.updateApplicationName(release);
	String applicationName = applicationManifest.getName();
	DeleteApplicationRequest deleteApplicationRequest = DeleteApplicationRequest.builder().name(applicationName)
			.build();
	this.platformCloudFoundryOperations.getCloudFoundryOperations(release.getPlatformName()).applications()
			.delete(deleteApplicationRequest)
			.doOnSuccess(v -> logger.info("Successfully undeployed app {}", applicationName))
			.doOnError(e -> logger.error("Failed to undeploy app %s", applicationName)).block();

	Status deletedStatus = new Status();
	deletedStatus.setStatusCode(StatusCode.DELETED);
	release.getInfo().setStatus(deletedStatus);
	release.getInfo().setDescription("Delete complete");
	this.releaseRepository.save(release);
	return release;
}
 
Example #3
Source File: CloudFoundryManifestApplicationDeployer.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
public Release delete(Release release) {
	ApplicationManifest applicationManifest = CloudFoundryApplicationManifestUtils.updateApplicationName(release);
	String applicationName = applicationManifest.getName();
	DeleteApplicationRequest deleteApplicationRequest = DeleteApplicationRequest.builder().name(applicationName)
			.build();
	this.platformCloudFoundryOperations.getCloudFoundryOperations(release.getPlatformName()).applications()
			.delete(deleteApplicationRequest)
			.timeout(DELETE_REQUEST_TIMEOUT)
			.doOnSuccess(v -> logger.info("Successfully undeployed app {}", applicationName))
			.doOnError(e -> logger.error("Failed to undeploy app %s", applicationName))
			.block();
	Status deletedStatus = new Status();
	deletedStatus.setStatusCode(StatusCode.DELETED);
	release.getInfo().setStatus(deletedStatus);
	release.getInfo().setDescription("Delete complete");
	return release;
}
 
Example #4
Source File: CloudFoundryManifestApplicationDeployer.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
public AppStatus status(Release release) {
	logger.info("Checking application status for the release: " + release.getName());
	ApplicationManifest applicationManifest = CloudFoundryApplicationManifestUtils.updateApplicationName(release);
	String applicationName = applicationManifest.getName();
	AppStatus appStatus = null;
	try {
		appStatus = getStatus(applicationName, release.getPlatformName())
				.doOnSuccess(v -> logger.info("Successfully computed status [{}] for {}", v,
						applicationName))
				.doOnError(e -> logger.error(
						String.format("Failed to compute status for %s", applicationName)))
				.block();
	}
	catch (Exception timeoutDueToBlock) {
		logger.error("Caught exception while querying for status of {}", applicationName, timeoutDueToBlock);
		appStatus = createErrorAppStatus(applicationName);
	}
	return appStatus;
}
 
Example #5
Source File: CloudFoundryReleaseAnalyzer.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
/**
 * Analyze the existing release and the replacing release to determine the minimal number
 * of changes that need to be made.
 * @param existingRelease the release that is currently deployed
 * @param replacingRelease the proposed release to be deployed that will replace the
 * existing release.
 * @param isForceUpdate flag to indicate if the update is forced
 * @return an analysis report describing the changes to make, if any.
 */
public ReleaseAnalysisReport analyze(Release existingRelease, Release replacingRelease, boolean isForceUpdate) {
	List<ApplicationManifestDifference> applicationManifestDifferences = new ArrayList<>();
	ApplicationManifest existingApplicationManifest = this.cfManifestApplicationDeployer
			.getCFApplicationManifest(existingRelease);
	ApplicationManifest replacingApplicationManifest = this.cfManifestApplicationDeployer
			.getCFApplicationManifest(replacingRelease);
	if (!existingApplicationManifest.equals(replacingApplicationManifest)) {
		Map<String, String> existingMap = CloudFoundryApplicationManifestUtils
				.getCFManifestMap(existingApplicationManifest);
		Map<String, String> replacingMap = CloudFoundryApplicationManifestUtils
				.getCFManifestMap(replacingApplicationManifest);
		PropertiesDiff emptyPropertiesDiff = PropertiesDiff.builder().build();
		PropertiesDiff propertiesDiff = PropertiesDiff.builder().left(existingMap).right(replacingMap).build();
		ApplicationManifestDifference applicationManifestDifference = new ApplicationManifestDifference(
				existingApplicationManifest.getName(),
				emptyPropertiesDiff, emptyPropertiesDiff, emptyPropertiesDiff, propertiesDiff, emptyPropertiesDiff);
		applicationManifestDifferences.add(applicationManifestDifference);
	}
	return createReleaseAnalysisReport(existingRelease, replacingRelease, applicationManifestDifferences,
			Arrays.asList(existingApplicationManifest.getName()), isForceUpdate);
}
 
Example #6
Source File: CloudFoundryReleaseManager.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
@Override
public LogInfo getLog(Release release, String appName) {
	logger.info("Checking application status for the release: " + release.getName());
	ApplicationManifest applicationManifest = CloudFoundryApplicationManifestUtils.updateApplicationName(release);
	String applicationName = applicationManifest.getName();
	if (StringUtils.hasText(appName)) {
		Assert.isTrue(applicationName.equalsIgnoreCase(appName),
				String.format("Application name % is different from the CF manifest: %", appName, applicationName));
	}
	String logMessage = this.platformCloudFoundryOperations.getCloudFoundryOperations(release.getPlatformName()).applications()
			.logs(LogsRequest.builder().name(applicationName).build())
			.blockFirst(Duration.ofMillis(API_TIMEOUT.toMillis())).getMessage();
	Map<String, String> logMap = new HashMap<>();
	logMap.put(appName, logMessage);
	return new LogInfo(logMap);
}
 
Example #7
Source File: CloudFoundryApplicationManifestUtils.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
public static ApplicationManifest updateApplicationPath(ApplicationManifest cfApplicationManifest, Resource application) {
	ApplicationManifest.Builder applicationManifestBuilder = ApplicationManifest.builder()
			.from(cfApplicationManifest);
	try {
		if (application != null && application instanceof DockerResource) {
			String uriString = application.getURI().toString();
			applicationManifestBuilder.docker(
					Docker.builder().image(uriString.replaceFirst("docker:", "")).build())
					.path(null);
		}
		else {
			applicationManifestBuilder.path(application.getFile().toPath());
		}
	}
	catch (IOException e) {
		throw new SkipperException(e.getMessage());
	}
	return applicationManifestBuilder.build();
}
 
Example #8
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private ArgumentMatcher<PushApplicationManifestRequest> matchesManifest(ApplicationManifest expectedManifest) {
	return new ArgumentMatcher<PushApplicationManifestRequest>() {
		@Override
		public boolean matches(PushApplicationManifestRequest request) {
			if (request.getManifests().size() == EXPECTED_MANIFESTS) {
				return request.getManifests().get(0).equals(expectedManifest);
			}

			return false;
		}

		@Override
		public String toString() {
			return expectedManifest.toString();
		}
	};
}
 
Example #9
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
private void setupFailedPush(Resource resource) throws IOException{
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(
			PushApplicationManifestRequest.builder()
					.manifest(ApplicationManifest.builder()
							.path(resource.getFile().toPath())
							.buildpack(deploymentProperties.getBuildpack())
							.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
							.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
							.environmentVariable("SPRING_APPLICATION_JSON", "{}")
							.healthCheckType(ApplicationHealthCheck.NONE)
							.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
							.name("test-application")
							.noRoute(true)
							.services(Collections.emptySet())
							.build())
					.stagingTimeout(this.deploymentProperties.getStagingTimeout())
					.startupTimeout(this.deploymentProperties.getStartupTimeout())
					.build(), Mono.error(new UnsupportedOperationException()));
}
 
Example #10
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
@Test
void deployAppWithEnvironmentUsingSpringAppJson() {
	deploymentProperties.setUseSpringApplicationJson(true);

	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.property(CloudFoundryDeploymentProperties.JAVA_OPTS_PROPERTY_KEY, "-Xms512m -Xmx1024m")
		.environment("ENV_VAR_1", "value1")
		.environment("ENV_VAR_2", "value2")
		.build();

	StepVerifier.create(appDeployer.deploy(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
		.verifyComplete();

	ApplicationManifest expectedManifest = baseManifestWithSpringAppJson(
		"\"ENV_VAR_2\":\"value2\",\"ENV_VAR_1\":\"value1\"")
		.name(APP_NAME)
		.path(new File(APP_PATH).toPath())
		.environmentVariable("JAVA_OPTS", "-Xms512m -Xmx1024m")
		.build();

	then(operationsApplications).should().pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #11
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
public void setupTaskWithNonExistentApplicationRetrievalFails(Resource resource) throws IOException {
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
			.manifest(ApplicationManifest.builder()
					.path(resource.getFile().toPath())
					.buildpack(deploymentProperties.getBuildpack())
					.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
					.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
					.environmentVariable("SPRING_APPLICATION_JSON", "{}")
					.healthCheckType(ApplicationHealthCheck.NONE)
					.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
					.name("test-application")
					.noRoute(true)
					.services(Collections.emptySet())
					.build())
			.stagingTimeout(this.deploymentProperties.getStagingTimeout())
			.startupTimeout(this.deploymentProperties.getStartupTimeout())
			.build(), Mono.empty());

	givenRequestStopApplication("test-application", Mono.empty());

	givenRequestGetApplication("test-application", Mono.error(new UnsupportedOperationException()));
}
 
Example #12
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
@Test
void deployAppWithPlatformDefaults() {
	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.build();

	StepVerifier.create(appDeployer.deploy(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
		.verifyComplete();

	ApplicationManifest expectedManifest = baseManifestWithSpringAppJson()
		.name(APP_NAME)
		.path(new File(APP_PATH).toPath())
		.build();

	then(operationsApplications).should().pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #13
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<Void> pushApplicationWithServiceParameters(ApplicationManifest manifest,
	AppDeploymentRequest request, String deploymentId) {

	logger.debug("Pushing application manifest with no start");

	return requestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(manifest)
		.noStart(true)
		.build())
		.doOnSuccess(v -> logger.info("Done uploading bits for {}", deploymentId))
		.doOnError(e -> logger.error(String.format("Error creating app %s.  Exception Message %s", deploymentId, e.getMessage())))

		.thenMany(Flux.fromStream(bindParameterizedServiceInstanceRequests(request, deploymentId)))
		.flatMap(bindRequest -> this.operations.services()
			.bind(bindRequest)
			.doOnSuccess(bv -> logger.info("Done binding service {} for {}", bindRequest.getServiceInstanceName(), deploymentId))
			.doOnError(e -> logger.error("Error: {} binding service {}", e.getMessage(), bindRequest.getServiceInstanceName())))

		.then(this.operations.applications()
			.start(StartApplicationRequest.builder()
				.name(deploymentId)
				.stagingTimeout(this.deploymentProperties.getStagingTimeout())
				.startupTimeout(this.deploymentProperties.getStartupTimeout())
				.build())
			.doOnSuccess(sv -> logger.info("Started app for {} ", deploymentId))
			.doOnError(e -> logger.error("Error: {} starting app for {}.", e.getMessage(), deploymentId)))

		.doOnError(e -> logger.error(String.format("Error: %s creating app %s", e.getMessage(), deploymentId), e));
}
 
Example #14
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<Void> pushApplicationWithNoServiceParameters(ApplicationManifest manifest, String deploymentId) {
	logger.debug("Pushing application manifest");
	return requestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(manifest)
		.stagingTimeout(this.deploymentProperties.getStagingTimeout())
		.startupTimeout(this.deploymentProperties.getStartupTimeout())
		.build())
		.doOnSuccess(v -> logger.info("Done uploading bits for {}", deploymentId))
		.doOnError(e -> logger.error("Error: {} creating app {}", e.getMessage(), deploymentId));
}
 
Example #15
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void deployDockerResource() {
	Resource resource = new DockerResource("somecorp/someimage:latest");

	given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

	givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()), Mono.just(
		ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(1)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(0)
			.stack("test-stack")
			.build()));

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.docker(Docker.builder().image("somecorp/someimage:latest").build())
			.disk(1024)
			.environmentVariables(defaultEnvironmentVariables())
			.instances(1)
			.memory(1024)
			.name("test-application-id")
			.service("test-service-2")
			.service("test-service-1")
			.build())
		.stagingTimeout(this.deploymentProperties.getStagingTimeout())
		.startupTimeout(this.deploymentProperties.getStartupTimeout())
		.build(), Mono.empty());

	String deploymentId = this.deployer.deploy(
		new AppDeploymentRequest(new AppDefinition("test-application", Collections.emptyMap()), resource,
			Collections.emptyMap()));

	assertThat(deploymentId, equalTo("test-application-id"));
}
 
Example #16
Source File: CfManifestUtilTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testIfRoutesAreCorrect() {
    final String A_ROUTE = "a-route-1.domain.com";
    CfProperties cfProperties = mock(CfProperties.class);
    when(cfProperties.name()).thenReturn("because-name-cant-be-null");
    when(cfProperties.routes()).thenReturn(Collections.singletonList(A_ROUTE));
    ApplicationManifest manifest = CfManifestUtil.convert(cfProperties);
    assertThat(manifest.getRoutes().size()).isEqualTo(1);
    assertThat(manifest.getRoutes().get(0).getRoute()).isEqualTo(A_ROUTE);
}
 
Example #17
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void setupTaskWithNonExistentApplicationAndRetrievingApplicationSummaryFails(Resource resource) throws IOException {
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(
			PushApplicationManifestRequest.builder()
					.manifest(ApplicationManifest.builder()
							.path(resource.getFile().toPath())
							.buildpack(deploymentProperties.getBuildpack())
							.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
							.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
							.environmentVariable("SPRING_APPLICATION_JSON", "{}")
							.healthCheckType(ApplicationHealthCheck.NONE)
							.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
							.name("test-application")
							.noRoute(true)
							.services(Collections.emptySet())
							.build())
					.stagingTimeout(this.deploymentProperties.getStagingTimeout())
					.startupTimeout(this.deploymentProperties.getStartupTimeout())
					.build(), Mono.empty());

	givenRequestGetApplication("test-application", Mono.just(ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(1)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(1)
			.stack("test-stack")
			.build()));

	givenRequestStopApplication("test-application", Mono.empty());

	givenRequestGetApplicationSummary("test-application-id", Mono.error(new UnsupportedOperationException()));

}
 
Example #18
Source File: CfManifestUtilTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testIfServicesAreCorrect() {
    final String A_SERVICE = "a-service-1";
    CfProperties cfProperties = mock(CfProperties.class);
    when(cfProperties.name()).thenReturn("because-name-cant-be-null");
    when(cfProperties.services()).thenReturn(Collections.singletonList(A_SERVICE));
    ApplicationManifest manifest = CfManifestUtil.convert(cfProperties);
    assertThat(manifest.getServices().size()).isEqualTo(1);
    assertThat(manifest.getServices().get(0)).isEqualTo(A_SERVICE);
}
 
Example #19
Source File: CfManifestUtil.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
public static ApplicationManifest convert(CfProperties properties) {
    ApplicationManifest.Builder builder = ApplicationManifest.builder();
    if(properties.manifestPath() != null)
        builder.from(ApplicationManifestUtils.read(new File(properties.manifestPath()).toPath()).get(0));

    builder
        .buildpack(properties.buildpack())
        .command(properties.command())
        .disk(properties.diskQuota())
        .environmentVariables(properties.environment())
        .instances(properties.instances())
        .memory(properties.memory())
        .name(properties.name())
        .timeout(properties.timeout());
    if(properties.filePath() != null)
        builder.path(new File(properties.filePath()).toPath());
    if(properties.services() != null && !properties.services().isEmpty())
        builder.services(properties.services());
    if(properties.host() != null)
        builder.host(properties.host());
    if(properties.domain() != null)
        builder.domain(properties.domain());
    if(properties.path() != null)
        builder.routePath(properties.path());
    if(properties.healthCheckType() != null)
        builder.healthCheckType(ApplicationHealthCheck.from(properties.healthCheckType()));
    if(properties.routes() != null && !properties.routes().isEmpty())
       builder.routes(properties.routes().stream().map(s -> Route.builder().route(s).build()).collect(Collectors.toList()));
    return builder.build();
}
 
Example #20
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void setupTaskWithNonExistentApplicationAndStoppingApplicationFails(Resource resource) throws IOException {
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(
			PushApplicationManifestRequest.builder()
					.manifest(ApplicationManifest.builder()
							.path(resource.getFile().toPath())
							.buildpack(deploymentProperties.getBuildpack())
							.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
							.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
							.environmentVariable("SPRING_APPLICATION_JSON", "{}")
							.healthCheckType(ApplicationHealthCheck.NONE)
							.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
							.name("test-application")
							.noRoute(true)
							.services(Collections.emptySet())
							.build())
					.stagingTimeout(this.deploymentProperties.getStagingTimeout())
					.startupTimeout(this.deploymentProperties.getStartupTimeout())
					.build(), Mono.empty());

	givenRequestGetApplication("test-application", Mono.just(ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(1)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(1)
			.stack("test-stack")
			.build()));

	givenRequestStopApplication("test-application", Mono.error(new UnsupportedOperationException()));
}
 
Example #21
Source File: CloudFoundryDeployAppStep.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
private void deployCFApp(Release replacingRelease) {
	ApplicationManifest applicationManifest = this.cfManifestApplicationDeployer.getCFApplicationManifest(replacingRelease);
	logger.debug("Manifest = " + ArgumentSanitizer.sanitizeYml(replacingRelease.getManifest().getData()));
	// Deploy the application
	String applicationName = applicationManifest.getName();
	Map<String, String> appDeploymentData = new HashMap<>();
	appDeploymentData.put(applicationManifest.getName(), applicationManifest.toString());
	this.platformCloudFoundryOperations.getCloudFoundryOperations(replacingRelease.getPlatformName())
			.applications().pushManifest(
			PushApplicationManifestRequest.builder()
					.manifest(applicationManifest)
					.stagingTimeout(CloudFoundryManifestApplicationDeployer.STAGING_TIMEOUT)
					.startupTimeout(CloudFoundryManifestApplicationDeployer.STARTUP_TIMEOUT)
					.build())
			.doOnSuccess(v -> logger.info("Done uploading bits for {}", applicationName))
			.doOnError(e -> logger.error(
					String.format("Error creating app %s.  Exception Message %s", applicationName,
							e.getMessage())))
			.timeout(CloudFoundryManifestApplicationDeployer.PUSH_REQUEST_TIMEOUT)
			.doOnSuccess(item -> {
				logger.info("Successfully deployed {}", applicationName);
				AppDeployerData appDeployerData = new AppDeployerData();
				appDeployerData.setReleaseName(replacingRelease.getName());
				appDeployerData.setReleaseVersion(replacingRelease.getVersion());
				appDeployerData.setDeploymentDataUsingMap(appDeploymentData);
				this.appDeployerDataRepository.save(appDeployerData);
			})
			.doOnError(error -> {
				if (CloudFoundryManifestApplicationDeployer.isNotFoundError().test(error)) {
					logger.warn("Unable to deploy application. It may have been destroyed before start completed: " + error.getMessage());
				}
				else {
					logger.error(String.format("Failed to deploy %s", applicationName + ". " + error.getMessage()));
				}
			})
			.block();
}
 
Example #22
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void deployResource(CloudFoundryAppDeployer deployer, Resource resource) throws IOException {
	given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

	givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()), Mono.just(
			ApplicationDetail.builder()
					.diskQuota(0)
					.id("test-application-id")
					.instances(1)
					.memoryLimit(0)
					.name("test-application")
					.requestedState("RUNNING")
					.runningInstances(0)
					.stack("test-stack")
					.build()));

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
			.manifest(ApplicationManifest.builder()
					.path(resource.getFile().toPath())
					.buildpack(deploymentProperties.getBuildpack())
					.disk(1024)
					.instances(1)
					.memory(1024)
					.name("test-application-id")
					.build())
			.stagingTimeout(this.deploymentProperties.getStagingTimeout())
			.startupTimeout(this.deploymentProperties.getStartupTimeout())
			.build(), Mono.empty());

	deployer.deploy(
			new AppDeploymentRequest(new AppDefinition("test-application", Collections.emptyMap()), resource,
					Collections.EMPTY_MAP));

}
 
Example #23
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private Mono<Void> pushApplication(DeployApplicationRequest request, Map<String, String> deploymentProperties,
	Resource appResource) {
	ApplicationManifest manifest = buildAppManifest(request, deploymentProperties, appResource);

	LOG.debug("Pushing app manifest. manifest={}", manifest.toString());

	PushApplicationManifestRequest applicationManifestRequest =
		PushApplicationManifestRequest.builder()
			.manifest(manifest)
			.stagingTimeout(this.defaultDeploymentProperties.getStagingTimeout())
			.startupTimeout(this.defaultDeploymentProperties.getStartupTimeout())
			.noStart(!start(deploymentProperties))
			.build();

	Mono<Void> requestPushApplication;
	if (deploymentProperties.containsKey(DeploymentProperties.TARGET_PROPERTY_KEY)) {
		String space = deploymentProperties.get(DeploymentProperties.TARGET_PROPERTY_KEY);
		requestPushApplication = pushManifestInSpace(applicationManifestRequest, space);
	}
	else {
		requestPushApplication = pushManifest(applicationManifestRequest);
	}

	return requestPushApplication
		.doOnSuccess(v -> LOG.info("Success pushing app manifest. appName={}", request.getName()))
		.doOnError(e -> LOG.error(String.format("Error pushing app manifest. appName=%s, " + ERROR_LOG_TEMPLATE,
			request.getName(), e.getMessage()), e));
}
 
Example #24
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deployAppWithPropertiesInRequest() {
	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.property(DeploymentProperties.COUNT_PROPERTY_KEY, "3")
		.property(DeploymentProperties.MEMORY_PROPERTY_KEY, "2G")
		.property(DeploymentProperties.DISK_PROPERTY_KEY, "3G")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_PROPERTY_KEY, "http")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_HTTP_ENDPOINT_PROPERTY_KEY, "/healthcheck")
		.property(CloudFoundryDeploymentProperties.BUILDPACK_PROPERTY_KEY, "buildpack")
		.property(CloudFoundryDeploymentProperties.DOMAINS_PROPERTY, "domain1,domain2")
		.property(DeploymentProperties.HOST_PROPERTY_KEY, "host")
		.property(CloudFoundryDeploymentProperties.NO_ROUTE_PROPERTY, "true")
		.build();

	StepVerifier.create(appDeployer.deploy(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
		.verifyComplete();

	ApplicationManifest expectedManifest = baseManifestWithSpringAppJson()
		.name(APP_NAME)
		.path(new File(APP_PATH).toPath())
		.instances(3)
		.memory(2048)
		.disk(3072)
		.healthCheckType(ApplicationHealthCheck.HTTP)
		.healthCheckHttpEndpoint("/healthcheck")
		.buildpack("buildpack")
		.domains("domain2", "domain1") // domains is a list so order matters
		.host("host")
		.noRoute(true)
		.build();

	then(operationsApplications).should().pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #25
Source File: CloudFoundryReleaseManager.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
public Release install(Release newRelease) {
	Release release = this.releaseRepository.save(newRelease);
	ApplicationManifest applicationManifest = this.cfManifestApplicationDeployer.getCFApplicationManifest(release);
	Assert.isTrue(applicationManifest != null, "CF Application Manifest must be set");
	logger.debug("Manifest = " + ArgumentSanitizer.sanitizeYml(newRelease.getManifest().getData()));
	// Deploy the application
	String applicationName = applicationManifest.getName();
	Map<String, String> appDeploymentData = new HashMap<>();
	appDeploymentData.put(applicationManifest.getName(), applicationManifest.toString());
	this.platformCloudFoundryOperations.getCloudFoundryOperations(newRelease.getPlatformName())
			.applications().pushManifest(
			PushApplicationManifestRequest.builder()
					.manifest(applicationManifest)
					.stagingTimeout(CloudFoundryManifestApplicationDeployer.STAGING_TIMEOUT)
					.startupTimeout(CloudFoundryManifestApplicationDeployer.STARTUP_TIMEOUT)
					.build())
			.doOnSuccess(v -> logger.info("Done uploading bits for {}", applicationName))
			.doOnError(e -> logger.error(
					String.format("Error creating app %s.  Exception Message %s", applicationName,
							e.getMessage())))
			.timeout(CloudFoundryManifestApplicationDeployer.PUSH_REQUEST_TIMEOUT)
			.doOnSuccess(item -> {
				logger.info("Successfully deployed {}", applicationName);
				saveAppDeployerData(release, appDeploymentData);

				// Update Status in DB
				updateInstallComplete(release);
			})
			.doOnError(error -> {
				if (CloudFoundryManifestApplicationDeployer.isNotFoundError().test(error)) {
					logger.warn("Unable to deploy application. It may have been destroyed before start completed: " + error.getMessage());
				}
				else {
					logger.error(String.format("Failed to deploy %s", applicationName));
				}
			})
			.block();
	// Store updated state in in DB and compute status
	return status(this.releaseRepository.save(release));
}
 
Example #26
Source File: CloudFoundryApplicationManifestUtils.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
public static ApplicationManifest updateApplicationName(Release release) {
	String name = release.getName() + "-v" + release.getVersion();
	ApplicationManifest cfApplicationManifest = ApplicationManifest.builder()
			.name(name)
			.build();
	return cfApplicationManifest;
}
 
Example #27
Source File: CloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
public Mono<Void> pushBrokerApp(String appName, Path appPath, String brokerClientId,
	List<String> appBrokerProperties) {
	return cloudFoundryOperations.applications().pushManifest(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.environmentVariables(appBrokerDeployerEnvironmentVariables(brokerClientId))
			.putAllEnvironmentVariables(propertiesToEnvironment(appBrokerProperties))
			.name(appName)
			.path(appPath)
			.memory(1024)
			.build())
		.build())
		.doOnSuccess(v -> LOG.info("Success pushing broker app. appName={}", appName))
		.doOnError(e -> LOG.error(String.format("Error pushing broker app. appName=%s, error=%s", appName,
			e.getMessage()), e));
}
 
Example #28
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deployAppWithDefaultProperties() {
	deploymentProperties.setCount(3);
	deploymentProperties.setMemory("2G");
	deploymentProperties.setDisk("3G");
	deploymentProperties.setBuildpack("buildpack");
	deploymentProperties.setHealthCheck(ApplicationHealthCheck.HTTP);
	deploymentProperties.setHealthCheckHttpEndpoint("/healthcheck");
	deploymentProperties.setDomains(singleton("domain"));
	deploymentProperties.setHost("host");

	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.build();

	StepVerifier.create(appDeployer.deploy(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
		.verifyComplete();

	ApplicationManifest expectedManifest = baseManifestWithSpringAppJson()
		.name(APP_NAME)
		.path(new File(APP_PATH).toPath())
		.instances(3)
		.memory(2048)
		.disk(3072)
		.healthCheckType(ApplicationHealthCheck.HTTP)
		.healthCheckHttpEndpoint("/healthcheck")
		.buildpack("buildpack")
		.domain("domain")
		.host("host")
		.build();

	then(operationsApplications).should().pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #29
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deployAppWithEnvironmentNotUsingSpringAppJson() {
	deploymentProperties.setUseSpringApplicationJson(false);

	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.property(CloudFoundryDeploymentProperties.JAVA_OPTS_PROPERTY_KEY, "-Xms512m -Xmx1024m")
		.environment("ENV_VAR_1", "value1")
		.environment("ENV_VAR_2", "value2")
		.build();

	StepVerifier.create(appDeployer.deploy(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
		.verifyComplete();

	ApplicationManifest expectedManifest = baseManifest()
		.name(APP_NAME)
		.path(new File(APP_PATH).toPath())
		.environmentVariable("JAVA_OPTS", "-Xms512m -Xmx1024m")
		.environmentVariable("spring.cloud.appbroker.service-instance-id", SERVICE_INSTANCE_ID)
		.environmentVariable("ENV_VAR_1", "value1")
		.environmentVariable("ENV_VAR_2", "value2")
		.build();

	then(operationsApplications).should().pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #30
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void deploy() throws IOException {
	Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

	given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

	givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()), Mono.just(
		ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(1)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(0)
			.stack("test-stack")
			.build()));

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.path(resource.getFile().toPath())
			.buildpack(deploymentProperties.getBuildpack())
			.disk(1024)
			.environmentVariables(defaultEnvironmentVariables())
			.instances(1)
			.memory(1024)
			.name("test-application-id")
			.service("test-service-2")
			.service("test-service-1")
			.build())
		.stagingTimeout(this.deploymentProperties.getStagingTimeout())
		.startupTimeout(this.deploymentProperties.getStartupTimeout())
		.build(), Mono.empty());

	String deploymentId = this.deployer.deploy(
		new AppDeploymentRequest(new AppDefinition("test-application", Collections.emptyMap()), resource,
			Collections.EMPTY_MAP));

	assertThat(deploymentId, equalTo("test-application-id"));
}