Search in sources :

Example 1 with TTopologyTemplate

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

the class BackendUtils method mergeServiceTemplateAinServiceTemplateB.

public static void mergeServiceTemplateAinServiceTemplateB(ServiceTemplateId serviceTemplateIdA, ServiceTemplateId serviceTemplateIdB) throws IOException {
    IRepository repository = RepositoryFactory.getRepository();
    TTopologyTemplate topologyTemplateA = repository.getElement(serviceTemplateIdA).getTopologyTemplate();
    TServiceTemplate serviceTemplateB = repository.getElement(serviceTemplateIdB);
    TTopologyTemplate topologyTemplateB = serviceTemplateB.getTopologyTemplate();
    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 (shiftLeft.isPresent()) {
        Map<String, String> idMapping = new HashMap<>();
        // collect existing node template ids
        topologyTemplateB.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TNodeTemplate).map(x -> (TNodeTemplate) x).forEach(x -> idMapping.put(x.getId(), x.getId()));
        // collect existing relationship template ids
        topologyTemplateB.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TRelationshipTemplate).map(x -> (TRelationshipTemplate) x).forEach(x -> idMapping.put(x.getId(), x.getId()));
        if (topologyTemplateB.getNodeTemplates() != null) {
            // collect existing requirement ids
            topologyTemplateB.getNodeTemplates().stream().filter(nt -> nt.getRequirements() != null).forEach(nt -> nt.getRequirements().getRequirement().stream().forEach(x -> idMapping.put(x.getId(), x.getId())));
            // collect existing capability ids
            topologyTemplateB.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).forEach(nt -> nt.getCapabilities().getCapability().stream().forEach(x -> idMapping.put(x.getId(), x.getId())));
        }
        if (topologyTemplateA.getNodeTemplates() != null) {
            // patch ids of reqs change them if required
            topologyTemplateA.getNodeTemplates().stream().filter(nt -> nt.getRequirements() != null).forEach(nt -> nt.getRequirements().getRequirement().forEach(req -> {
                String oldId = req.getId();
                String newId = req.getId();
                while (idMapping.containsKey(newId)) {
                    newId = newId + "-new";
                }
                idMapping.put(req.getId(), newId);
                req.setId(newId);
                topologyTemplateA.getRelationshipTemplates().stream().filter(rt -> rt.getSourceElement().getRef() instanceof TRequirement).forEach(rt -> {
                    TRequirement sourceElement = (TRequirement) rt.getSourceElement().getRef();
                    if (sourceElement.getId().equalsIgnoreCase(oldId)) {
                        sourceElement.setId(req.getId());
                    }
                });
            }));
            // patch ids of caps change them if required
            topologyTemplateA.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).forEach(nt -> nt.getCapabilities().getCapability().forEach(cap -> {
                String oldId = cap.getId();
                String newId = cap.getId();
                while (idMapping.containsKey(newId)) {
                    newId = newId + "-new";
                }
                idMapping.put(cap.getId(), newId);
                cap.setId(newId);
                topologyTemplateA.getRelationshipTemplates().stream().filter(rt -> rt.getTargetElement().getRef() instanceof TCapability).forEach(rt -> {
                    TCapability targetElement = (TCapability) rt.getTargetElement().getRef();
                    if (targetElement.getId().equalsIgnoreCase(oldId)) {
                        targetElement.setId(cap.getId());
                    }
                });
            }));
        }
        // patch the ids of node templates and add them
        topologyTemplateA.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TNodeTemplate).map(x -> (TNodeTemplate) x).forEach(nt -> {
            String newId = nt.getId();
            while (idMapping.containsKey(newId)) {
                newId = newId + "-new";
            }
            idMapping.put(nt.getId(), newId);
            nt.setId(newId);
            int newLeft = ModelUtilities.getLeft((TNodeTemplate) nt).orElse(0) + shiftLeft.get();
            ((TNodeTemplate) nt).setX(Integer.toString(newLeft));
            topologyTemplateB.getNodeTemplateOrRelationshipTemplate().add(nt);
        });
        // patch the ids of relationship templates and add them
        topologyTemplateA.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TRelationshipTemplate).map(x -> (TRelationshipTemplate) x).forEach(rt -> {
            String newId = rt.getId();
            while (idMapping.containsKey(newId)) {
                newId = newId + "-new";
            }
            idMapping.put(rt.getId(), newId);
            rt.setId(newId);
            topologyTemplateB.getNodeTemplateOrRelationshipTemplate().add(rt);
        });
    } else {
        topologyTemplateB.getNodeTemplateOrRelationshipTemplate().addAll(topologyTemplateA.getNodeTemplateOrRelationshipTemplate());
    }
    repository.setElement(serviceTemplateIdB, serviceTemplateB);
}
Also used : XLogger(org.slf4j.ext.XLogger) BufferedInputStream(java.io.BufferedInputStream) ToscaElementId(org.eclipse.winery.common.ids.elements.ToscaElementId) XSImplementation(org.apache.xerces.xs.XSImplementation) XLoggerFactory(org.slf4j.ext.XLoggerFactory) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) Metadata(org.apache.tika.metadata.Metadata) ErrorHandler(org.xml.sax.ErrorHandler) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) Constants(org.eclipse.winery.repository.Constants) XSObjectList(org.apache.xerces.xs.XSObjectList) Document(org.w3c.dom.Document) Map(java.util.Map) 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) Set(java.util.Set) Reader(java.io.Reader) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileVisitResult(java.nio.file.FileVisitResult) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) TCapability(org.eclipse.winery.model.tosca.TCapability) QName(javax.xml.namespace.QName) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Namespace(org.eclipse.winery.common.ids.Namespace) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) NonNull(org.eclipse.jdt.annotation.NonNull) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId) Definitions(org.eclipse.winery.model.tosca.Definitions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) MediaType(org.apache.tika.mime.MediaType) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) EntityTypeId(org.eclipse.winery.common.ids.definitions.EntityTypeId) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) XsdImportManager(org.eclipse.winery.repository.backend.xsd.XsdImportManager) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) 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) XSDImportId(org.eclipse.winery.common.ids.definitions.imports.XSDImportId) AdminId(org.eclipse.winery.common.ids.admin.AdminId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) DateUtils(org.apache.commons.lang3.time.DateUtils) StringReader(java.io.StringReader) XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) JAXBSupport(org.eclipse.winery.repository.JAXBSupport) 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) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) SortedSet(java.util.SortedSet) Date(java.util.Date) HasTargetNamespace(org.eclipse.winery.model.tosca.HasTargetNamespace) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) ByteArrayInputStream(java.io.ByteArrayInputStream) TPlans(org.eclipse.winery.model.tosca.TPlans) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) Locale(java.util.Locale) PathMatcher(java.nio.file.PathMatcher) TRequirement(org.eclipse.winery.model.tosca.TRequirement) XSComplexTypeDefinition(org.apache.xerces.xs.XSComplexTypeDefinition) URI(java.net.URI) ParseException(java.text.ParseException) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Filename(org.eclipse.winery.repository.backend.constants.Filename) Collection(java.util.Collection) GenericId(org.eclipse.winery.common.ids.GenericId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.kvproperties.WinerysPropertiesDefinition) AutoDetectParser(org.apache.tika.parser.AutoDetectParser) JAXBException(javax.xml.bind.JAXBException) Util(org.eclipse.winery.common.Util) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) PlanId(org.eclipse.winery.common.ids.elements.PlanId) Objects(java.util.Objects) ImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifacts.ImplementationArtifact) 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) SAXException(org.xml.sax.SAXException) Optional(java.util.Optional) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) Marshaller(javax.xml.bind.Marshaller) XSImplementationImpl(org.apache.xerces.impl.xs.XSImplementationImpl) TImplementationArtifacts(org.eclipse.winery.model.tosca.TImplementationArtifacts) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) XSLoader(org.apache.xerces.xs.XSLoader) XmlId(org.eclipse.winery.common.ids.XmlId) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) HashSet(java.util.HashSet) NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) XMLConstants(javax.xml.XMLConstants) TImport(org.eclipse.winery.model.tosca.TImport) Unmarshaller(javax.xml.bind.Unmarshaller) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) Iterator(java.util.Iterator) PropertyDefinitionKV(org.eclipse.winery.model.tosca.kvproperties.PropertyDefinitionKV) PropertiesDefinition(org.eclipse.winery.model.tosca.TEntityType.PropertiesDefinition) XSModelGroup(org.apache.xerces.xs.XSModelGroup) GitInfo(org.eclipse.winery.repository.GitInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) PropertyDefinitionKVList(org.eclipse.winery.model.tosca.kvproperties.PropertyDefinitionKVList) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RelationshipTypeImplementationId(org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId) PlansId(org.eclipse.winery.common.ids.elements.PlansId) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) LSInput(org.w3c.dom.ls.LSInput) Comparator(java.util.Comparator) Collections(java.util.Collections) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) InputStream(java.io.InputStream) HashMap(java.util.HashMap) 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) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 2 with TTopologyTemplate

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

