Search in sources :

Example 1 with RootNode

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

the class CheckModelRelationshipVisitor method visit.

@Override
public void visit(ConnectsTo relation) {
    RootNode source = topology.getEdgeSource(relation);
    RootNode target = topology.getEdgeTarget(relation);
    if (!(source instanceof WebApplication && target instanceof Database)) {
        throw new UnsupportedTypeException("ConnectsTo relationship from source: " + source + " to target: " + target + " not supported.");
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Database(org.opentosca.toscana.model.node.Database) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException) WebApplication(org.opentosca.toscana.model.node.WebApplication)

Example 2 with RootNode

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

the class NodeVisitor method visit.

/**
 *     a MysqlDatabase is a service in CloudFoundry
 *     Therefore the service will be added to the application where the source of the connects to relationship is
 */
@Override
public void visit(MysqlDatabase node) {
    /*
        create service
        ignore password and port
         */
    logger.debug("Visit Mysql Database");
    Set<RootNode> sourceNodes = getSourcesOfConnectsTo(node);
    Set<Application> belongingApplication = getSourceApplications(sourceNodes);
    if (CollectionUtils.isEmpty(belongingApplication)) {
        logger.error("No source node of connects to relationship of MysqlDatabase {} was found", node.getEntityName());
        throw new TransformationFailureException("Could not find source of database");
    }
    handleStandardLifecycle(node, false, myApp);
    logger.debug("Add MYSQL service to application");
    belongingApplication.forEach(app -> app.addService(node.getEntityName(), ServiceTypes.MYSQL));
    // current application is a dummy application
    myApp.applicationIsNotReal(belongingApplication);
    // check artifacts and add paths to application
    for (Artifact artifact : node.getArtifacts()) {
        String path = artifact.getFilePath();
        myApp.addFilePath(path);
        logger.debug("Add artifact path {} to application", path);
        if (path.endsWith("sql")) {
            myApp.addConfigMysql(node.getEntityName(), path);
            logger.info("Found a SQL script in artifact paths. Will execute it with python script in deployment phase");
        }
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) JavaApplication(org.opentosca.toscana.model.node.custom.JavaApplication) Artifact(org.opentosca.toscana.model.artifact.Artifact)

Example 3 with RootNode

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

the class CloudFormationPluginTest method testLamp.

@Test(expected = TransformationFailureException.class)
public void testLamp() {
    try {
        Set<RootNode> nodes = lamp.getNodes();
        // visit compute nodes first
        for (VisitableNode node : nodes) {
            if (node instanceof Compute) {
                node.accept(cfnNodeVisitor);
            }
        }
        for (VisitableNode node : nodes) {
            if (!(node instanceof Compute)) {
                node.accept(cfnNodeVisitor);
            }
        }
        System.err.println(cfnModule.toString());
    } catch (TransformationFailureException tfe) {
        // provided so this test can pass
        if (!(tfe.getCause() instanceof SdkClientException)) {
            throw tfe;
        }
        logger.debug("Passed without internet connection / credentials provided");
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) VisitableNode(org.opentosca.toscana.model.visitor.VisitableNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException) Compute(org.opentosca.toscana.model.node.Compute) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 4 with RootNode

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

the class TestNodeStacks method getLampNodeStacks.

public static Set<NodeStack> getLampNodeStacks(Log log) {
    Map<String, RootNode> map = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, log).getNodeMap();
    List<KubernetesNodeContainer> webAppNodes = new LinkedList<>();
    KubernetesNodeContainer computeContainer = new KubernetesNodeContainer(map.get("server"));
    computeContainer.hasParentComputeNode();
    webAppNodes.add(new KubernetesNodeContainer(map.get("my_app")));
    webAppNodes.add(new KubernetesNodeContainer(map.get("apache_web_server")));
    webAppNodes.add(computeContainer);
    NodeStack webAppNodeStack = new NodeStack(webAppNodes);
    // Manualy set the docker image tag (used for testing the ResourceFileCreator)
    webAppNodeStack.setDockerImageTag("my-app");
    return Sets.newHashSet(webAppNodeStack);
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) KubernetesNodeContainer(org.opentosca.toscana.plugins.kubernetes.util.KubernetesNodeContainer) NodeStack(org.opentosca.toscana.plugins.kubernetes.util.NodeStack) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) LinkedList(java.util.LinkedList)

Example 5 with RootNode

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

the class LinkResolver method resolveRepositories.

private static void resolveRepositories(ServiceGraph graph) {
    logger.debug(LogFormat.indent(1, "repositories"));
    Map<String, RootNode> nodes = new TypeWrapper().wrapNodes(graph);
    for (RootNode node : nodes.values()) {
        for (Artifact artifact : node.getArtifacts()) {
            MappingEntity artifactEntity = artifact.getBackingEntity();
            Optional<Entity> repository = artifactEntity.getChild(Artifact.REPOSITORY.name);
            if (repository.isPresent()) {
                String url = ((ScalarEntity) repository.get()).getValue();
                EntityId targetId = ToscaStructure.REPOSITORIES.descend(url);
                Optional<Entity> target = graph.getEntity(targetId);
                target.ifPresent(baseEntity -> {
                    logger.debug(LogFormat.pointAt(2, repository.get().getId(), baseEntity.getId()));
                    graph.replaceEntity(repository.get(), baseEntity);
                });
            }
        }
    }
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) RootNode(org.opentosca.toscana.model.node.RootNode) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Artifact(org.opentosca.toscana.model.artifact.Artifact) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity)

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