Merge "Replaced Equals/HashcodeBuilder for DatapacketListener"
[controller.git] / opendaylight / northbound / switchmanager / src / main / java / org / opendaylight / controller / switchmanager / northbound / SwitchNorthbound.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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.controller.switchmanager.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.core.Node;
43 import org.opendaylight.controller.sal.core.NodeConnector;
44 import org.opendaylight.controller.sal.core.Property;
45 import org.opendaylight.controller.sal.utils.GlobalConstants;
46 import org.opendaylight.controller.sal.utils.ServiceHelper;
47 import org.opendaylight.controller.sal.utils.Status;
48 import org.opendaylight.controller.switchmanager.ISwitchManager;
49
50 /**
51  * The class provides Northbound REST APIs to access the nodes, node connectors
52  * and their properties.
53  *
54  */
55
56 @Path("/")
57 public class SwitchNorthbound {
58
59     private String username;
60
61     @Context
62     public void setSecurityContext(SecurityContext context) {
63         username = context.getUserPrincipal().getName();
64     }
65
66     protected String getUserName() {
67         return username;
68     }
69
70     private ISwitchManager getIfSwitchManagerService(String containerName) {
71         IContainerManager containerManager = (IContainerManager) ServiceHelper
72                 .getGlobalInstance(IContainerManager.class, this);
73         if (containerManager == null) {
74             throw new ServiceUnavailableException("Container "
75                     + RestMessages.SERVICEUNAVAILABLE.toString());
76         }
77
78         boolean found = false;
79         List<String> containerNames = containerManager.getContainerNames();
80         for (String cName : containerNames) {
81             if (cName.trim().equalsIgnoreCase(containerName.trim())) {
82                 found = true;
83                 break;
84             }
85         }
86
87         if (found == false) {
88             throw new ResourceNotFoundException(containerName + " "
89                     + RestMessages.NOCONTAINER.toString());
90         }
91
92         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
93                 .getInstance(ISwitchManager.class, containerName, this);
94
95         if (switchManager == null) {
96             throw new ServiceUnavailableException("Switch Manager "
97                     + RestMessages.SERVICEUNAVAILABLE.toString());
98         }
99
100         return switchManager;
101     }
102
103     /**
104      *
105      * Retrieve a list of all the nodes and their properties in the network
106      *
107      * @param containerName
108      *            The container for which we want to retrieve the list
109      * @return A list of Pair each pair represents a
110      *         {@link org.opendaylight.controller.sal.core.Node} and Set of
111      *         {@link org.opendaylight.controller.sal.core.Property} attached to
112      *         it.
113      */
114     @Path("/{containerName}/nodes")
115     @GET
116     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
117     @TypeHint(Nodes.class)
118     @StatusCodes({
119             @ResponseCode(code = 200, condition = "Operation successful"),
120             @ResponseCode(code = 404, condition = "The containerName is not found"),
121             @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
122     public Nodes getNodes(@PathParam("containerName") String containerName) {
123
124         if (!NorthboundUtils.isAuthorized(
125                 getUserName(), containerName, Privilege.READ, this)) {
126             throw new UnauthorizedException(
127                     "User is not authorized to perform this operation on container "
128                             + containerName);
129         }
130
131         ISwitchManager switchManager = getIfSwitchManagerService(containerName);
132         if (switchManager == null) {
133             throw new ServiceUnavailableException("Switch Manager "
134                     + RestMessages.SERVICEUNAVAILABLE.toString());
135         }
136
137         List<NodeProperties> res = new ArrayList<NodeProperties>();
138         Set<Node> nodes = switchManager.getNodes();
139         if (nodes == null) {
140             return null;
141         }
142
143         for (Node node : nodes) {
144             Map<String, Property> propMap = switchManager.getNodeProps(node);
145             if (propMap == null) {
146                 continue;
147             }
148             Set<Property> props = new HashSet<Property>(propMap.values());
149
150             NodeProperties nodeProps = new NodeProperties(node, props);
151             res.add(nodeProps);
152         }
153
154         return new Nodes(res);
155     }
156
157     /**
158      * Add a Name/Tier property to a node
159      *
160      * @param containerName
161      *            Name of the Container
162      * @param nodeType
163      *            Type of the node being programmed
164      * @param nodeId
165      *            Node Identifier as specified by
166      *            {@link org.opendaylight.controller.sal.core.Node}
167      * @param propName
168      *            Name of the Property specified by
169      *            {@link org.opendaylight.controller.sal.core.Property} and its
170      *            extended classes
171      * @param propValue
172      *            Value of the Property specified by
173      *            {@link org.opendaylight.controller.sal.core.Property} and its
174      *            extended classes
175      * @return Response as dictated by the HTTP Response Status code
176      */
177
178     @Path("/{containerName}/node/{nodeType}/{nodeId}/property/{propName}/{propValue}")
179     @PUT
180     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
181     @TypeHint(Response.class)
182     @StatusCodes({
183             @ResponseCode(code = 200, condition = "Operation successful"),
184             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
185             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
186     public Response addNodeProperty(
187             @PathParam("containerName") String containerName,
188             @PathParam("nodeType") String nodeType,
189             @PathParam("nodeId") String nodeId,
190             @PathParam("propName") String propName,
191             @PathParam("propValue") String propValue) {
192
193         if (!NorthboundUtils.isAuthorized(
194                 getUserName(), containerName, Privilege.WRITE, this)) {
195             throw new UnauthorizedException(
196                     "User is not authorized to perform this operation on container "
197                             + containerName);
198         }
199         handleDefaultDisabled(containerName);
200
201         ISwitchManager switchManager = getIfSwitchManagerService(containerName);
202         if (switchManager == null) {
203             throw new ServiceUnavailableException("Switch Manager "
204                     + RestMessages.SERVICEUNAVAILABLE.toString());
205         }
206
207         handleNodeAvailability(containerName, nodeType, nodeId);
208         Node node = Node.fromString(nodeId);
209
210         Property prop = switchManager.createProperty(propName, propValue);
211         if (prop == null) {
212             throw new ResourceNotFoundException(
213                     RestMessages.INVALIDDATA.toString());
214         }
215
216         switchManager.setNodeProp(node, prop);
217         return Response.status(Response.Status.CREATED).build();
218     }
219
220     /**
221      * Delete a property of a node
222      *
223      * @param containerName
224      *            Name of the Container
225      * @param nodeType
226      *            Type of the node being programmed
227      * @param nodeId
228      *            Node Identifier as specified by
229      *            {@link org.opendaylight.controller.sal.core.Node}
230      * @param propertyName
231      *            Name of the Property specified by
232      *            {@link org.opendaylight.controller.sal.core.Property} and its
233      *            extended classes
234      * @return Response as dictated by the HTTP Response Status code
235      */
236
237     @Path("/{containerName}/node/{nodeType}/{nodeId}/property/{propertyName}")
238     @DELETE
239     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
240     @StatusCodes({
241             @ResponseCode(code = 200, condition = "Operation successful"),
242             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
243             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
244     public Response deleteNodeProperty(
245             @PathParam("containerName") String containerName,
246             @PathParam("nodeType") String nodeType,
247             @PathParam("nodeId") String nodeId,
248             @PathParam("propertyName") String propertyName) {
249
250         if (!NorthboundUtils.isAuthorized(
251                 getUserName(), containerName, Privilege.WRITE, this)) {
252             throw new UnauthorizedException(
253                     "User is not authorized to perform this operation on container "
254                             + containerName);
255         }
256         handleDefaultDisabled(containerName);
257
258         ISwitchManager switchManager = getIfSwitchManagerService(containerName);
259         if (switchManager == null) {
260             throw new ServiceUnavailableException("Switch Manager "
261                     + RestMessages.SERVICEUNAVAILABLE.toString());
262         }
263
264         handleNodeAvailability(containerName, nodeType, nodeId);
265         Node node = Node.fromString(nodeId);
266
267         Status ret = switchManager.removeNodeProp(node, propertyName);
268         if (ret.isSuccess()) {
269             return Response.ok().build();
270         }
271         throw new ResourceNotFoundException(ret.getDescription());
272     }
273
274     /**
275      *
276      * Retrieve a list of all the node connectors and their properties in a
277      * given node
278      *
279      * @param containerName
280      *            The container for which we want to retrieve the list
281      * @param nodeType
282      *            Type of the node being programmed
283      * @param nodeId
284      *            Node Identifier as specified by
285      *            {@link org.opendaylight.controller.sal.core.Node}
286      * @return A List of Pair each pair represents a
287      *         {@link org.opendaylight.controller.sal.core.NodeConnector} and
288      *         its corresponding
289      *         {@link org.opendaylight.controller.sal.core.Property} attached to
290      *         it.
291      */
292     @Path("/{containerName}/node/{nodeType}/{nodeId}")
293     @GET
294     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
295     @TypeHint(NodeConnectors.class)
296     @StatusCodes({
297             @ResponseCode(code = 200, condition = "Operation successful"),
298             @ResponseCode(code = 404, condition = "The containerName is not found"),
299             @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
300     public NodeConnectors getNodeConnectors(
301             @PathParam("containerName") String containerName,
302             @PathParam("nodeType") String nodeType,
303             @PathParam("nodeId") String nodeId) {
304
305         if (!NorthboundUtils.isAuthorized(
306                 getUserName(), containerName, Privilege.READ, this)) {
307             throw new UnauthorizedException(
308                     "User is not authorized to perform this operation on container "
309                             + containerName);
310         }
311
312         ISwitchManager switchManager = getIfSwitchManagerService(containerName);
313         if (switchManager == null) {
314             throw new ServiceUnavailableException("Switch Manager "
315                     + RestMessages.SERVICEUNAVAILABLE.toString());
316         }
317
318         handleNodeAvailability(containerName, nodeType, nodeId);
319         Node node = Node.fromString(nodeId);
320
321         List<NodeConnectorProperties> res = new ArrayList<NodeConnectorProperties>();
322         Set<NodeConnector> ncs = switchManager.getNodeConnectors(node);
323         if (ncs == null) {
324             return null;
325         }
326
327         for (NodeConnector nc : ncs) {
328             Map<String, Property> propMap = switchManager
329                     .getNodeConnectorProps(nc);
330             if (propMap == null) {
331                 continue;
332             }
333             Set<Property> props = new HashSet<Property>(propMap.values());
334             NodeConnectorProperties ncProps = new NodeConnectorProperties(nc,
335                     props);
336             res.add(ncProps);
337         }
338
339         return new NodeConnectors(res);
340     }
341
342     /**
343      * Add a Name/Bandwidth property to a node connector
344      *
345      * @param containerName
346      *            Name of the Container
347      * @param nodeType
348      *            Type of the node being programmed
349      * @param nodeId
350      *            Node Identifier as specified by
351      *            {@link org.opendaylight.controller.sal.core.Node}
352      * @param nodeConnectorType
353      *            Type of the node connector being programmed
354      * @param nodeConnectorId
355      *            NodeConnector Identifier as specified by
356      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
357      * @param propName
358      *            Name of the Property specified by
359      *            {@link org.opendaylight.controller.sal.core.Property} and its
360      *            extended classes
361      * @param propValue
362      *            Value of the Property specified by
363      *            {@link org.opendaylight.controller.sal.core.Property} and its
364      *            extended classes
365      * @return Response as dictated by the HTTP Response Status code
366      */
367
368     @Path("/{containerName}/nodeconnector/{nodeType}/{nodeId}/{nodeConnectorType}/{nodeConnectorId}/property/{propName}/{propValue}")
369     @PUT
370     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
371     @StatusCodes({
372             @ResponseCode(code = 200, condition = "Operation successful"),
373             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
374             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
375     public Response addNodeConnectorProperty(
376             @PathParam("containerName") String containerName,
377             @PathParam("nodeType") String nodeType,
378             @PathParam("nodeId") String nodeId,
379             @PathParam("nodeConnectorType") String nodeConnectorType,
380             @PathParam("nodeConnectorId") String nodeConnectorId,
381             @PathParam("propName") String propName,
382             @PathParam("propValue") String propValue) {
383
384         if (!NorthboundUtils.isAuthorized(
385                 getUserName(), containerName, Privilege.WRITE, this)) {
386             throw new UnauthorizedException(
387                     "User is not authorized to perform this operation on container "
388                             + containerName);
389         }
390
391         handleDefaultDisabled(containerName);
392
393         ISwitchManager switchManager = getIfSwitchManagerService(containerName);
394         if (switchManager == null) {
395             throw new ServiceUnavailableException("Switch Manager "
396                     + RestMessages.SERVICEUNAVAILABLE.toString());
397         }
398
399         handleNodeAvailability(containerName, nodeType, nodeId);
400         Node node = Node.fromString(nodeId);
401
402         handleNodeConnectorAvailability(containerName, node, nodeConnectorType,
403                 nodeConnectorId);
404         NodeConnector nc = NodeConnector
405                 .fromStringNoNode(nodeConnectorId, node);
406
407         Property prop = switchManager.createProperty(propName, propValue);
408         if (prop == null) {
409             throw new ResourceNotFoundException(
410                     RestMessages.INVALIDDATA.toString());
411         }
412
413         Status ret = switchManager.addNodeConnectorProp(nc, prop);
414         if (ret.isSuccess()) {
415             return Response.status(Response.Status.CREATED).build();
416         }
417         throw new InternalServerErrorException(ret.getDescription());
418     }
419
420     /**
421      * Delete a property of a node connector
422      *
423      * @param containerName
424      *            Name of the Container
425      * @param nodeType
426      *            Type of the node being programmed
427      * @param nodeId
428      *            Node Identifier as specified by
429      *            {@link org.opendaylight.controller.sal.core.Node}
430      * @param nodeConnectorType
431      *            Type of the node connector being programmed
432      * @param nodeConnectorId
433      *            NodeConnector Identifier as specified by
434      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
435      * @param propertyName
436      *            Name of the Property specified by
437      *            {@link org.opendaylight.controller.sal.core.Property} and its
438      *            extended classes
439      * @return Response as dictated by the HTTP Response Status code
440      */
441
442     @Path("/{containerName}/nodeconnector/{nodeType}/{nodeId}/{nodeConnectorType}/{nodeConnectorId}/property/{propertyName}")
443     @DELETE
444     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
445     @StatusCodes({
446             @ResponseCode(code = 200, condition = "Operation successful"),
447             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
448             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
449     public Response deleteNodeConnectorProperty(
450             @PathParam("containerName") String containerName,
451             @PathParam("nodeType") String nodeType,
452             @PathParam("nodeId") String nodeId,
453             @PathParam("nodeConnectorType") String nodeConnectorType,
454             @PathParam("nodeConnectorId") String nodeConnectorId,
455             @PathParam("propertyName") String propertyName) {
456
457         if (!NorthboundUtils.isAuthorized(
458                 getUserName(), containerName, Privilege.WRITE, this)) {
459             throw new UnauthorizedException(
460                     "User is not authorized to perform this operation on container "
461                             + containerName);
462         }
463
464         handleDefaultDisabled(containerName);
465
466         ISwitchManager switchManager = getIfSwitchManagerService(containerName);
467         if (switchManager == null) {
468             throw new ServiceUnavailableException("Switch Manager "
469                     + RestMessages.SERVICEUNAVAILABLE.toString());
470         }
471
472         handleNodeAvailability(containerName, nodeType, nodeId);
473         Node node = Node.fromString(nodeId);
474
475         handleNodeConnectorAvailability(containerName, node, nodeConnectorType,
476                 nodeConnectorId);
477         NodeConnector nc = NodeConnector
478                 .fromStringNoNode(nodeConnectorId, node);
479
480         Status ret = switchManager.removeNodeConnectorProp(nc, propertyName);
481         if (ret.isSuccess()) {
482             return Response.ok().build();
483         }
484         throw new ResourceNotFoundException(ret.getDescription());
485     }
486
487     /*    *//**
488      * Retrieve a list of Span ports that were configured previously.
489      *
490      * @param containerName
491      *            Name of the Container
492      * @return list of
493      *         {@link org.opendaylight.controller.switchmanager.SpanConfig}
494      *         resources
495      */
496     /*
497      * @Path("/span-config/{containerName}")
498      *
499      * @GET
500      *
501      * @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
502      *
503      * @StatusCodes( {
504      *
505      * @ResponseCode(code = 200, condition = "Operation successful"),
506      *
507      * @ResponseCode(code = 404, condition = "The containerName is not found"),
508      *
509      * @ResponseCode(code = 503, condition =
510      * "One or more of Controller Services are unavailable") }) public
511      * List<SpanConfig> getSpanConfigList(@PathParam("containerName") String
512      * containerName) { ISwitchManager switchManager = (ISwitchManager)
513      * getIfSwitchManagerService(containerName); if (switchManager == null) {
514      * throw new ServiceUnavailableException("Switch Manager " +
515      * RestMessages.SERVICEUNAVAILABLE.toString()); }
516      *
517      * return switchManager.getSpanConfigList(); }
518      *//**
519      * Add a span configuration
520      *
521      * @param containerName
522      *            Name of the Container
523      * @param config
524      *            {@link org.opendaylight.controller.switchmanager.SpanConfig}
525      *            in JSON or XML format
526      * @return Response as dictated by the HTTP Response Status code
527      */
528     /*
529      * @Path("/span-config/{containerName}")
530      *
531      * @PUT
532      *
533      * @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
534      *
535      * @StatusCodes( {
536      *
537      * @ResponseCode(code = 200, condition = "Operation successful"),
538      *
539      * @ResponseCode(code = 404, condition = "The containerName is not found"),
540      *
541      * @ResponseCode(code = 503, condition =
542      * "One or more of Controller Services are unavailable") }) public Response
543      * addSpanConfig(@PathParam("containerName") String containerName,
544      *
545      * @TypeHint(SubnetConfig.class) JAXBElement<SpanConfig> config) {
546      * ISwitchManager switchManager = (ISwitchManager)
547      * getIfSwitchManagerService(containerName); if (switchManager == null) {
548      * throw new ServiceUnavailableException("Switch Manager " +
549      * RestMessages.SERVICEUNAVAILABLE.toString()); }
550      *
551      * String ret = switchManager.addSpanConfig(config.getValue()); if
552      * (ret.equals(ReturnString.SUCCESS.toString())) { return
553      * Response.status(Response.Status.CREATED).build(); } throw new
554      * InternalServerErrorException(ret); }
555      *//**
556      * Delete a span configuration
557      *
558      * @param containerName
559      *            Name of the Container
560      * @param config
561      *            {@link org.opendaylight.controller.switchmanager.SpanConfig}
562      *            in JSON or XML format
563      * @return Response as dictated by the HTTP Response Status code
564      */
565     /*
566      * @Path("/span-config/{containerName}")
567      *
568      * @DELETE
569      *
570      * @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
571      *
572      * @StatusCodes( {
573      *
574      * @ResponseCode(code = 200, condition = "Operation successful"),
575      *
576      * @ResponseCode(code = 404, condition = "The containerName is not found"),
577      *
578      * @ResponseCode(code = 503, condition =
579      * "One or more of Controller Services are unavailable") }) public Response
580      * deleteSpanConfig(@PathParam("containerName") String containerName,
581      *
582      * @TypeHint(SubnetConfig.class) JAXBElement<SpanConfig> config) {
583      * ISwitchManager switchManager = (ISwitchManager)
584      * getIfSwitchManagerService(containerName); if (switchManager == null) {
585      * throw new ServiceUnavailableException("Switch Manager " +
586      * RestMessages.SERVICEUNAVAILABLE.toString()); }
587      *
588      * String ret = switchManager.removeSpanConfig(config.getValue()); if
589      * (ret.equals(ReturnString.SUCCESS.toString())) { return
590      * Response.ok().build(); } throw new ResourceNotFoundException(ret); }
591      */
592
593     /**
594      * Save the current switch configurations
595      *
596      * @param containerName
597      *            Name of the Container
598      * @return Response as dictated by the HTTP Response Status code
599      */
600     @Path("/{containerName}/switch-config")
601     @POST
602     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
603     @StatusCodes({
604             @ResponseCode(code = 200, condition = "Operation successful"),
605             @ResponseCode(code = 404, condition = "The containerName is not found"),
606             @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
607     public Response saveSwitchConfig(
608             @PathParam("containerName") String containerName) {
609
610         if (!NorthboundUtils.isAuthorized(
611                 getUserName(), containerName, Privilege.WRITE, this)) {
612             throw new UnauthorizedException(
613                     "User is not authorized to perform this operation on container "
614                             + containerName);
615         }
616         ISwitchManager switchManager = getIfSwitchManagerService(containerName);
617         if (switchManager == null) {
618             throw new ServiceUnavailableException("Switch Manager "
619                     + RestMessages.SERVICEUNAVAILABLE.toString());
620         }
621
622         Status ret = switchManager.saveSwitchConfig();
623         if (ret.isSuccess()) {
624             return Response.ok().build();
625         }
626         throw new InternalServerErrorException(ret.getDescription());
627     }
628
629     private void handleDefaultDisabled(String containerName) {
630         IContainerManager containerManager = (IContainerManager) ServiceHelper
631                 .getGlobalInstance(IContainerManager.class, this);
632         if (containerManager == null) {
633             throw new InternalServerErrorException(
634                     RestMessages.INTERNALERROR.toString());
635         }
636         if (containerName.equals(GlobalConstants.DEFAULT.toString())
637                 && containerManager.hasNonDefaultContainer()) {
638             throw new ResourceConflictException(
639                     RestMessages.DEFAULTDISABLED.toString());
640         }
641     }
642
643     private Node handleNodeAvailability(String containerName, String nodeType,
644             String nodeId) {
645
646         Node node = Node.fromString(nodeType, nodeId);
647         if (node == null) {
648             throw new ResourceNotFoundException(nodeId + " : "
649                     + RestMessages.NONODE.toString());
650         }
651
652         ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
653                 ISwitchManager.class, containerName, this);
654
655         if (sm == null) {
656             throw new ServiceUnavailableException("Switch Manager "
657                     + RestMessages.SERVICEUNAVAILABLE.toString());
658         }
659
660         if (!sm.getNodes().contains(node)) {
661             throw new ResourceNotFoundException(node.toString() + " : "
662                     + RestMessages.NONODE.toString());
663         }
664         return node;
665     }
666
667     private void handleNodeConnectorAvailability(String containerName,
668             Node node, String nodeConnectorType, String nodeConnectorId) {
669
670         NodeConnector nc = NodeConnector.fromStringNoNode(nodeConnectorType,
671                 nodeConnectorId, node);
672         if (nc == null) {
673             throw new ResourceNotFoundException(nc + " : "
674                     + RestMessages.NORESOURCE.toString());
675         }
676
677         ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
678                 ISwitchManager.class, containerName, this);
679
680         if (sm == null) {
681             throw new ServiceUnavailableException("Switch Manager "
682                     + RestMessages.SERVICEUNAVAILABLE.toString());
683         }
684
685         if (!sm.getNodeConnectors(node).contains(nc)) {
686             throw new ResourceNotFoundException(nc.toString() + " : "
687                     + RestMessages.NORESOURCE.toString());
688         }
689     }
690
691 }