Search in sources :

Example 6 with Entity

use of org.opentosca.toscana.core.parse.model.Entity 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)

Example 7 with Entity

use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.

the class TypeWrapper method wrapNodes.

public static Map<String, RootNode> wrapNodes(ServiceGraph graph) {
    Map<String, RootNode> nodes = new HashMap<>();
    Iterator<Entity> it = graph.iterator(ToscaStructure.NODE_TEMPLATES);
    while (it.hasNext()) {
        RootNode node = wrapTypedElement((MappingEntity) it.next());
        nodes.put(node.getEntityName(), node);
    }
    return nodes;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) HashMap(java.util.HashMap)

Example 8 with Entity

use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.

the class GraphNormalizerTest method operationNormalization.

@Test
public void operationNormalization() {
    ServiceGraph graph = new ServiceGraph(OPERATION, logMock());
    EntityId lifecycleId = ToscaStructure.NODE_TEMPLATES.descend("test-node").descend(RootNode.INTERFACES.name).descend(RootNode.STANDARD_LIFECYCLE.name);
    EntityId createId = lifecycleId.descend(StandardLifecycle.CREATE.name);
    Entity createEntity = graph.getEntity(createId).get();
    Operation create = new TypeWrapper().wrapEntity((MappingEntity) createEntity, Operation.class);
    assertTrue(create.getArtifact().isPresent());
    Artifact createArtifact = create.getArtifact().get();
    assertEquals("test-artifact", createArtifact.getFilePath());
    EntityId startId = lifecycleId.descend(StandardLifecycle.START.name);
    Entity startEntity = graph.getEntity(startId).get();
    Operation start = new TypeWrapper().wrapEntity((MappingEntity) startEntity, Operation.class);
    assertTrue(start.getArtifact().isPresent());
    Artifact startArtifact = start.getArtifact().get();
    assertEquals("test-artifact2", startArtifact.getFilePath());
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) Operation(org.opentosca.toscana.model.operation.Operation) Artifact(org.opentosca.toscana.model.artifact.Artifact) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 9 with Entity

use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.

the class GraphNormalizerTest method repositoryNormalization.

@Test
public void repositoryNormalization() {
    ServiceGraph graph = new ServiceGraph(REPOSITORY, logMock());
    Collection<Entity> repositories = graph.getEntity(ToscaStructure.REPOSITORIES).get().getChildren();
    Entity repository = repositories.iterator().next();
    Optional<Entity> url = repository.getChild("url");
    assertTrue(url.isPresent());
    Assert.assertEquals("http://test.repo.com/", ((ScalarEntity) url.get()).getValue());
}
Also used : ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 10 with Entity

use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.

the class GraphNormalizerTest method artifactNormalization.

@Test
public void artifactNormalization() {
    ServiceGraph graph = new ServiceGraph(ARTIFACT, logMock());
    EntityId nodeId = ToscaStructure.NODE_TEMPLATES.descend("test-node");
    Entity nodeEntity = graph.getEntityOrThrow(nodeId);
    WebApplication webApplication = new TypeWrapper().wrapEntity((MappingEntity) nodeEntity, WebApplication.class);
    Artifact artifact = webApplication.getArtifacts().iterator().next();
    assertEquals("test-artifact", artifact.getEntityName());
    assertEquals("test-artifact-file", artifact.getFilePath());
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) WebApplication(org.opentosca.toscana.model.node.WebApplication) Artifact(org.opentosca.toscana.model.artifact.Artifact) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Aggregations

Entity (org.opentosca.toscana.core.parse.model.Entity)18 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)17 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)15 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)5 EntityId (org.opentosca.toscana.model.EntityId)4 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 ToscaTemplateException (org.opentosca.toscana.core.parse.ToscaTemplateException)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 RootNode (org.opentosca.toscana.model.node.RootNode)2 ToscaKey (org.opentosca.toscana.model.util.ToscaKey)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 EnumUtils (org.apache.commons.lang3.EnumUtils)1 TypeWrapper (org.opentosca.toscana.core.parse.converter.TypeWrapper)1 Connection (org.opentosca.toscana.core.parse.model.Connection)1