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