mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-19 11:21:13 +02:00
ONOS-6372: Topo2 - Refactor "location" data to be consistent
- consistently labeled fields "locType", "latOrY", "longOrX" - simplified code in topo2NodePosition.js Change-Id: I73e8daadcc3e6ca3ff45f7f60e7b372ccfd8b045
This commit is contained in:
parent
5f97a30982
commit
f27a929fbb
@ -44,7 +44,12 @@ public final class LayoutLocation {
|
|||||||
* Designates the type of location; either geographic or logical grid.
|
* Designates the type of location; either geographic or logical grid.
|
||||||
*/
|
*/
|
||||||
public enum Type {
|
public enum Type {
|
||||||
GEO, GRID
|
GEO, GRID;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
@ -38,8 +38,8 @@ public class LayoutLocationTest extends AbstractUiTest {
|
|||||||
private static final double PI = 3.142;
|
private static final double PI = 3.142;
|
||||||
private static final double ZERO = 0.0;
|
private static final double ZERO = 0.0;
|
||||||
|
|
||||||
private static final String COMPACT_LL_1 = "foo,GEO,3.142,1.414";
|
private static final String COMPACT_LL_1 = "foo,geo,3.142,1.414";
|
||||||
private static final String COMPACT_LL_2 = "bar,GRID,1.414,3.142";
|
private static final String COMPACT_LL_2 = "bar,grid,1.414,3.142";
|
||||||
|
|
||||||
private static final String COMPACT_LIST = COMPACT_LL_1 + "~" + COMPACT_LL_2;
|
private static final String COMPACT_LIST = COMPACT_LL_1 + "~" + COMPACT_LL_2;
|
||||||
|
|
||||||
|
@ -93,8 +93,8 @@ public class TopologyResource extends BaseResource {
|
|||||||
// TODO: add handling of gridY/gridX if locType is "grid" (not "geo")
|
// TODO: add handling of gridY/gridX if locType is "grid" (not "geo")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
annot.put("latitude", memento.get("lat").asDouble())
|
annot.put("latitude", memento.get("latOrY").asDouble())
|
||||||
.put("longitude", memento.get("lng").asDouble());
|
.put("longitude", memento.get("longOrX").asDouble());
|
||||||
array.add(node);
|
array.add(node);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("Skipping geo entry");
|
log.debug("Skipping geo entry");
|
||||||
|
@ -319,21 +319,21 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String slng = annotations.value(AnnotationKeys.LONGITUDE);
|
|
||||||
String slat = annotations.value(AnnotationKeys.LATITUDE);
|
String slat = annotations.value(AnnotationKeys.LATITUDE);
|
||||||
boolean validLng = slng != null && !slng.equals(NO_GEO_VALUE);
|
String slng = annotations.value(AnnotationKeys.LONGITUDE);
|
||||||
boolean validLat = slat != null && !slat.equals(NO_GEO_VALUE);
|
boolean validLat = slat != null && !slat.equals(NO_GEO_VALUE);
|
||||||
|
boolean validLng = slng != null && !slng.equals(NO_GEO_VALUE);
|
||||||
if (validLat && validLng) {
|
if (validLat && validLng) {
|
||||||
try {
|
try {
|
||||||
double lng = Double.parseDouble(slng);
|
|
||||||
double lat = Double.parseDouble(slat);
|
double lat = Double.parseDouble(slat);
|
||||||
|
double lng = Double.parseDouble(slng);
|
||||||
ObjectNode loc = objectNode()
|
ObjectNode loc = objectNode()
|
||||||
.put("type", "geo")
|
.put("locType", "geo")
|
||||||
.put("lng", lng)
|
.put("latOrY", lat)
|
||||||
.put("lat", lat);
|
.put("longOrX", lng);
|
||||||
payload.set("location", loc);
|
payload.set("location", loc);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
log.warn("Invalid geo data: longitude={}, latitude={}", slng, slat);
|
log.warn("Invalid geo data: latitude={}, longitude={}", slat, slng);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,10 @@ public class Topo2Jsonifier {
|
|||||||
private static final String GEO = "geo";
|
private static final String GEO = "geo";
|
||||||
private static final String GRID = "grid";
|
private static final String GRID = "grid";
|
||||||
private static final String PEER_LOCATIONS = "peerLocations";
|
private static final String PEER_LOCATIONS = "peerLocations";
|
||||||
|
private static final String LOCATION = "location";
|
||||||
|
private static final String LOC_TYPE = "locType";
|
||||||
|
private static final String LAT_OR_Y = "latOrY";
|
||||||
|
private static final String LONG_OR_X = "longOrX";
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@ -478,29 +482,29 @@ public class Topo2Jsonifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addGeoGridLocation(ObjectNode node, Annotated a) {
|
private void addGeoGridLocation(ObjectNode node, Annotated a) {
|
||||||
List<String> lngLat = getAnnotValues(a, LONGITUDE, LATITUDE);
|
List<String> latLongData = getAnnotValues(a, LATITUDE, LONGITUDE);
|
||||||
List<String> gridYX = getAnnotValues(a, GRID_Y, GRID_X);
|
List<String> gridYXdata = getAnnotValues(a, GRID_Y, GRID_X);
|
||||||
|
|
||||||
if (lngLat != null) {
|
if (latLongData != null) {
|
||||||
attachLocation(node, "geo", "lng", "lat", lngLat);
|
attachLocation(node, GEO, latLongData);
|
||||||
} else if (gridYX != null) {
|
} else if (gridYXdata != null) {
|
||||||
attachLocation(node, "grid", "gridY", "gridX", gridYX);
|
attachLocation(node, GRID, gridYXdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachLocation(ObjectNode node, String locType,
|
private void attachLocation(ObjectNode node, String locType,
|
||||||
String keyA, String keyB, List<String> values) {
|
List<String> values) {
|
||||||
try {
|
try {
|
||||||
double valA = Double.parseDouble(values.get(0));
|
double latOrY = Double.parseDouble(values.get(0));
|
||||||
double valB = Double.parseDouble(values.get(1));
|
double longOrX = Double.parseDouble(values.get(1));
|
||||||
ObjectNode loc = objectNode()
|
ObjectNode loc = objectNode()
|
||||||
.put("type", locType)
|
.put(LOC_TYPE, locType)
|
||||||
.put(keyA, valA)
|
.put(LAT_OR_Y, latOrY)
|
||||||
.put(keyB, valB);
|
.put(LONG_OR_X, longOrX);
|
||||||
node.set("location", loc);
|
node.set(LOCATION, loc);
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
log.warn("Invalid {} data: long/Y={}, lat/X={}",
|
log.warn("Invalid {} data: lat/Y={}, long/X={}",
|
||||||
locType, values.get(0), values.get(1));
|
locType, values.get(0), values.get(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -513,9 +517,9 @@ public class Topo2Jsonifier {
|
|||||||
ObjectNode o = objectNode();
|
ObjectNode o = objectNode();
|
||||||
for (LayoutLocation ll : locs) {
|
for (LayoutLocation ll : locs) {
|
||||||
ObjectNode lnode = objectNode()
|
ObjectNode lnode = objectNode()
|
||||||
.put("locType", ll.locType().toString())
|
.put(LOC_TYPE, ll.locType().toString())
|
||||||
.put("latOrY", ll.latOrY())
|
.put(LAT_OR_Y, ll.latOrY())
|
||||||
.put("longOrX", ll.longOrX());
|
.put(LONG_OR_X, ll.longOrX());
|
||||||
o.set(ll.id(), lnode);
|
o.set(ll.id(), lnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,13 @@
|
|||||||
// Internal state;
|
// Internal state;
|
||||||
var nearDist = 15;
|
var nearDist = 15;
|
||||||
|
|
||||||
|
function setElCoord(el, coord) {
|
||||||
|
el.fix(true);
|
||||||
|
el.x = el.px = coord[0];
|
||||||
|
el.y = el.py = coord[1];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function positionNode(node, forUpdate) {
|
function positionNode(node, forUpdate) {
|
||||||
|
|
||||||
var meta = node.get('metaUi'),
|
var meta = node.get('metaUi'),
|
||||||
@ -40,7 +47,7 @@
|
|||||||
// If the node has metaUI data attached, it indicates that the user
|
// If the node has metaUI data attached, it indicates that the user
|
||||||
// has dragged the node to a new position on the view; so we should
|
// has dragged the node to a new position on the view; so we should
|
||||||
// respect that above any script-configured position...
|
// respect that above any script-configured position...
|
||||||
// (NOTE: This is a slightly different to the original topology code)
|
// (NOTE: This is slightly different to the "classic" topology code)
|
||||||
|
|
||||||
if (hasMeta) {
|
if (hasMeta) {
|
||||||
node.fix(true);
|
node.fix(true);
|
||||||
@ -53,33 +60,18 @@
|
|||||||
// LONG/LAT (or GRID) locations for regions/devices/hosts
|
// LONG/LAT (or GRID) locations for regions/devices/hosts
|
||||||
|
|
||||||
if (node.nodeType === 'peer-region') {
|
if (node.nodeType === 'peer-region') {
|
||||||
var coord = [0, 0],
|
|
||||||
loc = {};
|
|
||||||
|
|
||||||
if (t2bgs.getBackgroundType() === 'geo') {
|
if (t2bgs.getBackgroundType() === 'geo') {
|
||||||
|
|
||||||
var loc = node.get('location'),
|
|
||||||
type = loc.locType || loc.type;
|
|
||||||
|
|
||||||
node.set({ location: {
|
|
||||||
type: type.toLowerCase(),
|
|
||||||
lat: loc.latOrY || loc.lat,
|
|
||||||
lng: loc.longOrX || loc.lng
|
|
||||||
}});
|
|
||||||
|
|
||||||
setLongLat(node);
|
setLongLat(node);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
loc.gridX = -20;
|
|
||||||
loc.gridY = 10 * node.index();
|
|
||||||
coord = coordFromXY(loc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node.px = node.x = coord[0];
|
// assumed to be grid
|
||||||
node.py = node.y = coord[1];
|
var loc = {
|
||||||
|
longOrX: -20,
|
||||||
|
latOrY: 10 * node.index()
|
||||||
|
};
|
||||||
|
|
||||||
node.fix(true);
|
setElCoord(node, coordFromXY(loc));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,45 +122,29 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setLongLat(el) {
|
function setLongLat(el) {
|
||||||
var loc = el.get('location'),
|
var loc = el.get('location');
|
||||||
coord;
|
|
||||||
|
|
||||||
if (loc && loc.type === 'geo') {
|
// bail if no location set
|
||||||
|
if (!loc || (loc.latOrY === 0 && loc.longOrX === 0)) {
|
||||||
if (loc.lat === 0 && loc.lng === 0) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
coord = coordFromLngLat(loc);
|
|
||||||
el.fix(true);
|
|
||||||
el.x = el.px = coord[0];
|
|
||||||
el.y = el.py = coord[1];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loc && loc.type === 'grid') {
|
if (loc.locType === 'geo') {
|
||||||
|
return setElCoord(el, coordFromLngLat(loc));
|
||||||
if (loc.gridX === 0 && loc.gridY === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
coord = coordFromXY(loc);
|
|
||||||
el.fix(true);
|
|
||||||
el.x = el.px = coord[0];
|
|
||||||
el.y = el.py = coord[1];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (loc.locType === 'grid') {
|
||||||
|
return setElCoord(el, coordFromXY(loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function coordFromLngLat(loc) {
|
function coordFromLngLat(loc) {
|
||||||
var p = t2mcs.projection();
|
var p = t2mcs.projection();
|
||||||
return p ? p([loc.lng, loc.lat]) : [0, 0];
|
return p ? p([loc.longOrX, loc.latOrY]) : [0, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function coordFromXY(loc) {
|
function coordFromXY(loc) {
|
||||||
|
|
||||||
var bgWidth = t2sls.getWidth() || 100,
|
var bgWidth = t2sls.getWidth() || 100,
|
||||||
bgHeight = t2sls.getHeight() || 100;
|
bgHeight = t2sls.getHeight() || 100;
|
||||||
|
|
||||||
@ -176,8 +152,8 @@
|
|||||||
yOffset = (1000 - (bgHeight * scale)) / 2;
|
yOffset = (1000 - (bgHeight * scale)) / 2;
|
||||||
|
|
||||||
// 1000 is a hardcoded HTML value of the SVG element (topo2.html)
|
// 1000 is a hardcoded HTML value of the SVG element (topo2.html)
|
||||||
var x = scale * loc.gridX,
|
var x = scale * loc.longOrX,
|
||||||
y = (scale * loc.gridY) + yOffset;
|
y = (scale * loc.latOrY) + yOffset;
|
||||||
|
|
||||||
return [x, y];
|
return [x, y];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user