Search in sources :

Example 16 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitor method monitorProfileDelete.

@Override
public Future<RpcResult<Void>> monitorProfileDelete(final MonitorProfileDeleteInput input) {
    LOG.debug("Monitor Profile delete for Id: {}", input.getProfileId());
    final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    final Long profileId = input.getProfileId();
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitorProfile>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
    ListenableFuture<RpcResult<Void>> writeFuture = Futures.transformAsync(readFuture, optProfile -> {
        if (optProfile.isPresent()) {
            tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
            Futures.addCallback(tx.submit(), new FutureCallback<Void>() {

                @Override
                public void onFailure(Throwable error) {
                    String msg = String.format("Error when removing monitor profile %d from datastore", profileId);
                    LOG.error("Error when removing monitor profile {} from datastore", profileId, error);
                    result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
                }

                @Override
                public void onSuccess(Void noarg) {
                    MonitorProfile profile = optProfile.get();
                    String id = getUniqueProfileKey(profile.getFailureThreshold(), profile.getMonitorInterval(), profile.getMonitorWindow(), profile.getProtocolType());
                    releaseId(id);
                    result.set(RpcResultBuilder.<Void>success().build());
                }
            }, callbackExecutorService);
        } else {
            String msg = String.format("Monitor profile with Id: %d does not exist", profileId);
            LOG.info(msg);
            result.set(RpcResultBuilder.<Void>success().withWarning(ErrorType.PROTOCOL, "invalid-value", msg).build());
        }
        return result;
    }, callbackExecutorService);
    Futures.addCallback(writeFuture, new FutureCallback<RpcResult<Void>>() {

        @Override
        public void onFailure(Throwable error) {
            String msg = String.format("Error when removing monitor profile %d from datastore", profileId);
            LOG.error("Error when removing monitor profile {} from datastore", profileId, error);
            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
        }

        @Override
        public void onSuccess(RpcResult<Void> noarg) {
            LOG.debug("Successfully removed Monitor Profile {}", profileId);
        }
    }, callbackExecutorService);
    return result;
}
Also used : Optional(com.google.common.base.Optional) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 17 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitor method updateMonitorStatusTo.

private void updateMonitorStatusTo(final Long monitorId, final MonitorStatus newStatus, final Predicate<MonitorStatus> isValidStatus) {
    final String monitorKey = monitorIdKeyCache.getUnchecked(monitorId);
    if (monitorKey == null) {
        LOG.warn("No monitor Key associated with id {} to change the monitor status to {}", monitorId, newStatus);
        return;
    }
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitoringState>> readResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
    ListenableFuture<Void> writeResult = Futures.transformAsync(readResult, optState -> {
        if (optState.isPresent()) {
            MonitoringState state = optState.get();
            if (isValidStatus.apply(state.getStatus())) {
                MonitoringState updatedState = new MonitoringStateBuilder().setMonitorKey(monitorKey).setStatus(newStatus).build();
                tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), updatedState);
            } else {
                LOG.warn("Invalid Monitoring status {}, cannot be updated to {} for monitorId {}", state.getStatus(), newStatus, monitorId);
            }
        } else {
            LOG.warn("No associated monitoring state data available to update the status to {} for {}", newStatus, monitorId);
        }
        return tx.submit();
    }, MoreExecutors.directExecutor());
    Futures.addCallback(writeResult, new FutureCallbackImpl(String.format("Monitor status update for %d to %s", monitorId, newStatus.toString())), MoreExecutors.directExecutor());
}
Also used : MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) Optional(com.google.common.base.Optional) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 18 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitor method monitorStop.

