use of org.opentosca.toscana.core.parse.ToscaTemplateException in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizer method normalizeDynamicRequirement.
private static void normalizeDynamicRequirement(ServiceGraph graph, MappingEntity requirement) {
try {
ScalarEntity relationship = (ScalarEntity) requirement.getChildOrThrow(Requirement.RELATIONSHIP_NAME);
normalize(graph, relationship, BaseToscaElement.TYPE.name);
ScalarEntity capability = (ScalarEntity) requirement.getChildOrThrow(Requirement.CAPABILITY_NAME);
normalize(graph, capability, BaseToscaElement.TYPE.name);
} catch (ClassCastException | ToscaTemplateException e) {
logger.error("Detected invalid extended requirement assignment");
throw e;
}
}
use of org.opentosca.toscana.core.parse.ToscaTemplateException 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.ToscaTemplateException 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));
}
use of org.opentosca.toscana.core.parse.ToscaTemplateException 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