Search in sources :

Example 11 with MappingEntity

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

the class MapperTest method getEntity.

public static MappingEntity getEntity() {
    ServiceGraph graph = new ServiceGraph(BaseTest.logMock());
    MappingEntity entity = new MappingEntity(entityId, graph);
    graph.addEntity(entity);
    return entity;
}
Also used : ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity)

Example 12 with MappingEntity

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

the class MapperTagLoaderIT method setUp.

@BeforeClass
public static void setUp() {
    ServiceGraph graph = new ServiceGraph(logMock());
    nodeEntity = new MappingEntity(entityId, graph);
    graph.addEntity(nodeEntity);
}
Also used : ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) BeforeClass(org.junit.BeforeClass)

Example 13 with MappingEntity

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

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

Example 15 with MappingEntity

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

the class LinkResolver method resolveRequirements.

private static void resolveRequirements(ServiceGraph graph) {
    logger.debug(LogFormat.indent(1, "requirements"));
    Iterator<Entity> nodeIt = graph.iterator(ToscaStructure.NODE_TEMPLATES);
    while (nodeIt.hasNext()) {
        Entity nodeEntity = nodeIt.next();
        Optional<Entity> requirementsEntity = nodeEntity.getChild(RootNode.REQUIREMENTS.name);
        if (requirementsEntity.isPresent()) {
            Collection<Entity> requirements = requirementsEntity.get().getChildren();
            for (Entity requirement : requirements) {
                MappingEntity mappingRequirement = (MappingEntity) requirement;
                ScalarEntity fulfillerEntity = (ScalarEntity) mappingRequirement.getChild(Requirement.NODE_NAME).get();
                String fulfillerName = fulfillerEntity.getValue();
                EntityId fulfillerId = ToscaStructure.NODE_TEMPLATES.descend(fulfillerName);
                logger.debug(LogFormat.pointAt(2, mappingRequirement.getId() + "." + Requirement.NODE_NAME, fulfillerId));
                Entity fulfiller = graph.getEntity(fulfillerId).orElseThrow(() -> new ToscaTemplateException(String.format("No node with name '%s' found, but required as fulfiller in requirement", fulfillerName)));
                graph.removeVertex(fulfillerEntity);
                graph.addConnection(mappingRequirement, fulfiller, Requirement.NODE_NAME);
            }
        }
    }
}
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) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) ToscaTemplateException(org.opentosca.toscana.core.parse.ToscaTemplateException) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity)

Aggregations

MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)17 Entity (org.opentosca.toscana.core.parse.model.Entity)10 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)9 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)7 EntityId (org.opentosca.toscana.model.EntityId)5 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 RootNode (org.opentosca.toscana.model.node.RootNode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 ToscaTemplateException (org.opentosca.toscana.core.parse.ToscaTemplateException)1 TypeWrapper (org.opentosca.toscana.core.parse.converter.TypeWrapper)1 BaseToscaElement (org.opentosca.toscana.model.BaseToscaElement)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)1 Operation (org.opentosca.toscana.model.operation.Operation)1 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)1 Requirement (org.opentosca.toscana.model.requirement.Requirement)1