Search in sources :

Example 11 with Entity

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

the class GraphNormalizer method normalizeRepositories.

private static synchronized void normalizeRepositories(ServiceGraph graph) {
    logger.debug(LogFormat.indent(1, "repositories"));
    for (Entity repository : graph.getChildren(ToscaStructure.REPOSITORIES)) {
        logger.debug(LogFormat.indent(2, repository.getId()));
        normalize(graph, repository, Repository.URL.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 12 with Entity

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

the class IntrinsicFunctionResolver method holdsFunction.

/**
 *     @param entity holds function if entity is a MappingEntity and has a child entity with its name exactly matching
 *     one of the supported intrinsic function names.
 *     @return true if given entity holds a tosca intrinsic function,  false otherwise
 */
public static boolean holdsFunction(Entity entity) {
    if (entity instanceof MappingEntity) {
        MappingEntity mappingEntity = (MappingEntity) entity;
        Collection<Entity> children = mappingEntity.getChildren();
        if (children.size() == 1) {
            Entity child = children.iterator().next();
            for (ToscaFunction toscaFunction : ToscaFunction.values()) {
                if (toscaFunction.name.equals(child.getName())) {
                    return true;
                }
            }
        }
    }
    return false;
}
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) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity)

Example 13 with Entity

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

the class IntrinsicFunctionResolver method getPropertyOrAttributeTarget.

private static Entity getPropertyOrAttributeTarget(Entity functionEntity, ToscaFunction function) throws AttributeNotSetException {
    Collection<Entity> targetAddress = functionEntity.getChildren();
    if (targetAddress.size() < 2) {
        throw new ToscaTemplateException(String.format("Illegal amount of parameters for function at '%s'", functionEntity.getId()));
    }
    Iterator<Entity> it = targetAddress.iterator();
    Entity targetNode = getTargetNodeEntity(it.next(), functionEntity);
    List<Entity> possibleLocations = getPossibleTargetLocations(function.location, targetNode);
    if (possibleLocations.isEmpty()) {
        return noTargetFound(function, functionEntity);
    }
    for (Entity possibleLocation : possibleLocations) {
        Entity current = findTarget(possibleLocation, it);
        if (current != null) {
            return current;
        }
    }
    return (noTargetFound(function, functionEntity));
}
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) ToscaTemplateException(org.opentosca.toscana.core.parse.ToscaTemplateException)

Example 14 with Entity

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

the class IntrinsicFunctionResolver method findTarget.

private static Entity findTarget(Entity current, Iterator<Entity> it) {
    while (it.hasNext()) {
        Entity next = it.next();
        Optional<Entity> child = current.getChild(((ScalarEntity) next).getValue());
        if (child.isPresent()) {
            current = child.get();
        } else {
            return null;
        }
    }
    return current;
}
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 15 with Entity

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

the class IntrinsicFunctionResolver method getTarget.

private static Entity getTarget(MappingEntity functionHolder) throws AttributeNotSetException {
    Entity functionEntity = functionHolder.getChildren().iterator().next();
    ToscaFunction function = ToscaFunction.getFunction(functionEntity.getName());
    switch(function) {
        case GET_INPUT:
            return getInputTarget(functionEntity);
        case GET_PROPERTY:
        case GET_ATTRIBUTE:
            return getPropertyOrAttributeTarget(functionEntity, function);
        default:
            throw new UnsupportedOperationException(String.format("Function %s not supported yet", function));
    }
}
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)

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