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