use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.
the class TOSCAModelHelper method addEdge.
public static TOSCAEdge addEdge(TOSCAGraph graph, TOSCANode source, TOSCANode target, String id, String name) {
TOSCAEdge edge = graph.getEdgeFactory().createEdge(source, target);
edge.setId(id);
graph.addEdge(source, target, edge);
TRelationshipTemplate template = new TRelationshipTemplate();
template.setName(name);
edge.setTemplate(template);
return edge;
}
use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies.getPolicy()) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
if (serviceTemplate.getTopologyTemplate() != null) {
for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
for (TDeploymentArtifact da : das) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
// crawl through reqs/caps
TNodeTemplate.Requirements requirements = n.getRequirements();
if (requirements != null) {
for (TRequirement req : requirements.getRequirement()) {
QName type = req.getType();
RequirementTypeId rtId = new RequirementTypeId(type);
ids.add(rtId);
}
}
TNodeTemplate.Capabilities capabilities = n.getCapabilities();
if (capabilities != null) {
for (TCapability cap : capabilities.getCapability()) {
QName type = cap.getType();
CapabilityTypeId ctId = new CapabilityTypeId(type);
ids.add(ctId);
}
}
// crawl through policies
org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies.getPolicy()) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.
the class Detection method getLowestNode.
/**
* Get the lowest node in a topology, this is the only node with any outgoing relation
*/
private void getLowestNode(TNodeTemplate baseNodeTemplate, List<TRelationshipTemplate> tRelationshipTemplateList) {
List<TRelationshipTemplate> outgoing = new ArrayList<>();
List<TRelationshipTemplate> incoming = new ArrayList<>();
for (TRelationshipTemplate tRelationshipTemplate : tRelationshipTemplateList) {
if (baseNodeTemplate.equals((tRelationshipTemplate.getSourceElement().getRef()))) {
outgoing.add(tRelationshipTemplate);
getLowestNode((TNodeTemplate) tRelationshipTemplate.getTargetElement().getRef(), tRelationshipTemplateList);
break;
} else {
incoming.add(tRelationshipTemplate);
}
}
if (outgoing.isEmpty()) {
// lowestNode is set
basisNodeTemplate = baseNodeTemplate;
}
}
use of org.eclipse.winery.model.tosca.TRelationshipTemplate 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.TRelationshipTemplate 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;
}
Aggregations