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;
}
}
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;
}
}
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"));
}
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;
}
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();
}
Aggregations