SEBA-1007-Minor version upgrade

Change-Id: If1b012f93304aa8f3b76d39e3b309231b9e017c0
diff --git a/api/pom.xml b/api/pom.xml
index cde1c47..b9afe7f 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -24,6 +24,7 @@
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
+    <version>${dhcpl2relay.api.version}</version>
     <artifactId>dhcpl2relay-api</artifactId>
     <packaging>bundle</packaging>
     <description>DHCP L2 Relay application API</description>
diff --git a/app/app.xml b/app/app.xml
index f2d29af..b2b3cfc 100644
--- a/app/app.xml
+++ b/app/app.xml
@@ -18,8 +18,9 @@
      version="${project.version}"
      category="default" url="http://onosproject.org" title="DHCP L2 Relay"
      featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
-     features="${project.artifactId}" apps="org.opencord.sadis">
+     features="${project.artifactId}">
     <description>${project.description}</description>
     <artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact>
-    <artifact>mvn:${project.groupId}/dhcpl2relay-api/${project.version}</artifact>
+    <artifact>mvn:${project.groupId}/dhcpl2relay-api/${dhcpl2relay.api.version}</artifact>
+    <artifact>mvn:${project.groupId}/sadis-api/${sadis.api.version}</artifact>
 </app>
diff --git a/app/features.xml b/app/features.xml
index ba4b895..f23167b 100644
--- a/app/features.xml
+++ b/app/features.xml
@@ -18,7 +18,8 @@
     <feature name="${project.artifactId}" version="${project.version}"
              description="${project.description}">
         <feature>onos-api</feature>
-        <bundle>mvn:${project.groupId}/dhcpl2relay-api/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/dhcpl2relay-api/${dhcpl2relay.api.version}</bundle>
         <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/sadis-api/${sadis.api.version}</bundle>
     </feature>
 </features>
diff --git a/app/pom.xml b/app/pom.xml
index 25a8fab..4137aed 100644
--- a/app/pom.xml
+++ b/app/pom.xml
@@ -65,7 +65,7 @@
         <dependency>
             <groupId>org.opencord</groupId>
             <artifactId>dhcpl2relay-api</artifactId>
-            <version>${project.version}</version>
+            <version>${dhcpl2relay.api.version}</version>
             <scope>compile</scope>
         </dependency>
 
diff --git a/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java b/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java
index 7f523b9..84765a9 100755
--- a/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java
+++ b/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java
@@ -116,6 +116,7 @@
 import org.osgi.service.component.annotations.Modified;
 import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -137,7 +138,7 @@
 public class DhcpL2Relay
         extends AbstractListenerManager<DhcpL2RelayEvent, DhcpL2RelayListener>
         implements DhcpL2RelayService {
-
+    private static final String SADIS_NOT_RUNNING = "Sadis is not running.";
     public static final String DHCP_L2RELAY_APP = "org.opencord.dhcpl2relay";
     private static final String HOST_LOC_PROVIDER =
             "org.onosproject.provider.host.impl.HostLocationProvider";
@@ -147,8 +148,8 @@
 
     private final Set<ConfigFactory> factories = ImmutableSet.of(
             new ConfigFactory<ApplicationId, DhcpL2RelayConfig>(APP_SUBJECT_FACTORY,
-                                                                DhcpL2RelayConfig.class,
-                                                                "dhcpl2relay") {
+                    DhcpL2RelayConfig.class,
+                    "dhcpl2relay") {
                 @Override
                 public DhcpL2RelayConfig createConfig() {
                     return new DhcpL2RelayConfig();
@@ -171,8 +172,11 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     protected ComponentConfigService componentConfigService;
 
-    @Reference(cardinality = ReferenceCardinality.MANDATORY)
-    protected SadisService sadisService;
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL,
+            bind = "bindSadisService",
+            unbind = "unbindSadisService",
+            policy = ReferencePolicy.DYNAMIC)
+    protected volatile SadisService sadisService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     protected DeviceService deviceService;
@@ -263,8 +267,11 @@
         mastershipService.addListener(changeListener);
         deviceService.addListener(deviceListener);
 
-        subsService = sadisService.getSubscriberInfoService();
-
+        if (sadisService != null) {
+            subsService = sadisService.getSubscriberInfoService();
+        } else {
+            log.warn(SADIS_NOT_RUNNING);
+        }
         factories.forEach(cfgService::registerConfigFactory);
         //update the dhcp server configuration.
         updateConfig();
@@ -326,11 +333,23 @@
                 packetProcessorExecutor.shutdown();
             }
             packetProcessorExecutor = newFixedThreadPool(packetProcessorThreads,
-                                                         groupedThreads("onos/dhcp",
-                                                                        "dhcp-packet-%d", log));
+                    groupedThreads("onos/dhcp",
+                            "dhcp-packet-%d", log));
         }
     }
 
