Search in sources :

Example 1 with Provider

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

the class FileCreatorTest method checkMultipleApplicationServices.

@Test
public void checkMultipleApplicationServices() throws IOException, JSONException {
    String serviceName = "mydb";
    envUser = System.getenv(CF_ENVIRONMENT_USER);
    envPw = System.getenv(CF_ENVIRONMENT_PW);
    envHost = System.getenv(CF_ENVIRONMENT_HOST);
    envOrga = System.getenv(CF_ENVIRONMENT_ORGA);
    envSpace = System.getenv(CF_ENVIRONMENT_SPACE);
    connection = createConnection();
    Application app = new Application("app", 1, context);
    Application secondApp = new Application("appSec", 2, context);
    app.setProvider(new Provider(Provider.CloudFoundryProviderType.PIVOTAL));
    app.setConnection(connection);
    secondApp.setProvider(new Provider(Provider.CloudFoundryProviderType.PIVOTAL));
    secondApp.setConnection(connection);
    app.addService(service1, ServiceTypes.MYSQL);
    secondApp.addService(serviceName, ServiceTypes.MYSQL);
    EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    RootNode webApplicationNode = null;
    RootNode mysqlDatabaseNode = null;
    for (RootNode node : lamp.getNodes()) {
        if (node instanceof WebApplication) {
            webApplicationNode = node;
        }
        if (node instanceof MysqlDatabase) {
            mysqlDatabaseNode = node;
        }
    }
    app.addConfigMysql(service1, "my_db/configSql.sql");
    app.addExecuteFile("my_app/configure_myphpapp.sh", webApplicationNode);
    secondApp.addConfigMysql(serviceName, "database/config.sql");
    secondApp.addExecuteFile("database/dbinit.sh", mysqlDatabaseNode);
    List<Application> applications = new ArrayList<>();
    applications.add(app);
    applications.add(secondApp);
    FileCreator fileCreator = new FileCreator(fileAccess, applications, context);
    fileCreator.createFiles();
    File targetFile = new File(targetDir, outputPath + FILEPRAEFIX_DEPLOY + deploy_name + FILESUFFIX_DEPLOY);
    String deployscriptContent = FileUtils.readFileToString(targetFile);
    String expectedContent = "check python\n" + "python replace.py ../../app1/my_app/configure_myphpapp.sh /var/www/html/ /home/vcap/app/htdocs/\n" + "python replace.py ../../app2/database/dbinit.sh /var/www/html/ /home/vcap/app/htdocs/\n" + "cf push app -f ../manifest.yml --no-start\n" + "cf push appSec -f ../manifest.yml --no-start\n" + "python readCredentials.py app cleardb mysql cleardb\n" + "python configureMysql.py ../../app1/my_db/configSql.sql\n" + "cf start app\n" + "python executeCommand.py app /home/vcap/app/htdocs/my_app/configure_myphpapp.sh\n" + "python readCredentials.py appSec cleardb mysql mydb\n" + "python configureMysql.py ../../app2/database/config.sql\n" + "cf start appSec\n" + "python executeCommand.py appSec /home/vcap/app/database/dbinit.sh\n";
    assertTrue(deployscriptContent.contains(expectedContent));
// assertEquals(expectedContent, deployscriptContent);
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) WebApplication(org.opentosca.toscana.model.node.WebApplication) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) File(java.io.File) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Provider(org.opentosca.toscana.plugins.cloudfoundry.application.Provider) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 2 with Provider

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

the class ServiceHandler method readProviderServices.

/**
 *     reads the offered services from the provider
 *     tries to find a suitable service for the needed purpose.
 *     always add a service with a free plan
 */
private List<String> readProviderServices(List<String> alreadyHandledServices) throws IOException {
    if (application.getProvider() != null && !application.getServices().isEmpty() && application.getConnection() != null) {
        Provider provider = application.getProvider();
        logger.debug("Read service offerings from provider");
        provider.setOfferedService(application.getConnection().getServices());
        for (Map.Entry<String, ServiceTypes> service : application.getServices().entrySet()) {
            if (!alreadyHandledServices.contains(service.getKey())) {
                alreadyHandledServices.add(service.getKey());
                matchingServices(service, provider, true);
            } else {
                matchingServices(service, provider, false);
            }
        }
    } else {
        for (Map.Entry<String, ServiceTypes> service : application.getServices().entrySet()) {
            if (!alreadyHandledServices.contains(service.getKey())) {
                alreadyHandledServices.add(service.getKey());
                logger.error("Could not find a suitable service, add the default value {}. Please adapt the line in the deploy script!", CLI_CREATE_SERVICE_DEFAULT);
                deploymentScript.append(CLI_CREATE_SERVICE_DEFAULT + service.getKey());
            }
        }
    }
    return alreadyHandledServices;
}
Also used : ServiceTypes(org.opentosca.toscana.plugins.cloudfoundry.application.ServiceTypes) Map(java.util.Map) Provider(org.opentosca.toscana.plugins.cloudfoundry.application.Provider)

Example 3 with Provider

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

the class ServiceHandler method addProviderServiceOfferings.

/**
 *     adds all offered services from the provider to an extra file
 */
private void addProviderServiceOfferings() throws IOException {
    Provider provider = application.getProvider();
    List<ServiceOffering> services = provider.getOfferedService();
    BufferedLineWriter lineWriter = fileAccess.access(SERVICE_FILE_PATH);
    logger.info("List all services from the provider to the file '{}'", SERVICE_FILE_PATH);
    lineWriter.appendln("Following services you could choose:");
    lineWriter.appendln(String.format("%-20s %-40s %-50s\n", "Name", " Plans", "Description"));
    for (ServiceOffering service : services) {
        String plans = "";
        for (ServicePlan plan : service.getServicePlans()) {
            String currentPlan;
            if (plan.getFree()) {
                currentPlan = plan.getName();
            } else {
                currentPlan = plan.getName() + "*";
            }
            plans = String.format("%s %s ", plans, currentPlan);
        }
        logger.debug("Add '{}' to the service list in file '{}'", service.getLabel(), SERVICE_FILE_PATH);
        lineWriter.appendln(String.format("%-20s %-40s %-50s ", service.getLabel(), plans, service.getDescription()));
    }
    lineWriter.appendln("\n* These service plans have an associated cost. Creating a service instance will incur this cost.\n");
    lineWriter.close();
}
Also used : BufferedLineWriter(org.opentosca.toscana.core.plugin.PluginFileAccess.BufferedLineWriter) ServiceOffering(org.cloudfoundry.operations.services.ServiceOffering) ServicePlan(org.cloudfoundry.operations.services.ServicePlan) Provider(org.opentosca.toscana.plugins.cloudfoundry.application.Provider)

Aggregations

Provider (org.opentosca.toscana.plugins.cloudfoundry.application.Provider)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ServiceOffering (org.cloudfoundry.operations.services.ServiceOffering)1 ServicePlan (org.cloudfoundry.operations.services.ServicePlan)1 Test (org.junit.Test)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 BufferedLineWriter (org.opentosca.toscana.core.plugin.PluginFileAccess.BufferedLineWriter)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 MysqlDatabase (org.opentosca.toscana.model.node.MysqlDatabase)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)1 Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)1 ServiceTypes (org.opentosca.toscana.plugins.cloudfoundry.application.ServiceTypes)1 FileCreator (org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator)1