Search in sources :

Example 1 with ServiceGraph

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

the class MapperUtilsTest method setUp.

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

Example 2 with ServiceGraph

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

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

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

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

the class GraphNormalizerTest method operationNormalization.

@Test
public void operationNormalization() {
    ServiceGraph graph = new ServiceGraph(OPERATION, logMock());
    EntityId lifecycleId = ToscaStructure.NODE_TEMPLATES.descend("test-node").descend(RootNode.INTERFACES.name).descend(RootNode.STANDARD_LIFECYCLE.name);
    EntityId createId = lifecycleId.descend(StandardLifecycle.CREATE.name);
    Entity createEntity = graph.getEntity(createId).get();
    Operation create = new TypeWrapper().wrapEntity((MappingEntity) createEntity, Operation.class);
    assertTrue(create.getArtifact().isPresent());
    Artifact createArtifact = create.getArtifact().get();
    assertEquals("test-artifact", createArtifact.getFilePath());
    EntityId startId = lifecycleId.descend(StandardLifecycle.START.name);
    Entity startEntity = graph.getEntity(startId).get();
    Operation start = new TypeWrapper().wrapEntity((MappingEntity) startEntity, Operation.class);
    assertTrue(start.getArtifact().isPresent());
    Artifact startArtifact = start.getArtifact().get();
    assertEquals("test-artifact2", startArtifact.getFilePath());
}
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) ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) Operation(org.opentosca.toscana.model.operation.Operation) Artifact(org.opentosca.toscana.model.artifact.Artifact) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Aggregations

ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)11 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)9 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)7 Entity (org.opentosca.toscana.core.parse.model.Entity)5 Test (org.junit.Test)4 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)4 EntityId (org.opentosca.toscana.model.EntityId)2 Artifact (org.opentosca.toscana.model.artifact.Artifact)2 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 ToscaTemplateException (org.opentosca.toscana.core.parse.ToscaTemplateException)1 BaseToscaElement (org.opentosca.toscana.model.BaseToscaElement)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)1 Operation (org.opentosca.toscana.model.operation.Operation)1