Skip to content

Commit ba8edc4

Browse files
author
Sebastian Brandt
committed
Merge branch 'master' of github.com:mesos/elasticsearch into feature/credentialsChange
2 parents d9178ba + a22fcd1 commit ba8edc4

40 files changed

+837
-463
lines changed

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: java
2+
3+
jdk:
4+
- oraclejdk8
5+
6+
sudo: required
7+
8+
install:
9+
# one liner installation of docker 1.9.1 below did not work (see https://github.com/moul/travis-docker/issues/38).
10+
# - curl -sLo - http://j.mp/install-travis-docker | sh -xe
11+
# Therefore installing it through a script
12+
- sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-precise main" > /etc/apt/sources.list.d/docker.list'
13+
- sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
14+
- sudo apt-get update
15+
- sudo apt-key update
16+
- sudo apt-get -qqy install docker-engine=1.9.1-0~precise
17+
# Has to run this script with sudo because custom installation does not allow $USER to use docker and it's not possible to relogin
18+
19+
# Has to run the build script with sudo because custom installation does not allow $USER to use docker and it's not possible to relogin
20+
script: chmod +x travis.sh && sudo ./travis.sh
21+
22+
notifications:
23+
email: true

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ext {
1313
commonsIOVersion = "2.4"
1414
commonsLangVersion = "3.4"
1515
commonsValidatorVersion = "1.5.0"
16-
dockerJavaVersion = "1.4.0"
16+
dockerJavaVersion = "3.0.0"
1717
elasticsearchVersion="2.2.0"
1818
gradleDownloadTaskVersion = "2.1.0"
1919
hamcrestVersion = "1.3"
@@ -25,7 +25,7 @@ ext {
2525
junitVersion = "4.12"
2626
log4jVersion = "1.2.17"
2727
mesosVer = "0.28.2"
28-
minimesosVersion = "0.7.1"
28+
minimesosVersion = "0.10.2"
2929
springBootVersion = "1.2.5.RELEASE" // Bumping SB version causes Jackson incompatabilities with Docker-Java
3030
unirestVersion = "1.4.8"
3131

commons/src/main/java/org/apache/mesos/elasticsearch/common/zookeeper/model/ZKAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ZKAddress {
1414
public static final String ZK_PREFIX = "zk://";
1515
public static final String USER_AND_PASS_REG = "([^/@:]+):([^/@:]+)";
1616
public static final String HOST_AND_PORT_REG = "([A-z0-9-.]+)(?::)([0-9]+)";
17-
public static final String ZK_NODE_REG = "/([^/]+)";
17+
public static final String ZK_NODE_REG = "/([^/]+(?:/[^/]+)*)";
1818
public static final String ADDRESS_REGEX = "^(?:" + USER_AND_PASS_REG + "@)?" + HOST_AND_PORT_REG + "(?:" + ZK_NODE_REG + ")?";
1919
public static final String VALID_ZK_URL = "zk://host1:port1,user:pass@host2:port2/path,.../path";
2020
private String user;

commons/src/main/resources/log4j.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
33

4-
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
4+
<log4j:configuration xmlns:log4j="```http://jakarta.apache.org/log4j/">
55
<appender name="console" class="org.apache.log4j.ConsoleAppender">
66
<param name="Target" value="System.out"/>
77
<layout class="org.apache.log4j.PatternLayout">

commons/src/test/java/org/apache/mesos/elasticsearch/common/zookeeper/parser/ZKAddressParserTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ public void shouldAcceptIfMultiZKAddressWithPath() {
7070
assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos");
7171
}
7272

73+
@Test
74+
public void shouldAcceptIfSingleZKAddressWithSubpath() {
75+
String add = "zk://192.168.0.1:2182/mesos/subpath";
76+
List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add);
77+
assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", "mesos/subpath");
78+
}
79+
80+
@Test
81+
public void shouldAcceptIfMultiZKAddressWithSubpath() {
82+
String add = "zk://192.168.0.1:2182,10.4.52.3:1234/mesos/sub_path";
83+
List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add);
84+
assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", "");
85+
assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos/sub_path");
86+
}
87+
88+
@Test
89+
public void shouldAcceptIfMultiZKAddressWithMultiSubpath() {
90+
String add = "zk://192.168.0.1:2182/mesos/sub_path1,10.4.52.3:1234/mesos/sub_path2";
91+
List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add);
92+
assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", "mesos/sub_path1");
93+
assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos/sub_path2");
94+
}
95+
96+
7397
@Test
7498
public void shouldAcceptIfSpacesInPath() {
7599
String add = "zk://192.168.0.1:2182, 10.4.52.3:1234/mesos";
@@ -108,4 +132,4 @@ private void assertZKEquals(ZKAddress zk, String user, String pass, String addr,
108132
assertEquals(pass, zk.getPassword());
109133
assertEquals(zkNode, zk.getZkNode());
110134
}
111-
}
135+
}

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ Usage: (Options preceded by an asterisk are required) [options]
158158
--executorName
159159
The name given to the executor task.
160160
Default: elasticsearch-executor
161+
--executorLabels
162+
One or more labels given to the executor task. Example: 'environment=prod bananas=apples'
163+
Default: <empty string>
161164
--externalVolumeDriver
162165
Use external volume storage driver. By default, nodes will use volumes on
163166
host.

