Search in sources :

Example 31 with NodeTypeId

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

the class SelfContainmentPackager method createSelfContainedVersion.

public DefinitionsChildId createSelfContainedVersion(DefinitionsChildId entryId) throws IOException {
    ServiceTemplateId newServiceTemplateId = new ServiceTemplateId(VersionSupport.getSelfContainedVersion(entryId));
    if (!repository.exists(newServiceTemplateId)) {
        repository.duplicate(entryId, newServiceTemplateId);
        TServiceTemplate serviceTemplate = repository.getElement(newServiceTemplateId);
        Collection<DefinitionsChildId> referencedElements = repository.getReferencedDefinitionsChildIds(newServiceTemplateId);
        for (DefinitionsChildId elementId : referencedElements) {
            if (elementId instanceof NodeTypeId) {
                Collection<NodeTypeImplementationId> nodeTypeImplementationIds = repository.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, elementId.getQName());
                if (nodeTypeImplementationIds.stream().noneMatch(DefinitionsChildId::isSelfContained)) {
                    // self-contained element does not exist yet!
                    List<TNodeTypeImplementation> nodeTypeImplementations = nodeTypeImplementationIds.stream().map(repository::getElement).filter(element -> element.getImplementationArtifacts() != null).collect(Collectors.toList());
                    for (TNodeTypeImplementation impl : nodeTypeImplementations) {
                        Optional<SelfContainmentPlugin> nodeTypeBasedPlugin = this.selfContainmentPlugins.stream().filter(plugin -> plugin.canHandleNodeType(elementId.getQName(), repository)).findFirst();
                        if (nodeTypeBasedPlugin.isPresent()) {
                            NodeTypeImplementationId selfContainedNodeTypeImpl = getSelfContainedNodeTypeImplId(impl);
                            try {
                                repository.duplicate(new NodeTypeImplementationId(impl.getTargetNamespace(), impl.getIdFromIdOrNameField(), false), selfContainedNodeTypeImpl);
                                TNodeTypeImplementation selfContained = this.repository.getElement(selfContainedNodeTypeImpl);
                                nodeTypeBasedPlugin.get().downloadDependenciesBasedOnNodeType(selfContained, this.repository);
                                repository.setElement(selfContainedNodeTypeImpl, selfContained);
                            } catch (IOException e) {
                                logger.error("While creating self-contained Node Type Implementation", e);
                            }
                        } else if (impl.getImplementationArtifacts() != null) {
                            createSelfContainedNodeTypeImplementation(impl);
                        }
                    }
                }
            } else if (elementId instanceof ArtifactTemplateId) {
                if (serviceTemplate.getTopologyTemplate() != null) {
                    TArtifactTemplate artifactTemplate = repository.getElement(elementId);
                    SelfContainmentPlugin.GeneratedArtifacts generatedArtifacts = this.downloadArtifacts(elementId.getQName(), artifactTemplate.getType());
                    if (generatedArtifacts != null && generatedArtifacts.selfContainedArtifactQName != null) {
                        // first, we need to identify the element that is referencing the artifact
                        serviceTemplate.getTopologyTemplate().getNodeTemplates().stream().map(TNodeTemplate::getDeploymentArtifacts).filter(Objects::nonNull).filter(daList -> daList.stream().anyMatch(da -> da.getArtifactRef() != null && da.getArtifactRef().equals(elementId.getQName()))).flatMap(Collection::stream).forEach(da -> da.setArtifactRef(generatedArtifacts.selfContainedArtifactQName));
                    }
                }
            }
        }
        repository.setElement(newServiceTemplateId, serviceTemplate);
    } else {
        logger.info("Self-contained version already exists! '{}'", newServiceTemplateId.getQName());
    }
    return newServiceTemplateId;
}
Also used : TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Collection(java.util.Collection) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Objects(java.util.Objects) List(java.util.List) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) VersionSupport(org.eclipse.winery.model.version.VersionSupport) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Objects(java.util.Objects) Collection(java.util.Collection) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 32 with NodeTypeId

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

