public String getNameOfResource(Map<String, Object> resource) { return getEntityAttribute(resource, "name", String.class); }
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 CloudUser mapUserResource(Map<String, Object> resource) { boolean isActiveUser = getEntityAttribute(resource, "active", Boolean.class); boolean isAdminUser = getEntityAttribute(resource, "admin", Boolean.class); String defaultSpaceGuid = getEntityAttribute(resource, "default_space_guid", String.class); String username = getEntityAttribute(resource, "username", String.class); return new CloudUser(getMeta(resource), username,isAdminUser,isActiveUser,defaultSpaceGuid); }
private CloudServiceBroker mapServiceBrokerResource(Map<String, Object> resource) { return new CloudServiceBroker(getMeta(resource), getEntityAttribute(resource, "name", String.class), getEntityAttribute(resource, "broker_url", String.class), getEntityAttribute(resource, "auth_username", String.class)); }
private CloudQuota mapQuotaResource(Map<String, Object> resource) { Boolean nonBasicServicesAllowed = getEntityAttribute(resource, "non_basic_services_allowed", Boolean.class); int totalServices = getEntityAttribute(resource, "total_services", Integer.class); int totalRoutes = getEntityAttribute(resource, "total_routes", Integer.class); long memoryLimit = getEntityAttribute(resource, "memory_limit", Long.class); return new CloudQuota(getMeta(resource), getNameOfResource(resource), nonBasicServicesAllowed, totalServices, totalRoutes, memoryLimit); }
private CloudJob mapJobResource(Map<String, Object> resource) { String status = getEntityAttribute(resource, "status", String.class); Map<String, Object> errorDetailsResource = (Map<String, Object>) resource.get("error_details"); CloudJob.ErrorDetails errorDetails = null; if (errorDetailsResource != null) { Long code = getEntityAttribute(errorDetailsResource, "code", Long.class); String description = getEntityAttribute(errorDetailsResource, "description", String.class); String errorCode = getEntityAttribute(errorDetailsResource, "error_code", String.class); errorDetails = new CloudJob.ErrorDetails(code, description, errorCode); } return new CloudJob(getMeta(resource), CloudJob.Status.getEnum(status), errorDetails); }
@SuppressWarnings("unchecked") private List<SecurityGroupRule> getSecurityGroupRules(Map<String, Object> resource){ List<SecurityGroupRule> rules = new ArrayList<SecurityGroupRule>(); List<Map<String, Object>> jsonRules = getEntityAttribute(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.getEntityAttribute(resource, "host", String.class); String domain = CloudEntityResourceMapper.getEntityAttribute(domainResource, "name", String.class); if (host != null && host.length() > 0) uris.add(host + "." + domain); else uris.add(domain); } return uris; }
@SuppressWarnings("unchecked") private CloudServiceBinding mapServiceBinding(Map<String, Object> resource) { CloudServiceBinding binding = new CloudServiceBinding(getMeta(resource), getNameOfResource(resource)); binding.setAppGuid(UUID.fromString(getEntityAttribute(resource, "app_guid", String.class))); binding.setSyslogDrainUrl(getEntityAttribute(resource, "syslog_drain_url", String.class)); binding.setCredentials(getEntityAttribute(resource, "credentials", Map.class)); binding.setBindingOptions(getEntityAttribute(resource, "binding_options", Map.class)); return binding; }
private CloudSecurityGroup mapApplicationSecurityGroupResource(Map<String, Object> resource) { return new CloudSecurityGroup(getMeta(resource), getNameOfResource(resource), getSecurityGroupRules(resource), getEntityAttribute(resource, "running_default", Boolean.class), getEntityAttribute(resource, "staging_default", Boolean.class)); }
private CloudEvent mapEventResource(Map<String, Object> resource) { CloudEvent event = new CloudEvent( getMeta(resource), getNameOfResource(resource)); event.setType(getEntityAttribute(resource, "type", String.class)); event.setActor(getEntityAttribute(resource, "actor", String.class)); event.setActorType(getEntityAttribute(resource, "actor_type", String.class)); event.setActorName(getEntityAttribute(resource, "actor_name", String.class)); event.setActee(getEntityAttribute(resource, "actee", String.class)); event.setActeeType(getEntityAttribute(resource, "actee_type", String.class)); event.setActeeName(getEntityAttribute(resource, "actee_name", String.class)); Date timestamp = parseDate(getEntityAttribute(resource, "timestamp", String.class)); event.setTimestamp(timestamp); return event; }
private CloudRoute mapRouteResource(Map<String, Object> resource) { @SuppressWarnings("unchecked") List<Object> apps = getEntityAttribute(resource, "apps", List.class); String host = getEntityAttribute(resource, "host", String.class); CloudDomain domain = mapDomainResource(getEmbeddedResource(resource, "domain")); return new CloudRoute(getMeta(resource), host, domain, apps.size()); }
private UUID getRouteGuid(String host, 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", host); List<Map<String, Object>> allRoutes = getAllResources(urlPath, urlVars); UUID routeGuid = null; for (Map<String, Object> route : allRoutes) { UUID routeSpace = CloudEntityResourceMapper.getEntityAttribute(route, "space_guid", UUID.class); UUID routeDomain = CloudEntityResourceMapper.getEntityAttribute(route, "domain_guid", UUID.class); if (sessionSpace.getMeta().getGuid().equals(routeSpace) && domainGuid.equals(routeDomain)) { routeGuid = CloudEntityResourceMapper.getMeta(route).getGuid(); } } return routeGuid; }
private Map<String, UUID> getDomainGuids() { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; if (sessionSpace != null) { urlVars.put("space", sessionSpace.getMeta().getGuid()); urlPath = urlPath + "/spaces/{space}"; } String domainPath = urlPath + "/domains?inline-relations-depth=1"; List<Map<String, Object>> resourceList = getAllResources(domainPath, urlVars); Map<String, UUID> domains = new HashMap<String, UUID>(resourceList.size()); for (Map<String, Object> d : resourceList) { domains.put( CloudEntityResourceMapper.getEntityAttribute(d, "name", String.class), CloudEntityResourceMapper.getMeta(d).getGuid()); } return domains; }
private CloudService mapServiceResource(Map<String, Object> resource) { CloudService cloudService = new CloudService(getMeta(resource), getNameOfResource(resource)); Map<String, Object> servicePlanResource = getEmbeddedResource(resource, "service_plan"); if (servicePlanResource != null) { cloudService.setPlan(getEntityAttribute(servicePlanResource, "name", String.class)); Map<String, Object> serviceResource = getEmbeddedResource(servicePlanResource, "service"); if (serviceResource != null) { cloudService.setLabel(getEntityAttribute(serviceResource, "label", String.class)); cloudService.setProvider(getEntityAttribute(serviceResource, "provider", String.class)); cloudService.setVersion(getEntityAttribute(serviceResource, "version", String.class)); } } return cloudService; }
private CloudStack mapStackResource(Map<String, Object> resource) { return new CloudStack(getMeta(resource), getNameOfResource(resource), getEntityAttribute(resource, "description", String.class)); }
@SuppressWarnings("unchecked") private CloudServiceInstance mapServiceInstanceResource(Map<String, Object> resource) { CloudServiceInstance serviceInstance = new CloudServiceInstance(getMeta(resource), getNameOfResource(resource)); serviceInstance.setType(getEntityAttribute(resource, "type", String.class)); serviceInstance.setDashboardUrl(getEntityAttribute(resource, "dashboard_url", String.class)); serviceInstance.setCredentials(getEntityAttribute(resource, "credentials", Map.class)); Map<String, Object> servicePlanResource = getEmbeddedResource(resource, "service_plan"); 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; }
@SuppressWarnings("unchecked") private CloudApplication mapCloudApplication(Map<String, Object> resource) { UUID appId = resourceMapper.getGuidOfResource(resource); CloudApplication cloudApp = null; if (resource != null) { int running = getRunningInstances(appId, CloudApplication.AppState.valueOf( CloudEntityResourceMapper.getEntityAttribute(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 = getEntityAttribute(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(getMeta(resource), getNameOfResource(resource), quota, billingEnabled); }
private CloudDomain mapDomainResource(Map<String, Object> resource) { @SuppressWarnings("unchecked") Map<String, Object> ownerResource = getEntityAttribute(resource, "owning_organization", Map.class); CloudOrganization owner; if (ownerResource == null) { owner = new CloudOrganization(CloudEntity.Meta.defaultMeta(), "none"); } else { owner = mapOrganizationResource(ownerResource); } return new CloudDomain(getMeta(resource), getNameOfResource(resource), owner); }