use of org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator in project TOSCAna by StuPro-TOSCAna.
the class CloudFoundryPluginTest method setUp.
@Before
public void setUp() throws Exception {
EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
context = setUpMockTransformationContext(lamp);
String userName = System.getenv("TEST_CF_USER");
String pw = System.getenv("TEST_CF_PW");
String host = System.getenv("TEST_CF_HOST");
String space = System.getenv("TEST_CF_SPACE");
String orga = System.getenv("TEST_CF_ORGA");
Assume.assumeNotNull(userName, pw, host, space, orga);
when(context.getInputs()).thenReturn(mock(PropertyInstance.class));
when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_USERNAME)).thenReturn(userName);
when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_PASSWORD)).thenReturn(pw);
when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_API)).thenReturn(host);
when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_SPACE)).thenReturn(space);
when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_ORGANIZATION)).thenReturn(orga);
cfCycle = new CloudFoundryLifecycle(context);
cfCycle.checkModel();
cfCycle.prepare();
cfCycle.fillApplications();
File sourceDir = new File(resourcesPath, "csars/yaml/valid/lamp-noinput");
targetDir = new File(tmpdir, "targetDir");
sourceDir.mkdir();
targetDir.mkdir();
PluginFileAccess fileAccess = new PluginFileAccess(sourceDir, targetDir, logMock());
// Set<RootNode> nodes = lamp.getNodes();
when(context.getPluginFileAccess()).thenReturn(fileAccess);
paths.add("app1/my_app/index.php");
paths.add("app1/my_app/create_myphpapp.sh");
paths.add("app1/my_db/createtable.sql");
List<Application> applications = cfCycle.getFilledApplications();
FileCreator fileCreator = new FileCreator(fileAccess, applications, context);
fileCreator.createFiles();
}
use of org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator in project TOSCAna by StuPro-TOSCAna.
the class ServiceTest method checkService.
@Test
public void checkService() throws Exception {
assumeNotNull(envUser, envHost, envOrga, envPw, envSpace);
app.addService("my_db", ServiceTypes.MYSQL);
List<Application> applications = new ArrayList<>();
applications.add(app);
fileCreator = new FileCreator(fileAccess, applications, context);
fileCreator.createFiles();
File targetFile = new File(targetDir, outputPath + FILEPRAEFIX_DEPLOY + deploy_name + FILESUFFIX_DEPLOY);
String deployContent = FileUtils.readFileToString(targetFile);
assertThat(deployContent, CoreMatchers.containsString(expectedDeployContent));
}
use of org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator 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.filecreator.FileCreator 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.filecreator.FileCreator 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);
}
Aggregations