Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: use AnnotationKeys

Change-Id: I972b2816272cab2a6cb66f6df99f4dbe84198367
...@@ -25,6 +25,31 @@ public final class AnnotationKeys { ...@@ -25,6 +25,31 @@ public final class AnnotationKeys {
25 private AnnotationKeys() {} 25 private AnnotationKeys() {}
26 26
27 /** 27 /**
28 + * Annotation key for instance name.
29 + */
30 + public static final String NAME = "name";
31 +
32 + /**
33 + * Annotation key for instance type (e.g. host type).
34 + */
35 + public static final String TYPE = "type";
36 +
37 + /**
38 + * Annotation key for latitude (e.g. latitude of device).
39 + */
40 + public static final String LATITUDE = "latitude";
41 +
42 + /**
43 + * Annotation key for longitute (e.g. longitude of device).
44 + */
45 + public static final String LONGITUDE = "longitude";
46 +
47 + /**
48 + * Annotation key for southbound protocol.
49 + */
50 + public static final String PROTOCOL = "protocol";
51 +
52 + /**
28 * Annotation key for durable links. 53 * Annotation key for durable links.
29 */ 54 */
30 public static final String DURABLE = "durable"; 55 public static final String DURABLE = "durable";
......
...@@ -26,6 +26,7 @@ import org.onlab.onos.cluster.NodeId; ...@@ -26,6 +26,7 @@ import org.onlab.onos.cluster.NodeId;
26 import org.onlab.onos.core.CoreService; 26 import org.onlab.onos.core.CoreService;
27 import org.onlab.onos.mastership.MastershipService; 27 import org.onlab.onos.mastership.MastershipService;
28 import org.onlab.onos.net.Annotated; 28 import org.onlab.onos.net.Annotated;
29 +import org.onlab.onos.net.AnnotationKeys;
29 import org.onlab.onos.net.Annotations; 30 import org.onlab.onos.net.Annotations;
30 import org.onlab.onos.net.ConnectPoint; 31 import org.onlab.onos.net.ConnectPoint;
31 import org.onlab.onos.net.DefaultEdgeLink; 32 import org.onlab.onos.net.DefaultEdgeLink;
...@@ -325,7 +326,7 @@ public abstract class TopologyViewMessages { ...@@ -325,7 +326,7 @@ public abstract class TopologyViewMessages {
325 .put("master", master(device.id())); 326 .put("master", master(device.id()));
326 327
327 // Generate labels: id, chassis id, no-label, optional-name 328 // Generate labels: id, chassis id, no-label, optional-name
328 - String name = device.annotations().value("name"); 329 + String name = device.annotations().value(AnnotationKeys.NAME);
329 ArrayNode labels = mapper.createArrayNode(); 330 ArrayNode labels = mapper.createArrayNode();
330 labels.add(""); 331 labels.add("");
331 labels.add(isNullOrEmpty(name) ? device.id().toString() : name); 332 labels.add(isNullOrEmpty(name) ? device.id().toString() : name);
...@@ -362,7 +363,7 @@ public abstract class TopologyViewMessages { ...@@ -362,7 +363,7 @@ public abstract class TopologyViewMessages {
362 // Produces a host event message to the client. 363 // Produces a host event message to the client.
363 protected ObjectNode hostMessage(HostEvent event) { 364 protected ObjectNode hostMessage(HostEvent event) {
364 Host host = event.subject(); 365 Host host = event.subject();
365 - String hostType = host.annotations().value("type"); 366 + String hostType = host.annotations().value(AnnotationKeys.TYPE);
366 ObjectNode payload = mapper.createObjectNode() 367 ObjectNode payload = mapper.createObjectNode()
367 .put("id", host.id().toString()) 368 .put("id", host.id().toString())
368 .put("type", isNullOrEmpty(hostType) ? "endstation" : hostType) 369 .put("type", isNullOrEmpty(hostType) ? "endstation" : hostType)
...@@ -423,8 +424,8 @@ public abstract class TopologyViewMessages { ...@@ -423,8 +424,8 @@ public abstract class TopologyViewMessages {
423 return; 424 return;
424 } 425 }
425 426
426 - String slat = annotations.value("latitude"); 427 + String slat = annotations.value(AnnotationKeys.LATITUDE);
427 - String slng = annotations.value("longitude"); 428 + String slng = annotations.value(AnnotationKeys.LONGITUDE);
428 try { 429 try {
429 if (slat != null && slng != null && !slat.isEmpty() && !slng.isEmpty()) { 430 if (slat != null && slng != null && !slat.isEmpty() && !slng.isEmpty()) {
430 double lat = Double.parseDouble(slat); 431 double lat = Double.parseDouble(slat);
...@@ -464,7 +465,7 @@ public abstract class TopologyViewMessages { ...@@ -464,7 +465,7 @@ public abstract class TopologyViewMessages {
464 protected ObjectNode deviceDetails(DeviceId deviceId, long sid) { 465 protected ObjectNode deviceDetails(DeviceId deviceId, long sid) {
465 Device device = deviceService.getDevice(deviceId); 466 Device device = deviceService.getDevice(deviceId);
466 Annotations annot = device.annotations(); 467 Annotations annot = device.annotations();
467 - String name = annot.value("name"); 468 + String name = annot.value(AnnotationKeys.NAME);
468 int portCount = deviceService.getPorts(deviceId).size(); 469 int portCount = deviceService.getPorts(deviceId).size();
469 int flowCount = getFlowCount(deviceId); 470 int flowCount = getFlowCount(deviceId);
470 return envelope("showDetails", sid, 471 return envelope("showDetails", sid,
...@@ -475,11 +476,11 @@ public abstract class TopologyViewMessages { ...@@ -475,11 +476,11 @@ public abstract class TopologyViewMessages {
475 new Prop("H/W Version", device.hwVersion()), 476 new Prop("H/W Version", device.hwVersion()),
476 new Prop("S/W Version", device.swVersion()), 477 new Prop("S/W Version", device.swVersion()),
477 new Prop("Serial Number", device.serialNumber()), 478 new Prop("Serial Number", device.serialNumber()),
478 - new Prop("Protocol", annot.value("protocol")), 479 + new Prop("Protocol", annot.value(AnnotationKeys.PROTOCOL)),
479 new Separator(), 480 new Separator(),
480 new Prop("Master", master(deviceId)), 481 new Prop("Master", master(deviceId)),
481 - new Prop("Latitude", annot.value("latitude")), 482 + new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)),
482 - new Prop("Longitude", annot.value("longitude")), 483 + new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)),
483 new Separator(), 484 new Separator(),
484 new Prop("Ports", Integer.toString(portCount)), 485 new Prop("Ports", Integer.toString(portCount)),
485 new Prop("Flows", Integer.toString(flowCount)))); 486 new Prop("Flows", Integer.toString(flowCount))));
...@@ -542,8 +543,8 @@ public abstract class TopologyViewMessages { ...@@ -542,8 +543,8 @@ public abstract class TopologyViewMessages {
542 protected ObjectNode hostDetails(HostId hostId, long sid) { 543 protected ObjectNode hostDetails(HostId hostId, long sid) {
543 Host host = hostService.getHost(hostId); 544 Host host = hostService.getHost(hostId);
544 Annotations annot = host.annotations(); 545 Annotations annot = host.annotations();
545 - String type = annot.value("type"); 546 + String type = annot.value(AnnotationKeys.TYPE);
546 - String name = annot.value("name"); 547 + String name = annot.value(AnnotationKeys.NAME);
547 String vlan = host.vlan().toString(); 548 String vlan = host.vlan().toString();
548 return envelope("showDetails", sid, 549 return envelope("showDetails", sid,
549 json(isNullOrEmpty(name) ? hostId.toString() : name, 550 json(isNullOrEmpty(name) ? hostId.toString() : name,
...@@ -552,8 +553,8 @@ public abstract class TopologyViewMessages { ...@@ -552,8 +553,8 @@ public abstract class TopologyViewMessages {
552 new Prop("IP", host.ipAddresses().toString().replaceAll("[\\[\\]]", "")), 553 new Prop("IP", host.ipAddresses().toString().replaceAll("[\\[\\]]", "")),
553 new Prop("VLAN", vlan.equals("-1") ? "none" : vlan), 554 new Prop("VLAN", vlan.equals("-1") ? "none" : vlan),
554 new Separator(), 555 new Separator(),
555 - new Prop("Latitude", annot.value("latitude")), 556 + new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)),
556 - new Prop("Longitude", annot.value("longitude")))); 557 + new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE))));
557 } 558 }
558 559
559 560
......