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