Remove excessive (trace) logging in FRS
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorClusterDecorator.java
1 /**
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.applications.frsync.impl;
10
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;
22
23 /**
24  * Decorator for cluster related issues.
25  */
26 public class SyncReactorClusterDecorator implements SyncReactor {
27     private static final Logger LOG = LoggerFactory.getLogger(SyncReactorClusterDecorator.class);
28     private final SyncReactor delegate;
29     private final DeviceMastershipManager deviceMastershipManager;
30
31     public SyncReactorClusterDecorator(final SyncReactor delegate,
32                                        final DeviceMastershipManager deviceMastershipManager) {
33         this.delegate = delegate;
34         this.deviceMastershipManager = deviceMastershipManager;
35     }
36
37     @Override
38     public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
39                                             final SyncupEntry syncupEntry) throws InterruptedException {
40         final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
41         if (!deviceMastershipManager.isDeviceMastered(nodeId)) {
42             LOG.debug("Skip syncup since not master for: {}", nodeId.getValue());
43             return Futures.immediateFuture(Boolean.TRUE);
44         } else {
45             return delegate.syncup(flowcapableNodePath, syncupEntry);
46         }
47     }
48 }