private Boolean checkIfPlanExist(String planName, String serviceLabel){ for(CloudServicePlan csp : findCloudServiceOffering(serviceLabel).getCloudServicePlans()){ if(csp.getMeta().equals(serviceLabel)) return true; } return false; }
private boolean containsPlan(List<CloudServicePlan> plans, String servicePlanName) { return plans.stream() .filter(p -> servicePlanName.equalsIgnoreCase(p.getName())) .findFirst() .isPresent(); }
private CloudServicePlan mapServicePlanResource(Map<String, Object> servicePlanResource) { Boolean publicPlan = getEntityAttribute(servicePlanResource, "public", Boolean.class); return new CloudServicePlan( getMeta(servicePlanResource), getEntityAttribute(servicePlanResource, "name", String.class), getEntityAttribute(servicePlanResource, "description", String.class), getEntityAttribute(servicePlanResource, "free", Boolean.class), publicPlan == null ? true : publicPlan, getEntityAttribute(servicePlanResource, "extra", String.class), getEntityAttribute(servicePlanResource, "unique_id", String.class)); }
private CloudServiceOffering mapServiceOfferingResource(Map<String, Object> resource) { CloudServiceOffering cloudServiceOffering = new CloudServiceOffering( getMeta(resource), getEntityAttribute(resource, "label", String.class), getEntityAttribute(resource, "provider", String.class), getEntityAttribute(resource, "version", String.class), getEntityAttribute(resource, "description", String.class), getEntityAttribute(resource, "active", Boolean.class), getEntityAttribute(resource, "bindable", Boolean.class), getEntityAttribute(resource, "url", String.class), getEntityAttribute(resource, "info_url", String.class), getEntityAttribute(resource, "unique_id", String.class), getEntityAttribute(resource, "extra", String.class), getEntityAttribute(resource, "documentation_url", String.class)); List<Map<String, Object>> servicePlanList = getEmbeddedResourceList(getEntity(resource), "service_plans"); if (servicePlanList != null) { for (Map<String, Object> servicePlanResource : servicePlanList) { CloudServicePlan servicePlan = mapServicePlanResource(servicePlanResource); servicePlan.setServiceOffering(cloudServiceOffering); cloudServiceOffering.addCloudServicePlan(servicePlan); } } return cloudServiceOffering; }
private CloudServicePlan mapServicePlanResource(Map<String, Object> servicePlanResource) { Boolean publicPlan = getAttributeOfV2Resource(servicePlanResource, "public", Boolean.class); return new CloudServicePlan(getV2Meta(servicePlanResource), getAttributeOfV2Resource(servicePlanResource, "name", String.class), getAttributeOfV2Resource(servicePlanResource, "description", String.class), getAttributeOfV2Resource(servicePlanResource, "free", Boolean.class), publicPlan == null ? true : publicPlan, getAttributeOfV2Resource(servicePlanResource, "extra", String.class), getAttributeOfV2Resource(servicePlanResource, "unique_id", String.class)); }
private CloudServiceOffering mapServiceOfferingResource(Map<String, Object> resource) { CloudServiceOffering cloudServiceOffering = new CloudServiceOffering(getV2Meta(resource), getAttributeOfV2Resource(resource, "label", String.class), getAttributeOfV2Resource(resource, "provider", String.class), getAttributeOfV2Resource(resource, "version", String.class), getAttributeOfV2Resource(resource, "description", String.class), getAttributeOfV2Resource(resource, "active", Boolean.class), getAttributeOfV2Resource(resource, "bindable", Boolean.class), getAttributeOfV2Resource(resource, "url", String.class), getAttributeOfV2Resource(resource, "info_url", String.class), getAttributeOfV2Resource(resource, "unique_id", String.class), getAttributeOfV2Resource(resource, "extra", String.class), getAttributeOfV2Resource(resource, "documentation_url", String.class)); List<Map<String, Object>> servicePlanList = getEmbeddedResourceList(getEntity(resource), "service_plans"); if (servicePlanList != null) { for (Map<String, Object> servicePlanResource : servicePlanList) { CloudServicePlan servicePlan = mapServicePlanResource(servicePlanResource); servicePlan.setServiceOffering(cloudServiceOffering); cloudServiceOffering.addCloudServicePlan(servicePlan); } } return cloudServiceOffering; }
private Map<String, Object> createServiceRequest(CloudServiceExtended service, String spaceId, CloudServicePlan cloudServicePlan) { Map<String, Object> serviceRequest = new HashMap<>(); serviceRequest.put(SPACE_GUID, spaceId); serviceRequest.put(SERVICE_NAME, service.getName()); serviceRequest.put(SERVICE_PLAN_GUID, cloudServicePlan.getMeta() .getGuid() .toString()); serviceRequest.put(SERVICE_PARAMETERS, service.getCredentials()); serviceRequest.put(SERVICE_TAGS, service.getTags()); return serviceRequest; }
private List<String> computeValidServiceOfferings(List<String> possibleServiceOfferings, String desiredServicePlan, Map<String, List<CloudServicePlan>> existingServiceOfferings) { List<String> validServiceOfferings = new ArrayList<>(); for (String possibleServiceOffering : possibleServiceOfferings) { if (!existingServiceOfferings.containsKey(possibleServiceOffering)) { userMessageLogger.warnWithoutProgressMessage("Service offering \"{0}\" does not exist", possibleServiceOffering); continue; } Optional<CloudServicePlan> existingCloudServicePlan = existingServiceOfferings.get(possibleServiceOffering) .stream() .filter(servicePlan -> desiredServicePlan.equals(servicePlan.getName())) .findFirst(); if (!existingCloudServicePlan.isPresent()) { userMessageLogger.warnWithoutProgressMessage("Service offering \"{0}\" does not provide service plan \"{1}\"", possibleServiceOffering, desiredServicePlan); continue; } validServiceOfferings.add(possibleServiceOffering); } return validServiceOfferings; }
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); }
protected CloudServicePlan findPlanForService(CloudControllerClient client, CloudService service, String newPlan) { List<CloudServiceOffering> offerings = getServiceOfferings(client, service); for (CloudServiceOffering offering : offerings) { for (CloudServicePlan plan : offering.getCloudServicePlans()) { if (plan.getName() .equals(newPlan)) { return plan; } } } throw new CloudOperationException(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.getReasonPhrase(), MessageFormat.format(Messages.NO_SERVICE_PLAN_FOUND, service.getName(), newPlan, service.getLabel())); }
@Override public void createService(CloudService service) { assertSpaceProvided("create service"); Assert.notNull(service, "Service must not be null"); Assert.notNull(service.getName(), "Service name must not be null"); Assert.notNull(service.getLabel(), "Service label must not be null"); Assert.notNull(service.getPlan(), "Service plan must not be null"); CloudServicePlan cloudServicePlan = findPlanForService(service); HashMap<String, Object> serviceRequest = new HashMap<String, Object>(); serviceRequest.put("space_guid", sessionSpace.getMeta().getGuid()); serviceRequest.put("name", service.getName()); serviceRequest.put("service_plan_guid", cloudServicePlan.getMeta().getGuid()); getRestTemplate().postForObject(getUrl("/v2/service_instances"), serviceRequest, String.class); }
private CloudServicePlan findPlanForService(CloudService service) { List<CloudServiceOffering> offerings = getServiceOfferings(service.getLabel()); for (CloudServiceOffering offering : offerings) { if (service.getVersion() == null || service.getVersion().equals(offering.getVersion())) { for (CloudServicePlan plan : offering.getCloudServicePlans()) { if (service.getPlan() != null && service.getPlan().equals(plan.getName())) { return plan; } } } } throw new IllegalArgumentException("Service plan " + service.getPlan() + " not found"); }
@Override public void createService(CloudService service) { assertSpaceProvided("create service"); Assert.notNull(service, "Service must not be null"); Assert.notNull(service.getName(), "Service name must not be null"); Assert.notNull(service.getLabel(), "Service label must not be null"); Assert.notNull(service.getPlan(), "Service plan must not be null"); CloudServicePlan cloudServicePlan = findPlanForService(service); HashMap<String, Object> serviceRequest = new HashMap<String, Object>(); serviceRequest.put("space_guid", sessionSpace.getMeta() .getGuid()); serviceRequest.put("name", service.getName()); serviceRequest.put("service_plan_guid", cloudServicePlan.getMeta() .getGuid()); getRestTemplate().postForObject(getUrl("/v2/service_instances"), serviceRequest, String.class); }
private CloudServicePlan findPlanForService(CloudService service) { List<CloudServiceOffering> offerings = getServiceOfferings(service.getLabel()); for (CloudServiceOffering offering : offerings) { if (service.getVersion() == null || service.getVersion() .equals(offering.getVersion())) { for (CloudServicePlan plan : offering.getCloudServicePlans()) { if (service.getPlan() != null && service.getPlan() .equals(plan.getName())) { return plan; } } } } throw new CloudOperationException(HttpStatus.NOT_FOUND, "Not Found", "Service plan " + service.getPlan() + " not found."); }