>From Hussain Towaileb <[email protected]>:
Hussain Towaileb has uploaded this change for review. (
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19562 )
Change subject: [NO ISSUE][EXT]: Fail early in COPY TO if no write permissin
......................................................................
[NO ISSUE][EXT]: Fail early in COPY TO if no write permissin
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- fail early if no write permission.
- correctly check for bucket not found exception.
Ext-ref: MB-66031
Change-Id: I954a60004f104aea4787075a94a069daca305fde
---
M
asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriterFactory.java
M
asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/GCSExternalFileWriterFactory.java
M
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
M
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
M
asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
5 files changed, 69 insertions(+), 44 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/62/19562/1
diff --git
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriterFactory.java
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriterFactory.java
index 198b3ad..6132a4b 100644
---
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriterFactory.java
+++
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriterFactory.java
@@ -39,7 +39,6 @@
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.exceptions.SourceLocation;
-import org.apache.hyracks.api.util.ExceptionUtils;
import org.apache.hyracks.data.std.primitive.LongPointable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -63,9 +62,7 @@
abstract ICloudClient createCloudClient(IApplicationContext appCtx) throws
CompilationException;
- abstract boolean isNoContainerFoundException(IOException e);
-
- abstract boolean isSdkException(Throwable e);
+ abstract Throwable getCloudSpecificException(Throwable ex);
final void buildClient(IApplicationContext appCtx) throws
HyracksDataException {
try {
@@ -91,18 +88,16 @@
try {
doValidate(testClient, bucket);
- } catch (IOException e) {
- if (isNoContainerFoundException(e)) {
- throw
CompilationException.create(ErrorCode.EXTERNAL_SOURCE_CONTAINER_NOT_FOUND,
bucket);
- } else {
- throw
CompilationException.create(ErrorCode.EXTERNAL_SINK_ERROR,
- ExceptionUtils.getMessageOrToString(e));
- }
} catch (Throwable e) {
- if (isSdkException(e)) {
- throw
CompilationException.create(ErrorCode.EXTERNAL_SINK_ERROR, e,
getMessageOrToString(e));
+ Throwable cloudException = getCloudSpecificException(e);
+ if (cloudException != null) {
+ throw
CompilationException.create(ErrorCode.EXTERNAL_SINK_ERROR, cloudException,
+ getMessageOrToString(cloudException));
}
- throw e;
+ if (e instanceof AlgebricksException algebricksException) {
+ throw algebricksException;
+ }
+ throw CompilationException.create(ErrorCode.EXTERNAL_SINK_ERROR,
e, getMessageOrToString(e));
}
}
@@ -145,6 +140,7 @@
} catch (HyracksDataException e) {
writer.abort();
aborted = true;
+ throw e;
} finally {
if (writer != null && !aborted) {
writer.finish();
diff --git
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/GCSExternalFileWriterFactory.java
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/GCSExternalFileWriterFactory.java
index 3a34365..501f901 100644
---
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/GCSExternalFileWriterFactory.java
+++
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/GCSExternalFileWriterFactory.java
@@ -18,8 +18,6 @@
*/
package org.apache.asterix.cloud.writer;
-import java.io.IOException;
-
import org.apache.asterix.cloud.clients.ICloudClient;
import org.apache.asterix.cloud.clients.ICloudGuardian;
import org.apache.asterix.cloud.clients.google.gcs.GCSClientConfig;
@@ -39,9 +37,9 @@
import org.apache.hyracks.api.context.IHyracksTaskContext;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.exceptions.IWarningCollector;
+import org.apache.hyracks.api.util.ExceptionUtils;
import com.google.cloud.BaseServiceException;
-import com.google.cloud.storage.StorageException;
public final class GCSExternalFileWriterFactory extends
AbstractCloudExternalFileWriterFactory {
private static final long serialVersionUID = 1L;
@@ -71,13 +69,8 @@
}
@Override
- boolean isNoContainerFoundException(IOException e) {
- return e.getCause() instanceof StorageException;
- }
-
- @Override
- boolean isSdkException(Throwable e) {
- return e instanceof BaseServiceException;
+ Throwable getCloudSpecificException(Throwable ex) {
+ return ExceptionUtils.getCauseOfType(ex, BaseServiceException.class);
}
@Override
diff --git
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
index 6e5333f..9b6fede 100644
---
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
+++
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
@@ -18,8 +18,6 @@
*/
package org.apache.asterix.cloud.writer;
-import java.io.IOException;
-
import org.apache.asterix.cloud.clients.ICloudClient;
import org.apache.asterix.cloud.clients.ICloudGuardian;
import org.apache.asterix.cloud.clients.aws.s3.S3ClientConfig;
@@ -39,9 +37,9 @@
import org.apache.hyracks.api.context.IHyracksTaskContext;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.exceptions.IWarningCollector;
+import org.apache.hyracks.api.util.ExceptionUtils;
import software.amazon.awssdk.core.exception.SdkException;
-import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
public final class S3ExternalFileWriterFactory extends
AbstractCloudExternalFileWriterFactory {
private static final long serialVersionUID = 4551318140901866805L;
@@ -71,13 +69,8 @@
}
@Override
- boolean isNoContainerFoundException(IOException e) {
- return e.getCause() instanceof NoSuchBucketException;
- }
-
- @Override
- boolean isSdkException(Throwable e) {
- return e instanceof SdkException;
+ Throwable getCloudSpecificException(Throwable ex) {
+ return ExceptionUtils.getCauseOfType(ex, SdkException.class);
}
@Override
diff --git
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
index 75fb18d..ed29eb5 100644
---
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
+++
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
@@ -27,20 +27,21 @@
public class CompilationException extends AlgebricksException {
private static final long serialVersionUID = 1L;
- public static CompilationException create(ErrorCode error, SourceLocation
sourceLoc, Serializable... params) {
- return new CompilationException(error, sourceLoc, params);
- }
-
public static CompilationException create(ErrorCode error, Serializable...
params) {
- return create(error, null, params);
+ return create(error, null, null, params);
}
- public CompilationException(ErrorCode error, Throwable cause,
SourceLocation sourceLoc, Serializable... params) {
- super(error, cause, sourceLoc, params);
+ public static CompilationException create(ErrorCode error, Throwable th,
Serializable... params) {
+ return create(error, th, null, params);
}
- public CompilationException(ErrorCode error, SourceLocation sourceLoc,
Serializable... params) {
- this(error, null, sourceLoc, params);
+ public static CompilationException create(ErrorCode error, SourceLocation
sourceLoc, Serializable... params) {
+ return create(error, null, sourceLoc, params);
+ }
+
+ public static CompilationException create(ErrorCode error, Throwable th,
SourceLocation sourceLoc,
+ Serializable... params) {
+ return new CompilationException(error, th, sourceLoc, params);
}
public CompilationException(ErrorCode error, Serializable... params) {
@@ -51,6 +52,14 @@
this(errorCode, cause, null, params);
}
+ public CompilationException(ErrorCode error, SourceLocation sourceLoc,
Serializable... params) {
+ this(error, null, sourceLoc, params);
+ }
+
+ public CompilationException(ErrorCode error, Throwable cause,
SourceLocation sourceLoc, Serializable... params) {
+ super(error, cause, sourceLoc, params);
+ }
+
/**
* @deprecated (Don't use this and provide an error code. This exists for
the current exceptions and
* those exceptions need to adopt error code as well.)
@@ -81,4 +90,4 @@
super(message, cause);
}
-}
+}
\ No newline at end of file
diff --git
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
index ddba3f0..27c0fad 100644
---
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
+++
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
@@ -222,4 +222,20 @@
public static boolean isErrorCode(HyracksDataException throwable,
ErrorCode code) {
return throwable.getError().isPresent() && throwable.getError().get()
== code;
}
+
+ public static <T extends Throwable> T getCauseOfType(Throwable throwable,
Class<T> targetType) {
+ if (throwable == null || targetType == null) {
+ return null;
+ }
+
+ Throwable cause = throwable;
+ while (cause != null) {
+ if (targetType.isInstance(cause)) {
+ return targetType.cast(cause);
+ }
+ cause = cause.getCause();
+ }
+
+ return null;
+ }
}
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19562
To unsubscribe, or for help writing mail filters, visit
https://asterix-gerrit.ics.uci.edu/settings
Gerrit-Project: asterixdb
Gerrit-Branch: ionic
Gerrit-Change-Id: I954a60004f104aea4787075a94a069daca305fde
Gerrit-Change-Number: 19562
Gerrit-PatchSet: 1
Gerrit-Owner: Hussain Towaileb <[email protected]>
Gerrit-MessageType: newchange