Search in sources :

Example 16 with TNodeTemplate

use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.

the class Y2XConverter method convert.

/**
 * Converts TOSCA YAML NodeTemplates to TOSCA XML NodeTemplates Additional TOSCA YAML element metadata is put into
 * TOSCA XML documentation element Additional TOSCA YAML elements directives and copy are not converted
 *
 * @param node TOSCA YAML NodeTemplate
 * @return TOSCA XML NodeTemplate
 */
private TNodeTemplate convert(org.eclipse.winery.model.tosca.yaml.TNodeTemplate node, String id) {
    if (Objects.isNull(node))
        return null;
    TNodeTemplate.Builder builder = new TNodeTemplate.Builder(id, node.getType()).addDocumentation(node.getDescription()).addDocumentation(node.getMetadata()).setName(id).setProperties(convertPropertyAssignments(node.getProperties(), getPropertyTypeName(node.getType()))).addRequirements(convert(id, node.getRequirements())).addCapabilities(convert(node.getCapabilities())).setDeploymentArtifacts(convertDeploymentArtifacts(node.getArtifacts()));
    TNodeTemplate nodeTemplate = builder.build();
    this.nodeTemplateMap.put(id, nodeTemplate);
    return nodeTemplate;
}
Also used : TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 17 with TNodeTemplate

use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.

the class BackendUtils method getAllNestedNodeTemplates.

/**
 * Returns a list of the topology template nested in the given service template
 */
public static List<TNodeTemplate> getAllNestedNodeTemplates(TServiceTemplate serviceTemplate) {
    List<TNodeTemplate> l = new ArrayList<>();
    TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
    if (topologyTemplate == null) {
        return Collections.emptyList();
    }
    for (TEntityTemplate t : topologyTemplate.getNodeTemplateOrRelationshipTemplate()) {
        if (t instanceof TNodeTemplate) {
            l.add((TNodeTemplate) t);
        }
    }
    return l;
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 18 with TNodeTemplate

use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.

the class IGenericRepository method getReferenceCount.

default int getReferenceCount(ArtifactTemplateId id) {
    // We do not use a database, therefore, we have to go through all possibilities pointing to the artifact template
    // DAs and IAs point to an artifact template
    // DAs are contained in Node Type Implementations and Node Templates
    // IAs are contained in Node Type Implementations and Relationship Type Implementations
    int count = 0;
    Collection<TDeploymentArtifact> allDAs = new HashSet<>();
    Collection<TImplementationArtifact> allIAs = new HashSet<>();
    // handle Node Type Implementation, which contains DAs and IAs
    SortedSet<NodeTypeImplementationId> nodeTypeImplementations = this.getAllDefinitionsChildIds(NodeTypeImplementationId.class);
    for (NodeTypeImplementationId ntiId : nodeTypeImplementations) {
        final TNodeTypeImplementation nodeTypeImplementation = this.getElement(ntiId);
        TDeploymentArtifacts deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
        if (deploymentArtifacts != null) {
            allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
        }
        TImplementationArtifacts implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts.getImplementationArtifact());
        }
    }
    // check all Relationshiptype Implementations for IAs
    SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
    for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
        TImplementationArtifacts implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts.getImplementationArtifact());
        }
    }
    // check all node templates for DAs
    SortedSet<ServiceTemplateId> serviceTemplates = this.getAllDefinitionsChildIds(ServiceTemplateId.class);
    for (ServiceTemplateId sid : serviceTemplates) {
        TTopologyTemplate topologyTemplate = this.getElement(sid).getTopologyTemplate();
        if (topologyTemplate != null) {
            List<TEntityTemplate> nodeTemplateOrRelationshipTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
            for (TEntityTemplate template : nodeTemplateOrRelationshipTemplate) {
                if (template instanceof TNodeTemplate) {
                    TNodeTemplate nodeTemplate = (TNodeTemplate) template;
                    TDeploymentArtifacts deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
                    if (deploymentArtifacts != null) {
                        allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
                    }
                }
            }
        }
    }
    // now we have all DAs and IAs
    QName ourQName = id.getQName();
    // check DAs for artifact templates
    for (TDeploymentArtifact da : allDAs) {
        QName artifactRef = da.getArtifactRef();
        if (ourQName.equals(artifactRef)) {
            count++;
        }
    }
    // check IAs for artifact templates
    for (TImplementationArtifact ia : allIAs) {
        QName artifactRef = ia.getArtifactRef();
        if (ourQName.equals(artifactRef)) {
            count++;
        }
    }
    return count;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) QName(javax.xml.namespace.QName) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) RelationshipTypeImplementationId(org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) TImplementationArtifacts(org.eclipse.winery.model.tosca.TImplementationArtifacts) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet)

