Elffuss BraidHub

kikocis/java-driver public

Merge pull request #625 from datastax/multi-workload-support

Support multiple workloads for DSE nodes, updateDSENodeConfig
Changeset66e5cc716ac20387b4b00662a82f95aa10f95a2c4440ff020accb9aac19cab79
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2016-04-01 19:51 +02:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2016-04-01 19:51 +02:00
Parents6b53da5530f8, bdbef4d2f3a9

Browse the files at this changeset

7 files changed

modified driver-core/src/test/java/com/datastax/driver/core/CCMAccess.java +16 −2
@@ -203,11 +203,25 @@
203203 void updateNodeConfig(int n, Map<String, Object> configs);
204204
205205 /**
206- * Sets the workload for the {@code nth} host in the CCM cluster.
206+ * Updates the {@code nth} host's dse config file in the CCM cluster.
207207 *
208208 * @param n the node number (starting from 1).
209209 */
210- void setWorkload(int n, Workload workload);
210+ void updateDSENodeConfig(int n, String key, Object value);
211+
212+ /**
213+ * Updates the {@code nth} host's dse config file in the CCM cluster.
214+ *
215+ * @param n the node number (starting from 1).
216+ */
217+ void updateDSENodeConfig(int n, Map<String, Object> configs);
218+
219+ /**
220+ * Sets the workload(s) for the {@code nth} host in the CCM cluster.
221+ *
222+ * @param n the node number (starting from 1).
223+ */
224+ void setWorkload(int n, Workload... workload);
211225
212226
213227 // Methods blocking until nodes are up or down
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +25 −6
@@ -537,8 +537,27 @@
537537 }
538538
539539 @Override
540- public void setWorkload(int node, Workload workload) {
541- execute(CCM_COMMAND + " node%d setworkload %s", node, workload);
540+ public void updateDSENodeConfig(int n, String key, Object value) {
541+ updateDSENodeConfig(n, ImmutableMap.<String, Object>builder().put(key, value).build());
542+ }
543+
544+ @Override
545+ public void updateDSENodeConfig(int n, Map<String, Object> configs) {
546+ StringBuilder confStr = new StringBuilder();
547+ for (Map.Entry<String, Object> entry : configs.entrySet()) {
548+ confStr
549+ .append(entry.getKey())
550+ .append(":")
551+ .append(entry.getValue())
552+ .append(" ");
553+ }
554+ execute(CCM_COMMAND + " node%s updatedseconf %s", n, confStr);
555+ }
556+
557+ @Override
558+ public void setWorkload(int node, Workload... workload) {
559+ String workloadStr = Joiner.on(",").join(workload);
560+ execute(CCM_COMMAND + " node%d setworkload %s", node, workloadStr);
542561 }
543562
544563 private String execute(String command, Object... args) {
@@ -673,7 +692,7 @@
673692 private Set<String> jvmArgs = new LinkedHashSet<String>();
674693 private final Map<String, Object> cassandraConfiguration = Maps.newLinkedHashMap();
675694 private final Map<String, Object> dseConfiguration = Maps.newLinkedHashMap();
676- private Map<Integer, Workload> workloads = new HashMap<Integer, Workload>();
695+ private Map<Integer, Workload[]> workloads = new HashMap<Integer, Workload[]>();
677696
678697 private Builder() {
679698 cassandraConfiguration.put("start_rpc", false);
@@ -804,10 +823,10 @@
804823 * Sets the DSE workload for a given node.
805824 *
806825 * @param node The node to set the workload for (starting with 1).
807- * @param workload The workload (e.g. solr, spark, hadoop)
826+ * @param workload The workload(s) (e.g. solr, spark, hadoop)
808827 * @return This builder
809828 */
810- public Builder withWorkload(int node, Workload workload) {
829+ public Builder withWorkload(int node, Workload... workload) {
811830 this.workloads.put(node, workload);
812831 return this;
813832 }
@@ -833,7 +852,7 @@
833852 ccm.updateConfig(cassandraConfiguration);
834853 if (!dseConfiguration.isEmpty())
835854 ccm.updateDSEConfig(dseConfiguration);
836- for (Map.Entry<Integer, Workload> entry : workloads.entrySet()) {
855+ for (Map.Entry<Integer, Workload[]> entry : workloads.entrySet()) {
837856 ccm.setWorkload(entry.getKey(), entry.getValue());
838857 }
839858 if (start)
modified driver-core/src/test/java/com/datastax/driver/core/CCMCache.java +11 −1
@@ -191,7 +191,17 @@
191191 }
192192
193193 @Override
194- public void setWorkload(int n, Workload workload) {
194+ public void updateDSENodeConfig(int n, String key, Object value) {
195+ ccm.updateDSENodeConfig(n, key, value);
196+ }
197+
198+ @Override
199+ public void updateDSENodeConfig(int n, Map<String, Object> configs) {
200+ ccm.updateDSENodeConfig(n, configs);
201+ }
202+
203+ @Override
204+ public void setWorkload(int n, Workload... workload) {
195205 ccm.setWorkload(n, workload);
196206 }
197207
modified driver-core/src/test/java/com/datastax/driver/core/CCMConfig.java +1 −1
@@ -135,7 +135,7 @@
135135 *
136136 * @return The workloads to assign to each node.
137137 */
138- CCMAccess.Workload[] workloads() default {};
138+ CCMWorkload[] workloads() default {};
139139
140140 /**
141141 * Returns {@code true} if a {@link CCMBridge} instance should be automatically created, {@code false} otherwise.
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +19 −8
@@ -213,7 +213,17 @@
213213 }
214214
215215 @Override
216- public void setWorkload(int node, Workload workload) {
216+ public void updateDSENodeConfig(int n, String key, Object value) {
217+ throw new UnsupportedOperationException("This CCM cluster is read-only");
218+ }
219+
220+ @Override
221+ public void updateDSENodeConfig(int n, Map<String, Object> configs) {
222+ throw new UnsupportedOperationException("This CCM cluster is read-only");
223+ }
224+
225+ @Override
226+ public void setWorkload(int node, Workload... workload) {
217227 throw new UnsupportedOperationException("This CCM cluster is read-only");
218228 }
219229
@@ -351,17 +361,17 @@
351361 return args;
352362 }
353363
354- private List<Workload> workloads() {
364+ private List<Workload[]> workloads() {
355365 int total = 0;
356366 for (int perDc : numberOfNodes())
357367 total += perDc;
358- List<Workload> workloads = new ArrayList<Workload>(Collections.<Workload>nCopies(total, null));
368+ List<Workload[]> workloads = new ArrayList<Workload[]>(Collections.<Workload[]>nCopies(total, null));
359369 for (int i = annotations.size() - 1; i >= 0; i--) {
360370 CCMConfig ann = annotations.get(i);
361- Workload[] annWorkloads = ann.workloads();
371+ CCMWorkload[] annWorkloads = ann.workloads();
362372 for (int j = 0; j < annWorkloads.length; j++) {
363- Workload workload = annWorkloads[j];
364- workloads.set(j, workload);
373+ CCMWorkload nodeWorkloads = annWorkloads[j];
374+ workloads.set(j, nodeWorkloads.value());
365375 }
366376 }
367377 return workloads;
@@ -438,9 +448,9 @@
438448 for (String arg : jvmArgs()) {
439449 ccmBuilder.withJvmArgs(arg);
440450 }
441- List<Workload> workloads = workloads();
451+ List<Workload[]> workloads = workloads();
442452 for (int i = 0; i < workloads.size(); i++) {
443- Workload workload = workloads.get(i);
453+ Workload[] workload = workloads.get(i);
444454 if (workload != null)
445455 ccmBuilder.withWorkload(i + 1, workload);
446456 }
@@ -758,6 +768,7 @@
758768 }
759769 }
760770 }
771+
761772 /**
762773 * Signals that the test has encountered an unexpected error.
763774 * <p/>
added driver-core/src/test/java/com/datastax/driver/core/CCMWorkload.java +37 −0
@@ -0,0 +1,37 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core;
17+
18+import java.lang.annotation.ElementType;
19+import java.lang.annotation.Retention;
20+import java.lang.annotation.RetentionPolicy;
21+import java.lang.annotation.Target;
22+
23+/**
24+ * A set of workloads to assign to a specific node.
25+ */
26+@Retention(RetentionPolicy.RUNTIME)
27+@Target(ElementType.ANNOTATION_TYPE)
28+public @interface CCMWorkload {
29+
30+ /**
31+ * The workloads to assign to a specific node.
32+ *
33+ * @return The workloads to assign to a specifc node.
34+ */
35+ CCMAccess.Workload[] value() default {};
36+
37+}
modified driver-core/src/test/java/com/datastax/driver/core/DseCCMClusterTest.java +13 −1
@@ -17,6 +17,8 @@
1717
1818 import org.testng.annotations.Test;
1919
20+import static com.datastax.driver.core.CCMAccess.Workload.*;
21+
2022 /**
2123 * A simple test to validate DSE setups.
2224 * <p/>
@@ -68,11 +70,21 @@
6870 * A correct example is as follows: {@code /usr/bin:/usr/local/bin:/bin:/usr/sbin:$JAVA_HOME/bin:$PATH}.
6971 */
7072 @Test(enabled = false)
71-@CCMConfig(dse = true, version = "4.8.3")
73+@CCMConfig(
74+ dse = true,
75+ numberOfNodes = 3,
76+ version = "4.8.3",
77+ workloads = {
78+ @CCMWorkload(solr),
79+ @CCMWorkload({spark, solr}),
80+ @CCMWorkload({cassandra, spark})
81+ }
82+)
7283 public class DseCCMClusterTest extends CCMTestsSupport {
7384
7485 @Test(groups = "short")
7586 public void should_conenct_to_dse() throws InterruptedException {
87+
7688 }
7789
7890 }