Search in sources :

Example 16 with TEntityTemplate

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

the class BackendUtils method mergeTopologyTemplateAinTopologyTemplateB.

/**
 * Merges two Topology Templates and returns the mapping between the topology elements from the original Topology
 * Template and their respective clones inside the merged topology. Hereby, the staying elements must not be
 * merged.
 *
 * @param topologyTemplateA the topology to merged into <code>topologyTemplateB</code>
 * @param topologyTemplateB the target topology in which <dode>topologyTemplateA</dode> should be merged in
 * @param stayingElementIds the TEntityTemplates that must not be merged from A to B.
 * @return A mapping between the ids in the <code>topologyTemplateA</code> and their corresponding ids in
 * <code>topologyTemplateB</code>
 */
public static Map<String, String> mergeTopologyTemplateAinTopologyTemplateB(TTopologyTemplate topologyTemplateA, TTopologyTemplate topologyTemplateB, List<String> stayingElementIds) {
    Objects.requireNonNull(topologyTemplateA);
    Objects.requireNonNull(topologyTemplateB);
    TTopologyTemplate topologyTemplateToBeMerged = new TTopologyTemplate.Builder().build();
    Map<String, String> idMapping = new HashMap<>();
    Optional<Integer> shiftLeft = topologyTemplateB.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TNodeTemplate).map(x -> (TNodeTemplate) x).max(Comparator.comparingInt(n -> ModelUtilities.getLeft(n).orElse(0))).map(n -> ModelUtilities.getLeft(n).orElse(0));
    if (Objects.nonNull(stayingElementIds)) {
        topologyTemplateA.getNodeTemplateOrRelationshipTemplate().forEach(entity -> {
            if (!stayingElementIds.contains(entity.getId())) {
                if (entity instanceof TNodeTemplate) {
                    topologyTemplateToBeMerged.addNodeTemplate((TNodeTemplate) entity);
                } else if (entity instanceof TRelationshipTemplate) {
                    topologyTemplateToBeMerged.addRelationshipTemplate((TRelationshipTemplate) entity);
                }
            }
        });
    } else {
        topologyTemplateToBeMerged.getNodeTemplateOrRelationshipTemplate().addAll(topologyTemplateA.getNodeTemplateOrRelationshipTemplate());
    }
    if (shiftLeft.isPresent()) {
        ModelUtilities.collectIdsOfExistingTopologyElements(topologyTemplateB, idMapping);
        // patch ids of reqs change them if required
        topologyTemplateToBeMerged.getNodeTemplates().stream().filter(nt -> nt.getRequirements() != null).forEach(nt -> nt.getRequirements().forEach(oldReq -> {
            TRequirement req = SerializationUtils.clone(oldReq);
            ModelUtilities.generateNewIdOfTemplate(req, idMapping);
            topologyTemplateToBeMerged.getRelationshipTemplates().stream().filter(rt -> rt.getSourceElement().getRef() instanceof TRequirement).forEach(rt -> {
                TRequirement sourceElement = (TRequirement) rt.getSourceElement().getRef();
                if (sourceElement.getId().equalsIgnoreCase(oldReq.getId())) {
                    sourceElement.setId(req.getId());
                }
            });
        }));
        // patch ids of caps change them if required
        topologyTemplateToBeMerged.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).forEach(nt -> nt.getCapabilities().forEach(oldCap -> {
            TCapability cap = SerializationUtils.clone(oldCap);
            ModelUtilities.generateNewIdOfTemplate(cap, idMapping);
            topologyTemplateToBeMerged.getRelationshipTemplates().stream().filter(rt -> rt.getTargetElement().getRef() instanceof TCapability).forEach(rt -> {
                TCapability targetElement = (TCapability) rt.getTargetElement().getRef();
                if (targetElement.getId().equalsIgnoreCase(oldCap.getId())) {
                    targetElement.setId(cap.getId());
                }
            });
        }));
        ArrayList<TRelationshipTemplate> newRelationships = new ArrayList<>();
        // patch the ids of templates and add them
        topologyTemplateToBeMerged.getNodeTemplateOrRelationshipTemplate().forEach(element -> {
            TEntityTemplate rtOrNt = SerializationUtils.clone(element);
            ModelUtilities.generateNewIdOfTemplate(rtOrNt, idMapping);
            if (rtOrNt instanceof TNodeTemplate) {
                int newLeft = ModelUtilities.getLeft((TNodeTemplate) rtOrNt).orElse(0) + shiftLeft.get();
                ((TNodeTemplate) rtOrNt).setX(Integer.toString(newLeft));
            } else if (rtOrNt instanceof TRelationshipTemplate) {
                newRelationships.add((TRelationshipTemplate) rtOrNt);
            }
            topologyTemplateB.getNodeTemplateOrRelationshipTemplate().add(rtOrNt);
        });
        // update references to the new elements
        newRelationships.forEach(rel -> {
            RelationshipSourceOrTarget source = rel.getSourceElement().getRef();
            RelationshipSourceOrTarget target = rel.getTargetElement().getRef();
            if (source instanceof TNodeTemplate && (stayingElementIds == null || stayingElementIds.stream().noneMatch(elementId -> elementId.equals(source.getId())))) {
                TNodeTemplate newSource = topologyTemplateB.getNodeTemplate(idMapping.get(source.getId()));
                rel.setSourceNodeTemplate(newSource);
            }
            if (target instanceof TNodeTemplate && (stayingElementIds == null || stayingElementIds.stream().noneMatch(elementId -> elementId.equals(target.getId())))) {
                TNodeTemplate newTarget = topologyTemplateB.getNodeTemplate(idMapping.get(target.getId()));
                rel.setTargetNodeTemplate(newTarget);
            }
        });
    } else {
        topologyTemplateB.getNodeTemplateOrRelationshipTemplate().addAll(topologyTemplateToBeMerged.getNodeTemplateOrRelationshipTemplate());
    }
    return idMapping;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) PlansId(org.eclipse.winery.model.ids.elements.PlansId) IdUtil(org.eclipse.winery.model.ids.IdUtil) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) XSImplementation(org.apache.xerces.xs.XSImplementation) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) WineryVersion(org.eclipse.winery.common.version.WineryVersion) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) Metadata(org.apache.tika.metadata.Metadata) ErrorHandler(org.xml.sax.ErrorHandler) IdNames(org.eclipse.winery.model.ids.IdNames) XSObjectList(org.apache.xerces.xs.XSObjectList) Map(java.util.Map) GenericId(org.eclipse.winery.model.ids.GenericId) Path(java.nio.file.Path) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TEntityType(org.eclipse.winery.model.tosca.TEntityType) XSTerm(org.apache.xerces.xs.XSTerm) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Constants(org.eclipse.winery.common.Constants) Set(java.util.Set) Reader(java.io.Reader) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) StandardCharsets(java.nio.charset.StandardCharsets) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) InvocationTargetException(java.lang.reflect.InvocationTargetException) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) FileVisitResult(java.nio.file.FileVisitResult) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) TCapability(org.eclipse.winery.model.tosca.TCapability) QName(javax.xml.namespace.QName) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) NonNull(org.eclipse.jdt.annotation.NonNull) GenericDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.GenericDirectoryId) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RelationshipSourceOrTarget(org.eclipse.winery.model.tosca.RelationshipSourceOrTarget) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) SerializationUtils(org.apache.commons.lang3.SerializationUtils) MediaType(org.apache.tika.mime.MediaType) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) LinkedHashMap(java.util.LinkedHashMap) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) XmlId(org.eclipse.winery.model.ids.XmlId) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) XsdImportManager(org.eclipse.winery.repository.backend.xsd.XsdImportManager) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) VisualAppearanceId(org.eclipse.winery.repository.datatypes.ids.elements.VisualAppearanceId) XSParticle(org.apache.xerces.xs.XSParticle) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) Detector(org.apache.tika.detect.Detector) XSSimpleType(org.apache.xerces.impl.dv.XSSimpleType) InputStreamReader(java.io.InputStreamReader) CONTINUE(java.nio.file.FileVisitResult.CONTINUE) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) DateUtils(org.apache.commons.lang3.time.DateUtils) EntityTypeId(org.eclipse.winery.model.ids.definitions.EntityTypeId) XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) JAXBSupport(org.eclipse.winery.repository.JAXBSupport) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) XSModel(org.apache.xerces.xs.XSModel) FileSystems(java.nio.file.FileSystems) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) SortedSet(java.util.SortedSet) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) LoggerFactory(org.slf4j.LoggerFactory) HasTargetNamespace(org.eclipse.winery.model.tosca.HasTargetNamespace) Namespace(org.eclipse.winery.model.ids.Namespace) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) ByteArrayInputStream(java.io.ByteArrayInputStream) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) Locale(java.util.Locale) VersionSupport(org.eclipse.winery.model.version.VersionSupport) ToscaDiff(org.eclipse.winery.model.version.ToscaDiff) PathMatcher(java.nio.file.PathMatcher) TRequirement(org.eclipse.winery.model.tosca.TRequirement) Util(org.eclipse.winery.repository.common.Util) XSComplexTypeDefinition(org.apache.xerces.xs.XSComplexTypeDefinition) URI(java.net.URI) ParseException(java.text.ParseException) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Filename(org.eclipse.winery.repository.backend.constants.Filename) HasName(org.eclipse.winery.model.tosca.HasName) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Collection(java.util.Collection) TNodeType(org.eclipse.winery.model.tosca.TNodeType) AutoDetectParser(org.apache.tika.parser.AutoDetectParser) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) Objects(java.util.Objects) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) AdminId(org.eclipse.winery.model.ids.admin.AdminId) List(java.util.List) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) TPlan(org.eclipse.winery.model.tosca.TPlan) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) Marshaller(javax.xml.bind.Marshaller) XSImplementationImpl(org.apache.xerces.impl.xs.XSImplementationImpl) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) XSLoader(org.apache.xerces.xs.XSLoader) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) HashSet(java.util.HashSet) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) XMLConstants(javax.xml.XMLConstants) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TImport(org.eclipse.winery.model.tosca.TImport) Unmarshaller(javax.xml.bind.Unmarshaller) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) XSModelGroup(org.apache.xerces.xs.XSModelGroup) GitInfo(org.eclipse.winery.repository.GitInfo) PlanId(org.eclipse.winery.model.ids.elements.PlanId) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ToscaElementId(org.eclipse.winery.model.ids.elements.ToscaElementId) TDataType(org.eclipse.winery.model.tosca.TDataType) SAXParseException(org.xml.sax.SAXParseException) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) Element(org.w3c.dom.Element) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) LSInput(org.w3c.dom.ls.LSInput) Comparator(java.util.Comparator) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) Collections(java.util.Collections) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) InputStream(java.io.InputStream) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) RelationshipSourceOrTarget(org.eclipse.winery.model.tosca.RelationshipSourceOrTarget) ArrayList(java.util.ArrayList) TCapability(org.eclipse.winery.model.tosca.TCapability) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 17 with TEntityTemplate

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

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ComplianceRuleId 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<>();
    OTComplianceRule complianceRule = this.getElement(id);
    // TODO extend to required Structure
    if (complianceRule.getIdentifier() != null) {
        for (TEntityTemplate entityTemplate : complianceRule.getIdentifier().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    for (TDeploymentArtifact da : deploymentArtifacts) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                getReferencedRequirementTypeIds(ids, n);
                getCapabilitiesReferences(ids, n);
                // 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);
                    }
                }
            } 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) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) HashSet(java.util.HashSet)

