Search in sources :

Example 16 with RootNode

use of org.opentosca.toscana.model.node.RootNode in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationVisitorExtension method getHostsOfConnectedTo.

protected Set<Compute> getHostsOfConnectedTo(RootNode node) {
    Set<Compute> connected = new HashSet<>();
    Set<RootRelationship> incomingEdges = topology.incomingEdgesOf(node);
    for (RootRelationship incomingEdge : incomingEdges) {
        RootNode source = topology.getEdgeSource(incomingEdge);
        if (source instanceof WebApplication) {
            WebApplication webApplication = (WebApplication) source;
            Compute compute = getCompute(webApplication);
            connected.add(compute);
        }
    }
    return connected;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Compute(org.opentosca.toscana.model.node.Compute) WebApplication(org.opentosca.toscana.model.node.WebApplication) HashSet(java.util.HashSet) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 17 with RootNode

use of org.opentosca.toscana.model.node.RootNode in project TOSCAna by StuPro-TOSCAna.

the class PrepareModelRelationshipVisitor method visit.

@Override
public void visit(ConnectsTo relation) {
    RootNode source = topology.getEdgeSource(relation);
    RootNode target = topology.getEdgeTarget(relation);
    if (source instanceof WebApplication && target instanceof MysqlDatabase) {
        MysqlDatabase mysqlDatabase = (MysqlDatabase) target;
        WebApplication webApplication = (WebApplication) source;
        // if they are hosted on the same compute --> we can set the compute private address to
        Compute computeMysqlDatabase = getCompute(mysqlDatabase);
        Compute computeWebApplication = getCompute(webApplication);
        if (computeMysqlDatabase.equals(computeWebApplication)) {
            // means we can set the private address as reference to the database endpoint
            Fn databaseEndpointFn = Fn.fnGetAtt(toAlphanumerical(mysqlDatabase.getEntityName()), AWS_ENDPOINT_REFERENCE);
            String databaseEndpoint = databaseEndpointFn.toString(true);
            cfnModule.putFn(databaseEndpoint, databaseEndpointFn);
            computeMysqlDatabase.setPrivateAddress(databaseEndpoint);
            computeMysqlDatabase.setPublicAddress(databaseEndpoint);
            logger.debug("Set private address and public address of '{}' to reference MysqlDatabase '{}'", computeMysqlDatabase.getEntityName(), mysqlDatabase.getEntityName());
        } else {
            logger.debug("Cannot safely set private/public address of '{}'", computeMysqlDatabase.getEntityName());
        }
    } else {
        logger.debug("Drop relationship, because it is not supported");
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) Compute(org.opentosca.toscana.model.node.Compute) Fn(com.scaleset.cfbuilder.core.Fn) WebApplication(org.opentosca.toscana.model.node.WebApplication)

Example 18 with RootNode

use of org.opentosca.toscana.model.node.RootNode in project TOSCAna by StuPro-TOSCAna.

the class CloudFoundryLifecycle method prepare.

@Override
public void prepare() {
    logger.info("Begin preparation for transformation to Cloud Foundry");
    PrepareVisitor prepareVisitor = new PrepareVisitor(logger);
    for (RootNode node : context.getModel().getNodes()) {
        node.accept(prepareVisitor);
    }
    logger.debug("Collecting Compute Nodes in topology");
    ComputeNodeFindingVisitor computeFinder = new ComputeNodeFindingVisitor();
    model.getNodes().forEach(e -> {
        e.accept(computeFinder);
        KubernetesNodeContainer container = new KubernetesNodeContainer(e);
        nodes.put(e.getEntityName(), container);
    });
    computeFinder.getComputeNodes().forEach(e -> computeNodes.add(nodes.get(e.getEntityName())));
    logger.debug("Finding top Level Nodes");
    graph = model.getTopology();
    Set<RootNode> topLevelNodes = determineTopLevelNodes(context.getModel(), computeFinder.getComputeNodes().stream().map(Compute.class::cast).collect(Collectors.toList()), e -> nodes.get(e.getEntityName()).activateParentComputeNode());
    logger.debug("Building complete Topology stacks");
    this.stacks.addAll(buildTopologyStacks(model, topLevelNodes, nodes));
    // TODO: check how many different applications there are and fill list with them
    // probably there must be a combination of application and set of nodes
    applications = new ArrayList<>();
    int i = 1;
    for (NodeStack stack : stacks) {
        Application myApp = new Application(i, context);
        i++;
        myApp.setProvider(provider);
        myApp.setConnection(connection);
        myApp.setName(stack.getStackName());
        myApp.addStack(stack);
        applications.add(myApp);
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Compute(org.opentosca.toscana.model.node.Compute) KubernetesNodeContainer(org.opentosca.toscana.plugins.kubernetes.util.KubernetesNodeContainer) NodeStack(org.opentosca.toscana.plugins.kubernetes.util.NodeStack) ComputeNodeFindingVisitor(org.opentosca.toscana.plugins.kubernetes.visitor.util.ComputeNodeFindingVisitor) PrepareVisitor(org.opentosca.toscana.plugins.cloudfoundry.visitor.PrepareVisitor) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application)

Example 19 with RootNode

use of org.opentosca.toscana.model.node.RootNode in project TOSCAna by StuPro-TOSCAna.

the class EffectiveModel method initEdges.

private void initEdges() {
    logger.info("Populating edges");
    for (RootNode node : topology.vertexSet()) {
        for (Requirement<?, ?, ?> requirement : node.getRequirements()) {
            Set<? extends RootNode> fulfillers = requirement.getFulfillers();
            for (RootNode fulfiller : fulfillers) {
                RootRelationship relationship = requirement.get(requirement.RELATIONSHIP);
                logger.info(LogFormat.pointAt(1, 25, node.getEntityName(), relationship.getClass().getSimpleName(), fulfiller.getEntityName()));
                topology.addEdge(node, fulfiller, relationship);
            }
        }
    }
    initialized = true;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 20 with RootNode

use of org.opentosca.toscana.model.node.RootNode 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

RootNode (org.opentosca.toscana.model.node.RootNode)20 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)7 WebApplication (org.opentosca.toscana.model.node.WebApplication)6 Compute (org.opentosca.toscana.model.node.Compute)4 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)4 LinkedList (java.util.LinkedList)3 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 UnsupportedTypeException (org.opentosca.toscana.model.visitor.UnsupportedTypeException)3 Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)3 NodeStack (org.opentosca.toscana.plugins.kubernetes.util.NodeStack)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Entity (org.opentosca.toscana.core.parse.model.Entity)2 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)2 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)2 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2