public String getNameOfV2Resource(Map<String, Object> resource) { return getAttributeOfV2Resource(resource, "name", String.class); }
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 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 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 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 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; }
@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; }
@SuppressWarnings("unchecked") private List<SecurityGroupRule> getSecurityGroupRules(Map<String, Object> resource) { List<SecurityGroupRule> rules = new ArrayList<SecurityGroupRule>(); List<Map<String, Object>> jsonRules = getAttributeOfV2Resource(resource, "rules", List.class); for (Map<String, Object> jsonRule : jsonRules) { rules.add(new SecurityGroupRule((String) jsonRule.get("protocol"), (String) jsonRule.get("ports"), (String) jsonRule.get("destination"), (Boolean) jsonRule.get("log"), (Integer) jsonRule.get("type"), (Integer) jsonRule.get("code"))); } return rules; }
private List<String> findApplicationUris(UUID appGuid) { String urlPath = "/v2/apps/{app}/routes?inline-relations-depth=1"; Map<String, Object> urlVars = new HashMap<String, Object>(); urlVars.put("app", appGuid); List<Map<String, Object>> resourceList = getAllResources(urlPath, urlVars); List<String> uris = new ArrayList<String>(); for (Map<String, Object> resource : resourceList) { Map<String, Object> domainResource = CloudEntityResourceMapper.getEmbeddedResource(resource, "domain"); String host = CloudEntityResourceMapper.getAttributeOfV2Resource(resource, "host", String.class); String domain = CloudEntityResourceMapper.getAttributeOfV2Resource(domainResource, "name", String.class); if (host != null && host.length() > 0) uris.add(host + "." + domain); else uris.add(domain); } return uris; }
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); }
@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 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; }
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 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 CloudServiceBrokerExtended toCloudServiceBroker(Map<String, Object> resource) { CloudServiceBroker serviceBroker = resourceMapper.mapResource(resource, CloudServiceBroker.class); String spaceGuid = CloudEntityResourceMapper.getAttributeOfV2Resource(resource, "space_guid", String.class); return toCloudServiceBrokerExtended(serviceBroker, spaceGuid); }
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 CloudStack mapStackResource(Map<String, Object> resource) { return new CloudStack(getV2Meta(resource), getNameOfV2Resource(resource), getAttributeOfV2Resource(resource, "description", String.class)); }
@SuppressWarnings("unchecked") private CloudApplication mapCloudApplication(Map<String, Object> resource) { UUID appId = resourceMapper.getGuidOfV2Resource(resource); CloudApplication cloudApp = null; if (resource != null) { int running = getRunningInstances(appId, CloudApplication.AppState.valueOf(CloudEntityResourceMapper.getAttributeOfV2Resource(resource, "state", String.class))); ((Map<String, Object>) resource.get("entity")).put("running_instances", running); cloudApp = resourceMapper.mapResource(resource, CloudApplication.class); cloudApp.setUris(findApplicationUris(cloudApp.getMeta() .getGuid())); } return cloudApp; }
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 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); }