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.mdsal.singleton.common.api.ClusterSingletonService;
15 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Service (per device) for registration in singleton provider.
28 public class DeviceMastership implements ClusterSingletonService, AutoCloseable {
29 private static final Logger LOG = LoggerFactory.getLogger(DeviceMastership.class);
30 private final NodeId nodeId;
31 private final ServiceGroupIdentifier identifier;
32 private final AtomicBoolean deviceMastered = new AtomicBoolean(false);
33 private final AtomicBoolean isDeviceInOperDS = new AtomicBoolean(false);
34 private final InstanceIdentifier<FlowCapableNode> fcnIID;
36 public DeviceMastership(final NodeId nodeId) {
38 this.identifier = ServiceGroupIdentifier.create(nodeId.getValue());
39 fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId))
40 .augmentation(FlowCapableNode.class);
44 public void instantiateServiceInstance() {
45 LOG.info("FRM started for: {}", nodeId.getValue());
46 deviceMastered.set(true);
50 public ListenableFuture<Void> closeServiceInstance() {
51 LOG.info("FRM stopped for: {}", nodeId.getValue());
52 deviceMastered.set(false);
53 return Futures.immediateFuture(null);
57 public ServiceGroupIdentifier getIdentifier() {
65 public boolean isDeviceMastered() {
66 return deviceMastered.get();
69 public void setDeviceOperationalStatus(boolean inOperDS) {
70 isDeviceInOperDS.set(inOperDS);
73 public void reconcile() {
74 deviceMastered.set(true);