Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[Backport] [2.x] Restore support for Java 8 (#767)" #796

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/test-integration-unreleased.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
- { opensearch_ref: '1.x', java: 11 }
- { opensearch_ref: '2.x', java: 11 }
- { opensearch_ref: '2.x', java: 17 }
- { opensearch_ref: '2.x', java: 21 }
- { opensearch_ref: 'main', java: 11 }
- { opensearch_ref: 'main', java: 17 }
- { opensearch_ref: 'main', java: 21 }
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Bumps `org.apache.httpcomponents.client5:httpclient5` from 5.2.1 to 5.3

### Changed
- Restore support for Java 8 ([#767](https://github.com/opensearch-project/opensearch-java/pull/767))

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The below matrix shows the compatibility of the [`opensearch-java-client`](https
| Client Version | JDK |
|----------------|--------------------|
| 1.0.0 | 8 |
| 2.x.0 | 8 / 11 / 17 / 21 |
| 2.x.0 | 11 / 17 / 21 |

## Upgrading

Expand Down
46 changes: 3 additions & 43 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ configurations {
}

java {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11

withJavadocJar()
withSourcesJar()
Expand Down Expand Up @@ -146,20 +146,15 @@ val integrationTest = task<Test>("integrationTest") {
System.getProperty("tests.awsSdk2support.domainRegion", "us-east-1"))
}

val opensearchVersion = "2.12.0-SNAPSHOT"

dependencies {

val opensearchVersion = "2.7.0"
val jacksonVersion = "2.15.2"
val jacksonDatabindVersion = "2.15.2"

// Apache 2.0
implementation("org.opensearch.client", "opensearch-rest-client", opensearchVersion)
testImplementation("org.opensearch.test", "framework", opensearchVersion)
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.8.1") {
exclude(group = "junit")
}

// Apache 2.0
// https://search.maven.org/artifact/com.google.code.findbugs/jsr305
Expand Down Expand Up @@ -332,38 +327,3 @@ publishing {
}
}
}

if (JavaVersion.current() >= JavaVersion.VERSION_11) {
val java11: SourceSet = sourceSets.create("java11") {
java {
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output
srcDir("src/test/java11")
}
}

configurations[java11.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
configurations[java11.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get())

dependencies {
testImplementation("org.opensearch.test", "framework", opensearchVersion) {
exclude(group = "org.hamcrest")
}
}

tasks.named<JavaCompile>("compileJava11Java") {
targetCompatibility = JavaVersion.VERSION_11.toString()
sourceCompatibility = JavaVersion.VERSION_11.toString()
}

tasks.named<JavaCompile>("compileTestJava") {
targetCompatibility = JavaVersion.VERSION_11.toString()
sourceCompatibility = JavaVersion.VERSION_11.toString()
}

tasks.test {
testClassesDirs += java11.output.classesDirs
classpath = sourceSets["java11"].runtimeClasspath
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public CatRequestBase(CatRequestBaseBuilder<?> builder) {

protected final Map<String, String> queryParameters() {
Map<String, String> params = new HashMap<>();
if (headers != null && !headers.trim().isEmpty()) {
if (headers != null && !headers.isBlank()) {
params.put("h", headers);
}
if (sort != null && !sort.trim().isEmpty()) {
if (sort != null && !sort.isBlank()) {
params.put("s", sort);
}
params.put("format", "json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.client.transport;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -99,7 +98,7 @@ public Builder addHeader(String name, String value) {
if (headers.isEmpty()) {
headers = new ArrayList<>();
}
headers.add(new AbstractMap.SimpleEntry<>(name, value));
headers.add(Map.entry(name, value));
return this;
}

Expand Down Expand Up @@ -136,8 +135,8 @@ class DefaultImpl implements TransportOptions {
private final Function<List<String>, Boolean> onWarnings;

protected DefaultImpl(BuilderImpl builder) {
this.headers = builder.headers.isEmpty() ? Collections.emptyList() : new ArrayList<>(builder.headers);
this.params = builder.queryParameters.isEmpty() ? Collections.emptyMap() : new HashMap<>(builder.queryParameters);
this.headers = builder.headers.isEmpty() ? Collections.emptyList() : List.copyOf(builder.headers);
this.params = builder.queryParameters.isEmpty() ? Collections.emptyMap() : Map.copyOf(builder.queryParameters);
this.onWarnings = builder.onWarnings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
import java.util.zip.GZIPInputStream;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -262,12 +261,11 @@ private <RequestT> OpenSearchRequestBodyBuffer prepareRequestBody(
.map(o -> o instanceof AwsSdk2TransportOptions ? ((AwsSdk2TransportOptions) o) : null)
.map(AwsSdk2TransportOptions::mapper)
.orElse(defaultMapper);
final int maxUncompressedSize = or(
Optional.ofNullable(options)
.map(o -> o instanceof AwsSdk2TransportOptions ? ((AwsSdk2TransportOptions) o) : null)
.map(AwsSdk2TransportOptions::requestCompressionSize),
() -> Optional.ofNullable(transportOptions.requestCompressionSize())
).orElse(DEFAULT_REQUEST_COMPRESSION_SIZE);
final int maxUncompressedSize = Optional.ofNullable(options)
.map(o -> o instanceof AwsSdk2TransportOptions ? ((AwsSdk2TransportOptions) o) : null)
.map(AwsSdk2TransportOptions::requestCompressionSize)
.or(() -> Optional.ofNullable(transportOptions.requestCompressionSize()))
.orElse(DEFAULT_REQUEST_COMPRESSION_SIZE);

OpenSearchRequestBodyBuffer buffer = new OpenSearchRequestBodyBuffer(mapper, maxUncompressedSize);
buffer.addContent(request);
Expand All @@ -282,7 +280,7 @@ private <RequestT> SdkHttpFullRequest prepareRequest(
Endpoint<RequestT, ?, ?> endpoint,
@CheckForNull TransportOptions options,
@CheckForNull OpenSearchRequestBodyBuffer body
) throws UnsupportedEncodingException {
) {
SdkHttpFullRequest.Builder req = SdkHttpFullRequest.builder().method(SdkHttpMethod.fromValue(endpoint.method(request)));

StringBuilder url = new StringBuilder();
Expand All @@ -295,9 +293,9 @@ private <RequestT> SdkHttpFullRequest prepareRequest(
Map<String, String> params = endpoint.queryParameters(request);
if (params != null && !params.isEmpty()) {
char sep = '?';
for (Map.Entry<String, String> ent : params.entrySet()) {
for (var ent : params.entrySet()) {
url.append(sep).append(ent.getKey()).append('=');
url.append(URLEncoder.encode(ent.getValue(), "UTF-8"));
url.append(URLEncoder.encode(ent.getValue(), StandardCharsets.UTF_8));
sep = '&';
}
}
Expand All @@ -323,24 +321,22 @@ private <RequestT> SdkHttpFullRequest prepareRequest(
req.putHeader("x-amz-content-sha256", "required");
}

boolean responseCompression = or(
Optional.ofNullable(options)
.map(o -> o instanceof AwsSdk2TransportOptions ? ((AwsSdk2TransportOptions) o) : null)
.map(AwsSdk2TransportOptions::responseCompression),
() -> Optional.ofNullable(transportOptions.responseCompression())
).orElse(Boolean.TRUE);
boolean responseCompression = Optional.ofNullable(options)
.map(o -> o instanceof AwsSdk2TransportOptions ? ((AwsSdk2TransportOptions) o) : null)
.map(AwsSdk2TransportOptions::responseCompression)
.or(() -> Optional.ofNullable(transportOptions.responseCompression()))
.orElse(Boolean.TRUE);
if (responseCompression) {
req.putHeader("Accept-Encoding", "gzip");
} else {
req.removeHeader("Accept-Encoding");
}

final AwsCredentialsProvider credentials = or(
Optional.ofNullable(options)
.map(o -> o instanceof AwsSdk2TransportOptions ? ((AwsSdk2TransportOptions) o) : null)
.map(AwsSdk2TransportOptions::credentials),
() -> Optional.ofNullable(transportOptions.credentials())
).orElse(DefaultCredentialsProvider.create());
final AwsCredentialsProvider credentials = Optional.ofNullable(options)
.map(o -> o instanceof AwsSdk2TransportOptions ? ((AwsSdk2TransportOptions) o) : null)
.map(AwsSdk2TransportOptions::credentials)
.or(() -> Optional.ofNullable(transportOptions.credentials()))
.orElse(DefaultCredentialsProvider.create());

Aws4SignerParams signerParams = Aws4SignerParams.builder()
.awsCredentials(credentials.resolveCredentials())
Expand All @@ -350,7 +346,7 @@ private <RequestT> SdkHttpFullRequest prepareRequest(
return Aws4Signer.create().sign(req.build(), signerParams);
}

private void applyOptionsParams(StringBuilder url, TransportOptions options) throws UnsupportedEncodingException {
private void applyOptionsParams(StringBuilder url, TransportOptions options) {
if (options == null) {
return;
}
Expand All @@ -359,7 +355,7 @@ private void applyOptionsParams(StringBuilder url, TransportOptions options) thr
char sep = url.indexOf("?") < 0 ? '?' : '&';
for (Map.Entry<String, String> param : params.entrySet()) {
url.append(sep).append(param.getKey()).append('=');
url.append(URLEncoder.encode(param.getValue(), "UTF-8"));
url.append(URLEncoder.encode(param.getValue(), StandardCharsets.UTF_8));
sep = '?';
}
}
Expand Down Expand Up @@ -528,16 +524,4 @@ private <ResponseT, ErrorT> ResponseT parseResponse(
}
}
}

private static <T> Optional<T> or(Optional<T> opt, Supplier<? extends Optional<? extends T>> supplier) {
Objects.requireNonNull(opt);
Objects.requireNonNull(supplier);
if (opt.isPresent()) {
return opt;
} else {
@SuppressWarnings("unchecked")
Optional<T> r = (Optional<T>) supplier.get();
return Objects.requireNonNull(r);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -932,15 +932,9 @@ public long getContentLength() {
if (chunkedEnabled.get()) {
return -1L;
} else {
long size = 0;
final byte[] buf = new byte[8192];
int nread = 0;

long size;
try (InputStream is = getContent()) {
// read to EOF which may read more or less than buffer size
while ((nread = is.read(buf)) > 0) {
size += nread;
}
size = is.readAllBytes().length;
} catch (IOException ex) {
size = -1L;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import jakarta.json.stream.JsonParser;
import java.io.StringReader;
import java.util.Collections;
import java.util.Map;
import junit.framework.TestCase;
import org.junit.Test;
import org.opensearch.client.json.JsonData;
Expand All @@ -30,7 +30,7 @@ public void testCreateKnnVectorMethodWithAll() {
KnnVectorMethod knnVectorMethod = new KnnVectorMethod.Builder().name("hnsw")
.spaceType("l2")
.engine("nmslib")
.parameters(Collections.singletonMap("ef_construction", JsonData.of(128)))
.parameters(Map.of("ef_construction", JsonData.of(128)))
.build();
assertEquals("hnsw", knnVectorMethod.name());
assertEquals("l2", knnVectorMethod.spaceType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.stream.JsonParser;
import java.io.StringReader;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -13,9 +12,7 @@
import org.opensearch.client.json.jsonb.JsonbJsonpMapper;
import org.opensearch.client.opensearch._types.mapping.IcuCollationKeywordProperty;
import org.opensearch.client.opensearch._types.mapping.Property;
import org.opensearch.client.opensearch._types.mapping.TypeMapping;
import org.opensearch.client.opensearch.indices.GetTemplateResponse;
import org.opensearch.client.opensearch.indices.TemplateMapping;

public class GetMappingsResponseTest extends Assert {

Expand All @@ -39,27 +36,32 @@ public void deserialize_IcuCollationKeywordExists_propertyDeserializes() throws
icuCollationConfig.put("strength", "quaternary");
icuCollationConfig.put("variable_top", "$");

final Map<String, Object> mappingTemplateMap = new HashMap<>();
mappingTemplateMap.put("aliases", Collections.emptyMap());
mappingTemplateMap.put("index_patterns", Collections.singletonList("test-pattern*"));
mappingTemplateMap.put(
"mappings",
Collections.singletonMap("properties", Collections.singletonMap("icu_test_field", icuCollationConfig))
mappingTemplate.put(
"test-index",
Map.of(
"aliases",
Collections.emptyMap(),
"index_patterns",
Collections.singletonList("test-pattern*"),
"mappings",
Map.of("properties", Map.of("icu_test_field", icuCollationConfig)),
"order",
0,
"settings",
Collections.emptyMap(),
"version",
1
)
);
mappingTemplateMap.put("order", 0);
mappingTemplateMap.put("settings", Collections.emptyMap());
mappingTemplateMap.put("version", 1);
mappingTemplate.put("test-index", mappingTemplateMap);

final JsonpMapper mapper = new JsonbJsonpMapper();
final String indexTemplate = new ObjectMapper().writeValueAsString(mappingTemplate);
final JsonParser parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate));
final var parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate));

final GetTemplateResponse response = GetTemplateResponse._DESERIALIZER.deserialize(parser, mapper);
final TemplateMapping template = response.get("test-index");
final TypeMapping mappings = template.mappings();
final Map<String, Property> properties = mappings.properties();
final Property property = properties.get("icu_test_field");
final var template = response.get("test-index");
final var mappings = template.mappings();
final var properties = mappings.properties();
final var property = properties.get("icu_test_field");
final IcuCollationKeywordProperty icu = property.icuCollationKeyword();

assertEquals(property._kind(), Property.Kind.IcuCollationKeyword);
Expand Down
Loading
Loading