1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.deployment;
import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.SystemName;
import com.yahoo.config.provision.zone.ZoneId;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.Slime;
import com.yahoo.slime.SlimeUtils;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.RevisionId;
import com.yahoo.vespa.hosted.controller.application.Endpoint;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Instant;
import java.util.List;
import java.util.Map;
/**
* Serializes config for integration tests against Vespa deployments.
*
* @author jonmv
*/
public class TestConfigSerializer {
private final SystemName system;
public TestConfigSerializer(SystemName system) {
this.system = system;
}
public Slime configSlime(ApplicationId id,
JobType type,
boolean isCI,
Version platform,
RevisionId revision,
Instant deployedAt,
Map<ZoneId, List<Endpoint>> deployments,
Map<ZoneId, List<String>> clusters) {
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("application", id.serializedForm());
root.setString("zone", type.zone().value());
root.setString("system", system.value());
root.setBool("isCI", isCI);
root.setString("platform", platform.toFullString());
root.setLong("revision", revision.number());
root.setLong("deployedAt", deployedAt.toEpochMilli());
// TODO jvenstad: remove when clients can be updated
Cursor endpointsObject = root.setObject("endpoints");
deployments.forEach((zone, endpoints) -> {
Cursor endpointArray = endpointsObject.setArray(zone.value());
for (Endpoint endpoint : endpoints)
endpointArray.addString(endpoint.url().toString());
});
Cursor zoneEndpointsObject = root.setObject("zoneEndpoints");
deployments.forEach((zone, endpoints) -> {
Cursor clusterEndpointsObject = zoneEndpointsObject.setObject(zone.value());
for (Endpoint endpoint : endpoints)
clusterEndpointsObject.setString(endpoint.name(), endpoint.url().toString());
});
if ( ! clusters.isEmpty()) {
Cursor clustersObject = root.setObject("clusters");
clusters.forEach((zone, clusterList) -> {
Cursor clusterArray = clustersObject.setArray(zone.value());
for (String cluster : clusterList)
clusterArray.addString(cluster);
});
}
return slime;
}
/** Returns the config for the tests to run for the given job. */
public byte[] configJson(ApplicationId id,
JobType type,
boolean isCI,
Version platform,
RevisionId revision,
Instant deployedAt,
Map<ZoneId, List<Endpoint>> deployments,
Map<ZoneId, List<String>> clusters) {
try {
return SlimeUtils.toJsonBytes(configSlime(id, type, isCI, platform, revision, deployedAt, deployments, clusters));
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
|