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