Refactoring abstract driver loader to assure that default drivers get loaded first by default.
Change-Id: I2fd213d8f49b6390ec8f005795bb95661aaee793
diff --git a/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java b/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java
index e68eb99..7899d0c 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java
@@ -15,27 +15,19 @@
*/
package org.onosproject.net.driver;
-import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
- * Abstract boot-strapper for loading and registering driver definitions.
+ * Abstract bootstrapper for loading and registering driver definitions that
+ * are dependent on the default driver definitions.
*/
@Component
-public abstract class AbstractDriverLoader {
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- private DriverProvider provider;
- private final String path;
+public abstract class AbstractDriverLoader extends AbstractIndependentDriverLoader {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DriverAdminService driverAdminService;
+ protected DefaultDriverProviderService defaultDriverProviderService;
/**
* Creates a new loader for resource with the specified path.
@@ -43,25 +35,7 @@
* @param path drivers definition XML resource path
*/
protected AbstractDriverLoader(String path) {
- this.path = path;
- }
-
- @Activate
- protected void activate() {
- try {
- provider = new XmlDriverLoader(getClass().getClassLoader(), driverAdminService)
- .loadDrivers(getClass().getResourceAsStream(path), driverAdminService);
- driverAdminService.registerProvider(provider);
- } catch (Exception e) {
- log.error("Unable to load {} driver definitions", path, e);
- }
- log.info("Started");
- }
-
- @Deactivate
- protected void deactivate() {
- driverAdminService.unregisterProvider(provider);
- log.info("Stopped");
+ super(path);
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/AbstractIndependentDriverLoader.java b/core/api/src/main/java/org/onosproject/net/driver/AbstractIndependentDriverLoader.java
new file mode 100644
index 0000000..c8f6f17
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/driver/AbstractIndependentDriverLoader.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.net.driver;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract bootstrapper for loading and registering driver definitions that
+ * are independent from the default driver definitions.
+ */
+@Component
+public abstract class AbstractIndependentDriverLoader {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private DriverProvider provider;
+ private final String path;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DriverAdminService driverAdminService;
+
+ /**
+ * Creates a new loader for resource with the specified path.
+ *
+ * @param path drivers definition XML resource path
+ */
+ protected AbstractIndependentDriverLoader(String path) {
+ this.path = path;
+ }
+
+ @Activate
+ protected void activate() {
+ try {
+ provider = new XmlDriverLoader(getClass().getClassLoader(), driverAdminService)
+ .loadDrivers(getClass().getResourceAsStream(path), driverAdminService);
+ driverAdminService.registerProvider(provider);
+ } catch (Exception e) {
+ log.error("Unable to load {} driver definitions", path, e);
+ }
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ driverAdminService.unregisterProvider(provider);
+ log.info("Stopped");
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/net/driver/AbstractDriverLoaderTest.java b/core/api/src/test/java/org/onosproject/net/driver/AbstractDriverLoaderTest.java
index f91e629..f79b25b 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/AbstractDriverLoaderTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/AbstractDriverLoaderTest.java
@@ -44,7 +44,7 @@
}
}
- protected AbstractDriverLoader loader;
+ protected AbstractIndependentDriverLoader loader;
@Test
public void testLoader() {
diff --git a/drivers/corsa/src/main/java/org/onosproject/drivers/corsa/CorsaDriversLoader.java b/drivers/corsa/src/main/java/org/onosproject/drivers/corsa/CorsaDriversLoader.java
index 33eb06e..b2ad9ee 100644
--- a/drivers/corsa/src/main/java/org/onosproject/drivers/corsa/CorsaDriversLoader.java
+++ b/drivers/corsa/src/main/java/org/onosproject/drivers/corsa/CorsaDriversLoader.java
@@ -17,23 +17,13 @@
package org.onosproject.drivers.corsa;
import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.net.driver.AbstractDriverLoader;
-import org.onosproject.net.driver.DefaultDriverProviderService;
/**
* Loader for Corsa device drivers.
*/
@Component(immediate = true)
public class CorsaDriversLoader extends AbstractDriverLoader {
-
- //This reference is needed to enforce loading of the default drivers before
- //the corsa drivers at ONOS startup if corsa.drivers is specified
- //in the ONOS_APPS variable.
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- private DefaultDriverProviderService defaultDriverProviderService;
-
public CorsaDriversLoader() {
super("/corsa-drivers.xml");
}
diff --git a/drivers/default/src/main/java/org/onosproject/driver/DefaultDriversLoader.java b/drivers/default/src/main/java/org/onosproject/driver/DefaultDriversLoader.java
index 12ee006..fbf41a4 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/DefaultDriversLoader.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/DefaultDriversLoader.java
@@ -18,7 +18,7 @@
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
-import org.onosproject.net.driver.AbstractDriverLoader;
+import org.onosproject.net.driver.AbstractIndependentDriverLoader;
import org.onosproject.net.driver.DefaultDriverProviderService;
/**
@@ -26,7 +26,8 @@
*/
@Service
@Component(immediate = true)
-public class DefaultDriversLoader extends AbstractDriverLoader implements DefaultDriverProviderService {
+public class DefaultDriversLoader extends AbstractIndependentDriverLoader
+ implements DefaultDriverProviderService {
public DefaultDriversLoader() {
super("/onos-drivers.xml");
}