Search in sources :

Example 1 with ToscaTemplateException

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;
    }
}
Also used : ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) ToscaTemplateException(org.opentosca.toscana.core.parse.ToscaTemplateException)

Example 2 with ToscaTemplateException

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)));
}
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 3 with ToscaTemplateException

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));
}
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) ToscaTemplateException(org.opentosca.toscana.core.parse.ToscaTemplateException)

Example 4 with ToscaTemplateException

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

ToscaTemplateException (org.opentosca.toscana.core.parse.ToscaTemplateException)4 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)4 Entity (org.opentosca.toscana.core.parse.model.Entity)3 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)3 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)1 EntityId (org.opentosca.toscana.model.EntityId)1