use of org.opentosca.toscana.core.parse.model.MappingEntity 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);
});
}
}
}
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class TypeWrapper method wrapNodes.
public static Map<String, RootNode> wrapNodes(ServiceGraph graph) {
Map<String, RootNode> nodes = new HashMap<>();
Iterator<Entity> it = graph.iterator(ToscaStructure.NODE_TEMPLATES);
while (it.hasNext()) {
RootNode node = wrapTypedElement((MappingEntity) it.next());
nodes.put(node.getEntityName(), node);
}
return nodes;
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizerTest method operationNormalization.
@Test
public void operationNormalization() {
ServiceGraph graph = new ServiceGraph(OPERATION, logMock());
EntityId lifecycleId = ToscaStructure.NODE_TEMPLATES.descend("test-node").descend(RootNode.INTERFACES.name).descend(RootNode.STANDARD_LIFECYCLE.name);
EntityId createId = lifecycleId.descend(StandardLifecycle.CREATE.name);
Entity createEntity = graph.getEntity(createId).get();
Operation create = new TypeWrapper().wrapEntity((MappingEntity) createEntity, Operation.class);
assertTrue(create.getArtifact().isPresent());
Artifact createArtifact = create.getArtifact().get();
assertEquals("test-artifact", createArtifact.getFilePath());
EntityId startId = lifecycleId.descend(StandardLifecycle.START.name);
Entity startEntity = graph.getEntity(startId).get();
Operation start = new TypeWrapper().wrapEntity((MappingEntity) startEntity, Operation.class);
assertTrue(start.getArtifact().isPresent());
Artifact startArtifact = start.getArtifact().get();
assertEquals("test-artifact2", startArtifact.getFilePath());
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizerTest method artifactNormalization.
@Test
public void artifactNormalization() {
ServiceGraph graph = new ServiceGraph(ARTIFACT, logMock());
EntityId nodeId = ToscaStructure.NODE_TEMPLATES.descend("test-node");
Entity nodeEntity = graph.getEntityOrThrow(nodeId);
WebApplication webApplication = new TypeWrapper().wrapEntity((MappingEntity) nodeEntity, WebApplication.class);
Artifact artifact = webApplication.getArtifacts().iterator().next();
assertEquals("test-artifact", artifact.getEntityName());
assertEquals("test-artifact-file", artifact.getFilePath());
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class TypeResolverTest method supportForAllWineryNodeTypes.
@Test
public void supportForAllWineryNodeTypes() {
Set<String> wineryNodeTypes = getWineryNodeTypes();
for (String nodeType : wineryNodeTypes) {
logger.info("Testing conversion of type '{}'", nodeType);
ServiceGraph graph = new ServiceGraph(logMock());
MappingEntity nodeEntity = new MappingEntity(ToscaStructure.NODE_TEMPLATES.descend("my-node"), graph);
graph.addEntity(nodeEntity);
ScalarEntity typeEntity = new ScalarEntity(nodeType, nodeEntity.getId().descend("type"), graph);
graph.addEntity(typeEntity);
BaseToscaElement node = TypeWrapper.wrapTypedElement(nodeEntity);
assertNotNull(node);
logger.info("Node Type '{}': known", nodeType);
System.out.println();
}
// successful if no exception thrown
}
Aggregations