@Override
public Future<RpcResult<Void>> monitorStop(MonitorStopInput input) {
    LOG.debug("Monitor Stop operation for monitor id - {}", input.getMonitorId());
    SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    final Long monitorId = input.getMonitorId();
    Optional<MonitoringInfo> optInfo = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
    if (optInfo.isPresent()) {
        // Stop the monitoring task
        stopMonitoringTask(monitorId);
        String monitorKey = monitorIdKeyCache.getUnchecked(monitorId);
        // Cleanup the Data store
        Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
            if (monitorKey != null) {
                tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
                monitorIdKeyCache.invalidate(monitorId);
            }
            tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
        }), new FutureCallbackImpl(String.format("Delete monitor state with Id %d", monitorId)), MoreExecutors.directExecutor());
        MonitoringInfo info = optInfo.get();
        String interfaceName = getInterfaceName(info.getSource().getEndpointType());
        if (interfaceName != null) {
            removeMonitorIdFromInterfaceAssociation(monitorId, interfaceName);
        }
        releaseIdForMonitoringInfo(info);
        if (monitorKey != null) {
            lockMap.remove(monitorKey);
        }
        result.set(RpcResultBuilder.<Void>success().build());
    } else {
        String errorMsg = String.format("Do not have monitoring information associated with key %d", monitorId);
        LOG.error("Delete monitoring operation Failed - {}", errorMsg);
        result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, errorMsg).build());
    }
    return result;
}
Also used : IpAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.IpAddress) LoadingCache(com.google.common.cache.LoadingCache) EventData(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventData) PacketInReason(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInReason) EventDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventDataBuilder) Future(java.util.concurrent.Future) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Optional(com.google.common.base.Optional) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) CreateIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) InterfaceMonitorEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntry) ErrorType(org.opendaylight.yangtools.yang.common.RpcError.ErrorType) AlivenessProtocolHandler(org.opendaylight.genius.alivenessmonitor.protocols.AlivenessProtocolHandler) Executors(java.util.concurrent.Executors) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) Predicate(com.google.common.base.Predicate) AlivenessMonitorService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService) MonitorUnpauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInput) InterfaceMonitorEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryKey) InterfaceMonitorEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryBuilder) MonitorProfileGetOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetOutput) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) Interface(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.Interface) MonitorProfileDeleteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput) MonitorStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStatus) ArrayList(java.util.ArrayList) AlivenessProtocolHandlerRegistry(org.opendaylight.genius.alivenessmonitor.protocols.AlivenessProtocolHandlerRegistry) Strings(com.google.common.base.Strings) MonitorProfileCreateOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutputBuilder) MonitorEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEventBuilder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MonitorPauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorPauseInput) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) AlivenessMonitorUtil.getInterfaceMonitorMapId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getInterfaceMonitorMapId) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) MonitorStopInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStopInput) Futures(com.google.common.util.concurrent.Futures) MonitorStartInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartInput) MonitoringMode(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitoringMode) Preconditions(com.google.common.base.Preconditions) MonitorProfileGetInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetInput) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) AlivenessMonitorUtil.getMonitorProfileId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitorProfileId) MonitorProfileCreateInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ScheduledFuture(java.util.concurrent.ScheduledFuture) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) LoggerFactory(org.slf4j.LoggerFactory) NotificationPublishService(org.opendaylight.controller.md.sal.binding.api.NotificationPublishService) SettableFuture(com.google.common.util.concurrent.SettableFuture) MonitorEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEvent) ThreadFactoryProvider(org.opendaylight.infrautils.utils.concurrent.ThreadFactoryProvider) PreDestroy(javax.annotation.PreDestroy) MonitoringInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) AlivenessMonitorUtil.getMonitoringInfoId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitoringInfoId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) AlivenessMonitorUtil.getMonitorMapId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitorMapId) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) EndpointType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType) CacheBuilder(com.google.common.cache.CacheBuilder) MonitorStartOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartOutputBuilder) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) PacketProcessingListener(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener) LivenessState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState) MonitorProfileGetOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetOutputBuilder) Singleton(javax.inject.Singleton) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) NetUtils(org.opendaylight.openflowplugin.libraries.liblldp.NetUtils) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) SendToController(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController) CreateIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder) Profile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Config(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.start.input.Config) Nonnull(javax.annotation.Nonnull) ExecutorService(java.util.concurrent.ExecutorService) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) MonitorStartOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartOutput) ReleaseIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) TimeUnit(java.util.concurrent.TimeUnit) MonitorProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) Collections(java.util.Collections) AlivenessMonitorUtil.getMonitorStateId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitorStateId) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult)

Example 19 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitor method resumeMonitoring.

