org.springframework.cloud.deployer.spi.app.AppScaleRequest Java Examples
The following examples show how to use
org.springframework.cloud.deployer.spi.app.AppScaleRequest.
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: CloudFoundryAppDeployer.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 6 votes |
@Override public void scale(AppScaleRequest appScaleRequest) { logger.info("Scaling the application instance using ", appScaleRequest.toString()); ScaleApplicationRequest scaleApplicationRequest = ScaleApplicationRequest.builder() .name(appScaleRequest.getDeploymentId()) .instances(appScaleRequest.getCount()) .memoryLimit(memory(appScaleRequest)) .diskLimit(diskQuota(appScaleRequest)) .stagingTimeout(this.deploymentProperties.getStagingTimeout()) .startupTimeout(this.deploymentProperties.getStartupTimeout()) .build(); this.operations.applications().scale(scaleApplicationRequest) .timeout(Duration.ofSeconds(this.deploymentProperties.getApiTimeout())) .doOnSuccess(v -> logger.info("Scaled the application with deploymentId = {}", appScaleRequest.getDeploymentId())) .doOnError(e -> logger.error("Error: {} scaling the app instance {}", e.getMessage(), appScaleRequest.getDeploymentId())) .subscribe(); }
Example #2
Source File: CloudFoundryAppDeployerTests.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void scale() { givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder() .diskQuota(0) .id("test-application-id") .instances(2) .memoryLimit(0) .name("test-application") .requestedState("RUNNING") .runningInstances(2) .stack("test-stack") .instanceDetail(InstanceDetail.builder().state("RUNNING").index("1").build()) .build())); givenRequestScaleApplication("test-application-id", 2, 1024, 1024, Mono.empty()); this.deployer.scale(new AppScaleRequest("test-application-id", 2)); }
Example #3
Source File: KubernetesAppDeployer.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Override public void scale(AppScaleRequest appScaleRequest) { String deploymentId = appScaleRequest.getDeploymentId(); logger.debug(String.format("Scale app: %s to: %s", deploymentId, appScaleRequest.getCount())); ScalableResource scalableResource = this.client.apps().deployments().withName(deploymentId); if (scalableResource.get() == null) { scalableResource = this.client.apps().statefulSets().withName(deploymentId); } if (scalableResource.get() == null) { throw new IllegalStateException(String.format("App '%s' is not deployed", deploymentId)); } scalableResource.scale(appScaleRequest.getCount(), true); }
Example #4
Source File: KubernetesAppDeployerIntegrationTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testScaleDeployment() { log.info("Testing {}...", "ScaleDeployment"); KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties(); ContainerFactory containerFactory = new DefaultContainerFactory(deployProperties); KubernetesAppDeployer appDeployer = new KubernetesAppDeployer(deployProperties, kubernetesClient, containerFactory); AppDefinition definition = new AppDefinition(randomName(), null); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.emptyMap()); log.info("Deploying {}...", request.getDefinition().getName()); Timeout timeout = deploymentTimeout(); String deploymentId = appDeployer.deploy(request); assertThat(deploymentId, eventually(hasStatusThat( Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); assertThat(deploymentId, eventually(appInstanceCount(is(1)))); log.info("Scale Up {}...", request.getDefinition().getName()); appDeployer.scale(new AppScaleRequest(deploymentId, 3)); assertThat(deploymentId, eventually(appInstanceCount(is(3)), timeout.maxAttempts, timeout.pause)); log.info("Scale Down {}...", request.getDefinition().getName()); appDeployer.scale(new AppScaleRequest(deploymentId, 1)); assertThat(deploymentId, eventually(appInstanceCount(is(1)), timeout.maxAttempts, timeout.pause)); appDeployer.undeploy(deploymentId); }
Example #5
Source File: AbstractCloudFoundryDeployer.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 5 votes |
int memory(AppScaleRequest request) { if (request.getProperties().isPresent() && request.getProperties().get() != null) { return (int) ByteSizeUtils.parseToMebibytes(request.getProperties().get().getOrDefault(AppDeployer.MEMORY_PROPERTY_KEY, this.deploymentProperties.getMemory())); } return (int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()); }
Example #6
Source File: AbstractCloudFoundryDeployer.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 5 votes |
int diskQuota(AppScaleRequest request) { if (request.getProperties().isPresent() && request.getProperties().get() != null) { return (int) ByteSizeUtils.parseToMebibytes(request.getProperties().get().getOrDefault(AppDeployer.DISK_PROPERTY_KEY, this.deploymentProperties.getDisk())); } return (int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()); }
Example #7
Source File: KubernetesAppDeployerIntegrationTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 4 votes |
@Test public void testScaleStatefulSet() { log.info("Testing {}...", "ScaleStatefulSet"); KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties(); ContainerFactory containerFactory = new DefaultContainerFactory(deployProperties); KubernetesAppDeployer appDeployer = new KubernetesAppDeployer(deployProperties, kubernetesClient, containerFactory); AppDefinition definition = new AppDefinition(randomName(), null); Resource resource = testApplication(); Map<String, String> props = new HashMap<>(); props.put(KubernetesAppDeployer.COUNT_PROPERTY_KEY, "3"); props.put(KubernetesAppDeployer.INDEXED_PROPERTY_KEY, "true"); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props); log.info("Deploying {}...", request.getDefinition().getName()); Timeout timeout = deploymentTimeout(); String deploymentId = appDeployer.deploy(request); assertThat(deploymentId, eventually(hasStatusThat( Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); assertThat(deploymentId, eventually(appInstanceCount(is(3)))); // Ensure that a StatefulSet is deployed Map<String, String> selector = Collections.singletonMap(SPRING_APP_KEY, deploymentId); List<StatefulSet> statefulSets = kubernetesClient.apps().statefulSets().withLabels(selector).list().getItems(); assertNotNull(statefulSets); assertEquals(1, statefulSets.size()); StatefulSet statefulSet = statefulSets.get(0); StatefulSetSpec statefulSetSpec = statefulSet.getSpec(); Assertions.assertThat(statefulSetSpec.getPodManagementPolicy()).isEqualTo("Parallel"); Assertions.assertThat(statefulSetSpec.getReplicas()).isEqualTo(3); Assertions.assertThat(statefulSetSpec.getServiceName()).isEqualTo(deploymentId); Assertions.assertThat(statefulSet.getMetadata().getName()).isEqualTo(deploymentId); log.info("Scale Down {}...", request.getDefinition().getName()); appDeployer.scale(new AppScaleRequest(deploymentId, 1)); assertThat(deploymentId, eventually(appInstanceCount(is(1)), timeout.maxAttempts, timeout.pause)); statefulSets = kubernetesClient.apps().statefulSets().withLabels(selector).list().getItems(); assertEquals(1, statefulSets.size()); statefulSetSpec = statefulSets.get(0).getSpec(); Assertions.assertThat(statefulSetSpec.getReplicas()).isEqualTo(1); Assertions.assertThat(statefulSetSpec.getServiceName()).isEqualTo(deploymentId); Assertions.assertThat(statefulSet.getMetadata().getName()).isEqualTo(deploymentId); appDeployer.undeploy(deploymentId); }
Example #8
Source File: KubernetesAppDeployerIntegrationTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 4 votes |
@Test(expected = IllegalStateException.class) public void testScaleWithNonExistingApps() { appDeployer.scale(new AppScaleRequest("Fake App", 10)); }
Example #9
Source File: AbstractAppDeployerIntegrationTests.java From spring-cloud-deployer with Apache License 2.0 | 4 votes |
@Override public void scale(AppScaleRequest appScaleRequest) { wrapped.scale(appScaleRequest); }
Example #10
Source File: LocalAppDeployer.java From spring-cloud-deployer-local with Apache License 2.0 | 4 votes |
@Override public void scale(AppScaleRequest appScaleRequest) { validateStatus(appScaleRequest.getDeploymentId(), DeploymentState.deployed); AppInstancesHolder holder = running.get(appScaleRequest.getDeploymentId()); List<AppInstance> instances = holder != null ? holder.instances : null; if (instances == null) { throw new IllegalStateException( "Can't find existing instances for deploymentId " + appScaleRequest.getDeploymentId()); } AppDeploymentRequest request = holder.request; String group = request.getDeploymentProperties().get(GROUP_PROPERTY_KEY); String deploymentId = String.format("%s.%s", group, request.getDefinition().getName()); // consolidatedAppProperties is a Map of all application properties to be used by // the app being launched. These values should end up as environment variables // either explicitly or as a SPRING_APPLICATION_JSON value. HashMap<String, String> consolidatedAppProperties = new HashMap<>(request.getDefinition().getProperties()); consolidatedAppProperties.put(JMX_DEFAULT_DOMAIN_KEY, deploymentId); if (!request.getDefinition().getProperties().containsKey(ENDPOINTS_SHUTDOWN_ENABLED_KEY)) { consolidatedAppProperties.put(ENDPOINTS_SHUTDOWN_ENABLED_KEY, "true"); } consolidatedAppProperties.put("endpoints.jmx.unique-names", "true"); if (group != null) { consolidatedAppProperties.put("spring.cloud.application.group", group); } try { Path workDir = createWorkingDir(request.getDeploymentProperties(), deploymentId); int deltaCount = appScaleRequest.getCount() - instances.size(); int targetCount = instances.size() + deltaCount; if (deltaCount > 0) { for (int index = instances.size(); index < targetCount; index++) { instances.add(deployApp(request, workDir, group, deploymentId, index)); } } else if (deltaCount < 0) { List<AppInstance> processes = new ArrayList<>(); for (int index = instances.size() - 1; index >= targetCount; index--) { processes.add(instances.remove(index)); } for (AppInstance instance : processes) { if (isAlive(instance.getProcess())) { logger.info("Un-deploying app with deploymentId {} instance {}.", deploymentId, instance.getInstanceNumber()); shutdownAndWait(instance); } } } } catch (IOException e) { throw new RuntimeException("Exception trying to deploy " + request, e); } }
Example #11
Source File: AbstractAppDeployerIntegrationTests.java From spring-cloud-deployer with Apache License 2.0 | 2 votes |
protected void doTestScale(Boolean indexed) { final int DESIRED_COUNT = 3; Map<String, String> deploymentProperties = Collections.singletonMap(AppDeployer.INDEXED_PROPERTY_KEY, indexed.toString()); AppDefinition definition = new AppDefinition(randomName(), null); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties); log.info("Deploying {} index={}...", request.getDefinition().getName(), indexed); String deploymentId = appDeployer().deploy(request); Timeout timeout = deploymentTimeout(); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); log.info("Scaling {} to {} instances...", request.getDefinition().getName(), DESIRED_COUNT); appDeployer().scale(new AppScaleRequest(deploymentId, DESIRED_COUNT)); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); assertThat(deploymentId, eventually(appInstanceCount(is(DESIRED_COUNT)), timeout.maxAttempts, timeout.pause)); List<DeploymentState> individualStates = new ArrayList<>(); for (AppInstanceStatus status : appDeployer().status(deploymentId).getInstances().values()) { individualStates.add(status.getState()); } assertThat(individualStates, everyItem(is(deployed))); log.info("Scaling {} from {} to 1 instance...", request.getDefinition().getName(), DESIRED_COUNT); appDeployer().scale(new AppScaleRequest(deploymentId, 1)); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); assertThat(deploymentId, eventually(appInstanceCount(is(1)), timeout.maxAttempts, timeout.pause)); log.info("Undeploying {}...", deploymentId); timeout = undeploymentTimeout(); appDeployer().undeploy(deploymentId); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause)); }