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

Add spotless for formatting Java source files #120

Merged
merged 3 commits into from
Mar 15, 2024
Merged
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
38 changes: 19 additions & 19 deletions .github/workflows/add-untriaged.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: Apply 'untriaged' label during issue lifecycle
on:
issues:
types: [opened, reopened, transferred]
jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['untriaged']
})
name: Apply 'untriaged' label during issue lifecycle

on:
issues:
types: [opened, reopened, transferred]

jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['untriaged']
})
4 changes: 2 additions & 2 deletions .github/workflows/delete-backport-branch.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Delete merged branch of the backport PRs
on:
on:
pull_request:
types:
- closed

jobs:
delete-branch:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-maven-snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
export SONATYPE_PASSWORD=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text)
echo "::add-mask::$SONATYPE_USERNAME"
echo "::add-mask::$SONATYPE_PASSWORD"
./gradlew publishPluginZipPublicationToSnapshotsRepository
./gradlew publishPluginZipPublicationToSnapshotsRepository
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Custom Codecs
Custom Codecs plugin makes it possible for users to provide custom Lucene codecs for loading through Apache Lucene's `NamedSPILoader`.
These codecs can be used to customize the on-disk representation of the opensearch indexes. For example, zstd compression can be used for
These codecs can be used to customize the on-disk representation of the opensearch indexes. For example, zstd compression can be used for
`StoredField` types through the `ZstdCodec`.

## Security
Expand All @@ -13,4 +13,3 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
## License

This project is licensed under the Apache-2.0 License.

23 changes: 22 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
* GitHub history for details.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

