Java Code Examples for org.opendaylight.yangtools.yang.binding.InstanceIdentifier#firstIdentifierOf()

The following examples show how to use org.opendaylight.yangtools.yang.binding.InstanceIdentifier#firstIdentifierOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HostMonitor.java    From atrium-odl with Apache License 2.0 6 votes vote down vote up
public void packetReceived(ConnectorAddress addrs, InstanceIdentifier<?> ii) {
	InstanceIdentifier<NodeConnector> iinc = ii.firstIdentifierOf(NodeConnector.class);
	InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> iin//
	= ii.firstIdentifierOf(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class);

	ListenableFuture<Optional<NodeConnector>> futureNodeConnector;
	ListenableFuture<Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node>> futureNode;
	try (ReadOnlyTransaction readTx = dataService.newReadOnlyTransaction()) {
		futureNodeConnector = readTx.read(LogicalDatastoreType.OPERATIONAL, iinc);
		futureNode = readTx.read(LogicalDatastoreType.OPERATIONAL, iin);
		readTx.close();
	}
	Optional<NodeConnector> opNodeConnector = null;
	Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> opNode = null;
	try {
		opNodeConnector = futureNodeConnector.get();
		opNode = futureNode.get();
	} catch (ExecutionException | InterruptedException ex) {
		LOG.warn(ex.getLocalizedMessage());
	}
	if (opNode != null && opNode.isPresent() && opNodeConnector != null && opNodeConnector.isPresent()) {
		processHost(opNode.get(), opNodeConnector.get(), addrs);
	}
}
 
Example 2
Source File: ControllerRemovedCommand.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private static void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
                     final Set<InstanceIdentifier<ControllerEntry>> removedControllers,
                     final Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation>
                             modifiedBridges) {
    for (InstanceIdentifier<ControllerEntry> controllerIid : removedControllers) {
        LOG.debug("Removing Registered...ODL controller : {} ", controllerIid);
        InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
                controllerIid.firstIdentifierOf(OvsdbBridgeAugmentation.class);
        OvsdbBridgeAugmentation ovsdbBridge = modifiedBridges.get(bridgeIid);
        Optional<ControllerEntry> controllerEntryOptional = state.getControllerEntry(controllerIid);
        if (ovsdbBridge != null && controllerEntryOptional.isPresent()) {
            ControllerEntry controllerEntry = controllerEntryOptional.get();
            Bridge bridge = transaction.getTypedRowWrapper(Bridge.class);
            bridge.setController(Collections.singleton(new UUID(controllerEntry.getControllerUuid().getValue())));
            transaction.add(op.mutate(bridge).addMutation(bridge.getControllerColumn().getSchema(),
                    Mutator.DELETE, bridge.getControllerColumn().getData()));
        }
    }
}
 
Example 3
Source File: DataChangesManagedByOvsdbNodeEvent.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private InstanceIdentifier<?> getManagedByIid(Map<InstanceIdentifier<?>, DataObject> map,
        InstanceIdentifier<?> iidToCheck) {
    // Get the InstanceIdentifier of the containing node
    InstanceIdentifier<Node> nodeEntryIid = iidToCheck.firstIdentifierOf(Node.class);

    // Look for the Node in the created/updated data
    DataObject dataObject = null;
    if (map != null && map.get(nodeEntryIid) != null) {
        dataObject = map.get(nodeEntryIid);
    }
    // If we are contained in a bridge managed by this iid
    if (dataObject != null && dataObject instanceof Node) {
        Node node = (Node)dataObject;
        OvsdbBridgeAugmentation bridge = node.augmentation(OvsdbBridgeAugmentation.class);
        if (bridge != null && bridge.getManagedBy() != null && bridge.getManagedBy().getValue().equals(this.iid)) {
            return bridge.getManagedBy().getValue();
        }
    }
    return null;
}
 
Example 4
Source File: DeviceListener.java    From atrium-odl with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
	Map<InstanceIdentifier<?>, DataObject> createdData = change.getCreatedData();

	for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : createdData.entrySet()) {

		InstanceIdentifier<?> iiD = entrySet.getKey();
		final DataObject dataObject = entrySet.getValue();

		if (dataObject instanceof FlowCapableNode) {
			final InstanceIdentifier<Node> path = iiD.firstIdentifierOf(Node.class);

			ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
			final CheckedFuture<Optional<Node>, ReadFailedException> readFuture = readOnlyTransaction
					.read(LogicalDatastoreType.OPERATIONAL, path);
			Futures.addCallback(readFuture, new FutureCallback<Optional<Node>>() {
				@Override
				public void onSuccess(Optional<Node> result) {
					if (result.isPresent()) {
						bgpRouter.processNodeAdd(result.get().getId());
						LOG.info("Node discovered and passed to processNodeAdd : " + result.get().getId());
					} else {
						LOG.info("Read succeeded, node doesn't exist: {}", path);
					}
				}

				@Override
				public void onFailure(Throwable t) {
					LOG.info("Failed to read Node: {}", path, t);
				}
			});
		}
	}
}
 
