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()); } }
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()); } }
private MethodExecution<String> attemptToUpdateServicePlan(CloudControllerClient client, String serviceName, String servicePlanName) { CloudService service = client.getService(serviceName); CloudServicePlan servicePlan = findPlanForService(client, service, servicePlanName); String servicePlanGuid = servicePlan.getMeta().getGuid().toString(); return attemptToUpdateServiceParameter(client, serviceName, SERVICE_INSTANCES_URL, SERVICE_PLAN_GUID, servicePlanGuid); }
private MethodExecution<String> attemptToUpdateServiceParameter(CloudControllerClient client, String serviceName, String serviceUrl, String parameterName, Object parameter) { CloudService service = client.getService(serviceName); RestTemplate restTemplate = getRestTemplate(client); String cloudControllerUrl = getCloudControllerUrl(client); String updateServiceUrl = getUrl(cloudControllerUrl, getUpdateServiceUrl(serviceUrl, service.getMeta() .getGuid() .toString(), ACCEPTS_INCOMPLETE_TRUE)); Map<String, Object> serviceRequest = createUpdateServiceRequest(parameterName, parameter); HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(serviceRequest); ResponseEntity<String> response = restTemplate.exchange(updateServiceUrl, HttpMethod.PUT, requestEntity, String.class); return MethodExecution.fromResponseEntity(response); }
private MethodExecution<String> attemptToUpdateServiceParameters(CloudControllerClient client, String serviceName, Map<String, Object> parameters) { assertServiceAttributes(serviceName, parameters); CloudService service = client.getService(serviceName); if (service.isUserProvided()) { return attemptToUpdateServiceParameter(client, serviceName, USER_PROVIDED_SERVICE_INSTANCES_URL, SERVICE_CREDENTIALS, parameters); } return attemptToUpdateServiceParameter(client, serviceName, SERVICE_INSTANCES_URL, SERVICE_PARAMETERS, parameters); }
@Test public void testUpdateServicePlan1() throws MalformedURLException { CloudControllerClient client = getMockedClient(); Mockito.when(client.getService(EXISTING_SERVICE_NAME)) .thenReturn(EXISTING_SERVICE); serviceUpdater.updateServicePlan(client, EXISTING_SERVICE_NAME, "v3.0-small"); validatePlanUpdate("8e886beb-85cb-4455-9474-b6dfda36ffeb"); }
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); }
@Test public void testUpdateServicePlan2() { // Given: CloudControllerClient client = getMockedClient(); Mockito.when(client.getService(EXISTING_SERVICE_NAME)) .thenReturn(EXISTING_SERVICE); try { // When: serviceUpdater.updateServicePlan(client, EXISTING_SERVICE_NAME, "v3.0-large"); } catch (CloudOperationException e) { // Then: assertEquals( "404 Not Found: Could not create service instance \"foo\". Service plan \"v3.0-large\" from service offering \"mongodb\" was not found.", e.getMessage()); } }
@Test public void testUpdateServicePlan3() { // Given: CloudControllerClient client = getMockedClient(); Mockito.when(client.getService(EXISTING_SERVICE_NAME)) .thenThrow(new CloudOperationException(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.getReasonPhrase(), "Service \"foo\" was not found!")); try { // When: serviceUpdater.updateServicePlan(client, EXISTING_SERVICE_NAME, "v3.0-small"); } catch (CloudOperationException e) { // Then: assertEquals("404 Not Found: Service \"foo\" was not found!", e.getMessage()); } }
@Override protected StepPhase executeStep(ExecutionWrapper execution) throws Exception { CloudControllerClient controllerClient = execution.getControllerClient(); String spaceId = StepsUtil.getSpaceId(execution.getContext()); CloudServiceExtended serviceToProcess = StepsUtil.getServiceToProcess(execution.getContext()); execution.getStepLogger() .info(Messages.PROCESSING_SERVICE, serviceToProcess.getName()); CloudService existingService = controllerClient.getService(serviceToProcess.getName(), false); Map<String, List<String>> defaultTags = computeDefaultTags(controllerClient); List<String> serviceDefaultTags = defaultTags.getOrDefault(serviceToProcess.getLabel(), Collections.emptyList()); Map<String, List<ServiceKey>> serviceKeys = StepsUtil.getServiceKeysToCreate(execution.getContext()); List<ServiceAction> actions = determineActions(controllerClient, spaceId, serviceToProcess, existingService, serviceDefaultTags, serviceKeys, execution); StepsUtil.setServiceActionsToExecute(actions, execution.getContext()); StepsUtil.isServiceUpdated(false, execution.getContext()); StepsUtil.setServiceToProcessName(serviceToProcess.getName(), execution.getContext()); return StepPhase.DONE; }
@Override protected StepPhase executeStep(ExecutionWrapper execution) throws Exception { CloudControllerClient controllerClient = execution.getControllerClient(); String spaceId = StepsUtil.getSpaceId(execution.getContext()); CloudServiceExtended serviceToProcess = StepsUtil.getServiceToProcess(execution.getContext()); execution.getStepLogger() .info(Messages.PROCESSING_SERVICE, serviceToProcess.getName()); CloudService existingService = controllerClient.getService(serviceToProcess.getName(), false); Map<String, List<String>> defaultTags = computeDefaultTags(controllerClient); List<String> serviceDefaultTags = defaultTags.getOrDefault(serviceToProcess.getLabel(), Collections.emptyList()); Map<String, List<ServiceKey>> serviceKeys = StepsUtil.getServiceKeysToCreate(execution.getContext()); List<ServiceAction> actions = determineActions(controllerClient, spaceId, serviceToProcess, existingService, serviceDefaultTags, serviceKeys, execution); StepsUtil.setServiceActionsToExecute(actions, execution.getContext()); StepsUtil.isServiceUpdated(false, execution.getContext()); StepsUtil.setServiceToProcessName(serviceToProcess.getName(), execution.getContext()); return StepPhase.DONE; }