Search in sources :

Example 1 with AlarmEntityId

use of org.onosproject.alarm.AlarmEntityId 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 2 with AlarmEntityId

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

the class UpdateAlarm method doExecute.

@Override
protected void doExecute() {
    Alarm existing = alarmStore.getAlarm(AlarmId.alarmId(alarmId));
    DefaultAlarm.Builder newAlarmBuilder = new DefaultAlarm.Builder(existing);
    UpdateAlarm.AlarmField field = UpdateAlarm.AlarmField.valueOf(alarmField);
    switch(field) {
        case SOURCE:
            AlarmEntityId sourceId = AlarmEntityId.alarmEntityId(alarmFieldValue);
            newAlarmBuilder.forSource(sourceId);
            break;
        case ASSIGNED_USER:
            newAlarmBuilder.withAssignedUser(alarmFieldValue);
            break;
        case ACKNOWLEDGED:
            newAlarmBuilder.withAcknowledged("TRUE".equalsIgnoreCase(alarmFieldValue));
            break;
        case MANUALLY_CLEARABLE:
            newAlarmBuilder.withManuallyClearable("TRUE".equalsIgnoreCase(alarmFieldValue));
            break;
        case SERVICE_AFFECTING:
            newAlarmBuilder.withServiceAffecting("TRUE".equalsIgnoreCase(alarmFieldValue));
            break;
        case TIME_CLEARED:
            newAlarmBuilder.clear();
            newAlarmBuilder.withTimeCleared(Instant.parse(alarmFieldValue).toEpochMilli());
            break;
        case TIME_UPDATED:
        default:
            newAlarmBuilder.withTimeUpdated(Instant.parse(alarmFieldValue).toEpochMilli());
            break;
    }
    alarmStore.createOrUpdateAlarm(newAlarmBuilder.build());
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) AlarmEntityId(org.onosproject.alarm.AlarmEntityId) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Aggregations

Alarm (org.onosproject.alarm.Alarm)2 AlarmEntityId (org.onosproject.alarm.AlarmEntityId)2 DefaultAlarm (org.onosproject.alarm.DefaultAlarm)2 AlarmId (org.onosproject.alarm.AlarmId)1