package org.opendaylight.openflowplugin.applications.frm.impl;
+import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
-import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(DeviceMastership.class);
private final NodeId nodeId;
private final ServiceGroupIdentifier identifier;
- private final ClusterSingletonServiceProvider clusterSingletonServiceProvider;
- private final FlowNodeReconciliation reconcliationAgent;
private final AtomicBoolean deviceMastered = new AtomicBoolean(false);
private final AtomicBoolean isDeviceInOperDS = new AtomicBoolean(false);
private final InstanceIdentifier<FlowCapableNode> fcnIID;
- private ClusterSingletonServiceRegistration clusterSingletonServiceRegistration;
+ private final KeyedInstanceIdentifier<Node, NodeKey> path;
- public DeviceMastership(final NodeId nodeId,
- final ClusterSingletonServiceProvider clusterSingletonService,
- final FlowNodeReconciliation reconcliationAgent) {
+ private ObjectRegistration<@NonNull FrmReconciliationService> reg;
+
+ public DeviceMastership(final NodeId nodeId) {
this.nodeId = nodeId;
this.identifier = ServiceGroupIdentifier.create(nodeId.getValue());
- this.clusterSingletonServiceProvider = clusterSingletonService;
- this.reconcliationAgent = reconcliationAgent;
- fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId)).augmentation
- (FlowCapableNode.class);
+ fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId))
+ .augmentation(FlowCapableNode.class);
+ path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
}
@Override
public void instantiateServiceInstance() {
LOG.info("FRM started for: {}", nodeId.getValue());
deviceMastered.set(true);
- if(canReconcile()) {
- LOG.info("Triggering reconciliation for device {}", nodeId.getValue());
- reconcliationAgent.reconcileConfiguration(fcnIID);
- }
}
@Override
@Override
public void close() {
- if (clusterSingletonServiceRegistration != null) {
- try {
- clusterSingletonServiceRegistration.close();
- } catch (Exception e) {
- LOG.error("FRM cluster service close fail: {} {}", nodeId.getValue(), e);
- }
- }
}
public boolean isDeviceMastered() {
return deviceMastered.get();
}
- public void setDeviceOperationalStatus(boolean inOperDS) {
+ public void setDeviceOperationalStatus(final boolean inOperDS) {
isDeviceInOperDS.set(inOperDS);
- if(canReconcile()) {
- LOG.info("Triggering reconciliation for device {}", nodeId.getValue());
- reconcliationAgent.reconcileConfiguration(fcnIID);
- }
}
- public void registerClusterSingletonService() {
- LOG.info("Registering FRM as a cluster singleton service listner for service id : {}",getIdentifier());
- clusterSingletonServiceRegistration = clusterSingletonServiceProvider.registerClusterSingletonService(this);
+ public void reconcile() {
+ deviceMastered.set(true);
}
- private boolean canReconcile() {
- return (deviceMastered.get() && isDeviceInOperDS.get());
+ public void registerReconciliationRpc(final RpcProviderService rpcProviderService,
+ final FrmReconciliationService reconcliationService) {
+ if (reg == null) {
+ LOG.debug("The path is registered : {}", path);
+ reg = rpcProviderService.registerRpcImplementation(FrmReconciliationService.class, reconcliationService,
+ ImmutableSet.of(path));
+ } else {
+ LOG.debug("The path is already registered : {}", path);
+ }
+ }
+
+ public void deregisterReconciliationRpc() {
+ if (reg != null) {
+ reg.close();
+ reg = null;
+ LOG.debug("The path is unregistered : {}", path);
+ } else {
+ LOG.debug("The path is already unregistered : {}", path);
+ }
}
}