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