org.cloudfoundry.operations.applications.ApplicationHealthCheck Java Examples

The following examples show how to use org.cloudfoundry.operations.applications.ApplicationHealthCheck. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private ApplicationHealthCheck toApplicationHealthCheck(String raw) {
	try {
		return ApplicationHealthCheck.from(raw);
	} catch (IllegalArgumentException e) {
		throw new IllegalArgumentException(String.format("Unsupported health-check value '%s'. Available values are %s", raw,
			StringUtils.arrayToCommaDelimitedString(ApplicationHealthCheck.values())), e);
	}
}
 
Example #8
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 #9
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 #10
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private ApplicationHealthCheck toApplicationHealthCheck(String raw) {
	try {
		return ApplicationHealthCheck.from(raw);
	}
	catch (IllegalArgumentException e) {
		throw new IllegalArgumentException(
			String.format("Unsupported health-check value '%s'. Available values are %s", raw,
				StringUtils.arrayToCommaDelimitedString(ApplicationHealthCheck.values())), e);
	}
}
 
Example #11
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 deployWithCustomDeploymentProperties() 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()));

	this.deploymentProperties.setBuildpack("test-buildpack");
	this.deploymentProperties.setDisk("0");
	this.deploymentProperties.setDomain("test-domain");
	this.deploymentProperties.setHealthCheck(ApplicationHealthCheck.NONE);
	this.deploymentProperties.setHost("test-host");
	this.deploymentProperties.setInstances(0);
	this.deploymentProperties.setMemory("0");

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.path(resource.getFile().toPath())
			.buildpack("test-buildpack")
			.disk(0)
			.domain("test-domain")
			.environmentVariables(defaultEnvironmentVariables())
			.healthCheckType(ApplicationHealthCheck.NONE)
			.host("test-host")
			.instances(0)
			.memory(0)
			.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 #12
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 deployWithInvalidRoutePathProperty() 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("test-buildpack")
														  .disk(0)
														  .environmentVariables(defaultEnvironmentVariables())
														  .healthCheckType(ApplicationHealthCheck.NONE)
														  .instances(0)
														  .memory(0)
														  .name("test-application-id")
														  .noRoute(false)
														  .host("test-host")
														  .domain("test-domain")
														  .routePath("/test-route-path")
														  .service("test-service-2")
														  .service("test-service-1")
														  .build())
										.stagingTimeout(this.deploymentProperties.getStagingTimeout())
										.startupTimeout(this.deploymentProperties.getStartupTimeout())
										.build(), Mono.empty());
	try {
		this.deployer.deploy(new AppDeploymentRequest(
				new AppDefinition("test-application", Collections.emptyMap()),
				resource,
				FluentMap.<String, String>builder()
						.entry(BUILDPACK_PROPERTY_KEY, "test-buildpack")
						.entry(AppDeployer.DISK_PROPERTY_KEY, "0")
						.entry(DOMAIN_PROPERTY, "test-domain")
						.entry(HEALTHCHECK_PROPERTY_KEY, "none")
						.entry(HOST_PROPERTY, "test-host")
						.entry(COUNT_PROPERTY_KEY, "0")
						.entry(AppDeployer.MEMORY_PROPERTY_KEY, "0")
						.entry(NO_ROUTE_PROPERTY, "false")
						.entry(ROUTE_PATH_PROPERTY, "test-route-path")
						.build()));
		fail("Illegal Argument exception is expected.");
	}
	catch (IllegalArgumentException e) {
		assertThat(e.getMessage(), equalTo(
				"Cloud Foundry routes must start with \"/\". Route passed = [test-route-path]."));
	}
}
 
Example #13
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 deployWithApplicationDeploymentProperties() 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("test-buildpack")
			.disk(0)
			.environmentVariables(defaultEnvironmentVariables())
			.healthCheckType(ApplicationHealthCheck.NONE)
			.instances(0)
			.memory(0)
			.name("test-application-id")
			.noRoute(false)
			.host("test-host")
			.domain("test-domain")
			.routePath("/test-route-path")
			.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,
			FluentMap.<String, String>builder().entry(BUILDPACK_PROPERTY_KEY, "test-buildpack")
				.entry(AppDeployer.DISK_PROPERTY_KEY, "0")
				.entry(DOMAIN_PROPERTY, "test-domain")
				.entry(HEALTHCHECK_PROPERTY_KEY, "none")
				.entry(HOST_PROPERTY, "test-host")
				.entry(COUNT_PROPERTY_KEY, "0")
				.entry(AppDeployer.MEMORY_PROPERTY_KEY, "0")
				.entry(NO_ROUTE_PROPERTY, "false")
				.entry(ROUTE_PATH_PROPERTY, "/test-route-path")
				.build()));

	assertThat(deploymentId, equalTo("test-application-id"));
}
 
