本文整理匯總了Java中org.onosproject.incubator.net.faultmanagement.alarm.AlarmId類的典型用法代碼示例。如果您正苦於以下問題:Java AlarmId類的具體用法?Java AlarmId怎麽用?Java AlarmId使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AlarmId類屬於org.onosproject.incubator.net.faultmanagement.alarm包,在下文中一共展示了AlarmId類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: consumeAlarms
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Override
public List<Alarm> consumeAlarms() {
SnmpController controller = checkNotNull(handler().get(SnmpController.class));
List<Alarm> alarms = new ArrayList<>();
DeviceId deviceId = handler().data().deviceId();
SnmpDevice device = controller.getDevice(deviceId);
try {
snmp = new LumentumSnmpDevice(device.getSnmpHost(), device.getSnmpPort());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Gets the alarm table and for each entry get the ID and create the proper alarm.
snmp.get(ALARMS_TABLE_OID).stream()
.forEach(alarm -> snmp.get(ALARMS_ID_OID).forEach(alarmIdEvent -> {
int alarmId = getAlarmId(alarmIdEvent);
alarms.add(new DefaultAlarm.Builder(deviceId, getMessage(alarmId),
getSeverity(alarmId),
System.currentTimeMillis())
.withId(AlarmId.alarmId(alarmId))
.build());
}));
return ImmutableList.copyOf(alarms);
}
示例2: activate
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Activate
public void activate() {
log.info("Started");
alarms = storageService.<AlarmId, Alarm>consistentMapBuilder()
.withName("onos-alarm-table")
.withSerializer(Serializer.using(KryoNamespaces.API,
Alarm.class,
DefaultAlarm.class,
AlarmId.class,
AlarmEvent.Type.class,
Alarm.SeverityLevel.class,
AlarmEntityId.class))
.build();
alarms.addListener(listener);
alarmsMap = alarms.asJavaMap();
}
示例3: event
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Override
public void event(MapEvent<AlarmId, Alarm> mapEvent) {
final AlarmEvent.Type type;
final Alarm alarm;
switch (mapEvent.type()) {
case INSERT:
type = AlarmEvent.Type.CREATED;
alarm = mapEvent.newValue().value();
break;
case UPDATE:
type = AlarmEvent.Type.CREATED;
alarm = mapEvent.newValue().value();
break;
case REMOVE:
type = AlarmEvent.Type.REMOVED;
alarm = mapEvent.oldValue().value();
break;
default:
throw new IllegalArgumentException("Wrong event type " + mapEvent.type());
}
notifyDelegate(new AlarmEvent(type, alarm));
}
示例4: testGettersWhenNoAlarms
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Test
public void testGettersWhenNoAlarms() {
assertTrue("No alarms should be present", manager.getAlarms().isEmpty());
assertTrue("No active alarms should be present", manager.getActiveAlarms().isEmpty());
assertTrue("The map should be empty per unknown device",
manager.getAlarmCounts(DeviceId.NONE).keySet().isEmpty());
assertTrue("The counts should be empty", manager.getAlarmCounts().keySet().isEmpty());
assertEquals("Incorrect number of alarms for unknown device",
0, manager.getAlarms(DeviceId.NONE).size());
assertEquals("Incorrect number of major alarms for unknown device",
0, manager.getAlarms(Alarm.SeverityLevel.MAJOR).size());
exception.expect(NullPointerException.class);
manager.getAlarm(null);
exception.expect(ItemNotFoundException.class);
manager.getAlarm(AlarmId.alarmId(1));
}
示例5: newAlarmFromJsonNode
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
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;
}
}
示例6: consumeAlarms
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Override
public List<Alarm> consumeAlarms() {
SnmpController controller = checkNotNull(handler().get(SnmpController.class));
List<Alarm> alarms = new ArrayList<>();
DeviceId deviceId = handler().data().deviceId();
SnmpDevice device = controller.getDevice(deviceId);
try {
snmp = new LumentumSnmpDevice(device.getSnmpHost(), device.getSnmpPort());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Gets the alarm table and for each entry get the ID and create the proper alarm.
snmp.get(ALARMS_TABLE_OID)
.forEach(alarm -> snmp.get(ALARMS_ID_OID).forEach(alarmIdEvent -> {
int alarmId = getAlarmId(alarmIdEvent);
alarms.add(new DefaultAlarm.Builder(deviceId, getMessage(alarmId),
getSeverity(alarmId),
System.currentTimeMillis())
.withId(AlarmId.alarmId(deviceId, String.valueOf(alarmId)))
.build());
}));
return ImmutableList.copyOf(alarms);
}
示例7: event
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Override
public void event(MapEvent<AlarmId, Alarm> mapEvent) {
final AlarmEvent.Type type;
final Alarm alarm;
switch (mapEvent.type()) {
case INSERT:
type = AlarmEvent.Type.CREATED;
alarm = mapEvent.newValue().value();
break;
case UPDATE:
type = AlarmEvent.Type.UPDATED;
alarm = mapEvent.newValue().value();
break;
case REMOVE:
type = AlarmEvent.Type.REMOVED;
alarm = mapEvent.oldValue().value();
break;
default:
throw new IllegalArgumentException("Wrong event type " + mapEvent.type());
}
notifyDelegate(new AlarmEvent(type, alarm));
}
示例8: updateBookkeepingFields
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@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;
}
示例9: testGettersWhenNoAlarms
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Test
public void testGettersWhenNoAlarms() {
assertTrue("No alarms should be present", manager.getAlarms().isEmpty());
assertTrue("No active alarms should be present", manager.getActiveAlarms().isEmpty());
assertTrue("The map should be empty per unknown device",
manager.getAlarmCounts(DeviceId.NONE).keySet().isEmpty());
assertTrue("The counts should be empty", manager.getAlarmCounts().keySet().isEmpty());
assertEquals("Incorrect number of alarms for unknown device",
0, manager.getAlarms(DeviceId.NONE).size());
assertEquals("Incorrect number of major alarms for unknown device",
0, manager.getAlarms(Alarm.SeverityLevel.MAJOR).size());
exception.expect(NullPointerException.class);
manager.getAlarm(null);
exception.expect(ItemNotFoundException.class);
manager.getAlarm(AlarmId.alarmId(DEVICE_ID, "unique_3"));
}
示例10: process
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Override
public void process(long sid, ObjectNode payload) {
log.debug("sid={}, payload ={}", sid, payload);
String id = string(payload, ID, "(none)");
Alarm alarm = AlarmServiceUtil.lookupAlarm(AlarmId.alarmId(Long.parseLong(id)));
ObjectNode rootNode = objectNode();
ObjectNode data = objectNode();
rootNode.set(DETAILS, data);
if (alarm == null) {
rootNode.put(RESULT, "Item with id '" + id + "' not found");
log.warn("attempted to get item detail for id '{}'", id);
} else {
rootNode.put(RESULT, "Found item with id '" + id + "'");
data.put(ID, alarm.id().fingerprint());
data.put(DESCRIPTION, alarm.description());
data.put(DEVICE_ID_STR, alarm.deviceId().toString());
data.put(SOURCE, alarm.source().toString());
long timeRaised = alarm.timeRaised();
data.put(TIME_RAISED,
formatTime(timeRaised)
);
data.put(TIME_UPDATED, formatTime(alarm.timeUpdated()));
data.put(TIME_CLEARED, formatTime(alarm.timeCleared()));
data.put(SEVERITY, alarm.severity().toString());
}
log.debug("send ={}", rootNode);
sendMessage(ALARM_TABLE_DETAIL_RESP, 0, rootNode);
}
示例11: getAlarm
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
/**
* 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 = toAlarmId(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();
}
示例12: toAlarmId
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
private AlarmId toAlarmId(String id) {
try {
return AlarmId.alarmId(Long.parseLong(id));
} catch (NumberFormatException ex) {
throw new IllegalArgumentException("Alarm id should be numeric", ex);
}
}
示例13: decode
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Override
public Alarm decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
log.debug("id={}, full json={} ", json.get("id"), json);
Long id = json.get("id").asLong();
DeviceId deviceId = DeviceId.deviceId(json.get("deviceId").asText());
String description = json.get("description").asText();
Long timeRaised = json.get("timeRaised").asLong();
Long timeUpdated = json.get("timeUpdated").asLong();
JsonNode jsonTimeCleared = json.get("timeCleared");
Long timeCleared = jsonTimeCleared == null || jsonTimeCleared.isNull() ? null : jsonTimeCleared.asLong();
Alarm.SeverityLevel severity = Alarm.SeverityLevel.valueOf(json.get("severity").asText().toUpperCase());
Boolean serviceAffecting = json.get("serviceAffecting").asBoolean();
Boolean acknowledged = json.get("acknowledged").asBoolean();
Boolean manuallyClearable = json.get("manuallyClearable").asBoolean();
JsonNode jsonAssignedUser = json.get("assignedUser");
String assignedUser
= jsonAssignedUser == null || jsonAssignedUser.isNull() ? null : jsonAssignedUser.asText();
return new DefaultAlarm.Builder(
deviceId, description, severity, timeRaised).forSource(AlarmEntityId.NONE).
withId(AlarmId.alarmId(id)).
withTimeUpdated(timeUpdated).
withTimeCleared(timeCleared).
withServiceAffecting(serviceAffecting).
withAcknowledged(acknowledged).
withManuallyClearable(manuallyClearable).
withAssignedUser(assignedUser).
build();
}
示例14: assertCommon
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
private void assertCommon(Alarm alarm) {
assertThat(alarm.id(), is(AlarmId.alarmId(10L)));
assertThat(alarm.description(), is("NE is not reachable"));
assertThat(alarm.source(), is(AlarmEntityId.NONE));
assertThat(alarm.timeRaised(), is(999L));
assertThat(alarm.timeUpdated(), is(1111L));
assertThat(alarm.severity(), is(Alarm.SeverityLevel.MAJOR));
assertThat(alarm.serviceAffecting(), is(true));
assertThat(alarm.acknowledged(), is(false));
assertThat(alarm.manuallyClearable(), is(true));
}
示例15: updateBookkeepingFields
import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; //導入依賴的package包/類
@Override
public Alarm updateBookkeepingFields(AlarmId id, boolean isAcknowledged, String assignedUser) {
Alarm found = store.getAlarm(id);
if (found == null) {
throw new ItemNotFoundException("Alarm with id " + id + " found");
}
Alarm updated = new DefaultAlarm.Builder(found)
.withId(found.id())
.withAcknowledged(isAcknowledged)
.withAssignedUser(assignedUser).build();
store.setAlarm(updated);
return updated;
}