Search in sources :

Example 1 with ApplicationEnvironments

use of org.cloudfoundry.operations.applications.ApplicationEnvironments in project TOSCAna by StuPro-TOSCAna.

the class Connection method getServiceCredentials.

/**
 *     Method to get the service credentials which depends on the CloudFoundry instance.
 *     Therefore a connection to a CF instance is needed
 *     and the application has to be deployed and binded to the given service
 *     You can get special credentials in this way: JSONObject.getString("port")
 *
 *     @return JSONObject with credentials of the given serviceId
 */
public JSONObject getServiceCredentials(String serviceName, String applicationName) throws JSONException, JsonProcessingException {
    ApplicationEnvironments environments = cloudFoundryOperations.applications().getEnvironments(GetApplicationEnvironmentsRequest.builder().name(applicationName).build()).block();
    Object env = environments.getSystemProvided();
    ObjectMapper mapper = new ObjectMapper();
    String serviceCredentials = mapper.writeValueAsString(env);
    JSONObject jsonObject = new JSONObject(serviceCredentials).getJSONObject("VCAP_SERVICES");
    return jsonObject.getJSONArray(serviceName).getJSONObject(// TODO: Check if always on the same index
    0).getJSONObject("credentials");
}
Also used : ApplicationEnvironments(org.cloudfoundry.operations.applications.ApplicationEnvironments) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ApplicationEnvironments

use of org.cloudfoundry.operations.applications.ApplicationEnvironments in project cf-java-client by cloudfoundry.

the class ApplicationsTest method setEnvironmentVariable.

@SuppressWarnings("unchecked")
@Test
public void setEnvironmentVariable() throws IOException {
    String applicationName = this.nameFactory.getApplicationName();
    String variableName1 = this.nameFactory.getVariableName();
    String variableName2 = this.nameFactory.getVariableName();
    String variableValue1 = this.nameFactory.getVariableValue();
    String variableValue2 = this.nameFactory.getVariableValue();
    Map<String, Object> expected = FluentMap.<String, Object>builder().entry(variableName1, variableValue1).entry(variableName2, variableValue2).build();
    createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false).then(this.cloudFoundryOperations.applications().setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder().name(applicationName).variableName(variableName1).variableValue(variableValue1).build())).then(this.cloudFoundryOperations.applications().setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder().name(applicationName).variableName(variableName2).variableValue(variableValue2).build())).then(this.cloudFoundryOperations.applications().getEnvironments(GetApplicationEnvironmentsRequest.builder().name(applicationName).build())).map(ApplicationEnvironments::getUserProvided).as(StepVerifier::create).expectNext(expected).expectComplete().verify(Duration.ofMinutes(5));
}
Also used : ApplicationEnvironments(org.cloudfoundry.operations.applications.ApplicationEnvironments) ClassPathResource(org.springframework.core.io.ClassPathResource) AbstractIntegrationTest(org.cloudfoundry.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with ApplicationEnvironments

use of org.cloudfoundry.operations.applications.ApplicationEnvironments in project cf-java-client by cloudfoundry.

the class ApplicationsTest method unsetEnvironmentVariableComplete.

@SuppressWarnings("unchecked")
@Test
public void unsetEnvironmentVariableComplete() throws IOException {
    String applicationName = this.nameFactory.getApplicationName();
    String variableName1 = this.nameFactory.getVariableName();
    String variableName2 = this.nameFactory.getVariableName();
    String variableValue1 = this.nameFactory.getVariableValue();
    String variableValue2 = this.nameFactory.getVariableValue();
    createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false).then(this.cloudFoundryOperations.applications().setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder().name(applicationName).variableName(variableName1).variableValue(variableValue1).build())).then(this.cloudFoundryOperations.applications().setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder().name(applicationName).variableName(variableName2).variableValue(variableValue2).build())).then(this.cloudFoundryOperations.applications().unsetEnvironmentVariable(UnsetEnvironmentVariableApplicationRequest.builder().name(applicationName).variableName(variableName1).build())).then(this.cloudFoundryOperations.applications().unsetEnvironmentVariable(UnsetEnvironmentVariableApplicationRequest.builder().name(applicationName).variableName(variableName2).build())).then(this.cloudFoundryOperations.applications().getEnvironments(GetApplicationEnvironmentsRequest.builder().name(applicationName).build())).map(ApplicationEnvironments::getUserProvided).as(StepVerifier::create).expectNext(Collections.emptyMap()).expectComplete().verify(Duration.ofMinutes(5));
}
Also used : ApplicationEnvironments(org.cloudfoundry.operations.applications.ApplicationEnvironments) ClassPathResource(org.springframework.core.io.ClassPathResource) AbstractIntegrationTest(org.cloudfoundry.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

ApplicationEnvironments (org.cloudfoundry.operations.applications.ApplicationEnvironments)3 AbstractIntegrationTest (org.cloudfoundry.AbstractIntegrationTest)2 Test (org.junit.Test)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JSONObject (org.json.JSONObject)1