Skip to content

Commit

Permalink
HSEARCH-3922 Do not use "get"/"set" prefixes for SPI methods in the E…
Browse files Browse the repository at this point in the history
…lasticsearch backend module
  • Loading branch information
yrodiere committed May 20, 2020
1 parent b3ffe3b commit 08511f2
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 101 deletions.
Expand Up @@ -131,10 +131,10 @@ public void onFailure(Exception exception) {
}
);

long currentTimeoutValue = ( elasticsearchRequest.getTimeoutValue() == null ) ?
globalTimeoutValue : elasticsearchRequest.getTimeoutValue();
TimeUnit currentTimeoutUnit = ( elasticsearchRequest.getTimeoutUnit() == null ) ?
globalTimeoutUnit : elasticsearchRequest.getTimeoutUnit();
long currentTimeoutValue = ( elasticsearchRequest.timeoutValue() == null ) ?
globalTimeoutValue : elasticsearchRequest.timeoutValue();
TimeUnit currentTimeoutUnit = ( elasticsearchRequest.timeoutUnit() == null ) ?
globalTimeoutUnit : elasticsearchRequest.timeoutUnit();

/*
* TODO HSEARCH-3590 maybe the callback should also cancel the request?
Expand All @@ -158,9 +158,9 @@ public void onFailure(Exception exception) {
}

private static Request toRequest(ElasticsearchRequest elasticsearchRequest, HttpEntity entity) {
Request request = new Request( elasticsearchRequest.getMethod(), elasticsearchRequest.getPath() );
Request request = new Request( elasticsearchRequest.method(), elasticsearchRequest.path() );

for ( Entry<String, String> parameter : elasticsearchRequest.getParameters().entrySet() ) {
for ( Entry<String, String> parameter : elasticsearchRequest.parameters().entrySet() ) {
request.addParameter( parameter.getKey(), parameter.getValue() );
}

Expand Down Expand Up @@ -208,16 +208,16 @@ private void log(ElasticsearchRequest request, long start, ElasticsearchResponse
long executionTimeNs = System.nanoTime() - start;
long executionTimeMs = TimeUnit.NANOSECONDS.toMillis( executionTimeNs );
if ( requestLog.isTraceEnabled() ) {
requestLog.executedRequest( request.getMethod(), request.getPath(), request.getParameters(),
request.getBodyParts().size(), executionTimeMs,
response.getStatusCode(), response.getStatusMessage(),
jsonLogHelper.toString( request.getBodyParts() ),
jsonLogHelper.toString( response.getBody() ) );
requestLog.executedRequest( request.method(), request.path(), request.parameters(),
request.bodyParts().size(), executionTimeMs,
response.statusCode(), response.statusMessage(),
jsonLogHelper.toString( request.bodyParts() ),
jsonLogHelper.toString( response.body() ) );
}
else {
requestLog.executedRequest( request.getMethod(), request.getPath(), request.getParameters(),
request.getBodyParts().size(), executionTimeMs,
response.getStatusCode(), response.getStatusMessage() );
requestLog.executedRequest( request.method(), request.path(), request.parameters(),
request.bodyParts().size(), executionTimeMs,
response.statusCode(), response.statusMessage() );
}
}

Expand Down
Expand Up @@ -41,7 +41,7 @@ public static boolean isSuccessCode(int code) {
}

public static HttpEntity toEntity(Gson gson, ElasticsearchRequest request) throws IOException {
final List<JsonObject> bodyParts = request.getBodyParts();
final List<JsonObject> bodyParts = request.bodyParts();
if ( bodyParts.isEmpty() ) {
return null;
}
Expand All @@ -63,11 +63,11 @@ private static ElasticsearchVersion tryGetElasticsearchVersion(ElasticsearchClie
try {
response = Futures.unwrappedExceptionJoin( client.submit( request ) );

if ( !ElasticsearchClientUtils.isSuccessCode( response.getStatusCode() ) ) {
if ( !ElasticsearchClientUtils.isSuccessCode( response.statusCode() ) ) {
throw log.elasticsearchResponseIndicatesFailure();
}

return VERSION_ACCESSOR.get( response.getBody() )
return VERSION_ACCESSOR.get( response.body() )
.map( ElasticsearchVersion::of )
.orElseThrow( () -> new AssertionFailure( "Missing version number in JSON response" ) );
}
Expand Down
Expand Up @@ -58,27 +58,27 @@ private ElasticsearchRequest(Builder builder) {
this.timeoutUnit = builder.timeoutUnit;
}

public String getMethod() {
public String method() {
return method;
}

public String getPath() {
public String path() {
return path;
}

public Map<String, String> getParameters() {
public Map<String, String> parameters() {
return parameters;
}

public List<JsonObject> getBodyParts() {
public List<JsonObject> bodyParts() {
return bodyParts;
}

public Long getTimeoutValue() {
public Long timeoutValue() {
return timeoutValue;
}

public TimeUnit getTimeoutUnit() {
public TimeUnit timeoutUnit() {
return timeoutUnit;
}

Expand Down
Expand Up @@ -24,15 +24,15 @@ public ElasticsearchResponse(int statusCode, String statusMessage, JsonObject bo
this.body = body;
}

public int getStatusCode() {
public int statusCode() {
return statusCode;
}

public String getStatusMessage() {
public String statusMessage() {
return statusMessage;
}

public JsonObject getBody() {
public JsonObject body() {
return body;
}

Expand Down
Expand Up @@ -34,11 +34,11 @@ private static String formatRequest(ElasticsearchRequest request) {
//Wild guess for some tuning. The only certainty is that the default (16) is too small.
StringBuilder sb = new StringBuilder( 180 );

sb.append( request.getMethod() )
sb.append( request.method() )
.append( " " )
.append( request.getPath() )
.append( request.path() )
.append( " with parameters " )
.append( request.getParameters() );
.append( request.parameters() );

return sb.toString();
}
Expand Down
Expand Up @@ -37,11 +37,11 @@ private static String formatResponse(ElasticsearchResponse response) {
//Wild guess for some tuning. The only certainty is that the default (16) is too small.
//Also useful to hint the builder to use larger increment steps.
StringBuilder sb = new StringBuilder( 180 );
sb.append( response.getStatusCode() )
sb.append( response.statusCode() )
.append( " '" )
.append( response.getStatusMessage() )
.append( response.statusMessage() )
.append( "' with body " )
.append( helper.toString( response.getBody() ) );
.append( helper.toString( response.body() ) );

return sb.toString();
}
Expand Down
Expand Up @@ -39,15 +39,15 @@ static Function<ElasticsearchRequest, ElasticsearchRequest> createTransformerFun

private ElasticsearchSearchRequestTransformerContextImpl(ElasticsearchRequest originalRequest) {
this.originalRequest = originalRequest;
List<JsonObject> originalBodyParts = originalRequest.getBodyParts();
List<JsonObject> originalBodyParts = originalRequest.bodyParts();
if ( originalBodyParts.size() != 1 ) {
throw new AssertionFailure(
"Request transformation was applied to a request with no body part or more than one body parts."
+ " There is a bug in Hibernate Search, please report it."
);
}
this.originalBody = originalBodyParts.get( 0 );
this.path = originalRequest.getPath();
this.path = originalRequest.path();
}

@Override
Expand All @@ -65,7 +65,7 @@ public void path(String newPath) {
public Map<String, String> parametersMap() {
// Avoid side-effects on the original request
if ( potentiallyTransformedParametersMap == null ) {
potentiallyTransformedParametersMap = new LinkedHashMap<>( originalRequest.getParameters() );
potentiallyTransformedParametersMap = new LinkedHashMap<>( originalRequest.parameters() );
}
return potentiallyTransformedParametersMap;
}
Expand All @@ -82,12 +82,12 @@ public JsonObject body() {
public ElasticsearchRequest apply(ElasticsearchSearchRequestTransformer transformer) {
transformer.transform( this );

ElasticsearchRequest.Builder builder = ElasticsearchRequest.builder( originalRequest.getMethod() );
ElasticsearchRequest.Builder builder = ElasticsearchRequest.builder( originalRequest.method() );

builder.wholeEncodedPath( path );

Map<String, String> parameters = potentiallyTransformedParametersMap != null
? potentiallyTransformedParametersMap : originalRequest.getParameters();
? potentiallyTransformedParametersMap : originalRequest.parameters();
parameters.forEach( builder::param );

JsonObject body = potentiallyTransformedBody != null ? potentiallyTransformedBody : originalBody;
Expand Down
Expand Up @@ -41,7 +41,7 @@ public String toString() {
return new StringBuilder()
.append( getClass().getSimpleName() )
.append( "[" )
.append( "path = " ).append( request.getPath() )
.append( "path = " ).append( request.path() )
.append( "]" )
.toString();
}
Expand Down
Expand Up @@ -30,7 +30,7 @@ protected BulkWork(Builder builder) {

@Override
protected BulkResult generateResult(ElasticsearchWorkExecutionContext context, ElasticsearchResponse response) {
JsonObject parsedResponseBody = response.getBody();
JsonObject parsedResponseBody = response.body();
JsonArray resultItems = BULK_ITEMS.get( parsedResponseBody ).orElseGet( JsonArray::new );
return new BulkResultImpl( resultItems );
}
Expand Down
Expand Up @@ -31,7 +31,7 @@ protected CountWork(Builder builder) {

@Override
protected Long generateResult(ElasticsearchWorkExecutionContext context, ElasticsearchResponse response) {
JsonObject body = response.getBody();
JsonObject body = response.body();
return COUNT_ACCESSOR.get( body ).get();
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ protected CreateIndexWork(Builder builder) {

@Override
protected CreateIndexResult generateResult(ElasticsearchWorkExecutionContext context, ElasticsearchResponse response) {
int statusCode = response.getStatusCode();
int statusCode = response.statusCode();
if ( ElasticsearchClientUtils.isSuccessCode( statusCode ) ) {
return CreateIndexResult.CREATED;
}
Expand Down
Expand Up @@ -81,8 +81,8 @@ public String toString() {

@Override
public void checkSuccess(ElasticsearchResponse response) throws SearchException {
JsonObject responseBody = response.getBody();
Optional<Integer> statusCode = Optional.of( response.getStatusCode() );
JsonObject responseBody = response.body();
Optional<Integer> statusCode = Optional.of( response.statusCode() );
checkSuccess( statusCode, responseBody );
}

Expand Down
Expand Up @@ -38,10 +38,10 @@ private ExplainWork(Builder builder) {
@Override
protected ExplainResult generateResult(ElasticsearchWorkExecutionContext context,
ElasticsearchResponse response) {
if ( response.getStatusCode() == 404 ) {
if ( response.statusCode() == 404 ) {
throw log.explainUnknownDocument( id );
}
JsonObject body = response.getBody();
JsonObject body = response.body();
return new ExplainResultImpl( body );
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ private GetIndexMetadataWork(Builder builder) {
@Override
protected List<ExistingIndexMetadata> generateResult(ElasticsearchWorkExecutionContext context,
ElasticsearchResponse response) {
JsonObject body = response.getBody();
JsonObject body = response.body();
List<ExistingIndexMetadata> result = new ArrayList<>();
for ( Map.Entry<String, JsonElement> entry : body.entrySet() ) {
JsonObject indexAsObject = entry.getValue().getAsJsonObject();
Expand Down
Expand Up @@ -25,7 +25,7 @@ protected ScrollWork(Builder<R> builder) {

@Override
protected R generateResult(ElasticsearchWorkExecutionContext context, ElasticsearchResponse response) {
JsonObject body = response.getBody();
JsonObject body = response.body();
return resultExtractor.extract( body );
}

Expand Down
Expand Up @@ -38,16 +38,16 @@ protected SearchWork(Builder<R> builder) {
@Override
protected CompletableFuture<?> beforeExecute(ElasticsearchWorkExecutionContext executionContext, ElasticsearchRequest request) {
queryLog.executingElasticsearchQuery(
request.getPath(),
request.getParameters(),
executionContext.getGsonProvider().getLogHelper().toString( request.getBodyParts() )
request.path(),
request.parameters(),
executionContext.getGsonProvider().getLogHelper().toString( request.bodyParts() )
);
return super.beforeExecute( executionContext, request );
}

@Override
protected R generateResult(ElasticsearchWorkExecutionContext context, ElasticsearchResponse response) {
JsonObject body = response.getBody();
JsonObject body = response.body();
return resultExtractor.extract( body );
}

Expand Down
Expand Up @@ -141,14 +141,14 @@ public void execute_http500() {
private void assertBulkRequest(ElasticsearchRequest request, int ... bulkableIndices) {
assertThat( request ).isNotNull();
assertSoftly( softly -> {
softly.assertThat( request.getMethod() ).isEqualTo( "POST" );
softly.assertThat( request.getPath() ).isEqualTo( "/_bulk" );
softly.assertThat( request.method() ).isEqualTo( "POST" );
softly.assertThat( request.path() ).isEqualTo( "/_bulk" );
List<JsonObject> expectedBodyParts = new ArrayList<>();
for ( int bulkableIndex : bulkableIndices ) {
expectedBodyParts.add( bulkableWorkMetadata( bulkableIndex ) );
expectedBodyParts.add( bulkableWorkBody( bulkableIndex ) );
}
softly.assertThat( request.getBodyParts() ).containsExactlyElementsOf( expectedBodyParts );
softly.assertThat( request.bodyParts() ).containsExactlyElementsOf( expectedBodyParts );
} );
}

Expand Down

0 comments on commit 08511f2

Please sign in to comment.