the class DataFlowResource method createNodeTemplate.

/**
 * Create a NodeTemplate corresponding to the given filter with the given type, properties and artifacts and add it
 * to the topology of the incomplete deployment model.
 */
private TTopologyTemplate createNodeTemplate(TTopologyTemplate topology, NodeTypeId nodeTypeId, String templateName, Map<String, String> properties, List<QName> artifacts) {
    // get NodeType to access Requirements for the completion and available properties
    IRepository repo = RepositoryFactory.getRepository();
    TNodeType nodeType = repo.getElement(nodeTypeId);
    if (Objects.isNull(nodeType)) {
        return null;
    }
    TNodeTemplate.Builder templateBuilder = new TNodeTemplate.Builder(templateName, nodeTypeId.getQName());
    // add the defined properties to the NodeTemplate
    if (Objects.nonNull(properties)) {
        LinkedHashMap<String, String> propertyList = new LinkedHashMap<>();
        if (Objects.nonNull(nodeType.getWinerysPropertiesDefinition())) {
            // add empty property for NodeType properties to avoid errors due to missing properties
            WinerysPropertiesDefinition def = nodeType.getWinerysPropertiesDefinition();
            for (PropertyDefinitionKV prop : def.getPropertyDefinitions()) {
                propertyList.put(prop.getKey(), "");
            }
        }
        // add all properties which are defined at the filter
        propertyList.putAll(properties);
        TEntityTemplate.WineryKVProperties nodeProperties = new TEntityTemplate.WineryKVProperties();
        nodeProperties.setKVProperties(propertyList);
        templateBuilder.setProperties(nodeProperties);
    }
    // add all requirements which are defined by the corresponding NodeType
    if (nodeType.getRequirementDefinitions() != null) {
        for (TRequirementDefinition requirementDef : nodeType.getRequirementDefinitions()) {
            String requirementId = templateName + "-" + requirementDef.getName();
            templateBuilder.addRequirement(new TRequirement.Builder(requirementId, requirementDef.getName(), requirementDef.getRequirementType()).build());
        }
    }
    // add the DAs to the NodeTemplate
    if (Objects.nonNull(artifacts) && !artifacts.isEmpty()) {
        LOGGER.debug("{} artifacts specified for filter {}", artifacts.size(), templateName);
        // get the IDs of all available ArtifactTemplates
        List<ArtifactTemplateId> artifactTemplateIds = repo.getAllDefinitionsChildIds().stream().filter(id -> id.getGroup().equals(ARTIFACT_TEMPLATE_GROUP) && id instanceof ArtifactTemplateId).map(id -> (ArtifactTemplateId) id).collect(Collectors.toList());
        for (QName artifactName : artifacts) {
            Optional<ArtifactTemplateId> idOptional = artifactTemplateIds.stream().filter(id -> id.getQName().equals(artifactName)).findFirst();
            if (idOptional.isPresent()) {
                ArtifactTemplateId artifactTemplateId = idOptional.get();
                TArtifactTemplate artifactTemplate = repo.getElement(artifactTemplateId);
                templateBuilder.addDeploymentArtifact(new TDeploymentArtifact.Builder(artifactName.toString(), artifactTemplate.getType()).setArtifactRef(artifactName).build());
            } else {
                LOGGER.warn("Filter '{}' specifies DA with name '{}' but no such artifact available in repository!", templateName, artifactName);
            }
        }
    }
    topology.addNodeTemplate(templateBuilder.build());
    return topology;
}
Also used : URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) TRequirement(org.eclipse.winery.model.tosca.TRequirement) URI(java.net.URI) TAG_NAME_PROVIDER(org.eclipse.winery.model.adaptation.placement.Constants.TAG_NAME_PROVIDER) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) RELATIONSHIP_TEMPLATE_TRANSFER_TYPE_PULL(org.eclipse.winery.model.adaptation.placement.Constants.RELATIONSHIP_TEMPLATE_TRANSFER_TYPE_PULL) TNodeType(org.eclipse.winery.model.tosca.TNodeType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) 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) Response(javax.ws.rs.core.Response) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) QName(javax.xml.namespace.QName) ToscaBaseTypes(org.eclipse.winery.model.tosca.constants.ToscaBaseTypes) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) LinkedHashMap(java.util.LinkedHashMap) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) SERVICE_TEMPLATE_GROUP(org.eclipse.winery.model.adaptation.placement.Constants.SERVICE_TEMPLATE_GROUP) IOException(java.io.IOException) TTag(org.eclipse.winery.model.tosca.TTag) TAG_NAME_LOCATION(org.eclipse.winery.model.adaptation.placement.Constants.TAG_NAME_LOCATION) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) DataFlowModel(org.eclipse.winery.repository.rest.resources.apiData.DataFlowModel) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) ARTIFACT_TEMPLATE_GROUP(org.eclipse.winery.model.adaptation.placement.Constants.ARTIFACT_TEMPLATE_GROUP) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DATA_TRANSFER_TYPE_PULL(org.eclipse.winery.model.adaptation.placement.Constants.DATA_TRANSFER_TYPE_PULL) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) QName(javax.xml.namespace.QName) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) LinkedHashMap(java.util.LinkedHashMap) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) IRepository(org.eclipse.winery.repository.backend.IRepository) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 33 with NodeTypeId

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

