Search in sources :

Example 6 with TRequirementDefinition

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

Aggregations

TRequirementDefinition (org.eclipse.winery.model.tosca.TRequirementDefinition)6 TNodeType (org.eclipse.winery.model.tosca.TNodeType)4 QName (javax.xml.namespace.QName)3 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)3 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)3 TCapabilityDefinition (org.eclipse.winery.model.tosca.TCapabilityDefinition)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)2 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)2