Search in sources :

Example 1 with Entity

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

the class GraphNormalizer method normalizeOperations.

private static void normalizeOperations(ServiceGraph graph) {
    logger.debug(LogFormat.indent(1, "operations"));
    for (Entity node : graph.getChildren(ToscaStructure.NODE_TEMPLATES)) {
        Optional<Entity> interfaces = node.getChild(RootNode.INTERFACES.name);
        if (interfaces.isPresent()) {
            for (Entity thisInterface : interfaces.get().getChildren()) {
                for (Entity operation : thisInterface.getChildren()) {
                    logger.debug(LogFormat.indent(2, operation.getId()));
                    normalize(graph, operation, Operation.IMPLEMENTATION.name, Operation.PRIMARY.name);
                    Optional<Entity> implementation = graph.getEntity(operation.getId().descend(Operation.IMPLEMENTATION.name));
                    implementation.ifPresent(e -> normalize(graph, e, Operation.PRIMARY.name));
                    Optional<Entity> shortArtifact = graph.getEntity(operation.getId().descend(Operation.PRIMARY));
                    shortArtifact.ifPresent(artifact -> normalize(graph, artifact, Artifact.FILE_PATH.name));
                }
            }
        }
    }
}
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)

Example 2 with Entity

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

the class IntrinsicFunctionResolver method resolveFunction.

/**
 *     @param functionHolder the outcome of a call to {@link #holdsFunction(Entity)} with this entity must be true
 *     @return returns the resolved target. Returns null if target does not exist and function type allows missing target
 *     @throws IllegalStateException if call to {@link #holdsFunction(Entity)}
 *     with same entity as argument comes out as false
 */
public static Entity resolveFunction(Entity functionHolder) throws AttributeNotSetException {
    if (!holdsFunction(functionHolder)) {
        throw new IllegalStateException(String.format("Given entity '%s' does not hold a function - illegal call to resolveFunction", functionHolder));
    }
    Entity parent = functionHolder.getParent().orElseThrow(() -> new IllegalStateException("Function does not have a parent"));
    Entity functionTarget = getTarget((MappingEntity) functionHolder);
    if (functionTarget != null) {
        ServiceGraph graph = functionHolder.getGraph();
        // only removing connection - the actual function entities stay in the graph; might be easier for debugging
        graph.removeEdge(parent, functionHolder);
        graph.addConnection(parent, functionTarget, functionHolder.getName());
    }
    return functionTarget;
}
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)

Example 3 with Entity

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

the class BaseToscaElement method getThisAsSet.

protected <T> Set<T> getThisAsSet(Class<T> type) {
    TypeWrapper factory = new TypeWrapper();
    Collection<Entity> values = mappingEntity.getChildren();
    Set<T> results = new HashSet<>();
    for (Entity v : values) {
        T result = factory.wrapEntity((MappingEntity) v, type);
        results.add(result);
    }
    return results;
}
Also used : MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) TypeWrapper(org.opentosca.toscana.core.parse.converter.TypeWrapper) HashSet(java.util.HashSet)

Example 4 with Entity

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

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

the class IntrinsicFunctionResolver method getPossibleTargetLocations.

private static List<Entity> getPossibleTargetLocations(ToscaKey location, Entity targetNode) {
    List<Entity> possibleLocations = new ArrayList<>();
    ToscaKey capabilityLocation = new ToscaKey<>(RootNode.CAPABILITIES, location.name);
    ToscaKey requirementLocation = new ToscaKey<>(RootNode.REQUIREMENTS, location.name);
    for (ToscaKey key : new ToscaKey[] { location, capabilityLocation, requirementLocation }) {
        targetNode.getChild(key).ifPresent(possibleLocations::add);
    }
    return possibleLocations;
}
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) ArrayList(java.util.ArrayList) ToscaKey(org.opentosca.toscana.model.util.ToscaKey)

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