use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project bgpcep by opendaylight.
the class AbstractLabeledUnicastRIBSupport method extractLabel.
public static List<LabelStack> extractLabel(final DataContainerNode<? extends PathArgument> route, final NodeIdentifier labelStackNid, final NodeIdentifier labelValueNid) {
final List<LabelStack> labels = new ArrayList<>();
final Optional<DataContainerChild<? extends PathArgument, ?>> labelStacks = route.getChild(labelStackNid);
if (labelStacks.isPresent()) {
for (final UnkeyedListEntryNode label : ((UnkeyedListNode) labelStacks.get()).getValue()) {
final Optional<DataContainerChild<? extends PathArgument, ?>> labelStack = label.getChild(labelValueNid);
if (labelStack.isPresent()) {
final LabelStackBuilder labelStackbuilder = new LabelStackBuilder();
labelStackbuilder.setLabelValue(new MplsLabel((Long) labelStack.get().getValue()));
labels.add(labelStackbuilder.build());
}
}
}
return labels;
}
use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project bgpcep by opendaylight.
the class LinkstateNlriParser method serializeLocalNodeDescriptor.
private static void serializeLocalNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) {
// link local node descriptors
final LinkCaseBuilder linkBuilder = new LinkCaseBuilder();
linkBuilder.setLocalNodeDescriptors(NodeNlriParser.serializeLocalNodeDescriptors((ContainerNode) objectType.getChild(LOCAL_NODE_DESCRIPTORS_NID).get()));
// link remote node descriptors
if (objectType.getChild(REMOTE_NODE_DESCRIPTORS_NID).isPresent()) {
linkBuilder.setRemoteNodeDescriptors(NodeNlriParser.serializeRemoteNodeDescriptors((ContainerNode) objectType.getChild(REMOTE_NODE_DESCRIPTORS_NID).get()));
}
// link descriptors
final Optional<DataContainerChild<? extends PathArgument, ?>> linkDescriptors = objectType.getChild(LINK_DESCRIPTORS_NID);
if (linkDescriptors.isPresent()) {
linkBuilder.setLinkDescriptors(LinkNlriParser.serializeLinkDescriptors((ContainerNode) linkDescriptors.get()));
}
builder.setObjectType(linkBuilder.build());
}
use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project bgpcep by opendaylight.
the class LinkstateNlriParser method serializeCommonParts.
private static void serializeCommonParts(final CLinkstateDestinationBuilder builder, final DataContainerNode<? extends PathArgument> linkstate) {
// serialize common parts
final Optional<DataContainerChild<? extends PathArgument, ?>> distinguisher = linkstate.getChild(DISTINGUISHER_NID);
if (distinguisher.isPresent()) {
builder.setDistinguisher(new RouteDistinguisher((BigInteger) distinguisher.get().getValue()));
}
final Optional<DataContainerChild<? extends PathArgument, ?>> protocolId = linkstate.getChild(PROTOCOL_ID_NID);
// DOM representation contains values as are in the model, not as are in generated enum
if (protocolId.isPresent()) {
builder.setProtocolId(ProtocolId.forValue(domProtocolIdValue((String) protocolId.get().getValue())));
}
final Optional<DataContainerChild<? extends PathArgument, ?>> identifier = linkstate.getChild(IDENTIFIER_NID);
if (identifier.isPresent()) {
builder.setIdentifier(new Identifier((BigInteger) identifier.get().getValue()));
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project controller by opendaylight.
the class EntityOwnershipShard method onRegisterListenerLocal.
private void onRegisterListenerLocal(final RegisterListenerLocal registerListener) {
LOG.debug("{}: onRegisterListenerLocal: {}", persistenceId(), registerListener);
listenerSupport.addEntityOwnershipListener(registerListener.getEntityType(), registerListener.getListener());
getSender().tell(SuccessReply.INSTANCE, getSelf());
searchForEntities((entityTypeNode, entityNode) -> {
java.util.Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
String entityType = possibleType.isPresent() ? possibleType.get().getValue().toString() : null;
if (registerListener.getEntityType().equals(entityType)) {
final boolean hasOwner;
final boolean isOwner;
java.util.Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
if (possibleOwner.isPresent()) {
isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString());
hasOwner = true;
} else {
isOwner = false;
hasOwner = false;
}
DOMEntity entity = new DOMEntity(entityType, (YangInstanceIdentifier) entityNode.getChild(ENTITY_ID_NODE_ID).get().getValue());
listenerSupport.notifyEntityOwnershipListener(entity, false, isOwner, hasOwner, registerListener.getListener());
}
});
}
use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild 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));
}
Aggregations