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;
}
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());
}
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);
}
}
}
Aggregations