X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnorthbound%2Fsubnets%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsubnets%2Fnorthbound%2FSubnetsNorthbound.java;h=18d8e531143f66aceb1ab93b6f535112432175f3;hb=51e9be2b3aac6ea33bf21e5a3a978325d24e9e0e;hp=27650722460086fc227fb367ee1407026ddcf2d8;hpb=674ec80fc65bf6e1d389d2b9f4c302bc214dcfb3;p=controller.git
diff --git a/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java b/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java
index 2765072246..18d8e53114 100644
--- a/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java
+++ b/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java
@@ -7,10 +7,7 @@
*/
package org.opendaylight.controller.subnets.northbound;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -23,7 +20,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.xml.bind.JAXBElement;
+import javax.ws.rs.core.UriInfo;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
@@ -31,7 +28,6 @@ import org.codehaus.enunciate.jaxrs.TypeHint;
import org.opendaylight.controller.containermanager.IContainerManager;
import org.opendaylight.controller.northbound.commons.RestMessages;
import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
-import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;
import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException;
import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
@@ -45,6 +41,19 @@ import org.opendaylight.controller.switchmanager.SubnetConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * This class provides REST APIs to manage subnets.
+ *
+ *
+ *
+ * Authentication scheme : HTTP Basic
+ * Authentication realm : opendaylight
+ * Transport : HTTP and HTTPS
+ *
+ * HTTPS Authentication is disabled by default.
+ *
+ */
+
@Path("/")
public class SubnetsNorthbound {
protected static final Logger logger = LoggerFactory.getLogger(SubnetsNorthbound.class);
@@ -53,7 +62,9 @@ public class SubnetsNorthbound {
@Context
public void setSecurityContext(SecurityContext context) {
- username = context.getUserPrincipal().getName();
+ if (context != null && context.getUserPrincipal() != null) {
+ username = context.getUserPrincipal().getName();
+ }
}
protected String getUserName() {
@@ -100,38 +111,33 @@ public class SubnetsNorthbound {
*
* Example: * - * Request URL: http://localhost:8080/controller/nb/v2/subnet/default/subnet/all + * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnets * * Response in XML: * <subnetConfig> - * <name>subnet1</name> - * <subnet>30.0.0.1/24</subnet> - * <nodePorts>1/1>/nodePorts> - * <nodePorts>1/2>/nodePorts> - * <nodePorts>1/3>/nodePorts> + * <name>marketingdepartment</name> + * <subnet>30.31.54.254/24</subnet> * </subnetConfig> * <subnetConfig> - * <name>subnet2</name> - * <subnet>20.0.0.1/24</subnet> - * <nodePorts>2/1>/nodePorts> - * <nodePorts>2/2>/nodePorts> - * <nodePorts>2/3>/nodePorts> + * <name>salesdepartment</name> + * <subnet>20.18.1.254/16</subnet> + * <nodeConnectors>0F|11@OF|00:00:00:aa:bb:cc:dd:ee>/nodeConnectors> + * <nodeConnectors>0F|13@OF|00:00:00:aa:bb:cc:dd:ee>/nodeConnectors> * </subnetConfig> * * Response in JSON: * { - * "name":"subnet1", - * "subnet":"30.0.0.1/24", - * "nodePorts":["1/1","1/2","1/3"] + * "name":"marketingdepartment", + * "subnet":"30.31.54.254/24", * } * { - * "name":"subnet2", - * "subnet":"20.0.0.1/24", - * "nodePorts":["2/1","2/2","2/3"] + * "name":"salesdepartment", + * "subnet":"20.18.1.254/16", + * "nodeConnectors":["0F|11@OF|00:00:00:aa:bb:cc:dd:ee", "0F|13@OF|00:00:00:aa:bb:cc:dd:ee"] * } **/ - @Path("/{containerName}/subnet/all") + @Path("/{containerName}/subnets") @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @@ -165,22 +171,21 @@ public class SubnetsNorthbound { *
* Example: * - * Request URL: http://localhost:8080/controller/nb/v2/subnet/default/subnet/subnet1 + * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/marketingdepartment * * Response in XML: * <subnetConfig> - * <name>subnet1</name> + * <name>marketingdepartment</name> * <subnet>30.0.0.1/24</subnet> - * <nodePorts>1/1>/nodePorts> - * <nodePorts>1/2>/nodePorts> - * <nodePorts>1/3>/nodePorts> + * <nodeConnectors>0F|1@OF|00:00:11:22:33:44:55:66>/nodePorts> + * <nodeConnectors>0F|3@OF|00:00:11:22:33:44:55:66>/nodePorts> * </subnetConfig> * * Response in JSON: * { - * "name":"subnet1", + * "name":"marketingdepartment", * "subnet":"30.0.0.1/24", - * "nodePorts":["1/1","1/2","1/3"] + * "nodeConnectors":["0F|1@OF|00:00:11:22:33:44:55:66", "0F|3@OF|00:00:11:22:33:44:55:66"] * } **/ @@ -207,16 +212,15 @@ public class SubnetsNorthbound { SubnetConfig res = switchManager.getSubnetConfig(subnetName); if (res == null) { throw new ResourceNotFoundException(RestMessages.NOSUBNET.toString()); - } else { - return res; } + return res; } /** - * Add a subnet to a container + * Add a subnet into the specified container context, node connectors are optional * * @param containerName - * name of the container to which subnet needs to be added + * name of the container context in which the subnet needs to be added * @param subnetName * name of new subnet to be added * @param subnetConfigData @@ -227,24 +231,27 @@ public class SubnetsNorthbound { *
* Example: * - * Request URL: http://localhost:8080/controller/nb/v2/subnet/default/subnet/subnet1 + * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/salesdepartment * * Request XML: * <subnetConfig> - * <name>subnet1</name> - * <subnet>30.0.0.1/24</subnet> - * </subnetConfig> + * <name>salesdepartment</name> + * <subnet>172.173.174.254/24</subnet> + * <nodeConnectors>0F|22@OF|00:00:11:22:33:44:55:66>/nodeConnectors> + * <nodeConnectors>0F|39@OF|00:00:ab:cd:33:44:55:66>/nodeConnectors> + * </subnetConfig> * * Request in JSON: * { - * "name":"subnet1", - * "subnet":"30.0.0.1/24" + * "name":"salesdepartment", + * "subnet":"172.173.174.254/24" + * "nodeConnectors":["0F|22@OF|00:00:11:22:33:44:55:66", "0F|39@OF|00:00:ab:cd:33:44:55:66"] * } **/ @Path("/{containerName}/subnet/{subnetName}") - @POST + @PUT @StatusCodes({ @ResponseCode(code = 201, condition = "Subnet created successfully"), @ResponseCode(code = 400, condition = "Invalid data passed"), @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @@ -254,7 +261,7 @@ public class SubnetsNorthbound { @ResponseCode(code = 503, condition = "Service unavailable") }) public Response addSubnet(@PathParam("containerName") String containerName, @PathParam("subnetName") String subnetName, - @TypeHint(SubnetConfig.class) JAXBElement
* Example: - * Request URL: http://localhost:8080/controller/nb/v2/subnet/default/subnet/subnet1 + * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/engdepartment * **/ @@ -331,164 +329,51 @@ public class SubnetsNorthbound { } /** - * Modify a subnet. For now only changing the port list is allowed. + * Modify a subnet. Replace the existing subnet with the new specified one. + * For now only port list modification is allowed. If the respective subnet + * configuration does not exist this call is equivalent to a subnet + * creation. * * @param containerName - * Name of the Container + * Name of the Container context * @param subnetName - * Name of the SubnetConfig to be modified + * Name of the subnet to be modified * @param subnetConfigData - * the {@link SubnetConfig} structure in request body - * parameter - * @return If the operation is successful or not + * the {@link SubnetConfig} structure in request body parameter + * @return Response as dictated by the HTTP Response Status code * *
* Example: * - * Request URL: http://localhost:8080/controller/nb/v2/subnet/default/subnet/subnet1/node-ports + * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/salesdepartment * * Request in XML: * <subnetConfig> - * <name>subnet1</name> - * <subnet>30.0.0.1/24</subnet> - * <nodePorts>1/1</nodePorts> - * <nodePorts>1/2</nodePorts> - * <nodePorts>1/3</nodePorts> - * </subnetConfig> + * <name>salesdepartment</name> + * <subnet>172.173.174.254/24</subnet> + * <nodeConnectors>0F|22@OF|00:00:11:22:33:44:55:66>/nodeConnectors> + * <nodeConnectors>0F|39@OF|00:00:ab:cd:33:44:55:66>/nodeConnectors> + * </subnetConfig> * * Request in JSON: * { - * "name":"subnet1", - * "subnet":"30.0.0.1/24", - * "nodePorts":["1/1","1/2","1/3"] + * "name":"salesdepartment", + * "subnet":"172.173.174.254/24" + * "nodeConnectors":["0F|22@OF|00:00:11:22:33:44:55:66", "0F|39@OF|00:00:ab:cd:33:44:55:66"] * } **/ - @Path("/{containerName}/subnet/{subnetName}/node-ports") - @PUT - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @StatusCodes({ - @ResponseCode(code = 200, condition = "Ports replaced successfully"), - @ResponseCode(code = 400, condition = "Invalid request to change subnet name or invalid node ports passed"), - @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), - @ResponseCode(code = 409, condition = "Subnet name in url conflicts with name in request body"), - @ResponseCode(code = 404, condition = "The containerName or subnetName is not found"), - @ResponseCode(code = 500, condition = "Internal server error: Modify ports failed"), - @ResponseCode(code = 503, condition = "Service unavailable") }) - public Response modifySubnet(@PathParam("containerName") String containerName, - @PathParam("subnetName") String subnetName, - @TypeHint(SubnetConfig.class) JAXBElement
- * Example: - * Request URL: http://localhost:8080/controller/nb/v2/subnet/default/subnet/subnet1/node-ports - * - * Request XML: - * <subnetConfig> - * <name>subnet1</name> - * <subnet>30.0.0.1/24</subnet> - * <nodePorts>1/1</nodePorts> - * <nodePorts>1/2</nodePorts> - * <nodePorts>1/3</nodePorts> - * </subnetConfig> - * - * Request in JSON: - * { - * "name":"subnet1", - * "subnet":"30.0.0.1/24", - * "nodePorts":["1/1","1/2","1/3"] - * } - * - *- */ - @Path("/{containerName}/subnet/{subnetName}/node-ports") + @Path("/{containerName}/subnet/{subnetName}") @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @StatusCodes({ - @ResponseCode(code = 200, condition = "Added node ports to subnet successfully"), - @ResponseCode(code = 400, condition = "Invalid request to change subnet name or invalid node ports passed"), + @StatusCodes({ @ResponseCode(code = 200, condition = "Configuration replaced successfully"), @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), - @ResponseCode(code = 404, condition = "The containerName or subnet is not found"), @ResponseCode(code = 409, condition = "Subnet name in url conflicts with name in request body"), - @ResponseCode(code = 500, condition = "Internal server error : Port add failed"), + @ResponseCode(code = 404, condition = "The containerName or subnetName is not found"), + @ResponseCode(code = 500, condition = "Internal server error: Modify subnet failed"), @ResponseCode(code = 503, condition = "Service unavailable") }) - public Response addNodePorts(@PathParam("containerName") String containerName, - @PathParam("subnetName") String subnetName, - @TypeHint(SubnetConfig.class) JAXBElement
- * Example: - * Request URL: http://localhost:8080/controller/nb/v2/subnet/default/subnet/subnet1/node-ports - * - * Request XML: - * <subnetConfig> - * <name>subnet3</name> - * <subnet>30.0.0.1/24</subnet> - * <nodePorts>1/1,1/2,1/3</nodePorts> - * </subnetConfig> - * - * Request in JSON: - * { "name" : "subnet1", - * "subnet" : "30.0.0.1/24", - * nodePorts : ["1/1,1/2,1/3"]} - * - *- */ - @Path("/{containerName}/subnet/{subnetName}/node-ports") - @DELETE - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @StatusCodes({ - @ResponseCode(code = 204, condition = "No content"), - @ResponseCode(code = 400, condition = "Invalid request to change subnet name or invalid node ports passed"), - @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), - @ResponseCode(code = 404, condition = "The containerName or subnet is not found"), - @ResponseCode(code = 409, condition = "Subnet name in url conflicts with name in request body"), - @ResponseCode(code = 500, condition = "Internal server error : Delete node ports failed"), - @ResponseCode(code = 503, condition = "Service unavailable") }) - public Response deleteNodePorts(@PathParam("containerName") String containerName, - @PathParam("subnetName") String subnetName, - @TypeHint(SubnetConfig.class) JAXBElement