Search in sources :

Example 1 with EndpointCapability

use of org.opentosca.toscana.model.capability.EndpointCapability in project TOSCAna by StuPro-TOSCAna.

the class WebServer method init.

private void init() {
    setDefault(DATA_ENDPOINT, new EndpointCapability(getChildEntity(DATA_ENDPOINT)));
    setDefault(ADMIN_ENDPOINT, new AdminEndpointCapability(getChildEntity(ADMIN_ENDPOINT)));
    setDefault(CONTAINER_HOST, new ContainerCapability(getChildEntity(CONTAINER_HOST)));
}
Also used : AdminEndpointCapability(org.opentosca.toscana.model.capability.AdminEndpointCapability) ContainerCapability(org.opentosca.toscana.model.capability.ContainerCapability) AdminEndpointCapability(org.opentosca.toscana.model.capability.AdminEndpointCapability) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability)

Example 2 with EndpointCapability

use of org.opentosca.toscana.model.capability.EndpointCapability in project TOSCAna by StuPro-TOSCAna.

the class TransformModelNodeVisitor method visit.

@Override
public void visit(Nodejs node) {
    try {
        Compute computeHost = getCompute(node);
        String computeHostName = toAlphanumerical(computeHost.getEntityName());
        String nodeName = node.getEntityName();
        // handle configure
        operationHandler.handleConfigure(node, computeHostName);
        // handle start
        operationHandler.handleStart(node, computeHostName);
        // add NodeJs create script
        operationHandler.addCreate(FILEPATH_NODEJS_CREATE, computeHostName);
        // Get ports
        List<Integer> portList = new ArrayList<>();
        node.getCapabilities().forEach(e -> {
            try {
                if (e instanceof EndpointCapability && ((EndpointCapability) e).getPort().isPresent()) {
                    int port = ((EndpointCapability) e).getPort().get().port;
                    logger.debug("Marking '{}' as port to be opened for '{}'.", port, nodeName);
                    portList.add(port);
                }
            } catch (Exception ex) {
                logger.warn("Failed reading Port from node {}", nodeName, ex);
            }
        });
        // Open ports
        String SecurityGroupName = computeHostName + SECURITY_GROUP;
        SecurityGroup securityGroup = (SecurityGroup) cfnModule.getResource(SecurityGroupName);
        securityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, portList.toArray());
    } catch (Exception e) {
        logger.error("Error while creating Nodejs");
        throw new TransformationFailureException("Failed at Nodejs node " + node.getEntityName(), e);
    }
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Compute(org.opentosca.toscana.model.node.Compute) ArrayList(java.util.ArrayList) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability)

Example 3 with EndpointCapability

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

Example 4 with EndpointCapability

use of org.opentosca.toscana.model.capability.EndpointCapability in project TOSCAna by StuPro-TOSCAna.

the class DataTypeTest method portTest.

@Test
public void portTest() {
    EffectiveModel model = new EffectiveModelFactory().create(TestTemplates.Datatypes.PORT, logMock());
    WebApplication app = (WebApplication) model.getNodes().iterator().next();
    EndpointCapability endpoint = app.getAppEndpoint();
    assertEquals(new Port(3000), endpoint.getPort().get());
    Port expected = new Port(4000);
    endpoint.setPort(expected);
    assertEquals(expected, endpoint.getPort().get());
}
Also used : Port(org.opentosca.toscana.model.datatype.Port) WebApplication(org.opentosca.toscana.model.node.WebApplication) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 5 with EndpointCapability

use of org.opentosca.toscana.model.capability.EndpointCapability in project TOSCAna by StuPro-TOSCAna.

the class WebApplication method init.

private void init() {
    setDefault(APP_ENDPOINT, new EndpointCapability(getChildEntity(APP_ENDPOINT)));
    setDefault(HOST, new WebServerRequirement(getChildEntity(HOST)));
}
Also used : WebServerRequirement(org.opentosca.toscana.model.requirement.WebServerRequirement) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability)

Aggregations

EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)5 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)2 SdkClientException (com.amazonaws.SdkClientException)1 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 AdminEndpointCapability (org.opentosca.toscana.model.capability.AdminEndpointCapability)1 ContainerCapability (org.opentosca.toscana.model.capability.ContainerCapability)1 Port (org.opentosca.toscana.model.datatype.Port)1 Compute (org.opentosca.toscana.model.node.Compute)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)1 ConnectsTo (org.opentosca.toscana.model.relation.ConnectsTo)1 Requirement (org.opentosca.toscana.model.requirement.Requirement)1 WebServerRequirement (org.opentosca.toscana.model.requirement.WebServerRequirement)1