Change the deprecated APIs into the latest API in sfc provider 12/15212/4
authorHongli Chen <[email protected]>
Mon, 16 Feb 2015 03:54:18 +0000 (11:54 +0800)
committerReinaldo Penno <[email protected]>
Thu, 26 Feb 2015 00:57:39 +0000 (00:57 +0000)
Signed-off-by: Hongli Chen <[email protected]>
features/src/main/resources/features.xml
pom.xml
sfc-config/src/main/resources/80-sfc.xml
sfc-provider/pom.xml
sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModule.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/GetNetconfDataProvider.java [deleted file]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcNetconfDataProvider.java [new file with mode: 0755]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceFunctionAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderSfDescriptionMonitorAPI.java [moved from sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderSfDescriptionMonotorAPI.java with 89% similarity]
sfc-provider/src/main/yang/sfc-provider-impl.yang

index dcf93b61b761bc68a2d110a28d91592120911e17..cd32135300567c22fb9dbb4cc55e56794503cb71 100644 (file)
@@ -91,7 +91,6 @@
         <bundle>mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/${jackson.version}</bundle>
         <bundle>mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/${jackson.version}</bundle>
         <bundle>mvn:org.glassfish/javax.json/1.0.4</bundle>
-        <bundle>mvn:org.opendaylight.controller/sal/${sal.version}</bundle>
     </feature>
 <!--    <feature name='odl-sfc-provider' version='${project.version}' description='OpenDaylight :: sfc :: Provider '>
         <feature version='${project.version}'>odl-sfc-provider-internal</feature>
diff --git a/pom.xml b/pom.xml
index 395c1811da0f674a18861c8ce0eb8c299923cd75..e51945cfe783ffe4c827b5a4f0f07d876f3cd4f2 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,6 @@
         <bundle.plugin.version>2.4.0</bundle.plugin.version>
         <config.version>0.3.0-SNAPSHOT</config.version>
         <mdsal.version>1.2.0-SNAPSHOT</mdsal.version>
-        <sal.version>0.9.0-SNAPSHOT</sal.version>
         <controller.model.version>1.2.0-SNAPSHOT</controller.model.version>
         <build.helper.version>1.8</build.helper.version>
         <netconf.parent.version>0.3.0-SNAPSHOT</netconf.parent.version>
index 45904fe5cacfdd4d31edb8df78ca9a0f3a7c7040..9a184e1703d912d3965224f2ec55d090cc58811f 100755 (executable)
                         <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-async-data-broker</type>
                         <name>binding-data-broker</name>
                     </data-broker>
+                    <dom-registry>
+                        <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type>
+                        <name>dom-broker</name>
+                    </dom-registry>
                 </module>
 
                 <module>
