private boolean isSameSpace(CloudSpace space, String orgName, String spaceName) { CloudOrganization org = space.getOrganization(); if (orgName != null && !org.getName() .equals(orgName)) { return false; } return spaceName == null || space.getName() .equals(spaceName); }
private CloudSpace validateSpaceAndOrg(String spaceName, String orgName, CloudControllerClientImpl client) { List<CloudSpace> spaces = client.getSpaces(); for (CloudSpace space : spaces) { if (space.getName().equals(spaceName)) { CloudOrganization org = space.getOrganization(); if (orgName == null || org.getName().equals(orgName)) { return space; } } } throw new IllegalArgumentException("No matching organization and space found for org: " + orgName + " space: " + spaceName); }
@Override public List<CloudDomain> getDomainsForOrg() { assertSpaceProvided("access organization domains"); return doGetDomains(sessionSpace.getOrganization()); }
private List<ConfigurationSubscription> getConfigurationEntries(List<CloudSpace> clientSpaces, CloudControllerClient client) { return clientSpaces.stream() .map(clientSpace -> configurationSubscriptionsDao.findAll(null, null, computeSpaceId(client, clientSpace.getOrganization() .getName(), clientSpace.getName()), null)) .flatMap(List::stream) .collect(Collectors.toList()); }
@Override public List<CloudDomain> getDomainsForOrg() { assertSpaceProvided("access organization domains"); return doGetDomains(sessionSpace.getOrganization()); }
private void addServiceParameters(Operation operation, String spaceGuid) { String processDefinitionKey = operationsHelper.getProcessDefinitionKey(operation); Map<String, Object> parameters = operation.getParameters(); CloudControllerClient client = getCloudFoundryClient(spaceGuid); CloudSpace space = new CFOptimizedSpaceGetter().getSpace(client, spaceGuid); parameters.put(Constants.VARIABLE_NAME_SPACE_ID, spaceGuid); parameters.put(Constants.VARIABLE_NAME_SERVICE_ID, processDefinitionKey); parameters.put(com.sap.cloud.lm.sl.cf.process.Constants.VAR_ORG, space.getOrganization() .getName()); parameters.put(com.sap.cloud.lm.sl.cf.process.Constants.VAR_SPACE, space.getName()); }
private UUID doCreateDomain(String domainName) { String urlPath = "/v2/private_domains"; HashMap<String, Object> domainRequest = new HashMap<String, Object>(); domainRequest.put("owning_organization_guid", sessionSpace.getOrganization().getMeta().getGuid()); domainRequest.put("name", domainName); domainRequest.put("wildcard", true); String resp = getRestTemplate().postForObject(getUrl(urlPath), domainRequest, String.class); Map<String, Object> respMap = JsonUtil.convertJsonToMap(resp); return resourceMapper.getGuidOfResource(respMap); }
private UUID doCreateDomain(String domainName) { String urlPath = "/v2/private_domains"; HashMap<String, Object> domainRequest = new HashMap<String, Object>(); domainRequest.put("owning_organization_guid", sessionSpace.getOrganization() .getMeta() .getGuid()); domainRequest.put("name", domainName); domainRequest.put("wildcard", true); String resp = getRestTemplate().postForObject(getUrl(urlPath), domainRequest, String.class); Map<String, Object> respMap = JsonUtil.convertJsonToMap(resp); return resourceMapper.getGuidOfV2Resource(respMap); }
private CloudControllerClient getClientForApplicationSpace(ExecutionWrapper execution, CloudApplication app) { CloudSpace space = app.getSpace(); CloudOrganization organization = space.getOrganization(); return execution.getControllerClient(organization.getName(), space.getName()); }
private void addOrgAndSpaceIfNecessary(CloudApplication application, Pair<String, String> orgAndSpace) { // The entity returned by the getApplication(String appName) method of // the CF Java client does not contain a CloudOrganization, // because the value of the 'inline-relations-depth' is hardcoded to 1 // (see the findApplicationResource method of // org.cloudfoundry.client.lib.rest.CloudControllerClientImpl). if (application.getSpace() == null || application.getSpace() .getOrganization() == null) { CloudSpace space = createDummySpace(orgAndSpace); application.setSpace(space); } }
private CloudControllerClient getClientForApplicationSpace(ExecutionWrapper execution, CloudApplication app) { CloudSpace space = app.getSpace(); CloudOrganization organization = space.getOrganization(); return execution.getControllerClient(organization.getName(), space.getName()); }
public Pair<String, String> computeOrgAndSpace(String spaceId) { CloudSpace space = attemptToFindSpace(spaceId); if (space != null) { return new Pair<>(space.getOrganization() .getName(), space.getName()); } return null; }
private void addOrgAndSpaceIfNecessary(CloudApplication application, Pair<String, String> orgAndSpace) { // The entity returned by the getApplication(String appName) method of // the CF Java client does not contain a CloudOrganization, // because the value of the 'inline-relations-depth' is hardcoded to 1 // (see the findApplicationResource method of // org.cloudfoundry.client.lib.rest.CloudControllerClientImpl). if (application.getSpace() == null || application.getSpace() .getOrganization() == null) { CloudSpace space = createDummySpace(orgAndSpace); application.setSpace(space); } }
private void associateRoleWithSpace(String orgName, String spaceName, String userGuid, String urlPath) { assertSpaceProvided("associate roles"); CloudOrganization organization = (orgName == null ? sessionSpace.getOrganization() : getOrganization(orgName)); UUID orgGuid = organization.getMeta() .getGuid(); UUID spaceGuid = getSpaceGuid(spaceName, orgGuid); HashMap<String, Object> spaceRequest = new HashMap<String, Object>(); spaceRequest.put("guid", spaceGuid); String userId = (userGuid == null ? getCurrentUserId() : userGuid); getRestTemplate().put(getUrl(urlPath), spaceRequest, spaceGuid, userId); }
@Override public void deleteSpace(String spaceName) { assertSpaceProvided("delete a space"); UUID orgGuid = sessionSpace.getOrganization().getMeta().getGuid(); UUID spaceGuid = getSpaceGuid(spaceName, orgGuid); if (spaceGuid != null) { doDeleteSpace(spaceGuid); } }
@Override public void createSpace(String spaceName) { assertSpaceProvided("create a new space"); UUID orgGuid = sessionSpace.getOrganization() .getMeta() .getGuid(); UUID spaceGuid = getSpaceGuid(spaceName, orgGuid); if (spaceGuid == null) { doCreateSpace(spaceName, orgGuid); } }
private void associateRoleWithSpace(String orgName, String spaceName, String userGuid, String urlPath) { assertSpaceProvided("associate roles"); CloudOrganization organization = (orgName == null ? sessionSpace.getOrganization() : getOrgByName(orgName, true)); UUID orgGuid = organization.getMeta().getGuid(); UUID spaceGuid = getSpaceGuid(spaceName, orgGuid); HashMap<String, Object> spaceRequest = new HashMap<String, Object>(); spaceRequest.put("guid", spaceGuid); String userId = (userGuid==null?getCurrentUserId():userGuid); getRestTemplate().put(getUrl(urlPath), spaceRequest, spaceGuid, userId); }
@Override public void deleteSpace(String spaceName) { assertSpaceProvided("delete a space"); UUID orgGuid = sessionSpace.getOrganization() .getMeta() .getGuid(); UUID spaceGuid = getSpaceGuid(spaceName, orgGuid); if (spaceGuid != null) { doDeleteSpace(spaceGuid); } }
@Override public void createSpace(String spaceName) { assertSpaceProvided("create a new space"); UUID orgGuid = sessionSpace.getOrganization().getMeta().getGuid(); UUID spaceGuid = getSpaceGuid(spaceName, orgGuid); if (spaceGuid == null) { doCreateSpace(spaceName, orgGuid); } }
protected Pair<CloudControllerClient, TokenProvider> createClient(CloudCredentials credentials, String spaceId) { CloudControllerRestClientFactory factory = new CloudControllerRestClientFactory(null, configuration.shouldSkipSslValidation()); CloudSpace sessionSpace = getSessionSpace(credentials, spaceId); addTaggingInterceptor(factory.getRestTemplate(), sessionSpace.getOrganization() .getName(), sessionSpace.getName()); OauthClient oauthClient = createOauthClient(factory.getRestTemplate()); CloudControllerRestClient controllerClient = factory.newCloudController(configuration.getControllerUrl(), credentials, sessionSpace, oauthClient); return new Pair<>(new ResilientCloudControllerClient(controllerClient), new CloudFoundryTokenProvider(oauthClient)); }