Search in sources :

Example 1 with OperationVariable

use of org.opentosca.toscana.model.operation.OperationVariable 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 2 with OperationVariable

use of org.opentosca.toscana.model.operation.OperationVariable in project TOSCAna by StuPro-TOSCAna.

the class OperationHandler method handleOperationCommand.

/**
 *     Takes an artifact path and input variables and returns the corresponding CloudFormation command with input variables.
 *
 *     @param artifact path to the artifact
 *     @param inputs   set with all input variables
 *     @return CFNCommand corresponding to the given artifact
 */
private CFNCommand handleOperationCommand(String artifact, Set<OperationVariable> inputs) {
    String parent = new File(artifact).getParent();
    if (parent == null) {
        parent = "";
    }
    CFNCommand cfnCommand = new CFNCommand(artifact, // file is the full path, so need for "./"
    ABSOLUTE_FILE_PATH + artifact).setCwd(ABSOLUTE_FILE_PATH + parent);
    // add inputs to environment
    for (OperationVariable input : inputs) {
        String value = input.getValue().orElseThrow(() -> new IllegalArgumentException("Input value of " + input.getKey() + " expected to not be " + "null"));
        if (cfnModule.checkFn(value)) {
            cfnCommand.addEnv(input.getKey(), cfnModule.getFn(value));
        } else {
            cfnCommand.addEnv(input.getKey(), value);
        }
    }
    return cfnCommand;
}
Also used : OperationVariable(org.opentosca.toscana.model.operation.OperationVariable) CFNCommand(com.scaleset.cfbuilder.ec2.metadata.CFNCommand) File(java.io.File) CFNFile(com.scaleset.cfbuilder.ec2.metadata.CFNFile)

Example 3 with OperationVariable

use of org.opentosca.toscana.model.operation.OperationVariable in project TOSCAna by StuPro-TOSCAna.

the class IntrinsicFunctionResolverTest method getNestedPropertyTest.

@Test
public void getNestedPropertyTest() {
    EffectiveModel model = new EffectiveModelFactory().create(GET_PROPERTY_IN_INTERFACE, logMock());
    Database database = (Database) model.getNodeMap().get("my_db");
    Set<OperationVariable> inputs = database.getStandardLifecycle().getConfigure().get().getInputs();
    OperationVariable input = inputs.stream().findFirst().orElse(null);
    assertEquals("my_user_name", input.getValue().get());
}
Also used : OperationVariable(org.opentosca.toscana.model.operation.OperationVariable) Database(org.opentosca.toscana.model.node.Database) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 4 with OperationVariable

use of org.opentosca.toscana.model.operation.OperationVariable in project TOSCAna by StuPro-TOSCAna.

the class IntrinsicFunctionResolverTest method correctPropertyNameTest.

/**
 *     Tests whether names of linked properties are correct
 */
@Test
public void correctPropertyNameTest() {
    EffectiveModel model = new EffectiveModelFactory().create(GET_PROPERTY_IN_INPUT, logMock());
    Database myApp = (Database) model.getNodeMap().get("my_db");
    OperationVariable input = myApp.getStandardLifecycle().getConfigure().get().getInputs().iterator().next();
    assertEquals("correct-name", input.getKey());
    assertEquals("test-string", input.getValue().get());
}
Also used : OperationVariable(org.opentosca.toscana.model.operation.OperationVariable) Database(org.opentosca.toscana.model.node.Database) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 5 with OperationVariable

use of org.opentosca.toscana.model.operation.OperationVariable in project TOSCAna by StuPro-TOSCAna.

the class OperationHandler method handleStart.

/**
 *     Handles a start operation.
 *
 *     @param node            which the operation belongs to
 *     @param computeHostName alphanumerical name of the Compute host of node
 */
public void handleStart(RootNode node, String computeHostName) {
    if (node.getStandardLifecycle().getStart().isPresent()) {
        Operation start = node.getStandardLifecycle().getStart().get();
        handleOperation(start, computeHostName, CONFIG_START);
        // Add environment variables
        Set<OperationVariable> inputs = start.getInputs();
        if (!inputs.isEmpty()) {
            for (OperationVariable input : inputs) {
                String value = input.getValue().orElseThrow(() -> new IllegalArgumentException("Input value of " + input.getKey() + " expected to not be " + "null"));
                cfnModule.putEnvironmentMap(computeHostName, input.getKey(), value);
            }
        }
    }
}
Also used : OperationVariable(org.opentosca.toscana.model.operation.OperationVariable) Operation(org.opentosca.toscana.model.operation.Operation)

Aggregations

OperationVariable (org.opentosca.toscana.model.operation.OperationVariable)7 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)2 CFNFile (com.scaleset.cfbuilder.ec2.metadata.CFNFile)2 Test (org.junit.Test)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)2 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)2 Database (org.opentosca.toscana.model.node.Database)2 Operation (org.opentosca.toscana.model.operation.Operation)2 File (java.io.File)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 EnumUtils (org.apache.commons.lang3.EnumUtils)1 Connection (org.opentosca.toscana.core.parse.model.Connection)1 Entity (org.opentosca.toscana.core.parse.model.Entity)1 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)1 Port (org.opentosca.toscana.model.datatype.Port)1 SizeUnit (org.opentosca.toscana.model.datatype.SizeUnit)1 ToscaKey (org.opentosca.toscana.model.util.ToscaKey)1