scheduler/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ dependencies {
2727

2828
compile project(":commons")
2929

30-
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
30+
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") {
31+
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
32+
}
3133
compile("org.springframework.boot:spring-boot-starter-log4j:${springBootVersion}")
3234
compile "commons-io:commons-io:${commonsIOVersion}"
3335
compile "org.apache.commons:commons-collections4:${commonsCollectionsVersion}"

scheduler/src/main/java/org/apache/mesos/elasticsearch/scheduler/Configuration.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.ArrayList;
2020
import java.util.Collections;
2121
import java.util.List;
22+
import java.util.Map;
23+
import java.util.HashMap;
2224
import java.util.stream.Collectors;
2325

2426
import static java.util.Arrays.asList;
@@ -36,6 +38,7 @@ public class Configuration {
3638
public static final String WEB_UI_PORT = "--webUiPort";
3739
public static final String FRAMEWORK_NAME = "--frameworkName";
3840
public static final String EXECUTOR_NAME = "--executorName";
41+
public static final String EXECUTOR_LABELS = "--executorLabels";
3942
public static final String DATA_DIR = "--dataDir";
4043
public static final String DEFAULT_HOST_DATA_DIR = "/var/lib/mesos/slave/elasticsearch";
4144
// DCOS Certification requirement 01
@@ -85,6 +88,9 @@ public class Configuration {
8588
private String frameworkName = "elasticsearch";
8689
@Parameter(names = {EXECUTOR_NAME}, description = "The name given to the executor task.", validateWith = CLIValidators.NotEmptyString.class)
8790
private String executorName = "elasticsearch-executor";
91+
@Parameter(names = {EXECUTOR_LABELS}, description = "One or more labels given to the executor task." +
92+
"E.g. 'environment=prod bananas=apples'", variableArity = true)
93+
private List<String> executorLabels = new ArrayList<>();
8894
@Parameter(names = {DATA_DIR}, description = "The host data directory used by Docker volumes in the executors. [DOCKER MODE ONLY]")
8995
private String dataDir = DEFAULT_HOST_DATA_DIR;
9096
@Parameter(names = {FRAMEWORK_FAILOVER_TIMEOUT}, description = "The time before Mesos kills a scheduler and tasks if it has not recovered (ms).", validateValueWith = CLIValidators.PositiveDouble.class)
@@ -176,6 +182,18 @@ public String getTaskName() {
176182
return executorName;
177183
}
178184

185+
public Map<String, String> getTaskLabels() {
186+
HashMap<String, String> map = new HashMap<>();
187+
for (String keyValue : executorLabels) {
188+
String[] kvp = keyValue.split("=", 2);
189+
if (kvp.length == 2) {
190+
map.put(kvp[0], kvp[1]);
191+
}
192+
}
193+
194+
return map;
195+
}
196+
179197
public String getDataDir() {
180198
return dataDir;
181199
}

scheduler/src/main/java/org/apache/mesos/elasticsearch/scheduler/TaskInfoFactory.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.ZoneOffset;
2020
import java.time.ZonedDateTime;
2121
import java.util.List;
22+
import java.util.Map;
2223
import java.util.Optional;
2324
import java.util.Properties;
2425
import java.util.stream.Collectors;
@@ -69,6 +70,7 @@ private Protos.TaskInfo buildNativeTask(Protos.Offer offer, Configuration config
6970
final List<Integer> ports = getPorts(offer, configuration);
7071
final List<Protos.Resource> resources = getResources(configuration, ports);
7172
final Protos.DiscoveryInfo discovery = getDiscovery(ports, configuration);
73+
final Protos.Labels labels = getLabels(configuration);
7274

7375
final String hostAddress = resolveHostAddress(offer, ports);
7476

@@ -83,6 +85,7 @@ private Protos.TaskInfo buildNativeTask(Protos.Offer offer, Configuration config
8385
.setSlaveId(offer.getSlaveId())
8486
.addAllResources(resources)
8587
.setDiscovery(discovery)
88+
.setLabels(labels)
8689
.setCommand(nativeCommand(configuration, args, elasticSearchNodeId))
8790
.build();
8891
}
@@ -91,6 +94,7 @@ private Protos.TaskInfo buildDockerTask(Protos.Offer offer, Configuration config
9194
final List<Integer> ports = getPorts(offer, configuration);
9295
final List<Protos.Resource> resources = getResources(configuration, ports);
9396
final Protos.DiscoveryInfo discovery = getDiscovery(ports, configuration);
97+
final Protos.Labels labels = getLabels(configuration);
9498

9599
final String hostAddress = resolveHostAddress(offer, ports);
96100

@@ -107,6 +111,7 @@ private Protos.TaskInfo buildDockerTask(Protos.Offer offer, Configuration config
107111
.setSlaveId(offer.getSlaveId())
108112
.addAllResources(resources)
109113
.setDiscovery(discovery)
114+
.setLabels(labels)
110115
.setCommand(dockerCommand(configuration, args, elasticSearchNodeId))
111116
.setContainer(containerInfo)
112117
.build();
@@ -125,8 +130,7 @@ private List<Integer> getPorts(Protos.Offer offer, Configuration configuration)
125130
if (elasticsearchPorts.isEmpty() || elasticsearchPorts.stream().allMatch(port -> port == 0)) {
126131
//No ports requested by user or two random ports requested
127132
ports = Resources.selectTwoPortsFromRange(offer.getResourcesList());
128-
}
129-
else {
133+
} else {
130134
//Replace a user requested port 0 with a random port
131135
ports = elasticsearchPorts.stream().map(port -> port != 0 ? port : Resources.selectOnePortFromRange(offer.getResourcesList())).collect(Collectors.toList());
132136
}
@@ -143,14 +147,29 @@ private List<Protos.Resource> getResources(Configuration configuration, List<Int
143147
private Protos.DiscoveryInfo getDiscovery(List<Integer> ports, Configuration configuration) {
144148
Protos.DiscoveryInfo.Builder discovery = Protos.DiscoveryInfo.newBuilder();
145149
Protos.Ports.Builder discoveryPorts = Protos.Ports.newBuilder();
146-
discoveryPorts.addPorts(Discovery.CLIENT_PORT_INDEX, Protos.Port.newBuilder().setNumber(ports.get(0)).setName(Discovery.CLIENT_PORT_NAME).setProtocol("TCP"));
147-
discoveryPorts.addPorts(Discovery.TRANSPORT_PORT_INDEX, Protos.Port.newBuilder().setNumber(ports.get(1)).setName(Discovery.TRANSPORT_PORT_NAME).setProtocol("TCP"));
150+
discoveryPorts.addPorts(Discovery.CLIENT_PORT_INDEX, Protos.Port.newBuilder().setNumber(ports.get(0)).setName(Discovery.CLIENT_PORT_NAME).setProtocol("tcp"));
151+
discoveryPorts.addPorts(Discovery.TRANSPORT_PORT_INDEX, Protos.Port.newBuilder().setNumber(ports.get(1)).setName(Discovery.TRANSPORT_PORT_NAME).setProtocol("tcp"));
148152
discovery.setPorts(discoveryPorts);
149153
discovery.setVisibility(Protos.DiscoveryInfo.Visibility.EXTERNAL);
150154
discovery.setName(configuration.getTaskName());
151155
return discovery.build();
152156
}
153157

158+
private Protos.Labels getLabels(Configuration configuration) {
159+
Protos.Labels.Builder builder = Protos.Labels.newBuilder();
160+
Map<String, String> labels = configuration.getTaskLabels();
161+
for (Map.Entry<String, String> kvp : labels.entrySet()) {
162+
Protos.Label label = Protos.Label.newBuilder()
163+
.setKey(kvp.getKey())
164+
.setValue(kvp.getValue())
165+
.build();
166+
167+
builder.addLabels(label);
168+
}
169+
170+
return builder.build();
171+
}
172+
154173
private Protos.ContainerInfo getContainer(Configuration configuration, Protos.TaskID taskID, Long elasticSearchNodeId, Protos.SlaveID slaveID) {
155174
final Protos.Environment environment = Protos.Environment.newBuilder().addAllVariables(new ExecutorEnvironmentalVariables(configuration, elasticSearchNodeId).getList()).build();
156175
final Protos.ContainerInfo.DockerInfo.Builder dockerInfo = Protos.ContainerInfo.DockerInfo.newBuilder()

scheduler/src/test/java/org/apache/mesos/elasticsearch/scheduler/ConfigurationTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.net.UnknownHostException;
1212
import java.util.Arrays;
1313
import java.util.List;
14+
import java.util.Map;
1415

1516
import static org.junit.Assert.*;
1617

@@ -78,4 +79,20 @@ public void shouldCreateVolumeName() {
7879
Configuration configuration = new Configuration(ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, "aa", Configuration.FRAMEWORK_NAME, "test");
7980
assertEquals("test0data", configuration.dataVolumeName(0L));
8081
}
81-
}
82+
83+
@Test
84+
public void shouldCreateTaskLabels() {
85+
Configuration configuration = new Configuration(
86+
ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, "aa", Configuration.EXECUTOR_LABELS,
87+
"foo=bar",
88+
"incomplete",
89+
"empty=",
90+
"separator=values=are=joined");
91+
Map<String, String> labels = configuration.getTaskLabels();
92+
93+
assertEquals("bar", labels.get("foo"));
94+
assertFalse(labels.containsKey("incomplete"));
95+
assertEquals("", labels.get("empty"));
96+
assertEquals("values=are=joined", labels.get("separator"));
97+
}
98+
}

0 commit comments

Comments
 (0)