diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergCatalogWrapperManager.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergCatalogWrapperManager.java index cefc62bc268..6e25ceec427 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergCatalogWrapperManager.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergCatalogWrapperManager.java @@ -93,8 +93,7 @@ public IcebergCatalogWrapper getCatalogWrapper(String catalogName) { return catalogWrapper; } - public CredentialProvider getCredentialProvider(String prefix) { - String catalogName = IcebergRestUtils.getCatalogName(prefix); + public CredentialProvider getCredentialProvider(String catalogName) { return credentialProviderManager.getCredentialProvider(catalogName); } diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergRestUtils.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergRestUtils.java index af017b2de96..23ceb7790cf 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergRestUtils.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergRestUtils.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants; +import org.apache.iceberg.catalog.Namespace; import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.rest.responses.ErrorResponse; @@ -114,6 +115,13 @@ public static T cloneIcebergRESTObject(Object message, Class className) { } } + public static NameIdentifier getGravitinoNameIdentifier( + String metalakeName, String catalogName, Namespace namespace) { + Stream catalogNS = + Stream.concat(Stream.of(metalakeName, catalogName), Arrays.stream(namespace.levels())); + return NameIdentifier.of(catalogNS.toArray(String[]::new)); + } + // remove the last '/' from the prefix, for example transform 'iceberg_catalog/' to // 'iceberg_catalog' private static String normalizePrefix(String rawPrefix) { diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java index 315ba620378..bd49630dea5 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java @@ -25,10 +25,31 @@ import org.apache.gravitino.listener.api.event.IcebergCreateTableEvent; import org.apache.gravitino.listener.api.event.IcebergCreateTableFailureEvent; import org.apache.gravitino.listener.api.event.IcebergCreateTablePreEvent; +import org.apache.gravitino.listener.api.event.IcebergDropTableEvent; +import org.apache.gravitino.listener.api.event.IcebergDropTableFailureEvent; +import org.apache.gravitino.listener.api.event.IcebergDropTablePreEvent; +import org.apache.gravitino.listener.api.event.IcebergListTableEvent; +import org.apache.gravitino.listener.api.event.IcebergListTableFailureEvent; +import org.apache.gravitino.listener.api.event.IcebergListTablePreEvent; +import org.apache.gravitino.listener.api.event.IcebergLoadTableEvent; +import org.apache.gravitino.listener.api.event.IcebergLoadTableFailureEvent; +import org.apache.gravitino.listener.api.event.IcebergLoadTablePreEvent; +import org.apache.gravitino.listener.api.event.IcebergRenameTableEvent; +import org.apache.gravitino.listener.api.event.IcebergRenameTableFailureEvent; +import org.apache.gravitino.listener.api.event.IcebergRenameTablePreEvent; +import org.apache.gravitino.listener.api.event.IcebergTableExistsEvent; +import org.apache.gravitino.listener.api.event.IcebergTableExistsFailureEvent; +import org.apache.gravitino.listener.api.event.IcebergTableExistsPreEvent; +import org.apache.gravitino.listener.api.event.IcebergUpdateTableEvent; +import org.apache.gravitino.listener.api.event.IcebergUpdateTableFailureEvent; +import org.apache.gravitino.listener.api.event.IcebergUpdateTablePreEvent; import org.apache.gravitino.utils.PrincipalUtils; import org.apache.iceberg.catalog.Namespace; import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.rest.requests.CreateTableRequest; +import org.apache.iceberg.rest.requests.RenameTableRequest; +import org.apache.iceberg.rest.requests.UpdateTableRequest; +import org.apache.iceberg.rest.responses.ListTablesResponse; import org.apache.iceberg.rest.responses.LoadTableResponse; /** @@ -67,7 +88,7 @@ public LoadTableResponse createTable( } catch (Exception e) { eventBus.dispatchEvent( new IcebergCreateTableFailureEvent( - PrincipalUtils.getCurrentUserName(), nameIdentifier, e)); + PrincipalUtils.getCurrentUserName(), nameIdentifier, createTableRequest, e)); throw e; } eventBus.dispatchEvent( @@ -78,4 +99,137 @@ public LoadTableResponse createTable( loadTableResponse)); return loadTableResponse; } + + @Override + public LoadTableResponse updateTable( + String catalogName, TableIdentifier tableIdentifier, UpdateTableRequest updateTableRequest) { + NameIdentifier gravitinoNameIdentifier = + IcebergRestUtils.getGravitinoNameIdentifier(metalakeName, catalogName, tableIdentifier); + eventBus.dispatchEvent( + new IcebergUpdateTablePreEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, updateTableRequest)); + LoadTableResponse loadTableResponse; + try { + loadTableResponse = + icebergTableOperationDispatcher.updateTable( + catalogName, tableIdentifier, updateTableRequest); + } catch (Exception e) { + eventBus.dispatchEvent( + new IcebergUpdateTableFailureEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, updateTableRequest, e)); + throw e; + } + eventBus.dispatchEvent( + new IcebergUpdateTableEvent( + PrincipalUtils.getCurrentUserName(), + gravitinoNameIdentifier, + updateTableRequest, + loadTableResponse)); + return loadTableResponse; + } + + @Override + public void dropTable( + String catalogName, TableIdentifier tableIdentifier, boolean purgeRequested) { + NameIdentifier gravitinoNameIdentifier = + IcebergRestUtils.getGravitinoNameIdentifier(metalakeName, catalogName, tableIdentifier); + eventBus.dispatchEvent( + new IcebergDropTablePreEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, purgeRequested)); + try { + icebergTableOperationDispatcher.dropTable(catalogName, tableIdentifier, purgeRequested); + } catch (Exception e) { + eventBus.dispatchEvent( + new IcebergDropTableFailureEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, purgeRequested, e)); + throw e; + } + eventBus.dispatchEvent( + new IcebergDropTableEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, purgeRequested)); + } + + @Override + public LoadTableResponse loadTable(String catalogName, TableIdentifier tableIdentifier) { + NameIdentifier gravitinoNameIdentifier = + IcebergRestUtils.getGravitinoNameIdentifier(metalakeName, catalogName, tableIdentifier); + eventBus.dispatchEvent( + new IcebergLoadTablePreEvent(PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier)); + LoadTableResponse loadTableResponse; + try { + loadTableResponse = icebergTableOperationDispatcher.loadTable(catalogName, tableIdentifier); + } catch (Exception e) { + eventBus.dispatchEvent( + new IcebergLoadTableFailureEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, e)); + throw e; + } + eventBus.dispatchEvent( + new IcebergLoadTableEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, loadTableResponse)); + return loadTableResponse; + } + + @Override + public ListTablesResponse listTable(String catalogName, Namespace namespace) { + NameIdentifier gravitinoNameIdentifier = + IcebergRestUtils.getGravitinoNameIdentifier(metalakeName, catalogName, namespace); + eventBus.dispatchEvent( + new IcebergListTablePreEvent(PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier)); + ListTablesResponse listTablesResponse; + try { + listTablesResponse = icebergTableOperationDispatcher.listTable(catalogName, namespace); + } catch (Exception e) { + eventBus.dispatchEvent( + new IcebergListTableFailureEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, e)); + throw e; + } + eventBus.dispatchEvent( + new IcebergListTableEvent(PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier)); + return listTablesResponse; + } + + @Override + public boolean tableExists(String catalogName, TableIdentifier tableIdentifier) { + NameIdentifier gravitinoNameIdentifier = + IcebergRestUtils.getGravitinoNameIdentifier(metalakeName, catalogName, tableIdentifier); + eventBus.dispatchEvent( + new IcebergTableExistsPreEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier)); + boolean isExists; + try { + isExists = icebergTableOperationDispatcher.tableExists(catalogName, tableIdentifier); + } catch (Exception e) { + eventBus.dispatchEvent( + new IcebergTableExistsFailureEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, e)); + throw e; + } + eventBus.dispatchEvent( + new IcebergTableExistsEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, isExists)); + return isExists; + } + + @Override + public void renameTable(String catalogName, RenameTableRequest renameTableRequest) { + TableIdentifier sourceTable = renameTableRequest.source(); + NameIdentifier gravitinoNameIdentifier = + IcebergRestUtils.getGravitinoNameIdentifier(metalakeName, catalogName, sourceTable); + eventBus.dispatchEvent( + new IcebergRenameTablePreEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, renameTableRequest)); + try { + icebergTableOperationDispatcher.renameTable(catalogName, renameTableRequest); + } catch (Exception e) { + eventBus.dispatchEvent( + new IcebergRenameTableFailureEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, renameTableRequest, e)); + throw e; + } + eventBus.dispatchEvent( + new IcebergRenameTableEvent( + PrincipalUtils.getCurrentUserName(), gravitinoNameIdentifier, renameTableRequest)); + } } diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationDispatcher.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationDispatcher.java index 948e4866217..68a0db16faf 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationDispatcher.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationDispatcher.java @@ -20,7 +20,11 @@ package org.apache.gravitino.iceberg.service.dispatcher; import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.rest.requests.CreateTableRequest; +import org.apache.iceberg.rest.requests.RenameTableRequest; +import org.apache.iceberg.rest.requests.UpdateTableRequest; +import org.apache.iceberg.rest.responses.ListTablesResponse; import org.apache.iceberg.rest.responses.LoadTableResponse; /** @@ -28,6 +32,7 @@ * tables. */ public interface IcebergTableOperationDispatcher { + /** * Creates a new Iceberg table. * @@ -38,4 +43,59 @@ public interface IcebergTableOperationDispatcher { */ LoadTableResponse createTable( String catalogName, Namespace namespace, CreateTableRequest createTableRequest); + + /** + * Updates an Iceberg table. + * + * @param catalogName The catalog name when updating the table. + * @param tableIdentifier The Iceberg table identifier. + * @param updateTableRequest The request object containing the details for updating the table. + * @return A {@link LoadTableResponse} object containing the result of the operation. + */ + LoadTableResponse updateTable( + String catalogName, TableIdentifier tableIdentifier, UpdateTableRequest updateTableRequest); + + /** + * Drops an Iceberg table. + * + * @param catalogName The catalog name when dropping the table. + * @param tableIdentifier The Iceberg table identifier. + * @param purgeRequested Whether to purge the table. + */ + void dropTable(String catalogName, TableIdentifier tableIdentifier, boolean purgeRequested); + + /** + * Loads an Iceberg table. + * + * @param catalogName The catalog name when dropping the table. + * @param tableIdentifier The Iceberg table identifier. + * @return A {@link LoadTableResponse} object containing the result of the operation. + */ + LoadTableResponse loadTable(String catalogName, TableIdentifier tableIdentifier); + + /** + * Lists Iceberg tables. + * + * @param catalogName The catalog name when dropping the table. + * @param namespace The Iceberg namespace. + * @return A {@link ListTablesResponse} object containing the list of table identifiers. + */ + ListTablesResponse listTable(String catalogName, Namespace namespace); + + /** + * Check whether an Iceberg table exists. + * + * @param catalogName The catalog name when dropping the table. + * @param tableIdentifier The Iceberg table identifier. + * @return Whether table exists. + */ + boolean tableExists(String catalogName, TableIdentifier tableIdentifier); + + /** + * Rename an Iceberg table. + * + * @param catalogName The catalog name when dropping the table. + * @param renameTableRequest Rename table request information. + */ + void renameTable(String catalogName, RenameTableRequest renameTableRequest); } diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java index 9a51d7b7a00..8016b5def24 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java @@ -21,7 +21,11 @@ import org.apache.gravitino.iceberg.service.IcebergCatalogWrapperManager; import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.rest.requests.CreateTableRequest; +import org.apache.iceberg.rest.requests.RenameTableRequest; +import org.apache.iceberg.rest.requests.UpdateTableRequest; +import org.apache.iceberg.rest.responses.ListTablesResponse; import org.apache.iceberg.rest.responses.LoadTableResponse; public class IcebergTableOperationExecutor implements IcebergTableOperationDispatcher { @@ -39,4 +43,42 @@ public LoadTableResponse createTable( .getCatalogWrapper(catalogName) .createTable(namespace, createTableRequest); } + + @Override + public LoadTableResponse updateTable( + String catalogName, TableIdentifier tableIdentifier, UpdateTableRequest updateTableRequest) { + return icebergCatalogWrapperManager + .getCatalogWrapper(catalogName) + .updateTable(tableIdentifier, updateTableRequest); + } + + @Override + public void dropTable( + String catalogName, TableIdentifier tableIdentifier, boolean purgeRequested) { + if (purgeRequested) { + icebergCatalogWrapperManager.getCatalogWrapper(catalogName).purgeTable(tableIdentifier); + } else { + icebergCatalogWrapperManager.getCatalogWrapper(catalogName).dropTable(tableIdentifier); + } + } + + @Override + public LoadTableResponse loadTable(String catalogName, TableIdentifier tableIdentifier) { + return icebergCatalogWrapperManager.getCatalogWrapper(catalogName).loadTable(tableIdentifier); + } + + @Override + public ListTablesResponse listTable(String catalogName, Namespace namespace) { + return icebergCatalogWrapperManager.getCatalogWrapper(catalogName).listTable(namespace); + } + + @Override + public boolean tableExists(String catalogName, TableIdentifier tableIdentifier) { + return icebergCatalogWrapperManager.getCatalogWrapper(catalogName).tableExists(tableIdentifier); + } + + @Override + public void renameTable(String catalogName, RenameTableRequest renameTableRequest) { + icebergCatalogWrapperManager.getCatalogWrapper(catalogName).renameTable(renameTableRequest); + } } diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableOperations.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableOperations.java index cebb748845e..46546bbdcaf 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableOperations.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableOperations.java @@ -60,6 +60,7 @@ import org.apache.iceberg.rest.requests.CreateTableRequest; import org.apache.iceberg.rest.requests.ReportMetricsRequest; import org.apache.iceberg.rest.requests.UpdateTableRequest; +import org.apache.iceberg.rest.responses.ListTablesResponse; import org.apache.iceberg.rest.responses.LoadTableResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,8 +102,12 @@ public IcebergTableOperations( @ResponseMetered(name = "list-table", absolute = true) public Response listTable( @PathParam("prefix") String prefix, @PathParam("namespace") String namespace) { - return IcebergRestUtils.ok( - icebergCatalogWrapperManager.getOps(prefix).listTable(RESTUtil.decodeNamespace(namespace))); + String catalogName = IcebergRestUtils.getCatalogName(prefix); + Namespace icebergNS = RESTUtil.decodeNamespace(namespace); + LOG.info("List Iceberg tables, catalog: {}, namespace: {}", catalogName, icebergNS); + ListTablesResponse listTablesResponse = + tableOperationDispatcher.listTable(catalogName, icebergNS); + return IcebergRestUtils.ok(listTablesResponse); } @POST @@ -128,7 +133,7 @@ public Response createTable( LoadTableResponse loadTableResponse = tableOperationDispatcher.createTable(catalogName, icebergNS, createTableRequest); if (isCredentialVending) { - return IcebergRestUtils.ok(injectCredentialConfig(prefix, loadTableResponse)); + return IcebergRestUtils.ok(injectCredentialConfig(catalogName, loadTableResponse)); } else { return IcebergRestUtils.ok(loadTableResponse); } @@ -144,19 +149,20 @@ public Response updateTable( @PathParam("namespace") String namespace, @PathParam("table") String table, UpdateTableRequest updateTableRequest) { + String catalogName = IcebergRestUtils.getCatalogName(prefix); + Namespace icebergNS = RESTUtil.decodeNamespace(namespace); if (LOG.isInfoEnabled()) { LOG.info( - "Update Iceberg table, namespace: {}, table: {}, updateTableRequest: {}", - namespace, + "Update Iceberg table, catalog: {}, namespace: {}, table: {}, updateTableRequest: {}", + catalogName, + icebergNS, table, SerializeUpdateTableRequest(updateTableRequest)); } - TableIdentifier tableIdentifier = - TableIdentifier.of(RESTUtil.decodeNamespace(namespace), table); - return IcebergRestUtils.ok( - icebergCatalogWrapperManager - .getOps(prefix) - .updateTable(tableIdentifier, updateTableRequest)); + TableIdentifier tableIdentifier = TableIdentifier.of(icebergNS, table); + LoadTableResponse loadTableResponse = + tableOperationDispatcher.updateTable(catalogName, tableIdentifier, updateTableRequest); + return IcebergRestUtils.ok(loadTableResponse); } @DELETE @@ -169,18 +175,16 @@ public Response dropTable( @PathParam("namespace") String namespace, @PathParam("table") String table, @DefaultValue("false") @QueryParam("purgeRequested") boolean purgeRequested) { + String catalogName = IcebergRestUtils.getCatalogName(prefix); + Namespace icebergNS = RESTUtil.decodeNamespace(namespace); LOG.info( - "Drop Iceberg table, namespace: {}, table: {}, purgeRequested: {}", - namespace, + "Drop Iceberg table, catalog: {}, namespace: {}, table: {}, purgeRequested: {}", + catalogName, + icebergNS, table, purgeRequested); - TableIdentifier tableIdentifier = - TableIdentifier.of(RESTUtil.decodeNamespace(namespace), table); - if (purgeRequested) { - icebergCatalogWrapperManager.getOps(prefix).purgeTable(tableIdentifier); - } else { - icebergCatalogWrapperManager.getOps(prefix).dropTable(tableIdentifier); - } + TableIdentifier tableIdentifier = TableIdentifier.of(namespace, table); + tableOperationDispatcher.dropTable(catalogName, tableIdentifier, purgeRequested); return IcebergRestUtils.noContent(); } @@ -195,21 +199,23 @@ public Response loadTable( @PathParam("table") String table, @DefaultValue("all") @QueryParam("snapshots") String snapshots, @HeaderParam(X_ICEBERG_ACCESS_DELEGATION) String accessDelegation) { + String catalogName = IcebergRestUtils.getCatalogName(prefix); + Namespace icebergNS = RESTUtil.decodeNamespace(namespace); boolean isCredentialVending = isCredentialVending(accessDelegation); LOG.info( - "Load iceberg table, namespace: {}, table: {}, access delegation: {}, " + "Load Iceberg table, catalog: {}, namespace: {}, table: {}, access delegation: {}, " + "credential vending: {}", - namespace, + catalogName, + icebergNS, table, accessDelegation, isCredentialVending); // todo support snapshots - TableIdentifier tableIdentifier = - TableIdentifier.of(RESTUtil.decodeNamespace(namespace), table); + TableIdentifier tableIdentifier = TableIdentifier.of(icebergNS, table); LoadTableResponse loadTableResponse = - icebergCatalogWrapperManager.getOps(prefix).loadTable(tableIdentifier); + tableOperationDispatcher.loadTable(catalogName, tableIdentifier); if (isCredentialVending) { - return IcebergRestUtils.ok(injectCredentialConfig(prefix, loadTableResponse)); + return IcebergRestUtils.ok(injectCredentialConfig(catalogName, loadTableResponse)); } else { return IcebergRestUtils.ok(loadTableResponse); } @@ -224,9 +230,16 @@ public Response tableExists( @PathParam("prefix") String prefix, @PathParam("namespace") String namespace, @PathParam("table") String table) { - TableIdentifier tableIdentifier = - TableIdentifier.of(RESTUtil.decodeNamespace(namespace), table); - if (icebergCatalogWrapperManager.getOps(prefix).tableExists(tableIdentifier)) { + String catalogName = IcebergRestUtils.getCatalogName(prefix); + Namespace icebergNS = RESTUtil.decodeNamespace(namespace); + LOG.info( + "Check Iceberg table exists, catalog: {}, namespace: {}, table: {}", + catalogName, + icebergNS, + table); + TableIdentifier tableIdentifier = TableIdentifier.of(icebergNS, table); + boolean exists = tableOperationDispatcher.tableExists(catalogName, tableIdentifier); + if (exists) { return IcebergRestUtils.okWithoutContent(); } else { return IcebergRestUtils.notExists(); @@ -257,9 +270,9 @@ private String SerializeUpdateTableRequest(UpdateTableRequest updateTableRequest } private LoadTableResponse injectCredentialConfig( - String prefix, LoadTableResponse loadTableResponse) { + String catalogName, LoadTableResponse loadTableResponse) { CredentialProvider credentialProvider = - icebergCatalogWrapperManager.getCredentialProvider(prefix); + icebergCatalogWrapperManager.getCredentialProvider(catalogName); if (credentialProvider == null) { throw new NotSupportedException( "Doesn't support credential vending, please add " @@ -296,7 +309,7 @@ private boolean isCredentialVending(String accessDelegation) { X_ICEBERG_ACCESS_DELEGATION + ": " + accessDelegation - + " is illegal, Iceberg REST spec supports:[vended-credentials,remote-signing], " + + " is illegal, Iceberg REST spec supports: [vended-credentials,remote-signing], " + "Gravitino Iceberg REST server supports: vended-credentials"); } } diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableRenameOperations.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableRenameOperations.java index 553508c01ff..4d7ecef25cc 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableRenameOperations.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergTableRenameOperations.java @@ -30,25 +30,28 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.apache.gravitino.iceberg.service.IcebergCatalogWrapperManager; import org.apache.gravitino.iceberg.service.IcebergRestUtils; +import org.apache.gravitino.iceberg.service.dispatcher.IcebergTableOperationDispatcher; import org.apache.gravitino.metrics.MetricNames; import org.apache.iceberg.rest.requests.RenameTableRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Path("/v1/{prefix:([^/]*/)?}tables/rename") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public class IcebergTableRenameOperations { + private static final Logger LOG = LoggerFactory.getLogger(IcebergTableOperations.class); @SuppressWarnings("UnusedVariable") @Context private HttpServletRequest httpRequest; - private IcebergCatalogWrapperManager icebergCatalogWrapperManager; + private IcebergTableOperationDispatcher tableOperationDispatcher; @Inject - public IcebergTableRenameOperations(IcebergCatalogWrapperManager icebergCatalogWrapperManager) { - this.icebergCatalogWrapperManager = icebergCatalogWrapperManager; + public IcebergTableRenameOperations(IcebergTableOperationDispatcher tableOperationDispatcher) { + this.tableOperationDispatcher = tableOperationDispatcher; } @POST @@ -57,7 +60,13 @@ public IcebergTableRenameOperations(IcebergCatalogWrapperManager icebergCatalogW @ResponseMetered(name = "rename-table", absolute = true) public Response renameTable( @PathParam("prefix") String prefix, RenameTableRequest renameTableRequest) { - icebergCatalogWrapperManager.getOps(prefix).renameTable(renameTableRequest); + String catalogName = IcebergRestUtils.getCatalogName(prefix); + LOG.info( + "Rename Iceberg tables, catalog: {}, source: {}, destination: {}.", + catalogName, + renameTableRequest.source(), + renameTableRequest.destination()); + tableOperationDispatcher.renameTable(catalogName, renameTableRequest); return IcebergRestUtils.okWithoutContent(); } } diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableFailureEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableFailureEvent.java index 24f74da4fdf..bc67ef2d526 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableFailureEvent.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableFailureEvent.java @@ -21,11 +21,25 @@ import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.iceberg.service.IcebergRestUtils; +import org.apache.iceberg.rest.requests.CreateTableRequest; /** Represent a failure event when creating Iceberg table failed. */ @DeveloperApi public class IcebergCreateTableFailureEvent extends IcebergTableFailureEvent { - public IcebergCreateTableFailureEvent(String user, NameIdentifier nameIdentifier, Exception e) { + private CreateTableRequest createTableRequest; + + public IcebergCreateTableFailureEvent( + String user, + NameIdentifier nameIdentifier, + CreateTableRequest createTableRequest, + Exception e) { super(user, nameIdentifier, e); + this.createTableRequest = + IcebergRestUtils.cloneIcebergRESTObject(createTableRequest, CreateTableRequest.class); + } + + public CreateTableRequest createTableRequest() { + return createTableRequest; } } diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTableEvent.java new file mode 100644 index 00000000000..3b5c447bdc1 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTableEvent.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent an event after dropping Iceberg table successfully. */ +@DeveloperApi +public class IcebergDropTableEvent extends IcebergTableEvent { + private boolean purgeRequested; + + public IcebergDropTableEvent( + String user, NameIdentifier resourceIdentifier, boolean purgeRequested) { + super(user, resourceIdentifier); + this.purgeRequested = purgeRequested; + } + + public boolean purgeRequested() { + return purgeRequested; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTableFailureEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTableFailureEvent.java new file mode 100644 index 00000000000..e57ed35c5c4 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTableFailureEvent.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a failure event when dropping Iceberg table failed. */ +@DeveloperApi +public class IcebergDropTableFailureEvent extends IcebergTableFailureEvent { + private boolean purgeRequested; + + public IcebergDropTableFailureEvent( + String user, NameIdentifier nameIdentifier, Boolean purgeRequested, Exception e) { + super(user, nameIdentifier, e); + this.purgeRequested = purgeRequested; + } + + public boolean purgeRequested() { + return purgeRequested; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTablePreEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTablePreEvent.java new file mode 100644 index 00000000000..5e90a88ba05 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergDropTablePreEvent.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a pre event before dropping Iceberg table. */ +@DeveloperApi +public class IcebergDropTablePreEvent extends IcebergTablePreEvent { + private boolean purgeRequested; + + public IcebergDropTablePreEvent( + String user, NameIdentifier tableIdentifier, boolean purgeRequested) { + super(user, tableIdentifier); + this.purgeRequested = purgeRequested; + } + + public boolean purgeRequested() { + return purgeRequested; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableEvent.java new file mode 100644 index 00000000000..22589d2cd43 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableEvent.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** + * Represent an event after listing Iceberg table successfully. + * + *

