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);
}
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;
}
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)));
}
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));
}
}
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());
}
Aggregations