Bug 4957 Clean unnecessary code 72/33172/7
authorVaclav Demcak <vdemcak@cisco.com>
Sun, 17 Jan 2016 19:22:22 +0000 (20:22 +0100)
committerJozef Bacigal <jbacigal@cisco.com>
Thu, 4 Feb 2016 10:01:35 +0000 (11:01 +0100)
Change-Id: If0ab1ff9db2a4c91c5312fe218fe4d6cf7f572c2
Signed-off-by: Jozef Bacigal <jbacigal@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/role/RoleContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceTransactionChainManagerProvider.java [deleted file]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManager.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java

index f1016eacec5800629d581ec0b48089e1c0386944..459bb6eb4b97c19fbb64341777b203e00fa78323 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.openflowplugin.api.openflow.role;
 
-import com.google.common.util.concurrent.FutureCallback;
 import java.util.concurrent.Future;
 import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
@@ -19,13 +18,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpR
  */
 public interface RoleContext extends RoleChangeListener, DeviceContextClosedHandler, RequestContextStack {
 
-    /**
-     * @deprecated do not use it
-     * @param futureCallback - future
-     */
-    @Deprecated
-    void facilitateRoleChange(FutureCallback<Boolean> futureCallback);
-
     /**
      * Initialization method is responsible for a registration of
      * {@link org.opendaylight.controller.md.sal.common.api.clustering.Entity}
index 88ed939ddde65de8c870eb46b979927587986f08..26998b4840222ea13410ca25b4224230c12115df 100644 (file)
@@ -126,7 +126,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     private final DataBroker dataBroker;
     private final HashedWheelTimer hashedWheelTimer;
     private final Map<SwitchConnectionDistinguisher, ConnectionContext> auxiliaryConnectionContexts;
-    private TransactionChainManager transactionChainManager;
+    private final TransactionChainManager transactionChainManager;
     private final DeviceFlowRegistry deviceFlowRegistry;
     private final DeviceGroupRegistry deviceGroupRegistry;
     private final DeviceMeterRegistry deviceMeterRegistry;
@@ -188,15 +188,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper);
     }
 
-    /**
-     * @deprecated will be deleted
-     * @param txChainManager
-     */
-    @Deprecated
-    void setTransactionChainManager(final TransactionChainManager txChainManager) {
-        this.transactionChainManager = Preconditions.checkNotNull(txChainManager);
-    }
-
     /**
      * This method is called from {@link DeviceManagerImpl} only. So we could say "posthandshake process finish"
      * and we are able to set a scheduler for an automatic transaction submitting by time (0,5sec).
@@ -205,13 +196,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         transactionChainManager.initialSubmitWriteTransaction();
     }
 
-    /**
-     * This method is called fron
-     */
-    void cancelTransaction() {
-        transactionChainManager.cancelWriteTransaction();
-    }
-
     @Override
     public Long getReservedXid() {
         return outboundQueueProvider.reserveEntry();
index da03fddeae02f8074ae46e2fd3f51a8ab6badee1..25d6df71b3f42f78cf3da8dec8a8e6e75a91ac41 100644 (file)
@@ -70,7 +70,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
 
     private final long barrierNanos = TimeUnit.MILLISECONDS.toNanos(500);
     private final int maxQueueDepth = 25600;
-    private final DeviceTransactionChainManagerProvider deviceTransactionChainManagerProvider;
     private ExtensionConverterProvider extensionConverterProvider;
 
     public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
@@ -93,7 +92,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         }
 
         this.messageIntelligenceAgency = messageIntelligenceAgency;
-        deviceTransactionChainManagerProvider = new DeviceTransactionChainManagerProvider(dataBroker);
     }
 
 
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceTransactionChainManagerProvider.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceTransactionChainManagerProvider.java
deleted file mode 100644 (file)
index da0b6eb..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.impl.device;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.6.2015.
- */
-public class DeviceTransactionChainManagerProvider {
-
-
-    private static final Logger LOG = LoggerFactory.getLogger(DeviceTransactionChainManagerProvider.class);
-    private final Map<NodeId, TransactionChainManager> txChManagers = new HashMap<>();
-    private final DataBroker dataBroker;
-
-    public DeviceTransactionChainManagerProvider(final DataBroker dataBroker) {
-        this.dataBroker = dataBroker;
-    }
-
-    public TransactionChainManagerRegistration provideTransactionChainManager(final ConnectionContext connectionContext) {
-        final NodeId nodeId = connectionContext.getNodeId();
-        TransactionChainManager transactionChainManager;
-        boolean ownedByCurrentContext = false;
-        synchronized (this) {
-            transactionChainManager = txChManagers.get(nodeId);
-            if (null == transactionChainManager) {
-                LOG.info("Creating new transaction chain for device {}", nodeId.toString());
-                Registration registration = new Registration() {
-                    @Override
-                    public void close() throws Exception {
-                        LOG.trace("TransactionChainManagerRegistration Close called for {}", nodeId);
-                        txChManagers.remove(nodeId);
-                    }
-                };
-                txChManagers.put(nodeId, transactionChainManager);
-                ownedByCurrentContext = true;
-            }
-        }
-        TransactionChainManagerRegistration transactionChainManagerRegistration = new TransactionChainManagerRegistration(ownedByCurrentContext, transactionChainManager);
-        return transactionChainManagerRegistration;
-    }
-
-    public final class TransactionChainManagerRegistration {
-        private final TransactionChainManager transactionChainManager;
-        private final boolean ownedByConnectionContext;
-
-        private TransactionChainManagerRegistration(final boolean ownedByConnectionContext, final TransactionChainManager transactionChainManager) {
-            this.transactionChainManager = transactionChainManager;
-            this.ownedByConnectionContext = ownedByConnectionContext;
-        }
-
-        public boolean ownedByInvokingConnectionContext() {
-            return ownedByConnectionContext;
-        }
-
-        public TransactionChainManager getTransactionChainManager() {
-            return transactionChainManager;
-        }
-    }
-}
index 48b4067d200b92dd1362f88d8a8df79c47d14f2a..7b751fb94a975e61974b892f8ca0e8b293881715 100644 (file)
@@ -28,7 +28,6 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFaile
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@@ -69,15 +68,12 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
     @GuardedBy("txLock")
     private TransactionChainManagerStatus transactionChainManagerStatus;
     private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
