From e721fb73176218c4ddf07f3e12e1058e3662cf29 Mon Sep 17 00:00:00 2001 From: Prasanth Pallamreddy Date: Thu, 16 Jan 2014 19:57:56 -0800 Subject: [PATCH] Add NB capability to save configuration Change-Id: If8d567aa8c95e39e2618ff2916ce707232d8a20b Signed-off-by: Prasanth Pallamreddy --- .../northbound/controllermanager/pom.xml | 1 + .../ControllerManagerNorthbound.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/opendaylight/northbound/controllermanager/pom.xml b/opendaylight/northbound/controllermanager/pom.xml index 8c3279e6c7..5baaeb0dcc 100644 --- a/opendaylight/northbound/controllermanager/pom.xml +++ b/opendaylight/northbound/controllermanager/pom.xml @@ -43,6 +43,7 @@ org.opendaylight.controller.sal.core, org.opendaylight.controller.sal.utils, + org.opendaylight.controller.configuration, org.opendaylight.controller.containermanager, org.opendaylight.controller.switchmanager, org.opendaylight.controller.usermanager, diff --git a/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java b/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java index c515396212..003f8b3b95 100644 --- a/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java +++ b/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java @@ -29,6 +29,7 @@ import javax.ws.rs.core.UriInfo; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; import org.codehaus.enunciate.jaxrs.TypeHint; +import org.opendaylight.controller.configuration.IConfigurationService; import org.opendaylight.controller.containermanager.IContainerManager; import org.opendaylight.controller.northbound.commons.RestMessages; import org.opendaylight.controller.northbound.commons.exception.BadRequestException; @@ -254,6 +255,44 @@ public class ControllerManagerNorthbound { return NorthboundUtils.getResponse(status); } + /** + * Save controller configuration + * + * Request URL: + * http://localhost:8080/controller/nb/v2/controllermanager/configuration + * + * Request body is empty + */ + @Path("/configuration") + @PUT + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @StatusCodes({ + @ResponseCode(code = 204, condition = "Operation successful"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), + @ResponseCode(code = 503, condition = "Configuration service is unavailable.") + }) + public Response saveConfiguration() { + + if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) { + throw new UnauthorizedException("User is not authorized to perform this operation"); + } + + IConfigurationService configService = (IConfigurationService) + ServiceHelper.getGlobalInstance(IConfigurationService.class, this); + + if (configService == null) { + throw new ServiceUnavailableException("Configuration Service " + + RestMessages.SERVICEUNAVAILABLE.toString()); + } + Status status = configService.saveConfigurations(); + if (status.isSuccess()) { + NorthboundUtils.auditlog("Controller Configuration", username, + "save", "configuration"); + return Response.noContent().build(); + } + return NorthboundUtils.getResponse(status); + } + private boolean isValidContainer(String containerName) { if (containerName.equals(GlobalConstants.DEFAULT.toString())) { return true; -- 2.36.6