Add affinity delete code and api calls. 98/4798/1
authorSuchi Raman <suchi.raman@plexxi.com>
Sun, 26 Jan 2014 15:02:53 +0000 (10:02 -0500)
committerSuchi Raman <suchi.raman@plexxi.com>
Sun, 26 Jan 2014 15:02:53 +0000 (10:02 -0500)
Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImpl.java
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityNorthbound.java
scripts/affinity.py

index dc0ed86d408f85a79563e214bda02b6f5ff94b9f..588cccffe5c72eebe4248be41cfa4051e027972d 100644 (file)
@@ -309,6 +309,7 @@ public class AffinityManagerImpl implements IAffinityManager,
     @Override
     public Status removeAffinityGroup(String name) {
        affinityGroupList.remove(name);
+        log.info("affinityGroup has {} elements", affinityGroupList.size());
        return new Status(StatusCode.SUCCESS);
     }
 
index 326196aae906995ee460b641d43293a51d787233..3da7b9cd855eab5f42114edaa44fa5635b07d95d 100644 (file)
@@ -144,6 +144,73 @@ public class AffinityNorthbound {
         return Response.status(Response.Status.CREATED).build();
     }
 
+
+
+    /**
+     *  Remove affinity group from the configuration database
+     *
+     * @param containerName
+     *            Name of the Container
+     * @param affinityGroupName
+     *            Name of the new affinity group being added
+     * @return Response as dictated by the HTTP Response Status code
+     */
+
+    @Path("/{containerName}/delete/group/{affinityGroupName}")
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @TypeHint(Response.class)
+    @StatusCodes({
+            @ResponseCode(code = 200, condition = "Operation successful"),
+            @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") })
+    public Response deleteAffinityGroup(
+            @PathParam("containerName") String containerName,
+            @PathParam("affinityGroupName") String affinityGroupName) {
+
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                                            + containerName);
+        }
+        log.info("remove an affinity group = {}, containerName = {}",  affinityGroupName, containerName);
+        IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
+        if (affinityManager == null) {
+            throw new ServiceUnavailableException("Affinity Manager "
+                                                  + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+
+        Status ret = affinityManager.removeAffinityGroup(affinityGroupName);
+        
+        return Response.ok().build();
+    }
+
+
+    @Path("/{containerName}/delete/link/{affinityLinkName}")
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @TypeHint(Response.class)
+    @StatusCodes({
+            @ResponseCode(code = 200, condition = "Operation successful"),
+            @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") })
+    public Response deleteAffinityLink(
+            @PathParam("containerName") String containerName,
+            @PathParam("affinityLinkName") String affinityLinkName) {
+
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                                            + containerName);
+        }
+        log.info("remove an affinity link = {}, containerName = {}",  affinityLinkName, containerName);
+        IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
+        if (affinityManager == null) {
+            throw new ServiceUnavailableException("Affinity Manager "
+                                                  + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        Status ret = affinityManager.removeAffinityLink(affinityLinkName);        
+        return Response.ok().build();
+    }
+
     /**
      * Returns details of an affinity group.
      *
index 4808e15f051ffb45567529608b58b1ece15d85c1..eb4b2992389de1ef1e98f520411d43ad08b3c624 100644 (file)
@@ -89,12 +89,25 @@ def client_ws_example():
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/clients/add/ip/10.0.0.3'
     rest_method(put_url, "PUT")
 
+def drop_ws_objects(): 
+
+    print "remove inflows link"
+    put_url = "http://localhost:8080/affinity/nb/v2/affinity/default/delete/link/inflows"
+    rest_method(put_url, "PUT")
+    
+    print "remove web servers group"
+    put_url = "http://localhost:8080/affinity/nb/v2/affinity/default/delete/group/webservers"
+    rest_method(put_url, "PUT")
+
+    print "remove clients group"
+    put_url = "http://localhost:8080/affinity/nb/v2/affinity/default/delete/group/clients"
+    rest_method(put_url, "PUT")
+
 def repeat_add_link(): 
     print "create link inflows"
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/link/inflows/from/clients/to/webservers'
     rest_method(put_url, "PUT")
 
-
 # Only one waypoint supported. 
 def set_waypoint_address(al, wp):
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/setwaypoint/' + wp