Example #14
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Test
public void deployWithDeployerEnvironmentVariables() 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("test-buildpack")
					.disk(0)
					.environmentVariables(defaultEnvironmentVariables())
					.healthCheckType(ApplicationHealthCheck.NONE)
					.instances(0)
					.memory(0)
					.name("test-application-id")
					.noRoute(false)
					.host("test-host")
					.domain("test-domain")
					.service("test-service-2")
					.service("test-service-1")
					.build())
			.build(), Mono.empty());


	CloudFoundryAppDeployer deployer = new CloudFoundryAppDeployer(this.applicationNameGenerator,
			bindDeployerProperties(FluentMap.<String,String>builder()
			.entry("env.JBP_CONFIG_SPRING_AUTO_RECONFIGURATION",CfEnvConfigurer.ENABLED_FALSE)
			.entry("env.SPRING_PROFILES_ACTIVE","cloud,foo")
			.build()), this.operations, this.runtimeEnvironmentInfo);

	AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(new AppDefinition("test-application",
			Collections.EMPTY_MAP), resource,
			FluentMap.<String, String>builder().entry(BUILDPACK_PROPERTY_KEY, "test-buildpack")
					.entry(AppDeployer.DISK_PROPERTY_KEY, "0")
					.entry(DOMAIN_PROPERTY, "test-domain")
					.entry(HEALTHCHECK_PROPERTY_KEY, "none")
					.entry(HOST_PROPERTY, "test-host")
					.entry(COUNT_PROPERTY_KEY, "0")
					.entry(AppDeployer.MEMORY_PROPERTY_KEY, "0")
					.entry(NO_ROUTE_PROPERTY, "false")
					.entry(ROUTE_PATH_PROPERTY, "/test-route-path")
					.build());

	assertThat(deployer.getEnvironmentVariables("test-application-id", appDeploymentRequest),allOf(
			hasEntry("JBP_CONFIG_SPRING_AUTO_RECONFIGURATION", CfEnvConfigurer.ENABLED_FALSE),
			hasEntry("SPRING_PROFILES_ACTIVE","cloud,foo"),
			hasKey("SPRING_APPLICATION_JSON"))
	);

	String deploymentId = deployer.deploy(appDeploymentRequest);

	assertThat(deploymentId, equalTo("test-application-id"));
}
 
Example #15
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 deployWithMultipleRoutes() 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()));

	this.deploymentProperties.setBuildpack("test-buildpack");
	this.deploymentProperties.setDisk("0");
	this.deploymentProperties.setHealthCheck(ApplicationHealthCheck.NONE);
	this.deploymentProperties.setRoutes(Sets.newHashSet("route1.test-domain", "route2.test-domain"));
	this.deploymentProperties.setInstances(0);
	this.deploymentProperties.setMemory("0");

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
			.manifest(ApplicationManifest.builder()
					.path(resource.getFile().toPath())
					.buildpack("test-buildpack")
					.disk(0)
					.routes(Sets.newHashSet(
							Route.builder().route("route1.test-domain").build(),
							Route.builder().route("route2.test-domain").build()
					))
					.environmentVariables(defaultEnvironmentVariables())
					.healthCheckType(ApplicationHealthCheck.NONE)
					.instances(0)
					.memory(0)
					.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: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void setupTaskWithNonExistentApplicationBindingThreeServices(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)
					.service("test-service-instance-1")
					.service("test-service-instance-2")
					.service("test-service-instance-3")
					.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.just(SummaryApplicationResponse.builder()
			.id("test-application-id")
			.detectedStartCommand("test-command")
			.build()));

	givenRequestCreateTask("test-application-id",
				"test-command",
				this.deploymentProperties.getMemory(),
				"test-application",
				Mono.just(CreateTaskResponse.builder()
			.id("test-task-id")
			.memoryInMb(1024)
			.diskInMb(1024)
			.dropletId("1")
			.createdAt(new Date().toString())
			.updatedAt(new Date().toString())
			.sequenceId(1)
			.name("test-task-id")
			.state(TaskState.SUCCEEDED)
			.build()));
}
 
