Correct Frontend{Client,History}Metadata deserialization
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / FrontendMetadata.java
index f651efa3fab3c14933aa3a386ea7b8c8b8477576..d5ecbf6ea416c6c283f0e06b5537293bbdef99e8 100644 (file)
@@ -8,9 +8,10 @@
 package org.opendaylight.controller.cluster.datastore;
 
 import static com.google.common.base.Verify.verify;
+import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
 import java.util.HashMap;
 import java.util.Map;
@@ -38,7 +39,7 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
     private final String shardName;
 
     FrontendMetadata(final String shardName) {
-        this.shardName = Preconditions.checkNotNull(shardName);
+        this.shardName = requireNonNull(shardName);
     }
 
     @Override
@@ -132,7 +133,10 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
         final FrontendIdentifier frontendId = clientId.getFrontendId();
         final FrontendClientMetadataBuilder client = clients.get(frontendId);
         if (client == null) {
-            LOG.debug("{}: disableTracking {} does not match any client, ignoring", shardName, clientId);
+            // When we havent seen the client before, we still need to disable tracking for him since this only gets
+            // triggered once.
+            LOG.debug("{}: disableTracking {} does not match any client, pre-disabling client.", shardName, clientId);
+            clients.put(frontendId, new FrontendClientMetadataBuilder.Disabled(shardName, clientId));
             return;
         }
         if (!clientId.equals(client.getIdentifier())) {
@@ -146,4 +150,10 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
 
         verify(clients.replace(frontendId, client, new FrontendClientMetadataBuilder.Disabled(shardName, clientId)));
     }
+
+    ImmutableSet<ClientIdentifier> getClients() {
+        return clients.values().stream()
+                .map(FrontendClientMetadataBuilder::getIdentifier)
+                .collect(ImmutableSet.toImmutableSet());
+    }
 }