Example 18 with TEntityTemplate

use of org.eclipse.winery.model.tosca.TEntityTemplate in project container by OpenTOSCA.

the class BoundaryDefinitionController method getBoundaryDefinitionProperties.

@GET
@Path("/properties")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Get properties of a service tempate", response = PropertiesDTO.class)
public Response getBoundaryDefinitionProperties(@ApiParam("ID of CSAR") @PathParam("csar") final String csarId, @ApiParam("qualified name of the service template") @PathParam("servicetemplate") final String servicetemplate) {
    logger.debug("Invoking getBoundaryDefinitionProperties");
    final Csar csar = this.storage.findById(new CsarId(csarId));
    final TServiceTemplate serviceTemplate;
    try {
        serviceTemplate = ToscaEngine.resolveServiceTemplate(csar, servicetemplate);
    } catch (org.opentosca.container.core.common.NotFoundException e) {
        throw new NotFoundException(e);
    }
    if (Objects.isNull(serviceTemplate)) {
        return Response.status(Response.Status.NOT_FOUND).entity("ServiceTemplate not found!").build();
    }
    TBoundaryDefinitions boundary = serviceTemplate.getBoundaryDefinitions();
    if (Objects.isNull(boundary)) {
        return Response.status(Response.Status.NOT_FOUND).entity("BoundaryDefinitions not found!").build();
    }
    List<TPropertyMapping> propertyMappings = Optional.of(boundary).map(TBoundaryDefinitions::getProperties).map(TBoundaryDefinitions.Properties::getPropertyMappings).orElse(Collections.emptyList());
    logger.debug("Found <{}> property mappings", propertyMappings.size());
    final List<PropertyMappingDTO> propertyMappingDTOs = propertyMappings.stream().map(mapping -> {
        final PropertyMappingDTO result = new PropertyMappingDTO();
        result.setServiceTemplatePropertyRef(mapping.getServiceTemplatePropertyRef());
        result.setTargetPropertyRef(mapping.getTargetPropertyRef());
        if (!(mapping.getTargetObjectRef() instanceof TEntityTemplate)) {
            logger.error("Unexpected mapping target detected for the property (" + mapping.getServiceTemplatePropertyRef() + ")");
        } else {
            result.setTargetObjectRef(mapping.getTargetObjectRef().getId());
        }
        return result;
    }).collect(Collectors.toList());
    final PropertiesDTO dto = new PropertiesDTO();
    if (Objects.nonNull(boundary.getProperties())) {
        dto.setXmlFragment(boundary.getProperties().getAny());
        if (!propertyMappingDTOs.isEmpty()) {
            dto.setPropertyMappings(propertyMappingDTOs);
        }
    }
    dto.add(Link.fromUri(UriUtil.encode(this.uriInfo.getAbsolutePath())).rel("self").build());
    return Response.ok(dto).build();
}
Also used : Produces(javax.ws.rs.Produces) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) PlanType(org.opentosca.container.core.next.model.PlanType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ToscaEngine(org.opentosca.container.core.engine.ToscaEngine) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) ServiceTemplateInstanceRepository(org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository) Map(java.util.Map) URI(java.net.URI) CsarId(org.opentosca.container.core.model.csar.CsarId) Context(javax.ws.rs.core.Context) InterfaceDTO(org.opentosca.container.api.dto.boundarydefinitions.InterfaceDTO) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) Objects(java.util.Objects) PropertiesDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertiesDTO) List(java.util.List) Response(javax.ws.rs.core.Response) TPlan(org.eclipse.winery.model.tosca.TPlan) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) Optional(java.util.Optional) Request(javax.ws.rs.core.Request) UriInfo(javax.ws.rs.core.UriInfo) UriUtil(org.opentosca.container.core.common.uri.UriUtil) Link(javax.ws.rs.core.Link) InterfaceListDTO(org.opentosca.container.api.dto.boundarydefinitions.InterfaceListDTO) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) PropertyMappingDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertyMappingDTO) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) Inject(javax.inject.Inject) TExportedInterface(org.eclipse.winery.model.tosca.TExportedInterface) ResourceSupport(org.opentosca.container.api.dto.ResourceSupport) Api(io.swagger.annotations.Api) Csar(org.opentosca.container.core.model.csar.Csar) NodeOperationDTO(org.opentosca.container.api.dto.NodeOperationDTO) Logger(org.slf4j.Logger) CsarStorageService(org.opentosca.container.core.service.CsarStorageService) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) Component(org.springframework.stereotype.Component) OperationDTO(org.opentosca.container.api.dto.boundarydefinitions.OperationDTO) Collections(java.util.Collections) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation) Csar(org.opentosca.container.core.model.csar.Csar) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) NotFoundException(javax.ws.rs.NotFoundException) CsarId(org.opentosca.container.core.model.csar.CsarId) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) PropertiesDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertiesDTO) PropertyMappingDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertyMappingDTO) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 19 with TEntityTemplate

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

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

