| 
12 | 12 | import com.carrotsearch.randomizedtesting.annotations.Name;  | 
13 | 13 | 
 
  | 
14 | 14 | import org.elasticsearch.client.Request;  | 
 | 15 | +import org.elasticsearch.client.Response;  | 
 | 16 | +import org.elasticsearch.client.ResponseException;  | 
 | 17 | +import org.elasticsearch.client.RestClient;  | 
15 | 18 | import org.elasticsearch.common.network.NetworkAddress;  | 
 | 19 | +import org.elasticsearch.common.xcontent.XContentHelper;  | 
16 | 20 | import org.elasticsearch.test.rest.ObjectPath;  | 
 | 21 | +import org.elasticsearch.xcontent.XContentType;  | 
17 | 22 | 
 
  | 
 | 23 | +import java.io.IOException;  | 
 | 24 | +import java.io.InputStream;  | 
18 | 25 | import java.time.Instant;  | 
 | 26 | +import java.util.List;  | 
19 | 27 | import java.util.Locale;  | 
20 | 28 | import java.util.Map;  | 
21 | 29 | 
 
  | 
22 |  | -import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.getWriteBackingIndex;  | 
23 |  | -import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.createTemplate;  | 
24 |  | -import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.getIndexSettingsWithDefaults;  | 
25 |  | -import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.startTrial;  | 
26 | 30 | import static org.elasticsearch.upgrades.TsdbIT.TEMPLATE;  | 
27 | 31 | import static org.elasticsearch.upgrades.TsdbIT.formatInstant;  | 
 | 32 | +import static org.hamcrest.Matchers.containsString;  | 
28 | 33 | import static org.hamcrest.Matchers.equalTo;  | 
29 | 34 | import static org.hamcrest.Matchers.greaterThan;  | 
30 | 35 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;  | 
@@ -194,4 +199,51 @@ void query(String dataStreamName) throws Exception {  | 
194 | 199 |         assertThat(maxTx, notNullValue());  | 
195 | 200 |     }  | 
196 | 201 | 
 
  | 
 | 202 | +    protected static void startTrial() throws IOException {  | 
 | 203 | +        Request startTrial = new Request("POST", "/_license/start_trial");  | 
 | 204 | +        startTrial.addParameter("acknowledge", "true");  | 
 | 205 | +        try {  | 
 | 206 | +            assertOK(client().performRequest(startTrial));  | 
 | 207 | +        } catch (ResponseException e) {  | 
 | 208 | +            var responseBody = entityAsMap(e.getResponse());  | 
 | 209 | +            String error = ObjectPath.evaluate(responseBody, "error_message");  | 
 | 210 | +            assertThat(error, containsString("Trial was already activated."));  | 
 | 211 | +        }  | 
 | 212 | +    }  | 
 | 213 | + | 
 | 214 | +    static Map<String, Object> getIndexSettingsWithDefaults(String index) throws IOException {  | 
 | 215 | +        Request request = new Request("GET", "/" + index + "/_settings");  | 
 | 216 | +        request.addParameter("flat_settings", "true");  | 
 | 217 | +        request.addParameter("include_defaults", "true");  | 
 | 218 | +        Response response = client().performRequest(request);  | 
 | 219 | +        try (InputStream is = response.getEntity().getContent()) {  | 
 | 220 | +            return XContentHelper.convertToMap(  | 
 | 221 | +                XContentType.fromMediaType(response.getEntity().getContentType().getValue()).xContent(),  | 
 | 222 | +                is,  | 
 | 223 | +                true  | 
 | 224 | +            );  | 
 | 225 | +        }  | 
 | 226 | +    }  | 
 | 227 | + | 
 | 228 | +    static void createTemplate(String dataStreamName, String id, String template) throws IOException {  | 
 | 229 | +        final String INDEX_TEMPLATE = """  | 
 | 230 | +            {  | 
 | 231 | +                "index_patterns": ["$DATASTREAM"],  | 
 | 232 | +                "template": $TEMPLATE,  | 
 | 233 | +                "data_stream": {  | 
 | 234 | +                }  | 
 | 235 | +            }""";  | 
 | 236 | +        var putIndexTemplateRequest = new Request("POST", "/_index_template/" + id);  | 
 | 237 | +        putIndexTemplateRequest.setJsonEntity(INDEX_TEMPLATE.replace("$TEMPLATE", template).replace("$DATASTREAM", dataStreamName));  | 
 | 238 | +        assertOK(client().performRequest(putIndexTemplateRequest));  | 
 | 239 | +    }  | 
 | 240 | + | 
 | 241 | +    @SuppressWarnings("unchecked")  | 
 | 242 | +    static String getWriteBackingIndex(final RestClient client, final String dataStreamName, int backingIndex) throws IOException {  | 
 | 243 | +        final Request request = new Request("GET", "_data_stream/" + dataStreamName);  | 
 | 244 | +        final List<Object> dataStreams = (List<Object>) entityAsMap(client.performRequest(request)).get("data_streams");  | 
 | 245 | +        final Map<String, Object> dataStream = (Map<String, Object>) dataStreams.get(0);  | 
 | 246 | +        final List<Map<String, String>> backingIndices = (List<Map<String, String>>) dataStream.get("indices");  | 
 | 247 | +        return backingIndices.get(backingIndex).get("index_name");  | 
 | 248 | +    }  | 
197 | 249 | }  | 
0 commit comments