buildscript {
ext {
opensearch_group = "org.opensearch"
Expand All @@ -32,12 +51,14 @@ buildscript {

plugins {
id 'java'
id 'com.diffplug.spotless' version '6.25.0'
}

apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.internal-cluster-test'
apply plugin: 'opensearch.pluginzip'
apply plugin: 'opensearch.rest-test'
apply from: 'gradle/formatting.gradle'

repositories {
mavenLocal()
Expand All @@ -56,7 +77,7 @@ allprojects {
version += "-SNAPSHOT"
}

plugins.withId('java') {
java {
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
*/
package org.opensearch.customcodecs.bwc;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.net.ssl.SSLEngine;

import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
Expand All @@ -29,10 +19,6 @@
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.ssl.SSLContextBuilder;

import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.Before;
import org.opensearch.client.Response;
import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;
Expand All @@ -45,6 +31,20 @@
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.customcodecs.bwc.helper.RestHelper;
import org.opensearch.test.rest.OpenSearchRestTestCase;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.Before;

import javax.net.ssl.SSLEngine;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_PER_ROUTE;
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_TOTAL;
Expand All @@ -62,14 +62,10 @@ public void testSetup() throws IOException {
logger.info("Running Test for Cluster Type: {}", CLUSTER_TYPE);
CLUSTER_NAME = System.getProperty("tests.clustername");
if (testUserRestClient == null) {
testUserRestClient = buildClient(
super.restClientSettings(),
super.getClusterHosts().toArray(new HttpHost[0])
);
testUserRestClient = buildClient(super.restClientSettings(), super.getClusterHosts().toArray(new HttpHost[0]));
}
}


@Override
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
Expand Down Expand Up @@ -97,30 +93,26 @@ protected void configureHttpOrHttpsClient(RestClientBuilder builder, Settings se
credentialsProvider.setCredentials(anyScope, new UsernamePasswordCredentials(username, password.toCharArray()));

try {
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder
.create()
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSslContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build())
// See https://issues.apache.org/jira/browse/HTTPCLIENT-2219
.setTlsDetailsFactory(new Factory<SSLEngine, TlsDetails>() {
@Override
public TlsDetails create(final SSLEngine sslEngine) {
return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol());
}
})
.build();
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create()
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSslContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build())
// See https://issues.apache.org/jira/browse/HTTPCLIENT-2219
.setTlsDetailsFactory(new Factory<SSLEngine, TlsDetails>() {
@Override
public TlsDetails create(final SSLEngine sslEngine) {
return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol());
}
})
.build();

builder.setHttpClientConfigCallback(httpClientBuilder -> {
final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
.create()
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE)
.setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)
.setTlsStrategy(tlsStrategy)
.build();

return httpClientBuilder
.setDefaultCredentialsProvider(credentialsProvider)
.setConnectionManager(connectionManager);
final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder.create()
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE)
.setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)
.setTlsStrategy(tlsStrategy)
.build();

return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(connectionManager);
});
} catch (final NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) {
throw new IOException(ex);
Expand Down Expand Up @@ -149,19 +141,17 @@ protected final boolean preserveReposUponCompletion() {
return true;
}


@Override
protected final Settings restClientSettings() {
return Settings.builder()
.put(super.restClientSettings())
// increase the timeout here to 90 seconds to handle long waits for a green
// cluster health. the waits for green need to be longer than a minute to
// account for delayed shards
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
.build();
.put(super.restClientSettings())
// increase the timeout here to 90 seconds to handle long waits for a green
// cluster health. the waits for green need to be longer than a minute to
// account for delayed shards
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
.build();
}


/**
* Tests backward compatibility by created a test user and role with DLS, FLS and masked field settings. Ingests
* data into a test index and runs a matchAll query against the same.
Expand All @@ -176,7 +166,6 @@ public void testDataIngestionAndSearchBackwardsCompatibility() throws Exception
searchMatchAll(index);
}


/**
* Ingests data into the test index
*
Expand All @@ -195,7 +184,7 @@ private void ingestData(String index) throws IOException {
put("_index", index);
}
});

try (final XContentBuilder contentBuilder = MediaTypeRegistry.JSON.contentBuilder()) {
contentBuilder.map(indexRequest);
bulkRequestBody.append(contentBuilder.toString() + "\n");
Expand All @@ -204,10 +193,10 @@ private void ingestData(String index) throws IOException {
bulkRequestBody.append(Song.randomSong().asJson() + "\n");
}
List<Response> responses = RestHelper.requestAgainstAllNodes(
testUserRestClient,
"POST",
"_bulk?refresh=wait_for",
RestHelper.toHttpEntity(bulkRequestBody.toString())
testUserRestClient,
"POST",
"_bulk?refresh=wait_for",
RestHelper.toHttpEntity(bulkRequestBody.toString())
);
responses.forEach(r -> assertEquals(200, r.getStatusLine().getStatusCode()));
}
Expand All @@ -223,10 +212,10 @@ private void searchMatchAll(String index) throws IOException {
int numberOfRequests = Randomness.get().nextInt(10);
while (numberOfRequests-- > 0) {
List<Response> responses = RestHelper.requestAgainstAllNodes(
testUserRestClient,
"POST",
index + "/_search",
RestHelper.toHttpEntity(matchAllQuery)
testUserRestClient,
"POST",
index + "/_search",
RestHelper.toHttpEntity(matchAllQuery)
);
responses.forEach(r -> assertEquals(200, r.getStatusLine().getStatusCode()));
}
Expand All @@ -247,13 +236,13 @@ private void createIndexIfNotExists(String index) throws IOException {

// creating index
createIndex(
index,
Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.codec", randomFrom("zstd", "zstd_no_dict"))
.put("index.codec.compression_level", randomIntBetween(1, 6))
.build()
index,
Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.codec", randomFrom("zstd", "zstd_no_dict"))
.put("index.codec.compression_level", randomIntBetween(1, 6))
.build()
);
ensureGreen(index);
}
Expand Down
30 changes: 15 additions & 15 deletions bwc-test/src/test/java/org/opensearch/customcodecs/bwc/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*/
package org.opensearch.customcodecs.bwc;

import org.opensearch.common.Randomness;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import org.opensearch.common.Randomness;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;

public class Song {

public static final String FIELD_TITLE = "title";
Expand Down Expand Up @@ -57,12 +57,12 @@ public class Song {
public static final String QUERY_TITLE_MAGNUM_OPUS = FIELD_TITLE + ":" + TITLE_MAGNUM_OPUS;

public static final Song[] SONGS = {
new Song(ARTIST_FIRST, TITLE_MAGNUM_OPUS, LYRICS_1, 1, GENRE_ROCK),
new Song(ARTIST_STRING, TITLE_SONG_1_PLUS_1, LYRICS_2, 2, GENRE_BLUES),
new Song(ARTIST_TWINS, TITLE_NEXT_SONG, LYRICS_3, 3, GENRE_JAZZ),
new Song(ARTIST_NO, TITLE_POISON, LYRICS_4, 4, GENRE_ROCK),
new Song(ARTIST_YES, TITLE_AFFIRMATIVE, LYRICS_5, 5, GENRE_BLUES),
new Song(ARTIST_UNKNOWN, TITLE_CONFIDENTIAL, LYRICS_6, 6, GENRE_JAZZ)};
new Song(ARTIST_FIRST, TITLE_MAGNUM_OPUS, LYRICS_1, 1, GENRE_ROCK),
new Song(ARTIST_STRING, TITLE_SONG_1_PLUS_1, LYRICS_2, 2, GENRE_BLUES),
new Song(ARTIST_TWINS, TITLE_NEXT_SONG, LYRICS_3, 3, GENRE_JAZZ),
new Song(ARTIST_NO, TITLE_POISON, LYRICS_4, 4, GENRE_ROCK),
new Song(ARTIST_YES, TITLE_AFFIRMATIVE, LYRICS_5, 5, GENRE_BLUES),
new Song(ARTIST_UNKNOWN, TITLE_CONFIDENTIAL, LYRICS_6, 6, GENRE_JAZZ) };

private final String artist;
private final String title;
Expand Down Expand Up @@ -111,11 +111,11 @@ public String asJson() throws IOException {

public static Song randomSong() {
return new Song(
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
Randomness.get().nextInt(5),
UUID.randomUUID().toString()
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
Randomness.get().nextInt(5),
UUID.randomUUID().toString()
);
}
}
Loading
Loading