Search in sources :

Example 6 with NodeTypeImplementationId

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

the class ConsistencyCheckerTest method nodeTypeImplementationNamespaceHasNoErrors.

@Test
public void nodeTypeImplementationNamespaceHasNoErrors() {
    NodeTypeImplementationId id = new NodeTypeImplementationId("http://winery.opentosca.org/test/nodetypeimplementations/fruits", "baobab_impl", false);
    ConsistencyErrorCollector errorLogger = new ConsistencyErrorCollector();
    consistencyChecker.checkNamespaceUri(id);
    assertEquals(Collections.emptyMap(), errorLogger.getErrorList());
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with NodeTypeImplementationId

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

the class ToscaExportUtil method specifyImports.

private TDefinitions specifyImports(IRepository repository, DefinitionsChildId tcId, Collection<DefinitionsChildId> referencedDefinitionsChildIds) {
    TDefinitions entryDefinitions = repository.getDefinitions(tcId);
    // BEGIN: Definitions modification
    // the "imports" collection contains the imports of Definitions, not of other definitions
    // the other definitions are stored in entryDefinitions.getImport()
    // we modify the internal definitions object directly. It is not written back to the storage. Therefore, we do not need to clone it
    // the imports (pointing to not-definitions (xsd, wsdl, ...)) already have a correct relative URL. (quick hack)
    URI uri = (URI) this.exportConfiguration.get(CsarExportConfiguration.REPOSITORY_URI.name());
    if (uri != null) {
        // we are in the plain-XML mode, the URLs of the imports have to be adjusted
        for (TImport i : entryDefinitions.getImport()) {
            String loc = i.getLocation();
            if (!loc.startsWith("../")) {
                LOGGER.warn("Location is not relative for id " + tcId.toReadableString());
            }
            loc = loc.substring(3);
            loc = uri + loc;
            // now the location is an absolute URL
            i.setLocation(loc);
        }
    }
    // files of imports have to be added to the CSAR, too
    for (TImport i : entryDefinitions.getImport()) {
        String loc = i.getLocation();
        if (Util.isRelativeURI(loc)) {
            // locally stored, add to CSAR
            GenericImportId iid = new GenericImportId(i);
            String fileName = IdUtil.getLastURIPart(loc);
            fileName = EncodingUtil.URLdecode(fileName);
            RepositoryFileReference ref = new RepositoryFileReference(iid, fileName);
            putRefAsReferencedItemInCsar(repository, ref);
        }
    }
    Set<DefinitionsChildId> collect = referencedDefinitionsChildIds.stream().filter(id -> id instanceof NodeTypeImplementationId).collect(Collectors.toSet());
    if (collect.stream().anyMatch(DefinitionsChildId::isSelfContained)) {
        if (this.exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_DEPENDENCIES.name())) {
            referencedDefinitionsChildIds.removeAll(collect.stream().filter(id -> !id.isSelfContained()).collect(Collectors.toList()));
        } else if (collect.size() > 1 && collect.stream().anyMatch(id -> !id.isSelfContained())) {
            referencedDefinitionsChildIds.removeAll(collect.stream().filter(DefinitionsChildId::isSelfContained).collect(Collectors.toList()));
        }
    }
    // adjust imports: add imports of definitions to it
    Collection<TImport> imports = new ArrayList<>();
    for (DefinitionsChildId id : referencedDefinitionsChildIds) {
        this.addToImports(repository, id, imports);
    }
    entryDefinitions.getImport().addAll(imports);
    // END: Definitions modification
    return entryDefinitions;
}
Also used : PlansId(org.eclipse.winery.model.ids.elements.PlansId) SortedSet(java.util.SortedSet) IdUtil(org.eclipse.winery.model.ids.IdUtil) LoggerFactory(org.slf4j.LoggerFactory) QNames(org.eclipse.winery.model.tosca.constants.QNames) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) Document(org.w3c.dom.Document) Map(java.util.Map) Util(org.eclipse.winery.repository.common.Util) URI(java.net.URI) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) Filename(org.eclipse.winery.repository.backend.constants.Filename) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TEntityType(org.eclipse.winery.model.tosca.TEntityType) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Collection(java.util.Collection) Set(java.util.Set) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) GenericImportId(org.eclipse.winery.model.ids.definitions.imports.GenericImportId) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) TopologyGraphElementEntityTypeId(org.eclipse.winery.model.ids.definitions.TopologyGraphElementEntityTypeId) QName(javax.xml.namespace.QName) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) XMLConstants(javax.xml.XMLConstants) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) TImport(org.eclipse.winery.model.tosca.TImport) OutputStream(java.io.OutputStream) VisualAppearanceId(org.eclipse.winery.repository.datatypes.ids.elements.VisualAppearanceId) Logger(org.slf4j.Logger) PlanId(org.eclipse.winery.model.ids.elements.PlanId) IOException(java.io.IOException) EntityTypeId(org.eclipse.winery.model.ids.definitions.EntityTypeId) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TImport(org.eclipse.winery.model.tosca.TImport) ArrayList(java.util.ArrayList) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) URI(java.net.URI) GenericImportId(org.eclipse.winery.model.ids.definitions.imports.GenericImportId)

Example 8 with NodeTypeImplementationId

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

the class SelfContainmentPackager method getSelfContainedNodeTypeImplId.

private NodeTypeImplementationId getSelfContainedNodeTypeImplId(TNodeTypeImplementation impl) {
    QName implQName = new QName(impl.getTargetNamespace(), impl.getIdFromIdOrNameField());
    NodeTypeImplementationId originalId = new NodeTypeImplementationId(implQName);
    return new NodeTypeImplementationId(VersionSupport.getSelfContainedVersion(originalId));
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) QName(javax.xml.namespace.QName)

Example 9 with NodeTypeImplementationId

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

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

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