Example 5
Source File: AbstractDataChangeListener.java    From atrium-odl with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void createData(final Map<InstanceIdentifier<?>, DataObject> createdData) {
    final Set<InstanceIdentifier<?>> keys = createdData.keySet() != null
            ? createdData.keySet() : Collections.<InstanceIdentifier<?>> emptySet();
    for (InstanceIdentifier<?> key : keys) {
        if (clazz.equals(key.getTargetType())) {
             InstanceIdentifier<T> createKeyIdent = key.firstIdentifierOf(clazz);
             final Optional<DataObject> value = Optional.of(createdData.get(key));
             if (value.isPresent()) {
                 this.add(createKeyIdent, (T)value.get());
             }
        }
    }
}
 
Example 6
Source File: NodeChangedListener.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void categorizeIdentifier(final InstanceIdentifier<?> identifier,
        final Set<InstanceIdentifier<ReportedLsp>> changedLsps,
        final Set<InstanceIdentifier<Node>> changedNodes) {
    final InstanceIdentifier<ReportedLsp> li = identifier.firstIdentifierOf(ReportedLsp.class);
    if (li == null) {
        final InstanceIdentifier<Node> ni = identifier.firstIdentifierOf(Node.class);
        if (ni == null) {
            LOG.warn("Ignoring uncategorized identifier {}", identifier);
        } else {
            changedNodes.add(ni);
        }
    } else {
        changedLsps.add(li);
    }
}
 
Example 7
Source File: ProtocolRemovedCommand.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private static void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
        final Set<InstanceIdentifier<ProtocolEntry>> removed,
        final Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation> updatedBridges) {
    for (InstanceIdentifier<ProtocolEntry> protocolIid : removed) {
        InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
                protocolIid.firstIdentifierOf(OvsdbBridgeAugmentation.class);
        OvsdbBridgeAugmentation ovsdbBridge = updatedBridges.get(bridgeIid);
        Optional<ProtocolEntry> protocolEntryOptional = state.getProtocolEntry(protocolIid);
        if (ovsdbBridge != null
                && protocolEntryOptional.isPresent()) {
            ProtocolEntry protocolEntry = protocolEntryOptional.get();
            if (protocolEntry != null && protocolEntry.getProtocol() != null) {
                Bridge bridge = transaction.getTypedRowWrapper(Bridge.class);
                String protocolString = SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocolEntry.getProtocol());
                if (protocolString != null) {
                    bridge.setProtocols(Collections.singleton(protocolString));
                    try {
                        transaction.add(op.mutate(bridge).addMutation(bridge.getProtocolsColumn().getSchema(),
                                Mutator.DELETE,bridge.getProtocolsColumn().getData()));
                        LOG.info("Removed ProtocolEntry : {} for OVSDB Bridge : {} ",
                                protocolString, bridge.getName());
                    } catch (SchemaVersionMismatchException e) {
                        schemaMismatchLog("protocols", "Bridge", e);
                    }
                }
            }
        }
    }

}
 
