Search in sources :

Example 11 with NodeTypeImplementationId

use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId 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 12 with NodeTypeImplementationId

use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.

the class SelfContainmentPackager method createSelfContainedNodeTypeImplementation.

private void createSelfContainedNodeTypeImplementation(TNodeTypeImplementation impl) {
    if (impl.getImplementationArtifacts() != null) {
        List<SelfContainmentPlugin.GeneratedArtifacts> generatedArtifacts = impl.getImplementationArtifacts().stream().filter(ia -> Objects.nonNull(ia.getArtifactRef())).filter(ia -> !new ArtifactTemplateId(ia.getArtifactRef()).isSelfContained()).map(ia -> this.downloadArtifacts(ia.getArtifactRef(), ia.getArtifactType())).filter(Objects::nonNull).filter(SelfContainmentPlugin.GeneratedArtifacts::containsNewElements).collect(Collectors.toList());
        if (!generatedArtifacts.isEmpty()) {
            NodeTypeImplementationId nodeTypeImplementationId = getSelfContainedNodeTypeImplId(impl);
            try {
                this.repository.duplicate(new NodeTypeImplementationId(impl.getQName()), nodeTypeImplementationId);
                TNodeTypeImplementation implementation = this.repository.getElement(nodeTypeImplementationId);
                generatedArtifacts.forEach(generatedArtifact -> {
                    if (implementation.getImplementationArtifacts() != null) {
                        implementation.getImplementationArtifacts().forEach(ia -> {
                            if (generatedArtifact.artifactToReplaceQName.equals(ia.getArtifactRef())) {
                                ia.setArtifactRef(generatedArtifact.selfContainedArtifactQName);
                                TArtifactTemplate artifactTemplate = generatedArtifact.selfContainedArtifactTemplate;
                                if (artifactTemplate == null) {
                                    artifactTemplate = repository.getElement(new ArtifactTemplateId(generatedArtifact.selfContainedArtifactQName));
                                }
                                if (artifactTemplate.getType() == null) {
                                    logger.error("Artifact Template does not have a type assigned! {}", generatedArtifact.selfContainedArtifactQName);
                                }
                                ia.setArtifactType(artifactTemplate.getType());
                            }
                        });
                        List<TDeploymentArtifact> deploymentArtifacts = implementation.getDeploymentArtifacts();
                        if (deploymentArtifacts == null) {
                            deploymentArtifacts = new ArrayList<>();
                            implementation.setDeploymentArtifacts(deploymentArtifacts);
                        } else {
                            deploymentArtifacts.removeIf(da -> da.getArtifactRef() != null && generatedArtifact.deploymentArtifactsToRemove.contains(da.getArtifactRef()));
                        }
                        for (QName artifactTemplate : generatedArtifact.deploymentArtifactsToAdd) {
                            TArtifactTemplate generatedAT = repository.getElement(new ArtifactTemplateId(artifactTemplate));
                            deploymentArtifacts.add(new TDeploymentArtifact.Builder(artifactTemplate.getLocalPart(), generatedAT.getType()).setArtifactRef(artifactTemplate).build());
                        }
                    }
                });
                repository.setElement(nodeTypeImplementationId, implementation);
            } catch (IOException e) {
                logger.error("Error while creating new self-contained NodeTypeImplementation of {}", impl, e);
            }
        }
    } else {
        logger.info("No processable IAs found in Node Type Implementation {}", impl.getQName());
    }
}
Also used : TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Collection(java.util.Collection) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Objects(java.util.Objects) List(java.util.List) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) VersionSupport(org.eclipse.winery.model.version.VersionSupport) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) QName(javax.xml.namespace.QName) IOException(java.io.IOException) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Objects(java.util.Objects) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact)

Example 13 with NodeTypeImplementationId

use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.

the class VersionSupport method getDefinitionInTheGivenVersion.

public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
    if (childId.getVersion().compareTo(otherVersion) == 0) {
        return childId;
    }
    String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
    QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
    if (childId instanceof RelationshipTypeImplementationId) {
        return new RelationshipTypeImplementationId(qName);
    } else if (childId instanceof NodeTypeImplementationId) {
        return new NodeTypeImplementationId(qName);
    } else if (childId instanceof RequirementTypeId) {
        return new RequirementTypeId(qName);
    } else if (childId instanceof NodeTypeId) {
        return new NodeTypeId(qName);
    } else if (childId instanceof RelationshipTypeId) {
        return new RelationshipTypeId(qName);
    } else if (childId instanceof CapabilityTypeId) {
        return new CapabilityTypeId(qName);
    } else if (childId instanceof ArtifactTypeId) {
        return new ArtifactTypeId(qName);
    } else if (childId instanceof PolicyTypeId) {
        return new PolicyTypeId(qName);
    } else if (childId instanceof PolicyTemplateId) {
        return new PolicyTemplateId(qName);
    } else if (childId instanceof ServiceTemplateId) {
        return new ServiceTemplateId(qName);
    } else if (childId instanceof ArtifactTemplateId) {
        return new ArtifactTemplateId(qName);
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId)

