Work toward ONOS-1451: Separate Event Key space per instance

Misc changes and cleanup:
* Added new class OnosInstanceId
* Replace (as appropriate) the string controllerId (and associated methods)
  with the new class OnosInstanceId
* Renaming: Host -> Device
  - Method getDeviceID -> getHostID
  - Changed Host Key ID prefix 'D' to 'H'
  - Few renaming of Host -> Device inside Javadoc

Change-Id: I59c20d68277ecde2f7df4e7097a4a52d5786df1b
diff --git a/src/test/java/net/onrc/onos/core/registry/StandaloneRegistryTest.java b/src/test/java/net/onrc/onos/core/registry/StandaloneRegistryTest.java
index 6eb6687..88a1177 100644
--- a/src/test/java/net/onrc/onos/core/registry/StandaloneRegistryTest.java
+++ b/src/test/java/net/onrc/onos/core/registry/StandaloneRegistryTest.java
@@ -18,6 +18,7 @@
 
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.onrc.onos.core.registry.IControllerRegistryService.ControlChangeCallback;
+import net.onrc.onos.core.util.OnosInstanceId;
 
 import org.junit.After;
 import org.junit.Before;
@@ -185,25 +186,26 @@
     }
 
     /**
-     * Test if {@link StandaloneRegistry#getControllerId()} can return correct ID.
+     * Test if {@link StandaloneRegistry#getOnosInstanceId()} can return
+     * correct ID.
      *
      * @throws RegistryException
      */
     @Test
