Search in sources :

Example 1 with Alarm

use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.

the class AlarmCodecTest method getDecodedAlarm.

/**
 * Reads in a rule from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded flow rule
 * @throws IOException if processing the resource fails to decode
 */
private Alarm getDecodedAlarm(JsonCodec<Alarm> codec, String resourceName) throws IOException {
    try (InputStream jsonStream = AlarmCodecTest.class.getResourceAsStream(resourceName)) {
        JsonNode json = context.mapper().readTree(jsonStream);
        assertThat(json, notNullValue());
        Alarm result = codec.decode((ObjectNode) json, context);
        assertThat(result, notNullValue());
        return result;
    }
}
Also used : InputStream(java.io.InputStream) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) AlarmJsonMatcher.matchesAlarm(org.onosproject.faultmanagement.web.AlarmJsonMatcher.matchesAlarm) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with Alarm

use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.

the class AlarmCodecTest method verifyFullyLoadedAlarmIsEncoded.

@Test
public void verifyFullyLoadedAlarmIsEncoded() throws Exception {
    JsonCodec<Alarm> alarmCodec = context.codec(Alarm.class);
    Alarm alarm = getDecodedAlarm(alarmCodec, "alarm-full.json");
    assertCommon(alarm);
    assertThat(alarm.timeCleared(), is(2222L));
    assertThat(alarm.assignedUser(), is("foo"));
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) AlarmJsonMatcher.matchesAlarm(org.onosproject.faultmanagement.web.AlarmJsonMatcher.matchesAlarm) Test(org.junit.Test)

Example 3 with Alarm

use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.

the class AlarmManager method updateBookkeepingFields.

@Override
public Alarm updateBookkeepingFields(AlarmId id, boolean clear, boolean isAcknowledged, String assignedUser) {
    checkNotNull(id, "Alarm id is null");
    Alarm found = store.getAlarm(id);
    if (found == null) {
        throw new ItemNotFoundException("Alarm with id " + id + " found");
    }
    long now = System.currentTimeMillis();
    DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(found).withTimeUpdated(now);
    if (found.cleared() != clear) {
        alarmBuilder.clear().withTimeCleared(now);
    }
    if (found.acknowledged() != isAcknowledged) {
        alarmBuilder.withAcknowledged(isAcknowledged);
    }
    if (assignedUser != null && !found.assignedUser().equals(assignedUser)) {
        alarmBuilder.withAssignedUser(assignedUser);
    }
    DefaultAlarm updated = alarmBuilder.build();
    store.createOrUpdateAlarm(updated);
    return updated;
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Example 4 with Alarm

use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.

the class AlarmsWebResource method getAlarm.

/**
 * Get specified alarm. Returns details of the specified alarm.
 *
 * @param id ONOS allocated identifier
 * @return JSON encoded alarm
 */
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getAlarm(@PathParam("id") String id) {
    log.debug("HTTP GET alarm for id={}", id);
    AlarmId alarmId = AlarmId.alarmId(id);
    Alarm alarm = get(AlarmService.class).getAlarm(alarmId);
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("alarm", new AlarmCodec().encode(alarm, this));
    return ok(result.toString()).build();
}
Also used : AlarmId(org.onosproject.alarm.AlarmId) AlarmService(org.onosproject.alarm.AlarmService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Alarm(org.onosproject.alarm.Alarm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Alarm

use of org.onosproject.alarm.Alarm 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)

Aggregations

Alarm (org.onosproject.alarm.Alarm)25 DefaultAlarm (org.onosproject.alarm.DefaultAlarm)22 ArrayList (java.util.ArrayList)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Test (org.junit.Test)5 AlarmJsonMatcher.matchesAlarm (org.onosproject.faultmanagement.web.AlarmJsonMatcher.matchesAlarm)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)3 Produces (javax.ws.rs.Produces)3 SeverityLevel (org.onosproject.alarm.Alarm.SeverityLevel)3 AlarmId (org.onosproject.alarm.AlarmId)3 AlarmService (org.onosproject.alarm.AlarmService)3 DeviceId (org.onosproject.net.DeviceId)3 NetconfException (org.onosproject.netconf.NetconfException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2