2 * Copyright (c) 2016, 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.applications.frm.impl;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.concurrent.atomic.AtomicBoolean;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
15 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
16 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Service (per device) for registration in singleton provider.
31 public class DeviceMastership implements ClusterSingletonService, AutoCloseable {
32 private static final Logger LOG = LoggerFactory.getLogger(DeviceMastership.class);
33 private final NodeId nodeId;
34 private final ServiceGroupIdentifier identifier;
35 private final AtomicBoolean deviceMastered = new AtomicBoolean(false);
36 private final AtomicBoolean isDeviceInOperDS = new AtomicBoolean(false);
37 private final InstanceIdentifier<FlowCapableNode> fcnIID;
38 private final KeyedInstanceIdentifier<Node, NodeKey> path;
39 private final RoutedRpcRegistration routedRpcReg;
41 public DeviceMastership(final NodeId nodeId, final RoutedRpcRegistration routedRpcReg) {
43 this.identifier = ServiceGroupIdentifier.create(nodeId.getValue());
44 fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId))
45 .augmentation(FlowCapableNode.class);
46 path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
47 this.routedRpcReg = routedRpcReg;
51 public void instantiateServiceInstance() {
52 LOG.info("FRM started for: {}", nodeId.getValue());
53 deviceMastered.set(true);
57 public ListenableFuture<Void> closeServiceInstance() {
58 LOG.info("FRM stopped for: {}", nodeId.getValue());
59 deviceMastered.set(false);
60 return Futures.immediateFuture(null);
64 public ServiceGroupIdentifier getIdentifier() {
72 public boolean isDeviceMastered() {
73 return deviceMastered.get();
76 public void setDeviceOperationalStatus(boolean inOperDS) {
77 isDeviceInOperDS.set(inOperDS);
80 public void reconcile() {
81 deviceMastered.set(true);
84 public void registerReconciliationRpc() {
85 LOG.debug("The path is registered : {}", path);
86 routedRpcReg.registerPath(NodeContext.class, path);
89 public void deregisterReconciliationRpc() {
90 LOG.debug("The path is unregistered : {}", path);
91 routedRpcReg.unregisterPath(NodeContext.class, path);