2 * Copyright (c) 2016 Cisco Systems, Inc. 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.frsync.impl;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
14 import org.opendaylight.openflowplugin.applications.frsync.impl.clustering.DeviceMastershipManager;
15 import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;
16 import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Decorator for cluster related issues.
26 public class SyncReactorClusterDecorator implements SyncReactor {
28 private static final Logger LOG = LoggerFactory.getLogger(SyncReactorClusterDecorator.class);
29 private final SyncReactor delegate;
30 private final DeviceMastershipManager deviceMastershipManager;
32 public SyncReactorClusterDecorator(final SyncReactor delegate,
33 final DeviceMastershipManager deviceMastershipManager) {
34 this.delegate = delegate;
35 this.deviceMastershipManager = deviceMastershipManager;
39 public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
40 final SyncupEntry syncupEntry) {
41 final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
42 if (!deviceMastershipManager.isDeviceMastered(nodeId)) {
43 LOG.debug("Skip syncup since not master for: {}", nodeId.getValue());
44 return Futures.immediateFuture(Boolean.TRUE);
46 return delegate.syncup(flowcapableNodePath, syncupEntry);