Skip to content

Commit

Permalink
Resolve various backporting issues
Browse files Browse the repository at this point in the history
1. Can't reference version 3.0.0.
2. Bad merges of adjacent version checks.
3. Use of Apache HTTP client 4 (vs 5).
4. Use of old cluster manager naming in REST params.
5. CollectionUtils didn't have isEmpty for collections.

Signed-off-by: Michael Froh <froh@amazon.com>
  • Loading branch information
msfroh committed Apr 10, 2023
1 parent a6c16d5 commit 744d5f9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

package org.opensearch.client;

import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.opensearch.action.search.DeleteSearchPipelineRequest;
import org.opensearch.action.search.GetSearchPipelineRequest;
import org.opensearch.action.search.PutSearchPipelineRequest;
Expand All @@ -28,7 +28,7 @@ static Request putPipeline(PutSearchPipelineRequest putPipelineRequest) throws I

RequestConverters.Params params = new RequestConverters.Params();
params.withTimeout(putPipelineRequest.timeout());
params.withClusterManagerTimeout(putPipelineRequest.clusterManagerNodeTimeout());
params.withMasterTimeout(putPipelineRequest.clusterManagerNodeTimeout());
request.addParameters(params.asMap());
request.setEntity(RequestConverters.createEntity(putPipelineRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
Expand All @@ -42,7 +42,7 @@ static Request deletePipeline(DeleteSearchPipelineRequest deletePipelineRequest)

RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withTimeout(deletePipelineRequest.timeout());
parameters.withClusterManagerTimeout(deletePipelineRequest.clusterManagerNodeTimeout());
parameters.withMasterTimeout(deletePipelineRequest.clusterManagerNodeTimeout());
request.addParameters(parameters.asMap());
return request;
}
Expand All @@ -54,7 +54,7 @@ static Request getPipeline(GetSearchPipelineRequest getPipelineRequest) {
Request request = new Request(HttpGet.METHOD_NAME, endpoint);

RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withClusterManagerTimeout(getPipelineRequest.clusterManagerNodeTimeout());
parameters.withMasterTimeout(getPipelineRequest.clusterManagerNodeTimeout());
request.addParameters(parameters.asMap());
return request;
}
Expand Down
8 changes: 2 additions & 6 deletions server/src/main/java/org/opensearch/OpenSearchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import static org.opensearch.Version.V_2_4_0;
import static org.opensearch.Version.V_2_5_0;
import static org.opensearch.Version.V_2_6_0;
import static org.opensearch.Version.V_2_7_0;
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_UUID_NA_VALUE;
import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.opensearch.common.xcontent.XContentParserUtils.ensureFieldName;
Expand Down Expand Up @@ -1658,12 +1659,7 @@ private enum OpenSearchExceptionHandle {
V_2_6_0
),
NODE_WEIGHED_AWAY_EXCEPTION(NodeWeighedAwayException.class, NodeWeighedAwayException::new, 169, V_2_6_0),
SEARCH_PIPELINE_PROCESSING_EXCEPTION(
SearchPipelineProcessingException.class,
SearchPipelineProcessingException::new,
170,
V_3_0_0 // TODO: Update if/when we backport to 2.x
),
SEARCH_PIPELINE_PROCESSING_EXCEPTION(SearchPipelineProcessingException.class, SearchPipelineProcessingException::new, 170, V_2_7_0),
INDEX_CREATE_BLOCK_EXCEPTION(
org.opensearch.cluster.block.IndexCreateBlockException.class,
org.opensearch.cluster.block.IndexCreateBlockException::new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public NodeInfo(StreamInput in) throws IOException {
addInfoIfNonNull(IngestInfo.class, in.readOptionalWriteable(IngestInfo::new));
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
addInfoIfNonNull(AggregationInfo.class, in.readOptionalWriteable(AggregationInfo::new));
if (in.getVersion().onOrAfter(Version.V_3_0_0)) { // TODO: Change if/when we backport to 2.x
addInfoIfNonNull(SearchPipelineInfo.class, in.readOptionalWriteable(SearchPipelineInfo::new));
}
if (in.getVersion().onOrAfter(Version.V_2_7_0)) {
addInfoIfNonNull(SearchPipelineInfo.class, in.readOptionalWriteable(SearchPipelineInfo::new));
}
}

Expand Down Expand Up @@ -232,10 +232,11 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(getInfo(IngestInfo.class));
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
out.writeOptionalWriteable(getInfo(AggregationInfo.class));
if (out.getVersion().onOrAfter(Version.V_3_0_0)) { // TODO: Change if/when we backport to 2.x
out.writeOptionalWriteable(getInfo(SearchPipelineInfo.class));
}
if (out.getVersion().onOrAfter(Version.V_2_7_0)) {
out.writeOptionalWriteable(getInfo(SearchPipelineInfo.class));
}
}

public static NodeInfo.Builder builder(Version version, Build build, DiscoveryNode node) {
return new Builder(version, build, node);
Expand Down Expand Up @@ -349,6 +350,4 @@ public NodeInfo build() {
}

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ public SearchRequest(StreamInput in) throws IOException {

if (in.getVersion().onOrAfter(Version.V_1_1_0)) {
cancelAfterTimeInterval = in.readOptionalTimeValue();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) { // TODO: Update if/when we backport to 2.x
pipeline = in.readOptionalString();
}
if (in.getVersion().onOrAfter(Version.V_2_7_0)) {
pipeline = in.readOptionalString();
}
}

Expand Down Expand Up @@ -299,9 +299,9 @@ public void writeTo(StreamOutput out) throws IOException {

if (out.getVersion().onOrAfter(Version.V_1_1_0)) {
out.writeOptionalTimeValue(cancelAfterTimeInterval);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) { // TODO: Update if/when we backport to 2.x
out.writeOptionalString(pipeline);
}
if (out.getVersion().onOrAfter(Version.V_2_7_0)) {
out.writeOptionalString(pipeline);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,16 @@ public static <E> List<List<E>> eagerPartition(List<E> list, int size) {

return result;
}

/**
* Check if a collection is empty or not. Empty collection mean either it is null or it has no elements in it. If
* collection contains a null element it means it is not empty.
*
* @param collection {@link Collection}
* @return boolean
* @param <E> Element
*/
public static <E> boolean isEmpty(final Collection<E> collection) {
return collection == null || collection.isEmpty();
}
}

0 comments on commit 744d5f9

Please sign in to comment.