Example #17
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
private ApplicationHealthCheck healthCheck(Map<String, String> properties) {
	return Optional.ofNullable(properties.get(CloudFoundryDeploymentProperties.HEALTHCHECK_PROPERTY_KEY))
		.map(this::toApplicationHealthCheck)
		.orElse(this.defaultDeploymentProperties.getHealthCheck());
}
 
Example #18
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void setupTaskWithNonExistentApplicationBindingOneService(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)
					.service("test-service-instance-2")
					.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.just(SummaryApplicationResponse.builder()
			.id("test-application-id")

			.detectedStartCommand("test-command")
			.build()));

	givenRequestCreateTask("test-application-id",
				"test-command",
				this.deploymentProperties.getMemory(),
				"test-application",
				Mono.just(CreateTaskResponse.builder()
			.id("test-task-id")
			.memoryInMb(1024)
			.diskInMb(1024)
			.dropletId("1")
			.createdAt(new Date().toString())
			.updatedAt(new Date().toString())
			.sequenceId(1)
			.name("test-task-id")
			.state(TaskState.SUCCEEDED)
			.build()));
}
 
Example #19
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void setupTaskWithNonExistentApplication(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.just(SummaryApplicationResponse.builder()
			.id("test-application-id")
			.detectedStartCommand("test-command")
			.build()));

	givenRequestCreateTask("test-application-id",
				"test-command",
				this.deploymentProperties.getMemory(),
				"test-application",
				Mono.just(CreateTaskResponse.builder()
			.id("test-task-id")
			.memoryInMb(1024)
			.diskInMb(1024)
			.dropletId("1")
			.createdAt(new Date().toString())
			.updatedAt(new Date().toString())
			.sequenceId(1)
			.name("test-task-id")
			.state(TaskState.SUCCEEDED)
			.build()));
}
 
Example #20
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void launchTaskWithNonExistentApplicationAndTaskCreationFails() throws IOException {
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.path(this.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.just(SummaryApplicationResponse.builder()
		.id("test-application-id")
		.detectedStartCommand("test-command")
		.build()));

	givenRequestCreateTask("test-application-id",
			"test-command",
			this.deploymentProperties.getMemory(),
			"test-application",
			Mono.error(new UnsupportedOperationException()));

	this.launcher.launch(defaultRequest());
}
 
Example #21
Source File: CloudFoundryDeploymentProperties.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
public void setHealthCheck(ApplicationHealthCheck healthCheck) {
	this.healthCheck = healthCheck;
}
 
Example #22
Source File: CloudFoundryDeploymentProperties.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
public ApplicationHealthCheck getHealthCheck() {
	return healthCheck;
}
 
Example #23
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private ApplicationHealthCheck healthCheck(AppDeploymentRequest request) {
	return Optional.ofNullable(request.getDeploymentProperties().get(HEALTHCHECK_PROPERTY_KEY))
		.map(this::toApplicationHealthCheck)
		.orElse(this.deploymentProperties.getHealthCheck());
}
 
Example #24
Source File: CloudFoundryApplicationManifestUtilsTests.java    From spring-cloud-skipper with Apache License 2.0 4 votes vote down vote up
@Test
public void testManifestMap() {
	ApplicationManifest manifest = ApplicationManifest.builder()
			.name("name")
			.buildpack("buildpack")
			.command("command")
			.disk(1024)
			.domain("domain")
			.environmentVariable("key", "value")
			.healthCheckHttpEndpoint("endpoint")
			.healthCheckType(ApplicationHealthCheck.PROCESS)
			.host("host")
			.instances(2)
			.memory(1024)
			.noHostname(true)
			.noRoute(true)
			.randomRoute(true)
			.services("service1", "service2")
			.stack("stack")
			.timeout(100)
			.build();

	Map<String, String> map = CloudFoundryApplicationManifestUtils.getCFManifestMap(manifest);
	assertThat(map).hasSize(18);

	manifest = ApplicationManifest.builder()
			.name("name")
			.buildpack("buildpack")
			.command("command --foobar=x,y")
			.disk(1024)
			.domain("domain")
			.environmentVariable("key", "value")
			.healthCheckHttpEndpoint("endpoint")
			.healthCheckType(ApplicationHealthCheck.PROCESS)
			.host("host")
			.instances(2)
			.memory(1024)
			.noHostname(true)
			.noRoute(true)
			.randomRoute(true)
			.services("service1")
			.stack("stack")
			.timeout(100)
			.build();

	map = CloudFoundryApplicationManifestUtils.getCFManifestMap(manifest);
	assertThat(map).hasSize(17);
}
 
