From a2122cefdd97d2eaba4fb82d580e7e7ae7496eb2 Mon Sep 17 00:00:00 2001 From: Sapan Shah Date: Mon, 12 May 2014 17:06:28 -0700 Subject: [PATCH] REST API to fetch Node Property Change-Id: Iad693deefcc3a3f5420e8e19ddb81919c788738f Signed-off-by: Sapan Shah --- .../northbound/SwitchNorthbound.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) 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 662af723ed..e30dad24ab 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 @@ -396,6 +396,85 @@ public class SwitchNorthbound { return NorthboundUtils.getResponse(status); } + /** + * Get a property of a node + * + * @param containerName + * Name of the Container (Eg. 'SliceRed') + * @param nodeType + * 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:03:01:02') + * @param propertyName + * Name of the Property. Properties that can be deleted are + * description, forwarding(only in default container) and tier. + * @return Property value of the property + * + *
+     *
+     * Example:
+     *
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/switchmanager/default/node/OF/00:00:00:00:00:00:00:01/property/description
+     *
+     * Response body in XML
+     * <description>
+     *       <value>switch1</value>
+     * </description>
+     *
+     * Response body in JSON
+     * {
+     *       "value": "switch1"
+     * }
+     * 
+ */ + + @Path("/{containerName}/node/{nodeType}/{nodeId}/property/{propertyName}") + @GET + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @TypeHint(String.class) + @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), + @ResponseCode(code = 404, condition = "The containerName is not found"), + @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) + public Property getNodeProperty(@PathParam("containerName") String containerName, + @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId, + @PathParam("propertyName") String propertyName) { + + if (!isValidContainer(containerName)) { + throw new ResourceNotFoundException("Container " + containerName + " does not exist."); + } + if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) { + throw new UnauthorizedException("User is not authorized to perform this operation on container " + + containerName); + } + ISwitchManager switchManager = getIfSwitchManagerService(containerName); + if (switchManager == null) { + throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString()); + } + + handleNodeAvailability(containerName, nodeType, nodeId); + Node node = Node.fromString(nodeType, nodeId); + if (node == null) { + throw new ResourceNotFoundException(nodeId + " : " + RestMessages.NONODE.toString()); + } + SwitchConfig switchConfig = switchManager.getSwitchConfig(node.toString()); + if (switchConfig == null) { + throw new ResourceNotFoundException(nodeId + " : " + "Config Not Found" ); + } else { + Map nodeProperties = new HashMap(switchConfig.getNodeProperties()); + if (!nodeProperties.containsKey(propertyName.toLowerCase())) { + String msg = "Property " + propertyName + " does not exist or not " + + "configured for switch " + nodeId; + throw new ResourceNotFoundException(msg); + } else { + return nodeProperties.get(propertyName.toLowerCase()); + } + } + } + /** * * Retrieve a list of all the nodeconnectors and their properties in a given -- 2.36.6