X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fswitchmanager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Fnorthbound%2FSwitchNorthbound.java;h=d88f9efa66ba66efc90fd8f3066cab26add96ccf;hb=51e9be2b3aac6ea33bf21e5a3a978325d24e9e0e;hp=98aa5ad94e06c713dcd02fe7a71141ec02b46782;hpb=5e20076e352bae1f6b0bd0f8ac8f7c85235e4b27;p=controller.git diff --git a/opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthbound.java b/opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthbound.java index 98aa5ad94e..d88f9efa66 100644 --- a/opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthbound.java +++ b/opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthbound.java @@ -27,6 +27,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; @@ -62,7 +63,9 @@ public class SwitchNorthbound { @Context public void setSecurityContext(SecurityContext context) { - username = context.getUserPrincipal().getName(); + if (context != null && context.getUserPrincipal() != null) { + username = context.getUserPrincipal().getName(); + } } protected String getUserName() { @@ -118,12 +121,16 @@ public class SwitchNorthbound { * Example: * * RequestURL: - * http://.../default/nodes + * http://localhost:8080/controller/nb/v2/switchmanager/default/nodes * * Response in XML: + * <?xml version="1.0" encoding="UTF-8" standalone="yes"?> * <list> * <nodeProperties> - * <node type="OF" id="00:00:00:00:00:00:00:02"/> + * <node> + * <id>00:00:00:00:00:00:00:02</id> + * <type>OF</type> + * </node> * <properties> * <tables> * <value>-1</value> @@ -152,7 +159,7 @@ public class SwitchNorthbound { * </list> * * Response in JSON: - * {"nodeProperties":[{"node":{"@type":"OF","@id":"00:00:00:00:00:00:00:02"},"properties":{"tables":{"value":"-1"}, + * {"nodeProperties":[{"node":{"id":"00:00:00:00:00:00:00:02","type":"OF"},"properties":{"tables":{"value":"-1"}, * "description":{"value":"None"},"actions":{"value":"4095"},"macAddress":{"value":"00:00:00:00:00:02"},"capabilities" * :{"value":"199"},"timeStamp":{"value":"1377291227877","name":"connectedSince"},"buffers":{"value":"256"}}}]} * @@ -189,7 +196,7 @@ public class SwitchNorthbound { List res = new ArrayList(); Set nodes = switchManager.getNodes(); if (nodes == null) { - return null; + return new Nodes(res); } for (Node node : nodes) { @@ -207,7 +214,9 @@ public class SwitchNorthbound { } /** - * Add a Description, Tier and Forwarding mode property to a node. + * Add a Description, Tier and Forwarding mode property to a node. This + * method returns a non-successful response if a node by that name already + * exists. * * @param containerName * Name of the Container (Eg. 'default') @@ -215,24 +224,24 @@ public class SwitchNorthbound { * Type of the node being programmed (Eg. 'OF') * @param nodeId * Node Identifier as specified by - * {@link org.opendaylight.controller.sal.core.Node} - * (Eg. '00:00:00:00:00:00:00:03') + * {@link org.opendaylight.controller.sal.core.Node} (Eg. + * '00:00:00:00:00:00:00:03') * @param propertyName - * Name of the Property. Properties that can be - * configured are: description, forwarding(only for default - * container) and tier + * Name of the Property. Properties that can be configured are: + * description, forwarding(only for default container) and tier * @param propertyValue - * Value of the Property. Description can be any string (Eg. 'Node1'), - * valid values for tier are 0, 1 and 2, and valid values for forwarding are 0 for - * reactive and 1 for proactive forwarding. + * Value of the Property. Description can be any string (Eg. + * 'Node1'), valid values for tier are non negative numbers, and + * valid values for forwarding are 0 for reactive and 1 for + * proactive forwarding. * @return Response as dictated by the HTTP Response Status code * - *
+     *         
      *
      * Example:
      *
      * RequestURL:
-     * http://.../default/node/OF/00:00:00:00:00:00:00:03/property/description/Switch3
+     * http://localhost:8080/controller/nb/v2/switchmanager/default/node/OF/00:00:00:00:00:00:00:03/property/description/Switch3
      *
      * 
*/ @@ -250,6 +259,7 @@ public class SwitchNorthbound { @ResponseCode(code = 409, condition = "Unable to update configuration due to cluster conflict or conflicting description property"), @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") }) public Response addNodeProperty( + @Context UriInfo uriInfo, @PathParam("containerName") String containerName, @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId, @@ -284,7 +294,7 @@ public class SwitchNorthbound { SwitchConfig newSwitchConfig = new SwitchConfig(node.toString(), nodeProperties); Status status = switchManager.updateNodeConfig(newSwitchConfig); if (status.isSuccess()) { - return Response.status(Response.Status.CREATED).build(); + return Response.created(uriInfo.getRequestUri()).build(); } return NorthboundUtils.getResponse(status); } @@ -310,7 +320,7 @@ public class SwitchNorthbound { * Example: * * RequestURL: - * http://.../default/node/OF/00:00:00:00:00:00:00:03/property/forwarding + * http://localhost:8080/controller/nb/v2/switchmanager/default/node/OF/00:00:00:00:00:00:00:03/property/forwarding * *
*/ @@ -319,7 +329,7 @@ public class SwitchNorthbound { @DELETE @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({ - @ResponseCode(code = 200, condition = "Operation successful"), + @ResponseCode(code = 204, condition = "Property removed successfully"), @ResponseCode(code = 400, condition = "The nodeId or configuration is invalid"), @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"), @@ -363,7 +373,8 @@ public class SwitchNorthbound { SwitchConfig newSwitchConfig = new SwitchConfig(node.toString(), nodeProperties); status = switchManager.updateNodeConfig(newSwitchConfig); if(status.isSuccess()){ - NorthboundUtils.auditlog("Static Route", username, "updated", nodeId, containerName); + NorthboundUtils.auditlog("Node Property", username, "removed", propertyName + " from " + nodeId, containerName); + return Response.noContent().build(); } } } @@ -372,8 +383,8 @@ public class SwitchNorthbound { /** * - * Retrieve a list of all the nodeconnectors and their properties in a - * given node + * Retrieve a list of all the nodeconnectors and their properties in a given + * node * * @param containerName * The container for which we want to retrieve the list (Eg. @@ -395,13 +406,19 @@ public class SwitchNorthbound { * Example: * * RequestURL: - * http://.../default/node/OF/00:00:00:00:00:00:00:01 + * http://localhost:8080/controller/nb/v2/switchmanager/default/node/OF/00:00:00:00:00:00:00:01 * * Response in XML: + * <?xml version="1.0" encoding="UTF-8" standalone="yes"?> * <list> * <nodeConnectorProperties> - * <nodeconnector type="OF" id="2"> - * <node type="OF" id="00:00:00:00:00:00:00:01"/> + * <nodeconnector> + * <node> + * <id>00:00:00:00:00:00:00:01</id> + * <type>OF</type> + * </node> + * <id>2</id> + * <type>OF</type> * </nodeconnector> * <properties> * <state> @@ -418,7 +435,7 @@ public class SwitchNorthbound { * </list> * * Response in JSON: - * {"nodeConnectorProperties":[{"nodeconnector":{"@type":"OF","@id":"2","node":{"@type":"OF","@id":"00:00:00:00:00:00:00:01"}}, + * {"nodeConnectorProperties":[{"nodeconnector":{"node":{"id":"00:00:00:00:00:00:00:01","type":"OF"},"id":"2","type":"OF"}, * "properties":{"state":{"value":"1"},"config":{"value":"1"},"name":{"value":"L1_2-C2_1"}}}]} * * @@ -477,7 +494,9 @@ public class SwitchNorthbound { } /** - * Add Bandwidth property to a node connector + * Add node-connector property to a node connector. This method returns a + * non-successful response if a node connector by the given name already + * exists. * * @param containerName * Name of the Container (Eg. 'default') @@ -509,7 +528,7 @@ public class SwitchNorthbound { * Example: * * RequestURL: - * http://.../default/nodeconnector/OF/00:00:00:00:00:00:00:01/OF/2/property/bandwidth/1 + * http://localhost:8080/controller/nb/v2/switchmanager/default/nodeconnector/OF/00:00:00:00:00:00:00:01/OF/2/property/bandwidth/1 * * */ @@ -524,6 +543,7 @@ public class SwitchNorthbound { @ResponseCode(code = 409, condition = "Unable to add property due to cluster conflict"), @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") }) public Response addNodeConnectorProperty( + @Context UriInfo uriInfo, @PathParam("containerName") String containerName, @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId, @@ -564,7 +584,7 @@ public class SwitchNorthbound { Status ret = switchManager.addNodeConnectorProp(nc, prop); if (ret.isSuccess()) { - return Response.status(Response.Status.CREATED).build(); + return Response.created(uriInfo.getRequestUri()).build(); } throw new InternalServerErrorException(ret.getDescription()); } @@ -597,7 +617,7 @@ public class SwitchNorthbound { * Example: * * RequestURL: - * http://.../default/nodeconnector/OF/00:00:00:00:00:00:00:01/OF/2/property/bandwidth + * http://localhost:8080/controller/nb/v2/switchmanager/default/nodeconnector/OF/00:00:00:00:00:00:00:01/OF/2/property/bandwidth * * */ @@ -606,7 +626,7 @@ public class SwitchNorthbound { @DELETE @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({ - @ResponseCode(code = 200, condition = "Operation successful"), + @ResponseCode(code = 204, condition = "Property removed successfully"), @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"), @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") }) @@ -644,7 +664,7 @@ public class SwitchNorthbound { Status ret = switchManager.removeNodeConnectorProp(nc, propertyName); if (ret.isSuccess()) { NorthboundUtils.auditlog("Node Connector Property", username, "removed", nc + " from " + nodeConnectorId, containerName); - return Response.ok().build(); + return Response.noContent().build(); } throw new ResourceNotFoundException(ret.getDescription()); } @@ -661,11 +681,11 @@ public class SwitchNorthbound { * Example: * * RequestURL: - * http://.../default/switch-config + * http://localhost:8080/controller/nb/v2/switchmanager/default/save * * */ - @Path("/{containerName}/switch-config") + @Path("/{containerName}/save") @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({