use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizer method normalizeOperations.
private static void normalizeOperations(ServiceGraph graph) {
logger.debug(LogFormat.indent(1, "operations"));
for (Entity node : graph.getChildren(ToscaStructure.NODE_TEMPLATES)) {
Optional<Entity> interfaces = node.getChild(RootNode.INTERFACES.name);
if (interfaces.isPresent()) {
for (Entity thisInterface : interfaces.get().getChildren()) {
for (Entity operation : thisInterface.getChildren()) {
logger.debug(LogFormat.indent(2, operation.getId()));
normalize(graph, operation, Operation.IMPLEMENTATION.name, Operation.PRIMARY.name);
Optional<Entity> implementation = graph.getEntity(operation.getId().descend(Operation.IMPLEMENTATION.name));
implementation.ifPresent(e -> normalize(graph, e, Operation.PRIMARY.name));
Optional<Entity> shortArtifact = graph.getEntity(operation.getId().descend(Operation.PRIMARY));
shortArtifact.ifPresent(artifact -> normalize(graph, artifact, Artifact.FILE_PATH.name));
}
}
}
}
}
use of org.opentosca.toscana.core.parse.model.Entity 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.Entity in project TOSCAna by StuPro-TOSCAna.
the class BaseToscaElement method getThisAsSet.
protected <T> Set<T> getThisAsSet(Class<T> type) {
TypeWrapper factory = new TypeWrapper();
Collection<Entity> values = mappingEntity.getChildren();
Set<T> results = new HashSet<>();
for (Entity v : values) {
T result = factory.wrapEntity((MappingEntity) v, type);
results.add(result);
}
return results;
}
use of org.opentosca.toscana.core.parse.model.Entity 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.Entity in project TOSCAna by StuPro-TOSCAna.
the class IntrinsicFunctionResolver method getPossibleTargetLocations.
private static List<Entity> getPossibleTargetLocations(ToscaKey location, Entity targetNode) {
List<Entity> possibleLocations = new ArrayList<>();
ToscaKey capabilityLocation = new ToscaKey<>(RootNode.CAPABILITIES, location.name);
ToscaKey requirementLocation = new ToscaKey<>(RootNode.REQUIREMENTS, location.name);
for (ToscaKey key : new ToscaKey[] { location, capabilityLocation, requirementLocation }) {
targetNode.getChild(key).ifPresent(possibleLocations::add);
}
return possibleLocations;
}
Aggregations