public UUID getGuidOfResource(Map<String, Object> resource) { return getMeta(resource).getGuid(); }
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 CloudStack mapStackResource(Map<String, Object> resource) { return new CloudStack(getMeta(resource), getNameOfResource(resource), getEntityAttribute(resource, "description", String.class)); }
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 UUID doAddRoute(String host, UUID domainGuid) { assertSpaceProvided("add route"); HashMap<String, Object> routeRequest = new HashMap<String, Object>(); routeRequest.put("host", host); 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.getMeta(routeEntity).getGuid(); }
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(getMeta(resource), getNameOfResource(resource), organization); }
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()); }
@Override public void createApplication(String appName, Staging staging, Integer disk, Integer memory, List<String> uris, List<String> serviceNames) { HashMap<String, Object> appRequest = new HashMap<String, Object>(); appRequest.put("space_guid", sessionSpace.getMeta().getGuid()); appRequest.put("name", appName); appRequest.put("memory", memory); if (disk != null) { appRequest.put("disk_quota", disk); } appRequest.put("instances", 1); addStagingToRequest(staging, appRequest); appRequest.put("state", CloudApplication.AppState.STOPPED); String appResp = getRestTemplate().postForObject(getUrl("/v2/apps"), appRequest, String.class); Map<String, Object> appEntity = JsonUtil.convertJsonToMap(appResp); UUID newAppGuid = CloudEntityResourceMapper.getMeta(appEntity).getGuid(); if (serviceNames != null && serviceNames.size() > 0) { updateApplicationServices(appName, serviceNames); } if (uris != null && uris.size() > 0) { addUris(uris, newAppGuid); } }
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 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 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 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); }
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 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 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); }
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)); }
@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; }
@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; }
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 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; }