Search in sources :

Example 1 with DeploymentTechnologyDescriptor

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

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

the class TopologyTemplateResource method getAvailableFeatures.

@GET
@Path("availablefeatures")
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<AvailableFeaturesApiData> getAvailableFeatures() {
    ArrayList<AvailableFeaturesApiData> apiData = new ArrayList<>();
    List<DeploymentTechnologyDescriptor> deploymentTechnologies = Collections.emptyList();
    if (this.parent.getElement() instanceof HasTags && ((HasTags) this.parent.getElement()).getTags() != null) {
        ObjectMapper objectMapper = new ObjectMapper();
        deploymentTechnologies = ModelUtilities.extractDeploymentTechnologiesFromTags(((HasTags) this.parent.getElement()).getTags(), objectMapper);
    }
    EnhancementUtils.getAvailableFeaturesForTopology(this.topologyTemplate, deploymentTechnologies).forEach((nodeTemplateId, featuresMap) -> {
        ArrayList<AvailableFeaturesApiData.Features> features = new ArrayList<>();
        featuresMap.forEach((featureType, featureName) -> features.add(new AvailableFeaturesApiData.Features(featureType, featureName)));
        apiData.add(new AvailableFeaturesApiData(nodeTemplateId, features));
    });
    return apiData;
}
Also used : AvailableFeaturesApiData(org.eclipse.winery.repository.rest.resources.apiData.AvailableFeaturesApiData) HasTags(org.eclipse.winery.model.tosca.HasTags) DeploymentTechnologyDescriptor(org.eclipse.winery.model.tosca.DeploymentTechnologyDescriptor) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with DeploymentTechnologyDescriptor

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

the class EnhancementUtilsTestWithGitBackedRepository method getAvailableFeaturesFilteredByDeploymentTechnology.

@Test
void getAvailableFeaturesFilteredByDeploymentTechnology() throws Exception {
    this.setRevisionTo("origin/plain");
    TServiceTemplate serviceTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(// the resource.
    QName.valueOf("{http://opentosca.org/add/management/to/instances/servicetemplates}STWithBasicManagementOnly_noDeplTech-w1-wip1")));
    DeploymentTechnologyDescriptor deploymentTechnologyDescriptor = new DeploymentTechnologyDescriptor();
    deploymentTechnologyDescriptor.setId("OpenStackHeat");
    deploymentTechnologyDescriptor.setTechnologyId("OpenStackHeat");
    deploymentTechnologyDescriptor.setManagedIds(Collections.singletonList("NodeTypeWithDifferentFeatures_w1-wip1_0"));
    deploymentTechnologyDescriptor.setProperties(Collections.emptyMap());
    Map<String, Map<QName, String>> openStackFeatures = EnhancementUtils.getAvailableFeaturesForTopology(serviceTemplate.getTopologyTemplate(), Collections.singletonList(deploymentTechnologyDescriptor));
    assertEquals(1, openStackFeatures.size());
    Map<QName, String> openStackFeature = openStackFeatures.get("NodeTypeWithDifferentFeatures_w1-wip1_0");
    assertEquals(2, openStackFeature.size());
    assertEquals("scalable AWS and Heat", openStackFeature.get(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes}ScaleFeature_AWS-OpenStack-w1-wip1")));
    assertEquals("ping", openStackFeature.get(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes}TechIndependentFeature_w1-wip1")));
    deploymentTechnologyDescriptor.setTechnologyId("Kubernetes");
    Map<String, Map<QName, String>> kubernetesFeatures = EnhancementUtils.getAvailableFeaturesForTopology(serviceTemplate.getTopologyTemplate(), Collections.singletonList(deploymentTechnologyDescriptor));
    assertEquals(1, kubernetesFeatures.size());
    Map<QName, String> kubernetesFeature = kubernetesFeatures.get("NodeTypeWithDifferentFeatures_w1-wip1_0");
    assertEquals(2, kubernetesFeature.size());
    assertEquals("scalable Kubernetes", kubernetesFeature.get(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes}ScaleFeature_Kubernetes-w1-wip1")));
    assertEquals("ping", kubernetesFeature.get(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes}TechIndependentFeature_w1-wip1")));
    deploymentTechnologyDescriptor.setTechnologyId("Chef");
    Map<String, Map<QName, String>> chefFeatures = EnhancementUtils.getAvailableFeaturesForTopology(serviceTemplate.getTopologyTemplate(), Collections.singletonList(deploymentTechnologyDescriptor));
    assertEquals(1, chefFeatures.size());
    Map<QName, String> chefFeature = chefFeatures.get("NodeTypeWithDifferentFeatures_w1-wip1_0");
    assertEquals(1, chefFeature.size());
    assertEquals("ping", chefFeature.get(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes}TechIndependentFeature_w1-wip1")));
}
Also used : DeploymentTechnologyDescriptor(org.eclipse.winery.model.tosca.DeploymentTechnologyDescriptor) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) HashMap(java.util.HashMap) Map(java.util.Map) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentTechnologyDescriptor (org.eclipse.winery.model.tosca.DeploymentTechnologyDescriptor)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ListUtils.listIsNotNullOrEmpty (org.eclipse.winery.common.ListUtils.listIsNotNullOrEmpty)1 VersionUtils (org.eclipse.winery.common.version.VersionUtils)1 WineryVersion (org.eclipse.winery.common.version.WineryVersion)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)1