use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project controller by opendaylight.
the class TxchainDomDelete method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (int l = 0; l < outerListElem; l++) {
YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
tx.delete(dsType, yid);
writeCnt++;
if (writeCnt == writesPerTx) {
txSubmitted++;
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
txOk++;
}
@Override
public void onFailure(final Throwable t) {
LOG.error("Transaction failed, {}", t);
txError++;
}
});
tx = chain.newWriteOnlyTransaction();
writeCnt = 0;
}
}
// We need to empty the transaction chain before closing it
try {
txSubmitted++;
tx.submit().checkedGet();
txOk++;
} catch (final TransactionCommitFailedException e) {
LOG.error("Transaction failed", e);
txError++;
}
try {
chain.close();
} catch (final IllegalStateException e) {
LOG.error("Transaction close failed,", e);
}
LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project controller by opendaylight.
the class AbstractNormalizedNodeDataOutput method writePathArgument.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The casts in the switch clauses are indirectly confirmed via the determination of 'type'.")
@Override
public void writePathArgument(final PathArgument pathArgument) throws IOException {
byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument);
output.writeByte(type);
switch(type) {
case PathArgumentTypes.NODE_IDENTIFIER:
NodeIdentifier nodeIdentifier = (NodeIdentifier) pathArgument;
writeQName(nodeIdentifier.getNodeType());
break;
case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES:
NodeIdentifierWithPredicates nodeIdentifierWithPredicates = (NodeIdentifierWithPredicates) pathArgument;
writeQName(nodeIdentifierWithPredicates.getNodeType());
writeKeyValueMap(nodeIdentifierWithPredicates.getKeyValues());
break;
case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE:
NodeWithValue<?> nodeWithValue = (NodeWithValue<?>) pathArgument;
writeQName(nodeWithValue.getNodeType());
writeObject(nodeWithValue.getValue());
break;
case PathArgumentTypes.AUGMENTATION_IDENTIFIER:
AugmentationIdentifier augmentationIdentifier = (AugmentationIdentifier) pathArgument;
// No Qname in augmentation identifier
writeQNameSet(augmentationIdentifier.getPossibleChildNames());
break;
default:
throw new IllegalStateException("Unknown node identifier type is found : " + pathArgument.getClass().toString());
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project controller by opendaylight.
the class ProduceTransactionsHandler method start.
public static ListenableFuture<RpcResult<ProduceTransactionsOutput>> start(final DOMDataTreeService domDataTreeService, final ProduceTransactionsInput input) {
final String id = input.getId();
LOG.debug("Filling the item list {} with initial values.", id);
final YangInstanceIdentifier idListWithKey = ID_INT_YID.node(new NodeIdentifierWithPredicates(ID_INT, ID, id));
final DOMDataTreeProducer itemProducer = domDataTreeService.createProducer(Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey)));
final DOMDataTreeCursorAwareTransaction tx = itemProducer.createTransaction(false);
final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey));
final MapNode list = ImmutableNodes.mapNodeBuilder(ITEM).build();
cursor.write(list.getIdentifier(), list);
cursor.close();
try {
tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.warn("Unable to fill the initial item list.", e);
closeProducer(itemProducer);
return Futures.immediateFuture(RpcResultBuilder.<ProduceTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
}
final ProduceTransactionsHandler handler = new ProduceTransactionsHandler(itemProducer, new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey.node(list.getIdentifier()).toOptimized()), input);
// It is handler's responsibility to close itemProducer when the work is finished.
handler.doStart();
return handler.future;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project controller by opendaylight.
the class PrefixedShardConfigWriter method doWrite.
private DOMStoreThreePhaseCommitCohort doWrite(final YangInstanceIdentifier path, final Collection<MemberName> replicas) {
final ListNodeBuilder<Object, LeafSetEntryNode<Object>> replicaListBuilder = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_REPLICA_QNAME));
replicas.forEach(name -> replicaListBuilder.withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(ClusterUtils.SHARD_REPLICA_QNAME, name.getName())).withValue(name.getName()).build()));
final MapEntryNode newEntry = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifierWithPredicates(ClusterUtils.SHARD_LIST_QNAME, ClusterUtils.SHARD_PREFIX_QNAME, path)).withChild(ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_PREFIX_QNAME)).withValue(path).build()).withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_REPLICAS_QNAME)).withChild(replicaListBuilder.build()).build()).build();
final ClientTransaction tx = history.createTransaction();
final DOMDataTreeWriteCursor cursor = tx.openCursor();
ClusterUtils.SHARD_LIST_PATH.getPathArguments().forEach(cursor::enter);
cursor.write(newEntry.getIdentifier(), newEntry);
cursor.close();
return tx.ready();
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project controller by opendaylight.
the class PrefixedShardConfigWriter method checkDefaultIsPresent.
boolean checkDefaultIsPresent() {
final NodeIdentifierWithPredicates pag = new NodeIdentifierWithPredicates(ClusterUtils.SHARD_LIST_QNAME, ClusterUtils.SHARD_PREFIX_QNAME, YangInstanceIdentifier.EMPTY);
final YangInstanceIdentifier defaultId = ClusterUtils.SHARD_LIST_PATH.node(pag);
final ClientSnapshot snapshot = history.takeSnapshot();
try {
return snapshot.exists(defaultId).checkedGet();
} catch (final ReadFailedException e) {
LOG.error("Presence check of default shard in configuration failed.", e);
return false;
} finally {
snapshot.abort();
}
}
Aggregations