2828import org .elasticsearch .common .xcontent .json .JsonXContent ;
2929import org .junit .Before ;
3030import org .elasticsearch .Version ;
31+ import org .elasticsearch .client .ResponseException ;
3132
3233import java .io .IOException ;
3334import java .util .ArrayList ;
3435import java .util .Collections ;
3536import java .util .List ;
3637import java .util .Map ;
3738
39+ import static org .hamcrest .Matchers .anyOf ;
40+ import static org .hamcrest .Matchers .containsString ;
3841import static org .hamcrest .Matchers .equalTo ;
3942import static org .hamcrest .Matchers .hasSize ;
4043import static org .junit .Assume .assumeThat ;
4649 * cluster is the on the "zip" distribution.
4750 */
4851public class XPackIT extends AbstractRollingTestCase {
52+ private static final Version UPGRADE_FROM_VERSION =
53+ Version .fromString (System .getProperty ("tests.upgrade_from_version" ));
54+ private static final boolean UPGRADE_FROM_VERSION_HAS_XPACK =
55+ UPGRADE_FROM_VERSION .onOrAfter (Version .V_6_3_0 );
56+
4957 @ Before
5058 public void skipIfNotZip () {
5159 assumeThat ("test is only supported if the distribution contains xpack" ,
@@ -72,11 +80,8 @@ public void skipIfNotZip() {
7280 * system.
7381 */
7482 public void testIndexTemplatesCreated () throws Exception {
75- Version upgradeFromVersion =
76- Version .fromString (System .getProperty ("tests.upgrade_from_version" ));
77- boolean upgradeFromVersionHasXPack = upgradeFromVersion .onOrAfter (Version .V_6_3_0 );
7883 assumeFalse ("this test doesn't really prove anything if the starting version has xpack and it is *much* more complex to maintain" ,
79- upgradeFromVersionHasXPack );
84+ UPGRADE_FROM_VERSION_HAS_XPACK );
8085 assumeFalse ("since we're upgrading from a version without x-pack it won't have any templates" ,
8186 CLUSTER_TYPE == ClusterType .OLD );
8287
@@ -194,6 +199,66 @@ public void testTrialLicense() throws IOException {
194199 client ().performRequest ("PUT" , "/_xpack/ml/anomaly_detectors/test_job" , emptyMap (), createJob );
195200 }
196201
202+ /**
203+ * Attempts to create a rollup job and validates that the right
204+ * thing happens. If all nodes don't have xpack then it should
205+ * fail, either with a "I don't support this API" message or a
206+ * "the following nodes aren't ready". If all the nodes has xpack
207+ * then it should just work. This would catch issues where rollup
208+ * would pollute the cluster state with its job that the non-xpack
209+ * nodes couldn't understand.
210+ */
211+ public void testCreateRollup () throws IOException {
212+ // Rollup validates its input on job creation so lets make an index for it
213+ HttpEntity indexInputDoc = new NStringEntity (
214+ "{\n "
215+ + " \" timestamp\" :\" 2018-01-01T00:00:00\" ,\n "
216+ + " \" node\" : \" node1\" ,\n "
217+ + " \" voltage\" : 12.6\n "
218+ + "}" , ContentType .APPLICATION_JSON );
219+ client ().performRequest ("POST" , "/rollup_test_input_1/doc/" , emptyMap (), indexInputDoc );
220+
221+ // Actually attempt the rollup and catch the errors if there should be any
222+ HttpEntity createJob = new NStringEntity (
223+ "{\n "
224+ + " \" index_pattern\" : \" rollup_test_input_*\" ,\n "
225+ + " \" rollup_index\" : \" rollup_test_output\" ,\n "
226+ + " \" cron\" : \" */30 * * * * ?\" ,\n "
227+ + " \" page_size\" : 1000,\n "
228+ + " \" groups\" : {\n "
229+ + " \" date_histogram\" : {\n "
230+ + " \" field\" : \" timestamp\" ,\n "
231+ + " \" interval\" : \" 1h\" ,\n "
232+ + " \" delay\" : \" 7d\" \n "
233+ + " },\n "
234+ + " \" terms\" : {\n "
235+ + " \" fields\" : [\" node.keyword\" ]\n "
236+ + " }\n "
237+ + " },\n "
238+ + " \" metrics\" : [\n "
239+ + " {\" field\" : \" voltage\" , \" metrics\" : [\" avg\" ]}\n "
240+ + " ]\n "
241+ + "}\n " , ContentType .APPLICATION_JSON );
242+ if (UPGRADE_FROM_VERSION_HAS_XPACK || CLUSTER_TYPE == ClusterType .UPGRADED ) {
243+ client ().performRequest ("PUT" , "/_xpack/rollup/job/" + System .nanoTime (), emptyMap (), createJob );
244+ } else {
245+ ResponseException e = expectThrows (ResponseException .class , () ->
246+ client ().performRequest ("PUT" , "/_xpack/rollup/job/" + System .nanoTime (), emptyMap (), createJob ));
247+ assertThat (e .getMessage (), anyOf (
248+ // Request landed on a node without xpack
249+ containsString ("No handler found for uri" ),
250+ // Request landed on a node *with* xpack but the master doesn't have it
251+ containsString ("No handler for action" ),
252+ // Request landed on a node *with* xpack and the master has it but other nodes do not
253+ containsString ("The following nodes are not ready yet for enabling x-pack custom metadata" )));
254+ }
255+
256+ // Whether or not there are errors we should be able to modify the cluster state
257+ String testIndex = "/test_index" + System .nanoTime ();
258+ client ().performRequest ("PUT" , testIndex );
259+ client ().performRequest ("DELETE" , testIndex );
260+ }
261+
197262 /**
198263 * Has the master been upgraded to the new version?
199264 */
0 commit comments