Search in sources :

Example 1 with Requirement

use of org.opentosca.toscana.model.requirement.Requirement in project TOSCAna by StuPro-TOSCAna.

the class DockerfileBuildingVisitor method handleDefault.

/**
 *     This method implements the default node transformation behaviour. This means, the
 *     exectuion of scripts implements the functionality thats expected from the node.
 */
private void handleDefault(RootNode node, String[] ignoredLifecycles) {
    try {
        Map<NodeStack, String> address = new HashMap<>();
        // Add the ports exposed by the node to the ports list
        node.getCapabilities().forEach(e -> {
            try {
                if (e instanceof EndpointCapability) {
                    if (((EndpointCapability) e).getPort().isPresent()) {
                        ports.add(((EndpointCapability) e).getPort().get().port);
                    }
                }
            } catch (Exception ex) {
                logger.warn("Failed reading Port from node {}", node.getEntityName(), ex);
            }
        });
        // name. We therefore have to set this to 127.0.0.1 ('localhost' causes issues too)
        for (Requirement e : node.getRequirements()) {
            if (e.getRelationship().isPresent() && e.getRelationship().get() instanceof ConnectsTo) {
                for (Object o : e.getFulfillers()) {
                    if (o instanceof RootNode) {
                        NodeStack targetStack = this.connectionGraph.vertexSet().stream().filter(ek -> ek.hasNode((RootNode) o)).findFirst().orElse(null);
                        if (targetStack != null && targetStack.getComputeNode() == this.stack.getComputeNode()) {
                            address.put(this.stack, this.stack.getComputeNode().getPrivateAddress().orElse(null));
                            this.stack.getComputeNode().setPrivateAddress(IPV4_LOCAL_ADDRESS);
                        }
                    }
                }
            }
        }
        // Add the scripts from the lifecycle to the Dockerfile
        addLifecycleOperationsToDockerfile(node.getEntityName(), node.getStandardLifecycle(), ignoredLifecycles);
        // Reset to original address
        address.forEach((k, v) -> {
            k.getComputeNode().setPrivateAddress(v);
        });
    } catch (IOException e) {
        throw new UnsupportedOperationException("Transformation failed while copying artifacts", e);
    }
}
Also used : Requirement(org.opentosca.toscana.model.requirement.Requirement) RootNode(org.opentosca.toscana.model.node.RootNode) ConnectsTo(org.opentosca.toscana.model.relation.ConnectsTo) HashMap(java.util.HashMap) NodeStack(org.opentosca.toscana.plugins.kubernetes.util.NodeStack) IOException(java.io.IOException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) IOException(java.io.IOException) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 ConnectsTo (org.opentosca.toscana.model.relation.ConnectsTo)1 Requirement (org.opentosca.toscana.model.requirement.Requirement)1 NodeStack (org.opentosca.toscana.plugins.kubernetes.util.NodeStack)1 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)1