Search in sources :

Example 1 with MonitorProfileDeleteInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput 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 2 with MonitorProfileDeleteInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput in project genius by opendaylight.

the class AlivenessMonitorTest method testMonitorProfileDelete.

@Test
public void testMonitorProfileDelete() throws InterruptedException, ExecutionException {
    MonitorProfileDeleteInput input = new MonitorProfileDeleteInputBuilder().setProfileId(1L).build();
    Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
    when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
    RpcResult<Void> result = alivenessMonitor.monitorProfileDelete(input).get();
    verify(idManager).releaseId(any(ReleaseIdInput.class));
    verify(readWriteTx).delete(eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<MonitorProfile>>any());
    assertTrue("Monitor profile delete result", result.isSuccessful());
}
Also used : MonitorProfileDeleteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) MonitorProfileDeleteInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInputBuilder) Test(org.junit.Test)

Example 3 with MonitorProfileDeleteInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput in project genius by opendaylight.

the class AlivenessMonitorUtils method handleTunnelMonitorUpdates.

public void handleTunnelMonitorUpdates(Interface interfaceOld, Interface interfaceNew) {
    String interfaceName = interfaceNew.getName();
    IfTunnel ifTunnelNew = interfaceNew.getAugmentation(IfTunnel.class);
    if (!lldpMonitoringEnabled(ifTunnelNew)) {
        return;
    }
    LOG.debug("handling tunnel monitoring updates for interface {}", interfaceName);
    stopLLDPMonitoring(ifTunnelNew, interfaceOld.getName());
    if (ifTunnelNew.isMonitorEnabled()) {
        startLLDPMonitoring(ifTunnelNew, interfaceName);
        // Delete old profile from Aliveness Manager
        IfTunnel ifTunnelOld = interfaceOld.getAugmentation(IfTunnel.class);
        if (!ifTunnelNew.getMonitorInterval().equals(ifTunnelOld.getMonitorInterval())) {
            LOG.debug("deleting older monitor profile for interface {}", interfaceName);
            long profileId = allocateProfile(FAILURE_THRESHOLD, ifTunnelOld.getMonitorInterval(), MONITORING_WINDOW, EtherTypes.Lldp);
            MonitorProfileDeleteInput profileDeleteInput = new MonitorProfileDeleteInputBuilder().setProfileId(profileId).build();
            Future<RpcResult<Void>> future = alivenessMonitorService.monitorProfileDelete(profileDeleteInput);
            ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(future), LOG, "Delete monitor profile {}", interfaceName);
        }
    }
}
Also used : MonitorProfileDeleteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) MonitorProfileDeleteInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInputBuilder)

Aggregations

MonitorProfileDeleteInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput)2 MonitorProfileDeleteInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInputBuilder)2 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 Optional (com.google.common.base.Optional)1 Test (org.junit.Test)1 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)1 ReleaseIdInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput)1 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)1