Example #25
Source File: CloudFoundryManifestApplicationDeployer.java    From spring-cloud-skipper with Apache License 2.0 4 votes vote down vote up
public ApplicationManifest getCFApplicationManifest(Release release) {
	ApplicationManifest cfApplicationManifest = CloudFoundryApplicationManifestUtils.updateApplicationName(release);
	cfApplicationManifest = ApplicationManifest.builder()
			.from(cfApplicationManifest)
			.build();

	List<? extends CloudFoundryApplicationSkipperManifest> cfApplicationManifestList = this.cfApplicationManifestReader
			.read(release.getManifest().getData());
	for (CloudFoundryApplicationSkipperManifest cfApplicationSkipperManifest : cfApplicationManifestList) {
		CloudFoundryApplicationSpec spec = cfApplicationSkipperManifest.getSpec();
		String resource = spec.getResource();
		String version = spec.getVersion();

		Manifest manifest = spec.getManifest();
		cfApplicationManifest = ApplicationManifest.builder()
				.from(cfApplicationManifest)
				.buildpack(manifest.getBuildpack())
				.command(manifest.getCommand())
				.disk(CloudFoundryApplicationManifestUtils.memoryInteger(manifest.getDiskQuota()))
				.domains(manifest.getDomains() != null && !manifest.getDomains().isEmpty() ? manifest.getDomains()
						: null)
				.environmentVariables(manifest.getEnv() != null ? manifest.getEnv() : null)
				.healthCheckHttpEndpoint(manifest.getHealthCheckHttpEndpoint())
				.healthCheckType(manifest.getHealthCheckType() != null
						? ApplicationHealthCheck.from(manifest.getHealthCheckType().name())
						: null)
				.hosts(manifest.getHosts() != null && !manifest.getHosts().isEmpty() ? manifest.getHosts() : null)
				.instances(manifest.getInstances())
				.memory(CloudFoundryApplicationManifestUtils.memoryInteger(manifest.getMemory()))
				.noHostname(manifest.getNoHostname())
				.noRoute(manifest.getNoRoute())
				.randomRoute(manifest.getRandomRoute())
				.services(manifest.getServices())
				.stack(manifest.getStack())
				.timeout(manifest.getTimeout())
				.build();


		Resource application = this.delegatingResourceLoader.getResource(getResourceLocation(resource, version));
		cfApplicationManifest = CloudFoundryApplicationManifestUtils.updateApplicationPath(cfApplicationManifest, application);

	}

	return cfApplicationManifest;
}
 
