Search in sources :

Example 11 with Application

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

the class FileCreatorTest method checkMultipleApplicationsDeployScript.

@Test
public void checkMultipleApplicationsDeployScript() throws Exception {
    Application app1 = new Application("app1", 1, context);
    Application app2 = new Application("app2", 2, context);
    app1.addService(service1, ServiceTypes.MYSQL);
    app2.addService(service2, ServiceTypes.MYSQL);
    List<Application> applications = new ArrayList<>();
    applications.add(app1);
    applications.add(app2);
    FileCreator fileCreatorMult = new FileCreator(fileAccess, applications, context);
    fileCreatorMult.createFiles();
    File targetFile = new File(targetDir, outputPath + FILEPRAEFIX_DEPLOY + deploy_name + FILESUFFIX_DEPLOY);
    String deployscriptContent = FileUtils.readFileToString(targetFile);
    String expectedContent = SHEBANG + "\n" + SOURCE_UTIL_ALL + "\n" + SUBCOMMAND_EXIT + "\n" + "echo \"$(tput bold)--------TOSCAna Cloud Foundry deployment--------$(tput sgr0)\"\n" + "echo \"This script will deploy your application to the Cloud Foundry instance\"\n" + "echo \"We use the CloudFoundry CLI and show you the output as well\"\n" + "echo \"Is there no CF CLI installed we have to stop, we will check it\"\n" + "echo \"We will deploy the application to the connected provider\"\n" + "echo \"If you use a Cloud Foundry service with your application, you are able to change the service or plan in this deploy script manually\"\n" + "echo \"We tried to choose a suitable service with a free plan\"\n" + "echo \"You could check all possible services in the file$(tput bold) output/all_services.txt $(tput sgr0)\"\n" + "echo \"$(tput bold)--------TOSCAna Cloud Foundry deployment$(tput sgr0)--------\n" + "\"\n" + "check \"cf\"\n" + "cf create-service {plan} {service} cleardb\n" + "cf create-service {plan} {service} p-mysql\n" + "cf push app1 -f ../manifest.yml --no-start\n" + "cf push app2 -f ../manifest.yml --no-start\n" + "cf start app1\n" + "cf start app2\n" + "echo \"\n" + "\n" + "$(tput bold)The deployment of your application is finished. You see the urls of your apps here:$(tput sgr0)\n" + "\"\n" + "cf routes\n";
    assertEquals(expectedContent, deployscriptContent);
}
Also used : FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 12 with Application

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

the class FileCreatorTest method checkMultipleApplicationsManifest.

@Test
public void checkMultipleApplicationsManifest() throws Exception {
    Application app1 = new Application("app1", 1, context);
    Application app2 = new Application("app2", 2, context);
    app1.addService(service1, ServiceTypes.MYSQL);
    app2.addService(service2, ServiceTypes.MYSQL);
    app1.addAttribute("attr1", "value1");
    app1.addAttribute("attr2", "value2");
    app2.addAttribute("attr1", "value1");
    app2.addAttribute("attr2", "value2");
    app1.addEnvironmentVariables("EnvTest", "5");
    List<Application> applications = new ArrayList<>();
    applications.add(app1);
    applications.add(app2);
    FileCreator fileCreatorMult = new FileCreator(fileAccess, applications, context);
    fileCreatorMult.createFiles();
    File targetFile = new File(targetDir, MANIFEST_PATH);
    String manifestContent = FileUtils.readFileToString(targetFile);
    String expectedContent = "---\n" + "applications:\n" + "- name: app1\n" + "  path: ../app1\n" + "  attr2: value2\n" + "  attr1: value1\n" + "  random-route: true\n" + "  env:\n" + "    EnvTest: 5\n" + "  services:\n" + "    - cleardb\n" + "- name: app2\n" + "  path: ../app2\n" + "  attr2: value2\n" + "  attr1: value1\n" + "  random-route: true\n" + "  services:\n" + "    - p-mysql\n";
    assertEquals(expectedContent, manifestContent);
}
Also used : FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 13 with Application

use of org.opentosca.toscana.plugins.cloudfoundry.application.Application 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 14 with Application

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

the class FileCreatorTest method setUp.

@Before
public void setUp() throws IOException {
    EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    this.context = setUpMockTransformationContext(lamp);
    appName = "testApp";
    testApp = new Application("testApp", 1, context);
    testApp.setName(appName);
    File sourceDir = new File(tmpdir, "sourceDir");
    targetDir = new File(tmpdir, "targetDir");
    sourceDir.mkdir();
    targetDir.mkdir();
    fileAccess = new PluginFileAccess(sourceDir, targetDir, logMock());
    List<Application> applications = new ArrayList<>();
    applications.add(testApp);
    fileCreator = new FileCreator(fileAccess, applications, context);
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) 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) Before(org.junit.Before)

Example 15 with Application

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

the class ServiceTest method getAllServices.

@Test
public void getAllServices() throws Exception {
    assumeNotNull(envUser, envHost, envOrga, envPw, envSpace);
    app.addService("my_db1", ServiceTypes.MYSQL);
    List<Application> applications = new ArrayList<>();
    applications.add(app);
    fileCreator = new FileCreator(fileAccess, applications, context);
    fileCreator.createFiles();
    File all_services = new File(targetDir, SERVICE_FILE_PATH);
    String all_services_expected_content = "Following services you could choose:";
    String all_services_content = FileUtils.readFileToString(all_services, Charset.defaultCharset());
    assertTrue(all_services.exists());
    assertThat(all_services_content, CoreMatchers.containsString(all_services_expected_content));
}
Also used : FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Aggregations

Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)19 File (java.io.File)9 ArrayList (java.util.ArrayList)7 FileCreator (org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator)7 Test (org.junit.Test)5 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)5 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)5 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)5 WebApplication (org.opentosca.toscana.model.node.WebApplication)5 Before (org.junit.Before)4 PluginFileAccess (org.opentosca.toscana.core.plugin.PluginFileAccess)4 RootNode (org.opentosca.toscana.model.node.RootNode)3 Deployment (org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment)3 KubernetesNodeContainer (org.opentosca.toscana.plugins.kubernetes.util.KubernetesNodeContainer)2 BashScript (org.opentosca.toscana.plugins.scripts.BashScript)2 InputStream (java.io.InputStream)1 Map (java.util.Map)1 PropertyInstance (org.opentosca.toscana.core.transformation.properties.PropertyInstance)1 Artifact (org.opentosca.toscana.model.artifact.Artifact)1 Compute (org.opentosca.toscana.model.node.Compute)1