From 1558342cecd79e6c1c8ff55ecc1b1434e1cbb4ea Mon Sep 17 00:00:00 2001 From: Hassan EL MZABI Date: Fri, 19 Apr 2024 10:52:03 +0200 Subject: [PATCH 1/2] update .gitignore file to adapt with java binding impl initial java project for grpc impl Armonik: Java client layer - v1 rename module to java CI: add java config CI : add java distribution (oracle) CI: fix working directory for java package CI: Fix LinkJs error, correct distribution format CI: rename java stage java: add javadocs and fix result client impl java: remove tests temporary java: correct project version and artifactId name java: improve task client factory using static methods --- .github/workflows/ci.yml | 20 ++ .gitignore | 12 + packages/java/pom.xml | 128 ++++++++ .../client/event/EventClientFactory.java | 32 ++ .../client/event/impl/EventClientAsync.java | 69 +++++ .../client/event/impl/EventClientSync.java | 58 ++++ .../factory/EventClientRequestFactory.java | 52 ++++ .../EventSubscriptionResponseRecord.java | 16 + .../client/event/spec/IEventClientAsync.java | 10 + .../client/event/spec/IEventClientSync.java | 10 + .../client/result/ResultClientFactory.java | 32 ++ .../client/result/impl/ResultClientAsync.java | 277 ++++++++++++++++++ .../client/result/impl/ResultClientSync.java | 88 ++++++ .../factory/ResultClientRequestFactory.java | 60 ++++ .../DeleteResultsDataResponseRecord.java | 6 + .../records/WatchResultResponseRecord.java | 8 + .../result/spec/IResultClientAsync.java | 32 ++ .../client/result/spec/IResultClientSync.java | 26 ++ .../client/session/SessionClientFactory.java | 33 +++ .../session/impl/SessionClientAsync.java | 269 +++++++++++++++++ .../session/impl/SesssionClientSync.java | 162 ++++++++++ .../util/SessionClientRequestFactory.java | 69 +++++ .../session/spec/ISessionClientAsync.java | 30 ++ .../session/spec/ISessionClientSync.java | 52 ++++ .../client/task/TaskClientFactory.java | 33 +++ .../client/task/impl/TaskClientAsync.java | 203 +++++++++++++ .../client/task/impl/TaskClientSync.java | 79 +++++ .../impl/util/TaskClientRequestFactory.java | 77 +++++ .../client/task/spec/ITaskClientAsync.java | 24 ++ .../client/task/spec/ITaskClientSync.java | 23 ++ packages/java/src/main/resources/logback.xml | 13 + .../org.mockito.plugins.MockMaker | 1 + 32 files changed, 2004 insertions(+) create mode 100644 packages/java/pom.xml create mode 100644 packages/java/src/main/java/armonik/client/event/EventClientFactory.java create mode 100644 packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java create mode 100644 packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java create mode 100644 packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/result/ResultClientFactory.java create mode 100644 packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java create mode 100644 packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java create mode 100644 packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java create mode 100644 packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/session/SessionClientFactory.java create mode 100644 packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java create mode 100644 packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/task/TaskClientFactory.java create mode 100644 packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java create mode 100644 packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java create mode 100644 packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java create mode 100644 packages/java/src/main/resources/logback.xml create mode 100644 packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ae127ebe..c8b0a6d55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -336,3 +336,23 @@ jobs: if-no-files-found: error path: packages/cpp/tools/packaging/*.${{ matrix.type }} name: libarmonik.${{ matrix.type }} + + build-java-packages: + name: Build Java + runs-on: ubuntu-latest + defaults: + run: + working-directory: packages/java + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + fetch-depth: 0 + - name: Set up java 17 + uses: actions/setup-java@v4 + with: + distribution: oracle + java-version: 17 + cache: maven + - name: Build the package + run: mvn clean install -DskipTests diff --git a/.gitignore b/.gitignore index 0deaa71df..19ea261d4 100644 --- a/.gitignore +++ b/.gitignore @@ -381,6 +381,7 @@ dist !packages/python !packages/angular !packages/web +!packages/java packages/web/LICENSE !.docs/content/** @@ -390,3 +391,14 @@ packages/web/LICENSE **/.idea gen + +# Maven +target/ + +# Compiled class file +*.class + +# IDE-specific files +*.iml +*.ipr +*.iws diff --git a/packages/java/pom.xml b/packages/java/pom.xml new file mode 100644 index 000000000..ecad9114c --- /dev/null +++ b/packages/java/pom.xml @@ -0,0 +1,128 @@ + + + 4.0.0 + + org.aneo + armonik-java + GRPC java binding for the Armonik orchestrator API + 0.1.0 + + + 17 + 17 + UTF-8 + 0.6.1 + 1.7.1 + ../../Protos/V1 + 2.0.12 + 1.5.5 + + + + + io.grpc + grpc-netty + 1.62.2 + + + io.grpc + grpc-protobuf + 1.62.2 + + + io.grpc + grpc-stub + 1.62.2 + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + + org.slf4j + slf4j-api + ${sl4j.version} + + + + org.junit.jupiter + junit-jupiter-engine + 5.10.2 + test + + + + + + + org.mockito + mockito-core + 5.11.0 + test + + + + + org.mockito + mockito-junit-jupiter + 5.11.0 + test + + + + + + + + + + kr.motd.maven + os-maven-plugin + ${os-maven-plugin.version} + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + ${protobuf-maven-plugin.version} + + ${proto.path} + + com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier} + + grpc-java + + io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier} + + + + + + compile + compile-custom + + + + + + + + diff --git a/packages/java/src/main/java/armonik/client/event/EventClientFactory.java b/packages/java/src/main/java/armonik/client/event/EventClientFactory.java new file mode 100644 index 000000000..5f97b345c --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/EventClientFactory.java @@ -0,0 +1,32 @@ +package armonik.client.event; + +import armonik.client.event.impl.EventClientAsync; +import armonik.client.event.impl.EventClientSync; +import armonik.client.event.spec.IEventClientAsync; +import armonik.client.event.spec.IEventClientSync; +import io.grpc.ManagedChannel; + +/** + * EventClientFactory provides static factory methods to create instances of event client implementations. + */ +public abstract class EventClientFactory { + /** + * Creates an asynchronous event client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the event service + * @return an instance of {@link IEventClientAsync} representing an asynchronous event client + */ + public static IEventClientAsync createEventClientAsync(ManagedChannel managedChannel) { + return new EventClientAsync(managedChannel); + } + + /** + * Creates a synchronous event client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the event service + * @return an instance of {@link IEventClientSync} representing a synchronous event client + */ + public static IEventClientSync createEventClientSync(ManagedChannel managedChannel) { + return new EventClientSync(managedChannel); + } +} diff --git a/packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java b/packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java new file mode 100644 index 000000000..5eef6e32d --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java @@ -0,0 +1,69 @@ +package armonik.client.event.impl; + +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionRequest; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse; +import armonik.api.grpc.v1.events.EventsGrpc; +import armonik.client.event.impl.util.factory.EventClientRequestFactory; +import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; +import armonik.client.event.spec.IEventClientAsync; +import io.grpc.ManagedChannel; +import io.grpc.stub.StreamObserver; + +import java.util.List; + +/** + * EventClientAsync is an asynchronous implementation of the {@link IEventClientAsync} interface. + * It communicates with the event service using a non-blocking stub, making asynchronous calls to wait for event updates. + */ +public class EventClientAsync implements IEventClientAsync { + private final EventsGrpc.EventsStub eventsStub; + + /** + * Constructs an EventClientAsync object with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the event service + */ + public EventClientAsync(ManagedChannel managedChannel) { + eventsStub = EventsGrpc.newStub(managedChannel); + } + + + /** + * Waits for event updates for the specified session ID and result IDs, and sends responses to the provided StreamObserver. + * + * @param sessionId the ID of the session for which event updates are awaited + * @param resultIds the list of result IDs for which event updates are awaited + * @param responseObserver a StreamObserver to handle the responses, containing entry of EventSubscriptionResponseRecord + */ + @Override + public void waitForEventsUpdateBySessionId(String sessionId, List resultIds, StreamObserver responseObserver) { + StreamObserver proxyObserver = new StreamObserver<>() { + @Override + public void onNext(EventSubscriptionResponse esr) { + responseObserver + .onNext( + new EventSubscriptionResponseRecord( + sessionId, + esr.getTaskStatusUpdate(), + esr.getResultStatusUpdate(), + esr.getResultOwnerUpdate(), + esr.getNewTask(), + esr.getNewResult() + ) + ); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + EventSubscriptionRequest request = EventClientRequestFactory.CreateEventSubscriptionRequest(sessionId, resultIds); + eventsStub.getEvents(request, proxyObserver); + } +} diff --git a/packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java b/packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java new file mode 100644 index 000000000..c55c4fb90 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java @@ -0,0 +1,58 @@ +package armonik.client.event.impl; + +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionRequest; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse; +import armonik.api.grpc.v1.events.EventsGrpc; +import armonik.api.grpc.v1.events.EventsGrpc.EventsBlockingStub; +import armonik.client.event.impl.util.factory.EventClientRequestFactory; +import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; +import armonik.client.event.spec.IEventClientSync; +import com.google.common.collect.Lists; +import io.grpc.ManagedChannel; + +import java.util.List; + +/** + * EventClientSync is a synchronous implementation of the {@link IEventClientSync} interface. + * It communicates with the event service using a blocking stub, making synchronous calls to retrieve event updates. + */ +public class EventClientSync implements IEventClientSync { + + private final EventsBlockingStub eventsBlockingStub; + + + /** + * Constructs an EventClientSync object with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the event service + */ + public EventClientSync(ManagedChannel managedChannel) { + this.eventsBlockingStub = EventsGrpc.newBlockingStub(managedChannel); + } + + + /** + * Retrieves event updates for the specified session ID and result IDs. + * + * @param sessionId the session ID for which event updates are requested + * @param resultIds the list of result IDs for which event updates are requested + * @return a list containing event update responses + */ + @Override + public List getEventsUpdateBySessionId(String sessionId, List resultIds) { + EventSubscriptionRequest request = EventClientRequestFactory.CreateEventSubscriptionRequest(sessionId, resultIds); + + List subscriptionResponses = Lists.newArrayList(eventsBlockingStub.getEvents(request)); + + return subscriptionResponses.stream() + .map( + esr -> new EventSubscriptionResponseRecord( + sessionId, + esr.getTaskStatusUpdate(), + esr.getResultStatusUpdate(), + esr.getResultOwnerUpdate(), + esr.getNewTask(), + esr.getNewResult()) + ).toList(); + } +} diff --git a/packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java b/packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java new file mode 100644 index 000000000..2f493d5cf --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java @@ -0,0 +1,52 @@ +package armonik.client.event.impl.util.factory; + +import armonik.api.grpc.v1.FiltersCommon; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionRequest; +import armonik.api.grpc.v1.results.ResultsFields; +import armonik.api.grpc.v1.results.ResultsFilters; + +import java.util.List; + +import static armonik.api.grpc.v1.events.EventsCommon.EventsEnum.EVENTS_ENUM_NEW_RESULT; +import static armonik.api.grpc.v1.events.EventsCommon.EventsEnum.EVENTS_ENUM_RESULT_STATUS_UPDATE; +import static armonik.api.grpc.v1.results.ResultsFields.ResultRawEnumField.RESULT_RAW_ENUM_FIELD_RESULT_ID; + +/** + * EventClientRequestFactory provides static methods to create event subscription requests. + * It constructs EventSubscriptionRequest objects based on provided session ID and result IDs. + */ +public class EventClientRequestFactory { + + /** + * Creates an event subscription request with the specified session ID and result IDs. + * + * @param sessionId the session ID for which event subscription is requested + * @param resultIds the list of result IDs to filter events + * @return an EventSubscriptionRequest object configured with the provided session ID and result IDs + */ + public static EventSubscriptionRequest CreateEventSubscriptionRequest(String sessionId, List resultIds){ + FiltersCommon.FilterString filterString = FiltersCommon.FilterString.newBuilder() + .setOperator(FiltersCommon.FilterStringOperator.FILTER_STRING_OPERATOR_EQUAL) + .build(); + + ResultsFields.ResultField.Builder resultField = ResultsFields.ResultField.newBuilder() + .setResultRawField(ResultsFields.ResultRawField.newBuilder().setField(RESULT_RAW_ENUM_FIELD_RESULT_ID)); + + ResultsFilters.FilterField.Builder filterFieldBuilder = ResultsFilters.FilterField.newBuilder() + .setField(resultField) + .setFilterString(filterString); + + ResultsFilters.Filters.Builder resultFiltersBuilder = ResultsFilters.Filters.newBuilder(); + for (String resultId : resultIds) { + filterFieldBuilder.setFilterString(FiltersCommon.FilterString.newBuilder().setValue(resultId).build()); + resultFiltersBuilder.addOr(ResultsFilters.FiltersAnd.newBuilder().addAnd(filterFieldBuilder).build()); + } + + return EventSubscriptionRequest.newBuilder() + .setResultsFilters(resultFiltersBuilder.build()) + .addReturnedEvents(EVENTS_ENUM_RESULT_STATUS_UPDATE) + .addReturnedEvents(EVENTS_ENUM_NEW_RESULT) + .setSessionId(sessionId) + .build(); + } +} diff --git a/packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java b/packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java new file mode 100644 index 000000000..29a8aab5e --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java @@ -0,0 +1,16 @@ +package armonik.client.event.impl.util.records; + +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse.*; + +/** + * EventUpdateResponse represents the response containing updates for various event-related entities. + * It encapsulates changes in task status, result status, result owner, new task, and new result. + */ +public record EventSubscriptionResponseRecord(String sessionId, + TaskStatusUpdate taskStatusUpdate, + ResultStatusUpdate resultStatusUpdate, + ResultOwnerUpdate resultOwnerUpdate, + NewTask newTask, + NewResult newResult + ) { +} diff --git a/packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java b/packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java new file mode 100644 index 000000000..e844c1522 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java @@ -0,0 +1,10 @@ +package armonik.client.event.spec; + +import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; +import io.grpc.stub.StreamObserver; + +import java.util.List; + +public interface IEventClientAsync { + void waitForEventsUpdateBySessionId(String sessionId, List resultIds, StreamObserver responseObserver); +} diff --git a/packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java b/packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java new file mode 100644 index 000000000..098103e62 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java @@ -0,0 +1,10 @@ +package armonik.client.event.spec; + +import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; + +import java.util.List; + +public interface IEventClientSync { + List getEventsUpdateBySessionId(String sessionId, List resultIds); + +} diff --git a/packages/java/src/main/java/armonik/client/result/ResultClientFactory.java b/packages/java/src/main/java/armonik/client/result/ResultClientFactory.java new file mode 100644 index 000000000..57e61d3f5 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/ResultClientFactory.java @@ -0,0 +1,32 @@ +package armonik.client.result; + +import armonik.client.result.impl.ResultClientAsync; +import armonik.client.result.impl.ResultClientSync; +import armonik.client.result.spec.IResultClientAsync; +import armonik.client.result.spec.IResultClientSync; +import io.grpc.ManagedChannel; + +/** + * ResultClientFactory provides static factory methods to create instances of result client implementations. + */ +public abstract class ResultClientFactory { + /** + * Creates a synchronous result client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the result service + * @return an instance of {@link IResultClientSync} representing a synchronous result client + */ + public static IResultClientSync createResultClientSync(ManagedChannel managedChannel) { + return new ResultClientSync(managedChannel); + } + + /** + * Creates an asynchronous result client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the result service + * @return an instance of {@link IResultClientAsync} representing an asynchronous result client + */ + public static IResultClientAsync createResultClientAsync(ManagedChannel managedChannel) { + return new ResultClientAsync(managedChannel); + } +} diff --git a/packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java b/packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java new file mode 100644 index 000000000..bab5be18a --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java @@ -0,0 +1,277 @@ +package armonik.client.result.impl; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.results.ResultsCommon; +import armonik.api.grpc.v1.results.ResultsCommon.*; +import armonik.api.grpc.v1.results.ResultsFilters; +import armonik.api.grpc.v1.results.ResultsGrpc; +import armonik.api.grpc.v1.results.ResultsGrpc.ResultsStub; +import armonik.client.result.impl.util.factory.ResultClientRequestFactory; +import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; +import armonik.client.result.impl.util.records.WatchResultResponseRecord; +import armonik.client.result.spec.IResultClientAsync; +import io.grpc.ManagedChannel; +import io.grpc.stub.StreamObserver; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * ResultClientAsync is an asynchronous implementation of the {@link IResultClientAsync} interface. + * It communicates with the result service using a non-blocking stub, making asynchronous calls to perform various result-related operations. + */ +public class ResultClientAsync implements IResultClientAsync { + private final ResultsStub resultsStub; + + public ResultClientAsync(ManagedChannel managedChannel) { + this.resultsStub = ResultsGrpc.newStub(managedChannel); + } + + @Override + public StreamObserver watchResults(StreamObserver responseObserver) { + StreamObserver proxyObserver = new StreamObserver<>() { + @Override + public void onNext(WatchResultResponse watchResultResponse) { + responseObserver.onNext(new WatchResultResponseRecord(watchResultResponse.getStatus(), watchResultResponse.getResultIdsList())); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + return resultsStub.watchResults(proxyObserver); + } + + @Override + public void getServiceConfiguration(StreamObserver responseObserver) { + StreamObserver observer = new StreamObserver() { + @Override + public void onNext(ResultsServiceConfigurationResponse resultsServiceConfigurationResponse) { + responseObserver.onNext(resultsServiceConfigurationResponse.getDataChunkMaxSize()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + resultsStub.getServiceConfiguration(Objects.Empty.newBuilder().build(), observer); + } + + + @Override + public void deleteResultsData(String sessionId, List resultIds, StreamObserver responseObserver) { + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(DeleteResultsDataResponse deleteResultsDataResponse) { + responseObserver.onNext(new DeleteResultsDataResponseRecord(sessionId, deleteResultsDataResponse.getResultIdList())); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + ResultsCommon.DeleteResultsDataRequest request = ResultClientRequestFactory.createDeleteResultsDataRequest(sessionId, resultIds); + + + resultsStub.deleteResultsData(request, observer); + } + + @Override + public void downloadResultData(String sessionId, String resultId, StreamObserver responseObserver) { + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(DownloadResultDataResponse downloadResultDataResponse) { + responseObserver.onNext(downloadResultDataResponse.getDataChunk().toByteArray()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + DownloadResultDataRequest request = ResultClientRequestFactory.createDownloadResultDataRequest(sessionId, resultId); + + + resultsStub.downloadResultData(request, observer); + } + + + @Override + public StreamObserver uploadResultData(String sessionId, String resultId, String payload, StreamObserver responseObserver) { + StreamObserver proxyObserver = new StreamObserver<>() { + @Override + public void onNext(UploadResultDataResponse uploadResultDataResponse) { + responseObserver.onNext(uploadResultDataResponse.getResult()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + return resultsStub.uploadResultData(proxyObserver); + + } + + @Override + public void createResults(CreateResultsRequest request, StreamObserver> responseObserver) { + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(CreateResultsResponse createResultsResponse) { + responseObserver + .onNext( + createResultsResponse + .getResultsList() + .stream() + .collect(Collectors.toMap(ResultRaw::getName, ResultRaw::getResultId)) + ); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + resultsStub.createResults(request, observer); + } + + @Override + public void createResultsMetaData(String sessionId, List names, StreamObserver> responseObserver) { + CreateResultsMetaDataRequest request = ResultClientRequestFactory.createCreateResultsMetaDataRequest(sessionId, names); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(CreateResultsMetaDataResponse createResultsMetaDataResponse) { + responseObserver.onNext(createResultsMetaDataResponse.getResultsList()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + resultsStub.createResultsMetaData(request, observer); + } + + @Override + public void getOwnerTaskId(String sessionId, List resultIds, StreamObserver> responseObserver) { + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(GetOwnerTaskIdResponse getOwnerTaskIdResponse) { + responseObserver.onNext(getOwnerTaskIdResponse.getResultTaskList() + .stream() + .collect(Collectors.toMap(GetOwnerTaskIdResponse.MapResultTask::getResultId, GetOwnerTaskIdResponse.MapResultTask::getTaskId))); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + GetOwnerTaskIdRequest request = ResultClientRequestFactory.createGetOwnerTaskIdRequest(sessionId, resultIds); + + + resultsStub.getOwnerTaskId(request, observer); + } + + + @Override + public void getResult(String resultId, StreamObserver responseObserver) { + StreamObserver observer = new StreamObserver() { + @Override + public void onNext(GetResultResponse getResultResponse) { + responseObserver.onNext(getResultResponse.getResult()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + GetResultRequest request = ResultClientRequestFactory.createGetResultRequest(resultId); + + resultsStub.getResult(request, observer); + } + + + @Override + public void listResults(ResultsFilters.Filters filters, int total, int page, int pageSize, ListResultsRequest.Sort sort, StreamObserver> responseObserver) { + StreamObserver observer = new StreamObserver() { + @Override + public void onNext(ListResultsResponse listResultsResponse) { + responseObserver.onNext(listResultsResponse.getResultsList()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + ListResultsRequest request = ResultClientRequestFactory.createListResultsRequest(filters, total, page, pageSize, sort); + + resultsStub.listResults(request, observer); + } +} diff --git a/packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java b/packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java new file mode 100644 index 000000000..77f5f0c4f --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java @@ -0,0 +1,88 @@ +package armonik.client.result.impl; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.results.ResultsCommon.*; +import armonik.api.grpc.v1.results.ResultsCommon.GetOwnerTaskIdResponse.MapResultTask; +import armonik.api.grpc.v1.results.ResultsCommon.ListResultsRequest.Sort; +import armonik.api.grpc.v1.results.ResultsGrpc; +import armonik.client.result.impl.util.factory.ResultClientRequestFactory; +import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; +import armonik.client.result.spec.IResultClientSync; +import io.grpc.ManagedChannel; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static armonik.api.grpc.v1.results.ResultsFilters.*; + +/** + * ResultClientSync is a synchronous implementation of the {@link IResultClientSync} interface. + * It communicates with the result service using a blocking stub, making synchronous calls to interact with result data. + */ +public class ResultClientSync implements IResultClientSync { + private final ResultsGrpc.ResultsBlockingStub resultsBlockingStub; + + public ResultClientSync(ManagedChannel managedChannel) { + this.resultsBlockingStub = ResultsGrpc.newBlockingStub(managedChannel); + } + + @Override + public int getServiceConfiguration() { + return resultsBlockingStub.getServiceConfiguration(Objects.Empty.newBuilder().build()).getDataChunkMaxSize(); + } + + @Override + public DeleteResultsDataResponseRecord deleteResultsData(String sessionId, List resultIds) { + DeleteResultsDataRequest request = ResultClientRequestFactory.createDeleteResultsDataRequest(sessionId, resultIds); + return new DeleteResultsDataResponseRecord(sessionId, resultsBlockingStub.deleteResultsData(request).getResultIdList()); + } + + + @Override + public List downloadResultData(String sessionId, String resultId) { + DownloadResultDataRequest request = ResultClientRequestFactory.createDownloadResultDataRequest(sessionId, resultId); + Iterator iterator = resultsBlockingStub.downloadResultData(request); + List list = new ArrayList<>(); + + iterator.forEachRemaining(list::add); + return list.stream().map(downloadResultDataResponse -> downloadResultDataResponse.getDataChunk().toByteArray()) + .toList(); + } + + @Override + public Map createResults(CreateResultsRequest request) { + return resultsBlockingStub.createResults(request).getResultsList() + .stream() + .collect(Collectors.toMap(ResultRaw::getName,ResultRaw::getResultId)); + } + + + @Override + public List createResultsMetaData(String sessionId, List names) { + CreateResultsMetaDataRequest request = ResultClientRequestFactory.createCreateResultsMetaDataRequest(sessionId, names); + return resultsBlockingStub.createResultsMetaData(request).getResultsList(); + } + + @Override + public Map getOwnerTaskId(String sessionId, List resultIds) { + GetOwnerTaskIdRequest request = ResultClientRequestFactory.createGetOwnerTaskIdRequest(sessionId, resultIds); + return resultsBlockingStub.getOwnerTaskId(request).getResultTaskList() + .stream() + .collect(Collectors.toMap(MapResultTask::getResultId, MapResultTask::getTaskId)); + } + + @Override + public ResultRaw getResult(String resultId) { + GetResultRequest request = ResultClientRequestFactory.createGetResultRequest(resultId); + return resultsBlockingStub.getResult(request).getResult(); + } + + @Override + public List listResults(Filters filters, int total, int page, int pageSize, Sort sort) { + ListResultsRequest request = ResultClientRequestFactory.createListResultsRequest(filters, total, page, pageSize, sort); + return resultsBlockingStub.listResults(request).getResultsList(); + } +} diff --git a/packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java b/packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java new file mode 100644 index 000000000..b3d266437 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java @@ -0,0 +1,60 @@ +package armonik.client.result.impl.util.factory; + +import armonik.api.grpc.v1.results.ResultsCommon.*; +import armonik.api.grpc.v1.results.ResultsCommon.ListResultsRequest.Sort; +import armonik.api.grpc.v1.results.ResultsFilters.Filters; + +import java.util.List; + +public abstract class ResultClientRequestFactory { + + public static DeleteResultsDataRequest createDeleteResultsDataRequest(String sessionId, List resultIds) { + return DeleteResultsDataRequest.newBuilder() + .setSessionId(sessionId) + .addAllResultId(resultIds) + .build(); + } + + public static DownloadResultDataRequest createDownloadResultDataRequest(String sessionId, String resultId) { + return DownloadResultDataRequest.newBuilder() + .setSessionId(sessionId) + .setResultId(resultId) + .build(); + } + + + public static CreateResultsMetaDataRequest createCreateResultsMetaDataRequest(String sessionId, List names) { + return CreateResultsMetaDataRequest.newBuilder() + .setSessionId(sessionId) + .addAllResults(names.stream().map(name -> CreateResultsMetaDataRequest.ResultCreate.newBuilder().setName(name).build()).toList()) + .build(); + + } + + public static GetOwnerTaskIdRequest createGetOwnerTaskIdRequest(String sessionId, List resultIds) { + return GetOwnerTaskIdRequest.newBuilder() + .setSessionId(sessionId) + .addAllResultId(resultIds) + .build(); + + } + + public static GetResultRequest createGetResultRequest(String resultId) { + return GetResultRequest.newBuilder() + .setResultId(resultId) + .build(); + } + + public static ListResultsRequest createListResultsRequest(Filters filters, int total, int page, int pageSize, Sort sort) { + return ListResultsRequest.newBuilder() + .setFilters(filters) + .setSort(sort) + .setPage(page) + .setPageSize(pageSize) + .build(); + + + } + + +} diff --git a/packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java b/packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java new file mode 100644 index 000000000..b9ff6ccf0 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java @@ -0,0 +1,6 @@ +package armonik.client.result.impl.util.records; + +import java.util.List; + +public record DeleteResultsDataResponseRecord(String sessionId, List deletedResultIds) { +} diff --git a/packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java b/packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java new file mode 100644 index 000000000..3dddeeed7 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java @@ -0,0 +1,8 @@ +package armonik.client.result.impl.util.records; + +import armonik.api.grpc.v1.result_status.ResultStatusOuterClass; + +import java.util.List; + +public record WatchResultResponseRecord(ResultStatusOuterClass.ResultStatus resultStatus, List resultIds) { +} diff --git a/packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java b/packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java new file mode 100644 index 000000000..575f35194 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java @@ -0,0 +1,32 @@ +package armonik.client.result.spec; + +import armonik.api.grpc.v1.results.ResultsCommon; +import armonik.api.grpc.v1.results.ResultsFilters; +import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; +import armonik.client.result.impl.util.records.WatchResultResponseRecord; +import io.grpc.stub.StreamObserver; + +import java.util.List; +import java.util.Map; + +public interface IResultClientAsync { + StreamObserver watchResults(StreamObserver responseObserver); + + void getServiceConfiguration(StreamObserver responseObserver); + + void deleteResultsData(String sessionId, List resultIds, StreamObserver responseObserver); + + void downloadResultData(String sessionId, String resultId, StreamObserver responseObserver); + + StreamObserver uploadResultData(String sessionId, String resultId, String payload, StreamObserver responseObserver); + + void createResults(ResultsCommon.CreateResultsRequest request, StreamObserver> responseObserver); + + void createResultsMetaData(String sessionId, List names, StreamObserver> responseObserver); + + void getOwnerTaskId(String sessionId, List resultIds, StreamObserver> responseObserver); + + void getResult(String resultId, StreamObserver responseObserver); + + void listResults(ResultsFilters.Filters filters, int total, int page, int pageSize, ResultsCommon.ListResultsRequest.Sort sort, StreamObserver> responseObserver); +} diff --git a/packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java b/packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java new file mode 100644 index 000000000..d96638e19 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java @@ -0,0 +1,26 @@ +package armonik.client.result.spec; + +import armonik.api.grpc.v1.results.ResultsCommon; +import armonik.api.grpc.v1.results.ResultsFilters; +import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; + +import java.util.List; +import java.util.Map; + +public interface IResultClientSync { + int getServiceConfiguration(); + + DeleteResultsDataResponseRecord deleteResultsData(String sessionId, List resultIds); + + List downloadResultData(String sessionId, String resultId); + + Map createResults(ResultsCommon.CreateResultsRequest request); + + List createResultsMetaData(String sessionId, List names); + + Map getOwnerTaskId(String sessionId, List resultIds); + + ResultsCommon.ResultRaw getResult(String resultId); + + List listResults(ResultsFilters.Filters filters, int total, int page, int pageSize, ResultsCommon.ListResultsRequest.Sort sort); +} diff --git a/packages/java/src/main/java/armonik/client/session/SessionClientFactory.java b/packages/java/src/main/java/armonik/client/session/SessionClientFactory.java new file mode 100644 index 000000000..e34674bb1 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/session/SessionClientFactory.java @@ -0,0 +1,33 @@ +package armonik.client.session; + +import armonik.client.session.impl.SessionClientAsync; +import armonik.client.session.impl.SesssionClientSync; +import armonik.client.session.spec.ISessionClientAsync; +import armonik.client.session.spec.ISessionClientSync; +import io.grpc.ManagedChannel; + +/** + * SessionClientFactory provides static factory methods to create instances of session client implementations. + */ +public abstract class SessionClientFactory { + + /** + * Creates an asynchronous session client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the session service + * @return an instance of {@link ISessionClientAsync} representing an asynchronous session client + */ + public static ISessionClientAsync createSessionClientAsync(ManagedChannel managedChannel) { + return new SessionClientAsync(managedChannel); + } + + /** + * Creates a synchronous session client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the session service + * @return an instance of {@link ISessionClientSync} representing a synchronous session client + */ + public static ISessionClientSync createSesssionClientSync(ManagedChannel managedChannel) { + return new SesssionClientSync(managedChannel); + } +} diff --git a/packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java b/packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java new file mode 100644 index 000000000..f3f254287 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java @@ -0,0 +1,269 @@ +package armonik.client.session.impl; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.sessions.SessionsCommon; +import armonik.api.grpc.v1.sessions.SessionsCommon.*; +import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; +import armonik.api.grpc.v1.sessions.SessionsFilters.Filters; +import armonik.api.grpc.v1.sessions.SessionsGrpc; +import armonik.api.grpc.v1.sessions.SessionsGrpc.SessionsStub; +import armonik.client.session.impl.util.SessionClientRequestFactory; +import armonik.client.session.spec.ISessionClientAsync; +import io.grpc.ManagedChannel; +import io.grpc.stub.StreamObserver; + +import java.util.List; + +public class SessionClientAsync implements ISessionClientAsync { + private final SessionsStub sessionsStub; + + /** + * Constructs a new ArmonikSession object using the provided gRPC ManagedChannel. + * + * @param managedChannel The gRPC ManagedChannel to communicate with the Armonik service. + */ + + public SessionClientAsync(ManagedChannel managedChannel) { + sessionsStub = SessionsGrpc.newStub(managedChannel); + } + + @Override + public void createSession(Objects.TaskOptions taskOptions, List partitionIds, StreamObserver streamObserver) { + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(CreateSessionReply createSessionReply) { + streamObserver.onNext(createSessionReply.getSessionId()); + } + + @Override + public void onError(Throwable throwable) { + streamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + streamObserver.onCompleted(); + } + }; + + List partIds = partitionIds == null || partitionIds.isEmpty() ? null : partitionIds; + SessionsCommon.CreateSessionRequest request = SessionsCommon.CreateSessionRequest.newBuilder() + .setDefaultTaskOption(taskOptions) + .addAllPartitionIds(partIds) + .build(); + sessionsStub.createSession(request, observer); + } + + + @Override + public void getSession(String sessionId, StreamObserver rawStreamObserver) { + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(GetSessionResponse getSessionResponse) { + rawStreamObserver.onNext(getSessionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + rawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + rawStreamObserver.onCompleted(); + } + }; + + GetSessionRequest request = SessionClientRequestFactory.createGetSessionRequest(sessionId); + + + sessionsStub.getSession(request, observer); + } + + @Override + public void listSessions(int page, int pageSize, Filters filter, Sort sort, StreamObserver> listStreamObserver) { + ListSessionsRequest request = SessionClientRequestFactory.createListSessionsRequest(page, pageSize, filter, sort); + StreamObserver observer = new StreamObserver() { + @Override + public void onNext(ListSessionsResponse listSessionsResponse) { + listStreamObserver.onNext(listSessionsResponse.getSessionsList()); + } + + @Override + public void onError(Throwable throwable) { + listStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + listStreamObserver.onCompleted(); + } + }; + sessionsStub.listSessions(request, observer); + } + + @Override + public void cancelSession(String sessionId, StreamObserver sessionRawStreamObserver) throws Exception { + CancelSessionRequest request = SessionClientRequestFactory.createCancelSessionRequest(sessionId); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(CancelSessionResponse cancelSessionResponse) { + sessionRawStreamObserver.onNext(cancelSessionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + sessionRawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + sessionRawStreamObserver.onCompleted(); + } + }; + sessionsStub.cancelSession(request,observer); + } + + @Override + public void pauseSession(String sessionId, StreamObserver sessionRawStreamObserver) { + PauseSessionRequest request = SessionClientRequestFactory.createPauseSessionRequest(sessionId); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(PauseSessionResponse pauseSessionResponse) { + sessionRawStreamObserver.onNext(pauseSessionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + sessionRawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + sessionRawStreamObserver.onCompleted(); + } + }; + sessionsStub.pauseSession(request,observer); + } + + @Override + public void resumeSession(String sessionId, StreamObserver sessionRawStreamObserver) { + ResumeSessionRequest request = SessionClientRequestFactory.createResumeSessionRequest(sessionId); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(ResumeSessionResponse resumeSessionResponse) { + sessionRawStreamObserver.onNext(resumeSessionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + sessionRawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + sessionRawStreamObserver.onCompleted(); + } + }; + sessionsStub.resumeSession(request,observer); + } + + @Override + public void closeSession(String sessionId, StreamObserver sessionRawStreamObserver){ + CloseSessionRequest closeSessionRequest = SessionClientRequestFactory.createCloseSessionRequest(sessionId); + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(CloseSessionResponse closeSessionResponse) { + sessionRawStreamObserver.onNext(closeSessionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + sessionRawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + sessionRawStreamObserver.onCompleted(); + } + }; + sessionsStub.closeSession(closeSessionRequest,observer); + } + + @Override + public void purgeSession(String sessionId, StreamObserver sessionRawStreamObserver){ + PurgeSessionRequest purgeSessionRequest = SessionClientRequestFactory.createPurgeSessionRequest(sessionId); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(PurgeSessionResponse purgeSessionResponse) { + sessionRawStreamObserver.onNext(purgeSessionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + sessionRawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + sessionRawStreamObserver.onCompleted(); + } + }; + sessionsStub.purgeSession(purgeSessionRequest,observer); + } + + @Override + public void deleteSession(String sessionId, StreamObserver sessionRawStreamObserver){ + DeleteSessionRequest deleteSessionRequest = SessionClientRequestFactory.createDeleteSessionRequest(sessionId); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(DeleteSessionResponse deleteSessionResponse) { + sessionRawStreamObserver.onNext(deleteSessionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + sessionRawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + sessionRawStreamObserver.onCompleted(); + } + }; + + sessionsStub.deleteSession(deleteSessionRequest,observer); + } + + @Override + public void stopSubmissionSession(String sessionId, boolean client, boolean worker, StreamObserver sessionRawStreamObserver){ + StopSubmissionRequest request = SessionClientRequestFactory.createStopSubmissionSessionRequest(sessionId, client, worker); + + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(StopSubmissionResponse stopSubmissionResponse) { + sessionRawStreamObserver.onNext(stopSubmissionResponse.getSession()); + } + + @Override + public void onError(Throwable throwable) { + sessionRawStreamObserver.onError(throwable); + } + + @Override + public void onCompleted() { + sessionRawStreamObserver.onCompleted(); + } + }; + sessionsStub.stopSubmission(request,observer); + } + + + +} diff --git a/packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java b/packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java new file mode 100644 index 000000000..45f405a6d --- /dev/null +++ b/packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java @@ -0,0 +1,162 @@ +/** + * ArmonikSession provides a client interface to interact with Armonik session management functionality. + * This class allows creating, retrieving, listing, canceling, pausing, resuming, closing, purging, deleting, + * and stopping submissions for sessions in the Armonik system. + */ + +package armonik.client.session.impl; + +import armonik.api.grpc.v1.Objects.TaskOptions; +import armonik.api.grpc.v1.sessions.SessionsCommon.*; +import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; +import armonik.api.grpc.v1.sessions.SessionsFilters.Filters; +import armonik.api.grpc.v1.sessions.SessionsGrpc; +import armonik.client.session.impl.util.SessionClientRequestFactory; +import armonik.client.session.spec.ISessionClientSync; +import io.grpc.ManagedChannel; + +import java.util.List; + +public class SesssionClientSync implements ISessionClientSync { + private final SessionsGrpc.SessionsBlockingStub sessionsStub; + + /** + * Constructs a new ArmonikSession object using the provided gRPC ManagedChannel. + * + * @param managedChannel The gRPC ManagedChannel to communicate with the Armonik service. + */ + + public SesssionClientSync(ManagedChannel managedChannel){ + sessionsStub = SessionsGrpc.newBlockingStub(managedChannel); + } + + /** + * Creates a new session in the Armonik system with the given task options and partition IDs. + * + * @param taskOptions The task options for the session. + * @param partitionIds The list of partition IDs. + * @return The ID of the created session. + */ + @Override + public String createSession(TaskOptions taskOptions, List partitionIds) { + CreateSessionRequest request = SessionClientRequestFactory.createSessionRequest(taskOptions, partitionIds); + return sessionsStub.createSession(request).getSessionId(); + } + + + + /** + * Retrieves session information for the specified session ID. + * + * @param sessionId The ID of the session to retrieve. + * @return The session information. + */ + @Override + public SessionRaw getSession(String sessionId) { + GetSessionRequest request = SessionClientRequestFactory.createGetSessionRequest(sessionId); + return sessionsStub.getSession(request).getSession(); + } + + /** + * Lists sessions based on pagination, filters, and sorting options. + * + * @param page The page number. + * @param pageSize The size of each page. + * @param filter The filters to apply. + * @param sort The sorting options. + * @return A ListSessionsResult object containing the list of sessions and total count. + */ + @Override + public List listSessions(int page, int pageSize, Filters filter, Sort sort) { + ListSessionsRequest request = SessionClientRequestFactory.createListSessionsRequest(page, pageSize, filter, sort); + return sessionsStub.listSessions(request).getSessionsList(); + } + + /** + * Cancels the session with the specified session ID. + * + * @param sessionId The ID of the session to cancel. + * @return The updated session information after cancellation. + */ + @Override + public SessionRaw cancelSession(String sessionId) { + CancelSessionRequest request = SessionClientRequestFactory.createCancelSessionRequest(sessionId); + return sessionsStub.cancelSession(request).getSession(); + } + + /** + * Pauses the session with the specified session ID. + * + * @param sessionId The ID of the session to pause. + * @return The updated session information after pausing. + */ + @Override + public SessionRaw pauseSession(String sessionId) { + PauseSessionRequest request = SessionClientRequestFactory.createPauseSessionRequest(sessionId); + return sessionsStub.pauseSession(request).getSession(); + } + + /** + * Resumes the session with the specified session ID. + * + * @param sessionId The ID of the session to resume. + * @return The updated session information after resuming. + */ + @Override + public SessionRaw resumeSession(String sessionId) { + ResumeSessionRequest request = SessionClientRequestFactory.createResumeSessionRequest(sessionId); + return sessionsStub.resumeSession(request).getSession(); + } + + /** + * Closes the session with the specified session ID. + * + * @param sessionId The ID of the session to close. + * @return the closed session + */ + @Override + public SessionRaw closeSession(String sessionId){ + CloseSessionRequest closeSessionRequest = SessionClientRequestFactory.createCloseSessionRequest(sessionId); + return sessionsStub.closeSession(closeSessionRequest).getSession(); + } + + /** + * Purges the session with the specified session ID. + * + * @param sessionId The ID of the session to purge. + * @return The updated session information after purging. + */ + @Override + public SessionRaw purgeSession(String sessionId){ + PurgeSessionRequest purgeSessionRequest = SessionClientRequestFactory.createPurgeSessionRequest(sessionId); + return sessionsStub.purgeSession(purgeSessionRequest).getSession(); + } + + /** + * Deletes the session with the specified session ID. + * + * @param sessionId The ID of the session to delete. + * @return The updated session information after deletion. + */ + @Override + public SessionRaw deleteSession(String sessionId){ + DeleteSessionRequest deleteSessionRequest = SessionClientRequestFactory.createDeleteSessionRequest(sessionId); + return sessionsStub.deleteSession(deleteSessionRequest).getSession(); + } + + /** + * Stops submission for the session with the specified session ID. + * + * @param sessionId The ID of the session to stop submission for. + * @param client Boolean indicating whether to stop client submissions. + * @param worker Boolean indicating whether to stop worker submissions. + * @return The updated session information after stopping submissions. + */ + @Override + public SessionRaw stopSubmissionSession(String sessionId, boolean client, boolean worker){ + StopSubmissionRequest request = SessionClientRequestFactory.createStopSubmissionSessionRequest(sessionId, client, worker); + return sessionsStub.stopSubmission(request).getSession(); + } + + +} diff --git a/packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java b/packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java new file mode 100644 index 000000000..88759ea19 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java @@ -0,0 +1,69 @@ +package armonik.client.session.impl.util; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.sessions.SessionsCommon.*; +import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; +import armonik.api.grpc.v1.sessions.SessionsFilters; + +import java.util.List; + +public abstract class SessionClientRequestFactory { + + + public static CreateSessionRequest createSessionRequest(Objects.TaskOptions taskOptions, List partitionIds) { + List partIds = partitionIds == null || partitionIds.isEmpty() ? null : partitionIds; + return CreateSessionRequest.newBuilder() + .setDefaultTaskOption(taskOptions) + .addAllPartitionIds(partIds) + .build(); + } + + public static GetSessionRequest createGetSessionRequest(String sessionId) { + return GetSessionRequest + .newBuilder() + .setSessionId(sessionId) + .build(); + } + + public static ListSessionsRequest createListSessionsRequest(int page, int pageSize, SessionsFilters.Filters filter, Sort sort) { + return ListSessionsRequest.newBuilder() + .setPage(page) + .setPageSize(pageSize) + .setFilters(filter) + .setSort(sort) + .build(); + } + + public static CancelSessionRequest createCancelSessionRequest(String sessionId) { + return CancelSessionRequest.newBuilder().setSessionId(sessionId).build(); + } + + public static PauseSessionRequest createPauseSessionRequest(String sessionId) { + return PauseSessionRequest.newBuilder().setSessionId(sessionId).build(); + } + + public static ResumeSessionRequest createResumeSessionRequest(String sessionId) { + return ResumeSessionRequest.newBuilder().setSessionId(sessionId).build(); + } + + public static CloseSessionRequest createCloseSessionRequest(String sessionId) { + return CloseSessionRequest.newBuilder().setSessionId(sessionId).build(); + } + + public static PurgeSessionRequest createPurgeSessionRequest(String sessionId) { + return PurgeSessionRequest.newBuilder().setSessionId(sessionId).build(); + + } + + public static DeleteSessionRequest createDeleteSessionRequest(String sessionId) { + return DeleteSessionRequest.newBuilder().setSessionId(sessionId).build(); + } + + public static StopSubmissionRequest createStopSubmissionSessionRequest(String sessionId, boolean client, boolean worker) { + return StopSubmissionRequest.newBuilder() + .setSessionId(sessionId) + .setClient(client) + .setWorker(worker) + .build(); + } +} diff --git a/packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java b/packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java new file mode 100644 index 000000000..6c871222d --- /dev/null +++ b/packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java @@ -0,0 +1,30 @@ +package armonik.client.session.spec; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.sessions.SessionsCommon; +import armonik.api.grpc.v1.sessions.SessionsFilters; +import io.grpc.stub.StreamObserver; + +import java.util.List; + +public interface ISessionClientAsync { + void createSession(Objects.TaskOptions taskOptions, List partitionIds, StreamObserver streamObserver); + + void getSession(String sessionId, StreamObserver rawStreamObserver); + + void listSessions(int page, int pageSize, SessionsFilters.Filters filter, SessionsCommon.ListSessionsRequest.Sort sort, StreamObserver> listStreamObserver); + + void cancelSession(String sessionId, StreamObserver sessionRawStreamObserver) throws Exception; + + void pauseSession(String sessionId, StreamObserver sessionRawStreamObserver); + + void resumeSession(String sessionId, StreamObserver sessionRawStreamObserver); + + void closeSession(String sessionId, StreamObserver sessionRawStreamObserver); + + void purgeSession(String sessionId, StreamObserver sessionRawStreamObserver); + + void deleteSession(String sessionId, StreamObserver sessionRawStreamObserver); + + void stopSubmissionSession(String sessionId, boolean client, boolean worker, StreamObserver sessionRawStreamObserver); +} diff --git a/packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java b/packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java new file mode 100644 index 000000000..4d6efe115 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java @@ -0,0 +1,52 @@ +package armonik.client.session.spec; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; +import armonik.api.grpc.v1.sessions.SessionsCommon.SessionRaw; +import armonik.api.grpc.v1.sessions.SessionsFilters.Filters; + +import java.util.List; + +public interface ISessionClientSync { + default String createSession(Objects.TaskOptions taskOptions, List partitionIds) { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw getSession(String sessionId) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default List listSessions(int page, int pageSize, Filters filter, Sort sort) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw cancelSession(String sessionId) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw pauseSession(String sessionId) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw resumeSession(String sessionId) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw closeSession(String sessionId) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw purgeSession(String sessionId) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw deleteSession(String sessionId) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + default SessionRaw stopSubmissionSession(String sessionId, boolean client, boolean worker) throws Exception { + throw new UnsupportedOperationException("Method not implemented"); + } + + +} diff --git a/packages/java/src/main/java/armonik/client/task/TaskClientFactory.java b/packages/java/src/main/java/armonik/client/task/TaskClientFactory.java new file mode 100644 index 000000000..3c6e543e9 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/task/TaskClientFactory.java @@ -0,0 +1,33 @@ +package armonik.client.task; + +import armonik.client.task.impl.TaskClientAsync; +import armonik.client.task.impl.TaskClientSync; +import armonik.client.task.spec.ITaskClientAsync; +import armonik.client.task.spec.ITaskClientSync; +import io.grpc.ManagedChannel; + +/** + * TaskClientFactory provides factory methods to create instances of task client implementations. + */ +public abstract class TaskClientFactory { + + /** + * Creates a synchronous task client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the task service + * @return an instance of {@link ITaskClientSync} representing a synchronous task client + */ + public static ITaskClientSync createTaskClientSync(ManagedChannel managedChannel){ + return new TaskClientSync(managedChannel); + } + + /** + * Creates an asynchronous task client instance with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the task service + * @return an instance of {@link ITaskClientAsync} representing an asynchronous task client + */ + public static ITaskClientAsync createTaskClientAsync(ManagedChannel managedChannel){ + return new TaskClientAsync(managedChannel); + } +} diff --git a/packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java b/packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java new file mode 100644 index 000000000..d164288d2 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java @@ -0,0 +1,203 @@ +package armonik.client.task.impl; + +import armonik.api.grpc.v1.Objects.TaskOptions; +import armonik.api.grpc.v1.tasks.TasksCommon.*; +import armonik.api.grpc.v1.tasks.TasksCommon.GetResultIdsResponse.MapTaskResult; +import armonik.api.grpc.v1.tasks.TasksCommon.ListTasksRequest.Sort; +import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksRequest.TaskCreation; +import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksResponse.TaskInfo; +import armonik.api.grpc.v1.tasks.TasksFilters.Filters; +import armonik.api.grpc.v1.tasks.TasksGrpc; +import armonik.api.grpc.v1.tasks.TasksGrpc.TasksStub; +import armonik.client.task.impl.util.TaskClientRequestFactory; +import armonik.client.task.spec.ITaskClientAsync; +import io.grpc.ManagedChannel; +import io.grpc.stub.StreamObserver; + +import java.util.List; + +/** + * TaskClientAsync is an asynchronous implementation of the {@link ITaskClientAsync} interface. + * It communicates with the task service using a non-blocking stub, making asynchronous calls to perform various task-related operations. + */ +public class TaskClientAsync implements ITaskClientAsync { + private final TasksStub taskStub; + + + /** + * Constructs a TaskClientAsync object with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the task service + */ + public TaskClientAsync(ManagedChannel managedChannel) { + this.taskStub = TasksGrpc.newStub(managedChannel); + } + + @Override + public void submitTasks(String sessionId, List taskCreations, TaskOptions taskOptions, StreamObserver> responseObserver) { + SubmitTasksRequest request = TaskClientRequestFactory.createSubmitTasksRequest(sessionId, taskCreations, taskOptions); + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(SubmitTasksResponse submitTasksResponse) { + responseObserver.onNext(submitTasksResponse.getTaskInfosList()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + taskStub.submitTasks(request, observer); + } + + @Override + public void countTasksByStatus(Filters filters, StreamObserver responseObserver) { + CountTasksByStatusRequest request = TaskClientRequestFactory.createCountTasksByStatusRequest(filters); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(CountTasksByStatusResponse countTasksByStatusResponse) { + responseObserver.onNext(countTasksByStatusResponse); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + + taskStub.countTasksByStatus(request, observer); + } + + @Override + public void getResultIds(List tasksIds, StreamObserver> responseObserver) { + GetResultIdsRequest request = TaskClientRequestFactory.createGetResultIdsRequest(tasksIds); + + StreamObserver observer = new StreamObserver() { + @Override + public void onNext(GetResultIdsResponse getResultIdsResponse) { + responseObserver.onNext(getResultIdsResponse.getTaskResultsList()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + taskStub.getResultIds(request, observer); + } + + @Override + public void cancelTasks(List tasksIds, StreamObserver> responseObserver) { + CancelTasksRequest request = TaskClientRequestFactory.createCancelTasksRequest(tasksIds); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(CancelTasksResponse cancelTasksResponse) { + responseObserver.onNext(cancelTasksResponse.getTasksList()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + taskStub.cancelTasks(request, observer); + } + + @Override + public void getTask(String taskId, StreamObserver responseObserver) throws NoSuchMethodException { + GetTaskRequest request = TaskClientRequestFactory.createGetTaskRequest(taskId); + + StreamObserver observer = new StreamObserver<>() { + + @Override + public void onNext(GetTaskResponse getTaskResponse) { + responseObserver.onNext(getTaskResponse.getTask()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + taskStub.getTask(request, observer); + } + + @Override + public void listTasksDetailed(int page, int pageSize, Filters filters, Sort sort, StreamObserver> responseObserver) { + + ListTasksRequest request = TaskClientRequestFactory.createListTasksDetailedRequest(page, pageSize, filters, sort); + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(ListTasksDetailedResponse listTasksDetailedResponse) { + responseObserver.onNext(listTasksDetailedResponse.getTasksList()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + taskStub.listTasksDetailed(request, observer); + } + + @Override + public void listTasks(int page, int pageSize, Filters filters, Sort sort, StreamObserver> responseObserver) { + ListTasksRequest request = TaskClientRequestFactory.createListTasksSummaryRequest(page, pageSize, filters, sort); + + StreamObserver observer = new StreamObserver<>() { + @Override + public void onNext(ListTasksResponse listTasksResponse) { + responseObserver.onNext(listTasksResponse.getTasksList()); + } + + @Override + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + + + taskStub.listTasks(request, observer); + } +} diff --git a/packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java b/packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java new file mode 100644 index 000000000..da51a5b1a --- /dev/null +++ b/packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java @@ -0,0 +1,79 @@ +package armonik.client.task.impl; + +import armonik.api.grpc.v1.Objects.StatusCount; +import armonik.api.grpc.v1.Objects.TaskOptions; +import armonik.api.grpc.v1.tasks.TasksCommon.*; +import armonik.api.grpc.v1.tasks.TasksCommon.ListTasksRequest.Sort; +import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksRequest.TaskCreation; +import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksResponse.TaskInfo; +import armonik.api.grpc.v1.tasks.TasksFilters.Filters; +import armonik.api.grpc.v1.tasks.TasksGrpc; +import armonik.api.grpc.v1.tasks.TasksGrpc.TasksBlockingStub; +import armonik.client.task.impl.util.TaskClientRequestFactory; +import armonik.client.task.spec.ITaskClientSync; +import io.grpc.ManagedChannel; + +import java.util.List; + +import static armonik.api.grpc.v1.tasks.TasksCommon.GetResultIdsResponse.MapTaskResult; + +/** + * TaskClientSync is a synchronous implementation of the {@link ITaskClientSync} interface. + * It communicates with the task service using a blocking stub, making synchronous calls to perform various task-related operations. + */ +public class TaskClientSync implements ITaskClientSync { + private final TasksBlockingStub taskStub; + + + /** + * Constructs a TaskClientSync object with the provided managed channel. + * + * @param managedChannel the managed channel used for communication with the task service + */ + public TaskClientSync(ManagedChannel managedChannel) { + this.taskStub = TasksGrpc.newBlockingStub(managedChannel); + } + + @Override + public List listTasks(int page, int pageSize, Filters filters, Sort sort) { + ListTasksRequest request = TaskClientRequestFactory.createListTasksSummaryRequest(page, pageSize, filters, sort); + return taskStub.listTasks(request).getTasksList(); + } + + @Override + public List listTasksDetailed(int page, int pageSize, Filters filters, Sort sort) { + ListTasksRequest request = TaskClientRequestFactory.createListTasksDetailedRequest(page, pageSize, filters, sort); + return taskStub.listTasksDetailed(request).getTasksList(); + } + + @Override + public TaskDetailed getTask(String taskId) { + GetTaskRequest request = TaskClientRequestFactory.createGetTaskRequest(taskId); + return taskStub.getTask(request).getTask(); + } + + @Override + public List cancelTasks(List tasksIds) { + CancelTasksRequest request = TaskClientRequestFactory.createCancelTasksRequest(tasksIds); + return taskStub.cancelTasks(request).getTasksList(); + } + + + @Override + public List getResultIds(List tasksIds) { + GetResultIdsRequest request = TaskClientRequestFactory.createGetResultIdsRequest(tasksIds); + return taskStub.getResultIds(request).getTaskResultsList(); + } + + @Override + public List countTasksByStatus(Filters filters) { + CountTasksByStatusRequest request = TaskClientRequestFactory.createCountTasksByStatusRequest(filters); + return taskStub.countTasksByStatus(request).getStatusList(); + } + + @Override + public List submitTasks(String sessionId, List taskCreations, TaskOptions taskOptions) { + SubmitTasksRequest request = TaskClientRequestFactory.createSubmitTasksRequest(sessionId, taskCreations, taskOptions); + return taskStub.submitTasks(request).getTaskInfosList(); + } +} diff --git a/packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java b/packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java new file mode 100644 index 000000000..14e16a8a0 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java @@ -0,0 +1,77 @@ +package armonik.client.task.impl.util; + +import armonik.api.grpc.v1.Objects.TaskOptions; +import armonik.api.grpc.v1.tasks.TasksCommon; +import armonik.api.grpc.v1.tasks.TasksCommon.*; +import armonik.api.grpc.v1.tasks.TasksCommon.ListTasksRequest.Sort; +import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksRequest.TaskCreation; +import armonik.api.grpc.v1.tasks.TasksFilters.Filters; + +import java.util.List; + +import static armonik.api.grpc.v1.Objects.TaskOptions.getDefaultInstance; + +public abstract class TaskClientRequestFactory { + public static ListTasksRequest createListTasksSummaryRequest(int page, int pageSize, Filters filters, Sort sort) { + return ListTasksRequest.newBuilder() + .setPage(page) + .setPageSize(pageSize) + .setFilters(filters) + .setSort(sort) + .build(); + } + + public static ListTasksRequest createListTasksDetailedRequest(int page, int pageSize, Filters filters, Sort sort) { + return TasksCommon.ListTasksRequest.newBuilder() + .setSort(sort) + .setPageSize(page) + .setPageSize(pageSize) + .setFilters(filters) + .build(); + } + + public static GetTaskRequest createGetTaskRequest(String taskId) { + return GetTaskRequest.newBuilder() + .setTaskId(taskId) + .build(); + } + + public static CancelTasksRequest createCancelTasksRequest(List tasksIds) { + return CancelTasksRequest.newBuilder() + .addAllTaskIds(tasksIds) + .build(); + } + + public static GetResultIdsRequest createGetResultIdsRequest(List tasksIds) { + return GetResultIdsRequest.newBuilder() + .addAllTaskId(tasksIds) + .build(); + + } + + public static CountTasksByStatusRequest createCountTasksByStatusRequest(Filters filters) { + return CountTasksByStatusRequest.newBuilder() + .setFilters(filters) + .build(); + } + + public static SubmitTasksRequest createSubmitTasksRequest(String sessionId, List taskCreations, TaskOptions taskOptions) { + SubmitTasksRequest.Builder requestBuilder = SubmitTasksRequest.newBuilder(); + + requestBuilder.setSessionId(sessionId); + + if (!taskOptions.equals(getDefaultInstance())) { + requestBuilder.setTaskOptions(taskOptions); + } + taskCreations.forEach(taskCreation -> { + requestBuilder + .addTaskCreationsBuilder() + .setPayloadId(taskCreation.getPayloadId()) + .addAllDataDependencies(taskCreation.getDataDependenciesList()) + .addAllExpectedOutputKeys(taskCreation.getExpectedOutputKeysList()) + .setTaskOptions(!taskCreation.getTaskOptions().equals(getDefaultInstance()) ? taskCreation.getTaskOptions() : getDefaultInstance()); + }); + + return requestBuilder.build(); + } +} diff --git a/packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java b/packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java new file mode 100644 index 000000000..b7544581b --- /dev/null +++ b/packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java @@ -0,0 +1,24 @@ +package armonik.client.task.spec; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.tasks.TasksCommon; +import armonik.api.grpc.v1.tasks.TasksFilters; +import io.grpc.stub.StreamObserver; + +import java.util.List; + +public interface ITaskClientAsync { + void submitTasks(String sessionId, List taskCreations, Objects.TaskOptions taskOptions, StreamObserver> responseObserver); + + void countTasksByStatus(TasksFilters.Filters filters, StreamObserver responseObserver); + + void getResultIds(List tasksIds, StreamObserver> responseObserver); + + void cancelTasks(List tasksIds, StreamObserver> responseObserver); + + void getTask(String taskId, StreamObserver responseObserver) throws NoSuchMethodException; + + void listTasksDetailed(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort, StreamObserver> responseObserver) throws NoSuchMethodException; + + void listTasks(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort, StreamObserver> responseObserver) throws NoSuchMethodException; +} diff --git a/packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java b/packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java new file mode 100644 index 000000000..d4ed2d13e --- /dev/null +++ b/packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java @@ -0,0 +1,23 @@ +package armonik.client.task.spec; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.tasks.TasksCommon; +import armonik.api.grpc.v1.tasks.TasksFilters; + +import java.util.List; + +public interface ITaskClientSync { + List listTasks(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort); + + List listTasksDetailed(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort); + + TasksCommon.TaskDetailed getTask(String taskId); + + List cancelTasks(List tasksIds); + + List getResultIds(List tasksIds); + + List countTasksByStatus(TasksFilters.Filters filters); + + List submitTasks(String sessionId, List taskCreations, Objects.TaskOptions taskOptions); +} diff --git a/packages/java/src/main/resources/logback.xml b/packages/java/src/main/resources/logback.xml new file mode 100644 index 000000000..0ec161833 --- /dev/null +++ b/packages/java/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + diff --git a/packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 000000000..1f0955d45 --- /dev/null +++ b/packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline From a5fd6b16dea2fe578e958425f957b16c8a71f230 Mon Sep 17 00:00:00 2001 From: Hassan EL MZABI Date: Mon, 13 May 2024 14:56:23 +0200 Subject: [PATCH 2/2] java: final api client - preview. v1 add example project for java api delete java example add java example projectr fix: update client remove worker incomplete code, example and function that hides builder usage remove function that hides builder usage remove example changing end of lines remove extra code remove extra code --- packages/java/pom.xml | 9 + .../armonik/client/event/EventClient.java | 185 ++++++++++++ .../client/event/EventClientFactory.java | 32 -- .../client/event/impl/EventClientAsync.java | 69 ----- .../client/event/impl/EventClientSync.java | 58 ---- .../factory/EventClientRequestFactory.java | 52 ---- .../EventSubscriptionResponseRecord.java | 16 - .../client/event/spec/IEventClientAsync.java | 10 - .../client/event/spec/IEventClientSync.java | 10 - .../EventSubscriptionResponseRecord.java | 22 ++ .../armonik/client/result/ResultClient.java | 158 ++++++++++ .../client/result/ResultClientFactory.java | 32 -- .../client/result/impl/ResultClientAsync.java | 277 ------------------ .../client/result/impl/ResultClientSync.java | 88 ------ .../factory/ResultClientRequestFactory.java | 60 ---- .../DeleteResultsDataResponseRecord.java | 6 - .../records/WatchResultResponseRecord.java | 8 - .../result/spec/IResultClientAsync.java | 32 -- .../client/result/spec/IResultClientSync.java | 26 -- .../client/session/SessionClientFactory.java | 33 --- .../session/impl/SessionClientAsync.java | 269 ----------------- .../session/impl/SesssionClientSync.java | 162 ---------- .../util/SessionClientRequestFactory.java | 69 ----- .../session/spec/ISessionClientAsync.java | 30 -- .../session/spec/ISessionClientSync.java | 52 ---- .../client/task/TaskClientFactory.java | 33 --- .../client/task/impl/TaskClientAsync.java | 203 ------------- .../client/task/impl/TaskClientSync.java | 79 ----- .../impl/util/TaskClientRequestFactory.java | 77 ----- .../client/task/spec/ITaskClientAsync.java | 24 -- .../client/task/spec/ITaskClientSync.java | 23 -- .../org.mockito.plugins.MockMaker | 1 - 32 files changed, 374 insertions(+), 1831 deletions(-) create mode 100644 packages/java/src/main/java/armonik/client/event/EventClient.java delete mode 100644 packages/java/src/main/java/armonik/client/event/EventClientFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java delete mode 100644 packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java delete mode 100644 packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java create mode 100644 packages/java/src/main/java/armonik/client/event/util/records/EventSubscriptionResponseRecord.java create mode 100644 packages/java/src/main/java/armonik/client/result/ResultClient.java delete mode 100644 packages/java/src/main/java/armonik/client/result/ResultClientFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java delete mode 100644 packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java delete mode 100644 packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java delete mode 100644 packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java delete mode 100644 packages/java/src/main/java/armonik/client/session/SessionClientFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java delete mode 100644 packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java delete mode 100644 packages/java/src/main/java/armonik/client/task/TaskClientFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java delete mode 100644 packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java delete mode 100644 packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java delete mode 100644 packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java delete mode 100644 packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/packages/java/pom.xml b/packages/java/pom.xml index ecad9114c..45c41e740 100644 --- a/packages/java/pom.xml +++ b/packages/java/pom.xml @@ -26,6 +26,15 @@ grpc-netty 1.62.2 + + + + io.projectreactor + reactor-core + 3.6.5 + + + io.grpc grpc-protobuf diff --git a/packages/java/src/main/java/armonik/client/event/EventClient.java b/packages/java/src/main/java/armonik/client/event/EventClient.java new file mode 100644 index 000000000..c2c957e43 --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/EventClient.java @@ -0,0 +1,185 @@ +package armonik.client.event; + +import static armonik.api.grpc.v1.events.EventsCommon.EventsEnum.EVENTS_ENUM_NEW_RESULT; +import static armonik.api.grpc.v1.events.EventsCommon.EventsEnum.EVENTS_ENUM_RESULT_STATUS_UPDATE; +import static armonik.api.grpc.v1.results.ResultsFields.ResultRawEnumField.RESULT_RAW_ENUM_FIELD_RESULT_ID; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import armonik.api.grpc.v1.FiltersCommon; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionRequest; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse; +import armonik.api.grpc.v1.events.EventsGrpc; +import armonik.api.grpc.v1.events.EventsGrpc.EventsBlockingStub; +import armonik.api.grpc.v1.results.ResultsFields; +import armonik.api.grpc.v1.results.ResultsFilters; +import armonik.client.event.util.records.EventSubscriptionResponseRecord; +import io.grpc.ManagedChannel; +import io.grpc.stub.StreamObserver; + +/** + * EventClient is a client for interacting with event-related functionalities. + * It communicates with a gRPC server using a blocking stub to retrieve events. + */ +public class EventClient { + /** The blocking and nonblocking stub for communicating with the gRPC server. */ + private final EventsBlockingStub eventsBlockingStub; + private final EventsGrpc.EventsStub eventsStub; + + /** + * Constructs a new EventClient with the specified managed channel. + * + * @param managedChannel the managed channel used for communication with the + * server + */ + public EventClient(ManagedChannel managedChannel) { + eventsBlockingStub = EventsGrpc.newBlockingStub(managedChannel); + eventsStub = EventsGrpc.newStub(managedChannel); + } + + /** + * Retrieves a list of event subscription response records for the given session + * ID and result IDs. + * + * @param sessionId the session ID for which events are requested + * @param resultIds the list of result IDs for which events are requested + * @return a list of EventSubscriptionResponseRecord objects representing the + * events + */ + public List getEvents(String sessionId, List resultIds) { + EventSubscriptionRequest request = CreateEventSubscriptionRequest(sessionId, resultIds); + return mapToRecord(sessionId, request, resultIds); + } + + /** + * Maps the received event subscription response to + * EventSubscriptionResponseRecord objects. + * + * @param sessionId the session ID for which events are being mapped + * @param request the event subscription request + * @return a list of EventSubscriptionResponseRecord objects representing the + * events + */ + private List mapToRecord(String sessionId, EventSubscriptionRequest request, + List resultIds) { + List responseRecords = new ArrayList<>(); + Iterator events = eventsBlockingStub.getEvents(request); + Set resultsExpected = new HashSet<>(resultIds); + + while (events.hasNext()) { + var esr = events.next(); + resultsExpected.remove(esr.getNewResult().getResultId()); + responseRecords + .add(new EventSubscriptionResponseRecord(sessionId, + esr.getTaskStatusUpdate(), + esr.getResultStatusUpdate(), + esr.getResultOwnerUpdate(), + esr.getNewTask(), + esr.getNewResult())); + if (resultsExpected.isEmpty()) { + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + System.out.println("Thread was interrupted while sleeping"); + } + break; + } + } + return responseRecords; + } + + /** + * Retrieves a list of event subscription response records for the given session + * asynchrone + * ID and result IDs. + * + * @param sessionId the session ID for which events are requested + * @param resultIds the list of result IDs for which events are requested + * @return a list of EventSubscriptionResponseRecord objects representing the + * events + * @throws InterruptedException + */ + public List getEventResponseRecords(String sessionId, List resultIds) + throws InterruptedException { + + EventSubscriptionRequest request = CreateEventSubscriptionRequest(sessionId, resultIds); + List responseRecords = new ArrayList<>(); + CountDownLatch finishLatch = new CountDownLatch(1); + + StreamObserver responseObserver = new StreamObserver() { + + @Override + public void onNext(EventSubscriptionResponse esr) { + responseRecords.add(new EventSubscriptionResponseRecord( + sessionId, + esr.getTaskStatusUpdate(), + esr.getResultStatusUpdate(), + esr.getResultOwnerUpdate(), + esr.getNewTask(), + esr.getNewResult())); + } + + @Override + public void onError(Throwable t) { + t.printStackTrace(); + finishLatch.countDown(); + } + + @Override + public void onCompleted() { + System.out.println("Stream completed"); + finishLatch.countDown(); + } + }; + + eventsStub.getEvents(request, responseObserver); + + // Wait for the response observer to finish + if (!finishLatch.await(1, TimeUnit.MINUTES)) { + System.out.println("Request not completed within the timeout."); + } + + return responseRecords; + } + + /** + * Creates an event subscription request with the specified session ID and + * result IDs. + * + * @param sessionId the session ID for which event subscription is requested + * @param resultIds the list of result IDs to filter events + * @return an EventSubscriptionRequest object configured with the provided + * session ID and result IDs + */ + public static EventSubscriptionRequest CreateEventSubscriptionRequest(String sessionId, List resultIds) { + FiltersCommon.FilterString filterString = FiltersCommon.FilterString.newBuilder() + .setOperator(FiltersCommon.FilterStringOperator.FILTER_STRING_OPERATOR_EQUAL) + .build(); + + ResultsFields.ResultField.Builder resultField = ResultsFields.ResultField.newBuilder() + .setResultRawField(ResultsFields.ResultRawField.newBuilder().setField(RESULT_RAW_ENUM_FIELD_RESULT_ID)); + + ResultsFilters.FilterField.Builder filterFieldBuilder = ResultsFilters.FilterField.newBuilder() + .setField(resultField) + .setFilterString(filterString); + + ResultsFilters.Filters.Builder resultFiltersBuilder = ResultsFilters.Filters.newBuilder(); + for (String resultId : resultIds) { + filterFieldBuilder.setFilterString(FiltersCommon.FilterString.newBuilder().setValue(resultId).build()); + resultFiltersBuilder.addOr(ResultsFilters.FiltersAnd.newBuilder().addAnd(filterFieldBuilder).build()); + } + + return EventSubscriptionRequest.newBuilder() + .setResultsFilters(resultFiltersBuilder.build()) + .addReturnedEvents(EVENTS_ENUM_RESULT_STATUS_UPDATE) + .addReturnedEvents(EVENTS_ENUM_NEW_RESULT) + .setSessionId(sessionId) + .build(); + } +} diff --git a/packages/java/src/main/java/armonik/client/event/EventClientFactory.java b/packages/java/src/main/java/armonik/client/event/EventClientFactory.java deleted file mode 100644 index 5f97b345c..000000000 --- a/packages/java/src/main/java/armonik/client/event/EventClientFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -package armonik.client.event; - -import armonik.client.event.impl.EventClientAsync; -import armonik.client.event.impl.EventClientSync; -import armonik.client.event.spec.IEventClientAsync; -import armonik.client.event.spec.IEventClientSync; -import io.grpc.ManagedChannel; - -/** - * EventClientFactory provides static factory methods to create instances of event client implementations. - */ -public abstract class EventClientFactory { - /** - * Creates an asynchronous event client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the event service - * @return an instance of {@link IEventClientAsync} representing an asynchronous event client - */ - public static IEventClientAsync createEventClientAsync(ManagedChannel managedChannel) { - return new EventClientAsync(managedChannel); - } - - /** - * Creates a synchronous event client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the event service - * @return an instance of {@link IEventClientSync} representing a synchronous event client - */ - public static IEventClientSync createEventClientSync(ManagedChannel managedChannel) { - return new EventClientSync(managedChannel); - } -} diff --git a/packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java b/packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java deleted file mode 100644 index 5eef6e32d..000000000 --- a/packages/java/src/main/java/armonik/client/event/impl/EventClientAsync.java +++ /dev/null @@ -1,69 +0,0 @@ -package armonik.client.event.impl; - -import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionRequest; -import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse; -import armonik.api.grpc.v1.events.EventsGrpc; -import armonik.client.event.impl.util.factory.EventClientRequestFactory; -import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; -import armonik.client.event.spec.IEventClientAsync; -import io.grpc.ManagedChannel; -import io.grpc.stub.StreamObserver; - -import java.util.List; - -/** - * EventClientAsync is an asynchronous implementation of the {@link IEventClientAsync} interface. - * It communicates with the event service using a non-blocking stub, making asynchronous calls to wait for event updates. - */ -public class EventClientAsync implements IEventClientAsync { - private final EventsGrpc.EventsStub eventsStub; - - /** - * Constructs an EventClientAsync object with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the event service - */ - public EventClientAsync(ManagedChannel managedChannel) { - eventsStub = EventsGrpc.newStub(managedChannel); - } - - - /** - * Waits for event updates for the specified session ID and result IDs, and sends responses to the provided StreamObserver. - * - * @param sessionId the ID of the session for which event updates are awaited - * @param resultIds the list of result IDs for which event updates are awaited - * @param responseObserver a StreamObserver to handle the responses, containing entry of EventSubscriptionResponseRecord - */ - @Override - public void waitForEventsUpdateBySessionId(String sessionId, List resultIds, StreamObserver responseObserver) { - StreamObserver proxyObserver = new StreamObserver<>() { - @Override - public void onNext(EventSubscriptionResponse esr) { - responseObserver - .onNext( - new EventSubscriptionResponseRecord( - sessionId, - esr.getTaskStatusUpdate(), - esr.getResultStatusUpdate(), - esr.getResultOwnerUpdate(), - esr.getNewTask(), - esr.getNewResult() - ) - ); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - EventSubscriptionRequest request = EventClientRequestFactory.CreateEventSubscriptionRequest(sessionId, resultIds); - eventsStub.getEvents(request, proxyObserver); - } -} diff --git a/packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java b/packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java deleted file mode 100644 index c55c4fb90..000000000 --- a/packages/java/src/main/java/armonik/client/event/impl/EventClientSync.java +++ /dev/null @@ -1,58 +0,0 @@ -package armonik.client.event.impl; - -import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionRequest; -import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse; -import armonik.api.grpc.v1.events.EventsGrpc; -import armonik.api.grpc.v1.events.EventsGrpc.EventsBlockingStub; -import armonik.client.event.impl.util.factory.EventClientRequestFactory; -import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; -import armonik.client.event.spec.IEventClientSync; -import com.google.common.collect.Lists; -import io.grpc.ManagedChannel; - -import java.util.List; - -/** - * EventClientSync is a synchronous implementation of the {@link IEventClientSync} interface. - * It communicates with the event service using a blocking stub, making synchronous calls to retrieve event updates. - */ -public class EventClientSync implements IEventClientSync { - - private final EventsBlockingStub eventsBlockingStub; - - - /** - * Constructs an EventClientSync object with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the event service - */ - public EventClientSync(ManagedChannel managedChannel) { - this.eventsBlockingStub = EventsGrpc.newBlockingStub(managedChannel); - } - - - /** - * Retrieves event updates for the specified session ID and result IDs. - * - * @param sessionId the session ID for which event updates are requested - * @param resultIds the list of result IDs for which event updates are requested - * @return a list containing event update responses - */ - @Override - public List getEventsUpdateBySessionId(String sessionId, List resultIds) { - EventSubscriptionRequest request = EventClientRequestFactory.CreateEventSubscriptionRequest(sessionId, resultIds); - - List subscriptionResponses = Lists.newArrayList(eventsBlockingStub.getEvents(request)); - - return subscriptionResponses.stream() - .map( - esr -> new EventSubscriptionResponseRecord( - sessionId, - esr.getTaskStatusUpdate(), - esr.getResultStatusUpdate(), - esr.getResultOwnerUpdate(), - esr.getNewTask(), - esr.getNewResult()) - ).toList(); - } -} diff --git a/packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java b/packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java deleted file mode 100644 index 2f493d5cf..000000000 --- a/packages/java/src/main/java/armonik/client/event/impl/util/factory/EventClientRequestFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -package armonik.client.event.impl.util.factory; - -import armonik.api.grpc.v1.FiltersCommon; -import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionRequest; -import armonik.api.grpc.v1.results.ResultsFields; -import armonik.api.grpc.v1.results.ResultsFilters; - -import java.util.List; - -import static armonik.api.grpc.v1.events.EventsCommon.EventsEnum.EVENTS_ENUM_NEW_RESULT; -import static armonik.api.grpc.v1.events.EventsCommon.EventsEnum.EVENTS_ENUM_RESULT_STATUS_UPDATE; -import static armonik.api.grpc.v1.results.ResultsFields.ResultRawEnumField.RESULT_RAW_ENUM_FIELD_RESULT_ID; - -/** - * EventClientRequestFactory provides static methods to create event subscription requests. - * It constructs EventSubscriptionRequest objects based on provided session ID and result IDs. - */ -public class EventClientRequestFactory { - - /** - * Creates an event subscription request with the specified session ID and result IDs. - * - * @param sessionId the session ID for which event subscription is requested - * @param resultIds the list of result IDs to filter events - * @return an EventSubscriptionRequest object configured with the provided session ID and result IDs - */ - public static EventSubscriptionRequest CreateEventSubscriptionRequest(String sessionId, List resultIds){ - FiltersCommon.FilterString filterString = FiltersCommon.FilterString.newBuilder() - .setOperator(FiltersCommon.FilterStringOperator.FILTER_STRING_OPERATOR_EQUAL) - .build(); - - ResultsFields.ResultField.Builder resultField = ResultsFields.ResultField.newBuilder() - .setResultRawField(ResultsFields.ResultRawField.newBuilder().setField(RESULT_RAW_ENUM_FIELD_RESULT_ID)); - - ResultsFilters.FilterField.Builder filterFieldBuilder = ResultsFilters.FilterField.newBuilder() - .setField(resultField) - .setFilterString(filterString); - - ResultsFilters.Filters.Builder resultFiltersBuilder = ResultsFilters.Filters.newBuilder(); - for (String resultId : resultIds) { - filterFieldBuilder.setFilterString(FiltersCommon.FilterString.newBuilder().setValue(resultId).build()); - resultFiltersBuilder.addOr(ResultsFilters.FiltersAnd.newBuilder().addAnd(filterFieldBuilder).build()); - } - - return EventSubscriptionRequest.newBuilder() - .setResultsFilters(resultFiltersBuilder.build()) - .addReturnedEvents(EVENTS_ENUM_RESULT_STATUS_UPDATE) - .addReturnedEvents(EVENTS_ENUM_NEW_RESULT) - .setSessionId(sessionId) - .build(); - } -} diff --git a/packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java b/packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java deleted file mode 100644 index 29a8aab5e..000000000 --- a/packages/java/src/main/java/armonik/client/event/impl/util/records/EventSubscriptionResponseRecord.java +++ /dev/null @@ -1,16 +0,0 @@ -package armonik.client.event.impl.util.records; - -import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse.*; - -/** - * EventUpdateResponse represents the response containing updates for various event-related entities. - * It encapsulates changes in task status, result status, result owner, new task, and new result. - */ -public record EventSubscriptionResponseRecord(String sessionId, - TaskStatusUpdate taskStatusUpdate, - ResultStatusUpdate resultStatusUpdate, - ResultOwnerUpdate resultOwnerUpdate, - NewTask newTask, - NewResult newResult - ) { -} diff --git a/packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java b/packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java deleted file mode 100644 index e844c1522..000000000 --- a/packages/java/src/main/java/armonik/client/event/spec/IEventClientAsync.java +++ /dev/null @@ -1,10 +0,0 @@ -package armonik.client.event.spec; - -import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; -import io.grpc.stub.StreamObserver; - -import java.util.List; - -public interface IEventClientAsync { - void waitForEventsUpdateBySessionId(String sessionId, List resultIds, StreamObserver responseObserver); -} diff --git a/packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java b/packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java deleted file mode 100644 index 098103e62..000000000 --- a/packages/java/src/main/java/armonik/client/event/spec/IEventClientSync.java +++ /dev/null @@ -1,10 +0,0 @@ -package armonik.client.event.spec; - -import armonik.client.event.impl.util.records.EventSubscriptionResponseRecord; - -import java.util.List; - -public interface IEventClientSync { - List getEventsUpdateBySessionId(String sessionId, List resultIds); - -} diff --git a/packages/java/src/main/java/armonik/client/event/util/records/EventSubscriptionResponseRecord.java b/packages/java/src/main/java/armonik/client/event/util/records/EventSubscriptionResponseRecord.java new file mode 100644 index 000000000..0cead396d --- /dev/null +++ b/packages/java/src/main/java/armonik/client/event/util/records/EventSubscriptionResponseRecord.java @@ -0,0 +1,22 @@ +package armonik.client.event.util.records; + +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse.NewResult; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse.NewTask; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse.ResultOwnerUpdate; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse.ResultStatusUpdate; +import armonik.api.grpc.v1.events.EventsCommon.EventSubscriptionResponse.TaskStatusUpdate; + +/** + * EventSubscriptionResponseRecord represents a record containing subscription + * response details for an event. + * It encapsulates various attributes related to event subscription, such as + * session ID, task status update, + * result status update, result owner update, new task, and new result. + */ +public record EventSubscriptionResponseRecord(String sessionId, + TaskStatusUpdate taskStatusUpdate, + ResultStatusUpdate resultStatusUpdate, + ResultOwnerUpdate resultOwnerUpdate, + NewTask newTask, + NewResult newResult) { +} diff --git a/packages/java/src/main/java/armonik/client/result/ResultClient.java b/packages/java/src/main/java/armonik/client/result/ResultClient.java new file mode 100644 index 000000000..eb401344e --- /dev/null +++ b/packages/java/src/main/java/armonik/client/result/ResultClient.java @@ -0,0 +1,158 @@ +package armonik.client.result; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import com.google.protobuf.ByteString; + +import armonik.api.grpc.v1.Objects; +import armonik.api.grpc.v1.results.ResultsCommon.CreateResultsMetaDataRequest; +import armonik.api.grpc.v1.results.ResultsCommon.CreateResultsRequest; +import armonik.api.grpc.v1.results.ResultsCommon.DownloadResultDataRequest; +import armonik.api.grpc.v1.results.ResultsCommon.DownloadResultDataResponse; +import armonik.api.grpc.v1.results.ResultsCommon.GetOwnerTaskIdRequest; +import armonik.api.grpc.v1.results.ResultsCommon.GetOwnerTaskIdResponse.MapResultTask; +import armonik.api.grpc.v1.results.ResultsCommon.GetResultRequest; +import armonik.api.grpc.v1.results.ResultsCommon.ListResultsRequest; +import armonik.api.grpc.v1.results.ResultsCommon.ListResultsRequest.Sort; +import armonik.api.grpc.v1.results.ResultsCommon.ResultRaw; +import armonik.api.grpc.v1.results.ResultsFilters.Filters; +import armonik.api.grpc.v1.results.ResultsGrpc; +import io.grpc.ManagedChannel; + +/** + * ResultClient provides methods for interacting with result-related + * functionalities. + * It communicates with a gRPC server using a blocking stub to perform various + * operations on results. + */ +public class ResultClient { + /** The blocking stub for communicating with the gRPC server. */ + private final ResultsGrpc.ResultsBlockingStub resultsBlockingStub; + + /** + * Constructs a new ResultClient with the specified managed channel. + * + * @param managedChannel the managed channel used for communication with the + * server + */ + public ResultClient(ManagedChannel managedChannel) { + this.resultsBlockingStub = ResultsGrpc.newBlockingStub(managedChannel); + } + + /** + * Retrieves the service configuration data chunk max size from the server. + * + * @return the service configuration data chunk max size + */ + public int getServiceConfiguration() { + return resultsBlockingStub.getServiceConfiguration(Objects.Empty.newBuilder().build()).getDataChunkMaxSize(); + } + + /** + * Downloads result data for the specified session ID and result ID. + * + * @param sessionId the session ID associated with the result to download + * @param resultId the result ID to download + * @return a list of byte arrays representing the downloaded data chunks + */ + public List downloadResultData(String sessionId, String resultId) { + DownloadResultDataRequest request = DownloadResultDataRequest.newBuilder() + .setSessionId(sessionId) + .setResultId(resultId) + .build(); + Iterator iterator = resultsBlockingStub.downloadResultData(request); + List list = new ArrayList<>(); + + iterator.forEachRemaining(list::add); + + return list.stream() + .map(DownloadResultDataResponse::getDataChunk) + .map(ByteString::toByteArray) + .toList(); + } + + /** + * Creates results based on the specified request. + * + * @param request the request containing the data to create results + * @return a list of ResultRaw objects representing the created results + */ + public List createResults(CreateResultsRequest request) { + return resultsBlockingStub.createResults(request).getResultsList(); + + } + + /** + * Creates metadata for results associated with the specified session ID and + * names. + * + * @param sessionId the session ID for which metadata is being created + * @param names the list of names for the results + * @return a list of ResultRaw objects representing the created metadata + */ + public List createResultsMetaData(String sessionId, List names) { + CreateResultsMetaDataRequest request = CreateResultsMetaDataRequest.newBuilder() + .setSessionId(sessionId) + .addAllResults(names.stream() + .map(name -> CreateResultsMetaDataRequest.ResultCreate.newBuilder().setName(name).build()).toList()) + .build(); + + return resultsBlockingStub.createResultsMetaData(request).getResultsList(); + } + + /** + * Retrieves a map of result IDs to task IDs for the specified session ID and + * result IDs. + * + * @param sessionId the session ID associated with the results + * @param resultIds the list of result IDs for which task IDs are requested + * @return a map where result IDs are mapped to their corresponding task IDs + */ + public Map getOwnerTaskId(String sessionId, List resultIds) { + GetOwnerTaskIdRequest request = GetOwnerTaskIdRequest.newBuilder() + .setSessionId(sessionId) + .addAllResultId(resultIds) + .build(); + return resultsBlockingStub.getOwnerTaskId(request).getResultTaskList() + .stream() + .collect(Collectors.toMap(MapResultTask::getResultId, MapResultTask::getTaskId)); + } + + /** + * Retrieves the result with the specified result ID. + * + * @param resultId the ID of the result to retrieve + * @return the ResultRaw object representing the retrieved result + */ + public ResultRaw getResult(String resultId) { + GetResultRequest request = GetResultRequest.newBuilder() + .setResultId(resultId) + .build(); + return resultsBlockingStub.getResult(request).getResult(); + } + + /** + * Lists results based on the specified filters, total count, pagination + * parameters, and sorting criteria. + * + * @param filters the filters to apply to the result list + * @param total the total count of results + * @param page the page number of the results to retrieve + * @param pageSize the size of each page of results + * @param sort the sorting criteria for the results + * @return a list of ResultRaw objects representing the retrieved results + */ + public List listResults(Filters filters, int total, int page, int pageSize, Sort sort) { + ListResultsRequest request = ListResultsRequest.newBuilder() + .setFilters(filters) + .setSort(sort) + .setPage(page) + .setPageSize(pageSize) + .build(); + return resultsBlockingStub.listResults(request).getResultsList(); + } +} diff --git a/packages/java/src/main/java/armonik/client/result/ResultClientFactory.java b/packages/java/src/main/java/armonik/client/result/ResultClientFactory.java deleted file mode 100644 index 57e61d3f5..000000000 --- a/packages/java/src/main/java/armonik/client/result/ResultClientFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -package armonik.client.result; - -import armonik.client.result.impl.ResultClientAsync; -import armonik.client.result.impl.ResultClientSync; -import armonik.client.result.spec.IResultClientAsync; -import armonik.client.result.spec.IResultClientSync; -import io.grpc.ManagedChannel; - -/** - * ResultClientFactory provides static factory methods to create instances of result client implementations. - */ -public abstract class ResultClientFactory { - /** - * Creates a synchronous result client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the result service - * @return an instance of {@link IResultClientSync} representing a synchronous result client - */ - public static IResultClientSync createResultClientSync(ManagedChannel managedChannel) { - return new ResultClientSync(managedChannel); - } - - /** - * Creates an asynchronous result client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the result service - * @return an instance of {@link IResultClientAsync} representing an asynchronous result client - */ - public static IResultClientAsync createResultClientAsync(ManagedChannel managedChannel) { - return new ResultClientAsync(managedChannel); - } -} diff --git a/packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java b/packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java deleted file mode 100644 index bab5be18a..000000000 --- a/packages/java/src/main/java/armonik/client/result/impl/ResultClientAsync.java +++ /dev/null @@ -1,277 +0,0 @@ -package armonik.client.result.impl; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.results.ResultsCommon; -import armonik.api.grpc.v1.results.ResultsCommon.*; -import armonik.api.grpc.v1.results.ResultsFilters; -import armonik.api.grpc.v1.results.ResultsGrpc; -import armonik.api.grpc.v1.results.ResultsGrpc.ResultsStub; -import armonik.client.result.impl.util.factory.ResultClientRequestFactory; -import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; -import armonik.client.result.impl.util.records.WatchResultResponseRecord; -import armonik.client.result.spec.IResultClientAsync; -import io.grpc.ManagedChannel; -import io.grpc.stub.StreamObserver; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * ResultClientAsync is an asynchronous implementation of the {@link IResultClientAsync} interface. - * It communicates with the result service using a non-blocking stub, making asynchronous calls to perform various result-related operations. - */ -public class ResultClientAsync implements IResultClientAsync { - private final ResultsStub resultsStub; - - public ResultClientAsync(ManagedChannel managedChannel) { - this.resultsStub = ResultsGrpc.newStub(managedChannel); - } - - @Override - public StreamObserver watchResults(StreamObserver responseObserver) { - StreamObserver proxyObserver = new StreamObserver<>() { - @Override - public void onNext(WatchResultResponse watchResultResponse) { - responseObserver.onNext(new WatchResultResponseRecord(watchResultResponse.getStatus(), watchResultResponse.getResultIdsList())); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - return resultsStub.watchResults(proxyObserver); - } - - @Override - public void getServiceConfiguration(StreamObserver responseObserver) { - StreamObserver observer = new StreamObserver() { - @Override - public void onNext(ResultsServiceConfigurationResponse resultsServiceConfigurationResponse) { - responseObserver.onNext(resultsServiceConfigurationResponse.getDataChunkMaxSize()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - resultsStub.getServiceConfiguration(Objects.Empty.newBuilder().build(), observer); - } - - - @Override - public void deleteResultsData(String sessionId, List resultIds, StreamObserver responseObserver) { - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(DeleteResultsDataResponse deleteResultsDataResponse) { - responseObserver.onNext(new DeleteResultsDataResponseRecord(sessionId, deleteResultsDataResponse.getResultIdList())); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - ResultsCommon.DeleteResultsDataRequest request = ResultClientRequestFactory.createDeleteResultsDataRequest(sessionId, resultIds); - - - resultsStub.deleteResultsData(request, observer); - } - - @Override - public void downloadResultData(String sessionId, String resultId, StreamObserver responseObserver) { - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(DownloadResultDataResponse downloadResultDataResponse) { - responseObserver.onNext(downloadResultDataResponse.getDataChunk().toByteArray()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - DownloadResultDataRequest request = ResultClientRequestFactory.createDownloadResultDataRequest(sessionId, resultId); - - - resultsStub.downloadResultData(request, observer); - } - - - @Override - public StreamObserver uploadResultData(String sessionId, String resultId, String payload, StreamObserver responseObserver) { - StreamObserver proxyObserver = new StreamObserver<>() { - @Override - public void onNext(UploadResultDataResponse uploadResultDataResponse) { - responseObserver.onNext(uploadResultDataResponse.getResult()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - return resultsStub.uploadResultData(proxyObserver); - - } - - @Override - public void createResults(CreateResultsRequest request, StreamObserver> responseObserver) { - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(CreateResultsResponse createResultsResponse) { - responseObserver - .onNext( - createResultsResponse - .getResultsList() - .stream() - .collect(Collectors.toMap(ResultRaw::getName, ResultRaw::getResultId)) - ); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - resultsStub.createResults(request, observer); - } - - @Override - public void createResultsMetaData(String sessionId, List names, StreamObserver> responseObserver) { - CreateResultsMetaDataRequest request = ResultClientRequestFactory.createCreateResultsMetaDataRequest(sessionId, names); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(CreateResultsMetaDataResponse createResultsMetaDataResponse) { - responseObserver.onNext(createResultsMetaDataResponse.getResultsList()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - resultsStub.createResultsMetaData(request, observer); - } - - @Override - public void getOwnerTaskId(String sessionId, List resultIds, StreamObserver> responseObserver) { - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(GetOwnerTaskIdResponse getOwnerTaskIdResponse) { - responseObserver.onNext(getOwnerTaskIdResponse.getResultTaskList() - .stream() - .collect(Collectors.toMap(GetOwnerTaskIdResponse.MapResultTask::getResultId, GetOwnerTaskIdResponse.MapResultTask::getTaskId))); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - GetOwnerTaskIdRequest request = ResultClientRequestFactory.createGetOwnerTaskIdRequest(sessionId, resultIds); - - - resultsStub.getOwnerTaskId(request, observer); - } - - - @Override - public void getResult(String resultId, StreamObserver responseObserver) { - StreamObserver observer = new StreamObserver() { - @Override - public void onNext(GetResultResponse getResultResponse) { - responseObserver.onNext(getResultResponse.getResult()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - GetResultRequest request = ResultClientRequestFactory.createGetResultRequest(resultId); - - resultsStub.getResult(request, observer); - } - - - @Override - public void listResults(ResultsFilters.Filters filters, int total, int page, int pageSize, ListResultsRequest.Sort sort, StreamObserver> responseObserver) { - StreamObserver observer = new StreamObserver() { - @Override - public void onNext(ListResultsResponse listResultsResponse) { - responseObserver.onNext(listResultsResponse.getResultsList()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - ListResultsRequest request = ResultClientRequestFactory.createListResultsRequest(filters, total, page, pageSize, sort); - - resultsStub.listResults(request, observer); - } -} diff --git a/packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java b/packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java deleted file mode 100644 index 77f5f0c4f..000000000 --- a/packages/java/src/main/java/armonik/client/result/impl/ResultClientSync.java +++ /dev/null @@ -1,88 +0,0 @@ -package armonik.client.result.impl; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.results.ResultsCommon.*; -import armonik.api.grpc.v1.results.ResultsCommon.GetOwnerTaskIdResponse.MapResultTask; -import armonik.api.grpc.v1.results.ResultsCommon.ListResultsRequest.Sort; -import armonik.api.grpc.v1.results.ResultsGrpc; -import armonik.client.result.impl.util.factory.ResultClientRequestFactory; -import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; -import armonik.client.result.spec.IResultClientSync; -import io.grpc.ManagedChannel; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static armonik.api.grpc.v1.results.ResultsFilters.*; - -/** - * ResultClientSync is a synchronous implementation of the {@link IResultClientSync} interface. - * It communicates with the result service using a blocking stub, making synchronous calls to interact with result data. - */ -public class ResultClientSync implements IResultClientSync { - private final ResultsGrpc.ResultsBlockingStub resultsBlockingStub; - - public ResultClientSync(ManagedChannel managedChannel) { - this.resultsBlockingStub = ResultsGrpc.newBlockingStub(managedChannel); - } - - @Override - public int getServiceConfiguration() { - return resultsBlockingStub.getServiceConfiguration(Objects.Empty.newBuilder().build()).getDataChunkMaxSize(); - } - - @Override - public DeleteResultsDataResponseRecord deleteResultsData(String sessionId, List resultIds) { - DeleteResultsDataRequest request = ResultClientRequestFactory.createDeleteResultsDataRequest(sessionId, resultIds); - return new DeleteResultsDataResponseRecord(sessionId, resultsBlockingStub.deleteResultsData(request).getResultIdList()); - } - - - @Override - public List downloadResultData(String sessionId, String resultId) { - DownloadResultDataRequest request = ResultClientRequestFactory.createDownloadResultDataRequest(sessionId, resultId); - Iterator iterator = resultsBlockingStub.downloadResultData(request); - List list = new ArrayList<>(); - - iterator.forEachRemaining(list::add); - return list.stream().map(downloadResultDataResponse -> downloadResultDataResponse.getDataChunk().toByteArray()) - .toList(); - } - - @Override - public Map createResults(CreateResultsRequest request) { - return resultsBlockingStub.createResults(request).getResultsList() - .stream() - .collect(Collectors.toMap(ResultRaw::getName,ResultRaw::getResultId)); - } - - - @Override - public List createResultsMetaData(String sessionId, List names) { - CreateResultsMetaDataRequest request = ResultClientRequestFactory.createCreateResultsMetaDataRequest(sessionId, names); - return resultsBlockingStub.createResultsMetaData(request).getResultsList(); - } - - @Override - public Map getOwnerTaskId(String sessionId, List resultIds) { - GetOwnerTaskIdRequest request = ResultClientRequestFactory.createGetOwnerTaskIdRequest(sessionId, resultIds); - return resultsBlockingStub.getOwnerTaskId(request).getResultTaskList() - .stream() - .collect(Collectors.toMap(MapResultTask::getResultId, MapResultTask::getTaskId)); - } - - @Override - public ResultRaw getResult(String resultId) { - GetResultRequest request = ResultClientRequestFactory.createGetResultRequest(resultId); - return resultsBlockingStub.getResult(request).getResult(); - } - - @Override - public List listResults(Filters filters, int total, int page, int pageSize, Sort sort) { - ListResultsRequest request = ResultClientRequestFactory.createListResultsRequest(filters, total, page, pageSize, sort); - return resultsBlockingStub.listResults(request).getResultsList(); - } -} diff --git a/packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java b/packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java deleted file mode 100644 index b3d266437..000000000 --- a/packages/java/src/main/java/armonik/client/result/impl/util/factory/ResultClientRequestFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -package armonik.client.result.impl.util.factory; - -import armonik.api.grpc.v1.results.ResultsCommon.*; -import armonik.api.grpc.v1.results.ResultsCommon.ListResultsRequest.Sort; -import armonik.api.grpc.v1.results.ResultsFilters.Filters; - -import java.util.List; - -public abstract class ResultClientRequestFactory { - - public static DeleteResultsDataRequest createDeleteResultsDataRequest(String sessionId, List resultIds) { - return DeleteResultsDataRequest.newBuilder() - .setSessionId(sessionId) - .addAllResultId(resultIds) - .build(); - } - - public static DownloadResultDataRequest createDownloadResultDataRequest(String sessionId, String resultId) { - return DownloadResultDataRequest.newBuilder() - .setSessionId(sessionId) - .setResultId(resultId) - .build(); - } - - - public static CreateResultsMetaDataRequest createCreateResultsMetaDataRequest(String sessionId, List names) { - return CreateResultsMetaDataRequest.newBuilder() - .setSessionId(sessionId) - .addAllResults(names.stream().map(name -> CreateResultsMetaDataRequest.ResultCreate.newBuilder().setName(name).build()).toList()) - .build(); - - } - - public static GetOwnerTaskIdRequest createGetOwnerTaskIdRequest(String sessionId, List resultIds) { - return GetOwnerTaskIdRequest.newBuilder() - .setSessionId(sessionId) - .addAllResultId(resultIds) - .build(); - - } - - public static GetResultRequest createGetResultRequest(String resultId) { - return GetResultRequest.newBuilder() - .setResultId(resultId) - .build(); - } - - public static ListResultsRequest createListResultsRequest(Filters filters, int total, int page, int pageSize, Sort sort) { - return ListResultsRequest.newBuilder() - .setFilters(filters) - .setSort(sort) - .setPage(page) - .setPageSize(pageSize) - .build(); - - - } - - -} diff --git a/packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java b/packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java deleted file mode 100644 index b9ff6ccf0..000000000 --- a/packages/java/src/main/java/armonik/client/result/impl/util/records/DeleteResultsDataResponseRecord.java +++ /dev/null @@ -1,6 +0,0 @@ -package armonik.client.result.impl.util.records; - -import java.util.List; - -public record DeleteResultsDataResponseRecord(String sessionId, List deletedResultIds) { -} diff --git a/packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java b/packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java deleted file mode 100644 index 3dddeeed7..000000000 --- a/packages/java/src/main/java/armonik/client/result/impl/util/records/WatchResultResponseRecord.java +++ /dev/null @@ -1,8 +0,0 @@ -package armonik.client.result.impl.util.records; - -import armonik.api.grpc.v1.result_status.ResultStatusOuterClass; - -import java.util.List; - -public record WatchResultResponseRecord(ResultStatusOuterClass.ResultStatus resultStatus, List resultIds) { -} diff --git a/packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java b/packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java deleted file mode 100644 index 575f35194..000000000 --- a/packages/java/src/main/java/armonik/client/result/spec/IResultClientAsync.java +++ /dev/null @@ -1,32 +0,0 @@ -package armonik.client.result.spec; - -import armonik.api.grpc.v1.results.ResultsCommon; -import armonik.api.grpc.v1.results.ResultsFilters; -import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; -import armonik.client.result.impl.util.records.WatchResultResponseRecord; -import io.grpc.stub.StreamObserver; - -import java.util.List; -import java.util.Map; - -public interface IResultClientAsync { - StreamObserver watchResults(StreamObserver responseObserver); - - void getServiceConfiguration(StreamObserver responseObserver); - - void deleteResultsData(String sessionId, List resultIds, StreamObserver responseObserver); - - void downloadResultData(String sessionId, String resultId, StreamObserver responseObserver); - - StreamObserver uploadResultData(String sessionId, String resultId, String payload, StreamObserver responseObserver); - - void createResults(ResultsCommon.CreateResultsRequest request, StreamObserver> responseObserver); - - void createResultsMetaData(String sessionId, List names, StreamObserver> responseObserver); - - void getOwnerTaskId(String sessionId, List resultIds, StreamObserver> responseObserver); - - void getResult(String resultId, StreamObserver responseObserver); - - void listResults(ResultsFilters.Filters filters, int total, int page, int pageSize, ResultsCommon.ListResultsRequest.Sort sort, StreamObserver> responseObserver); -} diff --git a/packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java b/packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java deleted file mode 100644 index d96638e19..000000000 --- a/packages/java/src/main/java/armonik/client/result/spec/IResultClientSync.java +++ /dev/null @@ -1,26 +0,0 @@ -package armonik.client.result.spec; - -import armonik.api.grpc.v1.results.ResultsCommon; -import armonik.api.grpc.v1.results.ResultsFilters; -import armonik.client.result.impl.util.records.DeleteResultsDataResponseRecord; - -import java.util.List; -import java.util.Map; - -public interface IResultClientSync { - int getServiceConfiguration(); - - DeleteResultsDataResponseRecord deleteResultsData(String sessionId, List resultIds); - - List downloadResultData(String sessionId, String resultId); - - Map createResults(ResultsCommon.CreateResultsRequest request); - - List createResultsMetaData(String sessionId, List names); - - Map getOwnerTaskId(String sessionId, List resultIds); - - ResultsCommon.ResultRaw getResult(String resultId); - - List listResults(ResultsFilters.Filters filters, int total, int page, int pageSize, ResultsCommon.ListResultsRequest.Sort sort); -} diff --git a/packages/java/src/main/java/armonik/client/session/SessionClientFactory.java b/packages/java/src/main/java/armonik/client/session/SessionClientFactory.java deleted file mode 100644 index e34674bb1..000000000 --- a/packages/java/src/main/java/armonik/client/session/SessionClientFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -package armonik.client.session; - -import armonik.client.session.impl.SessionClientAsync; -import armonik.client.session.impl.SesssionClientSync; -import armonik.client.session.spec.ISessionClientAsync; -import armonik.client.session.spec.ISessionClientSync; -import io.grpc.ManagedChannel; - -/** - * SessionClientFactory provides static factory methods to create instances of session client implementations. - */ -public abstract class SessionClientFactory { - - /** - * Creates an asynchronous session client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the session service - * @return an instance of {@link ISessionClientAsync} representing an asynchronous session client - */ - public static ISessionClientAsync createSessionClientAsync(ManagedChannel managedChannel) { - return new SessionClientAsync(managedChannel); - } - - /** - * Creates a synchronous session client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the session service - * @return an instance of {@link ISessionClientSync} representing a synchronous session client - */ - public static ISessionClientSync createSesssionClientSync(ManagedChannel managedChannel) { - return new SesssionClientSync(managedChannel); - } -} diff --git a/packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java b/packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java deleted file mode 100644 index f3f254287..000000000 --- a/packages/java/src/main/java/armonik/client/session/impl/SessionClientAsync.java +++ /dev/null @@ -1,269 +0,0 @@ -package armonik.client.session.impl; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.sessions.SessionsCommon; -import armonik.api.grpc.v1.sessions.SessionsCommon.*; -import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; -import armonik.api.grpc.v1.sessions.SessionsFilters.Filters; -import armonik.api.grpc.v1.sessions.SessionsGrpc; -import armonik.api.grpc.v1.sessions.SessionsGrpc.SessionsStub; -import armonik.client.session.impl.util.SessionClientRequestFactory; -import armonik.client.session.spec.ISessionClientAsync; -import io.grpc.ManagedChannel; -import io.grpc.stub.StreamObserver; - -import java.util.List; - -public class SessionClientAsync implements ISessionClientAsync { - private final SessionsStub sessionsStub; - - /** - * Constructs a new ArmonikSession object using the provided gRPC ManagedChannel. - * - * @param managedChannel The gRPC ManagedChannel to communicate with the Armonik service. - */ - - public SessionClientAsync(ManagedChannel managedChannel) { - sessionsStub = SessionsGrpc.newStub(managedChannel); - } - - @Override - public void createSession(Objects.TaskOptions taskOptions, List partitionIds, StreamObserver streamObserver) { - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(CreateSessionReply createSessionReply) { - streamObserver.onNext(createSessionReply.getSessionId()); - } - - @Override - public void onError(Throwable throwable) { - streamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - streamObserver.onCompleted(); - } - }; - - List partIds = partitionIds == null || partitionIds.isEmpty() ? null : partitionIds; - SessionsCommon.CreateSessionRequest request = SessionsCommon.CreateSessionRequest.newBuilder() - .setDefaultTaskOption(taskOptions) - .addAllPartitionIds(partIds) - .build(); - sessionsStub.createSession(request, observer); - } - - - @Override - public void getSession(String sessionId, StreamObserver rawStreamObserver) { - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(GetSessionResponse getSessionResponse) { - rawStreamObserver.onNext(getSessionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - rawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - rawStreamObserver.onCompleted(); - } - }; - - GetSessionRequest request = SessionClientRequestFactory.createGetSessionRequest(sessionId); - - - sessionsStub.getSession(request, observer); - } - - @Override - public void listSessions(int page, int pageSize, Filters filter, Sort sort, StreamObserver> listStreamObserver) { - ListSessionsRequest request = SessionClientRequestFactory.createListSessionsRequest(page, pageSize, filter, sort); - StreamObserver observer = new StreamObserver() { - @Override - public void onNext(ListSessionsResponse listSessionsResponse) { - listStreamObserver.onNext(listSessionsResponse.getSessionsList()); - } - - @Override - public void onError(Throwable throwable) { - listStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - listStreamObserver.onCompleted(); - } - }; - sessionsStub.listSessions(request, observer); - } - - @Override - public void cancelSession(String sessionId, StreamObserver sessionRawStreamObserver) throws Exception { - CancelSessionRequest request = SessionClientRequestFactory.createCancelSessionRequest(sessionId); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(CancelSessionResponse cancelSessionResponse) { - sessionRawStreamObserver.onNext(cancelSessionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - sessionRawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - sessionRawStreamObserver.onCompleted(); - } - }; - sessionsStub.cancelSession(request,observer); - } - - @Override - public void pauseSession(String sessionId, StreamObserver sessionRawStreamObserver) { - PauseSessionRequest request = SessionClientRequestFactory.createPauseSessionRequest(sessionId); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(PauseSessionResponse pauseSessionResponse) { - sessionRawStreamObserver.onNext(pauseSessionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - sessionRawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - sessionRawStreamObserver.onCompleted(); - } - }; - sessionsStub.pauseSession(request,observer); - } - - @Override - public void resumeSession(String sessionId, StreamObserver sessionRawStreamObserver) { - ResumeSessionRequest request = SessionClientRequestFactory.createResumeSessionRequest(sessionId); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(ResumeSessionResponse resumeSessionResponse) { - sessionRawStreamObserver.onNext(resumeSessionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - sessionRawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - sessionRawStreamObserver.onCompleted(); - } - }; - sessionsStub.resumeSession(request,observer); - } - - @Override - public void closeSession(String sessionId, StreamObserver sessionRawStreamObserver){ - CloseSessionRequest closeSessionRequest = SessionClientRequestFactory.createCloseSessionRequest(sessionId); - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(CloseSessionResponse closeSessionResponse) { - sessionRawStreamObserver.onNext(closeSessionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - sessionRawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - sessionRawStreamObserver.onCompleted(); - } - }; - sessionsStub.closeSession(closeSessionRequest,observer); - } - - @Override - public void purgeSession(String sessionId, StreamObserver sessionRawStreamObserver){ - PurgeSessionRequest purgeSessionRequest = SessionClientRequestFactory.createPurgeSessionRequest(sessionId); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(PurgeSessionResponse purgeSessionResponse) { - sessionRawStreamObserver.onNext(purgeSessionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - sessionRawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - sessionRawStreamObserver.onCompleted(); - } - }; - sessionsStub.purgeSession(purgeSessionRequest,observer); - } - - @Override - public void deleteSession(String sessionId, StreamObserver sessionRawStreamObserver){ - DeleteSessionRequest deleteSessionRequest = SessionClientRequestFactory.createDeleteSessionRequest(sessionId); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(DeleteSessionResponse deleteSessionResponse) { - sessionRawStreamObserver.onNext(deleteSessionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - sessionRawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - sessionRawStreamObserver.onCompleted(); - } - }; - - sessionsStub.deleteSession(deleteSessionRequest,observer); - } - - @Override - public void stopSubmissionSession(String sessionId, boolean client, boolean worker, StreamObserver sessionRawStreamObserver){ - StopSubmissionRequest request = SessionClientRequestFactory.createStopSubmissionSessionRequest(sessionId, client, worker); - - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(StopSubmissionResponse stopSubmissionResponse) { - sessionRawStreamObserver.onNext(stopSubmissionResponse.getSession()); - } - - @Override - public void onError(Throwable throwable) { - sessionRawStreamObserver.onError(throwable); - } - - @Override - public void onCompleted() { - sessionRawStreamObserver.onCompleted(); - } - }; - sessionsStub.stopSubmission(request,observer); - } - - - -} diff --git a/packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java b/packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java deleted file mode 100644 index 45f405a6d..000000000 --- a/packages/java/src/main/java/armonik/client/session/impl/SesssionClientSync.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * ArmonikSession provides a client interface to interact with Armonik session management functionality. - * This class allows creating, retrieving, listing, canceling, pausing, resuming, closing, purging, deleting, - * and stopping submissions for sessions in the Armonik system. - */ - -package armonik.client.session.impl; - -import armonik.api.grpc.v1.Objects.TaskOptions; -import armonik.api.grpc.v1.sessions.SessionsCommon.*; -import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; -import armonik.api.grpc.v1.sessions.SessionsFilters.Filters; -import armonik.api.grpc.v1.sessions.SessionsGrpc; -import armonik.client.session.impl.util.SessionClientRequestFactory; -import armonik.client.session.spec.ISessionClientSync; -import io.grpc.ManagedChannel; - -import java.util.List; - -public class SesssionClientSync implements ISessionClientSync { - private final SessionsGrpc.SessionsBlockingStub sessionsStub; - - /** - * Constructs a new ArmonikSession object using the provided gRPC ManagedChannel. - * - * @param managedChannel The gRPC ManagedChannel to communicate with the Armonik service. - */ - - public SesssionClientSync(ManagedChannel managedChannel){ - sessionsStub = SessionsGrpc.newBlockingStub(managedChannel); - } - - /** - * Creates a new session in the Armonik system with the given task options and partition IDs. - * - * @param taskOptions The task options for the session. - * @param partitionIds The list of partition IDs. - * @return The ID of the created session. - */ - @Override - public String createSession(TaskOptions taskOptions, List partitionIds) { - CreateSessionRequest request = SessionClientRequestFactory.createSessionRequest(taskOptions, partitionIds); - return sessionsStub.createSession(request).getSessionId(); - } - - - - /** - * Retrieves session information for the specified session ID. - * - * @param sessionId The ID of the session to retrieve. - * @return The session information. - */ - @Override - public SessionRaw getSession(String sessionId) { - GetSessionRequest request = SessionClientRequestFactory.createGetSessionRequest(sessionId); - return sessionsStub.getSession(request).getSession(); - } - - /** - * Lists sessions based on pagination, filters, and sorting options. - * - * @param page The page number. - * @param pageSize The size of each page. - * @param filter The filters to apply. - * @param sort The sorting options. - * @return A ListSessionsResult object containing the list of sessions and total count. - */ - @Override - public List listSessions(int page, int pageSize, Filters filter, Sort sort) { - ListSessionsRequest request = SessionClientRequestFactory.createListSessionsRequest(page, pageSize, filter, sort); - return sessionsStub.listSessions(request).getSessionsList(); - } - - /** - * Cancels the session with the specified session ID. - * - * @param sessionId The ID of the session to cancel. - * @return The updated session information after cancellation. - */ - @Override - public SessionRaw cancelSession(String sessionId) { - CancelSessionRequest request = SessionClientRequestFactory.createCancelSessionRequest(sessionId); - return sessionsStub.cancelSession(request).getSession(); - } - - /** - * Pauses the session with the specified session ID. - * - * @param sessionId The ID of the session to pause. - * @return The updated session information after pausing. - */ - @Override - public SessionRaw pauseSession(String sessionId) { - PauseSessionRequest request = SessionClientRequestFactory.createPauseSessionRequest(sessionId); - return sessionsStub.pauseSession(request).getSession(); - } - - /** - * Resumes the session with the specified session ID. - * - * @param sessionId The ID of the session to resume. - * @return The updated session information after resuming. - */ - @Override - public SessionRaw resumeSession(String sessionId) { - ResumeSessionRequest request = SessionClientRequestFactory.createResumeSessionRequest(sessionId); - return sessionsStub.resumeSession(request).getSession(); - } - - /** - * Closes the session with the specified session ID. - * - * @param sessionId The ID of the session to close. - * @return the closed session - */ - @Override - public SessionRaw closeSession(String sessionId){ - CloseSessionRequest closeSessionRequest = SessionClientRequestFactory.createCloseSessionRequest(sessionId); - return sessionsStub.closeSession(closeSessionRequest).getSession(); - } - - /** - * Purges the session with the specified session ID. - * - * @param sessionId The ID of the session to purge. - * @return The updated session information after purging. - */ - @Override - public SessionRaw purgeSession(String sessionId){ - PurgeSessionRequest purgeSessionRequest = SessionClientRequestFactory.createPurgeSessionRequest(sessionId); - return sessionsStub.purgeSession(purgeSessionRequest).getSession(); - } - - /** - * Deletes the session with the specified session ID. - * - * @param sessionId The ID of the session to delete. - * @return The updated session information after deletion. - */ - @Override - public SessionRaw deleteSession(String sessionId){ - DeleteSessionRequest deleteSessionRequest = SessionClientRequestFactory.createDeleteSessionRequest(sessionId); - return sessionsStub.deleteSession(deleteSessionRequest).getSession(); - } - - /** - * Stops submission for the session with the specified session ID. - * - * @param sessionId The ID of the session to stop submission for. - * @param client Boolean indicating whether to stop client submissions. - * @param worker Boolean indicating whether to stop worker submissions. - * @return The updated session information after stopping submissions. - */ - @Override - public SessionRaw stopSubmissionSession(String sessionId, boolean client, boolean worker){ - StopSubmissionRequest request = SessionClientRequestFactory.createStopSubmissionSessionRequest(sessionId, client, worker); - return sessionsStub.stopSubmission(request).getSession(); - } - - -} diff --git a/packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java b/packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java deleted file mode 100644 index 88759ea19..000000000 --- a/packages/java/src/main/java/armonik/client/session/impl/util/SessionClientRequestFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -package armonik.client.session.impl.util; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.sessions.SessionsCommon.*; -import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; -import armonik.api.grpc.v1.sessions.SessionsFilters; - -import java.util.List; - -public abstract class SessionClientRequestFactory { - - - public static CreateSessionRequest createSessionRequest(Objects.TaskOptions taskOptions, List partitionIds) { - List partIds = partitionIds == null || partitionIds.isEmpty() ? null : partitionIds; - return CreateSessionRequest.newBuilder() - .setDefaultTaskOption(taskOptions) - .addAllPartitionIds(partIds) - .build(); - } - - public static GetSessionRequest createGetSessionRequest(String sessionId) { - return GetSessionRequest - .newBuilder() - .setSessionId(sessionId) - .build(); - } - - public static ListSessionsRequest createListSessionsRequest(int page, int pageSize, SessionsFilters.Filters filter, Sort sort) { - return ListSessionsRequest.newBuilder() - .setPage(page) - .setPageSize(pageSize) - .setFilters(filter) - .setSort(sort) - .build(); - } - - public static CancelSessionRequest createCancelSessionRequest(String sessionId) { - return CancelSessionRequest.newBuilder().setSessionId(sessionId).build(); - } - - public static PauseSessionRequest createPauseSessionRequest(String sessionId) { - return PauseSessionRequest.newBuilder().setSessionId(sessionId).build(); - } - - public static ResumeSessionRequest createResumeSessionRequest(String sessionId) { - return ResumeSessionRequest.newBuilder().setSessionId(sessionId).build(); - } - - public static CloseSessionRequest createCloseSessionRequest(String sessionId) { - return CloseSessionRequest.newBuilder().setSessionId(sessionId).build(); - } - - public static PurgeSessionRequest createPurgeSessionRequest(String sessionId) { - return PurgeSessionRequest.newBuilder().setSessionId(sessionId).build(); - - } - - public static DeleteSessionRequest createDeleteSessionRequest(String sessionId) { - return DeleteSessionRequest.newBuilder().setSessionId(sessionId).build(); - } - - public static StopSubmissionRequest createStopSubmissionSessionRequest(String sessionId, boolean client, boolean worker) { - return StopSubmissionRequest.newBuilder() - .setSessionId(sessionId) - .setClient(client) - .setWorker(worker) - .build(); - } -} diff --git a/packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java b/packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java deleted file mode 100644 index 6c871222d..000000000 --- a/packages/java/src/main/java/armonik/client/session/spec/ISessionClientAsync.java +++ /dev/null @@ -1,30 +0,0 @@ -package armonik.client.session.spec; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.sessions.SessionsCommon; -import armonik.api.grpc.v1.sessions.SessionsFilters; -import io.grpc.stub.StreamObserver; - -import java.util.List; - -public interface ISessionClientAsync { - void createSession(Objects.TaskOptions taskOptions, List partitionIds, StreamObserver streamObserver); - - void getSession(String sessionId, StreamObserver rawStreamObserver); - - void listSessions(int page, int pageSize, SessionsFilters.Filters filter, SessionsCommon.ListSessionsRequest.Sort sort, StreamObserver> listStreamObserver); - - void cancelSession(String sessionId, StreamObserver sessionRawStreamObserver) throws Exception; - - void pauseSession(String sessionId, StreamObserver sessionRawStreamObserver); - - void resumeSession(String sessionId, StreamObserver sessionRawStreamObserver); - - void closeSession(String sessionId, StreamObserver sessionRawStreamObserver); - - void purgeSession(String sessionId, StreamObserver sessionRawStreamObserver); - - void deleteSession(String sessionId, StreamObserver sessionRawStreamObserver); - - void stopSubmissionSession(String sessionId, boolean client, boolean worker, StreamObserver sessionRawStreamObserver); -} diff --git a/packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java b/packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java deleted file mode 100644 index 4d6efe115..000000000 --- a/packages/java/src/main/java/armonik/client/session/spec/ISessionClientSync.java +++ /dev/null @@ -1,52 +0,0 @@ -package armonik.client.session.spec; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.sessions.SessionsCommon.ListSessionsRequest.Sort; -import armonik.api.grpc.v1.sessions.SessionsCommon.SessionRaw; -import armonik.api.grpc.v1.sessions.SessionsFilters.Filters; - -import java.util.List; - -public interface ISessionClientSync { - default String createSession(Objects.TaskOptions taskOptions, List partitionIds) { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw getSession(String sessionId) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default List listSessions(int page, int pageSize, Filters filter, Sort sort) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw cancelSession(String sessionId) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw pauseSession(String sessionId) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw resumeSession(String sessionId) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw closeSession(String sessionId) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw purgeSession(String sessionId) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw deleteSession(String sessionId) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - default SessionRaw stopSubmissionSession(String sessionId, boolean client, boolean worker) throws Exception { - throw new UnsupportedOperationException("Method not implemented"); - } - - -} diff --git a/packages/java/src/main/java/armonik/client/task/TaskClientFactory.java b/packages/java/src/main/java/armonik/client/task/TaskClientFactory.java deleted file mode 100644 index 3c6e543e9..000000000 --- a/packages/java/src/main/java/armonik/client/task/TaskClientFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -package armonik.client.task; - -import armonik.client.task.impl.TaskClientAsync; -import armonik.client.task.impl.TaskClientSync; -import armonik.client.task.spec.ITaskClientAsync; -import armonik.client.task.spec.ITaskClientSync; -import io.grpc.ManagedChannel; - -/** - * TaskClientFactory provides factory methods to create instances of task client implementations. - */ -public abstract class TaskClientFactory { - - /** - * Creates a synchronous task client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the task service - * @return an instance of {@link ITaskClientSync} representing a synchronous task client - */ - public static ITaskClientSync createTaskClientSync(ManagedChannel managedChannel){ - return new TaskClientSync(managedChannel); - } - - /** - * Creates an asynchronous task client instance with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the task service - * @return an instance of {@link ITaskClientAsync} representing an asynchronous task client - */ - public static ITaskClientAsync createTaskClientAsync(ManagedChannel managedChannel){ - return new TaskClientAsync(managedChannel); - } -} diff --git a/packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java b/packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java deleted file mode 100644 index d164288d2..000000000 --- a/packages/java/src/main/java/armonik/client/task/impl/TaskClientAsync.java +++ /dev/null @@ -1,203 +0,0 @@ -package armonik.client.task.impl; - -import armonik.api.grpc.v1.Objects.TaskOptions; -import armonik.api.grpc.v1.tasks.TasksCommon.*; -import armonik.api.grpc.v1.tasks.TasksCommon.GetResultIdsResponse.MapTaskResult; -import armonik.api.grpc.v1.tasks.TasksCommon.ListTasksRequest.Sort; -import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksRequest.TaskCreation; -import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksResponse.TaskInfo; -import armonik.api.grpc.v1.tasks.TasksFilters.Filters; -import armonik.api.grpc.v1.tasks.TasksGrpc; -import armonik.api.grpc.v1.tasks.TasksGrpc.TasksStub; -import armonik.client.task.impl.util.TaskClientRequestFactory; -import armonik.client.task.spec.ITaskClientAsync; -import io.grpc.ManagedChannel; -import io.grpc.stub.StreamObserver; - -import java.util.List; - -/** - * TaskClientAsync is an asynchronous implementation of the {@link ITaskClientAsync} interface. - * It communicates with the task service using a non-blocking stub, making asynchronous calls to perform various task-related operations. - */ -public class TaskClientAsync implements ITaskClientAsync { - private final TasksStub taskStub; - - - /** - * Constructs a TaskClientAsync object with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the task service - */ - public TaskClientAsync(ManagedChannel managedChannel) { - this.taskStub = TasksGrpc.newStub(managedChannel); - } - - @Override - public void submitTasks(String sessionId, List taskCreations, TaskOptions taskOptions, StreamObserver> responseObserver) { - SubmitTasksRequest request = TaskClientRequestFactory.createSubmitTasksRequest(sessionId, taskCreations, taskOptions); - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(SubmitTasksResponse submitTasksResponse) { - responseObserver.onNext(submitTasksResponse.getTaskInfosList()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - taskStub.submitTasks(request, observer); - } - - @Override - public void countTasksByStatus(Filters filters, StreamObserver responseObserver) { - CountTasksByStatusRequest request = TaskClientRequestFactory.createCountTasksByStatusRequest(filters); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(CountTasksByStatusResponse countTasksByStatusResponse) { - responseObserver.onNext(countTasksByStatusResponse); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - - taskStub.countTasksByStatus(request, observer); - } - - @Override - public void getResultIds(List tasksIds, StreamObserver> responseObserver) { - GetResultIdsRequest request = TaskClientRequestFactory.createGetResultIdsRequest(tasksIds); - - StreamObserver observer = new StreamObserver() { - @Override - public void onNext(GetResultIdsResponse getResultIdsResponse) { - responseObserver.onNext(getResultIdsResponse.getTaskResultsList()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - taskStub.getResultIds(request, observer); - } - - @Override - public void cancelTasks(List tasksIds, StreamObserver> responseObserver) { - CancelTasksRequest request = TaskClientRequestFactory.createCancelTasksRequest(tasksIds); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(CancelTasksResponse cancelTasksResponse) { - responseObserver.onNext(cancelTasksResponse.getTasksList()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - taskStub.cancelTasks(request, observer); - } - - @Override - public void getTask(String taskId, StreamObserver responseObserver) throws NoSuchMethodException { - GetTaskRequest request = TaskClientRequestFactory.createGetTaskRequest(taskId); - - StreamObserver observer = new StreamObserver<>() { - - @Override - public void onNext(GetTaskResponse getTaskResponse) { - responseObserver.onNext(getTaskResponse.getTask()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - taskStub.getTask(request, observer); - } - - @Override - public void listTasksDetailed(int page, int pageSize, Filters filters, Sort sort, StreamObserver> responseObserver) { - - ListTasksRequest request = TaskClientRequestFactory.createListTasksDetailedRequest(page, pageSize, filters, sort); - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(ListTasksDetailedResponse listTasksDetailedResponse) { - responseObserver.onNext(listTasksDetailedResponse.getTasksList()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - taskStub.listTasksDetailed(request, observer); - } - - @Override - public void listTasks(int page, int pageSize, Filters filters, Sort sort, StreamObserver> responseObserver) { - ListTasksRequest request = TaskClientRequestFactory.createListTasksSummaryRequest(page, pageSize, filters, sort); - - StreamObserver observer = new StreamObserver<>() { - @Override - public void onNext(ListTasksResponse listTasksResponse) { - responseObserver.onNext(listTasksResponse.getTasksList()); - } - - @Override - public void onError(Throwable throwable) { - responseObserver.onError(throwable); - } - - @Override - public void onCompleted() { - responseObserver.onCompleted(); - } - }; - - - taskStub.listTasks(request, observer); - } -} diff --git a/packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java b/packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java deleted file mode 100644 index da51a5b1a..000000000 --- a/packages/java/src/main/java/armonik/client/task/impl/TaskClientSync.java +++ /dev/null @@ -1,79 +0,0 @@ -package armonik.client.task.impl; - -import armonik.api.grpc.v1.Objects.StatusCount; -import armonik.api.grpc.v1.Objects.TaskOptions; -import armonik.api.grpc.v1.tasks.TasksCommon.*; -import armonik.api.grpc.v1.tasks.TasksCommon.ListTasksRequest.Sort; -import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksRequest.TaskCreation; -import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksResponse.TaskInfo; -import armonik.api.grpc.v1.tasks.TasksFilters.Filters; -import armonik.api.grpc.v1.tasks.TasksGrpc; -import armonik.api.grpc.v1.tasks.TasksGrpc.TasksBlockingStub; -import armonik.client.task.impl.util.TaskClientRequestFactory; -import armonik.client.task.spec.ITaskClientSync; -import io.grpc.ManagedChannel; - -import java.util.List; - -import static armonik.api.grpc.v1.tasks.TasksCommon.GetResultIdsResponse.MapTaskResult; - -/** - * TaskClientSync is a synchronous implementation of the {@link ITaskClientSync} interface. - * It communicates with the task service using a blocking stub, making synchronous calls to perform various task-related operations. - */ -public class TaskClientSync implements ITaskClientSync { - private final TasksBlockingStub taskStub; - - - /** - * Constructs a TaskClientSync object with the provided managed channel. - * - * @param managedChannel the managed channel used for communication with the task service - */ - public TaskClientSync(ManagedChannel managedChannel) { - this.taskStub = TasksGrpc.newBlockingStub(managedChannel); - } - - @Override - public List listTasks(int page, int pageSize, Filters filters, Sort sort) { - ListTasksRequest request = TaskClientRequestFactory.createListTasksSummaryRequest(page, pageSize, filters, sort); - return taskStub.listTasks(request).getTasksList(); - } - - @Override - public List listTasksDetailed(int page, int pageSize, Filters filters, Sort sort) { - ListTasksRequest request = TaskClientRequestFactory.createListTasksDetailedRequest(page, pageSize, filters, sort); - return taskStub.listTasksDetailed(request).getTasksList(); - } - - @Override - public TaskDetailed getTask(String taskId) { - GetTaskRequest request = TaskClientRequestFactory.createGetTaskRequest(taskId); - return taskStub.getTask(request).getTask(); - } - - @Override - public List cancelTasks(List tasksIds) { - CancelTasksRequest request = TaskClientRequestFactory.createCancelTasksRequest(tasksIds); - return taskStub.cancelTasks(request).getTasksList(); - } - - - @Override - public List getResultIds(List tasksIds) { - GetResultIdsRequest request = TaskClientRequestFactory.createGetResultIdsRequest(tasksIds); - return taskStub.getResultIds(request).getTaskResultsList(); - } - - @Override - public List countTasksByStatus(Filters filters) { - CountTasksByStatusRequest request = TaskClientRequestFactory.createCountTasksByStatusRequest(filters); - return taskStub.countTasksByStatus(request).getStatusList(); - } - - @Override - public List submitTasks(String sessionId, List taskCreations, TaskOptions taskOptions) { - SubmitTasksRequest request = TaskClientRequestFactory.createSubmitTasksRequest(sessionId, taskCreations, taskOptions); - return taskStub.submitTasks(request).getTaskInfosList(); - } -} diff --git a/packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java b/packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java deleted file mode 100644 index 14e16a8a0..000000000 --- a/packages/java/src/main/java/armonik/client/task/impl/util/TaskClientRequestFactory.java +++ /dev/null @@ -1,77 +0,0 @@ -package armonik.client.task.impl.util; - -import armonik.api.grpc.v1.Objects.TaskOptions; -import armonik.api.grpc.v1.tasks.TasksCommon; -import armonik.api.grpc.v1.tasks.TasksCommon.*; -import armonik.api.grpc.v1.tasks.TasksCommon.ListTasksRequest.Sort; -import armonik.api.grpc.v1.tasks.TasksCommon.SubmitTasksRequest.TaskCreation; -import armonik.api.grpc.v1.tasks.TasksFilters.Filters; - -import java.util.List; - -import static armonik.api.grpc.v1.Objects.TaskOptions.getDefaultInstance; - -public abstract class TaskClientRequestFactory { - public static ListTasksRequest createListTasksSummaryRequest(int page, int pageSize, Filters filters, Sort sort) { - return ListTasksRequest.newBuilder() - .setPage(page) - .setPageSize(pageSize) - .setFilters(filters) - .setSort(sort) - .build(); - } - - public static ListTasksRequest createListTasksDetailedRequest(int page, int pageSize, Filters filters, Sort sort) { - return TasksCommon.ListTasksRequest.newBuilder() - .setSort(sort) - .setPageSize(page) - .setPageSize(pageSize) - .setFilters(filters) - .build(); - } - - public static GetTaskRequest createGetTaskRequest(String taskId) { - return GetTaskRequest.newBuilder() - .setTaskId(taskId) - .build(); - } - - public static CancelTasksRequest createCancelTasksRequest(List tasksIds) { - return CancelTasksRequest.newBuilder() - .addAllTaskIds(tasksIds) - .build(); - } - - public static GetResultIdsRequest createGetResultIdsRequest(List tasksIds) { - return GetResultIdsRequest.newBuilder() - .addAllTaskId(tasksIds) - .build(); - - } - - public static CountTasksByStatusRequest createCountTasksByStatusRequest(Filters filters) { - return CountTasksByStatusRequest.newBuilder() - .setFilters(filters) - .build(); - } - - public static SubmitTasksRequest createSubmitTasksRequest(String sessionId, List taskCreations, TaskOptions taskOptions) { - SubmitTasksRequest.Builder requestBuilder = SubmitTasksRequest.newBuilder(); - - requestBuilder.setSessionId(sessionId); - - if (!taskOptions.equals(getDefaultInstance())) { - requestBuilder.setTaskOptions(taskOptions); - } - taskCreations.forEach(taskCreation -> { - requestBuilder - .addTaskCreationsBuilder() - .setPayloadId(taskCreation.getPayloadId()) - .addAllDataDependencies(taskCreation.getDataDependenciesList()) - .addAllExpectedOutputKeys(taskCreation.getExpectedOutputKeysList()) - .setTaskOptions(!taskCreation.getTaskOptions().equals(getDefaultInstance()) ? taskCreation.getTaskOptions() : getDefaultInstance()); - }); - - return requestBuilder.build(); - } -} diff --git a/packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java b/packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java deleted file mode 100644 index b7544581b..000000000 --- a/packages/java/src/main/java/armonik/client/task/spec/ITaskClientAsync.java +++ /dev/null @@ -1,24 +0,0 @@ -package armonik.client.task.spec; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.tasks.TasksCommon; -import armonik.api.grpc.v1.tasks.TasksFilters; -import io.grpc.stub.StreamObserver; - -import java.util.List; - -public interface ITaskClientAsync { - void submitTasks(String sessionId, List taskCreations, Objects.TaskOptions taskOptions, StreamObserver> responseObserver); - - void countTasksByStatus(TasksFilters.Filters filters, StreamObserver responseObserver); - - void getResultIds(List tasksIds, StreamObserver> responseObserver); - - void cancelTasks(List tasksIds, StreamObserver> responseObserver); - - void getTask(String taskId, StreamObserver responseObserver) throws NoSuchMethodException; - - void listTasksDetailed(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort, StreamObserver> responseObserver) throws NoSuchMethodException; - - void listTasks(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort, StreamObserver> responseObserver) throws NoSuchMethodException; -} diff --git a/packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java b/packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java deleted file mode 100644 index d4ed2d13e..000000000 --- a/packages/java/src/main/java/armonik/client/task/spec/ITaskClientSync.java +++ /dev/null @@ -1,23 +0,0 @@ -package armonik.client.task.spec; - -import armonik.api.grpc.v1.Objects; -import armonik.api.grpc.v1.tasks.TasksCommon; -import armonik.api.grpc.v1.tasks.TasksFilters; - -import java.util.List; - -public interface ITaskClientSync { - List listTasks(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort); - - List listTasksDetailed(int page, int pageSize, TasksFilters.Filters filters, TasksCommon.ListTasksRequest.Sort sort); - - TasksCommon.TaskDetailed getTask(String taskId); - - List cancelTasks(List tasksIds); - - List getResultIds(List tasksIds); - - List countTasksByStatus(TasksFilters.Filters filters); - - List submitTasks(String sessionId, List taskCreations, Objects.TaskOptions taskOptions); -} diff --git a/packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d45..000000000 --- a/packages/java/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline