Rename NativeEosService to DataCenterControl 43/97243/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Aug 2021 22:57:08 +0000 (00:57 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Aug 2021 06:49:37 +0000 (08:49 +0200)
This is a wee bit more descriptive name. While we are here, also ditch
java.lang.Void, as it promotes nulls. Use yamg.common.Empty, which has a
singleton instance.

Fold common implementation code into a static method, which is making
things very obvious.

Change-Id: I28230523034224e978244d1edce997376812bf91
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/eos-dom-akka/src/main/java/org/opendaylight/controller/eos/akka/AkkaEntityOwnershipService.java
opendaylight/md-sal/eos-dom-akka/src/main/java/org/opendaylight/controller/eos/akka/DataCenterControl.java [moved from opendaylight/md-sal/eos-dom-akka/src/main/java/org/opendaylight/controller/eos/akka/NativeEosService.java with 82% similarity]
opendaylight/md-sal/sal-cluster-admin-impl/src/main/java/org/opendaylight/controller/cluster/datastore/admin/ClusterAdminRpcService.java
opendaylight/md-sal/sal-cluster-admin-impl/src/main/java/org/opendaylight/controller/cluster/datastore/admin/OSGiClusterAdmin.java

index ffce30d..fdb8a4d 100644 (file)
@@ -38,7 +38,6 @@ import org.opendaylight.controller.eos.akka.owner.checker.command.StateCheckerCo
 import org.opendaylight.controller.eos.akka.owner.supervisor.command.ActivateDataCenter;
 import org.opendaylight.controller.eos.akka.owner.supervisor.command.DeactivateDataCenter;
 import org.opendaylight.controller.eos.akka.owner.supervisor.command.OwnerSupervisorCommand;
-import org.opendaylight.controller.eos.akka.owner.supervisor.command.OwnerSupervisorReply;
 import org.opendaylight.controller.eos.akka.registry.candidate.command.CandidateRegistryCommand;
 import org.opendaylight.controller.eos.akka.registry.candidate.command.RegisterCandidate;
 import org.opendaylight.controller.eos.akka.registry.candidate.command.UnregisterCandidate;
@@ -52,6 +51,7 @@ import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistratio
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -65,8 +65,8 @@ import org.slf4j.LoggerFactory;
  * the appropriate owners.
  */
 @Singleton
-@Component(immediate = true, service = { DOMEntityOwnershipService.class, NativeEosService.class })
-public class AkkaEntityOwnershipService implements DOMEntityOwnershipService, NativeEosService, AutoCloseable {
+@Component(immediate = true, service = { DOMEntityOwnershipService.class, DataCenterControl.class })
+public class AkkaEntityOwnershipService implements DOMEntityOwnershipService, DataCenterControl, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(AkkaEntityOwnershipService.class);
     private static final String DATACENTER_PREFIX = "dc";
     private static final Duration DATACENTER_OP_TIMEOUT = Duration.ofSeconds(20);
@@ -171,45 +171,18 @@ public class AkkaEntityOwnershipService implements DOMEntityOwnershipService, Na
     }
 
     @Override
-    public ListenableFuture<Void> activateDataCenter() {
+    public ListenableFuture<Empty> activateDataCenter() {
         LOG.debug("Activating datacenter: {}", datacenter);
-        final SettableFuture<Void> future = SettableFuture.create();
-        final CompletionStage<OwnerSupervisorReply> ask =
-                AskPattern.ask(ownerSupervisor, ActivateDataCenter::new, DATACENTER_OP_TIMEOUT, scheduler);
 
-        ask.whenComplete((reply, failure) -> {
-            if (failure != null) {
-                LOG.warn("Activate DataCenter has failed.", failure);
-                future.setException(failure);
-                return;
-            }
-
-            LOG.debug("Activate DataCenter successful.");
-            future.set(null);
-        });
-
-        return future;
+        return toListenableFuture("Activate",
+            AskPattern.ask(ownerSupervisor, ActivateDataCenter::new, DATACENTER_OP_TIMEOUT, scheduler));
     }
 
     @Override
-    public ListenableFuture<Void> deactivateDataCenter() {
+    public ListenableFuture<Empty> deactivateDataCenter() {
         LOG.debug("Deactivating datacenter: {}", datacenter);
-        final SettableFuture<Void> future = SettableFuture.create();
-        final CompletionStage<OwnerSupervisorReply> ask =
-                AskPattern.ask(ownerSupervisor, DeactivateDataCenter::new, DATACENTER_OP_TIMEOUT, scheduler);
-
-        ask.whenComplete((reply, failure) -> {
-            if (failure != null) {
-                LOG.warn("Deactivate DataCenter has failed.", failure);
-                future.setException(failure);
-                return;
-            }
-
-            LOG.debug("Deactivate DataCenter successful.");
-            future.set(null);
-        });
-
-        return future;
+        return toListenableFuture("Deactivate",
+            AskPattern.ask(ownerSupervisor, DeactivateDataCenter::new, DATACENTER_OP_TIMEOUT, scheduler));
     }
 
     void unregisterCandidate(final DOMEntity entity) {
@@ -230,4 +203,18 @@ public class AkkaEntityOwnershipService implements DOMEntityOwnershipService, Na
     RunningContext getRunningContext() {
         return runningContext;
     }
+
+    private static ListenableFuture<Empty> toListenableFuture(final String op, final CompletionStage<?> stage) {
+        final SettableFuture<Empty> future = SettableFuture.create();
+        stage.whenComplete((reply, failure) -> {
+            if (failure != null) {
+                LOG.warn("{} DataCenter has failed", op, failure);
+                future.setException(failure);
+            } else {
+                LOG.debug("{} DataCenter successful", op);
+                future.set(Empty.getInstance());
+            }
+        });
+        return future;
+    }
 }
@@ -9,6 +9,8 @@ package org.opendaylight.controller.eos.akka;
 
 import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.ListenableFuture;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Empty;
 
 /**
  * Service used to bring up/down the NativeEos service in individual datacenters.
@@ -22,15 +24,16 @@ import com.google.common.util.concurrent.ListenableFuture;
  * datacenter or multiple datacenters.
  */
 @Beta
-public interface NativeEosService {
-
+public interface DataCenterControl {
     /**
      * Activates the native eos service in the datacenter that this method is called.
      */
-    ListenableFuture<Void> activateDataCenter();
+    @NonNull ListenableFuture<Empty> activateDataCenter();
 
     /**
      * Deactivates the native eos service in the datacenter that this method is called.
+     *
+     * @return Completion future
      */
-    ListenableFuture<Void> deactivateDataCenter();
+    @NonNull ListenableFuture<Empty> deactivateDataCenter();
 }
index f11c60f..e00d620 100644 (file)
@@ -54,7 +54,7 @@ import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot
 import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList;
 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
 import org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot;
-import org.opendaylight.controller.eos.akka.NativeEosService;
+import org.opendaylight.controller.eos.akka.DataCenterControl;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ActivateEosDatacenterInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ActivateEosDatacenterOutput;
@@ -135,12 +135,12 @@ public class ClusterAdminRpcService implements ClusterAdminService {
     private final DistributedDataStoreInterface operDataStore;
     private final BindingNormalizedNodeSerializer serializer;
     private final Timeout makeLeaderLocalTimeout;
-    private final NativeEosService nativeEosService;
+    private final DataCenterControl dataCenterControl;
 
     public ClusterAdminRpcService(final DistributedDataStoreInterface configDataStore,
                                   final DistributedDataStoreInterface operDataStore,
                                   final BindingNormalizedNodeSerializer serializer,
-                                  final NativeEosService nativeEosService) {
+                                  final DataCenterControl dataCenterControl) {
         this.configDataStore = configDataStore;
         this.operDataStore = operDataStore;
         this.serializer = serializer;
@@ -149,7 +149,7 @@ public class ClusterAdminRpcService implements ClusterAdminService {
                 new Timeout(configDataStore.getActorUtils().getDatastoreContext()
                         .getShardLeaderElectionTimeout().duration().$times(2));
 
-        this.nativeEosService = nativeEosService;
+        this.dataCenterControl = dataCenterControl;
     }
 
     @Override
@@ -528,9 +528,9 @@ public class ClusterAdminRpcService implements ClusterAdminService {
             final ActivateEosDatacenterInput input) {
         LOG.debug("Activating EOS Datacenter");
         final SettableFuture<RpcResult<ActivateEosDatacenterOutput>> future = SettableFuture.create();
-        Futures.addCallback(nativeEosService.activateDataCenter(), new FutureCallback<>() {
+        Futures.addCallback(dataCenterControl.activateDataCenter(), new FutureCallback<>() {
             @Override
-            public void onSuccess(final Void result) {
+            public void onSuccess(final Empty result) {
                 LOG.debug("Successfully activated datacenter.");
                 future.set(RpcResultBuilder.<ActivateEosDatacenterOutput>success().build());
             }
@@ -550,9 +550,9 @@ public class ClusterAdminRpcService implements ClusterAdminService {
             final DeactivateEosDatacenterInput input) {
         LOG.debug("Deactivating EOS Datacenter");
         final SettableFuture<RpcResult<DeactivateEosDatacenterOutput>> future = SettableFuture.create();
-        Futures.addCallback(nativeEosService.deactivateDataCenter(), new FutureCallback<>() {
+        Futures.addCallback(dataCenterControl.deactivateDataCenter(), new FutureCallback<>() {
             @Override
-            public void onSuccess(final Void result) {
+            public void onSuccess(final Empty result) {
                 LOG.debug("Successfully deactivated datacenter.");
                 future.set(RpcResultBuilder.<DeactivateEosDatacenterOutput>success().build());
             }
index c0e9448..82a669e 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.controller.cluster.datastore.admin;
 
 import com.google.common.annotations.Beta;
 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
-import org.opendaylight.controller.eos.akka.NativeEosService;
+import org.opendaylight.controller.eos.akka.DataCenterControl;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ClusterAdminService;
@@ -35,14 +35,14 @@ public final class OSGiClusterAdmin {
     @Reference
     RpcProviderService rpcProviderService = null;
     @Reference
-    NativeEosService nativeEosService = null;
+    DataCenterControl dataCenterControl = null;
 
     private ObjectRegistration<?> reg;
 
     @Activate
     void activate() {
         reg = rpcProviderService.registerRpcImplementation(ClusterAdminService.class,
-            new ClusterAdminRpcService(configDatastore, operDatastore, serializer, nativeEosService));
+            new ClusterAdminRpcService(configDatastore, operDatastore, serializer, dataCenterControl));
         LOG.info("Cluster Admin services started");
     }