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();
}
}
}
}
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;
}
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();
}
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();
}
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;
}
Aggregations