public UUID getGuidOfV2Resource(Map<String, Object> resource) { return getV2Meta(resource).getGuid(); }
private CloudJob mapJobResource(Map<String, Object> resource) { String status = getAttributeOfV2Resource(resource, "status", String.class); @SuppressWarnings("unchecked") Map<String, Object> errorDetailsResource = getAttributeOfV2Resource(resource, "error_details", Map.class); ErrorDetails errorDetails = null; if (errorDetailsResource != null) { Long code = Long.valueOf(String.valueOf(errorDetailsResource.get("code"))); String description = (String) errorDetailsResource.get("description"); String errorCode = (String) errorDetailsResource.get("error_code"); errorDetails = new ErrorDetails(code, description, errorCode); } return new CloudJob(getV2Meta(resource), CloudJob.Status.getEnum(status), errorDetails); }
private UUID doAddRoute(Map<String, String> uriInfo, UUID domainGuid) { assertSpaceProvided("add route"); HashMap<String, Object> routeRequest = new HashMap<String, Object>(); routeRequest.put("host", uriInfo.get("host")); routeRequest.put("path", uriInfo.get("path")); routeRequest.put("domain_guid", domainGuid); routeRequest.put("space_guid", sessionSpace.getMeta() .getGuid()); String routeResp = getRestTemplate().postForObject(getUrl("/v2/routes"), routeRequest, String.class); Map<String, Object> routeEntity = JsonUtil.convertJsonToMap(routeResp); return CloudEntityResourceMapper.getV2Meta(routeEntity) .getGuid(); }
@SuppressWarnings("unchecked") private ServiceKey mapServiceKeyResource(Map<String, Object> resource) { ServiceKey serviceKey = new ServiceKey(getV2Meta(resource), getAttributeOfV2Resource(resource, "name", String.class), null, getAttributeOfV2Resource(resource, "credentials", Map.class), null); return serviceKey; }
private UUID getRouteGuid(Map<String, String> uriInfo, UUID domainGuid) { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; urlPath = urlPath + "/routes?inline-relations-depth=0&q=host:{host}"; urlVars.put("host", uriInfo.get("host")); String path = uriInfo.get("path"); if (!StringUtils.isEmpty(path)) { urlPath = urlPath + "&q=path:{path}"; urlVars.put("path", path); } List<Map<String, Object>> allRoutes = getAllResources(urlPath, urlVars); UUID routeGuid = null; for (Map<String, Object> route : allRoutes) { UUID routeSpace = CloudEntityResourceMapper.getAttributeOfV2Resource(route, "space_guid", UUID.class); UUID routeDomain = CloudEntityResourceMapper.getAttributeOfV2Resource(route, "domain_guid", UUID.class); if (sessionSpace.getMeta() .getGuid() .equals(routeSpace) && domainGuid.equals(routeDomain)) { routeGuid = CloudEntityResourceMapper.getV2Meta(route) .getGuid(); } } return routeGuid; }
private CloudStack mapStackResource(Map<String, Object> resource) { return new CloudStack(getV2Meta(resource), getNameOfV2Resource(resource), getAttributeOfV2Resource(resource, "description", String.class)); }
private CloudRoute mapRouteResource(Map<String, Object> resource) { @SuppressWarnings("unchecked") List<Object> apps = getAttributeOfV2Resource(resource, "apps", List.class); String host = getAttributeOfV2Resource(resource, "host", String.class); CloudDomain domain = mapDomainResource(getEmbeddedResource(resource, "domain")); return new CloudRoute(getV2Meta(resource), host, domain, apps.size()); }
private CloudSpace mapSpaceResource(Map<String, Object> resource) { Map<String, Object> organizationMap = getEmbeddedResource(resource, "organization"); CloudOrganization organization = null; if (organizationMap != null) { organization = mapOrganizationResource(organizationMap); } return new CloudSpace(getV2Meta(resource), getNameOfV2Resource(resource), organization); }
private CloudServiceBroker mapServiceBrokerResource(Map<String, Object> resource) { return new CloudServiceBroker(getV2Meta(resource), getAttributeOfV2Resource(resource, "name", String.class), getAttributeOfV2Resource(resource, "broker_url", String.class), getAttributeOfV2Resource(resource, "auth_username", String.class)); }
private CloudSecurityGroup mapApplicationSecurityGroupResource(Map<String, Object> resource) { return new CloudSecurityGroup(getV2Meta(resource), getNameOfV2Resource(resource), getSecurityGroupRules(resource), getAttributeOfV2Resource(resource, "running_default", Boolean.class), getAttributeOfV2Resource(resource, "staging_default", Boolean.class)); }
private CloudOrganization mapOrganizationResource(Map<String, Object> resource) { Boolean billingEnabled = getAttributeOfV2Resource(resource, "billing_enabled", Boolean.class); Map<String, Object> quotaDefinition = getEmbeddedResource(resource, "quota_definition"); CloudQuota quota = null; if (quotaDefinition != null) { quota = mapQuotaResource(quotaDefinition); } return new CloudOrganization(getV2Meta(resource), getNameOfV2Resource(resource), quota, billingEnabled); }
private CloudUser mapUserResource(Map<String, Object> resource) { boolean isActiveUser = getAttributeOfV2Resource(resource, "active", Boolean.class); boolean isAdminUser = getAttributeOfV2Resource(resource, "admin", Boolean.class); String defaultSpaceGuid = getAttributeOfV2Resource(resource, "default_space_guid", String.class); String username = getAttributeOfV2Resource(resource, "username", String.class); return new CloudUser(getV2Meta(resource), username, isAdminUser, isActiveUser, defaultSpaceGuid); }
private CloudQuota mapQuotaResource(Map<String, Object> resource) { Boolean nonBasicServicesAllowed = getAttributeOfV2Resource(resource, "non_basic_services_allowed", Boolean.class); int totalServices = getAttributeOfV2Resource(resource, "total_services", Integer.class); int totalRoutes = getAttributeOfV2Resource(resource, "total_routes", Integer.class); long memoryLimit = getAttributeOfV2Resource(resource, "memory_limit", Long.class); return new CloudQuota(getV2Meta(resource), getNameOfV2Resource(resource), nonBasicServicesAllowed, totalServices, totalRoutes, memoryLimit); }
private CloudDomain mapDomainResource(Map<String, Object> resource) { @SuppressWarnings("unchecked") Map<String, Object> ownerResource = getAttributeOfV2Resource(resource, "owning_organization", Map.class); CloudOrganization owner; if (ownerResource == null) { owner = new CloudOrganization(CloudEntity.Meta.defaultMeta(), "none"); } else { owner = mapOrganizationResource(ownerResource); } return new CloudDomain(getV2Meta(resource), getNameOfV2Resource(resource), owner); }
@SuppressWarnings("unchecked") private CloudServiceBinding mapServiceBinding(Map<String, Object> resource) { CloudServiceBinding binding = new CloudServiceBinding(getV2Meta(resource), getNameOfV2Resource(resource)); binding.setAppGuid(UUID.fromString(getAttributeOfV2Resource(resource, "app_guid", String.class))); binding.setSyslogDrainUrl(getAttributeOfV2Resource(resource, "syslog_drain_url", String.class)); binding.setCredentials(getAttributeOfV2Resource(resource, "credentials", Map.class)); binding.setBindingOptions(getAttributeOfV2Resource(resource, "binding_options", Map.class)); return binding; }
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)); }
@SuppressWarnings("unchecked") private CloudServiceInstance mapServiceInstanceResource(Map<String, Object> resource) { CloudServiceInstance serviceInstance = new CloudServiceInstance(getV2Meta(resource), getNameOfV2Resource(resource)); serviceInstance.setType(getAttributeOfV2Resource(resource, "type", String.class)); serviceInstance.setDashboardUrl(getAttributeOfV2Resource(resource, "dashboard_url", String.class)); serviceInstance.setCredentials(getAttributeOfV2Resource(resource, "credentials", Map.class)); Map<String, Object> servicePlanResource = getEmbeddedResource(resource, "service_plan"); if (servicePlanResource != null) { serviceInstance.setServicePlan(mapServicePlanResource(servicePlanResource)); } CloudService service = mapServiceResource(resource); serviceInstance.setService(service); List<Map<String, Object>> bindingsResource = getEmbeddedResourceList(getEntity(resource), "service_bindings"); List<CloudServiceBinding> bindings = new ArrayList<>(bindingsResource.size()); for (Map<String, Object> bindingResource : bindingsResource) { bindings.add(mapServiceBinding(bindingResource)); } serviceInstance.setBindings(bindings); return serviceInstance; }
private CloudService mapServiceResource(Map<String, Object> resource) { CloudService cloudService = new CloudService(getV2Meta(resource), getNameOfV2Resource(resource)); Map<String, Object> servicePlanResource = getEmbeddedResource(resource, "service_plan"); if (servicePlanResource != null) { cloudService.setPlan(getAttributeOfV2Resource(servicePlanResource, "name", String.class)); Map<String, Object> serviceResource = getEmbeddedResource(servicePlanResource, "service"); if (serviceResource != null) { cloudService.setLabel(getAttributeOfV2Resource(serviceResource, "label", String.class)); cloudService.setProvider(getAttributeOfV2Resource(serviceResource, "provider", String.class)); cloudService.setVersion(getAttributeOfV2Resource(serviceResource, "version", String.class)); } } return cloudService; }
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 CloudEvent mapEventResource(Map<String, Object> resource) { CloudEvent event = new CloudEvent(getV2Meta(resource), getNameOfV2Resource(resource)); event.setType(getAttributeOfV2Resource(resource, "type", String.class)); event.setActor(getAttributeOfV2Resource(resource, "actor", String.class)); event.setActorType(getAttributeOfV2Resource(resource, "actor_type", String.class)); event.setActorName(getAttributeOfV2Resource(resource, "actor_name", String.class)); event.setActee(getAttributeOfV2Resource(resource, "actee", String.class)); event.setActeeType(getAttributeOfV2Resource(resource, "actee_type", String.class)); event.setActeeName(getAttributeOfV2Resource(resource, "actee_name", String.class)); Date timestamp = parseDate(getAttributeOfV2Resource(resource, "timestamp", String.class)); event.setTimestamp(timestamp); return event; }