private List<CloudApplication> getExistingApps() { try { return client.getApplications(); } catch (CloudOperationException e) { throw new SLException(e, Messages.ERROR_GETTING_APPLICATIONS); } }
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 Map<String, CloudServiceExtended> getServicesData(List<String> serviceNames, ExecutionWrapper execution) { CloudControllerClient client = execution.getControllerClient(); return serviceNames.parallelStream() .map(name -> client.getService(name, false)) .filter(Objects::nonNull) .map(service -> new CloudServiceExtended(service.getMeta(), service.getName())) .collect(Collectors.toMap(e -> e.getName(), e -> e)); }
private void deleteServiceKeys(CloudControllerClient client, String serviceName) { CloudService service = client.getService(serviceName); if (service.isUserProvided()) { return; } List<ServiceKey> serviceKeys = client.getServiceKeys(serviceName); for (ServiceKey serviceKey : serviceKeys) { getStepLogger().info(Messages.DELETING_SERVICE_KEY_FOR_SERVICE, serviceKey.getName(), serviceName); client.deleteServiceKey(serviceName, serviceKey.getName()); } }
protected void deleteAllocatedRoutes(HistoryService historyService, String processInstanceId) { HistoricVariableInstance allocatedPortsInstance = getHistoricVarInstanceValue(historyService, processInstanceId, Constants.VAR_ALLOCATED_PORTS); if (allocatedPortsInstance == null) { return; } CloudControllerClient client = getCloudFoundryClient(historyService, processInstanceId); String defaultDomain = client.getDefaultDomain() != null ? client.getDefaultDomain() .getName() : null; if (defaultDomain == null) { LOGGER.warn(Messages.COULD_NOT_COMPUTE_DEFAULT_DOMAIN); return; } Integer[] allocatedPorts = JsonUtil.fromBinaryJson((byte[]) allocatedPortsInstance.getValue(), Integer[].class); for (Integer port : allocatedPorts) { try { client.deleteRoute(port.toString(), defaultDomain); } catch (CloudOperationException e) { LOGGER.warn(format(Messages.COULD_NOT_DELETE_ROUTE_FOR_PORT, port.toString())); } } }
private void unbindService(CloudControllerClient client, String serviceName) { CloudServiceInstance serviceInstance = client.getServiceInstance(serviceName); List<CloudServiceBinding> bindings = serviceInstance.getBindings(); if (bindings.isEmpty()) { return; } logBindings(bindings); for (CloudServiceBinding binding : bindings) { CloudApplication application = StepsUtil.getBoundApplication(client.getApplications(), binding.getAppGuid()); getStepLogger().info(Messages.UNBINDING_APP_FROM_SERVICE, application.getName(), serviceName); client.unbindService(application.getName(), serviceName); } }
CloudApplication existingApp = client.getApplication(app.getName(), false); .getImage()); client.createApplication(appName, staging, diskQuota, memory, uris, Collections.emptyList(), app.getDockerInfo()); client.updateApplicationEnv(appName, env);
client.updateApplicationStaging(appName, staging); appPropertiesChanged = true; client.updateApplicationMemory(appName, memory); appPropertiesChanged = true; client.updateApplicationDiskQuota(appName, diskQuota); appPropertiesChanged = true; client.updateApplicationUris(appName, uris); appPropertiesChanged = true; getStepLogger().debug("Updating env of application \"{0}\"", appName); getStepLogger().debug("Updated env: {0}", JsonUtil.toJson(env, true)); client.updateApplicationEnv(appName, env); userPropertiesChanged = true;
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); }
CloudApplication existingApplication = client.getApplication(subscription.getAppName()); client.updateApplicationEnv(existingApplication.getName(), currentEnvironment); return existingApplication;
private String getUrlForEndpoint(CloudControllerClient client, String endpoint) { return client.getCloudControllerUrl() + endpoint; }
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 prepareClient() throws IOException { URL controllerUrl = new URL(CONTROLLER_URL); Mockito.when(client.getCloudControllerUrl()) .thenReturn(controllerUrl); List<CloudServiceOffering> serviceOfferings = loadServiceOfferingsFromFile(SERVICE_OFFERINGS_RESPONSE_PATH); Mockito.when(client.getServiceOfferings()) .thenReturn(serviceOfferings); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); this.spaceGetter = new CFOptimizedSpaceGetter(restTemplateFactory); when(restTemplateFactory.getRestTemplate(client)).thenReturn(restTemplate); when(client.login()).thenReturn(new DefaultOAuth2AccessToken(DUMMY)); when(client.getCloudControllerUrl()).thenReturn(new URL(CONTROLLER_URL)); }
private void updateEnvironment(Map<String, Object> updatedEnv) { Map<String, String> asEnv = new MapToEnvironmentConverter(prettyPrinting).asEnv(updatedEnv); client.updateApplicationEnv(app.getName(), asEnv); }
private Stream<CloudSpace> filterSpaces(CloudControllerClient client, String orgName, String spaceName) { return client.getSpaces() .stream() .filter(space -> isSameSpace(space, orgName, spaceName)); }
private String getOrgGuid(CloudControllerClient client, String orgName) { if (orgName == null) { return null; } CloudOrganization org = client.getOrganization(orgName, false); return org != null ? org.getMeta() .getGuid() .toString() : null; }
private List<CloudServiceOffering> getServiceOfferings(CloudControllerClient client, CloudService service) { List<CloudServiceOffering> offerings = client.getServiceOfferings(); offerings = filterByLabel(offerings, service.getLabel()); offerings = filterByVersion(offerings, service.getVersion()); return offerings; }
private String computeAuthorizationToken() { return client.login() .toString(); }
public void deleteRoute(String uri, boolean portBasedRouting) { if (!portBasedRouting) { uri = UriUtil.removePort(uri); } Pair<String, String> hostAndDomain = UriUtil.getHostAndDomain(uri); if (client instanceof XsCloudControllerClient) { XsCloudControllerClient xsClient = (XsCloudControllerClient) client; xsClient.deleteRoute(hostAndDomain._1, hostAndDomain._2, UriUtil.getPath(uri)); } else { client.deleteRoute(hostAndDomain._1, hostAndDomain._2); } }