To optimize memory usage and avoid the potential overhead associated with storing a large + * number of tables directly within the ListTableEvent, the actual tables listed are not maintained + * in this event. + */ +@DeveloperApi +public class IcebergListTableEvent extends IcebergTableEvent { + public IcebergListTableEvent(String user, NameIdentifier resourceIdentifier) { + super(user, resourceIdentifier); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableFailureEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableFailureEvent.java new file mode 100644 index 00000000000..3cbda0f4461 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableFailureEvent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a failure event when listing Iceberg table failed. */ +@DeveloperApi +public class IcebergListTableFailureEvent extends IcebergTableFailureEvent { + public IcebergListTableFailureEvent(String user, NameIdentifier nameIdentifier, Exception e) { + super(user, nameIdentifier, e); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTablePreEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTablePreEvent.java new file mode 100644 index 00000000000..7da059c7e1f --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTablePreEvent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a pre event before listing Iceberg table. */ +@DeveloperApi +public class IcebergListTablePreEvent extends IcebergTablePreEvent { + public IcebergListTablePreEvent(String user, NameIdentifier tableIdentifier) { + super(user, tableIdentifier); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTableEvent.java new file mode 100644 index 00000000000..7007fd7061b --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTableEvent.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.iceberg.service.IcebergRestUtils; +import org.apache.iceberg.rest.responses.LoadTableResponse; + +/** Represent an event after loading Iceberg table successfully. */ +@DeveloperApi +public class IcebergLoadTableEvent extends IcebergTableEvent { + private LoadTableResponse loadTableResponse; + + public IcebergLoadTableEvent( + String user, NameIdentifier resourceIdentifier, LoadTableResponse loadTableResponse) { + super(user, resourceIdentifier); + this.loadTableResponse = + IcebergRestUtils.cloneIcebergRESTObject(loadTableResponse, LoadTableResponse.class); + } + + public LoadTableResponse loadTableResponse() { + return loadTableResponse; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTableFailureEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTableFailureEvent.java new file mode 100644 index 00000000000..03402583bee --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTableFailureEvent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a failure event when loading Iceberg table failed. */ +@DeveloperApi +public class IcebergLoadTableFailureEvent extends IcebergTableFailureEvent { + public IcebergLoadTableFailureEvent(String user, NameIdentifier nameIdentifier, Exception e) { + super(user, nameIdentifier, e); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTablePreEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTablePreEvent.java new file mode 100644 index 00000000000..9485b1b93fe --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergLoadTablePreEvent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a pre event before loading Iceberg table. */ +@DeveloperApi +public class IcebergLoadTablePreEvent extends IcebergTablePreEvent { + public IcebergLoadTablePreEvent(String user, NameIdentifier tableIdentifier) { + super(user, tableIdentifier); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTableEvent.java new file mode 100644 index 00000000000..70b7ef4e960 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTableEvent.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.iceberg.service.IcebergRestUtils; +import org.apache.iceberg.rest.requests.RenameTableRequest; + +/** Represent an event after rename Iceberg table successfully. */ +@DeveloperApi +public class IcebergRenameTableEvent extends IcebergTableEvent { + private RenameTableRequest renameTableRequest; + + public IcebergRenameTableEvent( + String user, NameIdentifier resourceIdentifier, RenameTableRequest renameTableRequest) { + super(user, resourceIdentifier); + this.renameTableRequest = + IcebergRestUtils.cloneIcebergRESTObject(renameTableRequest, RenameTableRequest.class); + } + + public RenameTableRequest renameTableRequest() { + return renameTableRequest; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTableFailureEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTableFailureEvent.java new file mode 100644 index 00000000000..936e56d10bc --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTableFailureEvent.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.iceberg.rest.requests.RenameTableRequest; + +/** Represent an event when rename Iceberg table failed. */ +@DeveloperApi +public class IcebergRenameTableFailureEvent extends IcebergTableFailureEvent { + private RenameTableRequest renameTableRequest; + + public IcebergRenameTableFailureEvent( + String user, + NameIdentifier resourceIdentifier, + RenameTableRequest renameTableRequest, + Exception e) { + super(user, resourceIdentifier, e); + this.renameTableRequest = renameTableRequest; + } + + public RenameTableRequest renameTableRequest() { + return renameTableRequest; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTablePreEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTablePreEvent.java new file mode 100644 index 00000000000..8b654ab03e1 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergRenameTablePreEvent.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.iceberg.rest.requests.RenameTableRequest; + +/** Represent an pre event before rename an Iceberg table. */ +@DeveloperApi +public class IcebergRenameTablePreEvent extends IcebergTablePreEvent { + private RenameTableRequest renameTableRequest; + + public IcebergRenameTablePreEvent( + String user, NameIdentifier resourceIdentifier, RenameTableRequest renameTableRequest) { + super(user, resourceIdentifier); + this.renameTableRequest = renameTableRequest; + } + + public RenameTableRequest renameTableRequest() { + return renameTableRequest; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsEvent.java new file mode 100644 index 00000000000..512deac0696 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsEvent.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent an event after check Iceberg table exists successfully. */ +@DeveloperApi +public class IcebergTableExistsEvent extends IcebergTableEvent { + private boolean isExists; + + public IcebergTableExistsEvent(String user, NameIdentifier resourceIdentifier, boolean isExists) { + super(user, resourceIdentifier); + this.isExists = isExists; + } + + public boolean isExists() { + return isExists; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsFailureEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsFailureEvent.java new file mode 100644 index 00000000000..04cb0d7e5a0 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsFailureEvent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a failure event when check Iceberg table exist failed. */ +@DeveloperApi +public class IcebergTableExistsFailureEvent extends IcebergTableFailureEvent { + public IcebergTableExistsFailureEvent(String user, NameIdentifier nameIdentifier, Exception e) { + super(user, nameIdentifier, e); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsPreEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsPreEvent.java new file mode 100644 index 00000000000..bdd66677692 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergTableExistsPreEvent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; + +/** Represent a pre event before checking Iceberg table exists. */ +@DeveloperApi +public class IcebergTableExistsPreEvent extends IcebergTablePreEvent { + public IcebergTableExistsPreEvent(String user, NameIdentifier tableIdentifier) { + super(user, tableIdentifier); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableEvent.java new file mode 100644 index 00000000000..82ea7732fea --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableEvent.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.iceberg.service.IcebergRestUtils; +import org.apache.iceberg.rest.requests.UpdateTableRequest; +import org.apache.iceberg.rest.responses.LoadTableResponse; + +/** Represent an event after updating Iceberg table successfully. */ +@DeveloperApi +public class IcebergUpdateTableEvent extends IcebergTableEvent { + + private UpdateTableRequest updateTableRequest; + private LoadTableResponse loadTableResponse; + + public IcebergUpdateTableEvent( + String user, + NameIdentifier resourceIdentifier, + UpdateTableRequest updateTableRequest, + LoadTableResponse loadTableResponse) { + super(user, resourceIdentifier); + this.updateTableRequest = + IcebergRestUtils.cloneIcebergRESTObject(updateTableRequest, UpdateTableRequest.class); + this.loadTableResponse = + IcebergRestUtils.cloneIcebergRESTObject(loadTableResponse, LoadTableResponse.class); + } + + public UpdateTableRequest createTableRequest() { + return updateTableRequest; + } + + public LoadTableResponse loadTableResponse() { + return loadTableResponse; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableFailureEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableFailureEvent.java new file mode 100644 index 00000000000..7f5b478ce1f --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableFailureEvent.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.iceberg.service.IcebergRestUtils; +import org.apache.iceberg.rest.requests.UpdateTableRequest; + +/** Represent a failure event when updating Iceberg table failed. */ +@DeveloperApi +public class IcebergUpdateTableFailureEvent extends IcebergTableFailureEvent { + private UpdateTableRequest updateTableRequest; + + public IcebergUpdateTableFailureEvent( + String user, + NameIdentifier nameIdentifier, + UpdateTableRequest updateTableRequest, + Exception e) { + super(user, nameIdentifier, e); + this.updateTableRequest = + IcebergRestUtils.cloneIcebergRESTObject(updateTableRequest, UpdateTableRequest.class); + } + + public UpdateTableRequest updateTableRequest() { + return updateTableRequest; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTablePreEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTablePreEvent.java new file mode 100644 index 00000000000..4681efbdb8c --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTablePreEvent.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.gravitino.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.iceberg.rest.requests.UpdateTableRequest; + +/** Represent a pre event before updating Iceberg table. */ +@DeveloperApi +public class IcebergUpdateTablePreEvent extends IcebergTablePreEvent { + private UpdateTableRequest updateTableRequest; + + public IcebergUpdateTablePreEvent( + String user, NameIdentifier resourceIdentifier, UpdateTableRequest updateTableRequest) { + super(user, resourceIdentifier); + this.updateTableRequest = updateTableRequest; + } + + public UpdateTableRequest updateTableRequest() { + return updateTableRequest; + } +}