Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
remove historical detector related test code
Browse files Browse the repository at this point in the history
  • Loading branch information
ylwu-amzn committed Mar 4, 2021
1 parent cfba67f commit 1d88cb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

package com.amazon.opendistroforelasticsearch.ad;

import static org.apache.http.entity.ContentType.APPLICATION_JSON;
import static org.elasticsearch.cluster.node.DiscoveryNodeRole.BUILT_IN_ROLES;
import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength;
import static org.elasticsearch.test.ESTestCase.randomBoolean;
import static org.elasticsearch.test.ESTestCase.randomDouble;
import static org.elasticsearch.test.ESTestCase.randomInt;
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
Expand All @@ -44,7 +46,7 @@

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -53,11 +55,13 @@
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
Expand Down Expand Up @@ -109,7 +113,6 @@

import com.amazon.opendistroforelasticsearch.ad.constant.CommonName;
import com.amazon.opendistroforelasticsearch.ad.constant.CommonValue;

import com.amazon.opendistroforelasticsearch.ad.feature.Features;
import com.amazon.opendistroforelasticsearch.ad.ml.ThresholdingResult;
import com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector;
Expand Down Expand Up @@ -144,7 +147,7 @@ public static Response makeRequest(
String jsonEntity,
List<Header> headers
) throws IOException {
HttpEntity httpEntity = Strings.isBlank(jsonEntity) ? null : new NStringEntity(jsonEntity, ContentType.APPLICATION_JSON);
HttpEntity httpEntity = Strings.isBlank(jsonEntity) ? null : new NStringEntity(jsonEntity, APPLICATION_JSON);
return makeRequest(client, method, endpoint, params, httpEntity, headers);
}

Expand Down Expand Up @@ -220,35 +223,12 @@ public static AnomalyDetector randomAnomalyDetector(Map<String, Object> uiMetada

public static AnomalyDetector randomAnomalyDetector(List<Feature> features, Map<String, Object> uiMetadata, Instant lastUpdateTime)
throws IOException {
return randomAnomalyDetector(features, uiMetadata, lastUpdateTime, null, null);
}

public static AnomalyDetector randomAnomalyDetector(
List<Feature> features,
Map<String, Object> uiMetadata,
Instant lastUpdateTime,
String detectorType,
DetectionDateRange dateRange
) throws IOException {
return randomAnomalyDetector(features, uiMetadata, lastUpdateTime, detectorType, dateRange, true);
}

public static AnomalyDetector randomAnomalyDetector(
List<Feature> features,
Map<String, Object> uiMetadata,
Instant lastUpdateTime,
String detectorType,
DetectionDateRange dateRange,
boolean withUser
) throws IOException {
return randomAnomalyDetector(
ImmutableList.of(randomAlphaOfLength(10).toLowerCase()),
features,
uiMetadata,
lastUpdateTime,
detectorType,
dateRange,
withUser
randomBoolean()
);
}

Expand All @@ -257,8 +237,6 @@ public static AnomalyDetector randomAnomalyDetector(
List<Feature> features,
Map<String, Object> uiMetadata,
Instant lastUpdateTime,
String detectorType,
DetectionDateRange dateRange,
boolean withUser
) throws IOException {
User user = withUser ? randomUser() : null;
Expand Down Expand Up @@ -685,6 +663,11 @@ public static void createIndex(RestClient client, String indexName, HttpEntity d
);
}

public static CreateIndexResponse createIndex(AdminClient adminClient, String indexName, String indexMapping) {
CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(AnomalyDetector.TYPE, indexMapping, XContentType.JSON);
return adminClient.indices().create(request).actionGet(5_000);
}

public static GetResponse createGetResponse(ToXContentObject o, String id, String indexName) throws IOException {
XContentBuilder content = o.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS);
return new GetResponse(
Expand Down
Loading

0 comments on commit 1d88cb4

Please sign in to comment.