Search in sources :

Example 26 with TDeploymentArtifact

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

the class Visitor method visit.

public void visit(TNodeTypeImplementation nodeTypeImplementation) {
    Objects.requireNonNull(nodeTypeImplementation);
    visit((TEntityTypeImplementation) nodeTypeImplementation);
    if (nodeTypeImplementation.getDeploymentArtifacts() != null) {
        for (TDeploymentArtifact da : nodeTypeImplementation.getDeploymentArtifacts()) {
            da.accept(this);
        }
    }
}
Also used : TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact)

Example 27 with TDeploymentArtifact

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

the class BackendUtils method getArtifactTemplatesOfReferencedDeploymentArtifacts.

public static Collection<QName> getArtifactTemplatesOfReferencedDeploymentArtifacts(TNodeTemplate nodeTemplate, IRepository repo) {
    // DAs may be assigned directly to a node template
    Collection<QName> allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInDAs(nodeTemplate.getDeploymentArtifacts());
    List<QName> list = new ArrayList<>(allReferencedArtifactTemplates);
    // DAs may be assigned via node type implementations
    QName nodeTypeQName = nodeTemplate.getType();
    Collection<NodeTypeImplementationId> allNodeTypeImplementations = repo.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, nodeTypeQName);
    for (NodeTypeImplementationId nodeTypeImplementationId : allNodeTypeImplementations) {
        List<TDeploymentArtifact> deploymentArtifacts = repo.getElement(nodeTypeImplementationId).getDeploymentArtifacts();
        allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInDAs(deploymentArtifacts);
        list.addAll(allReferencedArtifactTemplates);
    }
    return list;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact)

Example 28 with TDeploymentArtifact

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

the class IRepository 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);
        List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
        if (deploymentArtifacts != null) {
            allDAs.addAll(deploymentArtifacts);
        }
        List<TImplementationArtifact> implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts);
        }
    }
    // check all RelationshipTypeImplementations for IAs
    SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
    for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
        List<TImplementationArtifact> implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts);
        }
    }
    // 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;
                    List<TDeploymentArtifact> deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
                    if (deploymentArtifacts != null) {
                        allDAs.addAll(deploymentArtifacts);
                    }
                }
            }
        }
    }
    // 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.model.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.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) 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 29 with TDeploymentArtifact

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

the class IRepository 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) {
        List<TPolicy> policies = boundaryDefs.getPolicies();
        if (policies != null) {
            for (TPolicy policy : policies) {
                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)
    }
    final TTopologyTemplate topology = serviceTemplate.getTopologyTemplate();
    if (topology != null) {
        if (Objects.nonNull(topology.getPolicies())) {
            topology.getPolicies().stream().filter(Objects::nonNull).forEach(p -> {
                QName type = p.getPolicyType();
                PolicyTypeId policyTypeIdId = new PolicyTypeId(type);
                ids.add(policyTypeIdId);
            });
        }
        for (TEntityTemplate entityTemplate : topology.getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through policies
                List<TPolicy> policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies) {
                        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);
                        }
                    }
                }
                // Crawl RequirementTypes and Capabilities for their references
                getReferencedRequirementTypeIds(ids, n);
                getCapabilitiesReferences(ids, n);
                // TODO: this information is collected differently for YAML and XML modes
                // crawl through deployment artifacts
                List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    for (TDeploymentArtifact da : deploymentArtifacts) {
                        if (da.getArtifactType() != null) {
                            // This is considered Nullable, because the test case ConsistencyCheckerTest#hasError
                            // expects an empty artifactType and thus it may be null.
                            ids.add(new ArtifactTypeId(da.getArtifactType()));
                        }
                        if (da.getArtifactRef() != null) {
                            ids.add(new ArtifactTemplateId(da.getArtifactRef()));
                        }
                    }
                }
                // Store all referenced artifact types
                List<TArtifact> artifacts = n.getArtifacts();
                if (Objects.nonNull(artifacts)) {
                    artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
                }
                TNodeType nodeType = this.getElement(new NodeTypeId(qname));
                if (Objects.nonNull(nodeType.getInterfaceDefinitions())) {
                    nodeType.getInterfaceDefinitions().stream().filter(Objects::nonNull).forEach(iDef -> {
                        if (Objects.nonNull(iDef.getType())) {
                            ids.add(new InterfaceTypeId(iDef.getType()));
                        }
                    });
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifact(org.eclipse.winery.model.tosca.TArtifact) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 30 with TDeploymentArtifact

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

the class NodeTemplateResourceTest method addStateArtifactToNodeTemplateThatAlreadyHasADeploymentArtifact.

@Test
public void addStateArtifactToNodeTemplateThatAlreadyHasADeploymentArtifact() throws Exception {
    this.setRevisionTo("origin/plain");
    Path filePath = MavenTestingUtils.getProjectFilePath("src/test/resources/servicetemplates/plan.zip");
    this.assertNoContentPost("servicetemplates/http%253A%252F%252Fopentosca.org%252Fexamples%252Fservicetemplates/ServiceTemplateWithDeploymentArtifact_w1-wip1/" + "topologytemplate/nodetemplates/StatefulComponent_w1-wip1/state", filePath);
    TNodeTemplate nodeTemplate = getObjectFromGetRequest("servicetemplates/" + "http%253A%252F%252Fopentosca.org%252Fexamples%252Fservicetemplates/ServiceTemplateWithDeploymentArtifact_w1-wip1/" + "topologytemplate/nodetemplates/StatefulComponent_w1-wip1", TNodeTemplate.class);
    List<TDeploymentArtifact> deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
    assertNotNull(deploymentArtifacts);
    assertEquals(2, deploymentArtifacts.size());
    Optional<TDeploymentArtifact> testArtifact = deploymentArtifacts.stream().filter(artifact -> artifact.getName().equals("test-artifact")).findFirst();
    assertTrue(testArtifact.isPresent());
    assertNotNull(testArtifact.get());
    assertNotNull(deploymentArtifacts);
    Optional<TDeploymentArtifact> state = deploymentArtifacts.stream().filter(artifact -> artifact.getName().equals("state")).findFirst();
    assertTrue(state.isPresent());
    assertEquals(OpenToscaBaseTypes.stateArtifactType, state.get().getArtifactType());
}
Also used : Path(java.nio.file.Path) Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) List(java.util.List) MavenTestingUtils(org.eclipse.jetty.toolchain.test.MavenTestingUtils) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) AbstractResourceTest(org.eclipse.winery.repository.rest.resources.AbstractResourceTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) Path(java.nio.file.Path) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test) AbstractResourceTest(org.eclipse.winery.repository.rest.resources.AbstractResourceTest)

Aggregations

TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)48 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)13 TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)12 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)12 HashSet (java.util.HashSet)11 List (java.util.List)9 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)9 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)9 IOException (java.io.IOException)8 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)8 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)7 Test (org.junit.jupiter.api.Test)7 TArtifactType (org.eclipse.winery.model.tosca.TArtifactType)6 TImplementationArtifact (org.eclipse.winery.model.tosca.TImplementationArtifact)6 Node (org.w3c.dom.Node)6 Map (java.util.Map)5