Example #26
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deployAppWithRoutesAndMutuallyExclusiveProperties() {
	deploymentProperties.setCount(3);
	deploymentProperties.setMemory("2G");
	deploymentProperties.setDisk("3G");
	deploymentProperties.setBuildpack("buildpack1");
	deploymentProperties.setHealthCheck(ApplicationHealthCheck.HTTP);
	deploymentProperties.setHealthCheckHttpEndpoint("/healthcheck1");
	deploymentProperties.setHost("host1");
	deploymentProperties.setDomain("domain1");
	deploymentProperties.setDomains(singleton("domain2"));

	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.property(DeploymentProperties.COUNT_PROPERTY_KEY, "5")
		.property(DeploymentProperties.MEMORY_PROPERTY_KEY, "4G")
		.property(DeploymentProperties.DISK_PROPERTY_KEY, "5G")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_PROPERTY_KEY, "port")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_HTTP_ENDPOINT_PROPERTY_KEY, "/healthcheck2")
		.property(CloudFoundryDeploymentProperties.BUILDPACK_PROPERTY_KEY, "buildpack2")
		.property(CloudFoundryDeploymentProperties.DOMAIN_PROPERTY, "domain1")
		.property(CloudFoundryDeploymentProperties.DOMAINS_PROPERTY, "domain2")
		.property(CloudFoundryDeploymentProperties.ROUTES_PROPERTY, "route.domain3")
		.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(5)
		.memory(4096)
		.disk(5120)
		.healthCheckType(ApplicationHealthCheck.PORT)
		.healthCheckHttpEndpoint("/healthcheck2")
		.buildpack("buildpack2")
		.routes(Route.builder().route("route.domain3").build())
		.build();

	then(operationsApplications).should().pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #27
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deployAppWithBothDomainAndDomainsProperties() {
	deploymentProperties.setCount(3);
	deploymentProperties.setMemory("2G");
	deploymentProperties.setDisk("3G");
	deploymentProperties.setBuildpack("buildpack1");
	deploymentProperties.setHealthCheck(ApplicationHealthCheck.HTTP);
	deploymentProperties.setHealthCheckHttpEndpoint("/healthcheck1");
	deploymentProperties.setHost("host1");
	deploymentProperties.setDomains(singleton("default-domain"));

	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.property(DeploymentProperties.COUNT_PROPERTY_KEY, "5")
		.property(DeploymentProperties.MEMORY_PROPERTY_KEY, "4G")
		.property(DeploymentProperties.DISK_PROPERTY_KEY, "5G")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_PROPERTY_KEY, "port")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_HTTP_ENDPOINT_PROPERTY_KEY, "/healthcheck2")
		.property(CloudFoundryDeploymentProperties.BUILDPACK_PROPERTY_KEY, "buildpack2")
		.property(CloudFoundryDeploymentProperties.DOMAIN_PROPERTY, "domain1")
		.property(CloudFoundryDeploymentProperties.DOMAINS_PROPERTY, "domain2")
		.property(DeploymentProperties.HOST_PROPERTY_KEY, "host2")
		.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(5)
		.memory(4096)
		.disk(5120)
		.healthCheckType(ApplicationHealthCheck.PORT)
		.healthCheckHttpEndpoint("/healthcheck2")
		.buildpack("buildpack2")
		.domains("domain1", "default-domain", "domain2")
		.host("host2")
		.noRoute(true)
		.build();

	then(operationsApplications).should().pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #28
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deployAppWithRequestOverridingDefaultProperties() {
	deploymentProperties.setCount(3);
	deploymentProperties.setMemory("2G");
	deploymentProperties.setDisk("3G");
	deploymentProperties.setBuildpack("buildpack1");
	deploymentProperties.setHealthCheck(ApplicationHealthCheck.HTTP);
	deploymentProperties.setHealthCheckHttpEndpoint("/healthcheck1");
	deploymentProperties.setDomains(singleton("domain1"));
	deploymentProperties.setHost("host1");

	DeployApplicationRequest request = DeployApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.serviceInstanceId(SERVICE_INSTANCE_ID)
		.property(DeploymentProperties.COUNT_PROPERTY_KEY, "5")
		.property(DeploymentProperties.MEMORY_PROPERTY_KEY, "4G")
		.property(DeploymentProperties.DISK_PROPERTY_KEY, "5G")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_PROPERTY_KEY, "port")
		.property(CloudFoundryDeploymentProperties.HEALTHCHECK_HTTP_ENDPOINT_PROPERTY_KEY, "/healthcheck2")
		.property(CloudFoundryDeploymentProperties.BUILDPACK_PROPERTY_KEY, "buildpack2")
		.property(CloudFoundryDeploymentProperties.DOMAINS_PROPERTY, "domain2")
		.property(DeploymentProperties.HOST_PROPERTY_KEY, "host2")
		.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(5)
		.memory(4096)
		.disk(5120)
		.healthCheckType(ApplicationHealthCheck.PORT)
		.healthCheckHttpEndpoint("/healthcheck2")
		.buildpack("buildpack2")
		.domains("domain2", "domain1")
		.host("host2")
		.noRoute(true)
		.build();

	then(operationsApplications).should()
		.pushManifest(argThat(matchesManifest(expectedManifest)));
}
 
Example #29
Source File: CloudFoundryDeploymentProperties.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
public void setHealthCheck(ApplicationHealthCheck healthCheck) {
	this.healthCheck = healthCheck;
}
 
Example #30
Source File: CloudFoundryDeploymentProperties.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
public ApplicationHealthCheck getHealthCheck() {
	return healthCheck;
}