the class RESTHelper method saveCompleteTopology.

/**
 * This method uses a REST call to save the completed {@link TTopologyTemplate} to the repository.
 *
 * @param topology            the {@link TTopologyTemplate} to be saved
 * @param topologyTemplateURL the URL the {@link TTopologyTemplate} is saved to
 * @param overwriteTopology   whether the topology is overwritten or a new topology shall be created
 * @param topologyName        the name of the newly created topology to build the URL if a new topology shall be created
 * @param topologyNamespace   the name space of the newly created topology to build the URL if a new topology shall be created
 * @param repositoryURL       the URL to the repository to build the URL if a new topology shall be created
 */
public static void saveCompleteTopology(TTopologyTemplate topology, String topologyTemplateURL, boolean overwriteTopology, String topologyName, String topologyNamespace, String repositoryURL) {
    try {
        URL url = null;
        if (overwriteTopology) {
            url = new URL(topologyTemplateURL);
        } else {
            // this is necessary to avoid encoding issues
            topologyNamespace = Util.DoubleURLencode(topologyNamespace);
            // build the URL with the repositoryURL, the topology namespace and the topology name
            url = new URL(repositoryURL + "/servicetemplates/" + topologyNamespace + "/" + topologyName + "/topologytemplate/");
            LOGGER.info("The URL the topology is saved to: " + url);
        }
        // using SSL
        System.setProperty("javax.net.ssl.trustStore", "jssecacerts.cert");
        // configure message
        HttpURLConnection urlConn;
        urlConn = (HttpURLConnection) url.openConnection();
        LOGGER.info("Sending HTTP request...");
        urlConn.setDoOutput(true);
        urlConn.setRequestMethod("PUT");
        urlConn.setRequestProperty("Content-type", "text/xml");
        OutputStreamWriter out = new OutputStreamWriter(urlConn.getOutputStream());
        // build the XML string to be saved
        TTopologyTemplate outputTopology = JAXBHelper.buildXML(topology);
        String outputString = JAXBHelper.getXMLAsString(outputTopology.getClass(), outputTopology);
        LOGGER.info(outputString);
        LOGGER.info("Sending output to Winery.");
        out.write(outputString);
        out.close();
        urlConn.getOutputStream().close();
        LOGGER.info("Output sent, waiting for response...");
        urlConn.getInputStream();
        LOGGER.info("HTTP Response Code is: " + urlConn.getResponseCode());
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage());
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) URL(java.net.URL)

