Search in sources :

Example 1 with ConnectsTo

use of org.opentosca.toscana.model.relation.ConnectsTo in project TOSCAna by StuPro-TOSCAna.

the class ServiceGraphTest method requirementTest.

@Test
public void requirementTest() {
    currentFile = REQUIREMENT;
    Optional<Entity> fulfiller = getGraph().getEntity(Lists.newArrayList("topology_template", "node_templates", "test-node", "requirements", "test-requirement1", "node"));
    assertTrue(fulfiller.isPresent());
    Optional<Entity> fulfiller2 = getGraph().getEntity(Lists.newArrayList("topology_template", "node_templates", "test-node", "requirements", "test-requirement2", "node"));
    assertTrue(fulfiller2.isPresent());
    MappingEntity capabilityEntity = (MappingEntity) getGraph().getEntity(new EntityId(Lists.newArrayList("topology_template", "node_templates", "test-node", "requirements", "test-requirement2", "capability"))).get();
    DatabaseEndpointCapability capability = TypeWrapper.wrapTypedElement(capabilityEntity);
    assertNotNull(capability);
    MappingEntity relationshipEntity = (MappingEntity) getGraph().getEntity(new EntityId(Lists.newArrayList("topology_template", "node_templates", "test-node", "requirements", "test-requirement2", "relationship"))).get();
    ConnectsTo relationship = TypeWrapper.wrapTypedElement(relationshipEntity);
    assertNotNull(relationship);
    assertEquals(Lists.newArrayList("1", "2"), getList("topology_template", "node_templates", "test-node", "requirements", "test-requirement2", "occurrences"));
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) ConnectsTo(org.opentosca.toscana.model.relation.ConnectsTo) DatabaseEndpointCapability(org.opentosca.toscana.model.capability.DatabaseEndpointCapability) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 2 with ConnectsTo

use of org.opentosca.toscana.model.relation.ConnectsTo 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

ConnectsTo (org.opentosca.toscana.model.relation.ConnectsTo)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 EntityId (org.opentosca.toscana.model.EntityId)1 DatabaseEndpointCapability (org.opentosca.toscana.model.capability.DatabaseEndpointCapability)1 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)1 RootNode (org.opentosca.toscana.model.node.RootNode)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