Search in sources :

Example 1 with TRequirement

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

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

the class IGenericRepository 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<>();
    TComplianceRule 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
                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);
                    }
                }
            } 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) TComplianceRule(org.eclipse.winery.model.tosca.TComplianceRule) 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) 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) 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) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 3 with TRequirement

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

the class ServiceTemplateResource method injectNodeTemplates.

@POST
@Path("injector/replace")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response injectNodeTemplates(InjectorReplaceData injectorReplaceData, @Context UriInfo uriInfo) throws Exception, IOException, ParserConfigurationException, SAXException, SplittingException {
    if (injectorReplaceData.hostInjections != null) {
        Collection<TTopologyTemplate> hostInjectorTopologyTemplates = injectorReplaceData.hostInjections.values();
        hostInjectorTopologyTemplates.forEach(t -> {
            try {
                ModelUtilities.patchAnyAttributes(t.getNodeTemplates());
            } catch (IOException e) {
                LOGGER.error("XML was invalid", e);
            }
        });
    }
    if (injectorReplaceData.connectionInjections != null) {
        Collection<TTopologyTemplate> connectionInjectorTopologyTemplates = injectorReplaceData.connectionInjections.values();
        connectionInjectorTopologyTemplates.forEach(t -> {
            try {
                ModelUtilities.patchAnyAttributes(t.getNodeTemplates());
            } catch (IOException e) {
                LOGGER.error("XML was invalid", e);
            }
        });
    }
    Splitting splitting = new Splitting();
    TTopologyTemplate matchedHostsTopologyTemplate;
    TTopologyTemplate matchedConnectedTopologyTemplate;
    // Test Method findOpenRequirements
    Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = splitting.getOpenRequirementsAndMatchingBasisCapabilityTypeNames(this.getServiceTemplate().getTopologyTemplate());
    // Output check
    for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
        System.out.println("open Requirement: " + req.getId());
        System.out.println("matchingbasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
    }
    if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
        matchedHostsTopologyTemplate = splitting.injectNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.hostInjections);
        if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
            matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(matchedHostsTopologyTemplate, injectorReplaceData.connectionInjections);
        } else {
            matchedConnectedTopologyTemplate = matchedHostsTopologyTemplate;
        }
    } else if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
        matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.connectionInjections);
    } else {
        throw new SplittingException("No open Requirements which can be matched");
    }
    TTopologyTemplate daSpecifiedTopology = matchedConnectedTopologyTemplate;
    // Start additional functionality Driver Injection
    if (!DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate).isEmpty() && DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate) != null) {
        daSpecifiedTopology = DriverInjection.injectDriver(matchedConnectedTopologyTemplate);
    }
    // End additional functionality Driver Injection
    this.getServiceTemplate().setTopologyTemplate(daSpecifiedTopology);
    LOGGER.debug("Persisting...");
    RestUtils.persist(this);
    LOGGER.debug("Persisted.");
    // No renaming of the Service Template allowed because of the plans
    URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(id));
    LOGGER.debug("URI of the old and new service template {}", url.toString());
    return Response.created(url).build();
}
Also used : Splitting(org.eclipse.winery.repository.splitting.Splitting) TRequirement(org.eclipse.winery.model.tosca.TRequirement) SplittingException(org.eclipse.winery.repository.splitting.SplittingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) IOException(java.io.IOException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with TRequirement

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

the class ServiceTemplateResource method getInjectorOptions.

@GET
@Path("injector/options")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response getInjectorOptions() {
    Splitting splitting = new Splitting();
    TTopologyTemplate topologyTemplate = this.getServiceTemplate().getTopologyTemplate();
    Map<String, List<TTopologyTemplate>> hostMatchingOptions;
    Map<String, List<TTopologyTemplate>> connectionMatchingOptions;
    InjectorReplaceOptions injectionReplaceOptions = new InjectorReplaceOptions();
    try {
        Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = splitting.getOpenRequirementsAndMatchingBasisCapabilityTypeNames(this.getServiceTemplate().getTopologyTemplate());
        // Output check
        for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
            System.out.println("open Requirement: " + req.getId());
            System.out.println("matchingBasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
        }
        if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
            hostMatchingOptions = splitting.getHostingMatchingOptionsWithDefaultLabeling(topologyTemplate);
        } else {
            hostMatchingOptions = null;
        }
        if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
            connectionMatchingOptions = splitting.getConnectionInjectionOptions(topologyTemplate);
        } else {
            connectionMatchingOptions = null;
        }
        injectionReplaceOptions.setTopologyTemplate(topologyTemplate);
        injectionReplaceOptions.setHostInjectionOptions(hostMatchingOptions);
        injectionReplaceOptions.setConnectionInjectionOptions(connectionMatchingOptions);
        if (hostMatchingOptions == null && connectionMatchingOptions == null) {
            return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("No need for matching").build();
        }
    } catch (SplittingException e) {
        LOGGER.error("Could not match", e);
        return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
    }
    return Response.ok().entity(injectionReplaceOptions).build();
}
Also used : InjectorReplaceOptions(org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceOptions) Splitting(org.eclipse.winery.repository.splitting.Splitting) TRequirement(org.eclipse.winery.model.tosca.TRequirement) SplittingException(org.eclipse.winery.repository.splitting.SplittingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) List(java.util.List) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with TRequirement

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

the class RequirementsResource method addNewElement.

/**
 * Adds an element using form-encoding
 * <p>
 * This is necessary as TRequirementRef contains an IDREF and the XML snippet itself does not contain the target id
 *
 * @param name      the optional name of the requirement
 * @param reference the reference to a requirement in the topology
 */
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response addNewElement(@FormParam("name") String name, @FormParam("ref") String reference) {
    if (reference == null) {
        return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
    }
    TRequirementRef ref = new TRequirementRef();
    // may also be null
    ref.setName(name);
    // The XML model forces us to put a reference to the object and not just the string
    ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
    TRequirement resolved = ModelUtilities.resolveRequirement(rs.getServiceTemplate(), reference);
    // In case nothing was found: report back to the user
    if (resolved == null) {
        return Response.status(Status.BAD_REQUEST).entity("Reference could not be resolved").build();
    }
    ref.setRef(resolved);
    // "this.alreadyContains(ref)" cannot be called as this leads to a mappable exception: The data does not contain an id where the given ref attribute may point to
    this.list.add(ref);
    return CollectionsHelper.persist(this.res, this, ref, true);
}
Also used : TRequirement(org.eclipse.winery.model.tosca.TRequirement) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef)

Aggregations

TRequirement (org.eclipse.winery.model.tosca.TRequirement)8 QName (javax.xml.namespace.QName)4 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)4 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)4 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)4 HashSet (java.util.HashSet)3 List (java.util.List)3 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)3 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)3 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)3 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)3 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)3 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)3 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)3 TCapability (org.eclipse.winery.model.tosca.TCapability)3 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)3 TDeploymentArtifacts (org.eclipse.winery.model.tosca.TDeploymentArtifacts)3 IOException (java.io.IOException)2