Example 3 with TTopologyTemplate

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

the class TOSCAModelHelper method createTTopologyTemplate.

public static TTopologyTemplate createTTopologyTemplate(List<TNodeTemplate> nodeTemplates, List<TRelationshipTemplate> relationshipTemplates) {
    TTopologyTemplate template = new TTopologyTemplate();
    template.setNodeTemplates(nodeTemplates);
    template.setRelationshipTemplates(relationshipTemplates);
    return template;
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate)

Example 4 with TTopologyTemplate

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

the class EnhancementUtils method getAvailableFeaturesForTopology.

// region ******************** Add Management Features ********************
/**
 * Gathers all feature NodeTypes available for the given topology.
 *
 * If the underlying implementation of the feature does not matter, use <code>null</code>.
 *
 * <p>
 * Note: If feature NodeTypes are used in the topology, they cannot be enhanced with more features.
 * </p>
 *
 * @param topology               The topology to update.
 * @param deploymentTechnologies Deployment technology descriptors contained in the service template
 */
public static Map<String, Map<QName, String>> getAvailableFeaturesForTopology(TTopologyTemplate topology, List<DeploymentTechnologyDescriptor> deploymentTechnologies) {
    IRepository repository = RepositoryFactory.getRepository();
    Map<String, Map<QName, String>> availableFeatures = new HashMap<>();
    Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
    topology.getNodeTemplates().forEach(node -> {
        List<String> nodeDeploymentTechnologies = deploymentTechnologies.stream().filter(deploymentTechnologyDescriptor -> deploymentTechnologyDescriptor.getManagedIds().contains(node.getId())).map(DeploymentTechnologyDescriptor::getTechnologyId).collect(Collectors.toList());
        Map<TNodeType, String> featureChildren = ModelUtilities.getAvailableFeaturesOfType(node.getType(), nodeTypes, nodeDeploymentTechnologies);
        Map<QName, String> applicableFeatures = new HashMap<>();
        // Check requirements
        featureChildren.forEach((featureType, value) -> {
            if (listIsNotNullOrEmpty(featureType.getRequirementDefinitions())) {
                List<TRequirementDefinition> requirements = featureType.getRequirementDefinitions().stream().filter(req -> req.getRequirementType().equals(OpenToscaBaseTypes.managementFeatureRequirement)).collect(Collectors.toList());
                requirements.forEach(req -> {
                    boolean applicable = ModelUtilities.getHostedOnSuccessors(topology, node).stream().anyMatch(hosts -> {
                        WineryVersion reqVersion = VersionUtils.getVersion(req.getName());
                        String reqName = VersionUtils.getNameWithoutVersion(req.getName());
                        String type = hosts.getType().getLocalPart();
                        if (VersionUtils.getNameWithoutVersion(type).equals(reqName)) {
                            return reqVersion.getComponentVersion().isEmpty() || reqVersion.getComponentVersion().equals(VersionUtils.getVersion(type).getComponentVersion());
                        }
                        return false;
                    });
                    if (applicable) {
                        applicableFeatures.put(featureType.getQName(), value);
                    }
                });
            } else {
                applicableFeatures.put(featureType.getQName(), value);
            }
        });
        if (featureChildren.size() > 0) {
            availableFeatures.put(node.getId(), applicableFeatures);
        }
    });
    return availableFeatures;
}
Also used : TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) OpenToscaInterfaces(org.eclipse.winery.model.tosca.constants.OpenToscaInterfaces) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Map(java.util.Map) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) Logger(org.slf4j.Logger) ListUtils.listIsNotNullOrEmpty(org.eclipse.winery.common.ListUtils.listIsNotNullOrEmpty) Collection(java.util.Collection) IOException(java.io.IOException) DeploymentTechnologyDescriptor(org.eclipse.winery.model.tosca.DeploymentTechnologyDescriptor) TNodeType(org.eclipse.winery.model.tosca.TNodeType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) TInterface(org.eclipse.winery.model.tosca.TInterface) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) Objects(java.util.Objects) List(java.util.List) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) VersionUtils(org.eclipse.winery.common.version.VersionUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) ToscaBaseTypes(org.eclipse.winery.model.tosca.constants.ToscaBaseTypes) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QName(javax.xml.namespace.QName) TNodeType(org.eclipse.winery.model.tosca.TNodeType) IRepository(org.eclipse.winery.repository.backend.IRepository) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Example 5 with TTopologyTemplate

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

