use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile in project genius by opendaylight.
the class AlivenessMonitor method monitorStart.
@Override
public Future<RpcResult<MonitorStartOutput>> monitorStart(MonitorStartInput input) {
RpcResultBuilder<MonitorStartOutput> rpcResultBuilder;
final Config in = input.getConfig();
Long profileId = in.getProfileId();
LOG.debug("Monitor Start invoked with Config: {}, Profile Id: {}", in, profileId);
try {
if (in.getMode() != MonitoringMode.OneOne) {
throw new UnsupportedConfigException("Unsupported Monitoring mode. Currently one-one mode is supported");
}
Optional<MonitorProfile> optProfile = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
final MonitorProfile profile;
if (!optProfile.isPresent()) {
String errMsg = String.format("No monitoring profile associated with Id: %d", profileId);
LOG.error("Monitor start failed. {}", errMsg);
throw new RuntimeException(errMsg);
} else {
profile = optProfile.get();
}
final EtherTypes ethType = profile.getProtocolType();
String interfaceName = null;
EndpointType srcEndpointType = in.getSource().getEndpointType();
if (srcEndpointType instanceof Interface) {
Interface endPoint = (Interface) srcEndpointType;
interfaceName = endPoint.getInterfaceName();
} else {
throw new UnsupportedConfigException("Unsupported source Endpoint type. Only Interface Endpoint currently supported for monitoring");
}
if (Strings.isNullOrEmpty(interfaceName)) {
throw new RuntimeException("Interface Name not defined in the source Endpoint");
}
// Initially the support is for one monitoring per interface.
// Revisit the retrieving monitor id logic when the multiple
// monitoring for same interface is needed.
EndpointType destEndpointType = null;
if (in.getDestination() != null) {
destEndpointType = in.getDestination().getEndpointType();
}
String idKey = getUniqueKey(interfaceName, ethType.toString(), srcEndpointType, destEndpointType);
final long monitorId = getUniqueId(idKey);
Optional<MonitoringInfo> optKey = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
final AlivenessProtocolHandler<?> handler;
if (optKey.isPresent()) {
String message = String.format("Monitoring for the interface %s with this configuration " + "is already registered.", interfaceName);
LOG.warn("Monitoring for the interface {} with this configuration is already registered.", interfaceName);
MonitorStartOutput output = new MonitorStartOutputBuilder().setMonitorId(monitorId).build();
rpcResultBuilder = RpcResultBuilder.success(output).withWarning(ErrorType.APPLICATION, "config-exists", message);
return Futures.immediateFuture(rpcResultBuilder.build());
} else {
// Construct the monitor key
final MonitoringInfo monitoringInfo = new MonitoringInfoBuilder().setId(monitorId).setMode(in.getMode()).setProfileId(profileId).setDestination(in.getDestination()).setSource(in.getSource()).build();
// Construct the initial monitor state
handler = alivenessProtocolHandlerRegistry.get(ethType);
final String monitoringKey = handler.getUniqueMonitoringKey(monitoringInfo);
MonitoringStateBuilder monitoringStateBuilder = new MonitoringStateBuilder().setMonitorKey(monitoringKey).setMonitorId(monitorId).setState(LivenessState.Unknown).setStatus(MonitorStatus.Started);
if (ethType != EtherTypes.Bfd) {
monitoringStateBuilder.setRequestCount(INITIAL_COUNT).setResponsePendingCount(INITIAL_COUNT);
}
MonitoringState monitoringState = monitoringStateBuilder.build();
Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
tx.put(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId), monitoringInfo, CREATE_MISSING_PARENT);
LOG.debug("adding oper monitoring info {}", monitoringInfo);
tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitoringKey), monitoringState, CREATE_MISSING_PARENT);
LOG.debug("adding oper monitoring state {}", monitoringState);
MonitoridKeyEntry mapEntry = new MonitoridKeyEntryBuilder().setMonitorId(monitorId).setMonitorKey(monitoringKey).build();
tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorMapId(monitorId), mapEntry, CREATE_MISSING_PARENT);
LOG.debug("adding oper map entry {}", mapEntry);
}), new FutureCallback<Void>() {
@Override
public void onFailure(Throwable error) {
String errorMsg = String.format("Adding Monitoring info: %s in Datastore failed", monitoringInfo);
LOG.warn("Adding Monitoring info: {} in Datastore failed", monitoringInfo, error);
throw new RuntimeException(errorMsg, error);
}
@Override
public void onSuccess(Void noarg) {
lockMap.put(monitoringKey, new Semaphore(1, true));
if (ethType == EtherTypes.Bfd) {
handler.startMonitoringTask(monitoringInfo);
return;
}
// Schedule task
LOG.debug("Scheduling monitor task for config: {}", in);
scheduleMonitoringTask(monitoringInfo, profile.getMonitorInterval());
}
}, callbackExecutorService);
}
associateMonitorIdWithInterface(monitorId, interfaceName);
MonitorStartOutput output = new MonitorStartOutputBuilder().setMonitorId(monitorId).build();
rpcResultBuilder = RpcResultBuilder.success(output);
} catch (UnsupportedConfigException e) {
LOG.error("Start Monitoring Failed. ", e);
rpcResultBuilder = RpcResultBuilder.<MonitorStartOutput>failed().withError(ErrorType.APPLICATION, e.getMessage(), e);
}
return Futures.immediateFuture(rpcResultBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile 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.monitor.profile.create.input.Profile 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile in project genius by opendaylight.
the class AlivenessMonitor method monitorProfileCreate.
@Override
public Future<RpcResult<MonitorProfileCreateOutput>> monitorProfileCreate(final MonitorProfileCreateInput input) {
LOG.debug("Monitor Profile Create operation - {}", input.getProfile());
final SettableFuture<RpcResult<MonitorProfileCreateOutput>> returnFuture = SettableFuture.create();
Profile profile = input.getProfile();
final Long failureThreshold = profile.getFailureThreshold();
final Long monitorInterval = profile.getMonitorInterval();
final Long monitorWindow = profile.getMonitorWindow();
final EtherTypes ethType = profile.getProtocolType();
String idKey = getUniqueProfileKey(failureThreshold, monitorInterval, monitorWindow, ethType);
final Long profileId = (long) getUniqueId(idKey);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<MonitorProfile>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
ListenableFuture<RpcResult<MonitorProfileCreateOutput>> resultFuture = Futures.transformAsync(readFuture, optProfile -> {
if (optProfile.isPresent()) {
tx.cancel();
MonitorProfileCreateOutput output = new MonitorProfileCreateOutputBuilder().setProfileId(profileId).build();
String msg = String.format("Monitor profile %s already present for the given input", input);
LOG.warn(msg);
returnFuture.set(RpcResultBuilder.success(output).withWarning(ErrorType.PROTOCOL, "profile-exists", msg).build());
} else {
final MonitorProfile monitorProfile = new MonitorProfileBuilder().setId(profileId).setFailureThreshold(failureThreshold).setMonitorInterval(monitorInterval).setMonitorWindow(monitorWindow).setProtocolType(ethType).build();
tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId), monitorProfile, CREATE_MISSING_PARENT);
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onFailure(Throwable error) {
String msg = String.format("Error when storing monitorprofile %s in datastore", monitorProfile);
LOG.error("Error when storing monitorprofile {} in datastore", monitorProfile, error);
returnFuture.set(RpcResultBuilder.<MonitorProfileCreateOutput>failed().withError(ErrorType.APPLICATION, msg, error).build());
}
@Override
public void onSuccess(Void noarg) {
MonitorProfileCreateOutput output = new MonitorProfileCreateOutputBuilder().setProfileId(profileId).build();
returnFuture.set(RpcResultBuilder.success(output).build());
}
}, callbackExecutorService);
}
return returnFuture;
}, callbackExecutorService);
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<MonitorProfileCreateOutput>>() {
@Override
public void onFailure(Throwable error) {
// This would happen when any error happens during reading for
// monitoring profile
String msg = String.format("Error in creating monitorprofile - %s", input);
returnFuture.set(RpcResultBuilder.<MonitorProfileCreateOutput>failed().withError(ErrorType.APPLICATION, msg, error).build());
LOG.error("Error in creating monitorprofile - {} ", input, error);
}
@Override
public void onSuccess(RpcResult<MonitorProfileCreateOutput> result) {
LOG.debug("Successfully created monitor Profile {} ", input);
}
}, callbackExecutorService);
return returnFuture;
}
Aggregations