Search in sources :

Example 6 with Alarm

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

the class CienaRestDevice method newAlarmFromJsonNode.

private Alarm newAlarmFromJsonNode(JsonNode jsonNode) {
    try {
        AlarmId alarmId = AlarmId.alarmId(checkNotNull(jsonNode.get(ALARM_INSTANCE_ID)).asText());
        String time = checkNotNull(jsonNode.get(ALARM_LOCAL_DATE_TIME)).asText();
        String instance = checkNotNull(jsonNode.get(INSTANCE).asText()).toLowerCase();
        String description = checkNotNull(jsonNode.get(DESCRIPTION)).asText() + " - " + instance + " - " + time;
        AlarmEntityId source = getAlarmSource(instance);
        Alarm.SeverityLevel severity = Alarm.SeverityLevel.valueOf(checkNotNull(jsonNode.get(SEVERITY)).asText().toUpperCase());
        long timeRaised = parseAlarmTime(time);
        boolean isAcknowledged = checkNotNull(jsonNode.get(ACKNOWLEDGE)).asBoolean();
        return new DefaultAlarm.Builder(alarmId, deviceId, description, severity, timeRaised).withAcknowledged(isAcknowledged).forSource(source).build();
    } catch (NullPointerException e) {
        log.error("got exception while parsing alarm json node {} for device {}:\n", jsonNode, deviceId, e);
        return null;
    }
}
Also used : AlarmId(org.onosproject.alarm.AlarmId) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) AlarmEntityId(org.onosproject.alarm.AlarmEntityId) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 7 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 8 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 9 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 10 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)

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