Huawei driver to use AbstractModelRegistrator.
Change-Id: I7e13d0da47ee7a86bbcac4b0d8cb3a5cacb1d172
diff --git a/drivers/huawei/BUCK b/drivers/huawei/BUCK
index bc5f34c..c8401e0 100644
--- a/drivers/huawei/BUCK
+++ b/drivers/huawei/BUCK
@@ -1,3 +1,16 @@
+APPS = [
+ 'org.onosproject.yang',
+ 'org.onosproject.yang-gui',
+ 'org.onosproject.config',
+ 'org.onosproject.restconf',
+ 'org.onosproject.yms',
+ 'org.onosproject.protocols.restconfserver',
+ 'org.onosproject.netconf',
+ 'org.onosproject.netconfsb',
+ 'org.onosproject.models.l3vpn',
+ 'org.onosproject.l3vpn',
+]
+
BUNDLES = [
'//drivers/huawei/yangmodel:onos-drivers-huawei-yangmodel',
'//drivers/huawei/driver:onos-drivers-huawei-driver',
@@ -10,7 +23,5 @@
url = 'http://onosproject.org',
description = 'ONOS Huawei Device Drivers application.',
included_bundles = BUNDLES,
- required_apps = [
- 'org.onosproject.netconf'
- ],
+ required_apps = APPS
)
\ No newline at end of file
diff --git a/drivers/huawei/driver/BUCK b/drivers/huawei/driver/BUCK
index 7b20046..4056f2e 100644
--- a/drivers/huawei/driver/BUCK
+++ b/drivers/huawei/driver/BUCK
@@ -9,6 +9,7 @@
'//apps/config:onos-apps-config',
'//lib:onos-yang-model',
'//lib:onos-yang-runtime',
+ '//apps/yang:onos-apps-yang',
]
TEST_DEPS = [
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3VpnConfig.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3VpnConfig.java
index 300e480..c8516b1 100644
--- a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3VpnConfig.java
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3VpnConfig.java
@@ -23,22 +23,11 @@
import org.onosproject.l3vpn.netl3vpn.BgpInfo;
import org.onosproject.net.behaviour.L3VpnConfig;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
-import org.onosproject.yang.gen.v1.l3vpn.comm.type.rev20141225.NeL3VpncommType;
-import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.NeBgpcomm;
-import org.onosproject.yang.gen.v1.ne.bgpcomm.type.rev20141225.NeBgpcommType;
-import org.onosproject.yang.gen.v1.ne.l3vpn.api.rev20141225.NeL3VpnApi;
-import org.onosproject.yang.gen.v1.ne.l3vpn.comm.rev20141225.NeL3Vpncomm;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.ModelObjectData;
import org.onosproject.yang.model.ResourceId;
-import org.onosproject.yang.model.YangModel;
-import org.onosproject.yang.model.YangModuleId;
-import org.onosproject.yang.runtime.DefaultAppModuleInfo;
-import org.onosproject.yang.runtime.ModelRegistrationParam;
import org.onosproject.yang.runtime.YangModelRegistry;
-import java.util.Iterator;
-
import static org.onosproject.drivers.huawei.BgpConstructionUtil.getCreateBgp;
import static org.onosproject.drivers.huawei.BgpConstructionUtil.getDeleteBgp;
import static org.onosproject.drivers.huawei.DriverUtil.DEVICES;
@@ -48,8 +37,6 @@
import static org.onosproject.drivers.huawei.InsConstructionUtil.getCreateVpnIns;
import static org.onosproject.drivers.huawei.InsConstructionUtil.getDeleteVpnIns;
import static org.onosproject.drivers.huawei.IntConstructionUtil.getCreateInt;
-import static org.onosproject.yang.runtime.DefaultModelRegistrationParam.builder;
-import static org.onosproject.yang.runtime.helperutils.YangApacheUtils.getYangModel;
/**
* Configures l3vpn on Huawei devices.
@@ -81,53 +68,11 @@
try {
modelRegistry = handler().get(YangModelRegistry.class);
configService = handler().get(DynamicConfigService.class);
- registerModel();
} catch (ServiceNotFoundException e) {
throw new ServiceNotFoundException(SERVICE_NOT_FOUND);
}
}
- /**
- * Registers the huawei generated classes to the YANG model.
- */
- private void registerModel() {
- YangModel model = getYangModel(NeBgpcomm.class);
- Iterator<YangModuleId> it = model.getYangModulesId().iterator();
-
- //Create model registration param.
- ModelRegistrationParam.Builder b = builder().setYangModel(model);
- YangModuleId id;
- while (it.hasNext()) {
- id = it.next();
- switch (id.moduleName()) {
- case "ne-bgpcomm":
- b.addAppModuleInfo(id, new DefaultAppModuleInfo(
- NeBgpcomm.class, null));
- break;
- case "ne-bgpcomm-type":
- b.addAppModuleInfo(id, new DefaultAppModuleInfo(
- NeBgpcommType.class, null));
- break;
- case "ne-l3vpn-api":
- b.addAppModuleInfo(id, new DefaultAppModuleInfo(
- NeL3VpnApi.class, null));
- break;
- case "ne-l3vpncomm":
- b.addAppModuleInfo(id, new DefaultAppModuleInfo(
- NeL3Vpncomm.class, null));
- break;
- case "ne-l3vpncomm-type":
- b.addAppModuleInfo(id, new DefaultAppModuleInfo(
- NeL3VpncommType.class, null));
- break;
- default:
- break;
- }
- }
- ModelRegistrationParam regParam = b.build();
- modelRegistry.registerModel(regParam);
- }
-
@Override
public Object createInstance(Object objectData) {
if (modelRegistry == null) {
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiModelRegistrator.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiModelRegistrator.java
new file mode 100644
index 0000000..40f6351
--- /dev/null
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiModelRegistrator.java
@@ -0,0 +1,63 @@
+/*
+ * 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.drivers.huawei;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.felix.scr.annotations.Component;
+import org.onosproject.yang.AbstractYangModelRegistrator;
+import org.onosproject.yang.gen.v1.l3vpn.comm.type.rev20141225.NeL3VpncommType;
+import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.NeBgpcomm;
+import org.onosproject.yang.gen.v1.ne.bgpcomm.type.rev20141225.NeBgpcommType;
+import org.onosproject.yang.gen.v1.ne.l3vpn.api.rev20141225.NeL3VpnApi;
+import org.onosproject.yang.gen.v1.ne.l3vpn.comm.rev20141225.NeL3Vpncomm;
+import org.onosproject.yang.model.DefaultYangModuleId;
+import org.onosproject.yang.model.YangModuleId;
+import org.onosproject.yang.runtime.AppModuleInfo;
+import org.onosproject.yang.runtime.DefaultAppModuleInfo;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Representation of huawei model registrator which registers huawei device
+ * models.
+ */
+@Component(immediate = true)
+public class HuaweiModelRegistrator extends AbstractYangModelRegistrator {
+
+ /**
+ * Creates L3VPN model registrator.
+ */
+ public HuaweiModelRegistrator() {
+ super(NeBgpcomm.class, getAppInfo());
+ }
+
+ private static Map<YangModuleId, AppModuleInfo> getAppInfo() {
+ Map<YangModuleId, AppModuleInfo> appInfo = new HashMap<>();
+ appInfo.put(new DefaultYangModuleId("NeBgpcomm.class", "2014-00-25"),
+ new DefaultAppModuleInfo(NeBgpcomm.class, null));
+ appInfo.put(new DefaultYangModuleId("ne-bgpcomm-type", "2014-00-25"),
+ new DefaultAppModuleInfo(NeBgpcommType.class, null));
+ appInfo.put(new DefaultYangModuleId("ne-l3vpn-api", "2014-00-25"),
+ new DefaultAppModuleInfo(NeL3VpnApi.class, null));
+ appInfo.put(new DefaultYangModuleId("ne-l3vpncomm", "2014-00-25"),
+ new DefaultAppModuleInfo(NeL3Vpncomm.class, null));
+ appInfo.put(new DefaultYangModuleId("ne-l3vpncomm-type", "2014-00-25"),
+ new DefaultAppModuleInfo(NeL3VpncommType.class, null));
+ return ImmutableMap.copyOf(appInfo);
+ }
+}