use of org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner in project netvirt by opendaylight.
the class NodeConnectedHandlerTest method testD1Connect.
@Test
// need to fix this Test. Actual functionality is fine
@Ignore
public void testD1Connect() throws Exception {
ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(getDataBroker());
txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> handlerUtils.addPsNode(d1PsNodePath, d1NodePath, DataProvider.getPortNameListD1(), tx)).get();
txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> handlerUtils.addNode(d1NodePath, d1PsNodePath, DataProvider.getLogicalSwitchDataD1(), DataProvider.getLocalUcasMacDataD1(), DataProvider.getLocalMcastDataD1(), DataProvider.getRemoteMcastDataD1(), DataProvider.getRemoteUcasteMacDataD1(), DataProvider.getGlobalTerminationPointIpD1(), tx)).get();
readNodes();
txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> nodeConnectedHandler.handleNodeConnected(d1GlobalOpNode.get(), d1NodePath, haNodePath, haGlobalConfigNode, haPsConfigNode, confTx, operTx)).get()).get();
readNodes();
// verify global ha manager config should have ha_children
Assert.assertTrue(haGlobalConfigNode.isPresent());
Assert.assertTrue(d1GlobalOpNode.isPresent());
TestUtil.verifyHAconfigNode(haGlobalConfigNode.get(), d1GlobalOpNode.get());
Assert.assertTrue(d1GlobalOpNode.isPresent());
Assert.assertTrue(haGlobalOpNode.isPresent());
Assert.assertTrue(d1PsOpNode.isPresent());
Assert.assertTrue(haPsOpNode.isPresent());
TestUtil.verifyHAOpNode(d1GlobalOpNode.get(), haGlobalOpNode.get(), d1PsOpNode.get(), haPsOpNode.get(), haNodePath, d1PsNodePath, haPsNodePath, getDataBroker());
}
use of org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner in project netvirt by opendaylight.
the class NetworkL2gwDeviceInfoCli method doExecute.
@Override
@Nullable
@SuppressWarnings("illegalcatch")
protected Object doExecute() {
ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
try {
txRunner.callWithNewReadOnlyTransactionAndClose(OPERATIONAL, operTx -> {
List<Node> nodes = new ArrayList<>();
Set<String> networks = new HashSet<>();
if (nodeId == null) {
Optional<Topology> topologyOptional = operTx.read(createHwvtepTopologyInstanceIdentifier()).get();
if (topologyOptional.isPresent()) {
nodes = new ArrayList<>(topologyOptional.get().getNode().values());
}
} else {
Optional<Node> nodeOptional = operTx.read(createInstanceIdentifier(new NodeId(new Uri(nodeId)))).get();
if (nodeOptional.isPresent()) {
nodes.add(nodeOptional.get());
}
}
if (elanName == null) {
// get all elan instance
// get all device node id
// print result
Optional<ElanInstances> elanInstancesOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(ElanInstances.class).build());
if (elanInstancesOptional.isPresent()) {
List<ElanInstance> elans = new ArrayList<>(elanInstancesOptional.get().getElanInstance().values());
if (elans != null) {
for (ElanInstance elan : elans) {
networks.add(elan.getElanInstanceName());
}
}
}
} else {
networks.add(elanName);
}
if (nodes != null) {
for (Node node : nodes) {
if (node.getNodeId().getValue().contains("physicalswitch")) {
continue;
}
Node hwvtepConfigNode = HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION, node.getNodeId());
Node hwvtepOpPsNode = getPSnode(node, LogicalDatastoreType.OPERATIONAL);
Node hwvtepConfigPsNode = null;
if (hwvtepOpPsNode != null) {
hwvtepConfigPsNode = HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION, hwvtepOpPsNode.getNodeId());
opPSNodes.put(node.getNodeId(), hwvtepOpPsNode);
}
opNodes.put(node.getNodeId(), node);
configNodes.put(node.getNodeId(), hwvtepConfigNode);
if (hwvtepConfigPsNode != null) {
configPSNodes.put(node.getNodeId(), hwvtepConfigPsNode);
}
}
}
if (!networks.isEmpty()) {
for (String network : networks) {
session.getConsole().println("Network info for " + network);
if (nodes != null) {
for (Node node : nodes) {
if (node.getNodeId().getValue().contains("physicalswitch")) {
continue;
}
session.getConsole().println("Printing for node " + node.getNodeId().getValue());
process(node.getNodeId(), network);
}
}
}
}
});
} catch (Exception e) {
session.getConsole().println("Failed with error " + e.getMessage());
}
return null;
}
use of org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner in project netvirt by opendaylight.
the class MergeCommandsAggregator method mergeUpdate.
@SuppressWarnings("illegalcatch")
public <D extends Datastore> void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, Class<D> datastoreType, TypedReadWriteTransaction<D> transaction, ManagedNewTransactionRunner txRunner) {
BatchedTransaction tx = null;
if (mod == null || mod.getModifiedChildren() == null) {
return;
}
if (!(transaction instanceof BatchedTransaction)) {
return;
} else {
tx = (BatchedTransaction) transaction;
}
final BatchedTransaction transaction1 = tx;
String srcNodeId = transaction1.getSrcNodeId().getValue();
String dstNodeId = dstPath.firstKeyOf(Node.class).getNodeId().getValue();
Collection<DataObjectModification> modifications = mod.getModifiedChildren();
modifications.stream().filter(modification -> skipCopy.negate().test(datastoreType, modification.getDataType())).filter(modification -> commands.get(modification.getDataType()) != null).peek(modification -> LOG.debug("Received {} modification {} copy/delete to {}", datastoreType, modification, dstPath)).forEach(modification -> {
try {
copyModification(dstPath, datastoreType, transaction1, srcNodeId, dstNodeId, modification, txRunner);
} catch (Exception e) {
LOG.error("Failed to copy mod from {} to {} {} {} id {}", srcNodeId, dstNodeId, modification.getDataType().getSimpleName(), modification, modification.getIdentifier(), e);
}
});
}
Aggregations