private void resumeMonitoring(final long monitorId) {
    final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
    ListenableFuture<Optional<MonitoringInfo>> readInfoResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
    Futures.addCallback(readInfoResult, new FutureCallback<Optional<MonitoringInfo>>() {

        @Override
        public void onFailure(Throwable error) {
            String msg = String.format("Unable to read monitoring info associated with monitor id %d", monitorId);
            LOG.error("Monitor resume Failed. {}", msg, error);
            tx.close();
        }

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringInfo> optInfo) {
            if (optInfo.isPresent()) {
                final MonitoringInfo info = optInfo.get();
                ListenableFuture<Optional<MonitorProfile>> readProfile = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(info.getProfileId()));
                Futures.addCallback(readProfile, new FutureCallback<Optional<MonitorProfile>>() {

                    @Override
                    public void onFailure(Throwable error) {
                        String msg = String.format("Unable to read Monitoring profile associated with id %d", info.getProfileId());
                        LOG.warn("Monitor resume Failed. {}", msg, error);
                        tx.close();
                    }

                    @Override
                    public void onSuccess(@Nonnull Optional<MonitorProfile> optProfile) {
                        tx.close();
                        if (optProfile.isPresent()) {
                            updateMonitorStatusTo(monitorId, MonitorStatus.Started, currentStatus -> currentStatus != MonitorStatus.Started);
                            MonitorProfile profile = optProfile.get();
                            LOG.debug("Monitor Resume - Scheduling monitoring task for Id: {}", monitorId);
                            scheduleMonitoringTask(info, profile.getMonitorInterval());
                        } else {
                            String msg = String.format("Monitoring profile associated with id %d is not present", info.getProfileId());
                            LOG.warn("Monitor resume Failed. {}", msg);
                        }
                    }
                }, MoreExecutors.directExecutor());
            } else {
                tx.close();
                String msg = String.format("Monitoring info associated with id %d is not present", monitorId);
                LOG.warn("Monitor resume Failed. {}", msg);
            }
        }
    }, MoreExecutors.directExecutor());
}
Also used : Optional(com.google.common.base.Optional) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Nonnull(javax.annotation.Nonnull) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 20 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitor method monitorUnpause.

@Override
public Future<RpcResult<Void>> monitorUnpause(MonitorUnpauseInput input) {
    LOG.debug("Monitor Unpause operation invoked for monitor id: {}", input.getMonitorId());
    final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    final Long monitorId = input.getMonitorId();
    final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
    ListenableFuture<Optional<MonitoringInfo>> readInfoResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
    Futures.addCallback(readInfoResult, new FutureCallback<Optional<MonitoringInfo>>() {

        @Override
        public void onFailure(Throwable error) {
            tx.close();
            String msg = String.format("Unable to read monitoring info associated with monitor id %d", monitorId);
            LOG.error("Monitor unpause Failed. {}", msg, error);
            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
        }

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringInfo> optInfo) {
            if (optInfo.isPresent()) {
                final MonitoringInfo info = optInfo.get();
                ListenableFuture<Optional<MonitorProfile>> readProfile = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(info.getProfileId()));
                Futures.addCallback(readProfile, new FutureCallback<Optional<MonitorProfile>>() {

                    @Override
                    public void onFailure(Throwable error) {
                        tx.close();
                        String msg = String.format("Unable to read Monitoring profile associated with id %d", info.getProfileId());
                        LOG.warn("Monitor unpause Failed. {}", msg, error);
                        result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
                    }

                    @Override
                    public void onSuccess(@Nonnull Optional<MonitorProfile> optProfile) {
                        tx.close();
                        if (optProfile.isPresent()) {
                            updateMonitorStatusTo(monitorId, MonitorStatus.Started, currentStatus -> (currentStatus == MonitorStatus.Paused || currentStatus == MonitorStatus.Stopped));
                            MonitorProfile profile = optProfile.get();
                            LOG.debug("Monitor Resume - Scheduling monitoring task with Id: {}", monitorId);
                            EtherTypes protocolType = profile.getProtocolType();
                            if (protocolType == EtherTypes.Bfd) {
                                LOG.debug("disabling bfd for hwvtep tunnel montior id {}", monitorId);
                                ((HwVtepTunnelsStateHandler) alivenessProtocolHandlerRegistry.get(protocolType)).resetMonitoringTask(true);
                            } else {
                                scheduleMonitoringTask(info, profile.getMonitorInterval());
                            }
                            result.set(RpcResultBuilder.<Void>success().build());
                        } else {
                            String msg = String.format("Monitoring profile associated with id %d is not present", info.getProfileId());
                            LOG.warn("Monitor unpause Failed. {}", msg);
                            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg).build());
                        }
                    }
                }, callbackExecutorService);
            } else {
                tx.close();
                String msg = String.format("Monitoring info associated with id %d is not present", monitorId);
                LOG.warn("Monitor unpause Failed. {}", msg);
                result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg).build());
            }
        }
    }, callbackExecutorService);
    return result;
}
Also used : Optional(com.google.common.base.Optional) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Nonnull(javax.annotation.Nonnull) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

Optional (com.google.common.base.Optional)15 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)15 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 Test (org.junit.Test)8 MonitoringInfo (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo)8 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)8 MonitoringStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder)8 FutureCallback (com.google.common.util.concurrent.FutureCallback)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 EtherTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes)6 LivenessState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState)6 MonitorProfileCreateOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput)6 ArrayList (java.util.ArrayList)5 Semaphore (java.util.concurrent.Semaphore)5 Nonnull (javax.annotation.Nonnull)5 MonitorProfileDeleteInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput)5 MonitoringInfoBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder)5 MonitoridKeyEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry)5 MonitoridKeyEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder)5