the class IGenericRepository 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) {
        TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
        if (policies != null) {
            for (TPolicy policy : policies.getPolicy()) {
                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)
    }
    if (serviceTemplate.getTopologyTemplate() != null) {
        for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
                    for (TDeploymentArtifact da : das) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                // crawl through reqs/caps
                TNodeTemplate.Requirements requirements = n.getRequirements();
                if (requirements != null) {
                    for (TRequirement req : requirements.getRequirement()) {
                        QName type = req.getType();
                        RequirementTypeId rtId = new RequirementTypeId(type);
                        ids.add(rtId);
                    }
                }
                TNodeTemplate.Capabilities capabilities = n.getCapabilities();
                if (capabilities != null) {
                    for (TCapability cap : capabilities.getCapability()) {
                        QName type = cap.getType();
                        CapabilityTypeId ctId = new CapabilityTypeId(type);
                        ids.add(ctId);
                    }
                }
                // crawl through policies
                org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies.getPolicy()) {
                        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);
                        }
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Aggregations

TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)42 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)19 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)14 QName (javax.xml.namespace.QName)13 ArrayList (java.util.ArrayList)9 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)9 Map (java.util.Map)8 HashSet (java.util.HashSet)7 List (java.util.List)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)7 TPolicy (org.eclipse.winery.model.tosca.TPolicy)7 PUT (javax.ws.rs.PUT)6 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)6 TEntityType (org.eclipse.winery.model.tosca.TEntityType)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4