use of org.onosproject.alarm.AlarmService in project onos by opennetworkinglab.
the class AlarmsWebResource method update.
/**
* Update book-keeping fields on the alarm. Returns an up-to-date version of the alarm. Some of its fields may have
* been updated since the REST client last retrieved the alarm being updated.
*
* @param alarmIdPath alarm id path
* @param stream input JSON
* @return updated JSON encoded alarm
*/
@PUT
@Path("{alarm_id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response update(@PathParam("alarm_id") String alarmIdPath, InputStream stream) {
log.debug("PUT NEW ALARM at /{}", alarmIdPath);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
log.debug("jsonTree={}", jsonTree);
Alarm alarm = new AlarmCodec().decode(jsonTree, this);
AlarmService service = get(AlarmService.class);
if (!alarmIdPath.equals(alarm.id().toString())) {
throw new IllegalArgumentException("id in path is " + alarmIdPath + " but payload uses id=" + alarm.id().toString());
}
Alarm updated = service.updateBookkeepingFields(alarm.id(), alarm.cleared(), alarm.acknowledged(), alarm.assignedUser());
ObjectNode encoded = new AlarmCodec().encode(updated, this);
return ok(encoded.toString()).build();
} catch (IOException ioe) {
throw new IllegalArgumentException(ioe);
}
}
use of org.onosproject.alarm.AlarmService in project onos by opennetworkinglab.
the class AlarmsWebResource method getAlarms.
/**
* Get alarms. Returns a list of alarms
*
* @param includeCleared (optional) include recently cleared alarms in response
* @param devId (optional) include only for specified device
* @return JSON encoded set of alarms
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAlarms(@DefaultValue("false") @QueryParam("includeCleared") boolean includeCleared, @DefaultValue("") @QueryParam("devId") String devId) {
log.debug("Requesting all alarms, includeCleared={}", includeCleared);
AlarmService service = get(AlarmService.class);
Iterable<Alarm> alarms;
if (StringUtils.isBlank(devId)) {
alarms = includeCleared ? service.getAlarms() : service.getActiveAlarms();
} else {
alarms = service.getAlarms(DeviceId.deviceId(devId));
}
ObjectNode result = new ObjectMapper().createObjectNode();
result.set("alarms", new AlarmCodec().encode(alarms, this));
return ok(result.toString()).build();
}
Aggregations