Search in sources :

Example 1 with AlarmService

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AlarmService(org.onosproject.alarm.AlarmService) Alarm(org.onosproject.alarm.Alarm) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with AlarmService

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();
}
Also used : AlarmService(org.onosproject.alarm.AlarmService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Alarm(org.onosproject.alarm.Alarm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Produces (javax.ws.rs.Produces)2 Alarm (org.onosproject.alarm.Alarm)2 AlarmService (org.onosproject.alarm.AlarmService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1