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
|
// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.service.duper;
import com.yahoo.config.model.api.ApplicationInfo;
import com.yahoo.config.model.api.HostInfo;
import com.yahoo.config.provision.HostName;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author hakonhall
*/
public class TestZoneApplication {
private final List<HostName> nodeAdminHostnames;
private final List<HostName> routingHostnames;
private TestZoneApplication(List<HostName> nodeAdminHostnames, List<HostName> routingHostnames) {
this.nodeAdminHostnames = nodeAdminHostnames;
this.routingHostnames = routingHostnames;
}
public ApplicationInfo makeApplicationInfo() {
// Make a test ApplicationInfo by:
// 1. Make an ApplicationInfo as-if the node-admin cluster of the zone application were the only cluster.
// Make sure to get the correct tenant name, application name, cluster id, service type, hostnames,
// services, and ports. This should be easy with the help of InfraApplication.
ApplicationInfo nodeAdminPart = new NodeAdminPartOfZoneApplication().makeApplicationInfo(nodeAdminHostnames);
// 2. Make an ApplicationInfo as-if the routing cluster of the zone application were the only cluster.
// Don't care if the application is not perfect.
ApplicationInfo routingPart = new RoutingPartOfZoneApplication().makeApplicationInfo(routingHostnames);
// 3. Take HostInfo from (1) and (2) to make a single ApplicationInfo.
List<HostInfo> allHostInfos = new ArrayList<>();
allHostInfos.addAll(nodeAdminPart.getModel().getHosts());
allHostInfos.addAll(routingPart.getModel().getHosts());
return new ApplicationInfo(nodeAdminPart.getApplicationId(), 0, new HostsModel(allHostInfos));
}
public static class Builder {
private List<HostName> nodeAdminHostnames = null;
private List<HostName> routingHostnames = null;
public Builder addNodeAdminCluster(String... hostnames) {
this.nodeAdminHostnames = Stream.of(hostnames).map(HostName::from).collect(Collectors.toList());
return this;
}
public Builder addRoutingCluster(String... hostnames) {
this.routingHostnames = Stream.of(hostnames).map(HostName::from).collect(Collectors.toList());
return this;
}
public TestZoneApplication build() {
return new TestZoneApplication(Objects.requireNonNull(nodeAdminHostnames), Objects.requireNonNull(routingHostnames));
}
}
private static class NodeAdminPartOfZoneApplication extends InfraApplication {
public NodeAdminPartOfZoneApplication() {
super(ZoneApplication.getApplicationName().value(),
ZoneApplication.getNodeAdminNodeType(),
ZoneApplication.getNodeAdminClusterSpecType(),
ZoneApplication.getNodeAdminClusterSpecId(),
ZoneApplication.getNodeAdminServiceType(),
ZoneApplication.getNodeAdminHealthPort());
}
}
/**
* This InfraApplication is bogus (containing host admin instead of jdisc container), but the tests are
* not supposed to explore this cluster.
*/
private static class RoutingPartOfZoneApplication extends InfraApplication {
public RoutingPartOfZoneApplication() {
super(ZoneApplication.getApplicationName().value(),
ZoneApplication.getRoutingNodeType(),
ZoneApplication.getRoutingClusterSpecType(),
ZoneApplication.getRoutingClusterSpecId(),
ZoneApplication.getRoutingServiceType(),
ZoneApplication.getRoutingHealthPort());
}
}
}
|