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

Closes #345, Introduces KustoRequest wrapper object and async methods #358

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b2b670d
Introduces KustoQuery wrapper object
Mar 26, 2024
ab1102c
Merge branch 'master' into implement_kusto_query_object
The-Funk Apr 9, 2024
77aaf02
Merge branch 'master' into implement_kusto_query_object
The-Funk Apr 11, 2024
1f1f30d
working on async client
May 4, 2024
939d4a7
updating client with KustoQuery object
May 15, 2024
64b100b
updating client with KustoQuery object
May 15, 2024
0989842
updating client with KustoQuery object
May 15, 2024
abd512d
Merge remote-tracking branch 'origin/implement_kusto_query_object' in…
May 15, 2024
7c07207
Merge branch 'master' into implement_kusto_query_object
The-Funk May 15, 2024
4c4cc46
will simplify later.
May 20, 2024
d000948
Merge remote-tracking branch 'origin/implement_kusto_query_object' in…
May 20, 2024
8099b73
will simplify later.
May 20, 2024
610778e
will simplify later.
May 20, 2024
5972c30
Merge branch 'master' into implement_kusto_query_object
The-Funk May 21, 2024
39d479a
ran formatter, fixed test, fixed bad merge
May 21, 2024
c8c90a5
AtomicBooleans in already modified test. Save some lines, might as well.
May 21, 2024
c59c124
Merge branch 'master' into implement_kusto_query_object
The-Funk May 21, 2024
a5b6d37
hide KustoQuery object
May 22, 2024
2ff7eda
Merge remote-tracking branch 'origin/implement_kusto_query_object' in…
May 22, 2024
e329eef
rename and hide KustoRequest
May 22, 2024
7e7ccc2
adding E2ETests for async queries
Jun 11, 2024
1c96d72
ran formatter
Jun 11, 2024
ab201e4
no complete in sink
The-Funk Jun 21, 2024
96e3527
move blocking operations off the io thread
The-Funk Jun 21, 2024
5cd3b31
run formatter
The-Funk Jun 21, 2024
ae0c72e
replace execute utilization
The-Funk Jun 21, 2024
2904187
fixes teardown. async still doesn't work yet.
Aug 1, 2024
4924c7d
fixes msal4j issue
Aug 1, 2024
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
54 changes: 36 additions & 18 deletions data/src/main/java/com/microsoft/azure/kusto/data/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.util.Objects;
import java.util.Optional;

public abstract class BaseClient implements Client, StreamingClient {
Expand All @@ -30,33 +32,50 @@ public BaseClient(HttpClient httpClient) {
}

protected String post(HttpRequest request) throws DataServiceException {
The-Funk marked this conversation as resolved.
Show resolved Hide resolved

// Todo: Add async version of this method

// Execute and get the response
try (HttpResponse response = httpClient.sendSync(request, Context.NONE)) {
String responseBody = Utils.isGzipResponse(response) ? Utils.gzipedInputToString(response.getBodyAsBinaryData().toStream())
: response.getBodyAsBinaryData().toString();

if (responseBody != null) {
switch (response.getStatusCode()) {
case HttpStatus.OK:
return responseBody;
case HttpStatus.TOO_MANY_REQS:
throw new ThrottleException(request.getUrl().toString());
default:
throw createExceptionFromResponse(request.getUrl().toString(), response, null, responseBody);
}
}
return processResponseBody(response);
}
}

protected Mono<String> postAsync(HttpRequest request) {
// Execute and get the response
return httpClient.send(request)
.onErrorContinue((err, src) -> LOGGER.error("Error coming from src {}", src, err))
.flatMap(this::processResponseAsync)
.onErrorContinue((err, src) -> LOGGER.error("Error coming from src {}", src, err));
}

return null;
public Mono<String> processResponseAsync(HttpResponse response) {
try {
return Mono.just(Objects.requireNonNull(processResponseBody(response)));
} catch (Exception e) {
return Mono.error(new RuntimeException("Error processing response", e));
}
}

private String processResponseBody(HttpResponse response) throws DataServiceException {
String responseBody = Utils.isGzipResponse(response) ? Utils.gzipedInputToString(response.getBodyAsBinaryData().toStream())
: response.getBodyAsBinaryData().toString();

if (responseBody == null) {
return null;
}
switch (response.getStatusCode()) {
case HttpStatus.OK:
return responseBody;
case HttpStatus.TOO_MANY_REQS:
throw new ThrottleException(response.getRequest().getUrl().toString());
default:
throw createExceptionFromResponse(response.getRequest().getUrl().toString(), response, null, responseBody);
}
}

protected InputStream postToStreamingOutput(HttpRequest request) throws DataServiceException {
return postToStreamingOutput(request, 0);
}

// Todo: Implement async version of this method
protected InputStream postToStreamingOutput(HttpRequest request, int redirectCount) throws DataServiceException {

boolean returnInputStream = false;
Expand All @@ -65,7 +84,6 @@ protected InputStream postToStreamingOutput(HttpRequest request, int redirectCou
HttpResponse httpResponse = null;
try {

// Todo: Implement async version of this method
httpResponse = httpClient.sendSync(request, Context.NONE);

int responseStatusCode = httpResponse.getStatusCode();
Expand Down
16 changes: 11 additions & 5 deletions data/src/main/java/com/microsoft/azure/kusto/data/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,36 @@

import com.microsoft.azure.kusto.data.exceptions.DataClientException;
import com.microsoft.azure.kusto.data.exceptions.DataServiceException;
import reactor.core.publisher.Mono;

import java.io.Closeable;
public interface Client {

public interface Client extends Closeable {
KustoOperationResult execute(String command) throws DataServiceException, DataClientException;
Mono<KustoOperationResult> executeQueryAsync(String database, String command, ClientRequestProperties properties);

KustoOperationResult execute(String database, String command) throws DataServiceException, DataClientException;
Mono<KustoOperationResult> executeMgmtAsync(String database, String command, ClientRequestProperties properties);

KustoOperationResult execute(String database, String command, ClientRequestProperties properties) throws DataServiceException, DataClientException;
Mono<String> executeToJsonAsync(String database, String command, ClientRequestProperties properties);

@Deprecated
KustoOperationResult executeQuery(String command) throws DataServiceException, DataClientException;

@Deprecated
KustoOperationResult executeQuery(String database, String command) throws DataServiceException, DataClientException;

KustoOperationResult executeQuery(String database, String command, ClientRequestProperties properties) throws DataServiceException, DataClientException;

@Deprecated
KustoOperationResult executeMgmt(String command) throws DataServiceException, DataClientException;

@Deprecated
KustoOperationResult executeMgmt(String database, String command) throws DataServiceException, DataClientException;

KustoOperationResult executeMgmt(String database, String command, ClientRequestProperties properties) throws DataServiceException, DataClientException;

@Deprecated
String executeToJsonResult(String database) throws DataServiceException, DataClientException;

@Deprecated
String executeToJsonResult(String database, String command) throws DataServiceException, DataClientException;

String executeToJsonResult(String database, String command, ClientRequestProperties properties) throws DataServiceException, DataClientException;
Expand Down
Loading