the class DataFlowResource method parseDataFlowToServiceTemplate.

@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response parseDataFlowToServiceTemplate(DataFlowModel dataFlowModel) {
    if (Objects.isNull(dataFlowModel)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Passed data flow model is null!").build();
    }
    if (Objects.isNull(dataFlowModel.getId().getNamespaceURI())) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Namespace must be defined for the data flow " + "model ID!").build();
    }
    IRepository repo = RepositoryFactory.getRepository();
    ServiceTemplateId templateId = new ServiceTemplateId(dataFlowModel.getId());
    if (repo.exists(templateId)) {
        return Response.status(Response.Status.CONFLICT).entity("ServiceTemplate with name of the data flow model already exists!").build();
    }
    TDefinitions definitions = BackendUtils.createWrapperDefinitionsAndInitialEmptyElement(repo, templateId);
    TServiceTemplate serviceTemplate = definitions.getServiceTemplates().stream().filter(template -> template.getId().equals(templateId.getQName().getLocalPart()) && templateId.getQName().getNamespaceURI().equals(template.getTargetNamespace())).findFirst().orElse(null);
    if (Objects.isNull(serviceTemplate)) {
        return Response.serverError().entity("Unable to create ServiceTemplate for the given data flow model!").build();
    }
    TTopologyTemplate topology = serviceTemplate.getTopologyTemplate();
    if (Objects.isNull(topology)) {
        topology = new TTopologyTemplate.Builder().build();
    }
    // iterate over all filters of the data flow and create corresponding NodeTemplates
    for (DataFlowModel.Filter filter : dataFlowModel.getFilters()) {
        if (Objects.isNull(filter.getType())) {
            return Response.serverError().entity("Type is missing for a filter!").build();
        }
        NodeTypeId nodeTypeId = BackendUtils.getDefinitionsChildId(NodeTypeId.class, filter.getType());
        if (!repo.exists(nodeTypeId)) {
            TNodeType newNodeType = new TNodeType.Builder(nodeTypeId.getQName().getLocalPart()).setTargetNamespace(nodeTypeId.getQName().getNamespaceURI()).build();
            try {
                BackendUtils.persist(repo, nodeTypeId, newNodeType);
            } catch (IOException e) {
                return Response.serverError().entity("Unable to create NodeType " + filter.getType() + " which is not contained in the repository!").build();
            }
        }
        topology = handleFilter(topology, nodeTypeId, filter.getId(), filter.getProperties(), filter.getArtifacts(), filter.getLocation(), filter.getProvider());
        if (Objects.isNull(topology)) {
            return Response.serverError().entity("Unable to handle filter with name: " + filter.getId()).build();
        }
    }
    // without available connectsTo RelationshipType the transformation can not be done
    RelationshipTypeId relationTypeId = BackendUtils.getDefinitionsChildId(RelationshipTypeId.class, ToscaBaseTypes.connectsToRelationshipType);
    if (!repo.exists(relationTypeId)) {
        return Response.serverError().entity("Unable to parse data flow model without available connectsTo " + "RelationshipType!").build();
    }
    // create connectsTo RelationshipTemplates between NodeTemplates corresponding to connected filters
    for (DataFlowModel.Pipes pipe : dataFlowModel.getPipes()) {
        if (Objects.isNull(pipe.getSource()) || Objects.isNull(pipe.getTarget())) {
            return Response.serverError().entity("Unable to create RelationshipTemplate for pipe with source or " + "target equal to null!").build();
        }
        TNodeTemplate source = topology.getNodeTemplate(pipe.getSource());
        TNodeTemplate target = topology.getNodeTemplate(pipe.getTarget());
        if (Objects.isNull(source) || Objects.isNull(target)) {
            return Response.serverError().entity("Unable to find NodeTemplates for relation with source: " + pipe.getSource() + " and target: " + pipe.getTarget()).build();
        }
        TRelationshipTemplate relationshipTemplate = createRelationshipTemplate(relationTypeId, source, target, pipe.getDataTransferType());
        if (Objects.isNull(relationshipTemplate)) {
            return Response.serverError().entity("Unable to create RelationshipTemplate between " + source.getId() + " and " + target.getId()).build();
        }
        topology.addRelationshipTemplate(relationshipTemplate);
    }
    serviceTemplate.setTopologyTemplate(topology);
    try {
        BackendUtils.persist(repo, templateId, definitions);
        return Response.created(new URI(RestUtils.getAbsoluteURL(templateId))).build();
    } catch (IOException e) {
        return Response.serverError().entity("IOException while persisting ServiceTemplate for data flow model!").build();
    } catch (URISyntaxException e) {
        return Response.serverError().entity("Unable to parse URI for created ServiceTemplate!").build();
    }
}
Also used : RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DataFlowModel(org.eclipse.winery.repository.rest.resources.apiData.DataFlowModel) URI(java.net.URI) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IRepository(org.eclipse.winery.repository.backend.IRepository) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 34 with NodeTypeId

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

