Add upgrade event listener to UpgradeService on initialization of MastershipManager

Change-Id: Ic1d419d1c5908bddee633897391fa6ef11c525b3
diff --git a/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java b/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java
index 0cab28f..8987542 100644
--- a/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java
+++ b/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java
@@ -132,6 +132,7 @@
 
         requestRoleTimer = createTimer("Mastership", "requestRole", "responseTime");
         localNodeId = clusterService.getLocalNode().id();
+        upgradeService.addListener(upgradeEventListener);
         eventDispatcher.addSink(MastershipEvent.class, listenerRegistry);
         store.setDelegate(delegate);
         log.info("Started");
@@ -150,6 +151,7 @@
     @Deactivate
     public void deactivate() {
         eventDispatcher.removeSink(MastershipEvent.class);
+        upgradeService.removeListener(upgradeEventListener);
         store.unsetDelegate(delegate);
         log.info("Stopped");
         cfgService.unregisterProperties(getClass(), false);
diff --git a/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java b/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java
index 14c40fd..0f75445 100644
--- a/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java
@@ -49,6 +49,7 @@
 
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.Futures;
+import org.onosproject.upgrade.impl.UpgradeServiceAdapter;
 
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.expect;
@@ -104,6 +105,7 @@
         injectEventDispatcher(mgr, new TestEventDispatcher());
         testClusterService = new TestClusterService();
         mgr.clusterService = testClusterService;
+        mgr.upgradeService = new UpgradeServiceAdapter();
         mgr.store = new TestSimpleMastershipStore(mgr.clusterService);
         regionStore = new DistributedRegionStore();
         TestUtils.setField(regionStore, "storageService", new TestStorageService());
diff --git a/core/net/src/test/java/org/onosproject/upgrade/impl/UpgradeServiceAdapter.java b/core/net/src/test/java/org/onosproject/upgrade/impl/UpgradeServiceAdapter.java
new file mode 100644
index 0000000..cd327c4
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/upgrade/impl/UpgradeServiceAdapter.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.upgrade.impl;
+
+import org.onosproject.core.Version;
+import org.onosproject.upgrade.Upgrade;
+import org.onosproject.upgrade.UpgradeEventListener;
+import org.onosproject.upgrade.UpgradeService;
+
+/**
+ * Upgrade service adapter.
+ */
+public class UpgradeServiceAdapter implements UpgradeService {
+    @Override
+    public boolean isUpgrading() {
+        return false;
+    }
+
+    @Override
+    public Upgrade getState() {
+        return null;
+    }
+
+    @Override
+    public Version getVersion() {
+        return null;
+    }
+
+    @Override
+    public boolean isLocalActive() {
+        return false;
+    }
+
+    @Override
+    public boolean isLocalUpgraded() {
+        return false;
+    }
+
+    @Override
+    public void addListener(UpgradeEventListener listener) {
+
+    }
+
+    @Override
+    public void removeListener(UpgradeEventListener listener) {
+
+    }
+}