Search in sources :

Example 1 with EntityId

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

the class GraphNormalizer method normalize.

private static void normalize(ServiceGraph graph, Entity entity, String... referencedKeys) {
    if (entity instanceof ScalarEntity) {
        ScalarEntity shortEntity = (ScalarEntity) entity;
        MappingEntity normalizedEntity = new MappingEntity(shortEntity.getId(), graph);
        EntityId referencedId = shortEntity.getId();
        for (String referencedKey : referencedKeys) {
            referencedId = referencedId.descend(referencedKey);
        }
        ScalarEntity referencedEntity = new ScalarEntity(shortEntity.getValue(), referencedId, graph);
        graph.replaceEntity(shortEntity, normalizedEntity);
        graph.addEntity(referencedEntity);
    }
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity)

Example 2 with EntityId

use of org.opentosca.toscana.model.EntityId 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 3 with EntityId

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

the class Entity method getParent.

public Optional<Entity> getParent() {
    EntityId parentId = getId().ascend();
    if (parentId == null) {
        return Optional.empty();
    }
    Entity parent = graph.getEntityOrThrow(parentId);
    return Optional.of(parent);
}
Also used : EntityId(org.opentosca.toscana.model.EntityId)

Example 4 with EntityId

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

the class Entity method setValue.

public <V> void setValue(ToscaKey<V> key, V value) {
    EntityId id = this.id.descend(key);
    final Entity newEntity;
    if (BaseToscaElement.class.isAssignableFrom(key.getType())) {
        newEntity = ((BaseToscaElement) value).getBackingEntity();
    } else {
        String normalizedValue = (value == null) ? null : value.toString();
        newEntity = new ScalarEntity(normalizedValue, id, graph);
    }
    Optional<Entity> oldEntity = graph.getEntity(id);
    if (oldEntity.isPresent()) {
        graph.replaceEntity(oldEntity.get(), newEntity);
    } else {
        graph.addEntity(newEntity);
    }
}
Also used : EntityId(org.opentosca.toscana.model.EntityId)

Example 5 with EntityId

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

the class MappingEntity method getOrNewChild.

/**
 *     Returns the child entity specified by given key. If the child entity does not exist yet, creates the entity.
 */
public MappingEntity getOrNewChild(ToscaKey<?> key) {
    MappingEntity child;
    Optional<Entity> entity = getChild(key);
    if (entity.isPresent()) {
        child = (MappingEntity) entity.get();
    } else {
        EntityId childId = getId();
        if (key.getPredecessor().isPresent()) {
            if (key.getPredecessor().get().isList()) {
            // childId = childId.descend();
            // todo
            }
        }
        child = new MappingEntity(childId.descend(key), graph);
        graph.addEntity(child);
    }
    return child;
}
Also used : EntityId(org.opentosca.toscana.model.EntityId)

Aggregations

EntityId (org.opentosca.toscana.model.EntityId)13 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)5 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)5 Entity (org.opentosca.toscana.core.parse.model.Entity)4 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)2 ToscaTemplateException (org.opentosca.toscana.core.parse.ToscaTemplateException)1 DatabaseEndpointCapability (org.opentosca.toscana.model.capability.DatabaseEndpointCapability)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)1 Operation (org.opentosca.toscana.model.operation.Operation)1 ConnectsTo (org.opentosca.toscana.model.relation.ConnectsTo)1 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)1 Node (org.yaml.snakeyaml.nodes.Node)1 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)1