private boolean areAllDependenciesAlreadyDeployed(CloudControllerClient client, Set<String> deployedAfter) { List<CloudApplication> nonDeployedApplications = deployedAfter.stream() .map(deployAfterDependency -> client.getApplication(deployAfterDependency, false)) .filter(Objects::isNull) .collect(Collectors.toList()); return nonDeployedApplications.isEmpty(); }
private boolean areModulesAlreadyDeployed(CloudControllerClient client, List<String> deployedAfter) { List<CloudApplication> dependencyModulesApplications = deployedAfter.stream() .map(dependencyModule -> client.getApplication(dependencyModule, false)) .filter(Objects::isNull) .collect(Collectors.toList()); return dependencyModulesApplications.isEmpty(); }
private boolean areAllDependenciesAlreadyDeployed(CloudControllerClient client, Set<String> deployedAfter) { List<CloudApplication> nonDeployedApplications = deployedAfter.stream() .map(deployAfterDependency -> client.getApplication(deployAfterDependency, false)) .filter(Objects::isNull) .collect(Collectors.toList()); return nonDeployedApplications.isEmpty(); }
private List<CloudApplication> mapApplicationsFromContextToCloudApplications(ExecutionWrapper execution, CloudControllerClient client) { return StepsUtil.getAppsToDeploy(execution.getContext()) .stream() .map(app -> client.getApplication(app.getName())) .collect(Collectors.toList()); }
private List<CloudApplication> mapApplicationsFromContextToCloudApplications(ExecutionWrapper execution, CloudControllerClient client) { return StepsUtil.getAppsToDeploy(execution.getContext()) .stream() .map(app -> client.getApplication(app.getName())) .collect(Collectors.toList()); }
private ApplicationStartupState computeCurrentState(ExecutionWrapper execution, CloudApplication app) { CloudControllerClient client = execution.getControllerClient(); return appStateCalculatorSupplier.get() .computeCurrentState(client.getApplication(app.getName())); }
private ApplicationStartupState computeCurrentState(ExecutionWrapper execution, CloudApplication app) { CloudControllerClient client = execution.getControllerClient(); return appStateCalculatorSupplier.get() .computeCurrentState(client.getApplication(app.getName())); }
private boolean isStarted(CloudControllerClient client, String appName) { try { CloudApplication app = client.getApplication(appName); return app.getState() .equals(AppState.STARTED); } catch (CloudOperationException e) { if (e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR)) { logger.warn(e.getMessage(), e); return false; } throw e; } }
private boolean isStarted(CloudControllerClient client, String appName) { try { CloudApplication app = client.getApplication(appName); return app.getState() .equals(AppState.STARTED); } catch (CloudOperationException e) { if (e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR)) { logger.warn(e.getMessage(), e); return false; } throw e; } }
private List<CloudRoute> attemptToGetRoutes(CloudControllerClient client, String appName) { CloudApplication app = client.getApplication(appName); String appRoutesUrl = getAppRoutesUrl(app.getMeta() .getGuid()); return doGetRoutes(client, appRoutesUrl); }
@Before public void setUp() throws MalformedURLException { MockitoAnnotations.initMocks(this); this.applicationStagingUpdater = new ApplicationStagingUpdater(restTemplateFactory); Mockito.when(client.getCloudControllerUrl()) .thenReturn(new URL(CONTROLLER_ENDPOINT)); Mockito.when(client.getApplication(input.application.appName)) .thenReturn(input.application.toCloudApp()); Mockito.when(restTemplateFactory.getRestTemplate(Mockito.eq(client))) .thenReturn(restTemplate); updateStaging = input.staging.toStaging(); }
private void attemptToUpdateApplicationStaging(CloudControllerClient client, String appName, Staging staging) { String applicationsEndpoint = getApplicationsEndpoint(client.getCloudControllerUrl() .toString()); CloudApplication application = client.getApplication(appName); UUID applicationId = application.getMeta() .getGuid(); Map<String, Object> stagingParameters = createStagingParameters(staging); getRestTemplate(client).put(applicationsEndpoint, stagingParameters, applicationId); }
private void detectApplicationFileDigestChanges(ExecutionWrapper execution, CloudApplication app, File applicationFile, CloudControllerClient client) { CloudApplication existingApp = client.getApplication(app.getName()); ApplicationFileDigestDetector applicationFileDigestDetector = new ApplicationFileDigestDetector(existingApp); String appNewFileDigest = applicationFileDigestDetector.detectNewAppFileDigest(applicationFile); String currentFileDigest = applicationFileDigestDetector.detectCurrentAppFileDigest(); attemptToUpdateApplicationDigest(client, app, appNewFileDigest, currentFileDigest); setAppContentChanged(execution, hasAppFileDigestChanged(appNewFileDigest, currentFileDigest)); }
private void detectApplicationFileDigestChanges(ExecutionWrapper execution, CloudApplication app, File applicationFile, CloudControllerClient client) { CloudApplication existingApp = client.getApplication(app.getName()); ApplicationFileDigestDetector applicationFileDigestDetector = new ApplicationFileDigestDetector(existingApp); String appNewFileDigest = applicationFileDigestDetector.detectNewAppFileDigest(applicationFile); String currentFileDigest = applicationFileDigestDetector.detectCurrentAppFileDigest(); attemptToUpdateApplicationDigest(client, app, appNewFileDigest, currentFileDigest); setAppContentChanged(execution, hasAppFileDigestChanged(appNewFileDigest, currentFileDigest)); }
private void attemptToBindService(CloudControllerClient client, String appName, String serviceName, Map<String, Object> parameters) { String serviceBindingsUrl = getUrl(client.getCloudControllerUrl() .toString(), SERVICE_BINDINGS_ENDPOINT); CloudApplication cloudApplication = client.getApplication(appName); UUID appGuid = cloudApplication.getMeta() .getGuid(); CloudService cloudService = client.getService(serviceName); UUID serviceGuid = cloudService.getMeta() .getGuid(); Map<String, Object> request = createServiceBindingRequest(appGuid, serviceGuid, parameters); RestTemplate restTemplate = getRestTemplate(client); restTemplate.postForObject(serviceBindingsUrl, request, String.class); }
private List<ApplicationLog> attemptToGetRecentLogs(CloudControllerClient client, String appName) { UUID applicationGuid = client.getApplication(appName) .getMeta() .getGuid(); String dopplerEndpoint = getDopplerEndpoint(loggingEndpointGetter.getLoggingEndpoint(client)); String recentLogsUrl = dopplerEndpoint + "/apps/{guid}/recentlogs"; ResponseEntity<Resource> responseResource = getRestTemplate(client).exchange(recentLogsUrl, HttpMethod.GET, null, Resource.class, applicationGuid); List<LogMessageConverter> logMessages = null; try { logMessages = extractLogMessages(responseResource); } catch (InvalidProtocolBufferException e) { throw new SLException(e, Messages.ERROR_READING_PROTOCOL_BUFFER_LOGS); } catch (IOException e) { throw new SLException(e, Messages.ERROR_RETRIEVING_RECENT_LOGS); } return convertToApplicationLogs(logMessages); }
private StartupStatus getStartupStatus(ExecutionWrapper execution, CloudControllerClient client, String appName) { CloudApplication app = client.getApplication(appName); List<InstanceInfo> instances = getApplicationInstances(client, app); // The default value here is provided for undeploy processes: boolean failOnCrashed = StepsUtil.getVariableOrDefault(execution.getContext(), Constants.PARAM_FAIL_ON_CRASHED, true); if (instances != null) { int expectedInstances = app.getInstances(); int runningInstances = getInstanceCount(instances, InstanceState.RUNNING); int flappingInstances = getInstanceCount(instances, InstanceState.FLAPPING); int crashedInstances = getInstanceCount(instances, InstanceState.CRASHED); int startingInstances = getInstanceCount(instances, InstanceState.STARTING); showInstancesStatus(execution, appName, instances, runningInstances, expectedInstances); if (runningInstances == expectedInstances) { return StartupStatus.STARTED; } if (startingInstances > 0) { return StartupStatus.STARTING; } if (flappingInstances > 0) { return StartupStatus.FLAPPING; } if (crashedInstances > 0 && failOnCrashed) { return StartupStatus.CRASHED; } } return StartupStatus.STARTING; }
private StartupStatus getStartupStatus(ExecutionWrapper execution, CloudControllerClient client, String appName) { CloudApplication app = client.getApplication(appName); List<InstanceInfo> instances = getApplicationInstances(client, app); // The default value here is provided for undeploy processes: boolean failOnCrashed = StepsUtil.getVariableOrDefault(execution.getContext(), Constants.PARAM_FAIL_ON_CRASHED, true); if (instances != null) { int expectedInstances = app.getInstances(); int runningInstances = getInstanceCount(instances, InstanceState.RUNNING); int flappingInstances = getInstanceCount(instances, InstanceState.FLAPPING); int crashedInstances = getInstanceCount(instances, InstanceState.CRASHED); int startingInstances = getInstanceCount(instances, InstanceState.STARTING); showInstancesStatus(execution, appName, instances, runningInstances, expectedInstances); if (runningInstances == expectedInstances) { return StartupStatus.STARTED; } if (startingInstances > 0) { return StartupStatus.STARTING; } if (flappingInstances > 0) { return StartupStatus.FLAPPING; } if (crashedInstances > 0 && failOnCrashed) { return StartupStatus.CRASHED; } } return StartupStatus.STARTING; }
@Override protected StepPhase executeStep(ExecutionWrapper execution) { // Get the next cloud application from the context: CloudApplication app = StepsUtil.getApp(execution.getContext()); try { getStepLogger().debug(Messages.CHECKING_APP, app.getName()); CloudControllerClient client = execution.getControllerClient(); // Check if an application with this name already exists, and store it in the context: CloudApplication existingApp = client.getApplication(app.getName(), false); StepsUtil.setExistingApp(execution.getContext(), existingApp); if (existingApp == null) { getStepLogger().debug(Messages.APP_DOES_NOT_EXIST, app.getName()); } else { getStepLogger().debug(Messages.APP_EXISTS, app.getName()); } return StepPhase.DONE; } catch (SLException e) { getStepLogger().error(e, Messages.ERROR_CHECKING_APP, app.getName()); throw e; } catch (CloudOperationException coe) { CloudControllerException e = new CloudControllerException(coe); getStepLogger().error(e, Messages.ERROR_CHECKING_APP, app.getName()); throw e; } }
@Override protected StepPhase executeStep(ExecutionWrapper execution) { // Get the next cloud application from the context: CloudApplication app = StepsUtil.getApp(execution.getContext()); try { getStepLogger().debug(Messages.CHECKING_APP, app.getName()); CloudControllerClient client = execution.getControllerClient(); // Check if an application with this name already exists, and store it in the context: CloudApplication existingApp = client.getApplication(app.getName(), false); StepsUtil.setExistingApp(execution.getContext(), existingApp); if (existingApp == null) { getStepLogger().debug(Messages.APP_DOES_NOT_EXIST, app.getName()); } else { getStepLogger().debug(Messages.APP_EXISTS, app.getName()); } return StepPhase.DONE; } catch (SLException e) { getStepLogger().error(e, Messages.ERROR_CHECKING_APP, app.getName()); throw e; } catch (CloudOperationException coe) { CloudControllerException e = new CloudControllerException(coe); getStepLogger().error(e, Messages.ERROR_CHECKING_APP, app.getName()); throw e; } }