index ea61e00fc269f8cd3f12e31b1ec8bfd753f433aa..1c45265d71250c6e3eba6bbde8bc6764702752c7 100755 (executable)
             <!-- version>4.11</version -->
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal</artifactId>
-            <version>${sal.version}</version>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-core-api</artifactId>
             <artifactId>yang-data-api</artifactId>
             <version>${yangtools.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-common-impl</artifactId>
-            <version>${mdsal.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller.model</groupId>
-            <artifactId>model-inventory</artifactId>
-            <version>${mdsal.version}</version>
-        </dependency>
     </dependencies>
 
 
index efd3def590757c7eb167e165d3d9aba43b9c515f..d69b7f51d40e1dac7ad48e3055dcc705f607fa04 100755 (executable)
@@ -13,7 +13,6 @@ import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.core.api.Broker;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.sfc.provider.*;
 import org.opendaylight.sfc.provider.bootstrap.SfcProviderBootstrapRestAPI;
 import org.opendaylight.sfc.provider.logback.SfcProviderLogbackLoader;
@@ -72,7 +71,7 @@ public class SfcProviderModule extends org.opendaylight.controller.config.yang.c
 
         DataBroker dataBrokerService = getDataBrokerDependency();
         opendaylightSfc.setDataProvider(dataBrokerService);
-        Broker broker = (Broker) ServiceHelper.getGlobalInstance(Broker.class, this);
+        Broker broker = getDomRegistryDependency();
         opendaylightSfc.setBroker(broker);
 
         final SfcProviderRpc sfcProviderRpc = new SfcProviderRpc();
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/GetNetconfDataProvider.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/GetNetconfDataProvider.java
deleted file mode 100755 (executable)
index 54c6613..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.opendaylight.sfc.provider;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.opendaylight.controller.sal.core.api.Broker;
-import org.opendaylight.controller.sal.core.api.Provider;
-
-public class GetNetconfDataProvider implements Provider {
-    @Override
-    public Collection<Provider.ProviderFunctionality> getProviderFunctionality() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public void onSessionInitiated(final Broker.ProviderSession session) {
-    }
-}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcNetconfDataProvider.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcNetconfDataProvider.java
new file mode 100755 (executable)
index 0000000..bdf69c5
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+* Copyright (c) 2014 Intel Corp. and others.  All rights reserved.
+*
+* This program and the accompanying materials are made available under the
+* terms of the Eclipse Public License v1.0 which accompanies this distribution,
+* and is available at http://www.eclipse.org/legal/epl-v10.html
+*/
+package org.opendaylight.sfc.provider;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.sal.core.api.Broker;
+import org.opendaylight.controller.sal.core.api.Provider;
+
+public class SfcNetconfDataProvider implements Provider {
+
+    DOMMountPointService mountService;
+    static SfcNetconfDataProvider sfcNetconfDataProvider;
+
+    /*
+     * Factory method
+     */
+    public static SfcNetconfDataProvider GetNetconfDataProvider() {
+        if (sfcNetconfDataProvider != null)
+            return sfcNetconfDataProvider;
+        else {
+            sfcNetconfDataProvider = new SfcNetconfDataProvider();
+            return sfcNetconfDataProvider;
+        }
+    }
+
+    public DOMMountPointService getMountService() {
+        return mountService;
+    }
+
+    public void setMountService(DOMMountPointService mountService) {
+        this.mountService = mountService;
+    }
+
+    @Override
+    public Collection<Provider.ProviderFunctionality> getProviderFunctionality() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public void onSessionInitiated(final Broker.ProviderSession session) {
+        mountService = session.getService(DOMMountPointService.class);
+    }
+}
index c1782358627d977f65975d6a65fd9073f7f23c6e..07c2a575dfec506f269f2ff6b03bd34ba51ea7cd 100755 (executable)
@@ -78,7 +78,7 @@ import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
 public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
 
     private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceFunctionAPI.class);
-    private SfcProviderSfDescriptionMonotorAPI getSfDescMon = new SfcProviderSfDescriptionMonotorAPI();
+    private SfcProviderSfDescriptionMonitorAPI getSfDescMon = new SfcProviderSfDescriptionMonitorAPI();
 
     SfcProviderServiceFunctionAPI(Object[] params, String m) {
         super(params, m);
@@ -130,7 +130,9 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
     public static SfcProviderServiceFunctionAPI getReadServiceFunctionDescriptionMonitor(Object[] params, Class[] paramsTypes) {
         return new SfcProviderServiceFunctionAPI(params, paramsTypes, "readServiceFunctionDescriptionMonitor");
     }
-
+    public static SfcProviderServiceFunctionAPI getReadAllServiceFunctionsState(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "readAllServiceFunctionStates");
+    }
     /**
      * This method reads the operational state for a service function.
      * <p>
@@ -318,6 +320,20 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         return ret;
     }
 
+    protected ServiceFunctionsState readAllServiceFunctionStates() {
+        ServiceFunctionsState sfsState = null;
+        printTraceStart(LOG);
+
+        InstanceIdentifier<ServiceFunctionsState> sfStateIID = InstanceIdentifier
+                .builder(ServiceFunctionsState.class)
+                .build();
+
+        sfsState = SfcDataStoreAPI.readTransactionAPI(sfStateIID, LogicalDatastoreType.OPERATIONAL);
+
+        printTraceStop(LOG);
+        return sfsState;
+    }
+
     /**
      * This method deletes the operational state for a service function.
      * <p>
similarity index 89%
rename from sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderSfDescriptionMonotorAPI.java
rename to sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderSfDescriptionMonitorAPI.java
index 4b9deefd9af366795ba45c2eff00514d711efbd4..a5902fd24a4550372c82496105fedd54b7aaed82 100644 (file)
@@ -1,10 +1,19 @@
+/*
+* Copyright (c) 2014 Intel Corp. and others.  All rights reserved.
+*
+* This program and the accompanying materials are made available under the
+* terms of the Eclipse Public License v1.0 which accompanies this distribution,
+* and is available at http://www.eclipse.org/legal/epl-v10.html
+*/
 package org.opendaylight.sfc.provider.api;
 
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.sfc.provider.OpendaylightSfc;
-import org.opendaylight.sfc.provider.GetNetconfDataProvider;
+import org.opendaylight.sfc.provider.SfcNetconfDataProvider;
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
-import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
-import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
+import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -29,11 +38,10 @@ import com.google.common.base.Preconditions;
 
 import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
 import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
-public class SfcProviderSfDescriptionMonotorAPI{
-    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSfDescriptionMonotorAPI.class);
+public class SfcProviderSfDescriptionMonitorAPI{
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSfDescriptionMonitorAPI.class);
     private static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
     private static ProviderSession sessionData;
-    private static MountProvisionService mountService;
     private static URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0");
     private static QName NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf");
     private static QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type");
@@ -66,7 +74,7 @@ public class SfcProviderSfDescriptionMonotorAPI{
     private static final QName POWER_UTILIZATION_QNAME = QName.create("(urn.intel.params:xml:ns:sf-desc-mon-rpt)power-utilization");
     private Map<QName, String> sfDescMonInfoMap = new HashMap<QName, String>();
 
-    public SfcProviderSfDescriptionMonotorAPI() {
+    public SfcProviderSfDescriptionMonitorAPI() {
         sfDescMonInfoMap.put(PORT_BANDWIDTH_QNAME,"port-bandwidth");
         sfDescMonInfoMap.put(NUM_OF_PORTS_QNAME,"number-of-dataports");
         sfDescMonInfoMap.put(SUPPORTED_PACKET_RATE_QNAME,"supported-packet-rate");
@@ -85,13 +93,17 @@ public class SfcProviderSfDescriptionMonotorAPI{
         sfDescMonInfoMap.put(RIB_UTILIZATION_QNAME,"RIB-utilization");
         sfDescMonInfoMap.put(FIB_UTILIZATION_QNAME,"FIB-utilization");
         sfDescMonInfoMap.put(POWER_UTILIZATION_QNAME,"power-utilization");
+
+        setSession();
     }
 
     protected void setSession()  {
         printTraceStart(LOG);
         try {
-            sessionData = odlSfc.getBroker().registerProvider(new GetNetconfDataProvider());
-            Preconditions.checkState(sessionData != null,"GetNetconfDataProvider register is not available.");
+            if(sessionData==null) {
+                sessionData = odlSfc.getBroker().registerProvider(SfcNetconfDataProvider.GetNetconfDataProvider());
+                Preconditions.checkState(sessionData != null,"SfcNetconfDataProvider register is not available.");
+            }
         } catch (Exception e) {
             LOG.warn("failed to ...." , e);
         }
@@ -120,7 +132,7 @@ public class SfcProviderSfDescriptionMonotorAPI{
     public Map<String, Object> getSFDescriptionInfoFromNetconf(String mountpoint)  {
         printTraceStart(LOG);
 
-        MountProvisionInstance mountInstance;
+        Optional<DOMMountPoint> mountPoint;
         Map<String, Object> sfDescInfo  = new HashMap<String, Object>();
         final QName nodes = QName.create("urn:opendaylight:inventory","2013-08-19","nodes");
         final QName node = QName.create(nodes,"node");
@@ -129,21 +141,23 @@ public class SfcProviderSfDescriptionMonotorAPI{
             // data path
             final YangInstanceIdentifier path = YangInstanceIdentifier.builder().
                     node(nodes).nodeWithKey(node,idName,mountpoint).build();
-            setSession();
-            mountService = sessionData.getService(MountProvisionService.class);
+
+            DOMMountPointService mountService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService();
             if (mountService != null)  {
-                mountInstance = mountService.getMountPoint(path);
-                if (mountInstance != null) {
-                    RpcResult<CompositeNode> future = mountInstance.invokeRpc(SF_DESCRIPTION_QNAME, wrap(SF_DESCRIPTION_QNAME, null)).get();
+                mountPoint = mountService.getMountPoint(path);
+                if (mountPoint.isPresent()) {
+                    final Optional<RpcProvisionRegistry> service = mountPoint.get().getService(RpcProvisionRegistry.class);
+                    Preconditions.checkState(service.isPresent());
+                    RpcResult<CompositeNode> future = service.get().invokeRpc(SF_DESCRIPTION_QNAME, wrap(SF_DESCRIPTION_QNAME, null)).get();
                     CompositeNode data = future.getResult().getFirstCompositeByName(NETCONF_DATA_QNAME);
                     sfDescInfo = parseSFDescriptionInfo(data);
                 } else {
-                    LOG.error("In getSFDescriptionInfoFromNetconf(), MountProvisionInstance is null");
+                    LOG.error("In getSFDescriptionInfoFromNetconf(), DOMMountPoint is null");
                     return null;
                 }
             }
             else {
-                LOG.error("In getSFDescriptionInfoFromNetconf(), MountProvisionService is null");
+                LOG.error("In getSFDescriptionInfoFromNetconf(), DOMMountPointService is null");
                 return null;
             }
         } catch (Exception e) {
@@ -156,7 +170,7 @@ public class SfcProviderSfDescriptionMonotorAPI{
     public Map<String, Object> getSFMonitorInfoFromNetconf(String mountpoint)  {
         printTraceStart(LOG);
 
-        MountProvisionInstance mountInstance;
+        Optional<DOMMountPoint> mountPoint;
         Map<String, Object> sfMonInfoMap  = new HashMap<String, Object>();
         final QName nodes = QName.create("urn:opendaylight:inventory","2013-08-19","nodes");
         final QName node = QName.create(nodes,"node");
@@ -165,22 +179,23 @@ public class SfcProviderSfDescriptionMonotorAPI{
             // data path
             final YangInstanceIdentifier path = YangInstanceIdentifier.builder().
                     node(nodes).nodeWithKey(node,idName, mountpoint).build();
-            setSession();
-            mountService = sessionData.getService(MountProvisionService.class);
-            if (mountService != null)  {
-                mountInstance = mountService.getMountPoint(path);
 
-                if (mountInstance != null) {
-                    RpcResult<CompositeNode> future = mountInstance.invokeRpc(SF_MONITOR_INFO_QNAME, wrap(SF_MONITOR_INFO_QNAME, null)).get();
+            DOMMountPointService mountService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService();
+            if (mountService != null)  {
+                mountPoint = mountService.getMountPoint(path);
+                if (mountPoint.isPresent()) {
+                    final Optional<RpcProvisionRegistry> service = mountPoint.get().getService(RpcProvisionRegistry.class);
+                    Preconditions.checkState(service.isPresent());
+                    RpcResult<CompositeNode> future = service.get().invokeRpc(SF_MONITOR_INFO_QNAME, wrap(SF_MONITOR_INFO_QNAME, null)).get();
                     CompositeNode data = future.getResult().getFirstCompositeByName(NETCONF_DATA_QNAME);
                     sfMonInfoMap = parseSFMonitorInfo(data);
                 } else {
-                    LOG.error("In getSFMonitorInfoFromNetconf(), MountProvisionInstance is null");
+                    LOG.error("In getSFMonitorInfoFromNetconf(), DOMMountPoint is null");
                     return null;
                 }
             }
             else {
-                LOG.error("In getSFMonitorInfoFromNetconf(), MountProvisionService is null");
+                LOG.error("In getSFMonitorInfoFromNetconf(), DOMMountPointService is null");
                 return null;
             }
         } catch (Exception e) {
index f81da1d1d0846819f6b60fc7872468d4a2ecd64a..9f6ed8db1b4f65374abafdaf9ca0013dacfa01a4 100644 (file)
@@ -8,7 +8,7 @@ module sfc-provider-impl {
   import config { prefix config; revision-date 2013-04-05; }
   import rpc-context { prefix rpcx; revision-date 2013-06-17; }
   import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; }
-
+  import opendaylight-md-sal-dom {prefix dom;}
 
   description
       "This module contains the base YANG definitions for
@@ -43,6 +43,15 @@ module sfc-provider-impl {
         }
       }
 
+      container dom-registry {
+          uses config:service-ref {
+              refine type {
+                  mandatory true;
+                  config:required-identity dom:dom-broker-osgi-registry;
+              }
+          }
+      }
+
       container rpc-registry {
         uses config:service-ref {
           refine type {