Merge "Fixed schema path of types in augment statements. Updated tests."
authorGiovanni Meo <gmeo@cisco.com>
Thu, 13 Jun 2013 16:02:35 +0000 (16:02 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 13 Jun 2013 16:02:35 +0000 (16:02 +0000)
opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java
opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthbound.java
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java
opendaylight/sal/implementation/src/main/java/org/opendaylight/controller/sal/implementation/internal/DataPacketService.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTestIT.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/Util.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToSourcesProcessor.java
opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/IUserManager.java
opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java
opendaylight/usermanager/src/test/java/org/opendaylight/controller/usermanager/internal/UserManagerImplTest.java

index 0065cb5a08c78488542bb7d065667b0d4f917b38..112725976fa979a3ea2dce55c1f96369709cacc3 100644 (file)
@@ -167,6 +167,314 @@ public class NorthboundIT {
         }
     }
 
+    private void testNodeProperties(JSONObject node, Integer nodeId,
+            String nodeType, Integer timestamp, String timestampName,
+            Integer actionsValue, Integer capabilitiesValue,
+            Integer tablesValue, Integer buffersValue) throws JSONException {
+
+        JSONObject nodeInfo = node.getJSONObject("node");
+        Assert.assertEquals(nodeId, (Integer) nodeInfo.getInt("@id"));
+        Assert.assertEquals(nodeType, nodeInfo.getString("@type"));
+
+        JSONObject properties = node.getJSONObject("properties");
+
+        if (timestamp == null || timestampName == null) {
+            Assert.assertFalse(properties.has("timeStamp"));
+        } else {
+            Assert.assertEquals(
+                    timestamp,
+                    (Integer) properties.getJSONObject("timeStamp").getInt(
+                            "timestamp"));
+            Assert.assertEquals(
+                    timestampName,
+                    properties.getJSONObject("timeStamp").getString(
+                            "timestampName"));
+        }
+        if (actionsValue == null) {
+            Assert.assertFalse(properties.has("actions"));
+        } else {
+            Assert.assertEquals(actionsValue, (Integer) properties
+                    .getJSONObject("actions").getInt("actionsValue"));
+        }
+        if (capabilitiesValue == null) {
+            Assert.assertFalse(properties.has("capabilities"));
+        } else {
+            Assert.assertEquals(capabilitiesValue, (Integer) properties
+                    .getJSONObject("capabilities").getInt("capabilitiesValue"));
+        }
+        if (tablesValue == null) {
+            Assert.assertFalse(properties.has("tables"));
+        } else {
+            Assert.assertEquals(tablesValue, (Integer) properties
+                    .getJSONObject("tables").getInt("tablesValue"));
+        }
+        if (buffersValue == null) {
+            Assert.assertFalse(properties.has("buffers"));
+        } else {
+            Assert.assertEquals(buffersValue, (Integer) properties
+                    .getJSONObject("buffers").getInt("buffersValue"));
+        }
+    }
+
+    private void testNodeConnectorProperties(
+            JSONObject nodeConnectorProperties, Integer ncId, String ncType,
+            Integer nodeId, String nodeType, Integer state,
+            Integer capabilities, Integer bandwidth) throws JSONException {
+
+        JSONObject nodeConnector = nodeConnectorProperties
+                .getJSONObject("nodeconnector");
+        JSONObject node = nodeConnector.getJSONObject("node");
+        JSONObject properties = nodeConnectorProperties
+                .getJSONObject("properties");
+
+        Assert.assertEquals(ncId, (Integer) nodeConnector.getInt("@id"));
+        Assert.assertEquals(ncType, nodeConnector.getString("@type"));
+        Assert.assertEquals(nodeId, (Integer) node.getInt("@id"));
+        Assert.assertEquals(nodeType, node.getString("@type"));
+        if (state == null) {
+            Assert.assertFalse(properties.has("state"));
+        } else {
+            Assert.assertEquals(
+                    state,
+                    (Integer) properties.getJSONObject("state").getInt(
+                            "stateValue"));
+        }
+        if (capabilities == null) {
+            Assert.assertFalse(properties.has("capabilities"));
+        } else {
+            Assert.assertEquals(capabilities, (Integer) properties
+                    .getJSONObject("capabilities").getInt("capabilitiesValue"));
+        }
+        if (bandwidth == null) {
+            Assert.assertFalse(properties.has("bandwidth"));
+        } else {
+            Assert.assertEquals(
+                    bandwidth,
+                    (Integer) properties.getJSONObject("bandwidth").getInt(
+                            "bandwidthValue"));
+        }
+
+    }
+
+    @Test
+    public void testSwitchManager() {
+        String baseURL = "http://127.0.0.1:8080/controller/nb/v2/switch/default/";
+
+        // define Node/NodeConnector attributes for test
+        int nodeId_1 = 51966;
+        int nodeId_2 = 3366;
+        int nodeId_3 = 4477;
+        int nodeConnectorId_1 = 51966;
+        int nodeConnectorId_2 = 12;
+        int nodeConnectorId_3 = 34;
+        String nodeType = "STUB";
+        String ncType = "STUB";
+        int timestamp_1 = 100000;
+        String timestampName_1 = "connectedSince";
+        int actionsValue_1 = 2;
+        int capabilitiesValue_1 = 3;
+        int tablesValue_1 = 1;
+        int buffersValue_1 = 1;
+        int ncState = 1;
+        int ncCapabilities = 1;
+        int ncBandwidth = 1000000000;
+
+        // Test GET all nodes
+        try {
+            String result = getJsonResult(baseURL + "nodes");
+            JSONTokener jt = new JSONTokener(result);
+            JSONObject json = new JSONObject(jt);
+
+            // Test for first node
+            JSONObject node = getJsonInstance(json, "nodeProperties", nodeId_1);
+            Assert.assertNotNull(node);
+            testNodeProperties(node, nodeId_1, nodeType, timestamp_1,
+                    timestampName_1, actionsValue_1, capabilitiesValue_1,
+                    tablesValue_1, buffersValue_1);
+
+            // Test 2nd node, properties of 2nd node same as first node
+            node = getJsonInstance(json, "nodeProperties", nodeId_2);
+            Assert.assertNotNull(node);
+            testNodeProperties(node, nodeId_2, nodeType, timestamp_1,
+                    timestampName_1, actionsValue_1, capabilitiesValue_1,
+                    tablesValue_1, buffersValue_1);
+
+            // Test 3rd node, properties of 3rd node same as first node
+            node = getJsonInstance(json, "nodeProperties", nodeId_3);
+            Assert.assertNotNull(node);
+            testNodeProperties(node, nodeId_3, nodeType, timestamp_1,
+                    timestampName_1, actionsValue_1, capabilitiesValue_1,
+                    tablesValue_1, buffersValue_1);
+
+        } catch (Exception e) {
+            Assert.assertTrue(false);
+        }
+
+        // Test GET nodeConnectors of a node
+        try {
+            //Test first node
+            String result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
+            JSONTokener jt = new JSONTokener(result);
+            JSONObject json = new JSONObject(jt);
+            JSONObject nodeConnectorProperties = json
+                    .getJSONObject("nodeConnectorProperties");
+
+            testNodeConnectorProperties(nodeConnectorProperties,
+                    nodeConnectorId_1, ncType, nodeId_1, nodeType, ncState,
+                    ncCapabilities, ncBandwidth);
+
+            //Test second node
+            result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
+            jt = new JSONTokener(result);
+            json = new JSONObject(jt);
+            nodeConnectorProperties = json
+                    .getJSONObject("nodeConnectorProperties");
+
+            testNodeConnectorProperties(nodeConnectorProperties,
+                    nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
+                    ncCapabilities, ncBandwidth);
+
+            //Test third node
+            result = getJsonResult(baseURL + "node/STUB/" + nodeId_3);
+            jt = new JSONTokener(result);
+            json = new JSONObject(jt);
+
+            nodeConnectorProperties = json
+                    .getJSONObject("nodeConnectorProperties");
+            testNodeConnectorProperties(nodeConnectorProperties,
+                    nodeConnectorId_3, ncType, nodeId_3, nodeType, ncState,
+                    ncCapabilities, ncBandwidth);
+
+        } catch (Exception e) {
+            Assert.assertTrue(false);
+        }
+
+        // Test delete node property
+        try {
+            // Delete timestamp property from node1
+            String result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
+                    + "/property/timeStamp", "DELETE");
+            Assert.assertEquals(200, httpResponseCode.intValue());
+
+            // Check node1
+            result = getJsonResult(baseURL + "nodes");
+            JSONTokener jt = new JSONTokener(result);
+            JSONObject json = new JSONObject(jt);
+            JSONObject node = getJsonInstance(json, "nodeProperties", nodeId_1);
+            Assert.assertNotNull(node);
+            testNodeProperties(node, nodeId_1, nodeType, null, null,
+                    actionsValue_1, capabilitiesValue_1, tablesValue_1,
+                    buffersValue_1);
+
+            // Delete actions property from node2
+            result = getJsonResult(baseURL + "node/STUB/" + nodeId_2
+                    + "/property/actions", "DELETE");
+            Assert.assertEquals(200, httpResponseCode.intValue());
+
+            // Check node2
+            result = getJsonResult(baseURL + "nodes");
+            jt = new JSONTokener(result);
+            json = new JSONObject(jt);
+            node = getJsonInstance(json, "nodeProperties", nodeId_2);
+            Assert.assertNotNull(node);
+            testNodeProperties(node, nodeId_2, nodeType, timestamp_1,
+                    timestampName_1, null, capabilitiesValue_1, tablesValue_1,
+                    buffersValue_1);
+
+        } catch (Exception e) {
+            Assert.assertTrue(false);
+        }
+
+        // Test add property to node
+        try {
+            // Add Tier and Bandwidth property to node1
+            String result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
+                    + "/property/tier/1001", "PUT");
+            Assert.assertEquals(201, httpResponseCode.intValue());
+            result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
+                    + "/property/bandwidth/1002", "PUT");
+            Assert.assertEquals(201, httpResponseCode.intValue());
+
+            // Test for first node
+            result = getJsonResult(baseURL + "nodes");
+            JSONTokener jt = new JSONTokener(result);
+            JSONObject json = new JSONObject(jt);
+            JSONObject node = getJsonInstance(json, "nodeProperties", nodeId_1);
+            Assert.assertNotNull(node);
+            Assert.assertEquals(1001, node.getJSONObject("properties")
+                    .getJSONObject("tier").getInt("tierValue"));
+            Assert.assertEquals(1002, node.getJSONObject("properties")
+                    .getJSONObject("bandwidth").getInt("bandwidthValue"));
+
+        } catch (Exception e) {
+            Assert.assertTrue(false);
+        }
+
+        // Test delete nodeConnector property
+        try {
+            // Delete state property of nodeconnector1
+            String result = getJsonResult(baseURL + "nodeconnector/STUB/"
+                    + nodeId_1 + "/STUB/" + nodeConnectorId_1
+                    + "/property/state", "DELETE");
+            Assert.assertEquals(200, httpResponseCode.intValue());
+
+            result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
+            JSONTokener jt = new JSONTokener(result);
+            JSONObject json = new JSONObject(jt);
+            JSONObject nodeConnectorProperties = json
+                    .getJSONObject("nodeConnectorProperties");
+
+            testNodeConnectorProperties(nodeConnectorProperties,
+                    nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
+                    ncCapabilities, ncBandwidth);
+
+            // Delete capabilities property of nodeconnector2
+            result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_2
+                    + "/STUB/" + nodeConnectorId_2 + "/property/capabilities",
+                    "DELETE");
+            Assert.assertEquals(200, httpResponseCode.intValue());
+
+            result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
+            jt = new JSONTokener(result);
+            json = new JSONObject(jt);
+            nodeConnectorProperties = json
+                    .getJSONObject("nodeConnectorProperties");
+
+            testNodeConnectorProperties(nodeConnectorProperties,
+                    nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
+                    null, ncBandwidth);
+
+        } catch (Exception e) {
+            Assert.assertTrue(false);
+        }
+
+        // Test PUT nodeConnector property
+        try {
+            int newBandwidth = 1001;
+
+            // Add Name/Bandwidth property to nodeConnector1
+            String result = getJsonResult(baseURL + "nodeconnector/STUB/"
+                    + nodeId_1 + "/STUB/" + nodeConnectorId_1
+                    + "/property/bandwidth/" + newBandwidth, "PUT");
+            Assert.assertEquals(201, httpResponseCode.intValue());
+
+            result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
+            JSONTokener jt = new JSONTokener(result);
+            JSONObject json = new JSONObject(jt);
+            JSONObject nodeConnectorProperties = json
+                    .getJSONObject("nodeConnectorProperties");
+
+            // Check for new bandwidth value, state value removed from previous
+            // test
+            testNodeConnectorProperties(nodeConnectorProperties,
+                    nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
+                    ncCapabilities, newBandwidth);
+
+        } catch (Exception e) {
+            Assert.assertTrue(false);
+        }
+    }
+
     @Test
     public void testStatistics() {
         String actionTypes[] = { "drop", "loopback", "flood", "floodAll",
index e92583a33a9543c30c60b269ddc67a0c075c8561..d3b023512bebd5790559b7e047b813e0558395e9 100644 (file)
@@ -205,7 +205,7 @@ public class SwitchNorthbound {
         }
 
         handleNodeAvailability(containerName, nodeType, nodeId);
-        Node node = Node.fromString(nodeId);
+        Node node = Node.fromString(nodeType, nodeId);
 
         Property prop = switchManager.createProperty(propName, propValue);
         if (prop == null) {
@@ -262,8 +262,7 @@ public class SwitchNorthbound {
         }
 
         handleNodeAvailability(containerName, nodeType, nodeId);
-        Node node = Node.fromString(nodeId);
-
+        Node node = Node.fromString(nodeType, nodeId);
         Status ret = switchManager.removeNodeProp(node, propertyName);
         if (ret.isSuccess()) {
             return Response.ok().build();
@@ -316,8 +315,7 @@ public class SwitchNorthbound {
         }
 
         handleNodeAvailability(containerName, nodeType, nodeId);
-        Node node = Node.fromString(nodeId);
-
+        Node node = Node.fromString(nodeType, nodeId);
         List<NodeConnectorProperties> res = new ArrayList<NodeConnectorProperties>();
         Set<NodeConnector> ncs = switchManager.getNodeConnectors(node);
         if (ncs == null) {
@@ -397,12 +395,12 @@ public class SwitchNorthbound {
         }
 
         handleNodeAvailability(containerName, nodeType, nodeId);
-        Node node = Node.fromString(nodeId);
+        Node node = Node.fromString(nodeType, nodeId);
 
         handleNodeConnectorAvailability(containerName, node, nodeConnectorType,
                 nodeConnectorId);
         NodeConnector nc = NodeConnector
-                .fromStringNoNode(nodeConnectorId, node);
+                .fromStringNoNode(nodeConnectorType, nodeConnectorId, node);
 
         Property prop = switchManager.createProperty(propName, propValue);
         if (prop == null) {
@@ -470,13 +468,12 @@ public class SwitchNorthbound {
         }
 
         handleNodeAvailability(containerName, nodeType, nodeId);
-        Node node = Node.fromString(nodeId);
+        Node node = Node.fromString(nodeType, nodeId);
 
         handleNodeConnectorAvailability(containerName, node, nodeConnectorType,
                 nodeConnectorId);
         NodeConnector nc = NodeConnector
-                .fromStringNoNode(nodeConnectorId, node);
-
+                .fromStringNoNode(nodeConnectorType, nodeConnectorId, node);
         Status ret = switchManager.removeNodeConnectorProp(nc, propertyName);
         if (ret.isSuccess()) {
             return Response.ok().build();
index b3909a775bbe36156fa127e9b54841f02556a40e..22a4343f332ed2e79e7f7ecc979d8535acc4ea26 100644 (file)
@@ -42,9 +42,19 @@ public class InventoryService implements IPluginInInventoryService {
     private static final Logger logger = LoggerFactory
             .getLogger(InventoryService.class);
 
-    private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
-    private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
-
+    private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties
+                                                                  // are
+                                                                  // maintained
+                                                                  // in global
+                                                                  // container
+                                                                  // only
+    private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties
+                                                                                    // are
+                                                                                    // maintained
+                                                                                    // in
+                                                                                    // global
+                                                                                    // container
+                                                                                    // only
 
     /**
      * Function called by the dependency manager when all the required
@@ -55,51 +65,65 @@ public class InventoryService implements IPluginInInventoryService {
         nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
         nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
         Node.NodeIDType.registerIDType("STUB", Integer.class);
-        NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, "STUB");
-    }
+        NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class,
+                "STUB");
 
-    /**
-     * Function called by the dependency manager when at least one dependency
-     * become unsatisfied or when the component is shutting down because for
-     * example bundle is being stopped.
-     *
-     */
-    void destroy() {
+        setupNodeProps();
+        setupNodeConnectorProps();
     }
 
-    /**
-     * Function called by dependency manager after "init ()" is called and after
-     * the services provided by the class are registered in the service registry
-     *
-     */
-    void start() {
-    }
+    private void setupNodeConnectorProps() {
+        Map<String, Property> ncPropMap = new HashMap<String, Property>();
+        Capabilities cap = new Capabilities(
+                CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
+        ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
+        Bandwidth bw = new Bandwidth(Bandwidth.BW1Gbps);
+        ncPropMap.put(Bandwidth.BandwidthPropName, bw);
+        State st = new State(State.EDGE_UP);
+        ncPropMap.put(State.StatePropName, st);
 
-    /**
-     * Function called by the dependency manager before the services exported by
-     * the component are unregistered, this will be followed by a "destroy ()"
-     * calls
-     *
-     */
-    void stop() {
-    }
+        // setup property map for all node connectors
+        NodeConnector nc;
+        Node node;
+        try {
+            node = new Node("STUB", new Integer(0xCAFE));
+            nc = new NodeConnector("STUB", 0xCAFE, node);
+        } catch (ConstructionException e) {
+            nc = null;
+            node = null;
+        }
+        nodeConnectorProps.put(nc, ncPropMap);
 
-    /**
-     * Retrieve nodes from openflow
-     */
-    @Override
-    public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
+        try {
+            node = new Node("STUB", 3366);
+            nc = new NodeConnector("STUB", 12, node);
+        } catch (ConstructionException e) {
+            nc = null;
+            node = null;
+        }
+        nodeConnectorProps.put(nc, ncPropMap);
+
+        try {
+            node = new Node("STUB", 4477);
+            nc = new NodeConnector("STUB", 34, node);
+        } catch (ConstructionException e) {
+            nc = null;
+            node = null;
+        }
+        nodeConnectorProps.put(nc, ncPropMap);
 
-        //  setup nodeProps
+    }
+
+    private void setupNodeProps() {
         Map<String, Property> propMap = new HashMap<String, Property>();
 
-        Tables t = new Tables((byte)1);
+        Tables t = new Tables((byte) 1);
         propMap.put(Tables.TablesPropName, t);
-        Capabilities c = new Capabilities((int)3);
+        Capabilities c = new Capabilities((int) 3);
         propMap.put(Capabilities.CapabilitiesPropName, c);
-        Actions a = new Actions((int)2);
+        Actions a = new Actions((int) 2);
         propMap.put(Actions.ActionsPropName, a);
-        Buffers b = new Buffers((int)1);
+        Buffers b = new Buffers((int) 1);
         propMap.put(Buffers.BuffersPropName, b);
         Long connectedSinceTime = 100000L;
         TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
@@ -108,28 +132,61 @@ public class InventoryService implements IPluginInInventoryService {
 
         // setup property map for all nodes
         Node node;
-        try{
+        try {
             node = new Node("STUB", new Integer(0xCAFE));
-        }catch(ConstructionException e){
+        } catch (ConstructionException e) {
             node = null;
         }
 
         nodeProps.put(node, propMap);
 
-        try{
+        try {
             node = new Node("STUB", 3366);
-        }catch(ConstructionException e){
+        } catch (ConstructionException e) {
             node = null;
         }
         nodeProps.put(node, propMap);
 
-        try{
+        try {
             node = new Node("STUB", 4477);
-        }catch(ConstructionException e){
+        } catch (ConstructionException e) {
             node = null;
         }
         nodeProps.put(node, propMap);
 
+    }
+
+    /**
+     * Function called by the dependency manager when at least one dependency
+     * become unsatisfied or when the component is shutting down because for
+     * example bundle is being stopped.
+     *
+     */
+    void destroy() {
+    }
+
+    /**
+     * Function called by dependency manager after "init ()" is called and after
+     * the services provided by the class are registered in the service registry
+     *
+     */
+    void start() {
+    }
+
+    /**
+     * Function called by the dependency manager before the services exported by
+     * the component are unregistered, this will be followed by a "destroy ()"
+     * calls
+     *
+     */
+    void stop() {
+    }
+
+    /**
+     * Retrieve nodes from openflow
+     */
+    @Override
+    public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
         return nodeProps;
     }
 
@@ -139,49 +196,7 @@ public class InventoryService implements IPluginInInventoryService {
     @Override
     public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
             Boolean refresh) {
-
-        //  setup nodeConnectorProps
-        Map<String, Property> ncPropMap = new HashMap<String, Property>();
-        Capabilities cap = new Capabilities
-                (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
-        ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
-        Bandwidth bw = new Bandwidth (Bandwidth.BW1Gbps);
-        ncPropMap.put(Bandwidth.BandwidthPropName, bw);
-        State st = new State (State.EDGE_UP);
-        ncPropMap.put(State.StatePropName, st);
-
-        // setup property map for all node connectors
-        NodeConnector nc;
-        Node node;
-        try{
-            node = new Node("STUB", new Integer(0xCAFE));
-            nc = new NodeConnector("STUB", 0xCAFE, node);
-        }catch(ConstructionException e){
-            nc = null;
-            node = null;
-        }
-        nodeConnectorProps.put(nc, ncPropMap);
-
-        try{
-            node = new Node("STUB", 3366);
-            nc = new NodeConnector("STUB", 12, node);
-         } catch(ConstructionException e){
-            nc = null;
-            node = null;
-         }
-         nodeConnectorProps.put(nc, ncPropMap);
-
-         try{
-            node = new Node("STUB", 4477);
-            nc = new NodeConnector("STUB", 34, node);
-         }catch(ConstructionException e){
-            nc = null;
-            node = null;
-         }
-         nodeConnectorProps.put(nc, ncPropMap);
-
-         return nodeConnectorProps;
+        return nodeConnectorProps;
     }
 
-
 }
index 29d1c71204a68bde4edb0d66936b121590551ac2..a9eefd3a8a689d8b4d92bd76fc4ec0edf1198193 100644 (file)
@@ -46,7 +46,6 @@ import org.slf4j.LoggerFactory;
 
 public class DataPacketService implements IPluginOutDataPacketService,
         IDataPacketService {
-    private int RXMAXQUEUESIZE = 1000;
     private int TXMAXQUEUESIZE = 1000;
     protected static final Logger logger = LoggerFactory
             .getLogger(DataPacketService.class);
@@ -63,31 +62,21 @@ public class DataPacketService implements IPluginOutDataPacketService,
         pluginInDataService =
         new ConcurrentHashMap<String, IPluginInDataPacketService>();
     private Map<String, AtomicInteger> statistics = new HashMap<String, AtomicInteger>();
-    /**
-     * Queue for packets received from Data Path
-     */
-    private LinkedBlockingQueue<RawPacket> rxQueue = new LinkedBlockingQueue<RawPacket>(
-            RXMAXQUEUESIZE);
+
     /**
      * Queue for packets that need to be transmitted to Data Path
      */
     private LinkedBlockingQueue<RawPacket> txQueue = new LinkedBlockingQueue<RawPacket>(
-            RXMAXQUEUESIZE);
+            TXMAXQUEUESIZE);
     /**
      * Transmission thread
      */
     private Thread txThread = new Thread(new TxLoop(),
             "DataPacketService TX thread");
-    /**
-     * Receiving thread
-     */
-    private Thread rxThread = new Thread(new RxLoop(),
-            "DataPacketService RX thread");
 
     /**
      * Representation of a Data Packet Listener including of its
      * properties
-     *
      */
     private class DataPacketListener {
         // Key fields
@@ -152,49 +141,30 @@ public class DataPacketService implements IPluginOutDataPacketService,
 
     /**
      * Loop for processing Received packets
-     *
      */
-    private class RxLoop implements Runnable {
-        public void run() {
-            RawPacket pkt;
-            try {
-                for (pkt = rxQueue.take(); pkt != null; pkt = rxQueue.take()) {
-                    for (List<DataPacketListener> serialListeners : listenDataPacket) {
-                        int i = 0;
-                        for (i = 0; i < serialListeners.size(); i++) {
-                            RawPacket copyPkt = null;
-                            try {
-                                copyPkt = new RawPacket(pkt);
-                            } catch (ConstructionException cex) {
-                                logger.debug("Error while cloning the packet");
-                            }
-                            if (copyPkt == null) {
-                                increaseStat("RXPacketCopyFailed");
-                                continue;
-                            }
-                            DataPacketListener l = serialListeners.get(i);
-                            IListenDataPacket s = (l == null ? null
-                                    : l.listener);
-                            if (s != null) {
-                                try {
-                                    // TODO Make sure to filter based
-                                    // on the match too, later on
-                                    PacketResult res = s
-                                            .receiveDataPacket(copyPkt);
-                                    increaseStat("RXPacketSuccess");
-                                    if (res.equals(PacketResult.CONSUME)) {
-                                        increaseStat("RXPacketSerialExit");
-                                        break;
-                                    }
-                                } catch (Exception e) {
-                                    increaseStat("RXPacketFailedForException");
-                                }
-                            }
+    private void dispatchPacket(RawPacket pkt) {
+
+        // for now we treat all listeners as serial listeners
+        for (List<DataPacketListener> serialListeners : listenDataPacket) {
+            for (DataPacketListener l : serialListeners) {
+
+                // TODO: possibly deal with read-only and read-write packet
+                // copies
+                IListenDataPacket s = (l == null ? null : l.listener);
+                if (s != null) {
+                    try {
+                        // TODO Make sure to filter based on the match too,
+                        // later on
+                        PacketResult res = s.receiveDataPacket(pkt);
+                        increaseStat("RXPacketSuccess");
+                        if (res.equals(PacketResult.CONSUME)) {
+                            increaseStat("RXPacketSerialExit");
+                            break;
                         }
+                    } catch (Exception e) {
+                        increaseStat("RXPacketFailedForException");
                     }
                 }
-            } catch (InterruptedException e) {
-                // Not a big deal
             }
         }
     }
@@ -431,7 +401,6 @@ public class DataPacketService implements IPluginOutDataPacketService,
      */
     void init() {
         this.txThread.start();
-        this.rxThread.start();
     }
 
     /**
@@ -447,14 +416,11 @@ public class DataPacketService implements IPluginOutDataPacketService,
         this.indexDataPacket.clear();
         this.pluginInDataService.clear();
         this.statistics.clear();
-        this.rxQueue.clear();
         this.txQueue.clear();
         this.txThread.interrupt();
-        this.rxThread.interrupt();
         // Wait for them to be done
         try {
             this.txThread.join();
-            this.rxThread.join();
         } catch (InterruptedException ex) {
             // Not a big deal
         }
@@ -484,12 +450,8 @@ public class DataPacketService implements IPluginOutDataPacketService,
             return PacketResult.IGNORED;
         }
 
-        // If the queue was full don't wait, rather increase a counter
-        // for it
-        if (!this.rxQueue.offer(inPkt)) {
-            increaseStat("fullRXQueue");
-            return PacketResult.IGNORED;
-        }
+        // send the packet off to be processed by listeners
+        this.dispatchPacket(inPkt);
 
         // Walk the chain of listener going first throw all the
         // parallel ones and for each parallel in serial
index 0ea82f8fb8586fa52b0692316491c526241b688f..9532d4efc9f92a4fbabe32e6ab11b79665e81e37 100644 (file)
@@ -48,8 +48,12 @@ public class YangToSourcesPluginTestIT {
         Verifier v = setUp("AdditionalConfig/", false);
         v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}");
         v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}");
-        v.verifyTextInLog("../files marked as resources: META-INF/yang");
-        v.verifyTextInLog("target/generated-resources marked as resources for generator: org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
+        v.verifyTextInLog(File.separator
+                + "files marked as resources: META-INF" + File.separator
+                + "yang");
+        v.verifyTextInLog("target"
+                + File.separator
+                + "generated-resources marked as resources for generator: org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
     }
 
     @Test
@@ -105,9 +109,8 @@ public class YangToSourcesPluginTestIT {
 
     static Verifier setUp(String project, boolean ignoreF)
             throws VerificationException {
-        final URL path = YangToSourcesPluginTestIT
-                .class.getResource("/" + project
-                + "pom.xml");
+        final URL path = YangToSourcesPluginTestIT.class.getResource("/"
+                + project + "pom.xml");
         File parent = new File(path.getPath());
         Verifier verifier = new Verifier(parent.getParent());
         if (ignoreF)
@@ -125,9 +128,8 @@ public class YangToSourcesPluginTestIT {
 
     @Test
     public void testFindResourceOnCp() throws VerificationException {
-        Verifier v1 = new Verifier(
-                new File(getClass().getResource("/GenerateTest1/pom.xml")
-                        .getPath()).getParent());
+        Verifier v1 = new Verifier(new File(getClass().getResource(
+                "/GenerateTest1/pom.xml").getPath()).getParent());
         v1.executeGoal("clean");
         v1.executeGoal("package");
         v1.assertFilePresent("target/classes/META-INF/yang/testfile1.yang");
index 7b83af42428d9e6ebbda79b301e80f1672c114fd..e3b0b31215bef2a6deac7457d152d19ec81d1115 100644 (file)
@@ -216,7 +216,7 @@ final class Util {
                         String entryName = entry.getName();
 
                         if (entryName
-                                .startsWith(YangToSourcesProcessor.META_INF_YANG_STRING)) {
+                                .startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)) {
                             if (entry.isDirectory() == false
                                     && entryName.endsWith(".yang")) {
                                 foundFilesForReporting.add(entryName);
index a70ff956f03977082ecf74346b9ac93e7a73b67f..a7b7f429ccbffbd9bf4f4593094989446914105f 100644 (file)
@@ -40,6 +40,7 @@ class YangToSourcesProcessor {
     static final String LOG_PREFIX = "yang-to-sources:";
     static final String META_INF_YANG_STRING = "META-INF" + File.separator
             + "yang";
+    static final String META_INF_YANG_STRING_JAR = "META-INF" + "/" + "yang";
     static final File META_INF_YANG_DIR = new File(META_INF_YANG_STRING);
 
     private final Log log;
index ed23b5f067c45ebd000ac52fffc919e9707800ef..85a97f0b852e99fa728ab4366e69e8dda775dd93 100644 (file)
@@ -267,6 +267,18 @@ public interface IUserManager extends UserDetailsService {
      */
     public ISessionManager getSessionManager();
 
+    /**
+     * Checks if the specified role belongs to any application. Usually an
+     * application will call this function when configuring a role, to check if
+     * that role is already being used by another application.
+     *
+     * @param role
+     *            The role to check
+     * @return true if the specified role belongs to any application or if the
+     *         role is a well-known controller role, false otherwise.
+     */
+    public boolean isRoleInUse(String role);
+
     /* non-Javadoc
      * Returns the password for a given user
      *
index 5ddf6be6c54914e9f0cf0047c0dd272ea7813590..e835887606273ce478ae0cdc63c534b9bab8c253 100644 (file)
@@ -156,9 +156,9 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
                     "usermanager.authorizationSaveConfigEvent",
                     EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
         } catch (CacheConfigException cce) {
-            logger.error("\nCache configuration invalid - check cache mode");
+            logger.error("Cache configuration invalid - check cache mode");
         } catch (CacheExistException ce) {
-            logger.error("\nCache already exits - destroy and recreate if needed");
+            logger.debug("Skipping cache creation as already present");
         }
     }
 
@@ -172,43 +172,43 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         activeUsers = (ConcurrentMap<String, AuthenticatedUser>) clusterGlobalService
                 .getCache("usermanager.activeUsers");
         if (activeUsers == null) {
-            logger.error("\nFailed to get cache for activeUsers");
+            logger.error("Failed to get cache for activeUsers");
         }
 
         localUserConfigList = (ConcurrentMap<String, UserConfig>) clusterGlobalService
                 .getCache("usermanager.localUserConfigList");
         if (localUserConfigList == null) {
-            logger.error("\nFailed to get cache for localUserConfigList");
+            logger.error("Failed to get cache for localUserConfigList");
         }
 
         remoteServerConfigList = (ConcurrentMap<String, ServerConfig>) clusterGlobalService
                 .getCache("usermanager.remoteServerConfigList");
         if (remoteServerConfigList == null) {
-            logger.error("\nFailed to get cache for remoteServerConfigList");
+            logger.error("Failed to get cache for remoteServerConfigList");
         }
 
         authorizationConfList = (ConcurrentMap<String, AuthorizationConfig>) clusterGlobalService
                 .getCache("usermanager.authorizationConfList");
         if (authorizationConfList == null) {
-            logger.error("\nFailed to get cache for authorizationConfList");
+            logger.error("Failed to get cache for authorizationConfList");
         }
 
         localUserListSaveConfigEvent = (ConcurrentMap<Long, String>) clusterGlobalService
                 .getCache("usermanager.localUserSaveConfigEvent");
         if (localUserListSaveConfigEvent == null) {
-            logger.error("\nFailed to get cache for localUserSaveConfigEvent");
+            logger.error("Failed to get cache for localUserSaveConfigEvent");
         }
 
         remoteServerSaveConfigEvent = (ConcurrentMap<Long, String>) clusterGlobalService
                 .getCache("usermanager.remoteServerSaveConfigEvent");
         if (remoteServerSaveConfigEvent == null) {
-            logger.error("\nFailed to get cache for remoteServerSaveConfigEvent");
+            logger.error("Failed to get cache for remoteServerSaveConfigEvent");
         }
 
         authorizationSaveConfigEvent = (ConcurrentMap<Long, String>) clusterGlobalService
                 .getCache("usermanager.authorizationSaveConfigEvent");
         if (authorizationSaveConfigEvent == null) {
-            logger.error("\nFailed to get cache for authorizationSaveConfigEvent");
+            logger.error("Failed to get cache for authorizationSaveConfigEvent");
         }
     }
 
@@ -866,29 +866,29 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
 
     @Override
     public List<String> getUserRoles(String userName) {
-        if (userName == null) {
-            return new ArrayList<String>(0);
+        List<String> roles = null;
+        if (userName != null) {
+            /*
+             * First look in active users then in local configured users,
+             * finally in local authorized users
+             */
+            if (activeUsers.containsKey(userName)) {
+                roles = activeUsers.get(userName).getUserRoles();
+            } else if (localUserConfigList.containsKey(userName)) {
+                roles = localUserConfigList.get(userName).getRoles();
+            } else if (authorizationConfList.containsKey(userName)) {
+                roles = authorizationConfList.get(userName).getRoles();
+            }
         }
-        AuthenticatedUser locatedUser = activeUsers.get(userName);
-        return (locatedUser == null) ? new ArrayList<String>(0) : locatedUser
-                .getUserRoles();
+        return (roles == null) ? new ArrayList<String>(0) : roles;
     }
 
     @Override
     public UserLevel getUserLevel(String username) {
-        // Returns the controller well-know user level for the passed user
-        List<String> rolesNames = null;
-
-        // First check in active users then in local configured users
-        if (activeUsers.containsKey(username)) {
-            List<String> roles = activeUsers.get(username).getUserRoles();
-            rolesNames = (roles == null || roles.isEmpty()) ? null : roles;
-        } else if (localUserConfigList.containsKey(username)) {
-            UserConfig config = localUserConfigList.get(username);
-            rolesNames = (config == null) ? null : config.getRoles();
-        }
+        // Returns the highest controller user level for the passed user
+        List<String> rolesNames = getUserRoles(username);
 
-        if (rolesNames == null) {
+        if (rolesNames.isEmpty()) {
             return UserLevel.NOUSER;
         }
 
@@ -926,19 +926,11 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
 
     @Override
     public List<UserLevel> getUserLevels(String username) {
-        // Returns the controller well-know user levels for the passed user
-        List<String> rolesNames = null;
+        // Returns the controller user levels for the passed user
+        List<String> rolesNames =  getUserRoles(username);
         List<UserLevel> levels = new ArrayList<UserLevel>();
 
-        if (activeUsers.containsKey(username)) {
-            List<String> roles = activeUsers.get(username).getUserRoles();
-            rolesNames = (roles == null || roles.isEmpty()) ? null : roles;
-        } else if (localUserConfigList.containsKey(username)) {
-            UserConfig config = localUserConfigList.get(username);
-            rolesNames = (config == null) ? null : config.getRoles();
-        }
-
-        if (rolesNames == null) {
+        if (rolesNames.isEmpty()) {
             return levels;
         }
 
@@ -1075,7 +1067,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
 
     }
 
-    // following are setters for use in unit testing
+    // Following are setters for use in unit testing
     void setLocalUserConfigList(ConcurrentMap<String, UserConfig> ucl) {
         if (ucl != null) {
             this.localUserConfigList = ucl;
@@ -1119,4 +1111,32 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
     public String getPassword(String username) {
         return localUserConfigList.get(username).getPassword();
     }
+
+    @Override
+    public boolean isRoleInUse(String role) {
+        if (role == null || role.isEmpty()) {
+            return false;
+        }
+        // Check against controller roles
+        if (role.equals(UserLevel.SYSTEMADMIN.toString())
+                || role.equals(UserLevel.NETWORKADMIN.toString())
+                || role.equals(UserLevel.NETWORKOPERATOR.toString())) {
+            return true;
+        }
+        // Check if container roles
+        if (containerAuthorizationClient != null) {
+            if (containerAuthorizationClient.isApplicationRole(role)) {
+                return true;
+            }
+        }
+        // Finally if application role
+        if (applicationAuthorizationClients != null) {
+            for (IResourceAuthorization client : this.applicationAuthorizationClients) {
+                if (client.isApplicationRole(role)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }
index 626011bd695fc0288f9a064ac682df75cea17e8b..df421e4fe6c2a017c656ce70e93327b2175abec9 100644 (file)
@@ -55,14 +55,17 @@ public class UserManagerImplTest {
                         // Server config can't be empty
                         static final long serialVersionUID = 8645L;
 
+                        @Override
                         public String getAddress() {
                             return "1.1.1.1";
                         }
 
+                        @Override
                         public String getSecret() {
                             return "secret";
                         }
 
+                        @Override
                         public String getProtocol() {
                             return "IPv4";
                         }
@@ -80,11 +83,21 @@ public class UserManagerImplTest {
                             "7029,7455,8165,7029,7881", roles));
                 }
             });
+
+            um.setAuthorizationConfList(new ConcurrentHashMap<String, AuthorizationConfig>() {
+                static final long serialVersionUID = 2L;
+                {
+                    List<String> roles = new ArrayList<String>(3);
+                    roles.add(UserLevel.NETWORKOPERATOR.toString());
+                    roles.add("Container1-Admin");
+                    roles.add("Application2-User");
+
+                    put("Andrew", new AuthorizationConfig("Andrew", roles));
+                }
+            });
             // instantiate an empty activeUser collection
             um.setActiveUsers(new ConcurrentHashMap<String, AuthenticatedUser>());
-
         }
-
     }
 
     /**
@@ -97,11 +110,13 @@ public class UserManagerImplTest {
         // instantiate an anonymous AAAProvider
         IAAAProvider a3p = new IAAAProvider() {
 
+            @Override
             public AuthResponse authService(String userName, String password,
                     String server, String secretKey) {
                 return new AuthResponse();
             };
 
+            @Override
             public String getName() {
                 return "dummyAAAProvider";
             }
@@ -254,6 +269,9 @@ public class UserManagerImplTest {
         Assert.assertTrue(um.getUserLevel("Jack") == UserLevel.SYSTEMADMIN);
         // Run the check on configured users
         Assert.assertTrue(um.getUserLevel("John") == UserLevel.NETWORKOPERATOR);
-        Assert.assertTrue(um.getUserLevel("Andrew") == UserLevel.NOUSER);
+        // Run the check on local authorized users
+        Assert.assertTrue(um.getUserLevel("Andrew") == UserLevel.NETWORKOPERATOR);
+        // Non locally known user
+        Assert.assertTrue(um.getUserLevel("Tom") == UserLevel.NOUSER);
     }
 }