use of org.opentosca.toscana.core.parse.model.ScalarEntity 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.model.ScalarEntity in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizer method normalize.
private static void normalize(ServiceGraph graph, Entity entity, String... referencedKeys) {
if (entity instanceof ScalarEntity) {
ScalarEntity shortEntity = (ScalarEntity) entity;
MappingEntity normalizedEntity = new MappingEntity(shortEntity.getId(), graph);
EntityId referencedId = shortEntity.getId();
for (String referencedKey : referencedKeys) {
referencedId = referencedId.descend(referencedKey);
}
ScalarEntity referencedEntity = new ScalarEntity(shortEntity.getValue(), referencedId, graph);
graph.replaceEntity(shortEntity, normalizedEntity);
graph.addEntity(referencedEntity);
}
}
use of org.opentosca.toscana.core.parse.model.ScalarEntity 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.ScalarEntity 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.ScalarEntity in project TOSCAna by StuPro-TOSCAna.
the class LinkResolver method resolveRepositories.
private static void resolveRepositories(ServiceGraph graph) {
logger.debug(LogFormat.indent(1, "repositories"));
Map<String, RootNode> nodes = new TypeWrapper().wrapNodes(graph);
for (RootNode node : nodes.values()) {
for (Artifact artifact : node.getArtifacts()) {
MappingEntity artifactEntity = artifact.getBackingEntity();
Optional<Entity> repository = artifactEntity.getChild(Artifact.REPOSITORY.name);
if (repository.isPresent()) {
String url = ((ScalarEntity) repository.get()).getValue();
EntityId targetId = ToscaStructure.REPOSITORIES.descend(url);
Optional<Entity> target = graph.getEntity(targetId);
target.ifPresent(baseEntity -> {
logger.debug(LogFormat.pointAt(2, repository.get().getId(), baseEntity.getId()));
graph.replaceEntity(repository.get(), baseEntity);
});
}
}
}
}
Aggregations