>From Ali Alsuliman <[email protected]>:

Ali Alsuliman has submitted this change. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21180?usp=email )

Change subject: [ASTERIXDB-3649][API] Print request status after receiving CC 
response
......................................................................

[ASTERIXDB-3649][API] Print request status after receiving CC response

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
For async request, print the request status after the node
receives the response from the CC. For SUCCESS,RUNNING,QUEUED
statuses, print them as QUEUED.

- report jobQueueTime only if the job was created, otherwise
  set to 0.

Ext-ref: MB-69763
Change-Id: I71ab1e4b9d58ac36ae9f0560b20b2c28eaa06657
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21180
Tested-by: Jenkins <[email protected]>
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Ali Alsuliman <[email protected]>
Reviewed-by: Murtadha Hubail <[email protected]>
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ClientRequest.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
3 files changed, 15 insertions(+), 8 deletions(-)

Approvals:
  Anon. E. Moose #1000171:
  Jenkins: Verified; Verified
  Murtadha Hubail: Looks good to me, approved
  Ali Alsuliman: Looks good to me, but someone else must approve




diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ClientRequest.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ClientRequest.java
index 5c8310d..4e9a366 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ClientRequest.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ClientRequest.java
@@ -181,7 +181,10 @@
         putTime(json, state.createTime, "jobCreateTime", dateTime);
         putTime(json, state.startTime, "jobStartTime", dateTime);
         putTime(json, state.endTime, "jobEndTime", dateTime);
-        long queueTime = (state.startTime > 0 ? state.startTime : 
System.currentTimeMillis()) - state.createTime;
+        long queueTime = 0;
+        if (state.createTime > 0) {
+            queueTime = (state.startTime > 0 ? state.startTime : 
System.currentTimeMillis()) - state.createTime;
+        }
         json.put("jobQueueTime", TimeUnit.MILLISECONDS.toSeconds(queueTime));
         json.put("jobStatus", String.valueOf(state.status));
         json.put("jobRequiredCPUs", state.requiredCPUs);
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index 879332c..23e3d2b 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -322,10 +322,8 @@
             responsePrinter.addFooterPrinter(new 
StatusPrinter(executionState.getResultStatus()));
             responsePrinter.addFooterPrinter(new MetricsPrinter(metrics, 
resultCharset));
         } else {
-            // in case of ASYNC mode and compilation/parsing error, we need to 
print the statust
-            if (executionState.getResultStatus() == ResultStatus.FATAL) {
-                responsePrinter.addFooterPrinter(new 
StatusPrinter(ResultStatus.FATAL));
-            }
+            // in case of ASYNC mode and compilation/parsing error, we need to 
print the status
+            responsePrinter.addFooterPrinter(new 
StatusPrinter(getAsyncResultStatus(executionState.getResultStatus())));
             // Only print selected metrics for async requests
             responsePrinter.addFooterPrinter(new MetricsPrinter(metrics, 
resultCharset,
                     Set.of(MetricsPrinter.Metrics.ELAPSED_TIME, 
MetricsPrinter.Metrics.QUEUE_WAIT_TIME,
@@ -339,6 +337,15 @@
         return metrics;
     }

+    private static ResultStatus getAsyncResultStatus(ResultStatus 
resultStatus) {
+        return switch (resultStatus) {
+            case FATAL -> ResultStatus.FATAL;
+            case TIMEOUT -> ResultStatus.TIMEOUT;
+            case FAILED -> ResultStatus.FAILED;
+            default -> ResultStatus.QUEUED;
+        };
+    }
+
     protected void validateStatement(String statement) throws 
RuntimeDataException {
         if (statement == null || statement.isEmpty()) {
             throw new RuntimeDataException(NO_STATEMENT_PROVIDED);
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 53d2ec4..ea42a3d 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -59,7 +59,6 @@
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
 import org.apache.asterix.algebra.extension.ExtensionStatement;
 import org.apache.asterix.api.common.APIFramework;
-import org.apache.asterix.api.http.server.AbstractQueryApiServlet;
 import org.apache.asterix.api.http.server.ApiServlet;
 import org.apache.asterix.app.active.ActiveEntityEventsListener;
 import org.apache.asterix.app.active.ActiveNotificationHandler;
@@ -69,7 +68,6 @@
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.app.result.fields.ResultHandlePrinter;
 import org.apache.asterix.app.result.fields.ResultsPrinter;
-import org.apache.asterix.app.result.fields.StatusPrinter;
 import 
org.apache.asterix.app.translator.handlers.IcebergCatalogStatementHandler;
 import 
org.apache.asterix.app.translator.helpers.IcebergStatementValidationHelper;
 import org.apache.asterix.column.validation.ColumnPropertiesValidationUtil;
@@ -5705,7 +5703,6 @@
                     jobIdFuture.complete(id);
                     final ResultHandle handle = sessionConfig.isIncludeHost() 
? new ResultHandle(id, resultSetId, null)
                             : new ResultHandle(id, resultSetId, 
requestParameters.getRequestReference().getUuid());
-                    responsePrinter.addResultPrinter(new 
StatusPrinter(AbstractQueryApiServlet.ResultStatus.QUEUED));
                     responsePrinter.addResultPrinter(new 
ResultHandlePrinter(sessionOutput, handle));
                     responsePrinter.printResults();
                     synchronized (printed) {

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21180?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: asterixdb
Gerrit-Branch: lumina
Gerrit-Change-Id: I71ab1e4b9d58ac36ae9f0560b20b2c28eaa06657
Gerrit-Change-Number: 21180
Gerrit-PatchSet: 2
Gerrit-Owner: Ali Alsuliman <[email protected]>
Gerrit-Reviewer: Ali Alsuliman <[email protected]>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Jenkins <[email protected]>
Gerrit-Reviewer: Murtadha Hubail <[email protected]>

Reply via email to