org.cloudfoundry.client.lib.domain.CloudSpace Java Examples
The following examples show how to use
org.cloudfoundry.client.lib.domain.CloudSpace.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OperationsApiServiceImpl.java From multiapps-controller with Apache License 2.0 | 6 votes |
private Operation addServiceParameters(Operation operation, String spaceGuid, String user) { String processDefinitionKey = operationsHelper.getProcessDefinitionKey(operation); Map<String, Object> parameters = new HashMap<>(operation.getParameters()); CloudControllerClient client = getCloudFoundryClient(spaceGuid); CloudSpace space = client.getSpace(UUID.fromString(spaceGuid)); CloudOrganization organization = space.getOrganization(); parameters.put(Constants.VARIABLE_NAME_SERVICE_ID, processDefinitionKey); parameters.put(Variables.USER.getName(), user); parameters.put(Variables.SPACE_NAME.getName(), space.getName()); parameters.put(Variables.SPACE_GUID.getName(), spaceGuid); parameters.put(Variables.ORGANIZATION_NAME.getName(), organization.getName()); parameters.put(Variables.ORGANIZATION_GUID.getName(), organization.getMetadata() .getGuid() .toString()); String namespace = operation.getNamespace(); if (namespace != null) { parameters.put(Variables.MTA_NAMESPACE.getName(), namespace); parameters.put(Variables.APPLY_NAMESPACE.getName(), true); } return ImmutableOperation.copyOf(operation) .withParameters(parameters); }
Example #2
Source File: CloudControllerRestClientImpl.java From cf-java-client-sap with Apache License 2.0 | 6 votes |
public CloudControllerRestClientImpl(URL controllerUrl, CloudCredentials credentials, RestTemplate restTemplate, OAuthClient oAuthClient, CloudFoundryClient delegate, DopplerClient dopplerClient, CloudSpace target) { Assert.notNull(controllerUrl, "CloudControllerUrl cannot be null"); Assert.notNull(restTemplate, "RestTemplate cannot be null"); Assert.notNull(oAuthClient, "OAuthClient cannot be null"); this.controllerUrl = controllerUrl; this.credentials = credentials; this.restTemplate = restTemplate; this.oAuthClient = oAuthClient; this.target = target; this.delegate = delegate; this.dopplerClient = dopplerClient; }
Example #3
Source File: ClientHelper.java From multiapps-controller with Apache License 2.0 | 6 votes |
private CloudSpace attemptToFindSpace(String spaceId) { try { return client.getSpace(UUID.fromString(spaceId)); } catch (CloudOperationException e) { // From our point of view 403 means the same as 404 - the user does not have access to a space, so it is like it does not exist // for him. if (e.getStatusCode() .equals(HttpStatus.FORBIDDEN)) { LOGGER.debug(MessageFormat.format("The user does not have access to space with ID {0}!", spaceId)); return null; } if (e.getStatusCode() .equals(HttpStatus.NOT_FOUND)) { LOGGER.debug(MessageFormat.format("Space with ID {0} does not exist!", spaceId)); return null; } throw e; } }
Example #4
Source File: UpdateSubscribersStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
private CloudApplication addOrgAndSpaceIfNecessary(CloudApplication application, CloudTarget cloudTarget) { // 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(cloudTarget); return ImmutableCloudApplication.copyOf(application) .withSpace(space); } return application; }
Example #5
Source File: CloudSpaceBluemixWizardPage.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
private String[] getSpaces(String org) { ArrayList <String> list = new ArrayList<String>(); for (CloudSpace space : _spaces) { if (StringUtil.equalsIgnoreCase(org, space.getOrganization().getName())) { list.add(space.getName()); } } return list.toArray(new String[list.size()]); }
Example #6
Source File: ClientHelperTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private CloudSpace createCloudSpace(UUID guid, String spaceName, String organizationName) { return ImmutableCloudSpace.builder() .name(spaceName) .organization(createCloudOrganization(organizationName)) .metadata(createCloudMetadata(guid)) .build(); }
Example #7
Source File: RawCloudSpace.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
@Override public CloudSpace derive() { Resource<SpaceEntity> resource = getResource(); SpaceEntity entity = resource.getEntity(); return ImmutableCloudSpace.builder() .metadata(parseResourceMetadata(resource)) .name(entity.getName()) .organization(deriveFromNullable(getOrganization())) .build(); }
Example #8
Source File: CloudFoundryClientFactory.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Override protected CloudControllerClient createClient(CloudCredentials credentials, String spaceId) { CloudSpace target = computeTarget(credentials, spaceId); OAuthClient oAuthClient = oAuthClientFactory.createOAuthClient(); CloudControllerRestClient controllerClient = clientFactory.createClient(configuration.getControllerUrl(), credentials, target, oAuthClient); addTaggingInterceptor(controllerClient.getRestTemplate(), target.getOrganization() .getName(), target.getName()); return new ResilientCloudControllerClient(controllerClient); }
Example #9
Source File: AuthorizationCheckerTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private void setUpMocks(boolean hasPermissions, boolean hasAccess, Exception e) { DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("testTokenValue"); accessToken.setScope(new HashSet<>()); CloudOrganization organization = ImmutableCloudOrganization.builder() .name(ORG) .build(); CloudSpace space = ImmutableCloudSpace.builder() .name(SPACE) .organization(organization) .build(); ClientHelper clientHelper = Mockito.mock(ClientHelper.class); if (hasAccess) { when(client.getSpace(ORG, SPACE, false)).thenReturn(space); when(clientHelper.computeTarget(SPACE_ID)).thenReturn(new CloudTarget(ORG, SPACE)); } else { when(clientHelper.computeTarget(SPACE_ID)).thenReturn(null); } when(authorizationChecker.getClientHelper(client)).thenReturn(clientHelper); userInfo = new UserInfo(USER_ID.toString(), USERNAME, accessToken); List<UUID> spaceDevelopersList = new ArrayList<>(); if (hasPermissions) { spaceDevelopersList.add(USER_ID); } if (e == null) { when(client.getSpaceDevelopers(ORG, SPACE)).thenReturn(spaceDevelopersList); when(client.getSpaceDevelopers(UUID.fromString(SPACE_ID))).thenReturn(spaceDevelopersList); } else { when(client.getSpaceDevelopers(ORG, SPACE)).thenThrow(e); when(client.getSpaceDevelopers(UUID.fromString(SPACE_ID))).thenThrow(e); } when(clientProvider.getControllerClient(userInfo.getName())).thenReturn(client); when(applicationConfiguration.getFssCacheUpdateTimeoutMinutes()).thenReturn(ApplicationConfiguration.DEFAULT_SPACE_DEVELOPER_CACHE_TIME_IN_SECONDS); }
Example #10
Source File: ClientHelper.java From multiapps-controller with Apache License 2.0 | 5 votes |
public CloudTarget computeTarget(String spaceId) { CloudSpace space = attemptToFindSpace(spaceId); if (space != null) { return new CloudTarget(space.getOrganization() .getName(), space.getName()); } return null; }
Example #11
Source File: ClientHelper.java From multiapps-controller with Apache License 2.0 | 5 votes |
public String computeSpaceId(String orgName, String spaceName) { CloudSpace space = client.getSpace(orgName, spaceName, false); if (space != null) { return space.getMetadata() .getGuid() .toString(); } return null; }
Example #12
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private CloudApplication createApp(String name, CloudSpace space, Map<String, String> env) { return ImmutableCloudApplication.builder() .name(name) .space(space) .env(env) .build(); }
Example #13
Source File: CloudControllerRestClientImpl.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
private CloudSpace findSpaceByOrganizationGuidAndName(UUID organizationGuid, String spaceName, boolean required) { CloudSpace space = findSpaceByOrganizationGuidAndName(organizationGuid, spaceName); if (space == null && required) { throw new CloudOperationException(HttpStatus.NOT_FOUND, "Not Found", "Space " + spaceName + " not found in organization with GUID " + organizationGuid + "."); } return space; }
Example #14
Source File: CloudControllerRestClientImpl.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
private Mono<Derivable<CloudSpace>> zipWithAuxiliarySpaceContent(Resource<SpaceEntity> resource) { UUID organizationGuid = UUID.fromString(resource.getEntity() .getOrganizationId()); return getOrganizationMono(organizationGuid).map(organization -> ImmutableRawCloudSpace.builder() .resource(resource) .organization(organization) .build()); }
Example #15
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private boolean userHasPermissions(CloudSpace space, UserPermission... permissions) { UserRole userRole = getUserRole(space); if (userRole == null) { throw new IllegalStateException(MessageFormat.format(NO_USER_ROLES_DEFINED_FOR_ORG_AND_SPACE, space.getOrganization() .getName(), space.getName())); } return userRole.permissions.containsAll(Arrays.asList(permissions)); }
Example #16
Source File: CloudControllerRestClientFactory.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
public CloudControllerRestClient createClient(URL controllerUrl, CloudCredentials credentials, String organizationName, String spaceName, OAuthClient oAuthClient) { CloudControllerRestClient clientWithoutTarget = createClient(controllerUrl, credentials, oAuthClient); CloudSpace target = clientWithoutTarget.getSpace(organizationName, spaceName); return createClient(controllerUrl, credentials, target, oAuthClient); }
Example #17
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private StepOutput captureStepOutput() { StepOutput result = new StepOutput(); result.callArgumentsOfUpdateApplicationEnvMethod = new ArrayList<>(); for (CloudSpace space : clients.keySet()) { if (userHasPermissions(space, UserPermission.READ, UserPermission.WRITE)) { List<CloudApplication> callArgumentsOfUpdateApplicationEnvMethod = getCallArgumentsOfUpdateApplicationEnvMethod(space, clients.get(space)); result.callArgumentsOfUpdateApplicationEnvMethod.addAll(callArgumentsOfUpdateApplicationEnvMethod); } } result.updatedSubscribers = context.getVariable(Variables.UPDATED_SUBSCRIBERS); return result; }
Example #18
Source File: CloudControllerRestClientFactory.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
public CloudControllerRestClient createClient(URL controllerUrl, CloudCredentials credentials, CloudSpace target, OAuthClient oAuthClient) { RestTemplate restTemplate = createAuthorizationSettingRestTemplate(credentials, oAuthClient); CloudFoundryClient delegate = getCloudFoundryClientFactory().createClient(controllerUrl, oAuthClient); DopplerClient dopplerClient = getCloudFoundryClientFactory().createDopplerClient(controllerUrl, oAuthClient); return new CloudControllerRestClientImpl(controllerUrl, credentials, restTemplate, oAuthClient, delegate, dopplerClient, target); }
Example #19
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private boolean isSameSpace(CloudSpace space1, CloudSpace space2) { return space1.getName() .equals(space2.getName()) && space1.getOrganization() .getName() .equals(space2.getOrganization() .getName()); }
Example #20
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private CloudControllerClient getOrCreateClientForSpace(Map<CloudSpace, CloudControllerClient> clients, CloudSpace space) { for (CloudSpace existingSpace : clients.keySet()) { if (isSameSpace(space, existingSpace)) { return clients.get(existingSpace); } } clients.put(space, client); return client; }
Example #21
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private Map<CloudSpace, CloudControllerClient> createClientsForSpacesOfSubscribedApps() { Map<CloudSpace, CloudControllerClient> result = new HashMap<>(); for (SubscriberToUpdate subscriber : input.subscribersToUpdate) { CloudControllerClient client = getOrCreateClientForSpace(result, subscriber.app.getSpace()); mockClientInvocations(subscriber, client); } return result; }
Example #22
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private void prepareClients() throws Exception { prepareClientProvider(input.currentSpace, clientForCurrentSpace); clients = createClientsForSpacesOfSubscribedApps(); for (CloudSpace space : clients.keySet()) { prepareClientProvider(space, clients.get(space)); } }
Example #23
Source File: RestartSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private CloudSpace createCloudSpace(String orgName, String spaceName) { return ImmutableCloudSpace.builder() .organization(ImmutableCloudOrganization.builder() .name(orgName) .build()) .name(spaceName) .build(); }
Example #24
Source File: CloudControllerClientImpl.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
public CloudControllerClientImpl(URL controllerUrl, CloudCredentials credentials, CloudSpace target, HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) { Assert.notNull(controllerUrl, "URL for cloud controller cannot be null"); CloudControllerRestClientFactory restClientFactory = ImmutableCloudControllerRestClientFactory.builder() .httpProxyConfiguration(httpProxyConfiguration) .shouldTrustSelfSignedCertificates(trustSelfSignedCerts) .build(); this.delegate = restClientFactory.createClient(controllerUrl, credentials, target); }
Example #25
Source File: UpdateSubscribersStep.java From multiapps-controller with Apache License 2.0 | 5 votes |
private CloudSpace createDummySpace(CloudTarget cloudTarget) { CloudOrganization org = createDummyOrg(cloudTarget.getOrganizationName()); return ImmutableCloudSpace.builder() .name(cloudTarget.getSpaceName()) .organization(org) .build(); }
Example #26
Source File: UpdateSubscribersStepTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private List<CloudApplication> getCallArgumentsOfUpdateApplicationEnvMethod(CloudSpace space, CloudControllerClient client) { ArgumentCaptor<Map> appEnvCaptor = ArgumentCaptor.forClass(Map.class); ArgumentCaptor<String> appNameCaptor = ArgumentCaptor.forClass(String.class); verify(client, Mockito.atLeast(0)).updateApplicationEnv(appNameCaptor.capture(), appEnvCaptor.capture()); List<Map> appEnvs = appEnvCaptor.getAllValues(); List<String> appNames = appNameCaptor.getAllValues(); List<CloudApplication> result = new ArrayList<>(); for (int i = 0; i < appNames.size(); i++) { result.add(createApp(appNames.get(i), space, appEnvs.get(i))); } return result; }
Example #27
Source File: LoggingCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public CloudSpace getSpace(String organizationName, String spaceName, boolean required) { logger.debug(Messages.GETTING_SPACE_IN_ORGANIZATION_0, spaceName, organizationName); return delegate.getSpace(organizationName, spaceName, required); }
Example #28
Source File: ResilientCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public CloudSpace getSpace(String organizationName, String spaceName, boolean required) { return executeWithRetry(() -> delegate.getSpace(organizationName, spaceName, required)); }
Example #29
Source File: LoggingCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public CloudSpace getSpace(String spaceName) { logger.debug(Messages.GETTING_SPACE_0, spaceName); return delegate.getSpace(spaceName); }
Example #30
Source File: ResilientCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public CloudSpace getSpace(String organizationName, String spaceName) { return executeWithRetry(() -> delegate.getSpace(organizationName, spaceName)); }