private SupportedAdditionalClusterFeature buildSupportedFeature(Guid featureId, Guid clusterId, boolean enabled) { SupportedAdditionalClusterFeature supportedAdditionalClusterFeature = new SupportedAdditionalClusterFeature(); supportedAdditionalClusterFeature.setClusterId(clusterId); supportedAdditionalClusterFeature.setEnabled(enabled); supportedAdditionalClusterFeature.setFeature(new AdditionalFeature()); supportedAdditionalClusterFeature.getFeature().setId(featureId); return supportedAdditionalClusterFeature; }
public static SupportedAdditionalClusterFeature getEnabledFeature(BackendResource resource, Guid clusterId, Guid id) { Set<SupportedAdditionalClusterFeature> addlFeatures = resource.getOptionalEntity(Set.class, QueryType.GetClusterFeaturesByClusterId, new IdQueryParameters(clusterId), clusterId.toString(), false); SupportedAdditionalClusterFeature feature = Optional.ofNullable(addlFeatures) .orElse(Collections.emptySet()) .stream() .filter(f -> f.getFeature().getId().equals(id) && f.isEnabled()) .findFirst() .orElse(null); return feature; }
@Override protected MapSqlParameterSource createFullParametersMapper(SupportedAdditionalClusterFeature entity) { return getCustomMapSqlParameterSource() .addValue("cluster_id", entity.getClusterId()) .addValue("feature_id", entity.getFeature().getId()) .addValue("is_enabled", entity.isEnabled()); }
@Override public Pair<Guid, Guid> getId() { return new Pair<>(getFeature().getId(), getClusterId()); }
@Override public void setId(Pair<Guid, Guid> id) { getFeature().setId(id.getFirst()); setClusterId(id.getSecond()); } }
public static Cluster getClusterWithFeatureDisabled(BackendResource resource, Guid clusterId, Guid id) { Cluster cluster = getClusterEntity(resource, clusterId); SupportedAdditionalClusterFeature feature = cluster.getAddtionalFeaturesSupported() .stream() .filter(f -> f.getFeature().getId().equals(id)) .findFirst() .orElse(null); if (feature != null) { feature.setEnabled(false); } return cluster; }
@Override public AdditionalFeature lookupEntity(Guid id) throws BackendFailureException { SupportedAdditionalClusterFeature supportedFeature = BackendClusterFeatureHelper .getEnabledFeature(BackendClusterEnabledFeaturesResource.this, clusterId, featureId); if (supportedFeature != null) { return supportedFeature.getFeature(); } else { return null; } } }
public SupportedAdditionalClusterFeature(Guid clusterId, boolean enabled, AdditionalFeature feature) { this.clusterId = clusterId; this.setEnabled(enabled); this.feature = feature; }
cluster.setGlusterService(model.getEnableGlusterService().getEntity()); for (AdditionalFeature feature : model.getAdditionalClusterFeatures().getSelectedItem()) { cluster.getAddtionalFeaturesSupported().add(new SupportedAdditionalClusterFeature(cluster.getId(), true, feature));
@Override public ClusterFeature get() { SupportedAdditionalClusterFeature feature = BackendClusterFeatureHelper.getEnabledFeature(this, clusterId, guid); if (feature != null) { return addLinks(ClusterFeaturesMapper.map(feature.getFeature(), null)); } else { throw new WebApplicationException(Response.Status.NOT_FOUND); } }
@Test public void testUpdateSupportedClusterFeature() { Set<SupportedAdditionalClusterFeature> features = dao.getAllByClusterId(EXISTING_CLUSTER); // Lets stop after testing the first feature. features.stream().findFirst().ifPresent(feature -> { feature.setEnabled(false); dao.update(feature); }); Set<SupportedAdditionalClusterFeature> newFeatureSet = dao.getAllByClusterId(EXISTING_CLUSTER); assertEquals(new HashSet<>(features), newFeatureSet, "Failed to update the feature set"); } }
@Override public Response add(ClusterFeature feature) { validateParameters(feature); org.ovirt.engine.core.common.businessentities.AdditionalFeature featureEntity = map(feature, null); org.ovirt.engine.core.common.businessentities.Cluster cluster = BackendClusterFeatureHelper.getClusterEntity(this, clusterId); SupportedAdditionalClusterFeature supportedFeature = new SupportedAdditionalClusterFeature(); supportedFeature.setFeature(featureEntity); supportedFeature.setEnabled(true); supportedFeature.setClusterId(clusterId); cluster.getAddtionalFeaturesSupported().add(supportedFeature); ManagementNetworkOnClusterOperationParameters param = new ManagementNetworkOnClusterOperationParameters(cluster); return performCreate(ActionType.UpdateCluster, param, new ClusterFeatureIdResolver(clusterId, featureEntity.getId())); }
@Override public ClusterFeatures list() { ClusterFeatures features = new ClusterFeatures(); Set<SupportedAdditionalClusterFeature> addlFeatures = getOptionalEntity(Set.class, QueryType.GetClusterFeaturesByClusterId, new IdQueryParameters(clusterId), clusterId.toString(), false); if (addlFeatures != null) { for (SupportedAdditionalClusterFeature entity : addlFeatures) { if (entity.isEnabled()) { features.getClusterFeatures().add(addLinks(map(entity.getFeature(), null))); } } } return features; }
@Override public String toString() { return ToStringBuilder.forInstance(this) .append("feature", getFeature()) .append("clusterId", getClusterId()) .append("enabled", isEnabled()) .build(); }
@Test public void testGetAllByClusterId() { Set<SupportedAdditionalClusterFeature> featuresSupportedInCluster = dao.getAllByClusterId(EXISTING_CLUSTER); List<String> expectedFeatures = Arrays.asList("TEST_FEATURE_1", "TEST_FEATURE_2", "TEST_FEATURE_3"); assertNotNull(featuresSupportedInCluster, "Failed to retrive supported additional features for the cluster"); assertThat("Failed to retrive correct set of features for the given version and category", featuresSupportedInCluster, hasSize(expectedFeatures.size())); for (SupportedAdditionalClusterFeature supportedFeatures : featuresSupportedInCluster) { assertThat("Wrong feature returned from DB", expectedFeatures, hasItem(supportedFeatures.getFeature().getName())); } }
Set<AdditionalFeature> featuresEnabled = new HashSet<>(); for (SupportedAdditionalClusterFeature feature : clusterFeatures) { if (feature.isEnabled()) { featuresEnabled.add(feature.getFeature());