diff options
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services')
2 files changed, 41 insertions, 5 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/TogglzFeatures.java b/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/TogglzFeatures.java index 9a1fde3d9c..6158421246 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/TogglzFeatures.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/TogglzFeatures.java @@ -18,20 +18,23 @@ package org.openecomp.sdcrests.togglz.rest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.openecomp.sdcrests.common.RestConstants; +import org.openecomp.sdcrests.togglz.types.FeatureDto; import org.openecomp.sdcrests.togglz.types.FeatureSetDto; import org.springframework.validation.annotation.Validated; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; + @Path("/v1.0/togglz") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) -@Api(value = "TOGGLZ") @Validated public interface TogglzFeatures { @@ -41,4 +44,15 @@ public interface TogglzFeatures { responseContainer = "List") Response getFeatures(); + + @PUT + @Path("/{featureName}/state/{state}") + @ApiOperation(value = "Update feature toggle state") + Response setFeatureState(@PathParam("featureName") String featureName, @PathParam("state") boolean state); + + @GET + @Path("/{featureName}/state") + @ApiOperation(value = "Get feature toggle state", + response = FeatureDto.class) + Response getFeatureState(@PathParam("featureName") String featureName); } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/services/TogglzFeaturesImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/services/TogglzFeaturesImpl.java index 5b7240be54..fd1c4dbd0c 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/services/TogglzFeaturesImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/togglz-rest/togglz-rest-services/src/main/java/org/openecomp/sdcrests/togglz/rest/services/TogglzFeaturesImpl.java @@ -19,9 +19,14 @@ package org.openecomp.sdcrests.togglz.rest.services; import org.openecomp.sdc.common.togglz.ToggleableFeature; import org.openecomp.sdcrests.togglz.rest.TogglzFeatures; import org.openecomp.sdcrests.togglz.rest.mapping.MapToggleableFeatureToDto; +import org.openecomp.sdcrests.togglz.types.FeatureDto; import org.openecomp.sdcrests.togglz.types.FeatureSetDto; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; +import org.togglz.core.Feature; +import org.togglz.core.context.FeatureContext; +import org.togglz.core.repository.FeatureState; +import org.togglz.core.util.NamedFeature; import javax.inject.Named; import javax.ws.rs.core.Response; @@ -38,5 +43,22 @@ public class TogglzFeaturesImpl implements TogglzFeatures { new MapToggleableFeatureToDto().doMapping(Arrays.asList(ToggleableFeature.values()), featureSetDto); return Response.ok(featureSetDto).build(); } + + @Override + public Response setFeatureState(String featureName, boolean state) { + Feature feature = new NamedFeature(featureName); + FeatureState featureState = new FeatureState(feature,state); + FeatureContext.getFeatureManager().setFeatureState(featureState); + return Response.ok().build(); + } + + @Override + public Response getFeatureState(String featureName) { + boolean active = ToggleableFeature.valueOf(featureName).isActive(); + FeatureDto featureDto = new FeatureDto(featureName,active); + + return Response.ok(featureDto).build(); + } + } |