Search in sources :

Example 16 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications in project openflowplugin by opendaylight.

the class ContextChainHolderImpl method ownershipChanged.

@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public void ownershipChanged(EntityOwnershipChange entityOwnershipChange) {
    if (entityOwnershipChange.getState().hasOwner()) {
        return;
    }
    // Findbugs flags a false violation for "Unchecked/unconfirmed cast" from GenericEntity to Entity hence the
    // suppression above. The suppression is temporary until EntityOwnershipChange is modified to eliminate the
    // violation.
    final String entityName = entityOwnershipChange.getEntity().getIdentifier().firstKeyOf(Entity.class).getName();
    if (Objects.nonNull(entityName)) {
        LOG.debug("Entity {} has no owner", entityName);
        try {
            // TODO:Remove notifications
            final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = DeviceStateUtil.createNodeInstanceIdentifier(new NodeId(entityName));
            deviceManager.sendNodeRemovedNotification(nodeInstanceIdentifier);
            LOG.info("Try to remove device {} from operational DS", entityName);
            deviceManager.removeDeviceFromOperationalDS(nodeInstanceIdentifier).get(REMOVE_DEVICE_FROM_DS_TIMEOUT, TimeUnit.MILLISECONDS);
            LOG.info("Removing device from operational DS {} was successful", entityName);
        } catch (TimeoutException | ExecutionException | NullPointerException | InterruptedException e) {
            LOG.warn("Not able to remove device {} from operational DS. ", entityName, e);
        }
    }
}
Also used : Entity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ExecutionException(java.util.concurrent.ExecutionException) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) TimeoutException(java.util.concurrent.TimeoutException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 17 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications in project lispflowmapping by opendaylight.

the class MappingServiceIntegrationTest method registerAddressAndQuery.

// takes an address, packs it in a MapRegister, sends it, returns the
// MapReply
private MapReply registerAddressAndQuery(Eid eid) throws SocketTimeoutException {
    mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
    sleepForSeconds(1);
    MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build();
    LOG.trace("Sending Map-Register via socket: {}", mapRegister);
    sendMapRegister(mapRegister);
    MapNotify mapNotify = receiveMapNotify();
    LOG.trace("Received Map-Notify via socket: {}", mapNotify);
    assertEquals(8, mapNotify.getNonce().longValue());
    // wait for the notifications to propagate
    sleepForSeconds(1);
    MapRequest mapRequest = MappingServiceIntegrationTestUtil.getDefaultMapRequestBuilder(eid).build();
    sendMapRequest(mapRequest);
    return receiveMapReply();
}
Also used : MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) GotMapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify) MapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify) MapRegister(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)

Example 18 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications in project genius by opendaylight.

the class AlivenessMonitor method processReceivedMonitorKey.

private void processReceivedMonitorKey(final String monitorKey) {
    Preconditions.checkNotNull(monitorKey, "Monitor Key required to process the state");
    LOG.debug("Processing monitorKey: {} for received packet", monitorKey);
    final Semaphore lock = lockMap.get(monitorKey);
    LOG.debug("Acquiring lock for monitor key : {} to process monitor packet", monitorKey);
    acquireLock(lock);
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
    // READ Callback
    Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
            if (optState.isPresent()) {
                final MonitoringState currentState = optState.get();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("OnPacketReceived : Monitoring state from ODS : {} ", currentState);
                }
                // Long responsePendingCount = currentState.getResponsePendingCount();
                // 
                // Need to relook at the pending count logic to support N
                // out of M scenarios
                // if (currentState.getState() != LivenessState.Up) {
                // //Reset responsePendingCount when state changes from DOWN
                // to UP
                // responsePendingCount = INITIAL_COUNT;
                // }
                // 
                // if (responsePendingCount > INITIAL_COUNT) {
                // responsePendingCount =
                // currentState.getResponsePendingCount() - 1;
                // }
                Long responsePendingCount = INITIAL_COUNT;
                final boolean stateChanged = currentState.getState() == LivenessState.Down || currentState.getState() == LivenessState.Unknown;
                final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(LivenessState.Up).setResponsePendingCount(responsePendingCount).build();
                tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
                ListenableFuture<Void> writeResult = tx.submit();
                // WRITE Callback
                Futures.addCallback(writeResult, new FutureCallback<Void>() {

                    @Override
                    public void onSuccess(Void noarg) {
                        releaseLock(lock);
                        if (stateChanged) {
                            // send notifications
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), LivenessState.Up);
                            }
                            publishNotification(currentState.getMonitorId(), LivenessState.Up);
                        } else {
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("Successful in writing monitoring state {} to ODS", state);
                            }
                        }
                    }

                    @Override
                    public void onFailure(Throwable error) {
                        releaseLock(lock);
                        LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
                        if (LOG.isTraceEnabled()) {
                            LOG.trace("Error in writing monitoring state: {} to Datastore", state);
                        }
                    }
                }, callbackExecutorService);
            } else {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Monitoring State not available for key: {} to process the Packet received", monitorKey);
                }
                // Complete the transaction
                tx.submit();
                releaseLock(lock);
            }
        }

        @Override
        public void onFailure(Throwable error) {
            LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
            // FIXME: Not sure if the transaction status is valid to cancel
            tx.cancel();
            releaseLock(lock);
        }
    }, callbackExecutorService);
}
Also used : Optional(com.google.common.base.Optional) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) Semaphore(java.util.concurrent.Semaphore) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 19 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications in project genius by opendaylight.

