private Map<String, CloudApplication> createExistingApplicationsMap(List<CloudApplication> existingApps) { Map<String, CloudApplication> applicationsMap = new HashMap<>(existingApps.size()); existingApps.forEach(app -> applicationsMap.put(app.getName(), app)); return applicationsMap; }
private StartingInfo startApp(CloudControllerClient client, CloudApplication app) { getStepLogger().info(Messages.STARTING_APP, app.getName()); if (client instanceof XsCloudControllerClient) { return ((XsCloudControllerClient) client).startApplication(app.getName(), false); } return client.startApplication(app.getName()); }
private boolean deployedMtaContainsApplication(DeployedMta deployedMta, CloudApplication existingApp) { String appName = existingApp.getName(); return deployedMta != null && deployedMta.getModules() .stream() .anyMatch(module -> module.getAppName() .equals(appName)); }
static void saveAppLogs(DelegateExecution context, CloudControllerClient client, RecentLogsRetriever recentLogsRetriever, CloudApplication app, Logger logger, ProcessLoggerProvider processLoggerProvider) { List<ApplicationLog> recentLogs = recentLogsRetriever.getRecentLogs(client, app.getName()); if (recentLogs != null) { recentLogs.forEach(log -> appLog(context, app.getName(), log.toString(), logger, processLoggerProvider)); } }
@Override public void onError(String description) { getStepLogger().error(Messages.ERROR_UPLOADING_APP_BECAUSE_OF, app.getName(), description); cleanUp(file.toPath()); }
private boolean unbindNotRequiredServices(CloudApplication app, List<String> requiredServices, CloudControllerClient client) { boolean hasUnbindedService = false; for (String serviceName : app.getServices()) { if (!requiredServices.contains(serviceName)) { unbindService(app.getName(), serviceName, client); hasUnbindedService = true; } } return hasUnbindedService; }
private void deleteApplicationRoutes(CloudApplication app, CloudControllerClient client) { getStepLogger().info(Messages.DELETING_APP_ROUTES, app.getName()); List<CloudRoute> appRoutes = applicationRoutesGetter.getRoutes(client, app.getName()); getStepLogger().debug(Messages.ROUTES_FOR_APPLICATION, app.getName(), JsonUtil.toJson(appRoutes)); client.updateApplicationUris(app.getName(), Collections.emptyList()); app.getUris() .stream() .forEach(uri -> deleteApplicationRoutes(appRoutes, uri, client)); getStepLogger().debug(Messages.DELETED_APP_ROUTES, app.getName()); }
@Override public void deleteAllApplications() { List<CloudApplication> cloudApps = getApplications(); for (CloudApplication cloudApp : cloudApps) { deleteApplication(cloudApp.getName()); } }
@Override public void deleteAllApplications() { List<CloudApplication> cloudApps = getApplications(); for (CloudApplication cloudApp : cloudApps) { deleteApplication(cloudApp.getName()); } }
private void stopApplicationIfSpecified(ExecutionWrapper execution, CloudControllerClient client, CloudApplication app, ApplicationAttributes appAttributes) { boolean stopApp = appAttributes.get(SupportedParameters.STOP_APP, Boolean.class, false); if (!stopApp) { return; } execution.getStepLogger() .info(Messages.STOPPING_APP, app.getName()); client.stopApplication(app.getName()); execution.getStepLogger() .debug(Messages.APP_STOPPED, app.getName()); }
private ApplicationStartupState computeCurrentState(ExecutionWrapper execution, CloudApplication app) { CloudControllerClient client = execution.getControllerClient(); return appStateCalculatorSupplier.get() .computeCurrentState(client.getApplication(app.getName())); }
private void restartSubscriber(ExecutionWrapper execution, CloudApplication subscriber) { try { attemptToRestartApplication(execution, subscriber); } catch (CloudOperationException e) { getStepLogger().warn(e, Messages.COULD_NOT_RESTART_SUBSCRIBER_0, subscriber.getName()); } }
private void reportAssignedUris(CloudApplication app) { for (String uri : app.getUris()) { getStepLogger().info(Messages.ASSIGNING_URI, uri, app.getName()); } }
private AsyncExecutionState checkStagingState(ExecutionWrapper execution, CloudApplication app, StagingState state) { if (state.getState().equals(PackageState.FAILED)) { // Application staging failed String message = format(Messages.ERROR_STAGING_APP_2, app.getName(), state.getError()); execution.getStepLogger() .error(message); return AsyncExecutionState.ERROR; } // Application not staged yet, wait and try again unless it's a timeout. return AsyncExecutionState.RUNNING; }
private StepPhase attemptToExecuteTask(ExecutionWrapper execution, CloudApplication app, CloudTask taskToExecute) { CloudControllerClient client = execution.getControllerClient(); getStepLogger().info(Messages.EXECUTING_TASK_ON_APP, taskToExecute.getName(), app.getName()); CloudTask startedTask = client.runTask(app.getName(), taskToExecute); StepsUtil.setStartedTask(execution.getContext(), startedTask); execution.getContext() .setVariable(Constants.VAR_START_TIME, currentTimeSupplier.get()); return StepPhase.POLL; }
private StepPhase attemptToExecuteStep(ExecutionWrapper execution) { CloudApplication app = StepsUtil.getApp(execution.getContext()); ApplicationStartupState currentState = computeCurrentState(execution, app); getStepLogger().debug(Messages.CURRENT_STATE, app.getName(), currentState); ApplicationStartupState desiredState = computeDesiredState(execution.getContext(), app); getStepLogger().debug(Messages.DESIRED_STATE, app.getName(), desiredState); Set<ApplicationStateAction> actionsToExecute = getActionsCalculator(execution.getContext()).determineActionsToExecute(currentState, desiredState); getStepLogger().debug(Messages.ACTIONS_TO_EXECUTE, app.getName(), actionsToExecute); StepsUtil.setAppStateActionsToExecute(execution.getContext(), actionsToExecute); return StepPhase.DONE; }
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)); }
@Override protected StepPhase executeAsyncStep(ExecutionWrapper execution) { CloudApplication app = StepsUtil.getApp(execution.getContext()); try { ApplicationStager applicationStager = ApplicationStagerFactory.createApplicationStager(configuration.getPlatformType()); return applicationStager.stageApp(execution.getContext(), execution.getControllerClient(), app, getStepLogger()); } catch (CloudOperationException coe) { CloudControllerException e = new CloudControllerException(coe); getStepLogger().error(e, Messages.ERROR_STAGING_APP_1, app.getName()); throw e; } }