Search in sources :

Example 1 with CFNFile

use of com.scaleset.cfbuilder.ec2.metadata.CFNFile in project TOSCAna by StuPro-TOSCAna.

the class OperationHandler method handleDependency.

/**
 *     Adds all dependencies to file uploads and to the EC2 Instance in the CloudFormation template.
 *
 *     @param operation  to be handled
 *     @param serverName name of the Compute/EC2 where the dependencies must be stored
 *     @param config     name of the config (Create/Start/Configure)
 */
private void handleDependency(Operation operation, String serverName, String config) {
    // Add dependencies
    for (String dependency : operation.getDependencies()) {
        markFile(dependency);
        CFNFile cfnFile = handleOperationFile(dependency, MODE_644, serverName);
        // Add file to config
        cfnModule.getCFNInit(serverName).getOrAddConfig(CONFIG_SETS, config).putFile(cfnFile);
    }
}
Also used : CFNFile(com.scaleset.cfbuilder.ec2.metadata.CFNFile)

Example 2 with CFNFile

use of com.scaleset.cfbuilder.ec2.metadata.CFNFile in project TOSCAna by StuPro-TOSCAna.

the class OperationHandler method handleArtifact.

/**
 *     Adds all artifacts to file uploads and to the EC2 Instance in the CloudFormation template.
 *     Also adds them as commands with input variables as environment variables to the given config.
 *
 *     @param operation  to be handled
 *     @param serverName name of the Compute/EC2 where the artifacts must be stored and executed
 *     @param config     name of the config (Create/Start/Configure)
 */
private void handleArtifact(Operation operation, String serverName, String config) {
    // Add artifact
    if (operation.getArtifact().isPresent()) {
        String artifact = operation.getArtifact().get().getFilePath();
        Set<OperationVariable> inputs = operation.getInputs();
        CFNCommand cfnCommand = handleOperationCommand(artifact, inputs);
        markFile(artifact);
        CFNFile cfnFile = handleOperationFile(artifact, MODE_500, serverName);
        // Add file to config and execution command
        cfnModule.getCFNInit(serverName).getOrAddConfig(CONFIG_SETS, config).putFile(cfnFile).putCommand(cfnCommand);
    }
}
Also used : OperationVariable(org.opentosca.toscana.model.operation.OperationVariable) CFNFile(com.scaleset.cfbuilder.ec2.metadata.CFNFile) CFNCommand(com.scaleset.cfbuilder.ec2.metadata.CFNCommand)

Example 3 with CFNFile

use of com.scaleset.cfbuilder.ec2.metadata.CFNFile in project TOSCAna by StuPro-TOSCAna.

the class EnvironmentHandler method addSetEnvScriptsToInstances.

/**
 *     Adds the setEnv scripts to their respective instances and adds commands to execute them.
 */
private void addSetEnvScriptsToInstances() {
    logger.debug("Adding setEnv scripts to Instances.");
    for (Map.Entry<String, Map<String, String>> instanceEnvironment : environmentMap.entrySet()) {
        String nodeName = instanceEnvironment.getKey();
        String filePath = SET_ENV + instanceEnvironment.getKey() + ".sh";
        String cfnSource = getFileURL(cfnModule.getBucketName(), filePath);
        CFNFile cfnFile = new CFNFile(ABSOLUTE_FILE_PATH + filePath).setSource(cfnSource).setMode(// TODO Check what mode is needed (read? + execute?)
        MODE_500).setOwner(// TODO Check what Owner is needed
        OWNER_GROUP_ROOT).setGroup(OWNER_GROUP_ROOT);
        CFNCommand cfnCommand = new CFNCommand(filePath, // file is the full path, so need for "./"
        ABSOLUTE_FILE_PATH + filePath).setCwd(ABSOLUTE_FILE_PATH);
        // Adds values of the environment variables to the environment of the setEnv scripts
        for (Map.Entry<String, String> environmentVariable : instanceEnvironment.getValue().entrySet()) {
            String value = environmentVariable.getValue();
            if (cfnModule.checkFn(value)) {
                cfnCommand.addEnv(environmentVariable.getKey(), cfnModule.getFn(value));
            } else {
                cfnCommand.addEnv(environmentVariable.getKey(), value);
            }
        }
        cfnModule.getCFNInit(nodeName).getOrAddConfig(CONFIG_SETS, CONFIG_CONFIGURE).putFile(cfnFile).putCommand(cfnCommand);
    }
}
Also used : CFNFile(com.scaleset.cfbuilder.ec2.metadata.CFNFile) CFNCommand(com.scaleset.cfbuilder.ec2.metadata.CFNCommand) Map(java.util.Map)

Example 4 with CFNFile

use of com.scaleset.cfbuilder.ec2.metadata.CFNFile in project TOSCAna by StuPro-TOSCAna.

the class OperationHandler method addCreate.

/**
 *     Manually adds a create command with the given input variables and file path to the given EC2 instance.
 *
 *     @param filePath   path to the artifact
 *     @param serverName name of the Instance
 */
public void addCreate(String filePath, String serverName) {
    markUtilFile(filePath);
    CFNFile cfnFile = handleOperationFile(filePath, MODE_500, serverName);
    CFNCommand cfnCommand = handleOperationCommand(filePath, new HashSet<>());
    // Add file to config and execution command
    cfnModule.getCFNInit(serverName).getOrAddConfig(CONFIG_SETS, CONFIG_CREATE).putFile(cfnFile).putCommand(cfnCommand);
}
Also used : CFNFile(com.scaleset.cfbuilder.ec2.metadata.CFNFile) CFNCommand(com.scaleset.cfbuilder.ec2.metadata.CFNCommand)

Aggregations

CFNFile (com.scaleset.cfbuilder.ec2.metadata.CFNFile)4 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)3 Map (java.util.Map)1 OperationVariable (org.opentosca.toscana.model.operation.OperationVariable)1