Search in sources :

Example 6 with TNodeTypeImplementation

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

the class SelfContainmentPackager method createSelfContainedVersion.

public DefinitionsChildId createSelfContainedVersion(DefinitionsChildId entryId) throws IOException {
    ServiceTemplateId newServiceTemplateId = new ServiceTemplateId(VersionSupport.getSelfContainedVersion(entryId));
    if (!repository.exists(newServiceTemplateId)) {
        repository.duplicate(entryId, newServiceTemplateId);
        TServiceTemplate serviceTemplate = repository.getElement(newServiceTemplateId);
        Collection<DefinitionsChildId> referencedElements = repository.getReferencedDefinitionsChildIds(newServiceTemplateId);
        for (DefinitionsChildId elementId : referencedElements) {
            if (elementId instanceof NodeTypeId) {
                Collection<NodeTypeImplementationId> nodeTypeImplementationIds = repository.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, elementId.getQName());
                if (nodeTypeImplementationIds.stream().noneMatch(DefinitionsChildId::isSelfContained)) {
                    // self-contained element does not exist yet!
                    List<TNodeTypeImplementation> nodeTypeImplementations = nodeTypeImplementationIds.stream().map(repository::getElement).filter(element -> element.getImplementationArtifacts() != null).collect(Collectors.toList());
                    for (TNodeTypeImplementation impl : nodeTypeImplementations) {
                        Optional<SelfContainmentPlugin> nodeTypeBasedPlugin = this.selfContainmentPlugins.stream().filter(plugin -> plugin.canHandleNodeType(elementId.getQName(), repository)).findFirst();
                        if (nodeTypeBasedPlugin.isPresent()) {
                            NodeTypeImplementationId selfContainedNodeTypeImpl = getSelfContainedNodeTypeImplId(impl);
                            try {
                                repository.duplicate(new NodeTypeImplementationId(impl.getTargetNamespace(), impl.getIdFromIdOrNameField(), false), selfContainedNodeTypeImpl);
                                TNodeTypeImplementation selfContained = this.repository.getElement(selfContainedNodeTypeImpl);
                                nodeTypeBasedPlugin.get().downloadDependenciesBasedOnNodeType(selfContained, this.repository);
                                repository.setElement(selfContainedNodeTypeImpl, selfContained);
                            } catch (IOException e) {
                                logger.error("While creating self-contained Node Type Implementation", e);
                            }
                        } else if (impl.getImplementationArtifacts() != null) {
                            createSelfContainedNodeTypeImplementation(impl);
                        }
                    }
                }
            } else if (elementId instanceof ArtifactTemplateId) {
                if (serviceTemplate.getTopologyTemplate() != null) {
                    TArtifactTemplate artifactTemplate = repository.getElement(elementId);
                    SelfContainmentPlugin.GeneratedArtifacts generatedArtifacts = this.downloadArtifacts(elementId.getQName(), artifactTemplate.getType());
                    if (generatedArtifacts != null && generatedArtifacts.selfContainedArtifactQName != null) {
                        // first, we need to identify the element that is referencing the artifact
                        serviceTemplate.getTopologyTemplate().getNodeTemplates().stream().map(TNodeTemplate::getDeploymentArtifacts).filter(Objects::nonNull).filter(daList -> daList.stream().anyMatch(da -> da.getArtifactRef() != null && da.getArtifactRef().equals(elementId.getQName()))).flatMap(Collection::stream).forEach(da -> da.setArtifactRef(generatedArtifacts.selfContainedArtifactQName));
                    }
                }
            }
        }
        repository.setElement(newServiceTemplateId, serviceTemplate);
    } else {
        logger.info("Self-contained version already exists! '{}'", newServiceTemplateId.getQName());
    }
    return newServiceTemplateId;
}
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) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Objects(java.util.Objects) Collection(java.util.Collection) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 7 with TNodeTypeImplementation

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

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

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

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

the class RestUtils method getEdmmEntityGraph.

public static EntityGraph getEdmmEntityGraph(TServiceTemplate element, boolean useAbsolutPaths) {
    IRepository repository = RepositoryFactory.getRepository();
    Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
    Map<QName, TRelationshipType> relationshipTypes = repository.getQNameToElementMapping(RelationshipTypeId.class);
    Map<QName, TNodeTypeImplementation> nodeTypeImplementations = repository.getQNameToElementMapping(NodeTypeImplementationId.class);
    Map<QName, TRelationshipTypeImplementation> relationshipTypeImplementations = repository.getQNameToElementMapping(RelationshipTypeImplementationId.class);
    Map<QName, TArtifactTemplate> artifactTemplates = repository.getQNameToElementMapping(ArtifactTemplateId.class);
    EdmmManager edmmManager = EdmmManager.forRepository(repository);
    Map<QName, EdmmType> oneToOneMappings = edmmManager.getOneToOneMap();
    Map<QName, EdmmType> typeMappings = edmmManager.getTypeMap();
    if (nodeTypes.isEmpty()) {
        throw new IllegalStateException("No Node Types defined!");
    } else if (relationshipTypes.isEmpty()) {
        throw new IllegalStateException("No Relationship Types defined!");
    }
    EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, typeMappings, oneToOneMappings, useAbsolutPaths);
    return edmmConverter.transform(element);
}
Also used : QName(javax.xml.namespace.QName) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) EdmmType(org.eclipse.winery.edmm.model.EdmmType) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) EdmmConverter(org.eclipse.winery.edmm.model.EdmmConverter) EdmmManager(org.eclipse.winery.edmm.EdmmManager) IRepository(org.eclipse.winery.repository.backend.IRepository)

Aggregations

TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)12 QName (javax.xml.namespace.QName)9 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)7 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)6 TNodeType (org.eclipse.winery.model.tosca.TNodeType)5 HashSet (java.util.HashSet)4 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)4 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)4 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)4 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4 IRepository (org.eclipse.winery.repository.backend.IRepository)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)3 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 List (java.util.List)2 Objects (java.util.Objects)2