Merge "Bug 4641 - openstack.net-virt-sfc-features fail to find artifacts"
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / HwvtepConnectionInstance.java
index b4055764ddeb5b99a17d60178f6f06e7b15d1467..11b3052290425730aef2d7f7359224f982826482 100644 (file)
@@ -41,6 +41,7 @@ import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
 import org.opendaylight.ovsdb.lib.schema.TableSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
@@ -63,6 +64,7 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     private volatile boolean hasDeviceOwnership = false;
     private Entity connectedEntity;
     private EntityOwnershipCandidateRegistration deviceOwnershipCandidateRegistration;
+    private HwvtepGlobalAugmentation initialCreatedData = null;
 
 
     HwvtepConnectionInstance (ConnectionInfo key,OvsdbClient client,
@@ -81,13 +83,17 @@ public class HwvtepConnectionInstance implements OvsdbClient{
 
     public void registerCallbacks() {
         if ( this.callback == null) {
+            if(this.initialCreatedData != null) {
+                this.updateConnectionAttributes();
+            }
+
             try {
                 List<String> databases = getDatabases().get();
                 this.callback = new HwvtepMonitorCallback(this,txInvoker);
                 for (String database : databases) {
                     DatabaseSchema dbSchema = getSchema(database).get();
                     if (dbSchema != null) {
-                        monitorAllTables(database, dbSchema);
+                        monitorAllTables(database, dbSchema, HwvtepSchemaConstants.databaseName);
                     } else {
                         LOG.warn("No schema reported for database {} for key {}",database,connectionInfo);
                     }
@@ -101,7 +107,7 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     public void createTransactInvokers() {
         if (transactInvokers == null) {
             try {
-                transactInvokers = new HashMap<DatabaseSchema,TransactInvoker>();
+                transactInvokers = new HashMap<>();
                 List<String> databases = getDatabases().get();
                 for (String database : databases) {
                     DatabaseSchema dbSchema = getSchema(database).get();
@@ -115,11 +121,16 @@ public class HwvtepConnectionInstance implements OvsdbClient{
         }
     }
 
-    private void monitorAllTables(String database, DatabaseSchema dbSchema) {
+    private void monitorAllTables(String database, DatabaseSchema dbSchema, String filter) {
+        if((filter != null) && (!dbSchema.getName().equals(filter))) {
+            LOG.debug("Not monitoring tables in {}, filter: {}", dbSchema.getName(), filter);
+            return;
+        }
         Set<String> tables = dbSchema.getTables();
         if (tables != null) {
-            List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
+            List<MonitorRequest> monitorRequests = Lists.newArrayList();
             for (String tableName : tables) {
+                LOG.debug("HwvtepSouthbound monitoring table {} in {}", tableName, dbSchema.getName());
                 GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class);
                 Set<String> columns = tableSchema.getColumns();
                 MonitorRequestBuilder<GenericTableSchema> monitorBuilder = MonitorRequestBuilder.builder(tableSchema);
@@ -134,6 +145,17 @@ public class HwvtepConnectionInstance implements OvsdbClient{
         }
     }
 
+    private void updateConnectionAttributes() {
+        LOG.debug("Update attributes of ovsdb node ip: {} port: {}",
+                    this.initialCreatedData.getConnectionInfo().getRemoteIp(),
+                    this.initialCreatedData.getConnectionInfo().getRemotePort());
+        /*
+         * TODO: Do we have anything to update?
+         * Hwvtep doesn't have other_config or external_ids like
+         * Open_vSwitch. What else will be needed?
+         */
+    }
+
     public ListenableFuture<List<String>> getDatabases() {
         return client.getDatabases();
     }
@@ -151,13 +173,13 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     }
 
     public <E extends TableSchema<E>> TableUpdates monitor(DatabaseSchema schema,
-                    List<MonitorRequest<E>> monitorRequests, MonitorCallBack callback) {
+                    List<MonitorRequest> monitorRequests, MonitorCallBack callback) {
         return client.monitor(schema, monitorRequests, callback);
     }
 
     @Override
     public <E extends TableSchema<E>> TableUpdates monitor(DatabaseSchema schema,
-                    List<MonitorRequest<E>> monitorRequests, MonitorHandle monitorHandle, MonitorCallBack callback) {
+                    List<MonitorRequest> monitorRequests, MonitorHandle monitorHandle, MonitorCallBack callback) {
         return null;
     }
 
@@ -251,12 +273,12 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     }
 
     public Boolean getHasDeviceOwnership() {
-        return Boolean.valueOf(hasDeviceOwnership);
+        return hasDeviceOwnership;
     }
 
     public void setHasDeviceOwnership(Boolean hasDeviceOwnership) {
         if (hasDeviceOwnership != null) {
-            this.hasDeviceOwnership = hasDeviceOwnership.booleanValue();
+            this.hasDeviceOwnership = hasDeviceOwnership;
         }
     }
 
@@ -270,4 +292,8 @@ public class HwvtepConnectionInstance implements OvsdbClient{
             setHasDeviceOwnership(Boolean.FALSE);
         }
     }
+
+    public void setHwvtepGlobalAugmentation(HwvtepGlobalAugmentation hwvtepGlobalData) {
+        this.initialCreatedData = hwvtepGlobalData;
+    }
 }