Search in sources :

Example 1 with ScalarEntity

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

the class GraphNormalizer method normalizeDynamicRequirement.

private static void normalizeDynamicRequirement(ServiceGraph graph, MappingEntity requirement) {
    try {
        ScalarEntity relationship = (ScalarEntity) requirement.getChildOrThrow(Requirement.RELATIONSHIP_NAME);
        normalize(graph, relationship, BaseToscaElement.TYPE.name);
        ScalarEntity capability = (ScalarEntity) requirement.getChildOrThrow(Requirement.CAPABILITY_NAME);
        normalize(graph, capability, BaseToscaElement.TYPE.name);
    } catch (ClassCastException | ToscaTemplateException e) {
        logger.error("Detected invalid extended requirement assignment");
        throw e;
    }
}
Also used : ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) ToscaTemplateException(org.opentosca.toscana.core.parse.ToscaTemplateException)

Example 2 with ScalarEntity

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

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

the class IntrinsicFunctionResolver method getInputTarget.

private static Entity getInputTarget(Entity functionEntity) {
    ServiceGraph graph = functionEntity.getGraph();
    ScalarEntity inputFunctionEntity = (ScalarEntity) functionEntity;
    String inputName = inputFunctionEntity.getValue();
    Entity inputEntity = graph.getEntityOrThrow(ToscaStructure.INPUTS.descend(inputName));
    Optional<Entity> inputValue = inputEntity.getChild(Parameter.VALUE);
    return inputValue.orElseThrow(() -> new ToscaTemplateException(String.format("Input '%s' is referenced but its value is not set", inputName)));
}
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) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) ToscaTemplateException(org.opentosca.toscana.core.parse.ToscaTemplateException)

Example 4 with ScalarEntity

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

the class IntrinsicFunctionResolver method getTargetNodeEntity.

private static Entity getTargetNodeEntity(Entity targetNodeNameEntity, Entity functionEntity) {
    ServiceGraph graph = targetNodeNameEntity.getGraph();
    String targetNodeName = ((ScalarEntity) targetNodeNameEntity).getValue();
    if ("SELF".equals(targetNodeName)) {
        return NavigationUtil.getEnclosingNode(functionEntity);
    } else {
        return graph.getEntityOrThrow(ToscaStructure.NODE_TEMPLATES.descend(targetNodeName));
    }
}
Also used : ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity)

Example 5 with ScalarEntity

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

ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)10 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)7 Entity (org.opentosca.toscana.core.parse.model.Entity)6 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)4 ToscaTemplateException (org.opentosca.toscana.core.parse.ToscaTemplateException)3 EntityId (org.opentosca.toscana.model.EntityId)3 Test (org.junit.Test)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 EnumUtils (org.apache.commons.lang3.EnumUtils)1 Connection (org.opentosca.toscana.core.parse.model.Connection)1 BaseToscaElement (org.opentosca.toscana.model.BaseToscaElement)1 Artifact (org.opentosca.toscana.model.artifact.Artifact)1 Port (org.opentosca.toscana.model.datatype.Port)1 SizeUnit (org.opentosca.toscana.model.datatype.SizeUnit)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 OperationVariable (org.opentosca.toscana.model.operation.OperationVariable)1 ToscaKey (org.opentosca.toscana.model.util.ToscaKey)1