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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.apps.clustercontroller;
import com.yahoo.cloud.config.SlobroksConfig;
import com.yahoo.cloud.config.ZookeepersConfig;
import com.yahoo.jdisc.Metric;
import com.yahoo.vespa.config.content.FleetcontrollerConfig;
import com.yahoo.vespa.config.content.StorDistributionConfig;
import junit.framework.TestCase;
import java.util.Map;
public class ClusterControllerClusterConfigurerTest extends TestCase {
public void testSimple() throws Exception {
ClusterController controller = new ClusterController();
StorDistributionConfig.Builder distributionConfig = new StorDistributionConfig.Builder();
StorDistributionConfig.Group.Builder group = new StorDistributionConfig.Group.Builder();
group.index("0").name("foo");
StorDistributionConfig.Group.Nodes.Builder node = new StorDistributionConfig.Group.Nodes.Builder();
node.index(0);
group.nodes.add(node);
distributionConfig.group.add(group);
FleetcontrollerConfig.Builder fleetcontrollerConfig = new FleetcontrollerConfig.Builder();
fleetcontrollerConfig
.cluster_name("storage")
.index(0)
.zookeeper_server("zoo")
.min_node_ratio_per_group(0.123);
SlobroksConfig.Builder slobroksConfig = new SlobroksConfig.Builder();
SlobroksConfig.Slobrok.Builder slobrok = new SlobroksConfig.Slobrok.Builder();
slobrok.connectionspec("foo");
slobroksConfig.slobrok.add(slobrok);
ZookeepersConfig.Builder zookeepersConfig = new ZookeepersConfig.Builder();
zookeepersConfig.zookeeperserverlist("foo");
Metric metric = new Metric() {
@Override
public void set(String s, Number number, Context context) {}
@Override
public void add(String s, Number number, Context context) {}
@Override
public Context createContext(Map<String, ?> stringMap) { return null; }
};
// Used in standalone modus to get config without a cluster controller instance
ClusterControllerClusterConfigurer configurer = new ClusterControllerClusterConfigurer(
null,
new StorDistributionConfig(distributionConfig),
new FleetcontrollerConfig(fleetcontrollerConfig),
new SlobroksConfig(slobroksConfig),
new ZookeepersConfig(zookeepersConfig),
metric
);
assertTrue(configurer.getOptions() != null);
assertEquals(0.123, configurer.getOptions().minNodeRatioPerGroup, 0.01);
// Oki with no zookeeper if one node
zookeepersConfig.zookeeperserverlist("");
new ClusterControllerClusterConfigurer(
controller,
new StorDistributionConfig(distributionConfig),
new FleetcontrollerConfig(fleetcontrollerConfig),
new SlobroksConfig(slobroksConfig),
new ZookeepersConfig(zookeepersConfig),
metric
);
try{
fleetcontrollerConfig.fleet_controller_count(5);
new ClusterControllerClusterConfigurer(
controller,
new StorDistributionConfig(distributionConfig),
new FleetcontrollerConfig(fleetcontrollerConfig),
new SlobroksConfig(slobroksConfig),
new ZookeepersConfig(zookeepersConfig),
metric
);
fail("Should not get here");
} catch (Exception e) {
assertEquals("Must set zookeeper server with multiple fleetcontrollers", e.getMessage());
}
}
}
|