org.cloudfoundry.client.lib.domain.CloudApplication Java Examples
The following examples show how to use
org.cloudfoundry.client.lib.domain.CloudApplication.
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: StopAppStep.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Override public StepPhase executeStepInternal(ProcessContext context) { // Get the next cloud application from the context CloudApplication app = context.getVariable(Variables.APP_TO_PROCESS); // Get the existing application from the context CloudApplication existingApp = context.getVariable(Variables.EXISTING_APP); if (existingApp != null && !existingApp.getState() .equals(State.STOPPED)) { getStepLogger().info(Messages.STOPPING_APP, app.getName()); // Get a cloud foundry client CloudControllerClient client = context.getControllerClient(); // Stop the application client.stopApplication(app.getName()); getStepLogger().debug(Messages.APP_STOPPED, app.getName()); } else { getStepLogger().debug("Application \"{0}\" already stopped", app.getName()); } return StepPhase.DONE; }
Example #2
Source File: RawCloudApplicationTest.java From cf-java-client-sap with Apache License 2.0 | 6 votes |
private static CloudApplication buildApplication(Staging staging) { return ImmutableCloudApplication.builder() .metadata(RawCloudEntityTest.EXPECTED_METADATA) .name(RawCloudEntityTest.NAME) .uris(EXPECTED_URIS) .memory(MEMORY) .diskQuota(DISK_QUOTA) .instances(INSTANCES) .runningInstances(RUNNING_INSTANCES) .state(EXPECTED_STATE) .packageState(EXPECTED_PACKAGE_STATE) .stagingError(STAGING_ERROR) .staging(staging) .services(EXPECTED_SERVICES) .env(EXPECTED_ENVIRONMENT) .space(SPACE) .build(); }
Example #3
Source File: ScaleAppStep.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Override protected StepPhase executeStep(ProcessContext context) { CloudApplication app = context.getVariable(Variables.APP_TO_PROCESS); CloudApplication existingApp = context.getVariable(Variables.EXISTING_APP); getStepLogger().debug(Messages.SCALING_APP, app.getName()); CloudControllerClient client = context.getControllerClient(); String appName = app.getName(); Integer instances = (app.getInstances() != 0) ? app.getInstances() : null; if (instances != null && (existingApp == null || !instances.equals(existingApp.getInstances()))) { getStepLogger().info(Messages.SCALING_APP_0_TO_X_INSTANCES, appName, instances); client.updateApplicationInstances(appName, instances); } getStepLogger().debug(Messages.APP_SCALED, app.getName()); return StepPhase.DONE; }
Example #4
Source File: ApplicationStager.java From multiapps-controller with Apache License 2.0 | 6 votes |
public boolean isApplicationStagedCorrectly(CloudApplication app) { // TODO Remove the null filtering. // We are not sure if the controller is returning null for created_at or not, so after the proper v3 client adoption, // we should decide what to do with this filtering. List<CloudBuild> buildsForApplication = client.getBuildsForApplication(app.getMetadata() .getGuid()); if (containsNullMetadata(buildsForApplication)) { return false; } CloudBuild build = getLastBuild(buildsForApplication); if (build == null) { logger.debug(Messages.NO_BUILD_FOUND_FOR_APPLICATION, app.getName()); return false; } if (isBuildStagedCorrectly(build)) { return true; } logMessages(app, build); return false; }
Example #5
Source File: PollExecuteAppStatusExecution.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Override public AsyncExecutionState execute(ProcessContext context) { List<ApplicationStateAction> actions = context.getVariable(Variables.APP_STATE_ACTIONS_TO_EXECUTE); if (!actions.contains(ApplicationStateAction.EXECUTE)) { return AsyncExecutionState.FINISHED; } CloudApplication app = getNextApp(context); CloudControllerClient client = context.getControllerClient(); ApplicationAttributes appAttributes = ApplicationAttributes.fromApplication(app); AppExecutionDetailedStatus status = getAppExecutionStatus(context, client, appAttributes, app); ProcessLoggerProvider processLoggerProvider = context.getStepLogger() .getProcessLoggerProvider(); StepsUtil.saveAppLogs(context.getExecution(), client, recentLogsRetriever, app, LOGGER, processLoggerProvider); return checkAppExecutionStatus(context, client, app, appAttributes, status); }
Example #6
Source File: UpdateServiceBrokerSubscriberStep.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Override protected StepPhase executeStep(ProcessContext context) { CloudApplication serviceBrokerApplication = StepsUtil.getUpdatedServiceBrokerSubscriber(context); CloudServiceBroker serviceBroker = getServiceBrokerFromApp(context, serviceBrokerApplication); try { CloudControllerClient client = context.getControllerClient(); CloudServiceBroker existingServiceBroker = client.getServiceBroker(serviceBroker.getName(), false); if (existingServiceBroker == null) { getStepLogger().warn(MessageFormat.format(Messages.SERVICE_BROKER_DOES_NOT_EXIST, serviceBroker.getName())); } else { serviceBroker = ImmutableCloudServiceBroker.copyOf(serviceBroker) .withMetadata(existingServiceBroker.getMetadata()); updateServiceBroker(context, serviceBroker, client); } return StepPhase.DONE; } catch (CloudOperationException coe) { CloudControllerException e = new CloudControllerException(coe); getStepLogger().warn(MessageFormat.format(Messages.FAILED_SERVICE_BROKER_UPDATE, serviceBroker.getName()), e, ExceptionMessageTailMapper.map(configuration, CloudComponents.SERVICE_BROKERS, serviceBroker.getName())); return StepPhase.DONE; } }
Example #7
Source File: RestartSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Test public void testClientsForCorrectSpacesAreRequested() { // Given: List<CloudApplication> updatedSubscribers = new ArrayList<>(); updatedSubscribers.add(createCloudApplication("app", createCloudSpace("org", "space-foo"))); updatedSubscribers.add(createCloudApplication("app", createCloudSpace("org", "space-bar"))); context.setVariable(Variables.UPDATED_SUBSCRIBERS, updatedSubscribers); // When: step.execute(execution); // Then: Mockito.verify(clientProvider, Mockito.atLeastOnce()) .getControllerClient(eq(USER_NAME), eq("org"), eq("space-foo"), anyString()); Mockito.verify(clientProvider, Mockito.atLeastOnce()) .getControllerClient(eq(USER_NAME), eq("org"), eq("space-bar"), anyString()); }
Example #8
Source File: DeleteIdleRoutesStep.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Override protected StepPhase executeStep(ProcessContext context) { boolean deleteIdleRoutes = context.getVariable(Variables.DELETE_IDLE_URIS); CloudApplication existingApp = context.getVariable(Variables.EXISTING_APP); if (!deleteIdleRoutes || existingApp == null) { return StepPhase.DONE; } getStepLogger().debug(Messages.DELETING_IDLE_URIS); CloudControllerClient client = context.getControllerClient(); CloudApplication app = context.getVariable(Variables.APP_TO_PROCESS); deleteIdleRoutes(existingApp, client, app); getStepLogger().debug(Messages.IDLE_URIS_DELETED); return StepPhase.DONE; }
Example #9
Source File: PollStageAppStatusExecution.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Override public AsyncExecutionState execute(ProcessContext context) { CloudApplication application = context.getVariable(Variables.APP_TO_PROCESS); CloudControllerClient client = context.getControllerClient(); StepLogger stepLogger = context.getStepLogger(); stepLogger.debug(Messages.CHECKING_APP_STATUS, application.getName()); StagingState state = applicationStager.getStagingState(); stepLogger.debug(Messages.APP_STAGING_STATUS, application.getName(), state.getState()); ProcessLoggerProvider processLoggerProvider = stepLogger.getProcessLoggerProvider(); StepsUtil.saveAppLogs(context.getExecution(), client, recentLogsRetriever, application, LOGGER, processLoggerProvider); if (state.getState() != PackageState.STAGED) { return checkStagingState(context.getStepLogger(), application, state); } bindDropletToApplication(client, application); stepLogger.info(Messages.APP_STAGED, application.getName()); return AsyncExecutionState.FINISHED; }
Example #10
Source File: ApplicationServicesUpdater.java From multiapps-controller with Apache License 2.0 | 6 votes |
public List<String> updateApplicationServices(String applicationName, Map<String, Map<String, Object>> serviceNamesWithBindingParameters, ApplicationServicesUpdateCallback applicationServicesUpdateCallback) { CloudApplication application = getControllerClient().getApplication(applicationName); List<String> addServices = calculateServicesToAdd(serviceNamesWithBindingParameters.keySet(), application); bindServices(addServices, applicationName, serviceNamesWithBindingParameters, applicationServicesUpdateCallback); List<String> deleteServices = calculateServicesToDelete(serviceNamesWithBindingParameters.keySet(), application); unbindServices(deleteServices, applicationName, applicationServicesUpdateCallback); List<String> rebindServices = calculateServicesToRebind(serviceNamesWithBindingParameters, application); rebindServices(rebindServices, applicationName, serviceNamesWithBindingParameters, applicationServicesUpdateCallback); return getUpdatedServiceNames(addServices, deleteServices, rebindServices); }
Example #11
Source File: DeployedMtaEnvDetector.java From multiapps-controller with Apache License 2.0 | 6 votes |
private MtaMetadata getMtaMetadata(List<CloudApplication> applications) { String mtaId = null; String mtaNamespace = null; Version mtaVersion = null; for (CloudApplication application : applications) { MtaMetadata metadata = envMtaMetadataParser.parseMtaMetadata(application); if (mtaId == null) { mtaId = metadata.getId(); mtaNamespace = metadata.getNamespace(); } Version currentVersion = metadata.getVersion(); if (mtaVersion != null && !mtaVersion.equals(currentVersion)) { mtaVersion = null; break; } mtaVersion = currentVersion; } return ImmutableMtaMetadata.builder() .id(mtaId) .namespace(mtaNamespace) .version(mtaVersion) .build(); }
Example #12
Source File: ApplicationServicesUpdater.java From multiapps-controller with Apache License 2.0 | 6 votes |
protected List<String> calculateServicesToRebind(Map<String, Map<String, Object>> serviceNamesWithBindingParameters, CloudApplication application) { List<String> servicesToRebind = new ArrayList<>(); for (String serviceName : serviceNamesWithBindingParameters.keySet()) { if (!application.getServices() .contains(serviceName)) { continue; } CloudServiceInstance serviceInstance = getControllerClient().getServiceInstance(serviceName); Map<String, Object> newServiceBindingParameters = getNewServiceBindingParameters(serviceNamesWithBindingParameters, serviceInstance); if (hasServiceBindingChanged(application, serviceInstance, newServiceBindingParameters)) { servicesToRebind.add(serviceInstance.getName()); } } return servicesToRebind; }
Example #13
Source File: ApplicationStagerTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Test public void testStageIfNotFoundExceptionIsThrown() { CloudApplication app = createApplication(); CloudOperationException cloudOperationException = Mockito.mock(CloudOperationException.class); Mockito.when(cloudOperationException.getStatusCode()) .thenReturn(HttpStatus.NOT_FOUND); Mockito.when(client.createBuild(any(UUID.class))) .thenThrow(cloudOperationException); Assertions.assertThrows(CloudOperationException.class, () -> applicationStager.stageApp(app)); }
Example #14
Source File: EnvMtaMetadataValidator.java From multiapps-controller with Apache License 2.0 | 5 votes |
private void validateMtaMetadataIsPresent(CloudApplication application) { if (!application.getEnv() .keySet() .containsAll(MtaMetadataUtil.ENV_MTA_METADATA_FIELDS)) { throw new ContentException(Messages.MTA_METADATA_FOR_APP_0_IS_INCOMPLETE, application.getName()); } }
Example #15
Source File: PrepareToRestartServiceBrokerSubscribersStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Override protected StepPhase executeStep(ProcessContext context) { List<CloudApplication> serviceBrokersToRestart = context.getVariable(Variables.UPDATED_SERVICE_BROKER_SUBSCRIBERS); context.setVariable(Variables.UPDATED_SERVICE_BROKER_SUBSCRIBERS_COUNT, serviceBrokersToRestart.size()); context.setVariable(Variables.UPDATED_SERVICE_BROKER_SUBSCRIBERS_INDEX, 0); context.setVariable(Variables.INDEX_VARIABLE_NAME, Variables.UPDATED_SERVICE_BROKER_SUBSCRIBERS_INDEX.getName()); return StepPhase.DONE; }
Example #16
Source File: DeployedMtaEnvDetector.java From multiapps-controller with Apache License 2.0 | 5 votes |
private String getQualifiedMtaId(CloudApplication application) { MtaMetadata metadata = envMtaMetadataParser.parseMtaMetadata(application); if (StringUtils.isEmpty(metadata.getNamespace())) { return metadata.getId(); } return metadata.getNamespace() + Constants.NAMESPACE_SEPARATOR + metadata.getId(); }
Example #17
Source File: UpdateSubscribersStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
private CloudApplication addOrgAndSpaceIfNecessary(CloudApplication application, CloudTarget cloudTarget) { // The entity returned by the getApplication(String appName) method of // the CF Java client does not contain a CloudOrganization, // because the value of the 'inline-relations-depth' is hardcoded to 1 // (see the findApplicationResource method of // org.cloudfoundry.client.lib.rest.CloudControllerClientImpl). if (application.getSpace() == null || application.getSpace() .getOrganization() == null) { CloudSpace space = createDummySpace(cloudTarget); return ImmutableCloudApplication.copyOf(application) .withSpace(space); } return application; }
Example #18
Source File: ApplicationEnvironmentUpdaterTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
CloudApplication toCloudApplication() { return ImmutableCloudApplication.builder() .metadata(CloudMetadata.defaultMetadata()) .name(name) .env(ENV_CONVERTER.asEnv(env)) .build(); }
Example #19
Source File: ApplicationAttributeUpdater.java From multiapps-controller with Apache License 2.0 | 5 votes |
public UpdateState update(CloudApplication existingApplication, CloudApplication application) { if (!shouldUpdateAttribute(existingApplication, application)) { return UpdateState.UNCHANGED; } updateAttribute(existingApplication, application); return UpdateState.UPDATED; }
Example #20
Source File: DeleteApplicationStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Override protected StepPhase undeployApplication(CloudControllerClient client, CloudApplication cloudApplicationToUndeploy, ProcessContext context) { String applicationName = cloudApplicationToUndeploy.getName(); try { cancelRunningTasks(client, applicationName); deleteApplication(client, applicationName); } catch (CloudOperationException e) { ignoreApplicationNotFound(e, cloudApplicationToUndeploy.getName()); } return StepPhase.DONE; }
Example #21
Source File: DeleteServiceBrokersStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Override protected StepPhase executeStep(ProcessContext context) { getStepLogger().debug(Messages.DELETING_SERVICE_BROKERS); List<CloudApplication> appsToUndeploy = context.getVariable(Variables.APPS_TO_UNDEPLOY); CloudControllerClient client = context.getControllerClient(); List<String> createdOrUpdatedServiceBrokers = getCreatedOrUpdatedServiceBrokerNames(context); for (CloudApplication app : appsToUndeploy) { deleteServiceBrokerIfNecessary(context, app, createdOrUpdatedServiceBrokers, client); } getStepLogger().debug(Messages.SERVICE_BROKERS_DELETED); return StepPhase.DONE; }
Example #22
Source File: UpdateSubscribersStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
private List<CloudApplication> removeDuplicates(List<CloudApplication> applications) { Map<UUID, CloudApplication> applicationsMap = new LinkedHashMap<>(); for (CloudApplication application : applications) { applicationsMap.put(application.getMetadata() .getGuid(), application); } return new ArrayList<>(applicationsMap.values()); }
Example #23
Source File: MtaConfigurationPurger.java From multiapps-controller with Apache License 2.0 | 5 votes |
public void purge(String org, String space) { CloudTarget targetSpace = new CloudTarget(org, space); String targetId = new ClientHelper(client).computeSpaceId(org, space); List<CloudApplication> existingApps = getExistingApps(); purgeConfigurationSubscriptions(targetId, existingApps); purgeConfigurationEntries(targetSpace, existingApps); }
Example #24
Source File: PaasWebAppCloudFoundryDriver.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void setEnv(String key, String value) { CloudApplication app = getClient().getApplication(applicationName); // app.setEnv() replaces the entire set of variables, so we need to add it externally. Map envAsMap = app.getEnvAsMap(); envAsMap.put(key, value); app.setEnv(envAsMap); getClient().updateApplicationEnv(applicationName, envAsMap); }
Example #25
Source File: UpdateSubscribersStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Override protected StepPhase executeStep(ProcessContext context) { getStepLogger().debug(Messages.UPDATING_SUBSCRIBERS); List<ConfigurationEntry> publishedEntries = StepsUtil.getPublishedEntriesFromSubProcesses(context, flowableFacade); List<ConfigurationEntry> deletedEntries = StepsUtil.getDeletedEntriesFromAllProcesses(context, flowableFacade); List<ConfigurationEntry> updatedEntries = ListUtils.union(publishedEntries, deletedEntries); CloudControllerClient clientForCurrentSpace = context.getControllerClient(); List<CloudApplication> updatedSubscribers = new ArrayList<>(); List<CloudApplication> updatedServiceBrokerSubscribers = new ArrayList<>(); List<ConfigurationSubscription> subscriptions = configurationSubscriptionService.createQuery() .onSelectMatching(updatedEntries) .list(); for (ConfigurationSubscription subscription : subscriptions) { ClientHelper clientHelper = new ClientHelper(clientForCurrentSpace); CloudTarget target = targetCalculator.apply(clientHelper, subscription.getSpaceId()); if (target == null) { getStepLogger().warn(Messages.COULD_NOT_COMPUTE_ORG_AND_SPACE, subscription.getSpaceId()); continue; } CloudApplication updatedApplication = updateSubscriber(context, target, subscription); if (updatedApplication != null) { updatedApplication = addOrgAndSpaceIfNecessary(updatedApplication, target); addApplicationToProperList(updatedSubscribers, updatedServiceBrokerSubscribers, updatedApplication); } } context.setVariable(Variables.UPDATED_SUBSCRIBERS, removeDuplicates(updatedSubscribers)); context.setVariable(Variables.UPDATED_SERVICE_BROKER_SUBSCRIBERS, updatedServiceBrokerSubscribers); getStepLogger().debug(Messages.SUBSCRIBERS_UPDATED); return StepPhase.DONE; }
Example #26
Source File: CreateOrUpdateAppStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Override public void handleApplicationMetadata() { CloudApplication appFromController = client.getApplication(app.getName()); client.updateApplicationMetadata(appFromController.getMetadata() .getGuid(), app.getV3Metadata()); }
Example #27
Source File: PollExecuteAppStatusExecution.java From multiapps-controller with Apache License 2.0 | 5 votes |
private AppExecutionDetailedStatus getAppExecutionStatus(ProcessContext context, CloudControllerClient client, ApplicationAttributes appAttributes, CloudApplication app) { long startTime = context.getVariable(Variables.START_TIME); Marker sm = getMarker(appAttributes, SupportedParameters.SUCCESS_MARKER, DEFAULT_SUCCESS_MARKER); Marker fm = getMarker(appAttributes, SupportedParameters.FAILURE_MARKER, DEFAULT_FAILURE_MARKER); boolean checkDeployId = appAttributes.get(SupportedParameters.CHECK_DEPLOY_ID, Boolean.class, Boolean.FALSE); String deployId = checkDeployId ? (StepsUtil.DEPLOY_ID_PREFIX + context.getVariable(Variables.CORRELATION_ID)) : null; List<ApplicationLog> recentLogs = recentLogsRetriever.getRecentLogs(client, app.getName(), null); return recentLogs.stream() .map(log -> getAppExecutionStatus(log, startTime, sm, fm, deployId)) .filter(Objects::nonNull) .reduce(new AppExecutionDetailedStatus(AppExecutionStatus.EXECUTING), (a, b) -> b); }
Example #28
Source File: DeployedMtaEnvDetectorTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
@ParameterizedTest @MethodSource public void testGetAllDeployedMtas(String appsResourceLocation, Expectation expectation) throws IOException { List<CloudApplication> apps = parseApps(appsResourceLocation); prepareClient(apps); tester.test(() -> deployedMtaEnvDetector.detectDeployedMtas(client), expectation); }
Example #29
Source File: DeployedMtaDetectorTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private List<CloudApplication> parseApps(String appsResourceLocation) { if (appsResourceLocation == null) { return Collections.emptyList(); } String appsJson = TestUtil.getResourceAsString(appsResourceLocation, getClass()); List<TestCloudApplication> testApps = JsonUtil.fromJson(appsJson, new TypeReference<List<TestCloudApplication>>() { }); return toCloudApplications(testApps); }
Example #30
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private StepOutput captureStepOutput() { StepOutput result = new StepOutput(); result.callArgumentsOfUpdateApplicationEnvMethod = new ArrayList<>(); for (CloudSpace space : clients.keySet()) { if (userHasPermissions(space, UserPermission.READ, UserPermission.WRITE)) { List<CloudApplication> callArgumentsOfUpdateApplicationEnvMethod = getCallArgumentsOfUpdateApplicationEnvMethod(space, clients.get(space)); result.callArgumentsOfUpdateApplicationEnvMethod.addAll(callArgumentsOfUpdateApplicationEnvMethod); } } result.updatedSubscribers = context.getVariable(Variables.UPDATED_SUBSCRIBERS); return result; }