the class EnhancementUtils method cleanFreezableComponents.

public static TTopologyTemplate cleanFreezableComponents(TTopologyTemplate topology) {
    topology.getNodeTemplates().stream().filter(node -> ModelUtilities.containsPolicyType(node, OpenToscaBaseTypes.freezableComponentPolicyType)).forEach(node -> {
        TRelationshipTemplate hostedOnRelationship = getHostedOnRelationship(topology, node);
        while (Objects.nonNull(hostedOnRelationship)) {
            TNodeTemplate host = (TNodeTemplate) hostedOnRelationship.getTargetElement().getRef();
            if (node.getPolicies() != null && ModelUtilities.containsPolicyType(host, OpenToscaBaseTypes.freezableComponentPolicyType)) {
                node.getPolicies().removeIf(policy -> policy.getPolicyType().equals(OpenToscaBaseTypes.freezableComponentPolicyType));
                hostedOnRelationship = null;
            } else {
                hostedOnRelationship = getHostedOnRelationship(topology, host);
            }
        }
    });
    return topology;
}
Also used : TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) OpenToscaInterfaces(org.eclipse.winery.model.tosca.constants.OpenToscaInterfaces) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Map(java.util.Map) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) Logger(org.slf4j.Logger) ListUtils.listIsNotNullOrEmpty(org.eclipse.winery.common.ListUtils.listIsNotNullOrEmpty) Collection(java.util.Collection) IOException(java.io.IOException) DeploymentTechnologyDescriptor(org.eclipse.winery.model.tosca.DeploymentTechnologyDescriptor) TNodeType(org.eclipse.winery.model.tosca.TNodeType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) TInterface(org.eclipse.winery.model.tosca.TInterface) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) Objects(java.util.Objects) List(java.util.List) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) VersionUtils(org.eclipse.winery.common.version.VersionUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) ToscaBaseTypes(org.eclipse.winery.model.tosca.constants.ToscaBaseTypes) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)158 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)112 ArrayList (java.util.ArrayList)85 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)62 List (java.util.List)59 QName (javax.xml.namespace.QName)55 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)55 Test (org.junit.jupiter.api.Test)51 Map (java.util.Map)48 HashMap (java.util.HashMap)47 LinkedHashMap (java.util.LinkedHashMap)42 TNodeType (org.eclipse.winery.model.tosca.TNodeType)42 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)38 IRepository (org.eclipse.winery.repository.backend.IRepository)38 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)36 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)35 Objects (java.util.Objects)34 IOException (java.io.IOException)32 HashSet (java.util.HashSet)32 Collectors (java.util.stream.Collectors)32