private boolean isSameSpace(CloudSpace space, String spaceId) { return space.getMeta() .getGuid() .toString() .equals(spaceId); }
public String computeSpaceId(String orgName, String spaceName) { CloudSpace space = spaceGetter.findSpace(client, orgName, spaceName); if (space != null) { return space.getMeta() .getGuid() .toString(); } return null; }
private Map<String, Object> findApplicationResource(String appName, boolean fetchServiceInfo) { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; if (sessionSpace != null) { urlVars.put("space", sessionSpace.getMeta() .getGuid()); urlPath = urlPath + "/spaces/{space}"; } urlVars.put("q", "name:" + appName); urlPath = urlPath + "/apps?inline-relations-depth=1&q={q}"; List<Map<String, Object>> allResources = getAllResources(urlPath, urlVars); if (!allResources.isEmpty()) { return processApplicationResource(allResources.get(0), fetchServiceInfo); } return null; }
private Map<String, Object> findApplicationResource(String appName, boolean fetchServiceInfo) { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; if (sessionSpace != null) { urlVars.put("space", sessionSpace.getMeta().getGuid()); urlPath = urlPath + "/spaces/{space}"; } urlVars.put("q", "name:" + appName); urlPath = urlPath + "/apps?inline-relations-depth=1&q={q}"; List<Map<String, Object>> allResources = getAllResources(urlPath, urlVars); if(!allResources.isEmpty()) { return processApplicationResource(allResources.get(0), fetchServiceInfo); } return null; }
@Override public List<CloudApplication> getApplications() { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; if (sessionSpace != null) { urlVars.put("space", sessionSpace.getMeta().getGuid()); urlPath = urlPath + "/spaces/{space}"; } urlPath = urlPath + "/apps?inline-relations-depth=1"; List<Map<String, Object>> resourceList = getAllResources(urlPath, urlVars); List<CloudApplication> apps = new ArrayList<CloudApplication>(); for (Map<String, Object> resource : resourceList) { processApplicationResource(resource, true); apps.add(mapCloudApplication(resource)); } return apps; }
private List<CloudApplication> getApplicationsWithCustomDepth(String inlineDepth) { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; if (sessionSpace != null) { urlVars.put("space", sessionSpace.getMeta() .getGuid()); urlPath = urlPath + "/spaces/{space}"; } urlPath = urlPath + "/apps?inline-relations-depth=" + inlineDepth; List<Map<String, Object>> resourceList = getAllResources(urlPath, urlVars); List<CloudApplication> apps = new ArrayList<CloudApplication>(); for (Map<String, Object> resource : resourceList) { if (processApplicationResource(resource, true) != null) { apps.add(mapCloudApplication(resource)); } } return apps; }
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 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(); }
@Override public List<CloudService> getServices() { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; if (sessionSpace != null) { urlVars.put("space", sessionSpace.getMeta() .getGuid()); urlPath = urlPath + "/spaces/{space}"; } urlPath = urlPath + "/service_instances?inline-relations-depth=1&return_user_provided_service_instances=true"; List<Map<String, Object>> resourceList = getAllResources(urlPath, urlVars); List<CloudService> services = new ArrayList<CloudService>(); for (Map<String, Object> resource : resourceList) { if (hasEmbeddedResource(resource, "service_plan")) { fillInEmbeddedResource(resource, "service_plan", "service"); } services.add(resourceMapper.mapResource(resource, CloudService.class)); } return services; }
@Override public List<CloudService> getServices() { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2"; if (sessionSpace != null) { urlVars.put("space", sessionSpace.getMeta().getGuid()); urlPath = urlPath + "/spaces/{space}"; } urlPath = urlPath + "/service_instances?inline-relations-depth=1&return_user_provided_service_instances=true"; List<Map<String, Object>> resourceList = getAllResources(urlPath, urlVars); List<CloudService> services = new ArrayList<CloudService>(); for (Map<String, Object> resource : resourceList) { if (hasEmbeddedResource(resource, "service_plan")) { fillInEmbeddedResource(resource, "service_plan", "service"); } services.add(resourceMapper.mapResource(resource, CloudService.class)); } return services; }
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(); }
@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); }
@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 void createUserProvidedServiceDelegate(CloudService service, Map<String, Object> credentials, String syslogDrainUrl) { assertSpaceProvided("create service"); Assert.notNull(credentials, "Service credentials must not be null"); Assert.notNull(service, "Service must not be null"); Assert.notNull(service.getName(), "Service name must not be null"); Assert.isNull(service.getLabel(), "Service label is not valid for user-provided services"); Assert.isNull(service.getProvider(), "Service provider is not valid for user-provided services"); Assert.isNull(service.getVersion(), "Service version is not valid for user-provided services"); Assert.isNull(service.getPlan(), "Service plan is not valid for user-provided services"); HashMap<String, Object> serviceRequest = new HashMap<>(); serviceRequest.put("space_guid", sessionSpace.getMeta() .getGuid()); serviceRequest.put("name", service.getName()); serviceRequest.put("credentials", credentials); if (syslogDrainUrl != null && !syslogDrainUrl.equals("")) { serviceRequest.put("syslog_drain_url", syslogDrainUrl); } getRestTemplate().postForObject(getUrl("/v2/user_provided_service_instances"), serviceRequest, String.class); }
private void createUserProvidedServiceDelegate(CloudService service, Map<String, Object> credentials, String syslogDrainUrl) { assertSpaceProvided("create service"); Assert.notNull(credentials, "Service credentials must not be null"); Assert.notNull(service, "Service must not be null"); Assert.notNull(service.getName(), "Service name must not be null"); Assert.isNull(service.getLabel(), "Service label is not valid for user-provided services"); Assert.isNull(service.getProvider(), "Service provider is not valid for user-provided services"); Assert.isNull(service.getVersion(), "Service version is not valid for user-provided services"); Assert.isNull(service.getPlan(), "Service plan is not valid for user-provided services"); HashMap<String, Object> serviceRequest = new HashMap<>(); serviceRequest.put("space_guid", sessionSpace.getMeta().getGuid()); serviceRequest.put("name", service.getName()); serviceRequest.put("credentials", credentials); if (syslogDrainUrl != null && !syslogDrainUrl.equals("")) { serviceRequest.put("syslog_drain_url", syslogDrainUrl); } getRestTemplate().postForObject(getUrl("/v2/user_provided_service_instances"), serviceRequest, String.class); }
private List<UUID> getSpaceUserGuids(String orgName, String spaceName, String urlPath) { if (orgName == null || spaceName == null) { assertSpaceProvided("get space users"); } UUID spaceGuid; if (spaceName == null) { spaceGuid = sessionSpace.getMeta().getGuid(); } else { CloudOrganization organization = (orgName == null ? sessionSpace.getOrganization() : getOrgByName(orgName, true)); spaceGuid = getSpaceGuid(spaceName, organization.getMeta().getGuid()); } Map<String, Object> urlVars = new HashMap<String, Object>(); urlVars.put("guid", spaceGuid); List<UUID> managersGuid = new ArrayList<UUID>(); List<Map<String, Object>> resourceList = getAllResources(urlPath, urlVars); for (Map<String, Object> resource : resourceList) { UUID userGuid = resourceMapper.getGuidOfResource(resource); managersGuid.add(userGuid); } return managersGuid; }
public void saveToken(URI target, OAuth2AccessToken token, CloudInfo cloudInfo, CloudSpace space) { TargetInfos targetInfos = getTokensFromFile(); if (targetInfos == null) { targetInfos = new TargetInfos(); } HashMap<String, String> targetInfo = targetInfos.get(target); if (targetInfo == null) { targetInfo = new LinkedHashMap<String, String>(); } targetInfos.putToken(targetInfo, token); targetInfos.putRefreshToken(targetInfo, token.getRefreshToken()); targetInfos.putVersion(targetInfo, cloudInfo.getVersion()); targetInfos.putSpace(targetInfo, space.getMeta().getGuid().toString()); targetInfos.putOrganization(targetInfo, space.getOrganization().getMeta().getGuid().toString()); targetInfos.put(target, targetInfo); saveTokensToFile(targetInfos); }
private List<UUID> getSpaceUserGuids(String orgName, String spaceName, String urlPath) { if (orgName == null || spaceName == null) { assertSpaceProvided("get space users"); } UUID spaceGuid; if (spaceName == null) { spaceGuid = sessionSpace.getMeta() .getGuid(); } else { CloudOrganization organization = (orgName == null ? sessionSpace.getOrganization() : getOrganization(orgName)); spaceGuid = getSpaceGuid(spaceName, organization.getMeta() .getGuid()); } return getSpaceUserGuids(spaceGuid, urlPath); }
public void saveToken(URI target, OAuth2AccessToken token, CloudInfo cloudInfo, CloudSpace space) { TargetInfos targetInfos = getTokensFromFile(); if (targetInfos == null) { targetInfos = new TargetInfos(); } HashMap<String, String> targetInfo = targetInfos.get(target); if (targetInfo == null) { targetInfo = new LinkedHashMap<String, String>(); } targetInfos.putToken(targetInfo, token); targetInfos.putRefreshToken(targetInfo, token.getRefreshToken()); targetInfos.putVersion(targetInfo, cloudInfo.getVersion()); targetInfos.putSpace(targetInfo, space.getMeta() .getGuid() .toString()); targetInfos.putOrganization(targetInfo, space.getOrganization() .getMeta() .getGuid() .toString()); targetInfos.put(target, targetInfo); saveTokensToFile(targetInfos); }