Search in sources :

Example 1 with FileUpload

use of org.opentosca.toscana.plugins.cloudformation.util.FileUpload in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationFileCreator method writeStackCreationScript.

/**
 *     Creates the script for creating the CloudFormation stack from the template.
 */
private void writeStackCreationScript() throws IOException {
    logger.debug("Creating create-stack script.");
    BashScript createStackScript = new BashScript(cfnModule.getFileAccess(), FILENAME_CREATE_STACK);
    // Build deploy command
    StringBuilder deployCommand = new StringBuilder("");
    deployCommand.append(CLI_COMMAND_CREATESTACK + CLI_PARAM_STACKNAME).append(cfnModule.getStackName()).append(" ").append(CLI_PARAM_TEMPLATEFILE).append("../").append(TEMPLATE_YAML);
    // Add IAM capability if needed
    List<FileUpload> fileUploadList = cfnModule.getFileUploadList();
    if (!fileUploadList.isEmpty()) {
        logger.debug("Adding IAM capability to create stack command.");
        deployCommand.append(" " + CLI_PARAM_CAPABILITIES + " " + CAPABILITY_IAM);
    }
    // Add parameters if needed
    Map<String, Parameter> parameters = cfnModule.getParameters();
    if (!parameters.isEmpty()) {
        logger.debug("Adding parameters to create stack command.");
        deployCommand.append(" " + CLI_PARAM_PARAMOVERRIDES);
        for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
            String id = entry.getKey();
            deployCommand.append(" ").append(id).append("=$").append(id).append("Var");
        }
    }
    createStackScript.append(deployCommand.toString());
}
Also used : BashScript(org.opentosca.toscana.plugins.scripts.BashScript) Parameter(com.scaleset.cfbuilder.core.Parameter) Map(java.util.Map) FileUpload(org.opentosca.toscana.plugins.cloudformation.util.FileUpload)

Example 2 with FileUpload

use of org.opentosca.toscana.plugins.cloudformation.util.FileUpload in project TOSCAna by StuPro-TOSCAna.

the class OperationHandler method markUtilFile.

/**
 *     Marks file as util file to be uploaded.
 *
 *     @param filePath path to file that needs to be uploaded
 */
private void markUtilFile(String filePath) {
    logger.debug("Marking '{}' as util file to be uploaded.", filePath);
    cfnModule.addFileUpload(new FileUpload(filePath, UTIL));
}
Also used : FileUpload(org.opentosca.toscana.plugins.cloudformation.util.FileUpload)

Example 3 with FileUpload

use of org.opentosca.toscana.plugins.cloudformation.util.FileUpload in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationFileCreatorTest method testWriteScripts.

@Test
public void testWriteScripts() throws Exception {
    cfnModule.addFileUpload(new FileUpload(FILENAME_TEST_FILE, FROM_CSAR));
    fileCreator.writeScripts();
    File deployScript = new File(targetDir, SCRIPTS_DIR_PATH + FILENAME_DEPLOY + BASH_FILE_ENDING);
    File fileUploadScript = new File(targetDir, SCRIPTS_DIR_PATH + FILENAME_UPLOAD + BASH_FILE_ENDING);
    File createStackScript = new File(targetDir, SCRIPTS_DIR_PATH + FILENAME_CREATE_STACK + BASH_FILE_ENDING);
    assertTrue(deployScript.exists());
    assertTrue(fileUploadScript.exists());
    String expectedDeployContent = SHEBANG + "\n" + SOURCE_UTIL_ALL + "\n" + SUBCOMMAND_EXIT + "\n" + "check \"aws\"\n" + "source file-upload.sh\n" + "source create-stack.sh\n";
    String expectedFileUploadContent = SHEBANG + "\n" + SOURCE_UTIL_ALL + "\n" + SUBCOMMAND_EXIT + "\n" + "createBucket " + cfnModule.getBucketName() + " " + cfnModule.getAWSRegion() + "\n" + "uploadFile " + cfnModule.getBucketName() + " \"" + FILENAME_TEST_FILE + "\" \"" + FILEPATH_TARGET_TEST_FILE_LOCAL + "\"" + "\n";
    String expectedCreateStackContent = SHEBANG + "\n" + SOURCE_UTIL_ALL + "\n" + SUBCOMMAND_EXIT + "\n" + CLI_COMMAND_CREATESTACK + CLI_PARAM_STACKNAME + cfnModule.getStackName() + " " + CLI_PARAM_TEMPLATEFILE + "../" + TEMPLATE_YAML + " " + CLI_PARAM_CAPABILITIES + " " + CAPABILITY_IAM + "\n";
    String actualDeployContent = FileUtils.readFileToString(deployScript, StandardCharsets.UTF_8);
    String actualFileUploadContent = FileUtils.readFileToString(fileUploadScript, StandardCharsets.UTF_8);
    String actualCreateStackContent = FileUtils.readFileToString(createStackScript, StandardCharsets.UTF_8);
    assertEquals(expectedDeployContent, actualDeployContent);
    assertEquals(expectedFileUploadContent, actualFileUploadContent);
    assertEquals(expectedCreateStackContent, actualCreateStackContent);
}
Also used : File(java.io.File) FileUpload(org.opentosca.toscana.plugins.cloudformation.util.FileUpload) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 4 with FileUpload

use of org.opentosca.toscana.plugins.cloudformation.util.FileUpload in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationFileCreatorTest method copyFiles.

@Test
public void copyFiles() {
    cfnModule.addFileUpload(new FileUpload(FILENAME_TEST_FILE, FROM_CSAR));
    fileCreator.copyFiles();
    assertTrue(FILEPATH_TARGET_TEST_FILE.exists());
}
Also used : FileUpload(org.opentosca.toscana.plugins.cloudformation.util.FileUpload) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 5 with FileUpload

use of org.opentosca.toscana.plugins.cloudformation.util.FileUpload in project TOSCAna by StuPro-TOSCAna.

the class OperationHandler method markFile.

/**
 *     Marks file as file to be uploaded.
 *
 *     @param filePath path to file that needs to be uploaded
 */
private void markFile(String filePath) {
    logger.debug("Marking '{}' as file to be uploaded.", filePath);
    cfnModule.addFileUpload(new FileUpload(filePath, FROM_CSAR));
}
Also used : FileUpload(org.opentosca.toscana.plugins.cloudformation.util.FileUpload)

Aggregations

FileUpload (org.opentosca.toscana.plugins.cloudformation.util.FileUpload)5 Test (org.junit.Test)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 Parameter (com.scaleset.cfbuilder.core.Parameter)1 File (java.io.File)1 Map (java.util.Map)1 BashScript (org.opentosca.toscana.plugins.scripts.BashScript)1