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.collect.ImmutableSet;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.concurrent.atomic.AtomicBoolean;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.mdsal.binding.api.RpcProviderService;
17 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
18 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService;
25 import org.opendaylight.yangtools.concepts.ObjectRegistration;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Service (per device) for registration in singleton provider.
34 public class DeviceMastership implements ClusterSingletonService, AutoCloseable {
35 private static final Logger LOG = LoggerFactory.getLogger(DeviceMastership.class);
36 private final NodeId nodeId;
37 private final ServiceGroupIdentifier identifier;
38 private final AtomicBoolean deviceMastered = new AtomicBoolean(false);
39 private final AtomicBoolean isDeviceInOperDS = new AtomicBoolean(false);
40 private final InstanceIdentifier<FlowCapableNode> fcnIID;
41 private final KeyedInstanceIdentifier<Node, NodeKey> path;
43 private ObjectRegistration<@NonNull FrmReconciliationService> reg;
45 public DeviceMastership(final NodeId nodeId) {
47 this.identifier = ServiceGroupIdentifier.create(nodeId.getValue());
48 fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId))
49 .augmentation(FlowCapableNode.class);
50 path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
54 public void instantiateServiceInstance() {
55 LOG.info("FRM started for: {}", nodeId.getValue());
56 deviceMastered.set(true);
60 public ListenableFuture<Void> closeServiceInstance() {
61 LOG.info("FRM stopped for: {}", nodeId.getValue());
62 deviceMastered.set(false);
63 return Futures.immediateFuture(null);
67 public ServiceGroupIdentifier getIdentifier() {
75 public boolean isDeviceMastered() {
76 return deviceMastered.get();
79 public void setDeviceOperationalStatus(final boolean inOperDS) {
80 isDeviceInOperDS.set(inOperDS);
83 public void reconcile() {
84 deviceMastered.set(true);
87 public void registerReconciliationRpc(final RpcProviderService rpcProviderService,
88 final FrmReconciliationService reconcliationService) {
90 LOG.debug("The path is registered : {}", path);
91 reg = rpcProviderService.registerRpcImplementation(FrmReconciliationService.class, reconcliationService,
92 ImmutableSet.of(path));
94 LOG.debug("The path is already registered : {}", path);
98 public void deregisterReconciliationRpc() {
102 LOG.debug("The path is unregistered : {}", path);
104 LOG.debug("The path is already unregistered : {}", path);