use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project bgpcep by opendaylight.
the class PCEPMonitoringReplyMessageParser method validate.
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcmonrep message cannot be empty.");
}
if (!(objects.get(0) instanceof Monitoring)) {
errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.absent()));
return null;
}
final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder();
builder.setMonitoring((Monitoring) objects.get(0));
objects.remove(0);
if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
builder.setPccIdReq((PccIdReq) objects.get(0));
objects.remove(0);
}
validateSpecificMetrics(objects, builder);
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getMonitoring.
protected MonitoringRequest getMonitoring(final List<Object> objects) {
final MonitoringRequestBuilder builder = new MonitoringRequestBuilder();
if (!objects.isEmpty() && objects.get(0) instanceof Monitoring) {
builder.setMonitoring((Monitoring) objects.get(0));
objects.remove(0);
} else {
return null;
}
if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
builder.setPccIdReq((PccIdReq) objects.get(0));
objects.remove(0);
}
final List<PceIdList> pceIdList = new ArrayList<>();
while (!objects.isEmpty() && objects.get(0) instanceof PceId) {
pceIdList.add(new PceIdListBuilder().setPceId((PceId) objects.get(0)).build());
objects.remove(0);
}
if (!pceIdList.isEmpty()) {
builder.setPceIdList(pceIdList);
}
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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;
}
Aggregations