Search in sources :

Example 1 with BashScript

use of org.opentosca.toscana.plugins.scripts.BashScript 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 BashScript

use of org.opentosca.toscana.plugins.scripts.BashScript in project TOSCAna by StuPro-TOSCAna.

the class DeploymentTest 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);
    File sourceDir = new File(tmpdir, "sourceDir");
    targetDir = new File(tmpdir, "targetDir");
    sourceDir.mkdir();
    targetDir.mkdir();
    fileAccess = new PluginFileAccess(sourceDir, targetDir, log);
    deployScript = new BashScript(fileAccess, "deploy_" + appName);
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) BashScript(org.opentosca.toscana.plugins.scripts.BashScript) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) File(java.io.File) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Before(org.junit.Before)

Example 3 with BashScript

use of org.opentosca.toscana.plugins.scripts.BashScript in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationFileCreator method writeDeployScript.

/**
 *     Creates a deploy script for deploying the cloudformation template.
 */
private void writeDeployScript() throws IOException {
    logger.debug("Creating deploy script.");
    BashScript deployScript = new BashScript(cfnModule.getFileAccess(), FILENAME_DEPLOY);
    deployScript.append(EnvironmentCheck.checkEnvironment("aws"));
    // Source file-upload script if needed
    List fileUploadList = cfnModule.getFileUploadList();
    if (!fileUploadList.isEmpty()) {
        deployScript.append("source " + FILENAME_UPLOAD + ".sh");
    }
    deployScript.append("source " + FILENAME_CREATE_STACK + ".sh");
}
Also used : BashScript(org.opentosca.toscana.plugins.scripts.BashScript) List(java.util.List)

Example 4 with BashScript

use of org.opentosca.toscana.plugins.scripts.BashScript in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationFileCreator method writeCleanUpScript.

/**
 *     Creates a script to delete the S3Bucket and the deployed Stack.
 *     Note: May or may not be included in the final version. Currently used for quicker manual debugging.
 */
private void writeCleanUpScript() throws IOException {
    logger.debug("Creating cleanup script.");
    BashScript cleanupScript = new BashScript(cfnModule.getFileAccess(), FILENAME_CLEANUP);
    // Delete Bucket
    cleanupScript.append(CLI_COMMAND_DELETEBUCKET + cfnModule.getBucketName() + " " + CLI_PARAM_FORCE);
    // Echo delete Stack
    cleanupScript.append(COMMAND_ECHO + STRING_DELETESTACK + cfnModule.getStackName());
    // Delete stack
    cleanupScript.append(CLI_COMMAND_DELETESTACK + CLI_PARAM_STACKNAME + cfnModule.getStackName());
}
Also used : BashScript(org.opentosca.toscana.plugins.scripts.BashScript)

Example 5 with BashScript

use of org.opentosca.toscana.plugins.scripts.BashScript in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationFileCreator method writeFileUploadScript.

/**
 *     Creates the script for File Uploads if files need to be uploaded.
 */
private void writeFileUploadScript() throws IOException {
    List<String> fileUploadList = getFilePaths(cfnModule.getFileUploadList());
    logger.debug("Checking if files need to be uploaded.");
    if (!fileUploadList.isEmpty()) {
        logger.debug("Files to be uploaded found. Creating file upload script.");
        BashScript fileUploadScript = new BashScript(cfnModule.getFileAccess(), FILENAME_UPLOAD);
        fileUploadScript.append(createBucket());
        logger.debug("Adding file upload commands.");
        addFileUploadsToScript(fileUploadList, fileUploadScript);
    } else {
        logger.debug("No files to be uploaded found. Skipping creation of file upload script.");
    }
}
Also used : BashScript(org.opentosca.toscana.plugins.scripts.BashScript)

Aggregations

BashScript (org.opentosca.toscana.plugins.scripts.BashScript)6 Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)2 Parameter (com.scaleset.cfbuilder.core.Parameter)1 File (java.io.File)1 List (java.util.List)1 Map (java.util.Map)1 Before (org.junit.Before)1 PluginFileAccess (org.opentosca.toscana.core.plugin.PluginFileAccess)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 FileUpload (org.opentosca.toscana.plugins.cloudformation.util.FileUpload)1 Deployment (org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment)1