Skip to content

Commit

Permalink
Fixed compilation errors after refactoring in core Strings class (ope…
Browse files Browse the repository at this point in the history
…nsearch-project#243)

Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski authored and navneet1v committed Aug 17, 2023
1 parent 2098d54 commit e5cfab6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.junit.Assert;
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.rest.RestRequest;
Expand Down Expand Up @@ -62,21 +61,20 @@ public void testValidateMLPluginSetup() throws IOException {
}

private void createBasicKnnIndex() throws IOException {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(KNN_VECTOR_FIELD_NAME)
.field("type", "knn_vector")
.field("dimension", Integer.toString(3))
.startObject("method")
.field("engine", "lucene")
.field("name", "hnsw")
.endObject()
.endObject()
.endObject()
.endObject()
);
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(KNN_VECTOR_FIELD_NAME)
.field("type", "knn_vector")
.field("dimension", Integer.toString(3))
.startObject("method")
.field("engine", "lucene")
.field("name", "hnsw")
.endObject()
.endObject()
.endObject()
.endObject()
.toString();
mapping = mapping.substring(1, mapping.length() - 1);
createIndex(KNN_INDEX_NAME, Settings.EMPTY, mapping);
}
Expand All @@ -99,16 +97,15 @@ private Set<String> getAllInstalledPlugins() throws IOException {
}

private void indexDocument() throws IOException {
final String indexRequestBody = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startArray(KNN_VECTOR_FIELD_NAME)
.value(1.0)
.value(2.0)
.value(4.0)
.endArray()
.endObject()
);
final String indexRequestBody = XContentFactory.jsonBuilder()
.startObject()
.startArray(KNN_VECTOR_FIELD_NAME)
.value(1.0)
.value(2.0)
.value(4.0)
.endArray()
.endObject()
.toString();
final Request indexRequest = new Request(RestRequest.Method.POST.name(), KNN_DOCUMENT_URL);
indexRequest.setJsonEntity(indexRequestBody);
assertOK(client().performRequest(indexRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.client.Response;
import org.opensearch.client.RestClient;
import org.opensearch.client.WarningsHandler;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -82,7 +81,7 @@ protected void updateClusterSettings(String settingKey, Object value) {
"PUT",
"_cluster/settings",
null,
toHttpEntity(Strings.toString(builder)),
toHttpEntity(builder.toString()),
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, ""))
);

Expand Down Expand Up @@ -293,7 +292,7 @@ protected Map<String, Object> search(String index, QueryBuilder queryBuilder, Qu

Request request = new Request("POST", "/" + index + "/_search");
request.addParameter("size", Integer.toString(resultSize));
request.setJsonEntity(Strings.toString(builder));
request.setJsonEntity(builder.toString());

Response response = client().performRequest(request);
assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
Expand Down Expand Up @@ -345,7 +344,7 @@ protected void addKnnDoc(
}
builder.endObject();

request.setJsonEntity(Strings.toString(builder));
request.setJsonEntity(builder.toString());
Response response = client().performRequest(request);
assertEquals(request.getEndpoint() + ": failed", RestStatus.CREATED, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
}
Expand Down Expand Up @@ -441,7 +440,8 @@ private String buildIndexConfiguration(List<KNNFieldConfig> knnFieldConfigs) {
.endObject()
.endObject();
}
return Strings.toString(xContentBuilder.endObject().endObject().endObject());
xContentBuilder.endObject().endObject().endObject();
return xContentBuilder.toString();
}

protected static Response makeRequest(
Expand Down Expand Up @@ -508,7 +508,7 @@ private String registerModelGroup() throws IOException, URISyntaxException {
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana"))
);
Map<String, Object> modelGroupResJson = XContentHelper.convertToMap(
XContentFactory.xContent(XContentType.JSON),
XContentType.JSON.xContent(),
EntityUtils.toString(modelGroupResponse.getEntity()),
false
);
Expand Down

0 comments on commit e5cfab6

Please sign in to comment.