Example 8
Source File: AutoAttachRemovedCommand.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private static OvsdbBridgeAugmentation getBridge(final InstanceIdentifier<OvsdbNodeAugmentation> key,
        final Uuid aaUuid) {
    if (aaUuid == null) {
        return null;
    }
    OvsdbBridgeAugmentation bridge = null;
    final InstanceIdentifier<Node> nodeIid = key.firstIdentifierOf(Node.class);
    try (ReadTransaction transaction = SouthboundProvider.getDb().newReadOnlyTransaction()) {
        final Optional<Node> nodeOptional = SouthboundUtil.readNode(transaction, nodeIid);
        if (nodeOptional.isPresent()) {
            final Map<ManagedNodeEntryKey, ManagedNodeEntry> managedNodes =
                    nodeOptional.get().augmentation(OvsdbNodeAugmentation.class).getManagedNodeEntry();
            for (final ManagedNodeEntry managedNode : managedNodes.values()) {
                final OvsdbBridgeRef ovsdbBridgeRef = managedNode.getBridgeRef();
                final InstanceIdentifier<OvsdbBridgeAugmentation> brIid = ovsdbBridgeRef.getValue()
                        .firstIdentifierOf(Node.class).augmentation(OvsdbBridgeAugmentation.class);
                final Optional<OvsdbBridgeAugmentation> optionalBridge =
                        transaction.read(LogicalDatastoreType.OPERATIONAL, brIid).get();
                bridge = optionalBridge.get();
                if (bridge != null && bridge.getAutoAttach() != null
                        && bridge.getAutoAttach().equals(aaUuid)) {
                    return bridge;
                }
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("Error reading from datastore",e);
    }
    return null;
}
 
Example 9
Source File: BridgeOperationalState.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("IllegalCatch")
public Optional<Node> getBridgeNode(InstanceIdentifier<?> iid) {
    InstanceIdentifier<Node> nodeIid = iid.firstIdentifierOf(Node.class);
    Optional<Node> bridgeNode = Optional.empty();
    try (ReadTransaction transaction = db.newReadOnlyTransaction()) {
        bridgeNode = SouthboundUtil.readNode(transaction, nodeIid);
    } catch (Exception exp) {
        LOG.error("Error in getting the brideNode for {}", iid, exp);
    }
    return bridgeNode;
}
 
Example 10
Source File: DataChangesManagedByOvsdbNodeEvent.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private InstanceIdentifier<?> getManagedByIidFromOperDS(InstanceIdentifier<?> bridgeIid) {
    // Get the InstanceIdentifier of the containing node
    InstanceIdentifier<Node> nodeEntryIid = bridgeIid.firstIdentifierOf(Node.class);

    Optional<?> bridgeNode =  SouthboundUtil.readNode(db.newReadWriteTransaction(),nodeEntryIid);
    if (bridgeNode.isPresent() && bridgeNode.get() instanceof Node) {
        Node node = (Node)bridgeNode.get();
        OvsdbBridgeAugmentation bridge = node.augmentation(OvsdbBridgeAugmentation.class);
        if (bridge != null && bridge.getManagedBy() != null) {
            return bridge.getManagedBy().getValue();
        }
    }
    return null;
}
 
Example 11
Source File: TunnellingConnectivityManager.java    From atrium-odl with Apache License 2.0 4 votes vote down vote up
private InstanceIdentifier<Node> getNodePath(final InstanceIdentifier<?> nodeChild) {
	return nodeChild.firstIdentifierOf(Node.class);
}
 
Example 12
Source File: NodeChangedListener.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
private void create(final ReadWriteTransaction trans, final InstanceIdentifier<ReportedLsp> identifier,
        final ReportedLsp value) throws ExecutionException, InterruptedException {
    final InstanceIdentifier<Node> ni = identifier.firstIdentifierOf(Node.class);

    final Path1 rl = value.nonnullPath().values().iterator().next().augmentation(Path1.class);

    final AddressFamily af = rl.getLsp().getTlvs().getLspIdentifiers().getAddressFamily();

    /*
     * We are trying to ensure we have source and destination nodes.
     */
    final IpAddress srcIp;
    final IpAddress dstIp;
    if (af instanceof Ipv4Case) {
        final Ipv4 ipv4 = ((Ipv4Case) af).getIpv4();
        srcIp = new IpAddress(ipv4.getIpv4TunnelSenderAddress());
        dstIp = new IpAddress(ipv4.getIpv4TunnelEndpointAddress());
    } else if (af instanceof Ipv6Case) {
        final Ipv6 ipv6 = ((Ipv6Case) af).getIpv6();
        srcIp = new IpAddress(ipv6.getIpv6TunnelSenderAddress());
        dstIp = new IpAddress(ipv6.getIpv6TunnelSenderAddress());
    } else {
        throw new IllegalArgumentException("Unsupported address family: " + af.implementedInterface());
    }

    final Path path0 = value.nonnullPath().values().iterator().next();
    final Link1Builder lab = new Link1Builder();
    if (path0.getBandwidth() != null) {
        lab.setBandwidth(path0.getBandwidth().getBandwidth());
    }
    if (path0.getClassType() != null) {
        lab.setClassType(path0.getClassType().getClassType());
    }
    lab.setSymbolicPathName(value.getName());

    final InstanceIdentifier<TerminationPoint> dst = getIpTerminationPoint(trans, dstIp, null, Boolean.FALSE);
    final InstanceIdentifier<TerminationPoint> src = getIpTerminationPoint(trans, srcIp, ni,
            rl.getLsp().isDelegate());

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109
            .Link1Builder slab = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf
            .stateful.rev181109.Link1Builder();
    slab.setOperationalStatus(rl.getLsp().getOperational());
    slab.setAdministrativeStatus(rl.getLsp().isAdministrative() ? AdministrativeStatus.Active :
            AdministrativeStatus.Inactive);

    final LinkId id = linkIdForLsp(identifier, value);
    final LinkBuilder lb = new LinkBuilder();
    lb.setLinkId(id);

    lb.setSource(new SourceBuilder().setSourceNode(src.firstKeyOf(Node.class).getNodeId())
            .setSourceTp(src.firstKeyOf(TerminationPoint.class).getTpId()).build());
    lb.setDestination(new DestinationBuilder().setDestNode(dst.firstKeyOf(Node.class).getNodeId())
            .setDestTp(dst.firstKeyOf(TerminationPoint.class).getTpId()).build());
    lb.addAugmentation(lab.build());
    lb.addAugmentation(slab.build());

    trans.put(LogicalDatastoreType.OPERATIONAL, linkForLsp(id), lb.build());
}
 
Example 13
Source File: HwvtepOperationalState.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
public Optional<Node> getGlobalNode(final InstanceIdentifier<?> iid) {
    InstanceIdentifier<Node> nodeIid = iid.firstIdentifierOf(Node.class);
    return Optional.ofNullable(operationalNodes.get(nodeIid));
}