Example 14 with NodeTypeImplementationId

use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.

the class BackendUtils method getArtifactTemplatesOfReferencedImplementationArtifacts.

public static Collection<QName> getArtifactTemplatesOfReferencedImplementationArtifacts(TNodeTemplate nodeTemplate, IRepository repo) {
    List<QName> l = new ArrayList<>();
    // IAs may be assigned via node type implementations
    QName nodeTypeQName = nodeTemplate.getType();
    Collection<NodeTypeImplementationId> allNodeTypeImplementations = repo.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, nodeTypeQName);
    for (NodeTypeImplementationId nodeTypeImplementationId : allNodeTypeImplementations) {
        List<TImplementationArtifact> implementationArtifacts = repo.getElement(nodeTypeImplementationId).getImplementationArtifacts();
        Collection<QName> allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInIAs(implementationArtifacts);
        l.addAll(allReferencedArtifactTemplates);
    }
    return l;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList)

Example 15 with NodeTypeImplementationId

use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.

the class YamlRepository method getRequestedDefinition.

/**
 * Parses only requested Definition from converted yaml service template
 *
 * @param id          Definitions Child id
 * @param definitions converted definitions
 * @return requested definitions
 */
private TDefinitions getRequestedDefinition(DefinitionsChildId id, TDefinitions definitions) {
    if (id instanceof ArtifactTemplateId) {
        String artifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
        List<TArtifactTemplate> artifactTemplates = definitions.getArtifactTemplates();
        List<TArtifactTemplate> requestedArtifactTemplates = new ArrayList<>();
        for (TArtifactTemplate artifactTemplate : artifactTemplates) {
            if (artifactTemplate.getId().equalsIgnoreCase(artifactName)) {
                requestedArtifactTemplates.add(artifactTemplate);
                TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
                requestedDefinitions.addArtifactTemplates(requestedArtifactTemplates);
                return requestedDefinitions.build();
            }
        }
        // we did not find the artifact template id (this should not happen!)
        LOGGER.error("requested artifact template id (" + id.toReadableString() + ") cannot be extracted from definitions object!");
        return definitions;
    } else {
        TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
        if (id instanceof NodeTypeId) {
            requestedDefinitions.addNodeTypes(definitions.getNodeTypes());
        } else if (id instanceof RelationshipTypeId) {
            requestedDefinitions.addRelationshipTypes(definitions.getRelationshipTypes());
        } else if (id instanceof NodeTypeImplementationId) {
            requestedDefinitions.addNodeTypeImplementations(definitions.getNodeTypeImplementations());
        } else if (id instanceof RelationshipTypeImplementationId) {
            requestedDefinitions.addRelationshipTypeImplementations(definitions.getRelationshipTypeImplementations());
        } else if (id instanceof ArtifactTypeId) {
            requestedDefinitions.addArtifactTypes(definitions.getArtifactTypes());
        } else if (id instanceof CapabilityTypeId) {
            requestedDefinitions.addCapabilityTypes(definitions.getCapabilityTypes());
        } else if (id instanceof DataTypeId) {
            requestedDefinitions.addDataTypes(definitions.getDataTypes());
        } else if (id instanceof RequirementTypeId) {
            requestedDefinitions.addRequirementTypes(definitions.getRequirementTypes());
        } else if (id instanceof PolicyTypeId) {
            requestedDefinitions.addPolicyTypes(definitions.getPolicyTypes());
        } else if (id instanceof InterfaceTypeId) {
            requestedDefinitions.addInterfaceTypes(definitions.getInterfaceTypes());
        } else {
            // we do not need to filter anything
            return definitions;
        }
        return requestedDefinitions.build();
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions)

Aggregations

NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)17 QName (javax.xml.namespace.QName)11 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)10 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)8 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)7 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)7 ArrayList (java.util.ArrayList)6 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)6 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)5 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)5 TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)5 IOException (java.io.IOException)4 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)4 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)4 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)4 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)4 IRepository (org.eclipse.winery.repository.backend.IRepository)4 Collection (java.util.Collection)3 Collectors (java.util.stream.Collectors)3 InterfaceTypeId (org.eclipse.winery.model.ids.definitions.InterfaceTypeId)3