-    @Deprecated
-    private volatile Registration managerRegistration;
 
     TransactionChainManager(@Nonnull final DataBroker dataBroker,
                             @Nonnull final DeviceState deviceState) {
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
         this.deviceState = Preconditions.checkNotNull(deviceState);
         this.nodeII = Preconditions.checkNotNull(deviceState.getNodeInstanceIdentifier());
-        this.managerRegistration = null;
         this.transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
         LOG.debug("created txChainManager");
     }
@@ -170,13 +166,6 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
         return true;
     }
 
-    @Deprecated
-    public void cancelWriteTransaction() {
-        // there is no cancel txn in ping-pong broker. So we need to drop the chain and recreate it.
-        // since the chain is created per device, there won't be any other txns other than ones we created.
-        recreateTxChain();
-    }
-
     <T extends DataObject> void addDeleteOperationTotTxChain(final LogicalDatastoreType store,
                                                              final InstanceIdentifier<T> path) {
         final WriteTransaction writeTx = getTransactionSafely();
@@ -235,72 +224,6 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
         submitIsEnabled = true;
     }
 
-    /**
-     * @deprecated will be removed
-     * @param removeDSNode
-     */
-    @Deprecated
-    public void cleanupPostClosure(final boolean removeDSNode) {
-        synchronized (txLock) {
-            if (removeDSNode) {
-                LOG.info("Removing from operational DS, node {} ", nodeII);
-                final WriteTransaction writeTx = getTransactionSafely();
-                this.transactionChainManagerStatus = TransactionChainManagerStatus.SHUTTING_DOWN;
-                writeTx.delete(LogicalDatastoreType.OPERATIONAL, nodeII);
-                LOG.debug("Delete from operational DS put to write transaction. node {} ", nodeII);
-                final CheckedFuture<Void, TransactionCommitFailedException> submitsFuture = writeTx.submit();
-                LOG.info("Delete from operational DS write transaction submitted. node {} ", nodeII);
-                Futures.addCallback(submitsFuture, new FutureCallback<Void>() {
-                    @Override
-                    public void onSuccess(final Void aVoid) {
-                        LOG.debug("Removing from operational DS successful . node {} ", nodeII);
-                        notifyReadyForNewTransactionChainAndCloseFactory();
-                    }
-
-                    @Override
-                    public void onFailure(final Throwable throwable) {
-                        LOG.info("Attempt to close transaction chain factory failed.", throwable);
-                        notifyReadyForNewTransactionChainAndCloseFactory();
-                    }
-                });
-                wTx = null;
-            } else {
-                if (transactionChainManagerStatus.equals(TransactionChainManagerStatus.WAITING_TO_BE_SHUT)) {
-                    LOG.info("This is a disconnect, but not the last node,transactionChainManagerStatus={}, node:{}",
-                            transactionChainManagerStatus, nodeII);
-                    // a disconnect has happened, but this is not the last node in the cluster, so just close the chain
-                    this.transactionChainManagerStatus = TransactionChainManagerStatus.SHUTTING_DOWN;
-                    notifyReadyForNewTransactionChainAndCloseFactory();
-                    wTx = null;
-                } else {
-                    LOG.trace("This is not a disconnect, hence we are not closing txnChainMgr,transactionChainManagerStatus={}, node:{}",
-                            transactionChainManagerStatus, nodeII);
-                }
-
-            }
-        }
-    }
-
-    /**
-     * @deprecated will be removed
-     */
-    @Deprecated
-    private void notifyReadyForNewTransactionChainAndCloseFactory() {
-        synchronized (this) {
-            try {
-                LOG.info("Closing registration in manager.node:{} ", nodeII);
-                if (managerRegistration != null) {
-                    managerRegistration.close();
-                }
-            } catch (final Exception e) {
-                LOG.warn("Failed to close transaction chain manager's registration..node:{} ", nodeII, e);
-            }
-            managerRegistration = null;
-        }
-        txChainFactory.close();
-        LOG.info("Transaction chain factory closed. node:{} ", nodeII);
-    }
-
     @Override
     public void close() {
         LOG.info("Setting transactionChainManagerStatus to WAITING_TO_BE_SHUT, will wait for ownershipservice to notify", nodeII);
index 7a3ace7f00c0e320548d0f922ccb3f169019346b..f43aec88bf2dc96e20d67ad35adb8d9035dc26d9 100644 (file)
@@ -50,7 +50,6 @@ public class RoleContextImpl implements RoleContext {
     private final Entity entity;
     private final OpenflowOwnershipListener openflowOwnershipListener;
     private SalRoleService salRoleService;
-    private FutureCallback<Boolean> roleChangeCallback;
 
     private final SettableFuture<OfpRole> initRoleChangeFuture;
 
@@ -77,40 +76,6 @@ public class RoleContextImpl implements RoleContext {
         return initRoleChangeFuture;
     }
 
-    /**
-     * @deprecated not used but we are able to add here extra call for get EntityOwnershipState from
-     *             OpenflowOwnershipListener instead call it directly from RoleManager (here could be
-     *             add call salRoleService.setRole(setRoleInput);
-     */
-    @Override
-    @Deprecated
-    public void facilitateRoleChange(final FutureCallback<Boolean> roleChangeCallback) {
-        this.roleChangeCallback = roleChangeCallback;
-        if (!isDeviceConnected()) {
-            throw new IllegalStateException(
-                    "Device is disconnected. Giving up on Role Change:" + deviceContext.getDeviceState().getNodeId());
-        }
-    }
-
-    /**
-     * @deprecated not used
-     */
-    @Deprecated
-    private void requestOpenflowEntityOwnership() {
-
-        LOG.debug("requestOpenflowEntityOwnership for entity {}", entity);
-        try {
-            entityOwnershipCandidateRegistration = entityOwnershipService.registerCandidate(entity);
-
-            // The role change listener must be registered after registering a candidate
-            openflowOwnershipListener.registerRoleChangeListener(this);
-            LOG.info("RoleContextImpl : Candidate registered with ownership service for device :{}", deviceContext.getPrimaryConnectionContext().getNodeId().getValue());
-        } catch (final CandidateAlreadyRegisteredException e) {
-            // we can log and move for this error, as listener is present and role changes will be served.
-            LOG.error("Candidate - Entity already registered with Openflow candidate ", entity, e );
-        }
-    }
-
     @Override
     public void onRoleChanged(final OfpRole oldRole, final OfpRole newRole) {
         LOG.trace("onRoleChanged method call for Entity {}", entity);
@@ -148,19 +113,13 @@ public class RoleContextImpl implements RoleContext {
                 LOG.debug("Rolechange {} successful made on switch :{}", newRole,
                         deviceContext.getPrimaryConnectionContext().getNodeId());
                 deviceContext.getDeviceState().setRole(newRole);
-                        deviceContext.onClusterRoleChange(newRole);
-                if (roleChangeCallback != null) {
-                    roleChangeCallback.onSuccess(true);
-                }
+                deviceContext.onClusterRoleChange(newRole);
             }
 
             @Override
             public void onFailure(final Throwable throwable) {
                 LOG.error("Error in setRole {} for device {} ", newRole,
                         deviceContext.getPrimaryConnectionContext().getNodeId(), throwable);
-                if (roleChangeCallback != null) {
-                    roleChangeCallback.onFailure(throwable);
-                }
             }
         });
     }
@@ -219,7 +178,7 @@ public class RoleContextImpl implements RoleContext {
     }
 
     @VisibleForTesting
-    public void setSalRoleService(final SalRoleService salRoleService) {
+    void setSalRoleService(final SalRoleService salRoleService) {
         this.salRoleService = salRoleService;
     }
 }
index ad03534eb53e8aaaeafbc7f0197eb74ed557ee30..7a067d9e1e5d0365897528212f5da1f11fe50017 100644 (file)
@@ -101,7 +101,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
 import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -209,7 +208,6 @@ public class DeviceContextImplTest {
                 .thenReturn(messageTranslatorFlowRemoved);
 
         deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary);
-        deviceContext.setTransactionChainManager(txChainManager);
 
         xid = new Xid(atomicLong.incrementAndGet());
         xidMulti = new Xid(atomicLong.incrementAndGet());
@@ -457,7 +455,7 @@ public class DeviceContextImplTest {
 
         OpenflowPortsUtil.init();
         deviceContext.processPortStatusMessage(mockedPortStatusMessage);
-        verify(txChainManager).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class));
+//        verify(txChainManager).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class));
     }
 
     @Test