-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception mappers to convert storage failures to Iceberg REST cli…
…ent exceptions * Note: before this change a storage 403 error would manifest as 500 on the REST client side. * Add AccessCheckHandler to ObjectStorageMock for simulating access failures in tests.
- Loading branch information
Showing
16 changed files
with
338 additions
and
13 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
.../files/api/src/main/java/org/projectnessie/catalog/files/api/ObjectIOExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2024 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.catalog.files.api; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.util.Collection; | ||
import java.util.OptionalInt; | ||
import java.util.ServiceLoader; | ||
import org.projectnessie.storage.uri.StorageUri; | ||
|
||
public interface ObjectIOExceptionMapper { | ||
|
||
OptionalInt toHttpStatusCode(Throwable th); | ||
|
||
static StorageFailureException toStorageFailure(StorageUri uri, boolean read, Throwable th) { | ||
if (th instanceof StorageFailureException) { | ||
return (StorageFailureException) th; | ||
} | ||
|
||
for (ObjectIOExceptionMapper mapper : Mappers.values) { | ||
OptionalInt status = mapper.toHttpStatusCode(th); | ||
if (status.isPresent()) { | ||
return new StorageFailureException(uri, read, status.getAsInt(), th); | ||
} | ||
} | ||
|
||
return new StorageFailureException(uri, read, 500, th); | ||
} | ||
|
||
class Mappers { | ||
private static final Collection<ObjectIOExceptionMapper> values; | ||
|
||
static { | ||
ImmutableList.Builder<ObjectIOExceptionMapper> list = ImmutableList.builder(); | ||
ServiceLoader.load(ObjectIOExceptionMapper.class).forEach(list::add); | ||
values = list.build(); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../files/api/src/main/java/org/projectnessie/catalog/files/api/StorageFailureException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2024 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.catalog.files.api; | ||
|
||
import org.projectnessie.storage.uri.StorageUri; | ||
|
||
public class StorageFailureException extends NonRetryableException { | ||
private final StorageUri uri; | ||
private final boolean read; | ||
private final int httpStatusCode; | ||
|
||
public StorageFailureException( | ||
StorageUri uri, boolean read, int httpStatusCode, Throwable cause) { | ||
super(cause); | ||
this.uri = uri; | ||
this.read = read; | ||
this.httpStatusCode = httpStatusCode; | ||
} | ||
|
||
public StorageUri getUri() { | ||
return uri; | ||
} | ||
|
||
public boolean isRead() { | ||
return read; | ||
} | ||
|
||
public int getHttpStatusCode() { | ||
return httpStatusCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
catalog/files/impl/src/main/java/org/projectnessie/catalog/files/gcs/GcsExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2024 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.catalog.files.gcs; | ||
|
||
import com.google.cloud.storage.StorageException; | ||
import java.util.OptionalInt; | ||
import org.projectnessie.catalog.files.api.ObjectIOExceptionMapper; | ||
|
||
/** Extracts storage-side HTTP status code from GCS client exceptions. */ | ||
public class GcsExceptionMapper implements ObjectIOExceptionMapper { | ||
// Note: unlike S3 and ADLS, GCS clients can throw access failures from I/O stream methods, | ||
// which is why GCS exceptions have to be mapped by a generic exception mapper as opposed to | ||
// a simple `catch` block in `GcsObjectIO`. | ||
|
||
@Override | ||
public OptionalInt toHttpStatusCode(Throwable th) { | ||
while (th != null) { | ||
if (th instanceof StorageException) { | ||
return OptionalInt.of((((StorageException) th).getCode())); | ||
} | ||
|
||
th = th.getCause(); | ||
} | ||
|
||
return OptionalInt.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...n/resources/META-INF/services/org.projectnessie.catalog.files.api.ObjectIOExceptionMapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright (C) 2024 Dremio | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
org.projectnessie.catalog.files.gcs.GcsExceptionMapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.