+    protected void bindSadisService(SadisService service) {
+        sadisService = service;
+        subsService = sadisService.getSubscriberInfoService();
+        log.info("Sadis-service binds to onos.");
+    }
+
+    protected void unbindSadisService(SadisService service) {
+        sadisService = null;
+        subsService = null;
+        log.info("Sadis-service unbinds from onos.");
+    }
+
     @Override
     public Map<String, DhcpAllocationInfo> getAllocationInfo() {
         return ImmutableMap.copyOf(allocations.asJavaMap());
@@ -464,6 +483,10 @@
      * are returned
      */
     private List<ConnectPoint> getUplinkPortsOfOlts() {
+        if (subsService == null) {
+            log.warn(SADIS_NOT_RUNNING);
+            return Lists.newArrayList();
+        }
         List<ConnectPoint> cps = new ArrayList<>();
 
         // find all the olt devices and if their uplink ports are visible
@@ -478,7 +501,7 @@
             }
 
             String devSerialNo = d.serialNumber();
-            SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo);
+            SubscriberAndDeviceInformation deviceInfo = getSubscriberAndDeviceInfo(devSerialNo);
             log.debug("getUplinkPortsOfOlts: Found device: {}", deviceInfo);
             if (deviceInfo != null) {
                 // check if the uplink port with that number is available on the device
@@ -493,6 +516,14 @@
         return cps;
     }
 
+    private SubscriberAndDeviceInformation getSubscriberAndDeviceInfo(String portOrDevice) {
+        if (subsService == null) {
+            log.warn(SADIS_NOT_RUNNING);
+            return null;
+        }
+        return subsService.get(portOrDevice);
+    }
+
     /**
      * Returns whether the passed port is the uplink port of the olt device.
      */
@@ -500,7 +531,7 @@
         log.debug("isUplinkPortOfOlt: DeviceId: {} Port: {}", dId, p);
 
         Device d = deviceService.getDevice(dId);
-        SubscriberAndDeviceInformation deviceInfo = subsService.get(d.serialNumber());
+        SubscriberAndDeviceInformation deviceInfo = getSubscriberAndDeviceInfo(d.serialNumber());
 
         if (deviceInfo != null) {
             return (deviceInfo.uplinkPort() == p.number().toLong());
@@ -515,7 +546,7 @@
     private ConnectPoint getUplinkConnectPointOfOlt(DeviceId dId) {
 
         Device d = deviceService.getDevice(dId);
-        SubscriberAndDeviceInformation deviceInfo = subsService.get(d.serialNumber());
+        SubscriberAndDeviceInformation deviceInfo = getSubscriberAndDeviceInfo(d.serialNumber());
         log.debug("getUplinkConnectPointOfOlt DeviceId: {} devInfo: {}", dId, deviceInfo);
         if (deviceInfo != null) {
             PortNumber pNum = PortNumber.portNumber(deviceInfo.uplinkPort());
@@ -1148,7 +1179,7 @@
         private SubscriberAndDeviceInformation getSubscriber(ConnectPoint subsCp) {
             if (subsCp != null) {
                 String portName = getPortName(subsCp);
-                return subsService.get(portName);
+                return getSubscriberAndDeviceInfo(portName);
             }
             return null;
         }
@@ -1163,7 +1194,7 @@
          */
         private SubscriberAndDeviceInformation getSubscriber(PacketContext context) {
             String portName = getPortName(context.inPacket().receivedFrom());
-            return subsService.get(portName);
+            return getSubscriberAndDeviceInfo(portName);
         }
 
         /**
@@ -1267,7 +1298,7 @@
             String serialNo = deviceService
                     .getDevice(context.inPacket().receivedFrom().deviceId())
                     .serialNumber();
-            return subsService.get(serialNo);
+            return getSubscriberAndDeviceInfo(serialNo);
         }
 
     }
diff --git a/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java
index ccecb51..2392947 100755
--- a/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java
+++ b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java
@@ -354,6 +354,11 @@
         }
 
         @Override
+        public void clearLocalData() {
+
+        }
+
+        @Override
         public void invalidateAll() {}
         @Override
         public void invalidateId(String id) {}
diff --git a/pom.xml b/pom.xml
index 71317e5..2f648c2 100755
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
     <parent>
         <groupId>org.onosproject</groupId>
         <artifactId>onos-dependencies</artifactId>
-        <version>2.2.2</version>
+        <version>2.2.7</version>
     </parent>
 
     <groupId>org.opencord</groupId>
@@ -32,7 +32,8 @@
     <url>http://opencord.org</url>
 
     <properties>
-        <sadis.api.version>5.2.0</sadis.api.version>
+        <sadis.api.version>5.3.0-SNAPSHOT</sadis.api.version>
+        <dhcpl2relay.api.version>2.4.0-SNAPSHOT</dhcpl2relay.api.version>
     </properties>
 
     <modules>