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;
}
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;
}
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")));
}
Aggregations