the class HwVtepTunnelsStateHandler method update.

@Override
public void update(@Nonnull Tunnels oldTunnelInfo, @Nonnull Tunnels updatedTunnelInfo) {
    List<BfdStatus> oldBfdStatus = oldTunnelInfo.getBfdStatus();
    List<BfdStatus> newBfdStatus = updatedTunnelInfo.getBfdStatus();
    LivenessState oldTunnelOpState = getTunnelOpState(oldBfdStatus);
    final LivenessState newTunnelOpState = getTunnelOpState(newBfdStatus);
    if (oldTunnelOpState == newTunnelOpState) {
        LOG.debug("Tunnel state of old tunnel {} and update tunnel {} are same", oldTunnelInfo, updatedTunnelInfo);
        return;
    }
    updatedTunnelInfo.getTunnelUuid();
    String interfaceName = "<TODO>";
    // TODO: find out the corresponding interface using tunnelIdentifier or
    // any attributes of tunnelInfo object
    final String monitorKey = getBfdMonitorKey(interfaceName);
    LOG.debug("Processing monitorKey: {} for received Tunnels update DCN", monitorKey);
    final Semaphore lock = alivenessMonitor.getLock(monitorKey);
    LOG.debug("Acquiring lock for monitor key : {} to process monitor DCN", monitorKey);
    alivenessMonitor.acquireLock(lock);
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
    Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
            if (optState.isPresent()) {
                final MonitoringState currentState = optState.get();
                if (currentState.getState() == newTunnelOpState) {
                    return;
                }
                final boolean stateChanged = true;
                final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(newTunnelOpState).build();
                tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
                ListenableFuture<Void> writeResult = tx.submit();
                // WRITE Callback
                Futures.addCallback(writeResult, new FutureCallback<Void>() {

                    @Override
                    public void onSuccess(Void arg0) {
                        alivenessMonitor.releaseLock(lock);
                        if (stateChanged) {
                            // send notifications
                            LOG.info("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), newTunnelOpState);
                            alivenessMonitor.publishNotification(currentState.getMonitorId(), newTunnelOpState);
                        } else {
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("Successful in writing monitoring state {} to ODS", state);
                            }
                        }
                    }

                    @Override
                    public void onFailure(@Nonnull Throwable error) {
                        alivenessMonitor.releaseLock(lock);
                        LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
                        if (LOG.isTraceEnabled()) {
                            LOG.trace("Error in writing monitoring state: {} to Datastore", state);
                        }
                    }
                }, MoreExecutors.directExecutor());
            } else {
                LOG.warn("Monitoring State not available for key: {} to process the Packet received", monitorKey);
                // Complete the transaction
                tx.submit();
                alivenessMonitor.releaseLock(lock);
            }
        }

        @Override
        public void onFailure(@Nonnull Throwable error) {
            LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
            // FIXME: Not sure if the transaction status is valid to cancel
            tx.cancel();
            alivenessMonitor.releaseLock(lock);
        }
    }, MoreExecutors.directExecutor());
}
Also used : Optional(com.google.common.base.Optional) Nonnull(javax.annotation.Nonnull) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) Semaphore(java.util.concurrent.Semaphore) BfdStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatus) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) LivenessState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

Notifications (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications)4 Optional (com.google.common.base.Optional)3 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 Test (org.junit.Test)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ByteBuf (io.netty.buffer.ByteBuf)2 Semaphore (java.util.concurrent.Semaphore)2 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 NotificationService (org.opendaylight.controller.sal.binding.api.NotificationService)2 L2vlan (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)2 MonitoringStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder)2 CNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification)2 Rps (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Rps)2 RpsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.RpsBuilder)2