the class DataFlowResource method mergeTemplateForDataSource.

/**
 * Replace a filter corresponding to a running and placed data source by a ServiceTemplate with the same location
 * and provider tag which contains a NodeTemplate of the NodeType specified for the data source filter.
 */
private TTopologyTemplate mergeTemplateForDataSource(TTopologyTemplate topology, NodeTypeId nodeTypeId, String templateName, Map<String, String> properties, String location, String provider) {
    // get all ServiceTemplates in the repo
    IRepository repo = RepositoryFactory.getRepository();
    List<ServiceTemplateId> serviceTemplateIds = repo.getAllDefinitionsChildIds().stream().filter(id -> id.getGroup().equals(SERVICE_TEMPLATE_GROUP) && id instanceof ServiceTemplateId).map(id -> (ServiceTemplateId) id).collect(Collectors.toList());
    for (ServiceTemplateId id : serviceTemplateIds) {
        TServiceTemplate serviceTemplate = repo.getElement(id);
        // only ServiceTemplates with location and provider tags are possible substitution candidates
        if (containsMatchingTags(serviceTemplate, location, provider) && containsMatchingNodeType(serviceTemplate, nodeTypeId)) {
            LOGGER.debug("Found suited substitution candidate for filter {}: {}", templateName, id.getQName());
            TTopologyTemplate substitutionTopology = serviceTemplate.getTopologyTemplate();
            TNodeTemplate filterCorrespondingNode = null;
            LinkedHashMap<String, String> filterCorrespondingNodeProperties = null;
            Map<String, String> nameMap = new HashMap<>();
            if (substitutionTopology == null) {
                continue;
            }
            // insert all NodeTemplates from the substitution candidate
            for (TNodeTemplate node : substitutionTopology.getNodeTemplates()) {
                LinkedHashMap<String, String> propertyList = ModelUtilities.getPropertiesKV(node);
                if (propertyList == null) {
                    propertyList = new LinkedHashMap<>();
                }
                if (node.getType().equals(nodeTypeId.getQName())) {
                    // the NodeTemplate from the data flow model must be renamed to the given name
                    nameMap.put(node.getId(), templateName);
                    node.setId(templateName);
                    filterCorrespondingNode = node;
                    filterCorrespondingNodeProperties = propertyList;
                } else if (Objects.nonNull(topology.getNodeTemplate(node.getId()))) {
                    // all existing names must be changed too
                    while (Objects.nonNull(topology.getNodeTemplate(node.getId() + "-" + IdCounter))) {
                        IdCounter++;
                    }
                    nameMap.put(node.getId(), node.getId() + "-" + IdCounter);
                    node.setId(node.getId() + "-" + IdCounter);
                }
                // update properties of the NodeTemplate if they are set at the filter
                Map<String, String> propertyCopy = new HashMap<>(properties);
                for (String propertyName : propertyCopy.keySet()) {
                    if (propertyName != null && propertyList.containsKey(propertyName)) {
                        propertyList.put(propertyName, properties.get(propertyName));
                        properties.remove(propertyName);
                    }
                }
                // set the state of all components related to the data source to running
                propertyList.put("State", "Running");
                ModelUtilities.setPropertiesKV(node, propertyList);
                topology.addNodeTemplate(node);
            }
            // add all properties that are not defined in the NodeTypes to the node corresponding to the filter
            if (Objects.nonNull(filterCorrespondingNode)) {
                LOGGER.debug("{} properties defined without property at a matching type. Adding to filter " + "NodeTemplate!", properties.size());
                for (String propertyName : properties.keySet()) {
                    filterCorrespondingNodeProperties.put(propertyName, properties.get(propertyName));
                }
                ModelUtilities.setPropertiesKV(filterCorrespondingNode, filterCorrespondingNodeProperties);
                // add location and provider attribute to the NodeTemplate
                filterCorrespondingNode.getOtherAttributes().put(ModelUtilities.NODE_TEMPLATE_REGION, location);
                filterCorrespondingNode.getOtherAttributes().put(ModelUtilities.NODE_TEMPLATE_PROVIDER, provider);
            }
            // add all relations from the substitution fragment to the incomplete topology
            for (TRelationshipTemplate relation : substitutionTopology.getRelationshipTemplates()) {
                // update source id if it was changed
                String sourceId = relation.getSourceElement().getRef().getId();
                if (nameMap.containsKey(sourceId)) {
                    TNodeTemplate nodeTemplate = topology.getNodeTemplate(nameMap.get(sourceId));
                    if (nodeTemplate != null) {
                        relation.setSourceNodeTemplate(nodeTemplate);
                    }
                }
                // update target id if it was changed
                if (nameMap.containsKey(relation.getTargetElement().getRef().getId())) {
                    relation.setTargetNodeTemplate(topology.getNodeTemplate(nameMap.get(relation.getTargetElement().getRef().getId())));
                }
                // update id if RelationshipTemplate with same id exists
                if (Objects.nonNull(topology.getRelationshipTemplate(relation.getId()))) {
                    while (Objects.nonNull(topology.getRelationshipTemplate(relation.getId() + "-" + IdCounter))) {
                        IdCounter++;
                    }
                    relation.setId(relation.getId() + "-" + IdCounter);
                }
                topology.addRelationshipTemplate(relation);
            }
            return topology;
        }
    }
    // no substitution of data source possible
    return null;
}
Also used : URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) TRequirement(org.eclipse.winery.model.tosca.TRequirement) URI(java.net.URI) TAG_NAME_PROVIDER(org.eclipse.winery.model.adaptation.placement.Constants.TAG_NAME_PROVIDER) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) RELATIONSHIP_TEMPLATE_TRANSFER_TYPE_PULL(org.eclipse.winery.model.adaptation.placement.Constants.RELATIONSHIP_TEMPLATE_TRANSFER_TYPE_PULL) TNodeType(org.eclipse.winery.model.tosca.TNodeType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) 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) Response(javax.ws.rs.core.Response) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) QName(javax.xml.namespace.QName) ToscaBaseTypes(org.eclipse.winery.model.tosca.constants.ToscaBaseTypes) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) LinkedHashMap(java.util.LinkedHashMap) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) SERVICE_TEMPLATE_GROUP(org.eclipse.winery.model.adaptation.placement.Constants.SERVICE_TEMPLATE_GROUP) IOException(java.io.IOException) TTag(org.eclipse.winery.model.tosca.TTag) TAG_NAME_LOCATION(org.eclipse.winery.model.adaptation.placement.Constants.TAG_NAME_LOCATION) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) DataFlowModel(org.eclipse.winery.repository.rest.resources.apiData.DataFlowModel) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) ARTIFACT_TEMPLATE_GROUP(org.eclipse.winery.model.adaptation.placement.Constants.ARTIFACT_TEMPLATE_GROUP) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DATA_TRANSFER_TYPE_PULL(org.eclipse.winery.model.adaptation.placement.Constants.DATA_TRANSFER_TYPE_PULL) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 35 with NodeTypeId

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

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
    // add all implementations
    Collection<DefinitionsChildId> ids = new ArrayList<>(this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName()));
    final TRelationshipType relationshipType = this.getElement(id);
    TRelationshipType.ValidSource validSource = relationshipType.getValidSource();
    if (validSource != null) {
        QName typeRef = validSource.getTypeRef();
        // can be a node type or a requirement type
        // similar code as for valid target (difference: req/cap)
        NodeTypeId ntId = new NodeTypeId(typeRef);
        if (this.exists(ntId)) {
            ids.add(ntId);
        } else {
            RequirementTypeId rtId = new RequirementTypeId(typeRef);
            ids.add(rtId);
        }
    }
    TRelationshipType.ValidTarget validTarget = relationshipType.getValidTarget();
    if (validTarget != null) {
        QName typeRef = validTarget.getTypeRef();
        // can be a node type or a capability type
        // similar code as for valid target (difference: req/cap)
        NodeTypeId ntId = new NodeTypeId(typeRef);
        if (this.exists(ntId)) {
            ids.add(ntId);
        } else {
            CapabilityTypeId capId = new CapabilityTypeId(typeRef);
            ids.add(capId);
        }
    }
    List<QName> validTargetList = relationshipType.getValidTargetList();
    if (validTargetList != null) {
        for (QName typeRef : validTargetList) {
            CapabilityTypeId capId = new CapabilityTypeId(typeRef);
            if (this.exists(capId)) {
                ids.add(capId);
            }
        }
    }
    getReferencedDefinitionsOfProperties(ids, relationshipType.getProperties());
    return ids;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ArrayList(java.util.ArrayList) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)

Aggregations

NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)67 TNodeType (org.eclipse.winery.model.tosca.TNodeType)36 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 Test (org.junit.jupiter.api.Test)27 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)23 QName (javax.xml.namespace.QName)21 IRepository (org.eclipse.winery.repository.backend.IRepository)20 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)15 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)15 WineryVersion (org.eclipse.winery.common.version.WineryVersion)14 Response (javax.ws.rs.core.Response)13 IOException (java.io.IOException)12 LinkedHashMap (java.util.LinkedHashMap)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)11 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)10 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)10 ArrayList (java.util.ArrayList)9 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)9