use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.
the class Detection method detectPattern.
/**
* 2. step: Create all subgraphs of the topology graph and test for isomorphism with pattern graphs
*
* @param tTopologyTemplate: the TOSCA topology will be labeled
*/
private void detectPattern(TTopologyTemplate tTopologyTemplate) {
abstractTopology = new AbstractTopology(tTopologyTemplate, labeledNodeTemplates);
List<TNodeTemplate> tNodeTemplateList = ModelUtilities.getAllNodeTemplates(tTopologyTemplate);
List<TRelationshipTemplate> tRelationshipTemplateList = ModelUtilities.getAllRelationshipTemplates(tTopologyTemplate);
getLowestNode(tNodeTemplateList.get(0), tRelationshipTemplateList);
Set<TNodeTemplateExtended> allNodes = abstractTopology.getGraph().vertexSet();
TNodeTemplateExtended baseNodeExtended = new TNodeTemplateExtended();
Iterator iterator = allNodes.iterator();
// search for the lowest node in the abstract topology graph, this is used to copy the lowest node from the original Topology to the AbstractTopology
while (iterator.hasNext()) {
TNodeTemplateExtended temp = (TNodeTemplateExtended) iterator.next();
if (temp.getNodeTemplate().getId().equals(basisNodeTemplate.getId())) {
baseNodeExtended = temp;
break;
}
}
// map the topology outgoing from the given base node
abstractTopology.map(baseNodeExtended);
// in the patternList all graphs of the pattern objects are added
List<DirectedGraph<PatternComponent, RelationshipEdge>> patternList = new ArrayList<>();
HashMap<Integer, String> patternNames = new HashMap<>();
// create objects of all known patterns
ExecutionEnvironmentPattern executionEnvironmentPattern = new ExecutionEnvironmentPattern();
NodeBasedAvailabilityPattern nodeBasedAvailabilityPattern = new NodeBasedAvailabilityPattern();
ElasticityManagerPattern elasticityManagerPattern = new ElasticityManagerPattern();
ElasticLoadBalancerPattern elasticLoadBalancerPattern = new ElasticLoadBalancerPattern();
ElasticQueuePattern elasticQueuePattern = new ElasticQueuePattern();
EnvironmentBasedAvailabilityPattern environmentBasedAvailabilityPattern = new EnvironmentBasedAvailabilityPattern();
MessageOrientedMiddlewarePattern messageOrientedMiddlewarePattern = new MessageOrientedMiddlewarePattern();
RelationalDatabasePattern relationalDatabasePattern = new RelationalDatabasePattern();
KeyValueStoragePattern keyValueStoragePattern = new KeyValueStoragePattern();
ExecutionEnvironmentPattern2 executionEnvironmentPattern2 = new ExecutionEnvironmentPattern2();
// to receive the right pattern name for the current counter, pattern names are associated with numbers
patternNames.put(0, patternExecEnv);
patternNames.put(1, patternNodeBasedAvail);
patternNames.put(2, patternElasticityManager);
patternNames.put(3, patternElasticLoadBalancer);
patternNames.put(4, patternElasticQueue);
patternNames.put(5, patternEnvBasedAvail);
patternNames.put(6, patternMessageMiddleware);
patternNames.put(7, patternRelationalDatabase);
patternNames.put(8, patternKeyValueStorage);
patternNames.put(9, patternExecEnv);
// pattern are added in order
patternList.add(executionEnvironmentPattern.getPatternGraph());
patternList.add(nodeBasedAvailabilityPattern.getPatternGraph());
patternList.add(elasticityManagerPattern.getPatternGraph());
patternList.add(elasticLoadBalancerPattern.getPatternGraph());
patternList.add(elasticQueuePattern.getPatternGraph());
patternList.add(environmentBasedAvailabilityPattern.getPatternGraph());
patternList.add(messageOrientedMiddlewarePattern.getPatternGraph());
patternList.add(relationalDatabasePattern.getPatternGraph());
patternList.add(keyValueStoragePattern.getPatternGraph());
patternList.add(executionEnvironmentPattern2.getPatternGraph());
int countIndex = 0;
// abstractTopology represents the base graph, for each pattern graph search for a subgraph isomorphism between base graph & pattern graph
for (DirectedGraph<PatternComponent, RelationshipEdge> pattern : patternList) {
VF2SubgraphIsomorphismInspector<TNodeTemplateExtended, RelationshipEdge> inspector = new VF2SubgraphIsomorphismInspector(abstractTopology.getGraph(), pattern);
if (inspector.isomorphismExists()) {
Iterator it = inspector.getMappings();
while (it.hasNext()) {
IsomorphicGraphMapping mapping = (IsomorphicGraphMapping) it.next();
// list for counting all matches between pattern nodes and base graph nodes, must be true for all
List<Boolean> matched = new ArrayList<>();
// this graph holds the nodes of the base graph in which the pattern occurs
DirectedGraph<TNodeTemplateExtended, RelationshipEdge> originGraph = new SimpleDirectedGraph<>(RelationshipEdge.class);
// each node of the pattern graph is compared to the according node in the GraphMapping
for (PatternComponent p : pattern.vertexSet()) {
// check if matched subgraph and topology have the same components, get the correspondent vertex in the mapping for a node
TNodeTemplateExtended v = (TNodeTemplateExtended) mapping.getVertexCorrespondence(p, false);
// if the names equal, the node is added to the originGraph and a boolean with value true is added to the matched list
if (p.getName().equals(v.getLabel())) {
matched.add(true);
originGraph.addVertex(v);
} else {
matched.add(false);
}
}
// correspondent to the countIndex, the pattern name is retrieved
if (!matched.contains(false) && !impossiblePattern.contains(patternNames.get(countIndex))) {
// add a new pattern position: the pattern name & the subgraph in which it occurs, this graph was built up in the previous step
PatternPosition temp = new PatternPosition(patternNames.get(countIndex), originGraph);
patternPositions.add(temp);
detectedPattern.add(patternNames.get(countIndex));
// sett some additional probabilities
if (patternNames.get(countIndex).equals(patternEnvBasedAvail)) {
patternProbabilityHigh.add(patternPublicCloud);
} else if (patternNames.get(countIndex).equals(patternEnvBasedAvail)) {
impossiblePattern.add(patternNodeBasedAvail);
} else if (patternNames.get(countIndex).equals(patternNodeBasedAvail)) {
impossiblePattern.add(patternEnvBasedAvail);
}
}
}
}
countIndex++;
}
}
use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.
the class ProviderRepository method getAllTopologyFragmentsForLocationAndOfferingCapability.
/**
* Pointing to a concrete node template has to be done by putting this node template into a separeate namespace <p>
* The given targetLocation is appended to {@see NS_NAME_START} to gain the namespace. All NodeTemplates in this
* namespace and all "lower" namespaces (e.g., starting with that string) are returned.
*
* @return All node templates available for the given targetLocation.
*/
public List<TTopologyTemplate> getAllTopologyFragmentsForLocationAndOfferingCapability(String targetLocation, TRequirement requirement) {
QName reqTypeQName = requirement.getType();
RequirementTypeId reqTypeId = new RequirementTypeId(reqTypeQName);
QName requiredCapabilityType = RepositoryFactory.getRepository().getElement(reqTypeId).getRequiredCapabilityType();
return getAllTopologyFragmentsForLocation(targetLocation).stream().filter(tf -> {
Optional<TNodeTemplate> nodeTemplate = ModelUtilities.getAllNodeTemplates(tf).stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().getCapability().stream().anyMatch(cap -> cap.getType().equals(requiredCapabilityType))).findAny();
if (nodeTemplate.isPresent()) {
return true;
} else {
return false;
}
}).collect(Collectors.toList());
}
use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.
the class ProviderRepository method breadthFirstSearch.
private List<TEntityTemplate> breadthFirstSearch(TNodeTemplate nodeTemplate, TTopologyTemplate topologyTemplate) {
List<TEntityTemplate> topologyFragmentElements = new ArrayList<>();
topologyFragmentElements.add(nodeTemplate);
List<TRelationshipTemplate> outgoingRelationships = ModelUtilities.getOutgoingRelationshipTemplates(topologyTemplate, nodeTemplate);
for (TRelationshipTemplate outgoingRelationship : outgoingRelationships) {
Object successor = outgoingRelationship.getTargetElement().getRef();
if (successor instanceof TNodeTemplate) {
topologyFragmentElements.add(outgoingRelationship);
topologyFragmentElements.addAll(breadthFirstSearch((TNodeTemplate) successor, topologyTemplate));
}
}
return topologyFragmentElements;
}
use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.
the class ProviderRepository method getAllTopologyFragmentsFromServiceTemplate.
private List<TTopologyTemplate> getAllTopologyFragmentsFromServiceTemplate(TTopologyTemplate topologyTemplate) {
List<TTopologyTemplate> topologyFragments = new ArrayList<>();
Splitting helperFunctions = new Splitting();
List<TNodeTemplate> nodeTemplatesWithoutIncomingRelationship = helperFunctions.getNodeTemplatesWithoutIncomingHostedOnRelationships(topologyTemplate);
List<TNodeTemplate> visitedNodeTemplates = new ArrayList<>();
// It can only be one topology fragment contained in the service template
if (nodeTemplatesWithoutIncomingRelationship.size() == 1) {
TDocumentation documentation = new TDocumentation();
Optional<String> targetLabel = ModelUtilities.getTargetLabel(nodeTemplatesWithoutIncomingRelationship.get(0));
String label;
if (!targetLabel.isPresent()) {
label = "unkown";
} else {
label = targetLabel.get();
}
documentation.getContent().add("Stack of Node Template " + nodeTemplatesWithoutIncomingRelationship.get(0).getId() + " from Provider Repository " + label);
topologyTemplate.getDocumentation().add(documentation);
topologyFragments.add(topologyTemplate);
} else {
for (TNodeTemplate nodeWithoutIncomingRel : nodeTemplatesWithoutIncomingRelationship) {
if (!visitedNodeTemplates.contains(nodeWithoutIncomingRel)) {
TTopologyTemplate topologyFragment = new TTopologyTemplate();
TDocumentation documentation = new TDocumentation();
Optional<String> targetLabel = ModelUtilities.getTargetLabel(nodeWithoutIncomingRel);
String label;
if (!targetLabel.isPresent()) {
label = "unkown";
} else {
label = targetLabel.get();
}
documentation.getContent().add("Stack of Node Template " + nodeWithoutIncomingRel.getId() + " from Provider Repository " + label);
topologyFragment.getDocumentation().add(documentation);
topologyFragment.getNodeTemplateOrRelationshipTemplate().addAll(breadthFirstSearch(nodeWithoutIncomingRel, topologyTemplate));
topologyFragments.add(topologyFragment);
topologyFragment.getNodeTemplateOrRelationshipTemplate().stream().filter(et -> et instanceof TNodeTemplate).map(TNodeTemplate.class::cast).forEach(nt -> visitedNodeTemplates.add(nt));
}
}
}
return topologyFragments;
}
use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.
the class APIResource method getAllArtifactTemplatesOfContainedImplementationArtifacts.
/**
* Implementation similar to
* getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only difference is
* "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of
* "getArtifactTemplatesOfReferencedDeploymentArtifacts".
*/
@GET
@Path("getallartifacttemplatesofcontainedimplementationartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedImplementationArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
if (StringUtils.isEmpty(serviceTemplateQNameString)) {
return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
}
QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
if (!RepositoryFactory.getRepository().exists(serviceTemplateId)) {
return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
}
ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
Collection<QName> artifactTemplates = new ArrayList<>();
List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedImplementationArtifacts(nodeTemplate);
artifactTemplates.addAll(ats);
}
}
// convert QName list to select2 data
Select2DataWithOptGroups res = new Select2DataWithOptGroups();
for (QName qName : artifactTemplates) {
res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
}
return Response.ok().entity(res.asSortedSet()).build();
}
Aggregations