Skip to content

Commit 00b09c5

Browse files
committed
QA: Check rollup job creation safety
Prior to elastic#30963 you could create a rollup job that would poison the cluster state for nodes that don't have xpack installed. This adds a test that would have caught that.
1 parent 7d955f8 commit 00b09c5

File tree

1 file changed

+71
-4
lines changed
  • qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades

1 file changed

+71
-4
lines changed

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/XPackIT.java

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
import org.junit.Before;
2727
import org.elasticsearch.Version;
2828
import org.elasticsearch.client.Request;
29+
import org.elasticsearch.client.ResponseException;
2930

3031
import java.io.IOException;
3132
import java.util.ArrayList;
3233
import java.util.Collections;
3334
import java.util.List;
3435
import java.util.Map;
3536

37+
import static org.hamcrest.Matchers.anyOf;
38+
import static org.hamcrest.Matchers.containsString;
3639
import static org.hamcrest.Matchers.equalTo;
3740
import static org.hamcrest.Matchers.hasSize;
3841
import static org.junit.Assume.assumeThat;
@@ -42,6 +45,11 @@
4245
* cluster is the on the "zip" distribution.
4346
*/
4447
public class XPackIT extends AbstractRollingTestCase {
48+
private static final Version UPGRADE_FROM_VERSION =
49+
Version.fromString(System.getProperty("tests.upgrade_from_version"));
50+
private static final boolean UPGRADE_FROM_VERSION_HAS_XPACK =
51+
UPGRADE_FROM_VERSION.onOrAfter(Version.V_6_3_0);
52+
4553
@Before
4654
public void skipIfNotZip() {
4755
assumeThat("test is only supported if the distribution contains xpack",
@@ -68,11 +76,8 @@ public void skipIfNotZip() {
6876
* system.
6977
*/
7078
public void testIndexTemplatesCreated() throws Exception {
71-
Version upgradeFromVersion =
72-
Version.fromString(System.getProperty("tests.upgrade_from_version"));
73-
boolean upgradeFromVersionHasXPack = upgradeFromVersion.onOrAfter(Version.V_6_3_0);
7479
assumeFalse("this test doesn't really prove anything if the starting version has xpack and it is *much* more complex to maintain",
75-
upgradeFromVersionHasXPack);
80+
UPGRADE_FROM_VERSION_HAS_XPACK);
7681
assumeFalse("since we're upgrading from a version without x-pack it won't have any templates",
7782
CLUSTER_TYPE == ClusterType.OLD);
7883

@@ -193,6 +198,68 @@ public void testTrialLicense() throws IOException {
193198
client().performRequest(createJob);
194199
}
195200

201+
/**
202+
* Attempts to create a rollup job and validates that the right
203+
* thing happens. If all nodes don't have xpack then it should
204+
* fail, either with a "I don't support this API" message or a
205+
* "the following nodes aren't ready". If all the nodes has xpack
206+
* then it should just work. This would catch issues where rollup
207+
* would pollute the cluster state with its job that the non-xpack
208+
* nodes couldn't understand.
209+
*/
210+
public void testCreateRollup() throws IOException {
211+
// Rollup validates its input on job creation so lets make an index for it
212+
Request indexInputDoc = new Request("POST", "/rollup_test_input_1/doc/");
213+
indexInputDoc.setJsonEntity(
214+
"{\n"
215+
+ " \"timestamp\":\"2018-01-01T00:00:00\",\n"
216+
+ " \"node\": \"node1\",\n"
217+
+ " \"voltage\": 12.6\n"
218+
+ "}");
219+
client().performRequest(indexInputDoc);
220+
221+
// Actually attempt the rollup and catch the errors if there should be any
222+
Request createJob = new Request("PUT", "/_xpack/rollup/job/" + System.nanoTime());
223+
createJob.setJsonEntity(
224+
"{\n"
225+
+ " \"index_pattern\" : \"rollup_test_input_*\",\n"
226+
+ " \"rollup_index\": \"rollup_test_output\",\n"
227+
+ " \"cron\": \"*/30 * * * * ?\",\n"
228+
+ " \"page_size\": 1000,\n"
229+
+ " \"groups\": {\n"
230+
+ " \"date_histogram\": {\n"
231+
+ " \"field\": \"timestamp\",\n"
232+
+ " \"interval\": \"1h\",\n"
233+
+ " \"delay\": \"7d\"\n"
234+
+ " },\n"
235+
+ " \"terms\": {\n"
236+
+ " \"fields\": [\"node.keyword\"]\n"
237+
+ " }\n"
238+
+ " },\n"
239+
+ " \"metrics\": [\n"
240+
+ " {\"field\": \"voltage\", \"metrics\": [\"avg\"]}\n"
241+
+ " ]\n"
242+
+ "}\n");
243+
if (UPGRADE_FROM_VERSION_HAS_XPACK || CLUSTER_TYPE == ClusterType.UPGRADED) {
244+
client().performRequest(createJob);
245+
} else {
246+
ResponseException e = expectThrows(ResponseException.class, () ->
247+
client().performRequest(createJob));
248+
assertThat(e.getMessage(), anyOf(
249+
// Request landed on a node without xpack
250+
containsString("No handler found for uri"),
251+
// Request landed on a node *with* xpack but the master doesn't have it
252+
containsString("No handler for action"),
253+
// Request landed on a node *with* xpack and the master has it but other nodes do not
254+
containsString("The following nodes are not ready yet for enabling x-pack custom metadata")));
255+
}
256+
257+
// Whether or not there are errors we should be able to modify the cluster state
258+
Request createIndex = new Request("PUT", "/test_index" + System.nanoTime());
259+
client().performRequest(createIndex);
260+
client().performRequest(new Request("DELETE", createIndex.getEndpoint()));
261+
}
262+
196263
/**
197264
* Has the master been upgraded to the new version?
198265
*/

0 commit comments

Comments
 (0)