use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class EntityOwnershipStatistics method onDataTreeChanged.
@Override
public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> changes) {
for (DataTreeCandidate change : changes) {
DataTreeCandidateNode changeRoot = change.getRootNode();
LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get();
String entityType = entityTypeFromEntityPath(change.getRootPath());
String newOwner = extractOwner(ownerLeaf);
if (!Strings.isNullOrEmpty(newOwner)) {
updateStatistics(entityType, newOwner, 1);
}
Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore();
if (dataBefore.isPresent()) {
String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get());
if (!Strings.isNullOrEmpty(origOwner)) {
updateStatistics(entityType, origOwner, -1);
}
}
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class DistributedEntityOwnershipService method getOwnershipState.
@Override
public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
Preconditions.checkNotNull(forEntity, "forEntity cannot be null");
DataTree dataTree = getLocalEntityOwnershipShardDataTree();
if (dataTree == null) {
return Optional.absent();
}
java.util.Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(entityPath(forEntity.getType(), forEntity.getIdentifier()));
if (!entityNode.isPresent()) {
return Optional.absent();
}
// Check if there are any candidates, if there are none we do not really have ownership state
final MapEntryNode entity = (MapEntryNode) entityNode.get();
final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID);
final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
if (!hasCandidates) {
return Optional.absent();
}
MemberName localMemberName = context.getCurrentMemberName();
java.util.Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID);
String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null;
boolean hasOwner = !Strings.isNullOrEmpty(owner);
boolean isOwner = hasOwner && localMemberName.getName().equals(owner);
return Optional.of(EntityOwnershipState.from(isOwner, hasOwner));
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class EntityOwnerChangeListener method onDataTreeChanged.
@Override
public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
for (DataTreeCandidate change : changes) {
DataTreeCandidateNode changeRoot = change.getRootNode();
LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get();
LOG.debug("{}: Entity node changed: {}, {}", logId(), changeRoot.getModificationType(), change.getRootPath());
String newOwner = extractOwner(ownerLeaf);
String origOwner = null;
Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore();
if (dataBefore.isPresent()) {
origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get());
}
LOG.debug("{}: New owner: {}, Original owner: {}", logId(), newOwner, origOwner);
if (!Objects.equals(origOwner, newOwner)) {
boolean isOwner = localMemberName.equals(newOwner);
boolean wasOwner = localMemberName.equals(origOwner);
boolean hasOwner = !Strings.isNullOrEmpty(newOwner);
DOMEntity entity = createEntity(change.getRootPath());
LOG.debug("{}: Calling notifyEntityOwnershipListeners: entity: {}, wasOwner: {}, isOwner: {}, hasOwner: {}", logId(), entity, wasOwner, isOwner, hasOwner);
publisher.notifyEntityOwnershipListeners(entity, wasOwner, isOwner, hasOwner);
}
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class DOMBrokerPerformanceTest method measureOneTransactionTopContainer.
private void measureOneTransactionTopContainer() throws Exception {
final DOMDataReadWriteTransaction writeTx = measure("Txs:1 Allocate", () -> domBroker.newReadWriteTransaction());
measure("Txs:1 Write", (Callable<Void>) () -> {
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
writeTx.put(OPERATIONAL, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
return null;
});
measure("Txs:1 Reads:1", (Callable<Void>) () -> {
// Reads /test in writeTx
ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(OPERATIONAL, TestModel.TEST_PATH);
assertTrue(writeTxContainer.get().isPresent());
return null;
});
measure("Txs:1 Reads:1", (Callable<Void>) () -> {
// Reads /test in writeTx
ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(OPERATIONAL, TestModel.TEST_PATH);
assertTrue(writeTxContainer.get().isPresent());
return null;
});
measure("Txs:1 Submit, Finish", (Callable<Void>) () -> {
measure("Txs:1 Submit", (Callable<ListenableFuture<?>>) () -> writeTx.submit()).get();
return null;
});
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class RoutedDOMRpcRoutingTableEntry method invokeRpc.
@Override
protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final NormalizedNode<?, ?> input) {
final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input, keyId);
// Routing key is present, attempt to deliver as a routed RPC
if (maybeKey.isPresent()) {
final NormalizedNode<?, ?> key = maybeKey.get();
final Object value = key.getValue();
if (value instanceof YangInstanceIdentifier) {
final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;
// Find a DOMRpcImplementation for a specific iid
final List<DOMRpcImplementation> specificImpls = getImplementations(iid);
if (specificImpls != null) {
return specificImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
}
LOG.debug("No implementation for context {} found will now look for wildcard id", iid);
// Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register an
// implementation this way
final List<DOMRpcImplementation> mayBeRemoteImpls = getImplementations(YangInstanceIdentifier.EMPTY);
if (mayBeRemoteImpls != null) {
return mayBeRemoteImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
}
} else {
LOG.warn("Ignoring wrong context value {}", value);
}
}
final List<DOMRpcImplementation> impls = getImplementations(null);
if (impls != null) {
return impls.get(0).invokeRpc(globalRpcId, input);
} else {
return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", getSchemaPath()));
}
}
Aggregations