Search in sources :

Example 1 with Service

use of org.opentosca.toscana.plugins.cloudfoundry.application.Service in project TOSCAna by StuPro-TOSCAna.

the class InjectionHandler method getServiceCredentials.

/**
 *     read the service credentials of the services which is binded to the application
 *     adds the value of the credentials to the environment variable
 *     //TODO: expand with more ServiceTypes
 */
public void getServiceCredentials() {
    for (Service service : app.getServicesMatchedToProvider()) {
        if (service.getServiceType() == ServiceTypes.MYSQL) {
            try {
                String port = connection.getServiceCredentials(service.getServiceName(), app.getName()).getString("port");
                String username = connection.getServiceCredentials(service.getServiceName(), app.getName()).getString("username");
                String database_name = connection.getServiceCredentials(service.getServiceName(), app.getName()).getString("name");
                String password = connection.getServiceCredentials(service.getServiceName(), app.getName()).getString("password");
                String host = connection.getServiceCredentials(service.getServiceName(), app.getName()).getString("hostname");
                // TODO: check for environment variable names. Probably in the ToscaSpec
                app.addEnvironmentVariables("database_user", username);
                app.addEnvironmentVariables("database_name", database_name);
                app.addEnvironmentVariables("database_host", host);
                app.addEnvironmentVariables("database_password", password);
                app.addEnvironmentVariables("database_port", port);
            } catch (JSONException | JsonProcessingException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Service(org.opentosca.toscana.plugins.cloudfoundry.application.Service) JSONException(org.json.JSONException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with Service

use of org.opentosca.toscana.plugins.cloudfoundry.application.Service in project TOSCAna by StuPro-TOSCAna.

the class ServiceHandler method addMatchedServices.

/**
 *     checks if a service of a provider matches the needed service
 */
private boolean addMatchedServices(List<ServiceOffering> services, BashScript deployScript, String description, Map.Entry<String, ServiceTypes> service, boolean insertCreateCommand) throws IOException {
    boolean isSet = false;
    for (ServiceOffering offeredService : services) {
        if (offeredService.getDescription().toLowerCase().contains(description.toLowerCase())) {
            for (ServicePlan plan : offeredService.getServicePlans()) {
                if (plan.getFree()) {
                    String serviceName = offeredService.getLabel();
                    String planName = plan.getName();
                    String serviceInstanceName = service.getKey();
                    if (insertCreateCommand) {
                        logger.info("A suitable service could be found, named {}. Add a free plan named {}, you could adpat the plan in the deploy script", serviceName, planName);
                        deployScript.append(String.format("%s%s %s %s", CLI_CREATE_SERVICE, serviceName, planName, serviceInstanceName));
                    }
                    application.addMatchedService(new Service(serviceName, serviceInstanceName, planName, service.getValue()));
                    isSet = true;
                    break;
                }
            }
            if (isSet) {
                break;
            }
        }
    }
    return isSet;
}
Also used : ServiceOffering(org.cloudfoundry.operations.services.ServiceOffering) ServicePlan(org.cloudfoundry.operations.services.ServicePlan) Service(org.opentosca.toscana.plugins.cloudfoundry.application.Service)

Example 3 with Service

use of org.opentosca.toscana.plugins.cloudfoundry.application.Service in project TOSCAna by StuPro-TOSCAna.

the class Connection method createService.

/**
 *     creates a service on the cloud foundry instance
 */
private void createService(String serviceInstanceName, String serviceName, String plan) throws InterruptedException {
    CountDownLatch latchService = new CountDownLatch(1);
    cloudFoundryOperations.services().createInstance(CreateServiceInstanceRequest.builder().serviceInstanceName(serviceInstanceName).serviceName(serviceName).planName(plan).build()).doOnSubscribe(s -> logger.info("Create Service Started")).doOnError(t -> this.logger.error("Service creation Failed", t)).doOnSuccess(v -> this.logger.info("Service creation Successful")).subscribe(System.out::println, t -> latchService.countDown(), latchService::countDown);
    latchService.await();
}
Also used : ListServiceOfferingsRequest(org.cloudfoundry.operations.services.ListServiceOfferingsRequest) PasswordGrantTokenProvider(org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider) DefaultConnectionContext(org.cloudfoundry.reactor.DefaultConnectionContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ApplicationEnvironments(org.cloudfoundry.operations.applications.ApplicationEnvironments) GetApplicationEnvironmentsRequest(org.cloudfoundry.operations.applications.GetApplicationEnvironmentsRequest) Service(org.opentosca.toscana.plugins.cloudfoundry.application.Service) DefaultCloudFoundryOperations(org.cloudfoundry.operations.DefaultCloudFoundryOperations) Path(java.nio.file.Path) ReactorCloudFoundryClient(org.cloudfoundry.reactor.client.ReactorCloudFoundryClient) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ApplicationManifest(org.cloudfoundry.operations.applications.ApplicationManifest) CreateServiceInstanceRequest(org.cloudfoundry.operations.services.CreateServiceInstanceRequest) CountDownLatch(java.util.concurrent.CountDownLatch) TokenProvider(org.cloudfoundry.reactor.TokenProvider) List(java.util.List) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) CloudFoundryOperations(org.cloudfoundry.operations.CloudFoundryOperations) ServiceOffering(org.cloudfoundry.operations.services.ServiceOffering) TRUE(java.lang.Boolean.TRUE) PushApplicationManifestRequest(org.cloudfoundry.operations.applications.PushApplicationManifestRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with Service

use of org.opentosca.toscana.plugins.cloudfoundry.application.Service in project TOSCAna by StuPro-TOSCAna.

the class Connection method deployApplication.

/**
 *     deploys a small application to the cloud foundry instance.
 *     contains only default values, the application represents not an instance of the template model
 */
private boolean deployApplication(Path pathToApplication, String name, List<Service> services) throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    String[] serviceInstanceNames = new String[services.size()];
    for (int i = 0; i < services.size(); i++) {
        serviceInstanceNames[i] = services.get(i).getServiceInstanceName();
    }
    AtomicBoolean succeed = new AtomicBoolean(false);
    cloudFoundryOperations.applications().pushManifest(PushApplicationManifestRequest.builder().manifest(ApplicationManifest.builder().path(pathToApplication).name(name).service(serviceInstanceNames).randomRoute(true).build()).noStart(TRUE).build()).doOnSubscribe(s -> logger.info("Deployment Started")).doOnError(t -> this.logger.error("Deployment Failed", t)).doOnSuccess(v -> this.logger.info("Deployment Successful")).doOnSuccess(u -> succeed.set(true)).subscribe(System.out::println, t -> latch.countDown(), latch::countDown);
    latch.await();
    return succeed.get();
}
Also used : ListServiceOfferingsRequest(org.cloudfoundry.operations.services.ListServiceOfferingsRequest) PasswordGrantTokenProvider(org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider) DefaultConnectionContext(org.cloudfoundry.reactor.DefaultConnectionContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ApplicationEnvironments(org.cloudfoundry.operations.applications.ApplicationEnvironments) GetApplicationEnvironmentsRequest(org.cloudfoundry.operations.applications.GetApplicationEnvironmentsRequest) Service(org.opentosca.toscana.plugins.cloudfoundry.application.Service) DefaultCloudFoundryOperations(org.cloudfoundry.operations.DefaultCloudFoundryOperations) Path(java.nio.file.Path) ReactorCloudFoundryClient(org.cloudfoundry.reactor.client.ReactorCloudFoundryClient) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ApplicationManifest(org.cloudfoundry.operations.applications.ApplicationManifest) CreateServiceInstanceRequest(org.cloudfoundry.operations.services.CreateServiceInstanceRequest) CountDownLatch(java.util.concurrent.CountDownLatch) TokenProvider(org.cloudfoundry.reactor.TokenProvider) List(java.util.List) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) CloudFoundryOperations(org.cloudfoundry.operations.CloudFoundryOperations) ServiceOffering(org.cloudfoundry.operations.services.ServiceOffering) TRUE(java.lang.Boolean.TRUE) PushApplicationManifestRequest(org.cloudfoundry.operations.applications.PushApplicationManifestRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with Service

use of org.opentosca.toscana.plugins.cloudfoundry.application.Service in project TOSCAna by StuPro-TOSCAna.

the class Connection method pushApplication.

/**
 *     Creates the services
 *     Deploys the application with minimal attributes and bind application to service.
 */
public boolean pushApplication(Path pathToApplication, String name, List<Service> services) throws InterruptedException {
    boolean succeed = false;
    for (Service service : services) {
        createService(service.getServiceInstanceName(), service.getServiceName(), service.getPlan());
    }
    succeed = deployApplication(pathToApplication, name, services);
    return succeed;
}
Also used : Service(org.opentosca.toscana.plugins.cloudfoundry.application.Service)

Aggregations

Service (org.opentosca.toscana.plugins.cloudfoundry.application.Service)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ServiceOffering (org.cloudfoundry.operations.services.ServiceOffering)3 JSONException (org.json.JSONException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TRUE (java.lang.Boolean.TRUE)2 Path (java.nio.file.Path)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CloudFoundryOperations (org.cloudfoundry.operations.CloudFoundryOperations)2 DefaultCloudFoundryOperations (org.cloudfoundry.operations.DefaultCloudFoundryOperations)2 ApplicationEnvironments (org.cloudfoundry.operations.applications.ApplicationEnvironments)2 ApplicationManifest (org.cloudfoundry.operations.applications.ApplicationManifest)2 GetApplicationEnvironmentsRequest (org.cloudfoundry.operations.applications.GetApplicationEnvironmentsRequest)2 PushApplicationManifestRequest (org.cloudfoundry.operations.applications.PushApplicationManifestRequest)2 CreateServiceInstanceRequest (org.cloudfoundry.operations.services.CreateServiceInstanceRequest)2 ListServiceOfferingsRequest (org.cloudfoundry.operations.services.ListServiceOfferingsRequest)2 DefaultConnectionContext (org.cloudfoundry.reactor.DefaultConnectionContext)2 TokenProvider (org.cloudfoundry.reactor.TokenProvider)2