-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccumuloClusterTest.java
123 lines (107 loc) · 4.95 KB
/
AccumuloClusterTest.java
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.whirr.service.accumulo;
import java.io.File;
import java.io.PrintStream;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.whirr.ClusterSpec;
import org.apache.whirr.service.BaseServiceDryRunTest;
import org.apache.whirr.service.DryRunModule.DryRun;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.Statement;
import org.junit.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
public class AccumuloClusterTest extends BaseServiceDryRunTest {
@Test
@Override
public void testBootstrapAndConfigure() throws Exception {
// override the default behaviour to create some scripts which we can
// run on docker containers
ClusterSpec cookbookWithDefaultRecipe = newClusterSpecForProperties(ImmutableMap
.of("whirr.instance-templates",
"1 hadoop-namenode+hadoop-jobtracker+zookeeper+accumulo-master+accumulo-monitor+accumulo-gc, 1 hadoop-datanode+hadoop-tasktracker+accumulo-tserver+accumulo-tracer",
"whirr.hadoop.version", "1.2.1", "whirr.zookeeper.tarball.url",
"http://archive.apache.org/dist/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz", "hadoop-hdfs.dfs.durable.sync", "true"));
DryRun dryRun = launchWithClusterSpec(cookbookWithDefaultRecipe);
File tgtDir = new File("target");
TreeMap<String, String> nodePropMap = new TreeMap<String, String>();
Set<String> nodes = new TreeSet<String>();
int n = -1;
int i = 0;
for (Entry<NodeMetadata, Statement> exe : dryRun.getExecutions().entries()) {
NodeMetadata nodeMeta = exe.getKey();
System.err.println(ToStringBuilder.reflectionToString(exe.getKey()));
if (!nodes.contains(nodeMeta.getName())) {
i = 0;
n++;
nodes.add(nodeMeta.getName());
}
String filename = String.format("%s-%s-%d.sh", nodeMeta.getPrivateAddresses().iterator().next(), nodeMeta
.getPublicAddresses().iterator().next(), i);
PrintStream ps = new PrintStream(new File(tgtDir, filename));
ps.println(exe.getValue().render(OsFamily.UNIX));
ps.close();
// System.err.println("\t" + exe.getValue().render(OsFamily.UNIX));
i++;
nodePropMap.put(String.format("%d\tPUBLIC_IP", n), nodeMeta.getPublicAddresses().iterator().next());
nodePropMap.put(String.format("%d\tPRIVATE_IP", n), nodeMeta.getPrivateAddresses().iterator().next());
nodePropMap.put(String.format("%d\tHOSTNAME", n), nodeMeta.getName());
nodePropMap.put(String.format("%d\tSCRIPTS", n), String.valueOf(i));
}
nodePropMap.put("NODES", String.valueOf(nodes.size()));
// write jclouds assigned properties to file so we can update with the
// actual ones assigned to each docker container
File propFile = new File(tgtDir, "cluster.properties");
PrintStream ps = new PrintStream(propFile);
for (Entry<String, String> entry : nodePropMap.entrySet()) {
ps.println(entry.getKey() + "\t" + entry.getValue());
}
ps.close();
}
@Override
protected Predicate<CharSequence> bootstrapPredicate() {
// TODO Auto-generated method stub
return new Predicate<CharSequence>() {
@Override
public boolean apply(CharSequence arg0) {
return true;
}
};
}
@Override
protected Predicate<CharSequence> configurePredicate() {
// TODO Auto-generated method stub
return new Predicate<CharSequence>() {
@Override
public boolean apply(CharSequence arg0) {
return true;
}
};
}
@Override
protected Set<String> getInstanceRoles() {
return ImmutableSet.of("accumulo-master");
}
}