diff options
author | toby <smorgrav@yahoo-inc.com> | 2017-10-02 11:45:55 +0200 |
---|---|---|
committer | toby <smorgrav@yahoo-inc.com> | 2017-10-10 13:39:36 +0200 |
commit | 96f241dab9c301aebd31830664a83f4ab52d77b7 (patch) | |
tree | 6384de1becfd2926327d23ff9d24a9b86724a890 /controller-server | |
parent | 7d5330266fea0669d0c903b525e815c004babb75 (diff) |
Complete serialization for the clusterinfo and clusterutils objects
Diffstat (limited to 'controller-server')
2 files changed, 26 insertions, 12 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java index 9266249f487..859e322b227 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java @@ -126,14 +126,13 @@ public class ApplicationSerializer { } private void clusterInfoToSlime(Map<ClusterSpec.Id, ClusterInfo> clusters, Cursor object) { - Cursor array = object.setArray(clusterInfoField); + Cursor root = object.setObject(clusterInfoField); for (Map.Entry<ClusterSpec.Id, ClusterInfo> entry : clusters.entrySet()) { - toSlime(entry.getValue(), array.addObject(), entry.getKey().value()); + toSlime(entry.getValue(), root.setObject(entry.getKey().value())); } } - private void toSlime(ClusterInfo info, Cursor object, String key) { - object = object.setObject(key); + private void toSlime(ClusterInfo info, Cursor object) { object.setString(clusterInfoFlavorField, info.getFlavor()); object.setLong(clusterInfoCostField, info.getCost()); object.setString(clusterInfoTypeField, info.getClusterType().name()); @@ -144,14 +143,13 @@ public class ApplicationSerializer { } private void clusterUtilsToSlime(Map<ClusterSpec.Id, ClusterUtilization> clusters, Cursor object) { - Cursor array = object.setArray(clusterUtilsField); + Cursor root = object.setObject(clusterUtilsField); for (Map.Entry<ClusterSpec.Id, ClusterUtilization> entry : clusters.entrySet()) { - toSlime(entry.getValue(), array.addObject(), entry.getKey().value()); + toSlime(entry.getValue(), root.setObject(entry.getKey().value())); } } - private void toSlime(ClusterUtilization utils, Cursor object, String key) { - object = object.setObject(key); + private void toSlime(ClusterUtilization utils, Cursor object) { object.setDouble(clusterUtilsCpuField, utils.getCpu()); object.setDouble(clusterUtilsMemField, utils.getMemory()); object.setDouble(clusterUtilsDiskField, utils.getDisk()); @@ -259,7 +257,7 @@ public class ApplicationSerializer { private Map<ClusterSpec.Id, ClusterUtilization> clusterUtilsMapFromSlime(Inspector object) { Map<ClusterSpec.Id, ClusterUtilization> map = new HashMap<>(); - object.traverse((String name, Inspector obect) -> map.put(new ClusterSpec.Id(name), clusterUtililzationFromSlime(obect))); + object.traverse((String name, Inspector value) -> map.put(new ClusterSpec.Id(name), clusterUtililzationFromSlime(value))); return map; } @@ -276,7 +274,10 @@ public class ApplicationSerializer { String flavor = inspector.field(clusterInfoFlavorField).asString(); int cost = (int)inspector.field(clusterInfoCostField).asLong(); String type = inspector.field(clusterInfoTypeField).asString(); - return new ClusterInfo(flavor, cost, ClusterSpec.Type.from(type), new ArrayList<>()); + + List<String> hostnames = new ArrayList<>(); + inspector.field(clusterInfoHostnamesField).traverse((ArrayTraverser)(int index, Inspector value) -> hostnames.add(value.asString())); + return new ClusterInfo(flavor, cost, ClusterSpec.Type.from(type), hostnames); } private Zone zoneFromSlime(Inspector object) { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java index a41437d1c39..3e73bf4445b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -110,6 +109,20 @@ public class ApplicationSerializerTest { assertEquals(original.deploying(), serialized.deploying()); + // Test cluster utilization + assertEquals(0, serialized.deployments().get(zone1).clusterUtils().size()); + assertEquals(3, serialized.deployments().get(zone2).clusterUtils().size()); + assertEquals(0.4, serialized.deployments().get(zone2).clusterUtils().get(ClusterSpec.Id.from("id2")).getCpu(), 0.01); + assertEquals(0.2, serialized.deployments().get(zone2).clusterUtils().get(ClusterSpec.Id.from("id1")).getCpu(), 0.01); + assertEquals(0.2, serialized.deployments().get(zone2).clusterUtils().get(ClusterSpec.Id.from("id1")).getMemory(), 0.01); + + // Test cluster info + assertEquals(3, serialized.deployments().get(zone2).clusterInfo().size()); + assertEquals(10, serialized.deployments().get(zone2).clusterInfo().get(ClusterSpec.Id.from("id2")).getCost()); + assertEquals(ClusterSpec.Type.content, serialized.deployments().get(zone2).clusterInfo().get(ClusterSpec.Id.from("id2")).getClusterType()); + assertEquals("flavor2", serialized.deployments().get(zone2).clusterInfo().get(ClusterSpec.Id.from("id2")).getFlavor()); + assertEquals(4, serialized.deployments().get(zone2).clusterInfo().get(ClusterSpec.Id.from("id2")).getHostnames().size()); + { // test more deployment serialization cases Application original2 = original.withDeploying(Optional.of(Change.ApplicationChange.of(ApplicationRevision.from("hash1")))); Application serialized2 = applicationSerializer.fromSlime(applicationSerializer.toSlime(original2)); @@ -140,7 +153,7 @@ public class ApplicationSerializerTest { } result.put(ClusterSpec.Id.from("id" + cluster), new ClusterInfo("flavor" + cluster, 10, - ClusterSpec.Type.content, Collections.singletonList("hostname1"))); + ClusterSpec.Type.content, hostnames)); } return result; } |