Search in sources :

Example 1 with Deployment

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

the class FileCreator method replaceStrings.

/**
 *     replaces strings in files with suitable strings.
 *     If a path is not suitable to the path in the warden container
 *     A replace command will be added to the deployscript which replaces the Strings locally.
 *
 *     @param deployScript script the commands will be written in
 */
private void replaceStrings(BashScript deployScript) throws IOException {
    for (Application application : applications) {
        Deployment deployment = new Deployment(deployScript, application, fileAccess, context);
        if (!application.getExecuteCommands().isEmpty()) {
            Map<String, String> executeCommands = application.getExecuteCommands();
            for (Map.Entry<String, String> command : executeCommands.entrySet()) {
                // TODO: add lists which strings should be replaced. In 12 Factor it is probably not necessary.
                String findStr = "/var/www/html/";
                String replaceStr = "/home/vcap/app/htdocs/";
                deployment.replaceStrings(command.getKey(), findStr, replaceStr);
                logger.info("Add command to replace all occurence of {} with {}", findStr, replaceStr);
            }
        }
    }
}
Also used : Deployment(org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) Map(java.util.Map)

Example 2 with Deployment

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

the class FileCreator method handleServices.

/**
 *     looks for a suitable service of the provider which matches to the needed service
 *     adds the creation command to the deployscript
 *
 *     @param deployScript script the commands will be written in
 */
private void handleServices(BashScript deployScript) throws IOException {
    for (Application application : applications) {
        Deployment deployment = new Deployment(deployScript, application, fileAccess, context);
        // only one time all service offerings should be printed
        this.alreadyHandledServices = deployment.treatServices(alreadyHandledServices);
    }
}
Also used : Deployment(org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application)

Example 3 with Deployment

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

the class DeploymentTest method replaceStrings.

@Test
public void replaceStrings() throws IOException {
    String pythonFilename = "replace.py";
    Deployment deployment = new Deployment(deployScript, testApp, fileAccess, context);
    String pathToFile = "../../testApp/move.sh";
    String findStr = "testAlt";
    String replaceStr = "testNeu";
    deployment.replaceStrings(pathToFile, findStr, replaceStr);
    File targetFile = new File(targetDir, outputPath + pythonFilename);
    File deployFile = new File(targetDir, outputPath + "deploy_" + appName + ".sh");
    String contentDeploy = FileUtils.readFileToString(deployFile);
    String expectedDeployContent = String.format(SHEBANG + "\n" + SOURCE_UTIL_ALL + "\n" + SUBCOMMAND_EXIT + "\n" + "check python\n" + "python %s %s %s %s\n", pythonFilename, pathToFile, findStr, replaceStr);
    assertTrue(targetFile.exists());
    assertEquals(expectedDeployContent, contentDeploy);
}
Also used : Deployment(org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 4 with Deployment

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

the class DeploymentTest method configureSql.

@Test
public void configureSql() throws IOException {
    String pythonFilename = "configureMysql.py";
    String pathToSqlFile = "../../test/configMysql.sql";
    Deployment deployment = new Deployment(deployScript, testApp, fileAccess, context);
    deployment.configureSql(pathToSqlFile);
    File targetFile = new File(targetDir, outputPath + pythonFilename);
    File deployFile = new File(targetDir, outputPath + "deploy_" + appName + ".sh");
    String contentDeploy = FileUtils.readFileToString(deployFile);
    String expectedDeployContent = String.format(SHEBANG + "\n" + SOURCE_UTIL_ALL + "\n" + SUBCOMMAND_EXIT + "\n" + "check python\n" + "python %s %s\n", pythonFilename, pathToSqlFile);
    assertTrue(targetFile.exists());
    assertEquals(expectedDeployContent, contentDeploy);
}
Also used : Deployment(org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 5 with Deployment

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

the class DeploymentTest method executeFile.

@Test
public void executeFile() throws IOException {
    String pythonFilename = "executeCommand.py";
    Deployment deployment = new Deployment(deployScript, testApp, fileAccess, context);
    String pathToFile = "/home/vcap/app/testApp/command.sh";
    deployment.executeFile(appName, pathToFile);
    File targetFile = new File(targetDir, outputPath + pythonFilename);
    File deployFile = new File(targetDir, outputPath + "deploy_" + appName + ".sh");
    String contentDeploy = FileUtils.readFileToString(deployFile);
    String expectedDeployContent = String.format(SHEBANG + "\n" + SOURCE_UTIL_ALL + "\n" + SUBCOMMAND_EXIT + "\n" + "check python\n" + "python %s %s %s\n", pythonFilename, appName, pathToFile);
    assertTrue(targetFile.exists());
    assertEquals(expectedDeployContent, contentDeploy);
}
Also used : Deployment(org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Aggregations

Deployment (org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment)7 File (java.io.File)4 Test (org.junit.Test)4 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)4 Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)3 Map (java.util.Map)1 BashScript (org.opentosca.toscana.plugins.scripts.BashScript)1