Search in sources :

Example 1 with TCapabilityRef

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

the class CapabilitiesResource method addNewElement.

@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();
    }
    TCapabilityRef ref = new TCapabilityRef();
    // may also be null
    ref.setName(name);
    // The XML model fordces us to put a reference to the object and not just the string
    ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
    TCapability resolved = ModelUtilities.resolveCapability(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 : ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TCapability(org.eclipse.winery.model.tosca.TCapability) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef)

Example 2 with TCapabilityRef

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

the class Substitution method replaceNodeTemplateWithServiceTemplate.

private void replaceNodeTemplateWithServiceTemplate(TTopologyTemplate topologyTemplate, Map<TNodeTemplate, TServiceTemplate> nodeTemplateToBeSubstitutedWithTopology) {
    nodeTemplateToBeSubstitutedWithTopology.forEach((substitutableNodeTemplate, stSubstitutingTheNodeTemplate) -> {
        if (Objects.nonNull(stSubstitutingTheNodeTemplate.getBoundaryDefinitions())) {
            TTopologyTemplate topologyToImport = stSubstitutingTheNodeTemplate.getTopologyTemplate();
            // 1. get all references of the Node Template
            // 1.1 Relationships
            // TODO 1.2 Boundary definitions
            List<TRelationshipTemplate> ingoingRelations = new ArrayList<>();
            List<TRelationshipTemplate> outgoingRelations = new ArrayList<>();
            topologyTemplate.getRelationshipTemplates().forEach(tRelationshipTemplate -> {
                if (substitutableNodeTemplate.getId().equals(tRelationshipTemplate.getSourceElement().getRef().getId())) {
                    outgoingRelations.add(tRelationshipTemplate);
                }
                if (substitutableNodeTemplate.getId().equals(tRelationshipTemplate.getTargetElement().getRef().getId())) {
                    ingoingRelations.add(tRelationshipTemplate);
                }
            });
            // 2. import the topology in the Service Template
            BackendUtils.mergeTopologyTemplateAinTopologyTemplateB(topologyToImport, topologyTemplate);
            // 3. update the references accordingly
            if (topologyToImport != null && ingoingRelations.size() > 0) {
                if (Objects.nonNull(stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getCapabilities())) {
                    List<TCapabilityRef> capabilities = stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getCapabilities();
                    ingoingRelations.forEach(ingoing -> capabilities.forEach(tCapabilityRef -> topologyToImport.getNodeTemplates().stream().filter(tNodeTemplate -> Objects.nonNull(tNodeTemplate.getCapabilities())).filter(tNodeTemplate -> tNodeTemplate.getCapabilities().stream().anyMatch(tCapability -> tCapability.equals(tCapabilityRef.getRef()))).findFirst().ifPresent(tNodeTemplate -> ingoing.getTargetElement().setRef(tNodeTemplate))));
                } else {
                    throw new UnsupportedOperationException("Mapping without Reqs/Caps is currently not supported");
                }
            }
            if (topologyToImport != null && outgoingRelations.size() > 0) {
                if (Objects.nonNull(stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getRequirements())) {
                    List<TRequirementRef> requirements = stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getRequirements();
                    outgoingRelations.forEach(outgoing -> requirements.forEach(requirementRef -> topologyToImport.getNodeTemplates().stream().filter(tNodeTemplate -> Objects.nonNull(tNodeTemplate.getRequirements()) && tNodeTemplate.getRequirements().stream().anyMatch(tRequirement -> tRequirement.equals(requirementRef.getRef()))).findFirst().ifPresent(tNodeTemplate -> outgoing.getSourceElement().setRef(tNodeTemplate))));
                } else {
                    throw new UnsupportedOperationException("Mapping without Reqs/Caps is currently not supported");
                }
            }
            // TODO: propagate property mappings
            topologyTemplate.getNodeTemplateOrRelationshipTemplate().remove(substitutableNodeTemplate);
        }
    });
}
Also used : TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef) Logger(org.slf4j.Logger) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) HashMap(java.util.HashMap) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Objects(java.util.Objects) List(java.util.List) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef)

Example 3 with TCapabilityRef

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

the class ServiceTemplateResource method cullElementReferences.

private void cullElementReferences() {
    final TTopologyTemplate topology = this.getServiceTemplate().getTopologyTemplate();
    TBoundaryDefinitions boundaryDefs = this.getServiceTemplate().getBoundaryDefinitions();
    if (topology == null || boundaryDefs == null) {
        return;
    }
    if (boundaryDefs.getProperties() != null && boundaryDefs.getProperties().getPropertyMappings() != null) {
        for (Iterator<TPropertyMapping> it = boundaryDefs.getProperties().getPropertyMappings().iterator(); it.hasNext(); ) {
            TPropertyMapping propMapping = it.next();
            HasId targetObject = propMapping.getTargetObjectRef();
            if (!containsTarget(topology, targetObject)) {
                // cull the property mapping pointing towards a no-longer existing element
                it.remove();
            }
        }
    }
    if (boundaryDefs.getCapabilities() != null) {
        for (Iterator<TCapabilityRef> it = boundaryDefs.getCapabilities().iterator(); it.hasNext(); ) {
            TCapabilityRef ref = it.next();
            TCapability target = ref.getRef();
            if (!containsCapability(topology, target)) {
                // cull the capability referencing a no longer existing capability in the topology
                it.remove();
            }
        }
    }
    if (boundaryDefs.getRequirements() != null) {
        for (Iterator<TRequirementRef> it = boundaryDefs.getRequirements().iterator(); it.hasNext(); ) {
            TRequirementRef ref = it.next();
            TRequirement target = ref.getRef();
            if (!containsRequirement(topology, target)) {
                // cull the requirement referencing a no longer existing requirement in the topology
                it.remove();
            }
        }
    }
}
Also used : HasId(org.eclipse.winery.model.tosca.HasId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TCapability(org.eclipse.winery.model.tosca.TCapability) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef)

Example 4 with TCapabilityRef

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

the class CapabilitiesResource method addNewElementJSON.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addNewElementJSON(RequirementsOrCapabilityApiData reqOrCap) {
    if (reqOrCap.ref == null) {
        return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
    }
    TCapabilityRef ref = new TCapabilityRef();
    // may also be null
    ref.setName(reqOrCap.name);
    // The XML model fordces us to put a reference to the object and not just the string
    ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
    TCapability resolved = ModelUtilities.resolveCapability(rs.getServiceTemplate(), reqOrCap.ref);
    // 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 : ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TCapability(org.eclipse.winery.model.tosca.TCapability) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef)

Aggregations

TCapabilityRef (org.eclipse.winery.model.tosca.TCapabilityRef)4 TCapability (org.eclipse.winery.model.tosca.TCapability)3 TRequirementRef (org.eclipse.winery.model.tosca.TRequirementRef)2 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)2 ServiceTemplateResource (org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 QName (javax.xml.namespace.QName)1 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)1 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)1 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)1 HasId (org.eclipse.winery.model.tosca.HasId)1 TBoundaryDefinitions (org.eclipse.winery.model.tosca.TBoundaryDefinitions)1 TCapabilityType (org.eclipse.winery.model.tosca.TCapabilityType)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TNodeType (org.eclipse.winery.model.tosca.TNodeType)1