-    public void testGetControllerId() throws RegistryException {
+    public void testGetOnosInstanceId() throws RegistryException {
         String controllerIdToRegister = "test";
 
         // try before controller is registered
-        String controllerId = registry.getControllerId();
-        assertNull(controllerId);
+        OnosInstanceId onosInstanceId = registry.getOnosInstanceId();
+        assertNull(onosInstanceId);
 
         // register
         registry.registerController(controllerIdToRegister);
 
-        // call getControllerId and verify
-        controllerId = registry.getControllerId();
-        assertNotNull(controllerId);
-        assertEquals(controllerIdToRegister, controllerId);
+        // call getOnosInstanceId and verify
+        onosInstanceId = registry.getOnosInstanceId();
+        assertNotNull(onosInstanceId);
+        assertEquals(controllerIdToRegister, onosInstanceId.toString());
     }
 
     /**
diff --git a/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java b/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java
index ca56736..5490162 100644
--- a/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java
+++ b/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java
@@ -9,6 +9,7 @@
 import net.floodlightcontroller.test.FloodlightTestCase;
 import net.onrc.onos.core.registry.StandaloneRegistryTest.LoggingCallback;
 import net.onrc.onos.core.registry.ZookeeperRegistry.SwitchLeaderListener;
+import net.onrc.onos.core.util.OnosInstanceId;
 
 import org.apache.curator.RetryPolicy;
 import org.apache.curator.framework.CuratorFramework;
@@ -115,25 +116,26 @@
     }
 
     /**
-     * Test if {@link ZookeeperRegistry#getControllerId()} correctly returns registered ID.
+     * Test if {@link ZookeeperRegistry#getOnosInstanceId()} correctly returns
+     * registered ID.
      *
      * @throws Exception
      */
     @Test
-    public void testGetControllerId() throws Exception {
+    public void testGetOnosInstanceId() throws Exception {
         String controllerIdToRegister = "controller1";
 
         // try before controller is registered
-        String controllerId = registry.getControllerId();
-        assertNull(controllerId);
+        OnosInstanceId onosInstanceId = registry.getOnosInstanceId();
+        assertNull(onosInstanceId);
 
         // register
         registry.registerController(controllerIdToRegister);
 
-        // call getControllerId and verify
-        controllerId = registry.getControllerId();
-        assertNotNull(controllerId);
-        assertEquals(controllerIdToRegister, controllerId);
+        // call getOnosInstanceId and verify
+        onosInstanceId = registry.getOnosInstanceId();
+        assertNotNull(onosInstanceId);
+        assertEquals(controllerIdToRegister, onosInstanceId.toString());
     }
 
     /**
diff --git a/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java b/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
index 79dfc89..ae0a936 100644
--- a/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
+++ b/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
@@ -22,6 +22,7 @@
 import net.onrc.onos.core.metrics.OnosMetrics;
 import net.onrc.onos.core.registry.IControllerRegistryService;
 import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.OnosInstanceId;
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
 import net.onrc.onos.core.util.TestUtils;
@@ -277,7 +278,8 @@
 
         // Generate a new Switch Mastership event
         Dpid dpid = new Dpid(100L);
-        String onosInstanceId = "ONOS-Test-Instance-ID";
+        OnosInstanceId onosInstanceId =
+            new OnosInstanceId("ONOS-Test-Instance-ID");
         Role role = Role.MASTER;
         MastershipEvent mastershipEvent =
             new MastershipEvent(dpid, onosInstanceId, role);
@@ -303,7 +305,8 @@
 
         // Generate a new Switch Mastership event
         Dpid dpid = new Dpid(100L);
-        String onosInstanceId = "ONOS-Test-Instance-ID";
+        OnosInstanceId onosInstanceId =
+            new OnosInstanceId("ONOS-Test-Instance-ID");
         Role role = Role.MASTER;
         MastershipEvent mastershipEvent =
             new MastershipEvent(dpid, onosInstanceId, role);
diff --git a/src/test/java/net/onrc/onos/core/util/OnosInstanceIdTest.java b/src/test/java/net/onrc/onos/core/util/OnosInstanceIdTest.java
new file mode 100644
index 0000000..bec3cd8
--- /dev/null
+++ b/src/test/java/net/onrc/onos/core/util/OnosInstanceIdTest.java
@@ -0,0 +1,79 @@
+package net.onrc.onos.core.util;
+
+import org.junit.Test;
+
+import static net.onrc.onos.core.util.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for class {@link OnosInstanceId}.
+ */
+public class OnosInstanceIdTest {
+    /**
+     * Tests the immutability of {@link OnosInstanceId}.
+     */
+    @Test
+    public void testImmutable() {
+        assertThatClassIsImmutable(OnosInstanceId.class);
+    }
+
+    /**
+     * Tests valid class constructor for a string.
+     */
+    @Test
+    public void testConstructorForString() {
+        OnosInstanceId id = new OnosInstanceId("ONOS-ID");
+        assertEquals(id.toString(), "ONOS-ID");
+    }
+
+    /**
+     * Tests invalid class constructor for a null string.
+     */
+    @Test(expected = NullPointerException.class)
+    public void testInvalidConstructorNullString() {
+        OnosInstanceId id = new OnosInstanceId(null);
+    }
+
+    /**
+     * Tests invalid class constructor for an empty string.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testInvalidConstructors() {
+        // Check constructor for invalid ID: empty string
+        OnosInstanceId id = new OnosInstanceId("");
+    }
+
+    /**
+     * Tests equality of {@link OnosInstanceId}.
+     */
+    @Test
+    public void testEquality() {
+        OnosInstanceId id1 = new OnosInstanceId("ONOS-ID");
+        OnosInstanceId id2 = new OnosInstanceId("ONOS-ID");
+
+        assertThat(id1, is(id2));
+    }
+
+    /**
+     * Tests non-equality of {@link OnosInstanceId}.
+     */
+    @Test
+    public void testNonEquality() {
+        OnosInstanceId id1 = new OnosInstanceId("ONOS-ID1");
+        OnosInstanceId id2 = new OnosInstanceId("ONOS-ID2");
+
+        assertThat(id1, is(not(id2)));
+    }
+
+    /**
+     * Tests object string representation.
+     */
+    @Test
+    public void testToString() {
+        OnosInstanceId id = new OnosInstanceId("ONOS-ID");
+        assertEquals("ONOS-ID", id.toString());
+    }
+}