Fixed bugs while getting demo.py to work.
[affinity.git] / affinity / northbound / src / main / java / org / opendaylight / affinity / affinity / northbound / AffinityNorthbound.java
1 /*
2  * Copyright (c) 2013 Plexxi, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.affinity.affinity.northbound;
10
11 import java.util.ArrayList;
12 import java.util.HashSet;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.Set;
16
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.DELETE;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.POST;
21 import javax.ws.rs.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.PathParam;
24 import javax.ws.rs.Produces;
25 import javax.ws.rs.core.Context;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28 import javax.ws.rs.core.SecurityContext;
29
30 import org.codehaus.enunciate.jaxrs.ResponseCode;
31 import org.codehaus.enunciate.jaxrs.StatusCodes;
32 import org.codehaus.enunciate.jaxrs.TypeHint;
33 import org.opendaylight.controller.containermanager.IContainerManager;
34 import org.opendaylight.controller.northbound.commons.RestMessages;
35 import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;
36 import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException;
37 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
38 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
39 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
40 import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
41 import org.opendaylight.controller.sal.authorization.Privilege;
42 import org.opendaylight.controller.sal.utils.GlobalConstants;
43 import org.opendaylight.controller.sal.utils.ServiceHelper;
44 import org.opendaylight.controller.sal.utils.Status;
45 import org.opendaylight.affinity.affinity.IAffinityManager;
46 import org.opendaylight.affinity.affinity.AffinityLink;
47 import org.opendaylight.affinity.affinity.AffinityGroup;
48
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51
52 /**
53  * The class provides Northbound REST APIs to access affinity configuration.
54  *
55  */
56
57 @Path("/")
58 public class AffinityNorthbound {
59
60     private String username;
61     private static final Logger log = LoggerFactory.getLogger(AffinityNorthbound.class);
62
63     @Context
64     public void setSecurityContext(SecurityContext context) {
65         username = context.getUserPrincipal().getName();
66     }
67
68     protected String getUserName() {
69         return username;
70     }
71
72     private IAffinityManager getIfAffinityManagerService(String containerName) {
73         log.debug("In getIfAffinityManager");
74
75         IContainerManager containerManager = (IContainerManager) ServiceHelper
76                 .getGlobalInstance(IContainerManager.class, this);
77         if (containerManager == null) {
78             throw new ServiceUnavailableException("Container "
79                     + RestMessages.SERVICEUNAVAILABLE.toString());
80         }
81
82         boolean found = false;
83         List<String> containerNames = containerManager.getContainerNames();
84         for (String cName : containerNames) {
85             if (cName.trim().equalsIgnoreCase(containerName.trim())) {
86                 found = true;
87                 break;
88             }
89         }
90
91         if (found == false) {
92             throw new ResourceNotFoundException(containerName + " "
93                     + RestMessages.SERVICEUNAVAILABLE.toString());
94         }
95
96         IAffinityManager affinityManager = (IAffinityManager) ServiceHelper
97                 .getInstance(IAffinityManager.class, containerName, this);
98
99         if (affinityManager == null) {
100             throw new ServiceUnavailableException("Affinity Manager "
101                     + RestMessages.SERVICEUNAVAILABLE.toString());
102         }
103
104         return affinityManager;
105     }
106
107     /**
108      * Add an affinity to the configuration database
109      *
110      * @param containerName
111      *            Name of the Container
112      * @param affinityGroupName
113      *            Name of the new affinity group being added
114      * @return Response as dictated by the HTTP Response Status code
115      */
116
117     @Path("/{containerName}/create/group/{affinityGroupName}")
118     @PUT
119     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
120     @TypeHint(Response.class)
121     @StatusCodes({
122             @ResponseCode(code = 200, condition = "Operation successful"),
123             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
124             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
125     public Response createAffinityGroup(
126             @PathParam("containerName") String containerName,
127             @PathParam("affinityGroupName") String affinityGroupName) {
128
129         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
130             throw new UnauthorizedException("User is not authorized to perform this operation on container "
131                                             + containerName);
132         }
133         log.info("add a new affinitygroup = {}, containerName = {}",  affinityGroupName, containerName);
134         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
135         if (affinityManager == null) {
136             throw new ServiceUnavailableException("Affinity Manager "
137                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
138         }
139
140         AffinityGroup ag1 = new AffinityGroup(affinityGroupName);
141         Status ret = affinityManager.addAffinityGroup(ag1);
142         
143         return Response.status(Response.Status.CREATED).build();
144     }
145
146     /**
147      * Returns details of an affinity group.
148      *
149      * @param containerName
150      *            Name of the Container. The Container name for the base
151      *            controller is "default".
152      * @param affinityGroupName
153      *            Name of the affinity group being retrieved.
154      * @return affinity configuration that matches the affinity name.
155      */
156     @Path("/{containerName}/group/{affinityGroupName}")
157     @GET
158     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
159     @TypeHint(AffinityGroup.class)
160     @StatusCodes({
161             @ResponseCode(code = 200, condition = "Operation successful"),
162             @ResponseCode(code = 404, condition = "The containerName is not found"),
163             @ResponseCode(code = 415, condition = "Affinity name is not found"),
164             @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
165     public AffinityGroup getAffinityGroupDetails(
166             @PathParam("containerName") String containerName,
167             @PathParam("affinityGroupName") String affinityGroupName) {
168         if (!NorthboundUtils.isAuthorized(
169                 getUserName(), containerName, Privilege.READ, this)) {
170             throw new UnauthorizedException(
171                     "User is not authorized to perform this operation on container "
172                             + containerName);
173         }
174         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
175         if (affinityManager == null) {
176             throw new ServiceUnavailableException("Affinity "
177                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
178         }
179
180         log.info("Get affinity group details" + affinityGroupName);
181         AffinityGroup ag = affinityManager.getAffinityGroup(affinityGroupName);
182         if (ag == null) {
183             throw new ResourceNotFoundException(RestMessages.SERVICEUNAVAILABLE.toString());
184         } else {
185             return ag;
186         }
187     }
188
189     /**
190      * Add an affinity link with one "from" and one "to" affinity group. 
191      *
192      * @param containerName
193      *            Name of the Container
194      * @param affinityLinkName
195      *            Name of the new affinity link being added
196      * @return Response as dictated by the HTTP Response Status code
197      */
198
199     @Path("/{containerName}/create/link/{affinityLinkName}/from/{fromAffinityGroup}/to/{toAffinityGroup}")
200     @PUT
201     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
202     @TypeHint(Response.class)
203     @StatusCodes({
204             @ResponseCode(code = 200, condition = "Operation successful"),
205             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
206             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
207     public Response createAffinityLink(
208             @PathParam("containerName") String containerName,
209             @PathParam("affinityLinkName") String affinityLinkName,
210             @PathParam("fromAffinityGroup") String fromAffinityGroup,
211             @PathParam("toAffinityGroup") String toAffinityGroup) {
212
213         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
214             throw new UnauthorizedException("User is not authorized to perform this operation on container "
215                                             + containerName);
216         }
217
218         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
219         if (affinityManager == null) {
220             throw new ServiceUnavailableException("Affinity Manager "
221                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
222         }
223
224         
225         log.info("Create affinity link" + affinityLinkName + "fromGroup" + fromAffinityGroup + "toGroup" + toAffinityGroup);
226         AffinityGroup from = affinityManager.getAffinityGroup(fromAffinityGroup);
227         AffinityGroup to = affinityManager.getAffinityGroup(toAffinityGroup);
228         AffinityLink al1 = new AffinityLink(affinityLinkName, from, to);
229
230         Status ret = affinityManager.addAffinityLink(al1);
231         if (!ret.isSuccess()) {
232             //            throw new InternalServerErrorException(ret.getDescription());
233             log.error("Create affinity link {}", ret);
234         }
235         return Response.status(Response.Status.CREATED).build();
236     }
237
238
239     /**
240      * Returns details of an affinity link.
241      *
242      * @param containerName
243      *            Name of the Container. The Container name for the base
244      *            controller is "default".
245      * @param affinityLinkName
246      *            Name of the affinity link being retrieved.
247      * @return affinity link details.
248      */
249     @Path("/{containerName}/link/{affinityLinkName}")
250     @GET
251     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
252     @TypeHint(AffinityLinkNorthbound.class)
253     @StatusCodes({
254             @ResponseCode(code = 200, condition = "Operation successful"),
255             @ResponseCode(code = 404, condition = "The containerName is not found"),
256             @ResponseCode(code = 415, condition = "Affinity name is not found"),
257             @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
258     public AffinityLinkNorthbound getAffinityLinkDetails(
259             @PathParam("containerName") String containerName,
260             @PathParam("affinityLinkName") String affinityLinkName) {
261         if (!NorthboundUtils.isAuthorized(
262                 getUserName(), containerName, Privilege.READ, this)) {
263             throw new UnauthorizedException(
264                     "User is not authorized to perform this operation on container "
265                             + containerName);
266         }
267         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
268         if (affinityManager == null) {
269             throw new ServiceUnavailableException("Affinity "
270                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
271         }
272
273         log.info("Get affinity link details" + affinityLinkName);
274         AffinityLink al = affinityManager.getAffinityLink(affinityLinkName);
275         if (al == null) {
276             throw new ResourceNotFoundException(RestMessages.SERVICEUNAVAILABLE.toString());
277         } else {
278             return new AffinityLinkNorthbound(al);
279         }
280     }
281
282     /**
283      * Add path redirect details to an affinity link. 
284      *
285      * @param containerName
286      *            Name of the Container
287      * @param affinityLinkName
288      *            Name of the new affinity link being added
289      * @param wayPoint
290      *            IP address string of a waypoint server or VM
291      * @return Response as dictated by the HTTP Response Status code
292      */
293
294     @Path("/{containerName}/link/{affinityLinkName}/setwaypoint/{waypointIP}")
295     @PUT
296     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
297     @TypeHint(Response.class)
298     @StatusCodes({
299             @ResponseCode(code = 200, condition = "Operation successful"),
300             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
301             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
302     public Response setLinkWaypoint(
303             @PathParam("containerName") String containerName,
304             @PathParam("affinityLinkName") String affinityLinkName,
305             @PathParam("waypointIP") String waypointIP) {
306
307         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
308             throw new UnauthorizedException("User is not authorized to perform this operation on container "
309                                             + containerName);
310         }
311
312         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
313         if (affinityManager == null) {
314             throw new ServiceUnavailableException("Affinity Manager "
315                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
316         }
317         log.info("Set waypoint address (link)" + affinityLinkName + " (waypoint ip) " + waypointIP);
318
319         AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
320         al1.setWaypoint(waypointIP);        
321         log.info("Affinity link is now: {} ", al1.toString());
322         return Response.status(Response.Status.CREATED).build();
323     }
324
325
326     /**
327      * Add path redirect details to an affinity link. 
328      *
329      * @param containerName
330      *            Name of the Container
331      * @param affinityLinkName
332      *            Name of the new affinity link being added
333      * @param wayPoint
334      *            IP address string of a waypoint server or VM
335      * @return Response as dictated by the HTTP Response Status code
336      */
337
338     @Path("/{containerName}/link/{affinityLinkName}/unsetwaypoint")
339     @PUT
340     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
341     @TypeHint(Response.class)
342     @StatusCodes({
343             @ResponseCode(code = 200, condition = "Operation successful"),
344             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
345             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
346     public Response setLinkWaypoint(
347             @PathParam("containerName") String containerName,
348             @PathParam("affinityLinkName") String affinityLinkName) {
349
350         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
351             throw new UnauthorizedException("User is not authorized to perform this operation on container "
352                                             + containerName);
353         }
354
355         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
356         if (affinityManager == null) {
357             throw new ServiceUnavailableException("Affinity Manager "
358                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
359         }
360         log.info("Unset waypoint setting (link)" + affinityLinkName);
361
362         AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
363         al1.unsetWaypoint();
364         return Response.status(Response.Status.CREATED).build();
365     }
366
367
368     /**
369      * Mark this affinity link with "deny". 
370      *
371      * @param containerName
372      *            Name of the Container
373      * @param affinityLinkName
374      *            Name of the new affinity link being marked. 
375      * @return Response as dictated by the HTTP Response Status code
376      */
377
378     @Path("/{containerName}/link/{affinityLinkName}/deny/")
379     @PUT
380     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
381     @TypeHint(Response.class)
382     @StatusCodes({
383             @ResponseCode(code = 200, condition = "Operation successful"),
384             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
385             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
386     public Response setLinkDeny(
387             @PathParam("containerName") String containerName,
388             @PathParam("affinityLinkName") String affinityLinkName) {
389         
390         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
391             throw new UnauthorizedException("User is not authorized to perform this operation on container "
392                                             + containerName);
393         }
394
395         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
396         if (affinityManager == null) {
397             throw new ServiceUnavailableException("Affinity Manager "
398                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
399         }
400         log.info("Set deny (link)" + affinityLinkName);
401
402         AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
403         al1.setDeny();        
404         return Response.status(Response.Status.CREATED).build();
405     }
406
407
408
409     /**
410      * Remove the "deny" attribute if it exists.
411      * @param containerName
412      *            Name of the Container
413      * @param affinityLinkName
414      *            Name of the new affinity link being marked. 
415      * @return Response as dictated by the HTTP Response Status code
416      */
417
418     @Path("/{containerName}/link/{affinityLinkName}/permit/")
419     @PUT
420     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
421     @TypeHint(Response.class)
422     @StatusCodes({
423             @ResponseCode(code = 200, condition = "Operation successful"),
424             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
425             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
426     public Response unsetLinkDeny(
427             @PathParam("containerName") String containerName,
428             @PathParam("affinityLinkName") String affinityLinkName) {
429         
430         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
431             throw new UnauthorizedException("User is not authorized to perform this operation on container "
432                                             + containerName);
433         }
434
435         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
436         if (affinityManager == null) {
437             throw new ServiceUnavailableException("Affinity Manager "
438                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
439         }
440         log.info("Unset deny (link)" + affinityLinkName);
441
442         AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
443         al1.unsetDeny();
444         return Response.status(Response.Status.CREATED).build();
445     }
446
447     /**
448      * Add IP addresses to a group. 
449      *
450      * @param containerName
451      *            Name of the Container
452      * @param affinityGroupName
453      *            Name of the affinity group to add to. 
454      * @param ipaddress
455      *            IP address of the new affinity member. 
456      * @return Response as dictated by the HTTP Response Status code
457      */
458     @Path("/{containerName}/group/{affinityGroupName}/add/ip/{ipaddress}")
459     @PUT
460     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
461     @TypeHint(Response.class)
462     @StatusCodes({
463             @ResponseCode(code = 200, condition = "Operation successful"),
464             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
465             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
466     public Response addInetAddress(
467             @PathParam("containerName") String containerName,
468             @PathParam("affinityGroupName") String affinityGroupName,
469             @PathParam("ipaddress") String ipaddress) {
470         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
471             throw new UnauthorizedException("User is not authorized to perform this operation on container "
472                                             + containerName);
473         }
474         
475         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
476         if (affinityManager == null) {
477             throw new ServiceUnavailableException("Affinity Manager "
478                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
479         }
480         
481         log.info("add Inet address " + affinityGroupName + " (ipaddress) " + ipaddress);
482         AffinityGroup ag1 = affinityManager.getAffinityGroup(affinityGroupName);
483         ag1.add(ipaddress);
484         
485         return Response.status(Response.Status.CREATED).build();
486     }
487     
488     /**
489      * Add prefix/mask subnet as a member of the affinity group.
490      *
491      * @param containerName
492      *            Name of the Container
493      * @param affinityGroupName
494      *            Name of the affinity group to add to. 
495      * @param ipmask
496      *            a.b.c.d/mm format of a set of IP addresses to add.
497      * @return Response as dictated by the HTTP Response Status code
498      */
499     @Path("/{containerName}/group/{affinityGroupName}/addsubnet/ipprefix/{ipprefix}/mask/{mask}")
500     @PUT
501     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
502     @TypeHint(Response.class)
503     @StatusCodes({
504             @ResponseCode(code = 200, condition = "Operation successful"),
505             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
506             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
507     public Response addSubnet(
508             @PathParam("containerName") String containerName,
509             @PathParam("affinityGroupName") String affinityGroupName,
510             @PathParam("ipprefix") String ipprefix,
511             @PathParam("mask") String mask) {
512         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
513             throw new UnauthorizedException("User is not authorized to perform this operation on container "
514                                             + containerName);
515         }
516         
517         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
518         if (affinityManager == null) {
519             throw new ServiceUnavailableException("Affinity Manager "
520                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
521         }
522         
523         log.info("addSubnet to affinitygroup" + affinityGroupName);
524         AffinityGroup ag1 = affinityManager.getAffinityGroup(affinityGroupName);
525         String ipmask = ipprefix + "/" + mask;
526         ag1.addInetMask(ipmask);
527         
528         return Response.status(Response.Status.CREATED).build();
529     }
530
531
532     @Path("/{containerName}/affinity-groups")
533     @GET
534     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
535     @TypeHint(AffinityGroupList.class)
536     @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"),
537         @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
538         @ResponseCode(code = 404, condition = "The containerName is not found"),
539         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
540     public AffinityGroupList getAllAffinityGroups(@PathParam("containerName") String containerName) {
541
542         //        if (!isValidContainer(containerName)) {
543         //            throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
544         //}
545
546         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
547             throw new UnauthorizedException("User is not authorized to perform this operation on container "
548                     + containerName);
549         }
550
551         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
552         if (affinityManager == null) {
553             throw new ServiceUnavailableException("Affinity Manager "
554                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
555         }
556         log.info("getallgroups");
557         return new AffinityGroupList(affinityManager.getAllAffinityGroups());
558     }
559
560
561
562     @Path("/{containerName}/affinity-links")
563     @GET
564     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
565     @TypeHint(AffinityLinkList.class)
566     @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"),
567     @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
568     @ResponseCode(code = 404, condition = "The containerName is not found"),
569     @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
570     public AffinityLinkList getAllAffinityLinks(@PathParam("containerName") String containerName) {
571
572         //        if (!isValidContainer(containerName)) {
573         //            throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
574         //}
575
576         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
577             throw new UnauthorizedException("User is not authorized to perform this operation on container "
578                     + containerName);
579         }
580
581         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
582         if (affinityManager == null) {
583             throw new ServiceUnavailableException("Affinity Manager "
584                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
585         }
586         log.info("list all links");
587         return new AffinityLinkList(affinityManager.getAllAffinityLinks());
588     }
589
590     /**
591     @Path("/{containerName}/")
592     @GET
593     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
594     @TypeHint(AffinityGroupList.class)
595     @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"),
596         @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
597         @ResponseCode(code = 404, condition = "The containerName is not found"),
598         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
599     public AffinityGroupList getAllAffinityGroups(@PathParam("containerName") String containerName) {
600
601         //        if (!isValidContainer(containerName)) {
602         //            throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
603         //}
604
605         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
606             throw new UnauthorizedException("User is not authorized to perform this operation on container "
607                     + containerName);
608         }
609
610         IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
611         if (affinityManager == null) {
612             throw new ServiceUnavailableException("Affinity Manager "
613                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
614         }
615         log.info("getallgroups");
616         return new AffinityGroupList(affinityManager.getAllAffinityGroups());
617     }
618     */
619
620 }