Skip to content

Commit

Permalink
Remove unecessary KNN code
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Dec 27, 2023
1 parent d6d7f9b commit 20ec55f
Showing 1 changed file with 0 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_PER_ROUTE;
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_TOTAL;
import static org.opensearch.knn.common.KNNConstants.MODELS;
import static org.opensearch.knn.common.KNNConstants.MODEL_INDEX_NAME;
import static org.opensearch.neuralsearch.TestUtils.NEURAL_SEARCH_BWC_PREFIX;
import static org.opensearch.neuralsearch.TestUtils.OPENDISTRO_SECURITY;
Expand All @@ -16,7 +15,6 @@
import static org.opensearch.neuralsearch.TestUtils.SKIP_DELETE_MODEL_INDEX;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -34,30 +32,22 @@
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.util.Timeout;
import org.junit.After;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.knn.plugin.KNNPlugin;
import org.opensearch.search.SearchHit;
import org.opensearch.test.rest.OpenSearchRestTestCase;

/**
Expand Down Expand Up @@ -198,55 +188,13 @@ public void deleteExternalIndices() throws IOException, ParseException {
.collect(Collectors.toList());

for (final String indexName : externalIndices) {
if (isIndexCleanupRequired(indexName)) {
wipeIndexContent(indexName);
continue;
}
if (!skipDeleteIndex(indexName)) {
adminClient().performRequest(new Request("DELETE", "/" + indexName));
}
}
}
}

private boolean isIndexCleanupRequired(final String index) {
return MODEL_INDEX_NAME.equals(index) && !getSkipDeleteModelIndexFlag();
}

private void wipeIndexContent(String indexName) throws IOException, ParseException {
deleteAllDocs(indexName);
}

private List<String> getModelIds() throws IOException, ParseException {
final String restURIGetModels = String.join("/", KNNPlugin.KNN_BASE_URI, MODELS, "_search");
final Response response = adminClient().performRequest(new Request("GET", restURIGetModels));

assertEquals(RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));

final String responseBody = EntityUtils.toString(response.getEntity());
assertNotNull(responseBody);

final XContentParser parser = createParser(MediaTypeRegistry.getDefaultMediaType().xContent(), responseBody);
final SearchResponse searchResponse = SearchResponse.fromXContent(parser);

return Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId).collect(Collectors.toList());
}

private void deleteAllDocs(final String indexName) throws IOException {
final String restURIDeleteByQuery = String.join("/", indexName, "_delete_by_query");
final Request request = new Request("POST", restURIDeleteByQuery);
final XContentBuilder matchAllDocsQuery = XContentFactory.jsonBuilder()
.startObject()
.startObject("query")
.startObject("match_all")
.endObject()
.endObject()
.endObject();

request.setJsonEntity(matchAllDocsQuery.toString());
adminClient().performRequest(request);
}

private boolean getSkipDeleteModelIndexFlag() {
return Boolean.parseBoolean(System.getProperty(SKIP_DELETE_MODEL_INDEX, "false"));
}
Expand Down

0 comments on commit 20ec55f

Please sign in to comment.