loadLspData(initialNodeState, this.lspData, this.lsps, isIncrementalSynchro());
pccBuilder.setReportedLsp(initialNodeState.getAugmentation(Node1.class).getPathComputationClient().getReportedLsp());
}
- writeNode(pccBuilder, state, topologyAugment);
+ state.storeNode(topologyAugment,
+ new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), this.session);
register();
if (this.registration == null) {
LOG.error("PCEP session fails to register. Closing session {}", session);
LOG.info("Session with {} attached to topology node {}", session.getRemoteAddress(), state.getNodeId());
}
- private void writeNode(final PathComputationClientBuilder pccBuilder, final TopologyNodeState state,
- final InstanceIdentifier<Node1> topologyAugment) {
- final Node1 ta = new Node1Builder().setPathComputationClient(pccBuilder.build()).build();
-
- final ReadWriteTransaction trans = state.rwTransaction();
- trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
- LOG.trace("Peer data {} set to {}", topologyAugment, ta);
-
- // All set, commit the modifications
- Futures.addCallback(trans.submit(), new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- LOG.trace("Internal state for session {} updated successfully", AbstractTopologySessionListener.this.session);
- }
-
- @Override
- public void onFailure(final Throwable t) {
- LOG.error("Failed to update internal state for session {}, terminating it", AbstractTopologySessionListener.this.session, t);
- AbstractTopologySessionListener.this.session.close(TerminationReason.UNKNOWN);
- }
- });
- }
-
protected void updatePccState(final PccSyncState pccSyncState) {
if (this.nodeState == null) {
LOG.info("Server Session Manager is closed.");
AbstractTopologySessionListener.this.session.close(TerminationReason.UNKNOWN);
return;
}
- final MessageContext ctx = new MessageContext(this.nodeState.beginTransaction());
+ final MessageContext ctx = new MessageContext(this.nodeState.getChain().newWriteOnlyTransaction());
updatePccNode(ctx, new PathComputationClientBuilder().setStateSync(pccSyncState).build());
if (pccSyncState != PccSyncState.Synchronized) {
this.synced = false;
Futures.addCallback(ctx.trans.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
- LOG.trace("Internal state for session {} updated successfully", AbstractTopologySessionListener.this.session);
+ LOG.trace("Pcc Internal state for session {} updated successfully", AbstractTopologySessionListener.this.session);
}
@Override
public void onFailure(final Throwable t) {
- LOG.error("Failed to update internal state for session {}", AbstractTopologySessionListener.this.session, t);
+ LOG.error("Failed to update Pcc internal state for session {}", AbstractTopologySessionListener.this.session, t);
AbstractTopologySessionListener.this.session.close(TerminationReason.UNKNOWN);
}
});
session.close(TerminationReason.UNKNOWN);
return;
}
- final MessageContext ctx = new MessageContext(this.nodeState.beginTransaction());
+ final MessageContext ctx = new MessageContext(this.nodeState.getChain().newWriteOnlyTransaction());
if (onMessage(ctx, message)) {
LOG.warn("Unhandled message {} on session {}", message, session);
new TopologyProgramming(this.scheduler, this.manager)));
this.network.registerPath(NetworkTopologyContext.class, this.topology);
try {
- this.manager.instantiateServiceInstance().checkedGet();
+ this.manager.instantiateServiceInstance();
final ChannelFuture channelFuture = this.dependenciesProvider.getPCEPDispatcher()
.createServer(this.address, this.keys, this.manager, this.manager);
channelFuture.get();
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
}
/**
- * Create Base Topology
- *
- * @throws TransactionCommitFailedException exception
+ * Create Base Topology.
*/
- synchronized CheckedFuture<Void, TransactionCommitFailedException> instantiateServiceInstance() {
+ synchronized void instantiateServiceInstance() {
final TopologyKey key = InstanceIdentifier.keyOf(this.topology);
final TopologyId topologyId = key.getTopologyId();
final WriteTransaction tx = this.broker.newWriteOnlyTransaction();
.addAugmentation(TopologyTypes1.class, new TopologyTypes1Builder().setTopologyPcep(
new TopologyPcepBuilder().build()).build()).build())
.setNode(new ArrayList<>()).build(), true);
- final CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
- Futures.addCallback(future, new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- LOG.debug("PCEP Topology {} created successfully.", topologyId.getValue());
- ServerSessionManager.this.isClosed.set(false);
- }
-
- @Override
- public void onFailure(final Throwable t) {
- LOG.error("Failed to create PCEP Topology {}.", topologyId.getValue(), t);
- ServerSessionManager.this.isClosed.set(true);
- }
- });
- return future;
+ try {
+ tx.submit().get();
+ LOG.info("PCEP Topology {} created successfully.", topologyId.getValue());
+ ServerSessionManager.this.isClosed.set(false);
+ } catch (final ExecutionException | InterruptedException throwable) {
+ LOG.error("Failed to create PCEP Topology {}.", topologyId.getValue(), throwable);
+ ServerSessionManager.this.isClosed.set(true);
+ }
}
private static NodeId createNodeId(final InetAddress addr) {
}
@Override
- protected boolean onMessage(final MessageContext ctx, final Message message) {
+ protected synchronized boolean onMessage(final MessageContext ctx, final Message message) {
if (message instanceof PcerrMessage) {
return handleErrorMessage((PcerrMessage) message);
}
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
+import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.TerminationReason;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.lsp.metadata.Metadata;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
private final long holdStateNanos;
private long lastReleased = 0;
//cache initial node state, if any node was persisted
+ @GuardedBy("this")
private Node initialNodeState = null;
public TopologyNodeState(final DataBroker broker, final InstanceIdentifier<Topology> topology, final NodeId id, final long holdStateNanos) {
// The session went down. Undo all the Topology changes we have done.
// We might want to persist topology node for later re-use.
if (!persist) {
- final WriteTransaction trans = beginTransaction();
+ final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
trans.delete(LogicalDatastoreType.OPERATIONAL, this.nodeId);
Futures.addCallback(trans.submit(), new FutureCallback<Void>() {
@Override
//try to get the topology's node
if (retrieveNode) {
- Futures.addCallback(readOperationalData(this.nodeId), new FutureCallback<Optional<Node>>() {
-
- @Override
- public void onSuccess(final Optional<Node> result) {
- if (!result.isPresent()) {
- putTopologyNode();
- } else {
- //cache retrieved node
- TopologyNodeState.this.initialNodeState = result.get();
- }
- }
-
- @Override
- public void onFailure(final Throwable t) {
- LOG.error("Failed to get topology node {}", TopologyNodeState.this.nodeId, t);
+ try {
+ final Optional<Node> prevNode = readOperationalData(this.nodeId).get();
+ if (!prevNode.isPresent()) {
+ putTopologyNode();
+ } else {
+ //cache retrieved node
+ TopologyNodeState.this.initialNodeState = prevNode.get();
}
- });
+ } catch (final ExecutionException | InterruptedException throwable) {
+ LOG.error("Failed to get topology node {}", TopologyNodeState.this.nodeId, throwable);
+ }
} else {
putTopologyNode();
}
return this.initialNodeState;
}
- WriteTransaction beginTransaction() {
- return this.chain.newWriteOnlyTransaction();
+ synchronized BindingTransactionChain getChain() {
+ return this.chain;
}
- ReadWriteTransaction rwTransaction() {
- return this.chain.newReadWriteTransaction();
- }
-
- <T extends DataObject> ListenableFuture<Optional<T>> readOperationalData(final InstanceIdentifier<T> id) {
+ synchronized <T extends DataObject> ListenableFuture<Optional<T>> readOperationalData(final InstanceIdentifier<T> id) {
try (final ReadOnlyTransaction t = this.chain.newReadOnlyTransaction()) {
return t.read(LogicalDatastoreType.OPERATIONAL, id);
}
}
@Override
- public void close() {
+ public synchronized void close() {
this.chain.close();
}
- private void putTopologyNode() {
- final Node node = new NodeBuilder().setKey(this.nodeId.getKey()).setNodeId(this.nodeId.getKey().getNodeId()).build();
- final WriteTransaction t = beginTransaction();
- t.put(LogicalDatastoreType.OPERATIONAL, this.nodeId, node);
- t.submit();
+ private synchronized void putTopologyNode() {
+ final Node node = new NodeBuilder().setKey(this.nodeId.getKey())
+ .setNodeId(this.nodeId.getKey().getNodeId()).build();
+ final WriteTransaction t = this.chain.newWriteOnlyTransaction();
+ LOG.trace("Put topology Node {}, value {}", this.nodeId, node);
+ t.merge(LogicalDatastoreType.OPERATIONAL, this.nodeId, node);
+ Futures.addCallback(t.submit(), new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ LOG.trace("Topology Node stored {}, value {}", TopologyNodeState.this.nodeId, node);
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.trace("Put topology Node failed {}, value {}, {}", TopologyNodeState.this.nodeId, node, throwable);
+ }
+ }, MoreExecutors.directExecutor());
}
+ public synchronized void storeNode(final InstanceIdentifier<Node1> topologyAugment, final Node1 ta,
+ final PCEPSession session) {
+ LOG.trace("Peer data {} set to {}", topologyAugment, ta);
+ final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
+ trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
+
+ // All set, commit the modifications
+ Futures.addCallback(trans.submit(), new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ LOG.trace("Node stored {} for session {} updated successfully", topologyAugment, session);
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.error("Failed to store node {} for session {}, terminating it",
+ topologyAugment, session, throwable);
+ session.close(TerminationReason.UNKNOWN);
+ }
+ }, MoreExecutors.directExecutor());
+ }
}
\ No newline at end of file
@Override
public synchronized void instantiateServiceInstance() {
LOG.info("PCEP Topology Provider Singleton Service {} instantiated", getIdentifier().getValue());
- if (this.pcepTopoProvider != null) {
- this.pcepTopoProvider.instantiateServiceInstance();
- this.serviceInstantiated = true;
- }
+ this.pcepTopoProvider.instantiateServiceInstance();
+ this.serviceInstantiated = true;
}
@Override
public synchronized ListenableFuture<Void> closeServiceInstance() {
LOG.info("Close PCEP Topology Provider Singleton Service {}", getIdentifier().getValue());
- if (this.pcepTopoProvider != null && this.serviceInstantiated) {
+ if (this.serviceInstantiated) {
this.serviceInstantiated = false;
return this.pcepTopoProvider.closeServiceInstance();
}
package org.opendaylight.bgpcep.pcep.topology.provider;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.MoreExecutors;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import javax.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
import org.mockito.Mock;
import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeRegistration;
import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeRegistrator;
import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiator;
import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
this.topologyRpcs = new TopologyRPCs(this.manager);
}
- protected void startSessionManager() throws TransactionCommitFailedException, InterruptedException {
+ protected void startSessionManager() throws InterruptedException {
this.manager.setRuntimeRootRegistrator(this.registrator);
- final CheckedFuture<Void, TransactionCommitFailedException> future = this.manager.instantiateServiceInstance();
+ this.manager.instantiateServiceInstance();
final CountDownLatch lock = new CountDownLatch(1);
- Futures.addCallback(future, new FutureCallback<Void>() {
- @Override
- public void onSuccess(@Nullable final Void aVoid) {
- lock.countDown();
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- // the test cannot continue
- fail();
- }
- }, MoreExecutors.directExecutor());
- future.checkedGet();
+ this.manager.instantiateServiceInstance();
+ lock.countDown();
lock.await(5000, TimeUnit.MILLISECONDS);
assertFalse(this.manager.isClosed.get());
}