Search in sources :

Example 16 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate 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 17 with TTopologyTemplate

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

the class Detection method detectPattern.

public List<List<String>> detectPattern() {
    TTopologyTemplate tTopologyTemplate = RepositoryFactory.getRepository().getElement(serviceTemplateId).getTopologyTemplate();
    searchForKeywords(tTopologyTemplate);
    detectPattern(tTopologyTemplate);
    List<List<String>> listLists = new ArrayList<>();
    listLists.add(detectedPattern);
    listLists.add(patternProbabilityHigh);
    listLists.add(patternProbabilityMedium);
    listLists.add(patternProbabilityLow);
    listLists.add(impossiblePattern);
    return listLists;
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate)

Example 18 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate 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());
}
Also used : RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) TDocumentation(org.eclipse.winery.model.tosca.TDocumentation) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) Collectors(java.util.stream.Collectors) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) ArrayList(java.util.ArrayList) List(java.util.List) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TRequirement(org.eclipse.winery.model.tosca.TRequirement) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Optional(java.util.Optional) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId)

Example 19 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate 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;
}
Also used : TDocumentation(org.eclipse.winery.model.tosca.TDocumentation) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 20 with TTopologyTemplate

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

the class WineryRepositoryClient method getTopologyTemplate.

@Override
public TTopologyTemplate getTopologyTemplate(QName serviceTemplate) {
    // we try all repositories until the first hit
    for (WebResource wr : this.repositoryResources) {
        WebResource r = WineryRepositoryClient.getTopologyTemplateWebResource(wr, serviceTemplate);
        ClientResponse response = r.accept(MediaType.TEXT_XML).get(ClientResponse.class);
        if (response.getClientResponseStatus() == ClientResponse.Status.OK) {
            TTopologyTemplate topologyTemplate;
            Document doc = this.parseAndValidateTOSCAXML(response.getEntityInputStream());
            if (doc == null) {
                // no valid document
                return null;
            }
            try {
                topologyTemplate = WineryRepositoryClient.createUnmarshaller().unmarshal(doc.getDocumentElement(), TTopologyTemplate.class).getValue();
            } catch (JAXBException e) {
                LOGGER.debug("Could not parse topology, returning null", e);
                return null;
            }
            // first hit: immediately stop and return result
            return topologyTemplate;
        }
    }
    // nothing found
    return null;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) JAXBException(javax.xml.bind.JAXBException) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document)

Aggregations

TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)21 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10 Test (org.junit.Test)8 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)7 ArrayList (java.util.ArrayList)6 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)6 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)5 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)4 IOException (java.io.IOException)3 List (java.util.List)3 QName (javax.xml.namespace.QName)3 TRequirement (org.eclipse.winery.model.tosca.TRequirement)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 URI (java.net.URI)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JAXBException (javax.xml.bind.JAXBException)2 TDocumentation (org.eclipse.winery.model.tosca.TDocumentation)2 Splitting (org.eclipse.winery.repository.splitting.Splitting)2