Search in sources :

Example 6 with Operation

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

the class OperationHandler method handleCreate.

/**
 *     Handles a create operation.
 *
 *     @param node            which the operation belongs to
 *     @param computeHostName alphanumerical name of the Compute host of node
 */
public void handleCreate(RootNode node, String computeHostName) {
    if (node.getStandardLifecycle().getCreate().isPresent()) {
        Operation create = node.getStandardLifecycle().getCreate().get();
        handleOperation(create, computeHostName, CONFIG_CREATE);
    }
}
Also used : Operation(org.opentosca.toscana.model.operation.Operation)

Example 7 with Operation

use of org.opentosca.toscana.model.operation.Operation 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)

Example 8 with Operation

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

the class NodeVisitor method getScripts.

private void getScripts(RootNode node, Application application) {
    StandardLifecycle lifecycle = node.getStandardLifecycle();
    Optional<Operation> configureOptional = lifecycle.getConfigure();
    // get configure script
    if (configureOptional.isPresent()) {
        Optional<Artifact> configureArtifact = configureOptional.get().getArtifact();
        configureArtifact.ifPresent(artifact -> application.addExecuteFile(artifact.getFilePath(), node));
    }
    // get create script
    Optional<Operation> createOptional = lifecycle.getCreate();
    if (createOptional.isPresent()) {
        Optional<Artifact> createArtifact = createOptional.get().getArtifact();
        createArtifact.ifPresent(artifact -> application.addExecuteFile(artifact.getFilePath(), node));
    }
}
Also used : StandardLifecycle(org.opentosca.toscana.model.operation.StandardLifecycle) Operation(org.opentosca.toscana.model.operation.Operation) Artifact(org.opentosca.toscana.model.artifact.Artifact)

Example 9 with Operation

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

the class NodeVisitor method handleStandardLifecycle.

private void handleStandardLifecycle(RootNode node, boolean isTopNode, Application application) {
    // get node artifacts
    node.getArtifacts().stream().forEach(artifact -> {
        String filePath = artifact.getFilePath();
        application.setPathToApplication(filePath);
        application.addFilePath(filePath);
    });
    // get StandardLifecycle inputs
    for (OperationVariable lifecycleInput : node.getStandardLifecycle().getInputs()) {
        addEnvironmentVariable(lifecycleInput);
    }
    // get operation inputs
    for (Operation operation : node.getStandardLifecycle().getOperations()) {
        // artifact path
        if (operation.getArtifact().isPresent()) {
            String path = operation.getArtifact().get().getFilePath();
            setPathToApplication(path, isTopNode);
        }
        // add dependencies paths
        for (String dependency : operation.getDependencies()) {
            application.addFilePath(dependency);
            setPathToApplication(dependency, isTopNode);
        }
        // add inputs to environment list
        for (OperationVariable input : operation.getInputs()) {
            addEnvironmentVariable(input);
        }
    // TODO: investigate what to do with outputs?
    }
}
Also used : OperationVariable(org.opentosca.toscana.model.operation.OperationVariable) Operation(org.opentosca.toscana.model.operation.Operation)

Example 10 with Operation

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

the class LinkResolver method resolveImplementationArtifacts.

private static void resolveImplementationArtifacts(ServiceGraph graph) {
    logger.debug(LogFormat.indent(1, "artifacts"));
    Map<String, RootNode> nodes = new TypeWrapper().wrapNodes(graph);
    for (RootNode node : nodes.values()) {
        for (Interface thisInterface : node.getInterfaces()) {
            for (Operation operation : thisInterface.getOperations()) {
                Optional<Artifact> optionalArtifact = operation.getArtifact();
                if (optionalArtifact.isPresent()) {
                    Artifact operationArtifact = optionalArtifact.get();
                    for (Artifact nodeArtifact : node.getArtifacts()) {
                        if (operationArtifact.getFilePath().equals(nodeArtifact.getEntityName())) {
                            graph.replaceEntity(operationArtifact.getBackingEntity(), nodeArtifact.getBackingEntity());
                            logger.debug(LogFormat.pointAt(2, operationArtifact.getBackingEntity().getId(), nodeArtifact.getBackingEntity().getId()));
                        // at this point it's obvious: we need a better solution for navigating the service graph...
                        }
                    }
                }
            }
        }
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Operation(org.opentosca.toscana.model.operation.Operation) Interface(org.opentosca.toscana.model.operation.Interface) Artifact(org.opentosca.toscana.model.artifact.Artifact)

Aggregations

Operation (org.opentosca.toscana.model.operation.Operation)10 Artifact (org.opentosca.toscana.model.artifact.Artifact)5 Test (org.junit.Test)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 OperationVariable (org.opentosca.toscana.model.operation.OperationVariable)2 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 Entity (org.opentosca.toscana.core.parse.model.Entity)1 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)1 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)1 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 EntityId (org.opentosca.toscana.model.EntityId)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 WebServer (org.opentosca.toscana.model.node.WebServer)1 Interface (org.opentosca.toscana.model.operation.Interface)1 StandardLifecycle (org.opentosca.toscana.model.operation.StandardLifecycle)1