*/
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;
*/
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}
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;
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).
transactionChainManager.initialSubmitWriteTransaction();
}
- /**
- * This method is called fron
- */
- void cancelTransaction() {
- transactionChainManager.cancelWriteTransaction();
- }
-
@Override
public Long getReservedXid() {
return outboundQueueProvider.reserveEntry();
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,
}
this.messageIntelligenceAgency = messageIntelligenceAgency;
- deviceTransactionChainManagerProvider = new DeviceTransactionChainManagerProvider(dataBroker);
}
+++ /dev/null
-/*
- * 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 <mbobak@cisco.com> 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;
- }
- }
-}
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;
@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");
}
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();
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);
private final Entity entity;
private final OpenflowOwnershipListener openflowOwnershipListener;
private SalRoleService salRoleService;
- private FutureCallback<Boolean> roleChangeCallback;
private final SettableFuture<OfpRole> initRoleChangeFuture;
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);
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);
- }
}
});
}
}
@VisibleForTesting
- public void setSalRoleService(final SalRoleService salRoleService) {
+ void setSalRoleService(final SalRoleService salRoleService) {
this.salRoleService = salRoleService;
}
}
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;
.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());
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