Example 19 with TNodeTemplate

use of org.eclipse.winery.model.tosca.TNodeTemplate 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;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 20 with TNodeTemplate

use of org.eclipse.winery.model.tosca.TNodeTemplate in project winery by eclipse.

the class Detection method searchForKeywords.

/**
 * 1. step: search for keywords using predefined keywords in enums
 */
private void searchForKeywords(TTopologyTemplate tTopologyTemplate) {
    List<TNodeTemplate> tNodeTemplateList = ModelUtilities.getAllNodeTemplates(tTopologyTemplate);
    List<Server> serverList = new ArrayList<>(EnumSet.allOf(Server.class));
    List<Service> serviceList = new ArrayList<>(EnumSet.allOf(Service.class));
    List<VirtualHardware> virtualHardwareList = new ArrayList<>(EnumSet.allOf(VirtualHardware.class));
    List<OperatingSystem> operatingSystemList = new ArrayList<>(EnumSet.allOf(OperatingSystem.class));
    List<Messaging> messagingList = new ArrayList<>(EnumSet.allOf(Messaging.class));
    List<Storage> storageList = new ArrayList<>(EnumSet.allOf(Storage.class));
    for (TNodeTemplate tNodeTemplate : tNodeTemplateList) {
        for (Server server : serverList) {
            if (tNodeTemplate.getName().toLowerCase().contains(server.toString().toLowerCase())) {
                // add the matching keyword
                matchedKeywords.add(server.toString());
                // create a new TNodeTemplateExtended with the detected keyword and set the according label
                TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelServer, server.toString());
                // add this object to the list with labeled NodeTemplates
                labeledNodeTemplates.add(temp);
                isPaaS = true;
            }
        }
        for (Service service : serviceList) {
            if (tNodeTemplate.getName().toLowerCase().contains(service.toString().toLowerCase())) {
                matchedKeywords.add(service.toString());
                TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelService, service.toString());
                labeledNodeTemplates.add(temp);
                isPaaS = true;
            }
        }
        for (VirtualHardware virtualHardware : virtualHardwareList) {
            if (tNodeTemplate.getName().toLowerCase().contains(virtualHardware.toString().toLowerCase())) {
                matchedKeywords.add(virtualHardware.toString());
                TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelVirtualHardware, virtualHardware.toString());
                labeledNodeTemplates.add(temp);
                isIaaS = true;
            }
        }
        for (OperatingSystem operatingSystem : operatingSystemList) {
            if (tNodeTemplate.getName().toLowerCase().contains(operatingSystem.toString().toLowerCase())) {
                matchedKeywords.add(operatingSystem.toString());
                TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelOS, operatingSystem.toString());
                labeledNodeTemplates.add(temp);
                isPaaS = true;
            }
        }
        for (Messaging messaging : messagingList) {
            if (tNodeTemplate.getName().toLowerCase().contains(messaging.toString().toLowerCase())) {
                matchedKeywords.add(messaging.toString());
                TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelMessaging, messaging.toString());
                labeledNodeTemplates.add(temp);
                isPaaS = true;
            }
        }
        for (Storage storage : storageList) {
            if (tNodeTemplate.getName().toLowerCase().contains(storage.toString().toLowerCase())) {
                matchedKeywords.add(storage.toString());
                TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelStorage, storage.toString());
                labeledNodeTemplates.add(temp);
                isPaaS = true;
            }
        }
    }
    // create all taxonomies
    paasGraph = paas.getPaasTaxonomie();
    iaasGraph = iaas.getIaasTaxonomie();
    // set propabilities for possible patterns according to detected keywords only if any keywords matched the node template names
    if (!matchedKeywords.isEmpty()) {
        // for each specific keyowrds like beanstalk or mysql, probabilities are set in the pattern taxonomy graph
        for (String keyword : matchedKeywords) {
            DefaultWeightedEdge tempEdge;
            if (keyword.equals(keywordBeanstalk)) {
                detectedPattern.add(patternPaaS);
                tempEdge = paasGraph.getEdge(paas.getElasticPlatform(), paas.getEnvBasedAv());
                // set 100% probability of the pattern this edge is pointing to
                paasGraph.setEdgeWeight(tempEdge, 0.99);
                tempEdge = paasGraph.getEdge(paas.getElasticPlatform(), paas.getElasticLoadBalancer());
                paasGraph.setEdgeWeight(tempEdge, 0.99);
                tempEdge = paasGraph.getEdge(paas.getElasticPlatform(), paas.getElasticityManager());
                paasGraph.setEdgeWeight(tempEdge, 0.99);
            } else if (keyword.equals(keywordOpenstack) || keyword.equals(keywordEC2)) {
                tempEdge = iaasGraph.getEdge(iaas.getIaas(), iaas.getElasticInfrastructure());
                iaasGraph.setEdgeWeight(tempEdge, 0.75);
            } else if (keyword.equals(keywordMySQL)) {
                tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getRelationalDatabase());
                paasGraph.setEdgeWeight(tempEdge, 0.99);
                tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getKeyValueStorage());
                paasGraph.setEdgeWeight(tempEdge, 0.0);
            } else if (keyword.equals(keywordJava) || keyword.equals(keywordPython) || keyword.equals(keywordTomcat) || keyword.equals(keywordApache)) {
                tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getExecEnvironment());
                paasGraph.setEdgeWeight(tempEdge, 0.75);
            } else if (keyword.equals(keywordMongoDB)) {
                tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getKeyValueStorage());
                paasGraph.setEdgeWeight(tempEdge, 0.99);
                tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getRelationalDatabase());
                paasGraph.setEdgeWeight(tempEdge, 0.0);
            }
        }
        // this case indicates only IaaS keywords and no detected PaaS keywords -> IaaS is assumed, therefore PaaS is added to impossible patterns
        if (isIaaS && !isPaaS) {
            detectedPattern.add(patternIaaS);
            impossiblePattern.add(patternPaaS);
            impossiblePattern.add(patternElasticPlatform);
            Set<DefaultWeightedEdge> edgeSet = iaasGraph.edgeSet();
            Iterator iterator2 = edgeSet.iterator();
            // iterate through the IaaS taxonomy and check the weight of each edge -> add the target nodes to the according pattern list
            while (iterator2.hasNext()) {
                DefaultWeightedEdge edge = (DefaultWeightedEdge) iterator2.next();
                double weight = iaasGraph.getEdgeWeight(edge);
                if (weight == 0.75) {
                    patternProbabilityHigh.add(iaasGraph.getEdgeTarget(edge));
                } else if (weight == 0.5) {
                    patternProbabilityMedium.add(iaasGraph.getEdgeTarget(edge));
                } else if (weight == 0.25) {
                    patternProbabilityLow.add(iaasGraph.getEdgeTarget(edge));
                } else if (weight == 0.99) {
                    detectedPattern.add(iaasGraph.getEdgeTarget(edge));
                } else if (weight == 0.0) {
                    impossiblePattern.add(iaasGraph.getEdgeTarget(edge));
                } else if (weight == 1.0) {
                    // for all other patterns add low probability, 1.0 is default edge value
                    patternProbabilityLow.add(iaasGraph.getEdgeTarget(edge));
                }
            }
        // this case occurs if IaaS and PaaS keywords are detected or just PaaS keywords -> PaaS is assumed and excludes IaaS
        } else {
            detectedPattern.add(patternPaaS);
            impossiblePattern.add(patternIaaS);
            impossiblePattern.add(patternElasticInfrastructure);
            Set<DefaultWeightedEdge> edgeSet;
            edgeSet = paasGraph.edgeSet();
            Iterator iterator = edgeSet.iterator();
            // iterate through the IaaS taxonomy and check the weight of each edge -> add the target nodes to the according pattern list
            while (iterator.hasNext()) {
                DefaultWeightedEdge edge = (DefaultWeightedEdge) iterator.next();
                double weight = paasGraph.getEdgeWeight(edge);
                if (weight == 0.75) {
                    patternProbabilityHigh.add(paasGraph.getEdgeTarget(edge));
                } else if (weight == 0.5) {
                    patternProbabilityMedium.add(paasGraph.getEdgeTarget(edge));
                } else if (weight == 0.25) {
                    patternProbabilityLow.add(paasGraph.getEdgeTarget(edge));
                } else if (weight == 0.99) {
                    detectedPattern.add(paasGraph.getEdgeTarget(edge));
                } else if (weight == 0.0) {
                    impossiblePattern.add(paasGraph.getEdgeTarget(edge));
                } else if (weight == 1.0) {
                    // for all other patterns add low probability, 1.0 is default edge value
                    patternProbabilityLow.add(paasGraph.getEdgeTarget(edge));
                }
            }
        }
    }
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)26 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)11 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)10 ArrayList (java.util.ArrayList)9 QName (javax.xml.namespace.QName)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)8 Test (org.junit.Test)7 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)6 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)6 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)6 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)4 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)4 TOSCANode (org.eclipse.winery.compliance.model.TOSCANode)4 TDeploymentArtifacts (org.eclipse.winery.model.tosca.TDeploymentArtifacts)4 TRequirement (org.eclipse.winery.model.tosca.TRequirement)4 TOSCAModelHelper.createNodeTypeId (org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId)3 TOSCAModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate)3