From 7e4f840b28e5d9cac0f92b3eec27d69f42087784 Mon Sep 17 00:00:00 2001 From: Yufei Gu Date: Mon, 3 Mar 2025 10:24:50 -0800 Subject: [PATCH] Move inner classes to standalone classes (#1095) --- .../core/auth/PolarisGrantManager.java | 2 +- .../core/auth/PolarisSecretsManager.java | 2 +- .../polaris/core/entity/PolarisEntity.java | 4 +- .../LocalPolarisMetaStoreManagerFactory.java | 8 +- .../persistence/MetaStoreManagerFactory.java | 1 + .../persistence/PolarisMetaStoreManager.java | 529 +----------------- .../TransactionWorkspaceMetaStoreManager.java | 13 +- .../core/persistence/cache/EntityCache.java | 2 +- .../{ => dao/entity}/BaseResult.java | 2 +- .../dao/entity/ChangeTrackingResult.java | 68 +++ .../dao/entity/CreateCatalogResult.java | 79 +++ .../dao/entity/CreatePrincipalResult.java | 79 +++ .../dao/entity/DropEntityResult.java | 82 +++ .../dao/entity/EntitiesResult.java | 67 +++ .../persistence/dao/entity/EntityResult.java | 102 ++++ .../dao/entity/EntityWithPath.java | 51 ++ .../dao/entity/GenerateEntityIdResult.java | 66 +++ .../dao/entity/ListEntitiesResult.java | 67 +++ .../dao/entity/ResolvedEntityResult.java | 97 ++++ .../core/persistence/resolver/Resolver.java | 4 +- .../PolarisMetaStoreManagerImpl.java | 11 + .../core/storage/PolarisCredentialVendor.java | 2 +- .../core/persistence/ResolverTest.java | 9 +- .../cache/StorageCredentialCacheTest.java | 2 +- .../PolarisTestMetaStoreManager.java | 31 +- .../quarkus/admin/PolarisAuthzTestBase.java | 5 +- .../quarkus/auth/JWTRSAKeyPairTest.java | 3 +- .../auth/JWTSymmetricKeyGeneratorTest.java | 3 +- .../catalog/BasePolarisCatalogTest.java | 2 +- ...PolarisCatalogHandlerWrapperAuthzTest.java | 4 +- .../test/PolarisIntegrationTestFixture.java | 6 +- .../service/admin/PolarisAdminService.java | 15 +- .../auth/DefaultActiveRolesProvider.java | 5 +- .../polaris/service/auth/JWTBroker.java | 3 +- .../service/auth/TestOAuth2ApiService.java | 5 +- .../polaris/service/auth/TokenBroker.java | 3 +- .../service/catalog/BasePolarisCatalog.java | 20 +- .../catalog/PolarisCatalogHandlerWrapper.java | 7 +- .../auth/BasePolarisAuthenticatorTest.java | 6 +- .../apache/polaris/service/TestServices.java | 3 +- 40 files changed, 884 insertions(+), 586 deletions(-) rename polaris-core/src/main/java/org/apache/polaris/core/persistence/{ => dao/entity}/BaseResult.java (98%) create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ChangeTrackingResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreateCatalogResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreatePrincipalResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/DropEntityResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntitiesResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityWithPath.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/GenerateEntityIdResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ListEntitiesResult.java create mode 100644 polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ResolvedEntityResult.java diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java index 35291a2a2..60c2ba925 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java @@ -31,7 +31,7 @@ import org.apache.polaris.core.entity.PolarisEntityCore; import org.apache.polaris.core.entity.PolarisGrantRecord; import org.apache.polaris.core.entity.PolarisPrivilege; -import org.apache.polaris.core.persistence.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; /** Manage grants for Polaris entities. */ public interface PolarisGrantManager { diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java index d63368fd9..fa5c4cd34 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java @@ -24,7 +24,7 @@ import jakarta.annotation.Nullable; import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; -import org.apache.polaris.core.persistence.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; /** Manages secrets for Polaris principals. */ public interface PolarisSecretsManager { diff --git a/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntity.java b/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntity.java index c68d1c974..08ac29b35 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntity.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntity.java @@ -28,7 +28,7 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; /** * For legacy reasons, this class is only a thin facade over PolarisBaseEntity's members/methods. No @@ -146,7 +146,7 @@ public static PolarisEntity of(PolarisBaseEntity sourceEntity) { return null; } - public static PolarisEntity of(PolarisMetaStoreManager.EntityResult result) { + public static PolarisEntity of(EntityResult result) { if (result.isSuccess()) { return new PolarisEntity(result.getEntity()); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java index c958dd5d2..ff2eaaf13 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java @@ -36,6 +36,8 @@ import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; import org.apache.polaris.core.persistence.cache.EntityCache; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.core.persistence.transactional.PolarisMetaStoreManagerImpl; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; import org.apache.polaris.core.storage.cache.StorageCredentialCache; @@ -198,7 +200,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm CallContext.setCurrentContext(CallContext.of(realmContext, polarisContext)); } - PolarisMetaStoreManager.EntityResult preliminaryRootPrincipalLookup = + EntityResult preliminaryRootPrincipalLookup = metaStoreManager.readEntityByName( polarisContext, null, @@ -215,7 +217,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm metaStoreManager.bootstrapPolarisService(polarisContext); - PolarisMetaStoreManager.EntityResult rootPrincipalLookup = + EntityResult rootPrincipalLookup = metaStoreManager.readEntityByName( polarisContext, null, @@ -256,7 +258,7 @@ private void checkPolarisServiceBootstrappedForRealm( CallContext.setCurrentContext(CallContext.of(realmContext, polarisContext)); } - PolarisMetaStoreManager.EntityResult rootPrincipalLookup = + EntityResult rootPrincipalLookup = metaStoreManager.readEntityByName( polarisContext, null, diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java index e35b62c40..ee5d99bb4 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java @@ -24,6 +24,7 @@ import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; import org.apache.polaris.core.persistence.cache.EntityCache; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; import org.apache.polaris.core.storage.cache.StorageCredentialCache; diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java index 8a364ef65..0825c8f49 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java @@ -18,9 +18,6 @@ */ package org.apache.polaris.core.persistence; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.util.List; @@ -28,16 +25,23 @@ import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.auth.PolarisGrantManager; import org.apache.polaris.core.auth.PolarisSecretsManager; -import org.apache.polaris.core.entity.EntityNameLookupRecord; import org.apache.polaris.core.entity.PolarisBaseEntity; -import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntityCore; import org.apache.polaris.core.entity.PolarisEntityId; import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; -import org.apache.polaris.core.entity.PolarisGrantRecord; -import org.apache.polaris.core.entity.PolarisPrincipalSecrets; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.ChangeTrackingResult; +import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult; +import org.apache.polaris.core.persistence.dao.entity.CreatePrincipalResult; +import org.apache.polaris.core.persistence.dao.entity.DropEntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntitiesResult; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntityWithPath; +import org.apache.polaris.core.persistence.dao.entity.GenerateEntityIdResult; +import org.apache.polaris.core.persistence.dao.entity.ListEntitiesResult; +import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult; import org.apache.polaris.core.storage.PolarisCredentialVendor; /** @@ -71,82 +75,6 @@ public interface PolarisMetaStoreManager @Nonnull BaseResult purge(@Nonnull PolarisCallContext callCtx); - /** the return for an entity lookup call */ - class EntityResult extends BaseResult { - - // null if not success - private final PolarisBaseEntity entity; - - /** - * Constructor for an error - * - * @param errorCode error code, cannot be SUCCESS - * @param extraInformation extra information if error. Implementation specific - */ - public EntityResult( - @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { - super(errorCode, extraInformation); - this.entity = null; - } - - /** - * Constructor for success - * - * @param entity the entity being looked-up - */ - public EntityResult(@Nonnull PolarisBaseEntity entity) { - super(ReturnStatus.SUCCESS); - this.entity = entity; - } - - /** - * Constructor for an object already exists error where the subtype of the existing entity is - * returned - * - * @param errorStatus error status, cannot be SUCCESS - * @param subTypeCode existing entity subtype code - */ - public EntityResult(@Nonnull BaseResult.ReturnStatus errorStatus, int subTypeCode) { - super(errorStatus, Integer.toString(subTypeCode)); - this.entity = null; - } - - /** - * For object already exist error, we use the extra information to serialize the subtype code of - * the existing object. Return the subtype - * - * @return object subtype or NULL (should not happen) if subtype code is missing or cannot be - * deserialized - */ - @Nullable - public PolarisEntitySubType getAlreadyExistsEntitySubType() { - if (this.getExtraInformation() == null) { - return null; - } else { - int subTypeCode; - try { - subTypeCode = Integer.parseInt(this.getExtraInformation()); - } catch (NumberFormatException e) { - return null; - } - return PolarisEntitySubType.fromCode(subTypeCode); - } - } - - @JsonCreator - private EntityResult( - @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, - @JsonProperty("extraInformation") @Nullable String extraInformation, - @JsonProperty("entity") @Nullable PolarisBaseEntity entity) { - super(returnStatus, extraInformation); - this.entity = entity; - } - - public PolarisBaseEntity getEntity() { - return entity; - } - } - /** * Resolve an entity by name. Can be a top-level entity like a catalog or an entity inside a * catalog like a namespace, a role, a table like entity, or a principal. If the entity is inside @@ -164,55 +92,13 @@ public PolarisBaseEntity getEntity() { * returned if the specified catalog path cannot be resolved. */ @Nonnull - PolarisMetaStoreManager.EntityResult readEntityByName( + EntityResult readEntityByName( @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull String name); - /** the return the result for a list entities call */ - class ListEntitiesResult extends BaseResult { - - // null if not success. Else the list of entities being returned - private final List entities; - - /** - * Constructor for an error - * - * @param errorCode error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public ListEntitiesResult( - @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { - super(errorCode, extraInformation); - this.entities = null; - } - - /** - * Constructor for success - * - * @param entities list of entities being returned, implies success - */ - public ListEntitiesResult(@Nonnull List entities) { - super(ReturnStatus.SUCCESS); - this.entities = entities; - } - - @JsonCreator - private ListEntitiesResult( - @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, - @JsonProperty("extraInformation") String extraInformation, - @JsonProperty("entities") List entities) { - super(returnStatus, extraInformation); - this.entities = entities; - } - - public List getEntities() { - return entities; - } - } - /** * List all entities of the specified type under the specified catalogPath. If the catalogPath is * null, listed entities will be top-level entities like catalogs. @@ -232,48 +118,6 @@ ListEntitiesResult listEntities( @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType); - /** the return for a generate new entity id */ - class GenerateEntityIdResult extends BaseResult { - - // null if not success - private final Long id; - - /** - * Constructor for an error - * - * @param errorCode error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public GenerateEntityIdResult( - @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { - super(errorCode, extraInformation); - this.id = null; - } - - /** - * Constructor for success - * - * @param id the new id which was generated - */ - public GenerateEntityIdResult(@Nonnull Long id) { - super(ReturnStatus.SUCCESS); - this.id = id; - } - - @JsonCreator - private GenerateEntityIdResult( - @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, - @JsonProperty("extraInformation") @Nullable String extraInformation, - @JsonProperty("id") @Nullable Long id) { - super(returnStatus, extraInformation); - this.id = id; - } - - public Long getId() { - return id; - } - } - /** * Generate a new unique id that can be used by the Polaris client when it needs to create a new * entity @@ -284,60 +128,6 @@ public Long getId() { @Nonnull GenerateEntityIdResult generateNewEntityId(@Nonnull PolarisCallContext callCtx); - /** the return the result of a create-principal method */ - class CreatePrincipalResult extends BaseResult { - // the principal which has been created. Null if error - private final PolarisBaseEntity principal; - - // principal client identifier and associated secrets. Null if error - private final PolarisPrincipalSecrets principalSecrets; - - /** - * Constructor for an error - * - * @param errorCode error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public CreatePrincipalResult( - @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { - super(errorCode, extraInformation); - this.principal = null; - this.principalSecrets = null; - } - - /** - * Constructor for success - * - * @param principal the principal - * @param principalSecrets and associated secret information - */ - public CreatePrincipalResult( - @Nonnull PolarisBaseEntity principal, @Nonnull PolarisPrincipalSecrets principalSecrets) { - super(ReturnStatus.SUCCESS); - this.principal = principal; - this.principalSecrets = principalSecrets; - } - - @JsonCreator - private CreatePrincipalResult( - @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, - @JsonProperty("extraInformation") @Nullable String extraInformation, - @JsonProperty("principal") @Nonnull PolarisBaseEntity principal, - @JsonProperty("principalSecrets") @Nonnull PolarisPrincipalSecrets principalSecrets) { - super(returnStatus, extraInformation); - this.principal = principal; - this.principalSecrets = principalSecrets; - } - - public PolarisBaseEntity getPrincipal() { - return principal; - } - - public PolarisPrincipalSecrets getPrincipalSecrets() { - return principalSecrets; - } - } - /** * Create a new principal. This not only creates the new principal entity but also generates a * client_id/secret pair for this new principal. @@ -351,61 +141,6 @@ public PolarisPrincipalSecrets getPrincipalSecrets() { CreatePrincipalResult createPrincipal( @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity principal); - /** the return the result of a create-catalog method */ - class CreateCatalogResult extends BaseResult { - - // the catalog which has been created - private final PolarisBaseEntity catalog; - - // its associated catalog admin role - private final PolarisBaseEntity catalogAdminRole; - - /** - * Constructor for an error - * - * @param errorCode error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public CreateCatalogResult( - @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { - super(errorCode, extraInformation); - this.catalog = null; - this.catalogAdminRole = null; - } - - /** - * Constructor for success - * - * @param catalog the catalog - * @param catalogAdminRole and associated admin role - */ - public CreateCatalogResult( - @Nonnull PolarisBaseEntity catalog, @Nonnull PolarisBaseEntity catalogAdminRole) { - super(ReturnStatus.SUCCESS); - this.catalog = catalog; - this.catalogAdminRole = catalogAdminRole; - } - - @JsonCreator - private CreateCatalogResult( - @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, - @JsonProperty("extraInformation") @Nullable String extraInformation, - @JsonProperty("catalog") @Nonnull PolarisBaseEntity catalog, - @JsonProperty("catalogAdminRole") @Nonnull PolarisBaseEntity catalogAdminRole) { - super(returnStatus, extraInformation); - this.catalog = catalog; - this.catalogAdminRole = catalogAdminRole; - } - - public PolarisBaseEntity getCatalog() { - return catalog; - } - - public PolarisBaseEntity getCatalogAdminRole() { - return catalogAdminRole; - } - } - /** * Create a new catalog. This not only creates the new catalog entity but also the initial admin * role required to admin this catalog. If inline storage integration property is provided, create @@ -447,48 +182,6 @@ EntityResult createEntityIfNotExists( @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity); - /** a set of returned entities result */ - class EntitiesResult extends BaseResult { - - // null if not success. Else the list of entities being returned - private final List entities; - - /** - * Constructor for an error - * - * @param errorStatus error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public EntitiesResult( - @Nonnull BaseResult.ReturnStatus errorStatus, @Nullable String extraInformation) { - super(errorStatus, extraInformation); - this.entities = null; - } - - /** - * Constructor for success - * - * @param entities list of entities being returned, implies success - */ - public EntitiesResult(@Nonnull List entities) { - super(ReturnStatus.SUCCESS); - this.entities = entities; - } - - @JsonCreator - private EntitiesResult( - @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, - @JsonProperty("extraInformation") String extraInformation, - @JsonProperty("entities") List entities) { - super(returnStatus, extraInformation); - this.entities = entities; - } - - public List getEntities() { - return entities; - } - } - /** * Persist a batch of newly created entities under the specified catalog path if specified, else * these are top-level entities. We will re-resolve the specified path to ensure nothing has @@ -529,31 +222,6 @@ EntityResult updateEntityPropertiesIfNotChanged( @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity); - /** Class to represent an entity with its path */ - class EntityWithPath { - // path to that entity. Could be null if this entity is top-level - private final @Nonnull List catalogPath; - - // the base entity itself - private final @Nonnull PolarisBaseEntity entity; - - @JsonCreator - public EntityWithPath( - @JsonProperty("catalogPath") @Nonnull List catalogPath, - @JsonProperty("entity") @Nonnull PolarisBaseEntity entity) { - this.catalogPath = catalogPath; - this.entity = entity; - } - - public @Nonnull List getCatalogPath() { - return catalogPath; - } - - public @Nonnull PolarisBaseEntity getEntity() { - return entity; - } - } - /** * This works exactly like {@link #updateEntityPropertiesIfNotChanged(PolarisCallContext, List, * PolarisBaseEntity)} but allows to operate on multiple entities at once. Just loop through the @@ -588,64 +256,6 @@ EntityResult renameEntity( @Nullable List newCatalogPath, @Nonnull PolarisEntity renamedEntity); - // the return the result of a drop entity - class DropEntityResult extends BaseResult { - - /** If cleanup was requested and a task was successfully scheduled, */ - private final Long cleanupTaskId; - - /** - * Constructor for an error - * - * @param errorStatus error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public DropEntityResult( - @Nonnull BaseResult.ReturnStatus errorStatus, @Nullable String extraInformation) { - super(errorStatus, extraInformation); - this.cleanupTaskId = null; - } - - /** Constructor for success when no cleanup needs to be performed */ - public DropEntityResult() { - super(ReturnStatus.SUCCESS); - this.cleanupTaskId = null; - } - - /** - * Constructor for success when a cleanup task has been scheduled - * - * @param cleanupTaskId id of the task which was created to clean up the table drop - */ - public DropEntityResult(long cleanupTaskId) { - super(ReturnStatus.SUCCESS); - this.cleanupTaskId = cleanupTaskId; - } - - @JsonCreator - private DropEntityResult( - @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, - @JsonProperty("extraInformation") String extraInformation, - @JsonProperty("cleanupTaskId") Long cleanupTaskId) { - super(returnStatus, extraInformation); - this.cleanupTaskId = cleanupTaskId; - } - - public Long getCleanupTaskId() { - return cleanupTaskId; - } - - @JsonIgnore - public boolean failedBecauseNotEmpty() { - ReturnStatus status = this.getReturnStatus(); - return status == ReturnStatus.CATALOG_NOT_EMPTY || status == ReturnStatus.NAMESPACE_NOT_EMPTY; - } - - public boolean isEntityUnDroppable() { - return this.getReturnStatus() == ReturnStatus.ENTITY_UNDROPPABLE; - } - } - /** * Drop the specified entity assuming it exists * @@ -688,50 +298,6 @@ DropEntityResult dropEntityIfExists( @Nonnull EntitiesResult loadTasks(@Nonnull PolarisCallContext callCtx, String executorId, int limit); - /** Result of a loadEntitiesChangeTracking call */ - class ChangeTrackingResult extends BaseResult { - - // null if not success. Else, will be null if the grant to revoke was not found - private final List changeTrackingVersions; - - /** - * Constructor for an error - * - * @param errorCode error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public ChangeTrackingResult( - @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { - super(errorCode, extraInformation); - this.changeTrackingVersions = null; - } - - /** - * Constructor for success - * - * @param changeTrackingVersions change tracking versions - */ - public ChangeTrackingResult( - @Nonnull List changeTrackingVersions) { - super(BaseResult.ReturnStatus.SUCCESS); - this.changeTrackingVersions = changeTrackingVersions; - } - - @JsonCreator - private ChangeTrackingResult( - @JsonProperty("returnStatus") @Nonnull BaseResult.ReturnStatus returnStatus, - @JsonProperty("extraInformation") String extraInformation, - @JsonProperty("changeTrackingVersions") - List changeTrackingVersions) { - super(returnStatus, extraInformation); - this.changeTrackingVersions = changeTrackingVersions; - } - - public List getChangeTrackingVersions() { - return changeTrackingVersions; - } - } - /** * Load change tracking information for a set of entities in one single shot and return for each * the version for the entity itself and the version associated to its grant records. @@ -746,77 +312,6 @@ public List getChangeTrackingVersions() { ChangeTrackingResult loadEntitiesChangeTracking( @Nonnull PolarisCallContext callCtx, @Nonnull List entityIds); - /** - * Represents an entity with its grants. If we "refresh" a previously fetched entity, we will only - * refresh the information which has changed, based on the version of the entity. - */ - class ResolvedEntityResult extends BaseResult { - - // the entity itself if it was loaded - private final @Nullable PolarisBaseEntity entity; - - // version for the grant records, in case the entity was not loaded - private final int grantRecordsVersion; - - private final @Nullable List entityGrantRecords; - - /** - * Constructor for an error - * - * @param errorCode error code, cannot be SUCCESS - * @param extraInformation extra information - */ - public ResolvedEntityResult( - @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { - super(errorCode, extraInformation); - this.entity = null; - this.entityGrantRecords = null; - this.grantRecordsVersion = 0; - } - - /** - * Constructor with success - * - * @param entity the main entity - * @param grantRecordsVersion the version of the grant records - * @param entityGrantRecords the list of grant records - */ - public ResolvedEntityResult( - @Nullable PolarisBaseEntity entity, - int grantRecordsVersion, - @Nullable List entityGrantRecords) { - super(BaseResult.ReturnStatus.SUCCESS); - this.entity = entity; - this.entityGrantRecords = entityGrantRecords; - this.grantRecordsVersion = grantRecordsVersion; - } - - @JsonCreator - public ResolvedEntityResult( - @JsonProperty("returnStatus") @Nonnull BaseResult.ReturnStatus returnStatus, - @JsonProperty("extraInformation") String extraInformation, - @Nullable @JsonProperty("entity") PolarisBaseEntity entity, - @JsonProperty("grantRecordsVersion") int grantRecordsVersion, - @Nullable @JsonProperty("entityGrantRecords") List entityGrantRecords) { - super(returnStatus, extraInformation); - this.entity = entity; - this.entityGrantRecords = entityGrantRecords; - this.grantRecordsVersion = grantRecordsVersion; - } - - public @Nullable PolarisBaseEntity getEntity() { - return entity; - } - - public int getGrantRecordsVersion() { - return grantRecordsVersion; - } - - public @Nullable List getEntityGrantRecords() { - return entityGrantRecords; - } - } - /** * Load a resolved entity, i.e. an entity definition and associated grant records, from the * backend store. The entity is identified by its id (entity catalog id and id). diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java index 0d7c72d29..4a389f1c4 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java @@ -33,6 +33,17 @@ import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PolarisPrivilege; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.ChangeTrackingResult; +import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult; +import org.apache.polaris.core.persistence.dao.entity.CreatePrincipalResult; +import org.apache.polaris.core.persistence.dao.entity.DropEntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntitiesResult; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntityWithPath; +import org.apache.polaris.core.persistence.dao.entity.GenerateEntityIdResult; +import org.apache.polaris.core.persistence.dao.entity.ListEntitiesResult; +import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult; import org.apache.polaris.core.storage.PolarisStorageActions; /** @@ -85,7 +96,7 @@ public BaseResult purge(@Nonnull PolarisCallContext callCtx) { } @Override - public PolarisMetaStoreManager.EntityResult readEntityByName( + public EntityResult readEntityByName( @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java index 791c43b2c..7ca5de621 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java @@ -32,8 +32,8 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PolarisGrantRecord; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager.ResolvedEntityResult; import org.apache.polaris.core.persistence.ResolvedPolarisEntity; +import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult; /** The entity cache, can be private or shared */ public class EntityCache { diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/BaseResult.java similarity index 98% rename from polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseResult.java rename to polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/BaseResult.java index cea33071e..b4e1757de 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseResult.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/BaseResult.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.polaris.core.persistence; +package org.apache.polaris.core.persistence.dao.entity; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ChangeTrackingResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ChangeTrackingResult.java new file mode 100644 index 000000000..ff4c9b9b5 --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ChangeTrackingResult.java @@ -0,0 +1,68 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import java.util.List; +import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; + +/** Result of a loadEntitiesChangeTracking call */ +public class ChangeTrackingResult extends BaseResult { + + // null if not success. Else, will be null if the grant to revoke was not found + private final List changeTrackingVersions; + + /** + * Constructor for an error + * + * @param errorCode error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public ChangeTrackingResult(@Nonnull ReturnStatus errorCode, @Nullable String extraInformation) { + super(errorCode, extraInformation); + this.changeTrackingVersions = null; + } + + /** + * Constructor for success + * + * @param changeTrackingVersions change tracking versions + */ + public ChangeTrackingResult(@Nonnull List changeTrackingVersions) { + super(ReturnStatus.SUCCESS); + this.changeTrackingVersions = changeTrackingVersions; + } + + @JsonCreator + private ChangeTrackingResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") String extraInformation, + @JsonProperty("changeTrackingVersions") + List changeTrackingVersions) { + super(returnStatus, extraInformation); + this.changeTrackingVersions = changeTrackingVersions; + } + + public List getChangeTrackingVersions() { + return changeTrackingVersions; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreateCatalogResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreateCatalogResult.java new file mode 100644 index 000000000..b45a2a82a --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreateCatalogResult.java @@ -0,0 +1,79 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import org.apache.polaris.core.entity.PolarisBaseEntity; + +/** the return the result of a create-catalog method */ +public class CreateCatalogResult extends BaseResult { + + // the catalog which has been created + private final PolarisBaseEntity catalog; + + // its associated catalog admin role + private final PolarisBaseEntity catalogAdminRole; + + /** + * Constructor for an error + * + * @param errorCode error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public CreateCatalogResult(@Nonnull ReturnStatus errorCode, @Nullable String extraInformation) { + super(errorCode, extraInformation); + this.catalog = null; + this.catalogAdminRole = null; + } + + /** + * Constructor for success + * + * @param catalog the catalog + * @param catalogAdminRole and associated admin role + */ + public CreateCatalogResult( + @Nonnull PolarisBaseEntity catalog, @Nonnull PolarisBaseEntity catalogAdminRole) { + super(ReturnStatus.SUCCESS); + this.catalog = catalog; + this.catalogAdminRole = catalogAdminRole; + } + + @JsonCreator + private CreateCatalogResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") @Nullable String extraInformation, + @JsonProperty("catalog") @Nonnull PolarisBaseEntity catalog, + @JsonProperty("catalogAdminRole") @Nonnull PolarisBaseEntity catalogAdminRole) { + super(returnStatus, extraInformation); + this.catalog = catalog; + this.catalogAdminRole = catalogAdminRole; + } + + public PolarisBaseEntity getCatalog() { + return catalog; + } + + public PolarisBaseEntity getCatalogAdminRole() { + return catalogAdminRole; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreatePrincipalResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreatePrincipalResult.java new file mode 100644 index 000000000..54bc0f6d2 --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/CreatePrincipalResult.java @@ -0,0 +1,79 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import org.apache.polaris.core.entity.PolarisBaseEntity; +import org.apache.polaris.core.entity.PolarisPrincipalSecrets; + +/** the return the result of a create-principal method */ +public class CreatePrincipalResult extends BaseResult { + // the principal which has been created. Null if error + private final PolarisBaseEntity principal; + + // principal client identifier and associated secrets. Null if error + private final PolarisPrincipalSecrets principalSecrets; + + /** + * Constructor for an error + * + * @param errorCode error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public CreatePrincipalResult(@Nonnull ReturnStatus errorCode, @Nullable String extraInformation) { + super(errorCode, extraInformation); + this.principal = null; + this.principalSecrets = null; + } + + /** + * Constructor for success + * + * @param principal the principal + * @param principalSecrets and associated secret information + */ + public CreatePrincipalResult( + @Nonnull PolarisBaseEntity principal, @Nonnull PolarisPrincipalSecrets principalSecrets) { + super(ReturnStatus.SUCCESS); + this.principal = principal; + this.principalSecrets = principalSecrets; + } + + @JsonCreator + private CreatePrincipalResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") @Nullable String extraInformation, + @JsonProperty("principal") @Nonnull PolarisBaseEntity principal, + @JsonProperty("principalSecrets") @Nonnull PolarisPrincipalSecrets principalSecrets) { + super(returnStatus, extraInformation); + this.principal = principal; + this.principalSecrets = principalSecrets; + } + + public PolarisBaseEntity getPrincipal() { + return principal; + } + + public PolarisPrincipalSecrets getPrincipalSecrets() { + return principalSecrets; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/DropEntityResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/DropEntityResult.java new file mode 100644 index 000000000..a86df30d8 --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/DropEntityResult.java @@ -0,0 +1,82 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; + +// the return the result of a drop entity +public class DropEntityResult extends BaseResult { + + /** If cleanup was requested and a task was successfully scheduled, */ + private final Long cleanupTaskId; + + /** + * Constructor for an error + * + * @param errorStatus error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public DropEntityResult(@Nonnull ReturnStatus errorStatus, @Nullable String extraInformation) { + super(errorStatus, extraInformation); + this.cleanupTaskId = null; + } + + /** Constructor for success when no cleanup needs to be performed */ + public DropEntityResult() { + super(ReturnStatus.SUCCESS); + this.cleanupTaskId = null; + } + + /** + * Constructor for success when a cleanup task has been scheduled + * + * @param cleanupTaskId id of the task which was created to clean up the table drop + */ + public DropEntityResult(long cleanupTaskId) { + super(ReturnStatus.SUCCESS); + this.cleanupTaskId = cleanupTaskId; + } + + @JsonCreator + private DropEntityResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") String extraInformation, + @JsonProperty("cleanupTaskId") Long cleanupTaskId) { + super(returnStatus, extraInformation); + this.cleanupTaskId = cleanupTaskId; + } + + public Long getCleanupTaskId() { + return cleanupTaskId; + } + + @JsonIgnore + public boolean failedBecauseNotEmpty() { + ReturnStatus status = this.getReturnStatus(); + return status == ReturnStatus.CATALOG_NOT_EMPTY || status == ReturnStatus.NAMESPACE_NOT_EMPTY; + } + + public boolean isEntityUnDroppable() { + return this.getReturnStatus() == ReturnStatus.ENTITY_UNDROPPABLE; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntitiesResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntitiesResult.java new file mode 100644 index 000000000..70d9edcf5 --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntitiesResult.java @@ -0,0 +1,67 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import java.util.List; +import org.apache.polaris.core.entity.PolarisBaseEntity; + +/** a set of returned entities result */ +public class EntitiesResult extends BaseResult { + + // null if not success. Else the list of entities being returned + private final List entities; + + /** + * Constructor for an error + * + * @param errorStatus error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public EntitiesResult(@Nonnull ReturnStatus errorStatus, @Nullable String extraInformation) { + super(errorStatus, extraInformation); + this.entities = null; + } + + /** + * Constructor for success + * + * @param entities list of entities being returned, implies success + */ + public EntitiesResult(@Nonnull List entities) { + super(ReturnStatus.SUCCESS); + this.entities = entities; + } + + @JsonCreator + private EntitiesResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") String extraInformation, + @JsonProperty("entities") List entities) { + super(returnStatus, extraInformation); + this.entities = entities; + } + + public List getEntities() { + return entities; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityResult.java new file mode 100644 index 000000000..518caf92a --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityResult.java @@ -0,0 +1,102 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import org.apache.polaris.core.entity.PolarisBaseEntity; +import org.apache.polaris.core.entity.PolarisEntitySubType; + +/** the return for an entity lookup call */ +public class EntityResult extends BaseResult { + + // null if not success + private final PolarisBaseEntity entity; + + /** + * Constructor for an error + * + * @param errorCode error code, cannot be SUCCESS + * @param extraInformation extra information if error. Implementation specific + */ + public EntityResult( + @Nonnull BaseResult.ReturnStatus errorCode, @Nullable String extraInformation) { + super(errorCode, extraInformation); + this.entity = null; + } + + /** + * Constructor for success + * + * @param entity the entity being looked-up + */ + public EntityResult(@Nonnull PolarisBaseEntity entity) { + super(ReturnStatus.SUCCESS); + this.entity = entity; + } + + /** + * Constructor for an object already exists error where the subtype of the existing entity is + * returned + * + * @param errorStatus error status, cannot be SUCCESS + * @param subTypeCode existing entity subtype code + */ + public EntityResult(@Nonnull BaseResult.ReturnStatus errorStatus, int subTypeCode) { + super(errorStatus, Integer.toString(subTypeCode)); + this.entity = null; + } + + /** + * For object already exist error, we use the extra information to serialize the subtype code of + * the existing object. Return the subtype + * + * @return object subtype or NULL (should not happen) if subtype code is missing or cannot be + * deserialized + */ + @Nullable + public PolarisEntitySubType getAlreadyExistsEntitySubType() { + if (this.getExtraInformation() == null) { + return null; + } else { + int subTypeCode; + try { + subTypeCode = Integer.parseInt(this.getExtraInformation()); + } catch (NumberFormatException e) { + return null; + } + return PolarisEntitySubType.fromCode(subTypeCode); + } + } + + @JsonCreator + private EntityResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") @Nullable String extraInformation, + @JsonProperty("entity") @Nullable PolarisBaseEntity entity) { + super(returnStatus, extraInformation); + this.entity = entity; + } + + public PolarisBaseEntity getEntity() { + return entity; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityWithPath.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityWithPath.java new file mode 100644 index 000000000..e4b0be4ef --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/EntityWithPath.java @@ -0,0 +1,51 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import java.util.List; +import org.apache.polaris.core.entity.PolarisBaseEntity; +import org.apache.polaris.core.entity.PolarisEntityCore; + +/** Class to represent an entity with its path */ +public class EntityWithPath { + // path to that entity. Could be null if this entity is top-level + private final @Nonnull List catalogPath; + + // the base entity itself + private final @Nonnull PolarisBaseEntity entity; + + @JsonCreator + public EntityWithPath( + @JsonProperty("catalogPath") @Nonnull List catalogPath, + @JsonProperty("entity") @Nonnull PolarisBaseEntity entity) { + this.catalogPath = catalogPath; + this.entity = entity; + } + + public @Nonnull List getCatalogPath() { + return catalogPath; + } + + public @Nonnull PolarisBaseEntity getEntity() { + return entity; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/GenerateEntityIdResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/GenerateEntityIdResult.java new file mode 100644 index 000000000..b549427db --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/GenerateEntityIdResult.java @@ -0,0 +1,66 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; + +/** the return for a generate new entity id */ +public class GenerateEntityIdResult extends BaseResult { + + // null if not success + private final Long id; + + /** + * Constructor for an error + * + * @param errorCode error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public GenerateEntityIdResult( + @Nonnull ReturnStatus errorCode, @Nullable String extraInformation) { + super(errorCode, extraInformation); + this.id = null; + } + + /** + * Constructor for success + * + * @param id the new id which was generated + */ + public GenerateEntityIdResult(@Nonnull Long id) { + super(ReturnStatus.SUCCESS); + this.id = id; + } + + @JsonCreator + private GenerateEntityIdResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") @Nullable String extraInformation, + @JsonProperty("id") @Nullable Long id) { + super(returnStatus, extraInformation); + this.id = id; + } + + public Long getId() { + return id; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ListEntitiesResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ListEntitiesResult.java new file mode 100644 index 000000000..bc51f4dab --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ListEntitiesResult.java @@ -0,0 +1,67 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import java.util.List; +import org.apache.polaris.core.entity.EntityNameLookupRecord; + +/** the return the result for a list entities call */ +public class ListEntitiesResult extends BaseResult { + + // null if not success. Else the list of entities being returned + private final List entities; + + /** + * Constructor for an error + * + * @param errorCode error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public ListEntitiesResult(@Nonnull ReturnStatus errorCode, @Nullable String extraInformation) { + super(errorCode, extraInformation); + this.entities = null; + } + + /** + * Constructor for success + * + * @param entities list of entities being returned, implies success + */ + public ListEntitiesResult(@Nonnull List entities) { + super(ReturnStatus.SUCCESS); + this.entities = entities; + } + + @JsonCreator + private ListEntitiesResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") String extraInformation, + @JsonProperty("entities") List entities) { + super(returnStatus, extraInformation); + this.entities = entities; + } + + public List getEntities() { + return entities; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ResolvedEntityResult.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ResolvedEntityResult.java new file mode 100644 index 000000000..0fc693694 --- /dev/null +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/ResolvedEntityResult.java @@ -0,0 +1,97 @@ +/* + * 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.polaris.core.persistence.dao.entity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import java.util.List; +import org.apache.polaris.core.entity.PolarisBaseEntity; +import org.apache.polaris.core.entity.PolarisGrantRecord; + +/** + * Represents an entity with its grants. If we "refresh" a previously fetched entity, we will only + * refresh the information which has changed, based on the version of the entity. + */ +public class ResolvedEntityResult extends BaseResult { + + // the entity itself if it was loaded + private final @Nullable PolarisBaseEntity entity; + + // version for the grant records, in case the entity was not loaded + private final int grantRecordsVersion; + + private final @Nullable List entityGrantRecords; + + /** + * Constructor for an error + * + * @param errorCode error code, cannot be SUCCESS + * @param extraInformation extra information + */ + public ResolvedEntityResult(@Nonnull ReturnStatus errorCode, @Nullable String extraInformation) { + super(errorCode, extraInformation); + this.entity = null; + this.entityGrantRecords = null; + this.grantRecordsVersion = 0; + } + + /** + * Constructor with success + * + * @param entity the main entity + * @param grantRecordsVersion the version of the grant records + * @param entityGrantRecords the list of grant records + */ + public ResolvedEntityResult( + @Nullable PolarisBaseEntity entity, + int grantRecordsVersion, + @Nullable List entityGrantRecords) { + super(ReturnStatus.SUCCESS); + this.entity = entity; + this.entityGrantRecords = entityGrantRecords; + this.grantRecordsVersion = grantRecordsVersion; + } + + @JsonCreator + public ResolvedEntityResult( + @JsonProperty("returnStatus") @Nonnull ReturnStatus returnStatus, + @JsonProperty("extraInformation") String extraInformation, + @Nullable @JsonProperty("entity") PolarisBaseEntity entity, + @JsonProperty("grantRecordsVersion") int grantRecordsVersion, + @Nullable @JsonProperty("entityGrantRecords") List entityGrantRecords) { + super(returnStatus, extraInformation); + this.entity = entity; + this.entityGrantRecords = entityGrantRecords; + this.grantRecordsVersion = grantRecordsVersion; + } + + public @Nullable PolarisBaseEntity getEntity() { + return entity; + } + + public int getGrantRecordsVersion() { + return grantRecordsVersion; + } + + public @Nullable List getEntityGrantRecords() { + return entityGrantRecords; + } +} diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java index fece68506..b90ca7c3e 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java @@ -41,12 +41,12 @@ import org.apache.polaris.core.entity.PolarisGrantRecord; import org.apache.polaris.core.entity.PolarisPrivilege; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager.ChangeTrackingResult; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager.ResolvedEntityResult; import org.apache.polaris.core.persistence.ResolvedPolarisEntity; import org.apache.polaris.core.persistence.cache.EntityCache; import org.apache.polaris.core.persistence.cache.EntityCacheByNameKey; import org.apache.polaris.core.persistence.cache.EntityCacheLookupResult; +import org.apache.polaris.core.persistence.dao.entity.ChangeTrackingResult; +import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult; /** * REST request resolver, allows to resolve all entities referenced directly or indirectly by in diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisMetaStoreManagerImpl.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisMetaStoreManagerImpl.java index da2ff2e92..30aa1d939 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisMetaStoreManagerImpl.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisMetaStoreManagerImpl.java @@ -51,6 +51,17 @@ import org.apache.polaris.core.entity.PolarisPrivilege; import org.apache.polaris.core.entity.PolarisTaskConstants; import org.apache.polaris.core.persistence.*; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.ChangeTrackingResult; +import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult; +import org.apache.polaris.core.persistence.dao.entity.CreatePrincipalResult; +import org.apache.polaris.core.persistence.dao.entity.DropEntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntitiesResult; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntityWithPath; +import org.apache.polaris.core.persistence.dao.entity.GenerateEntityIdResult; +import org.apache.polaris.core.persistence.dao.entity.ListEntitiesResult; +import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.PolarisStorageActions; import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo; diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java index 9f03082a9..9c3c1ce67 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.Set; import org.apache.polaris.core.PolarisCallContext; -import org.apache.polaris.core.persistence.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; /** Manage credentials for storage locations. */ public interface PolarisCredentialVendor { diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java index c3e5f7532..7099fdf44 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java @@ -44,8 +44,9 @@ import org.apache.polaris.core.entity.PolarisPrivilege; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.entity.PrincipalRoleEntity; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager.ResolvedEntityResult; import org.apache.polaris.core.persistence.cache.EntityCache; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; +import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult; import org.apache.polaris.core.persistence.resolver.Resolver; import org.apache.polaris.core.persistence.resolver.ResolverPath; import org.apache.polaris.core.persistence.resolver.ResolverStatus; @@ -486,8 +487,8 @@ private Resolver allocateResolver( PolarisEntityType.PRINCIPAL_ROLE, PolarisEntitySubType.NULL_SUBTYPE, role)) - .filter(PolarisMetaStoreManager.EntityResult::isSuccess) - .map(PolarisMetaStoreManager.EntityResult::getEntity) + .filter(EntityResult::isSuccess) + .map(EntityResult::getEntity) .map(PrincipalRoleEntity::of) .collect(Collectors.toList())); AuthenticatedPolarisPrincipal authenticatedPrincipal = @@ -775,7 +776,7 @@ private Resolver resolveDriver( // the principal does not exist, check that this is the case if (principalName != null) { // see if the principal exists - PolarisMetaStoreManager.EntityResult result = + EntityResult result = this.metaStoreManager.readEntityByName( this.callCtx, null, diff --git a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java index 848367fe5..22e4c8b9d 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java @@ -37,9 +37,9 @@ import org.apache.polaris.core.entity.PolarisEntityConstants; import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; -import org.apache.polaris.core.persistence.BaseResult; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.PolarisObjectMapperUtil; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; import org.apache.polaris.core.persistence.transactional.PolarisTreeMapMetaStoreSessionImpl; import org.apache.polaris.core.persistence.transactional.PolarisTreeMapStore; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; diff --git a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java index 5270990a9..0db9a6df4 100644 --- a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java +++ b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java @@ -43,7 +43,12 @@ import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.entity.PolarisPrivilege; import org.apache.polaris.core.entity.PolarisTaskConstants; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager.ResolvedEntityResult; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult; +import org.apache.polaris.core.persistence.dao.entity.CreatePrincipalResult; +import org.apache.polaris.core.persistence.dao.entity.DropEntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; +import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult; import org.assertj.core.api.Assertions; /** Test the Polaris persistence layer */ @@ -135,7 +140,7 @@ private PolarisBaseEntity ensureExistsById( Assertions.assertThat(entity.getPurgeTimestamp()).isEqualTo(0); // we should find it - PolarisMetaStoreManager.EntityResult result = + EntityResult result = polarisMetaStoreManager.readEntityByName( this.polarisCallContext, catalogPath, expectedType, expectedSubType, expectedName); @@ -152,7 +157,7 @@ private PolarisBaseEntity ensureExistsById( Assertions.assertThat(entity.getDropTimestamp()).isNotZero(); // we should not find it - PolarisMetaStoreManager.EntityResult result = + EntityResult result = polarisMetaStoreManager.readEntityByName( this.polarisCallContext, catalogPath, expectedType, expectedSubType, expectedName); @@ -368,7 +373,7 @@ PolarisBaseEntity createPrincipal(String name) { PolarisObjectMapperUtil.serializeProperties( this.polarisCallContext, Map.of(PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE, "true"))); - PolarisMetaStoreManager.CreatePrincipalResult createPrincipalResult = + CreatePrincipalResult createPrincipalResult = polarisMetaStoreManager.createPrincipal(this.polarisCallContext, principalEntity); Assertions.assertThat(createPrincipalResult).isNotNull(); @@ -418,7 +423,7 @@ PolarisBaseEntity createPrincipal(String name) { // simulate retry if we are asked to if (this.doRetry) { // simulate that we retried - PolarisMetaStoreManager.CreatePrincipalResult newCreatePrincipalResult = + CreatePrincipalResult newCreatePrincipalResult = polarisMetaStoreManager.createPrincipal(this.polarisCallContext, principalEntity); Assertions.assertThat(newCreatePrincipalResult).isNotNull(); @@ -636,7 +641,7 @@ void dropEntity(List catalogPath, PolarisEntityCore entityToD .loadEntity(this.polarisCallContext, entityToDrop.getCatalogId(), entityToDrop.getId()) .getEntity(); if (entity != null) { - PolarisMetaStoreManager.EntityResult entityFound = + EntityResult entityFound = polarisMetaStoreManager.readEntityByName( this.polarisCallContext, catalogPath, @@ -721,7 +726,7 @@ void dropEntity(List catalogPath, PolarisEntityCore entityToD // now drop it Map cleanupProperties = Map.of("taskId", String.valueOf(entity.getId()), "cleanupProperty", "cleanupValue"); - PolarisMetaStoreManager.DropEntityResult dropResult = + DropEntityResult dropResult = polarisMetaStoreManager.dropEntityIfExists( this.polarisCallContext, catalogPath, entityToDrop, cleanupProperties, true); @@ -778,7 +783,7 @@ void dropEntity(List catalogPath, PolarisEntityCore entityToD // should no longer exists Assertions.assertThat(entity).isNotNull(); - PolarisMetaStoreManager.EntityResult entityFound = + EntityResult entityFound = polarisMetaStoreManager.readEntityByName( this.polarisCallContext, catalogPath, @@ -916,7 +921,7 @@ PolarisBaseEntity createTestCatalog(String catalogName) { PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), catalogName); - PolarisMetaStoreManager.CreateCatalogResult catalogCreated = + CreateCatalogResult catalogCreated = polarisMetaStoreManager.createCatalog(this.polarisCallContext, catalog, List.of()); Assertions.assertThat(catalogCreated).isNotNull(); catalog = catalogCreated.getCatalog(); @@ -1012,7 +1017,7 @@ PolarisBaseEntity ensureExistsByName( PolarisEntitySubType entitySubType, String name) { // find by name, ensure we found it - PolarisMetaStoreManager.EntityResult entityFound = + EntityResult entityFound = polarisMetaStoreManager.readEntityByName( this.polarisCallContext, catalogPath, entityType, entitySubType, name); Assertions.assertThat(entityFound).isNotNull(); @@ -1930,7 +1935,7 @@ void testDropEntities() { this.dropEntity(null, catalog); // catalog exists - PolarisMetaStoreManager.EntityResult catalogFound = + EntityResult catalogFound = polarisMetaStoreManager.readEntityByName( this.polarisCallContext, null, @@ -2095,7 +2100,7 @@ void renameEntity( renamedEntityInput.setProperties(updatedPropertiesString); // check to see if we would have a name conflict - PolarisMetaStoreManager.EntityResult newNameLookup = + EntityResult newNameLookup = polarisMetaStoreManager.readEntityByName( polarisCallContext, newCatPath == null ? catPath : newCatPath, @@ -2130,7 +2135,7 @@ void renameEntity( Assertions.assertThat(renamedEntityOut.getProperties()).isEqualTo(updatedPropertiesString); // ensure the old one is gone - PolarisMetaStoreManager.EntityResult res = + EntityResult res = polarisMetaStoreManager.readEntityByName( polarisCallContext, catPath, entity.getType(), entity.getSubType(), oldName); diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java index e1176ce51..65bd9edbf 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java @@ -71,6 +71,7 @@ import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisEntityManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; import org.apache.polaris.service.admin.PolarisAdminService; @@ -370,7 +371,7 @@ public void after() { gr -> metaStoreManager.loadEntity( callContext.getPolarisCallContext(), 0L, gr.getSecurableId())) - .map(PolarisMetaStoreManager.EntityResult::getEntity) + .map(EntityResult::getEntity) .map(PolarisBaseEntity::getName) .collect(Collectors.toSet()); } @@ -380,7 +381,7 @@ public void after() { String principalName, PrincipalWithCredentialsCredentials credentials, PolarisCallContext polarisContext) { - PolarisMetaStoreManager.EntityResult lookupEntity = + EntityResult lookupEntity = metaStoreManager.readEntityByName( callContext.getPolarisCallContext(), null, diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTRSAKeyPairTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTRSAKeyPairTest.java index 6e4df3821..75fea55ad 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTRSAKeyPairTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTRSAKeyPairTest.java @@ -36,6 +36,7 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.service.auth.JWTRSAKeyPair; import org.apache.polaris.service.auth.LocalRSAKeyProvider; import org.apache.polaris.service.auth.PemUtils; @@ -75,7 +76,7 @@ public void testSuccessfulTokenGeneration() throws Exception { 0L, "principal"); Mockito.when(metastoreManager.loadEntity(polarisCallContext, 0L, 1L)) - .thenReturn(new PolarisMetaStoreManager.EntityResult(principal)); + .thenReturn(new EntityResult(principal)); TokenBroker tokenBroker = new JWTRSAKeyPair(metastoreManager, 420, publicFileLocation, privateFileLocation); TokenResponse token = diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTSymmetricKeyGeneratorTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTSymmetricKeyGeneratorTest.java index 423ff36c1..5151132e3 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTSymmetricKeyGeneratorTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTSymmetricKeyGeneratorTest.java @@ -33,6 +33,7 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.service.auth.JWTSymmetricKeyBroker; import org.apache.polaris.service.auth.TokenBroker; import org.apache.polaris.service.auth.TokenRequestValidator; @@ -80,7 +81,7 @@ public Map contextVariables() { 0L, "principal"); Mockito.when(metastoreManager.loadEntity(polarisCallContext, 0L, 1L)) - .thenReturn(new PolarisMetaStoreManager.EntityResult(principal)); + .thenReturn(new EntityResult(principal)); TokenBroker generator = new JWTSymmetricKeyBroker(metastoreManager, 666, () -> "polaris"); TokenResponse token = generator.generateFromClientSecrets( diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java index 8b9a53872..2469aaf46 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java @@ -89,13 +89,13 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.entity.TaskEntity; -import org.apache.polaris.core.persistence.BaseResult; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisEntityManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; import org.apache.polaris.core.persistence.cache.EntityCache; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.PolarisStorageActions; diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java index 7e5d0e00c..29d0bd90c 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java @@ -62,7 +62,7 @@ import org.apache.polaris.core.entity.PolarisPrivilege; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.PolarisEntityManager; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.CreatePrincipalResult; import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest; import org.apache.polaris.service.catalog.PolarisCatalogHandlerWrapper; import org.apache.polaris.service.catalog.io.DefaultFileIOFactory; @@ -227,7 +227,7 @@ public void testListNamespacesInsufficientPermissions() { @Test public void testInsufficientPermissionsPriorToSecretRotation() { String principalName = "all_the_powers"; - PolarisMetaStoreManager.CreatePrincipalResult newPrincipal = + CreatePrincipalResult newPrincipal = metaStoreManager.createPrincipal( callContext.getPolarisCallContext(), new PrincipalEntity.Builder() diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java index 7c7b6af8a..5b0f32350 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java @@ -44,6 +44,7 @@ import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory; import org.apache.polaris.service.quarkus.auth.TokenUtils; @@ -115,7 +116,7 @@ private PolarisPrincipalSecrets fetchAdminSecrets() { CallContext.setCurrentContext(ctx); PolarisMetaStoreManager metaStoreManager = helper.metaStoreManagerFactory.getOrCreateMetaStoreManager(ctx.getRealmContext()); - PolarisMetaStoreManager.EntityResult principal = + EntityResult principal = metaStoreManager.readEntityByName( ctx.getPolarisCallContext(), null, @@ -226,8 +227,7 @@ public void destroy() { } } - private Map readInternalProperties( - PolarisMetaStoreManager.EntityResult principal) { + private Map readInternalProperties(EntityResult principal) { try { return helper.objectMapper.readValue( principal.getEntity().getInternalProperties(), new TypeReference<>() {}); diff --git a/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java b/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java index 6a90e2ab4..70b2e20ef 100644 --- a/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java +++ b/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java @@ -84,6 +84,9 @@ import org.apache.polaris.core.persistence.PolarisEntityManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; +import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult; +import org.apache.polaris.core.persistence.dao.entity.CreatePrincipalResult; +import org.apache.polaris.core.persistence.dao.entity.DropEntityResult; import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest; import org.apache.polaris.core.persistence.resolver.ResolverPath; import org.apache.polaris.core.persistence.resolver.ResolverStatus; @@ -572,7 +575,7 @@ public PolarisEntity createCatalog(PolarisEntity entity) { .setId(metaStoreManager.generateNewEntityId(getCurrentPolarisContext()).getId()) .setCreateTimestamp(System.currentTimeMillis()) .build(); - PolarisMetaStoreManager.CreateCatalogResult catalogResult = + CreateCatalogResult catalogResult = metaStoreManager.createCatalog(getCurrentPolarisContext(), polarisEntity, List.of()); if (catalogResult.alreadyExists()) { throw new AlreadyExistsException( @@ -595,7 +598,7 @@ public void deleteCatalog(String name) { polarisCallContext .getConfigurationStore() .getConfiguration(polarisCallContext, PolarisConfiguration.CLEANUP_ON_CATALOG_DROP); - PolarisMetaStoreManager.DropEntityResult dropEntityResult = + DropEntityResult dropEntityResult = metaStoreManager.dropEntityIfExists( getCurrentPolarisContext(), null, entity, Map.of(), cleanup); @@ -768,7 +771,7 @@ public PrincipalWithCredentials createPrincipal(PolarisEntity entity) { checkArgument(entity.getId() == -1, "Entity to be created must have no ID assigned"); - PolarisMetaStoreManager.CreatePrincipalResult principalResult = + CreatePrincipalResult principalResult = metaStoreManager.createPrincipal( getCurrentPolarisContext(), new PolarisEntity.Builder(entity) @@ -795,7 +798,7 @@ public void deletePrincipal(String name) { findPrincipalByName(name) .orElseThrow(() -> new NotFoundException("Principal %s not found", name)); // TODO: Handle return value in case of concurrent modification - PolarisMetaStoreManager.DropEntityResult dropEntityResult = + DropEntityResult dropEntityResult = metaStoreManager.dropEntityIfExists( getCurrentPolarisContext(), null, entity, Map.of(), false); @@ -955,7 +958,7 @@ public void deletePrincipalRole(String name) { findPrincipalRoleByName(name) .orElseThrow(() -> new NotFoundException("PrincipalRole %s not found", name)); // TODO: Handle return value in case of concurrent modification - PolarisMetaStoreManager.DropEntityResult dropEntityResult = + DropEntityResult dropEntityResult = metaStoreManager.dropEntityIfExists( getCurrentPolarisContext(), null, entity, Map.of(), true); // cleanup grants @@ -1070,7 +1073,7 @@ public void deleteCatalogRole(String catalogName, String name) { throw new NotFoundException("CatalogRole %s not found in catalog %s", name, catalogName); } // TODO: Handle return value in case of concurrent modification - PolarisMetaStoreManager.DropEntityResult dropEntityResult = + DropEntityResult dropEntityResult = metaStoreManager.dropEntityIfExists( getCurrentPolarisContext(), PolarisEntity.toCoreList(resolvedCatalogRoleEntity.getRawParentPath()), diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java b/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java index a9cea1f00..869a27b52 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java @@ -34,6 +34,7 @@ import org.apache.polaris.core.entity.PrincipalRoleEntity; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,8 +89,8 @@ protected List loadActivePrincipalRoles( gr -> metaStoreManager.loadEntity( polarisContext, gr.getSecurableCatalogId(), gr.getSecurableId())) - .filter(PolarisMetaStoreManager.EntityResult::isSuccess) - .map(PolarisMetaStoreManager.EntityResult::getEntity) + .filter(EntityResult::isSuccess) + .map(EntityResult::getEntity) .map(PrincipalRoleEntity::of) .filter(includeRoleFilter) .toList(); diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/JWTBroker.java b/service/common/src/main/java/org/apache/polaris/service/auth/JWTBroker.java index 37e36c287..0e7ca3107 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/JWTBroker.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/JWTBroker.java @@ -34,6 +34,7 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.service.types.TokenType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,7 +110,7 @@ public TokenResponse generateFromToken( return new TokenResponse(OAuthTokenErrorResponse.Error.invalid_request); } DecodedToken decodedToken = verify(subjectToken); - PolarisMetaStoreManager.EntityResult principalLookup = + EntityResult principalLookup = metaStoreManager.loadEntity( CallContext.getCurrentContext().getPolarisCallContext(), 0L, diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java b/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java index 910defbfa..00330bc2c 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java @@ -35,6 +35,7 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.service.catalog.api.IcebergRestOAuth2ApiService; import org.apache.polaris.service.types.TokenType; import org.slf4j.Logger; @@ -88,7 +89,7 @@ private String getPrincipalName(String clientId, RealmContext realmContext) { metaStoreManager.loadPrincipalSecrets(polarisCallContext, clientId); if (secretsResult.isSuccess()) { LOGGER.debug("Found principal secrets for client id {}", clientId); - PolarisMetaStoreManager.EntityResult principalResult = + EntityResult principalResult = metaStoreManager.loadEntity( polarisCallContext, 0L, secretsResult.getPrincipalSecrets().getPrincipalId()); if (!principalResult.isSuccess()) { @@ -98,7 +99,7 @@ private String getPrincipalName(String clientId, RealmContext realmContext) { } else { LOGGER.debug( "Unable to find principal secrets for client id {} - trying as principal name", clientId); - PolarisMetaStoreManager.EntityResult principalResult = + EntityResult principalResult = metaStoreManager.readEntityByName( polarisCallContext, null, diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/TokenBroker.java b/service/common/src/main/java/org/apache/polaris/service/auth/TokenBroker.java index 3488024bc..aaf094950 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/TokenBroker.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/TokenBroker.java @@ -25,6 +25,7 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.apache.polaris.service.types.TokenType; /** Generic token class intended to be extended by different token types */ @@ -124,7 +125,7 @@ TokenResponse generateFromToken( if (!principalSecrets.getPrincipalSecrets().matchesSecret(clientSecret)) { return Optional.empty(); } - PolarisMetaStoreManager.EntityResult result = + EntityResult result = metaStoreManager.loadEntity( polarisCallContext, 0L, principalSecrets.getPrincipalSecrets().getPrincipalId()); if (!result.isSuccess() || result.getEntity().getType() != PolarisEntityType.PRINCIPAL) { diff --git a/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java b/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java index 731d3b5d9..2e487675b 100644 --- a/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java +++ b/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java @@ -89,11 +89,14 @@ import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PolarisTaskConstants; import org.apache.polaris.core.entity.TableLikeEntity; -import org.apache.polaris.core.persistence.BaseResult; import org.apache.polaris.core.persistence.PolarisEntityManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; import org.apache.polaris.core.persistence.ResolvedPolarisEntity; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.DropEntityResult; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; +import org.apache.polaris.core.persistence.dao.entity.ListEntitiesResult; import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest; import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifestCatalogView; import org.apache.polaris.core.persistence.resolver.ResolverPath; @@ -432,7 +435,7 @@ public boolean dropTable(TableIdentifier tableIdentifier, boolean purge) { return clone; }) .orElse(Map.of()); - PolarisMetaStoreManager.DropEntityResult dropEntityResult = + DropEntityResult dropEntityResult = dropTableLike(PolarisEntitySubType.TABLE, tableIdentifier, storageProperties, purge); if (!dropEntityResult.isSuccess()) { return false; @@ -637,7 +640,7 @@ public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyExcept // drop if exists and is empty PolarisCallContext polarisCallContext = callContext.getPolarisCallContext(); - PolarisMetaStoreManager.DropEntityResult dropEntityResult = + DropEntityResult dropEntityResult = getMetaStoreManager() .dropEntityIfExists( getCurrentPolarisContext(), @@ -1077,7 +1080,7 @@ private void validateNoLocationOverlap( */ private void validateNoLocationOverlap( String location, List parentPath, String name) { - PolarisMetaStoreManager.ListEntitiesResult siblingNamespacesResult = + ListEntitiesResult siblingNamespacesResult = getMetaStoreManager() .listEntities( callContext.getPolarisCallContext(), @@ -1100,7 +1103,7 @@ private void validateNoLocationOverlap( parentNamespace .map( ns -> { - PolarisMetaStoreManager.ListEntitiesResult siblingTablesResult = + ListEntitiesResult siblingTablesResult = getMetaStoreManager() .listEntities( callContext.getPolarisCallContext(), @@ -1690,7 +1693,7 @@ private void renameTableLike( } // rename the entity now - PolarisMetaStoreManager.EntityResult returnedEntityResult = + EntityResult returnedEntityResult = getMetaStoreManager() .renameEntity( getCurrentPolarisContext(), @@ -1860,7 +1863,7 @@ private void updateTableLike(TableIdentifier identifier, PolarisEntity entity) { } @SuppressWarnings("FormatStringAnnotation") - private @Nonnull PolarisMetaStoreManager.DropEntityResult dropTableLike( + private @Nonnull DropEntityResult dropTableLike( PolarisEntitySubType subType, TableIdentifier identifier, Map storageProperties, @@ -1869,8 +1872,7 @@ private void updateTableLike(TableIdentifier identifier, PolarisEntity entity) { resolvedEntityView.getResolvedPath(identifier, subType); if (resolvedEntities == null) { // TODO: Error? - return new PolarisMetaStoreManager.DropEntityResult( - BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); + return new DropEntityResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } List catalogPath = resolvedEntities.getRawParentPath(); diff --git a/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java b/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java index 6d8f9aa48..489ccd488 100644 --- a/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java +++ b/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java @@ -86,6 +86,8 @@ import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; import org.apache.polaris.core.persistence.TransactionWorkspaceMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.EntitiesResult; +import org.apache.polaris.core.persistence.dao.entity.EntityWithPath; import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest; import org.apache.polaris.core.persistence.resolver.ResolverPath; import org.apache.polaris.core.persistence.resolver.ResolverStatus; @@ -1089,9 +1091,8 @@ public void commitTransaction(CommitTransactionRequest commitTransactionRequest) }); // Commit the collected updates in a single atomic operation - List pendingUpdates = - transactionMetaStoreManager.getPendingUpdates(); - PolarisMetaStoreManager.EntitiesResult result = + List pendingUpdates = transactionMetaStoreManager.getPendingUpdates(); + EntitiesResult result = metaStoreManager.updateEntitiesPropertiesIfNotChanged( callContext.getPolarisCallContext(), pendingUpdates); if (!result.isSuccess()) { diff --git a/service/common/src/test/java/org/apache/polaris/service/auth/BasePolarisAuthenticatorTest.java b/service/common/src/test/java/org/apache/polaris/service/auth/BasePolarisAuthenticatorTest.java index b2511f7ca..69e15bc4e 100644 --- a/service/common/src/test/java/org/apache/polaris/service/auth/BasePolarisAuthenticatorTest.java +++ b/service/common/src/test/java/org/apache/polaris/service/auth/BasePolarisAuthenticatorTest.java @@ -27,9 +27,10 @@ import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.context.RealmContext; -import org.apache.polaris.core.persistence.BaseResult; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.BaseResult; +import org.apache.polaris.core.persistence.dao.entity.EntityResult; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -80,8 +81,7 @@ public void testFetchPrincipalThrowsNotAuthorizedWhenNotFound() { when(token.getPrincipalId()).thenReturn(principalId); when(token.getClientId()).thenReturn("abc"); when(metaStoreManager.loadEntity(polarisCallContext, 0L, principalId)) - .thenReturn( - new PolarisMetaStoreManager.EntityResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, "")); + .thenReturn(new EntityResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, "")); Assertions.assertThatThrownBy(() -> authenticator.getPrincipal(token)) .isInstanceOf(NotAuthorizedException.class) diff --git a/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java b/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java index 645165628..7dd4f6804 100644 --- a/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java +++ b/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java @@ -40,6 +40,7 @@ import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisEntityManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; +import org.apache.polaris.core.persistence.dao.entity.CreatePrincipalResult; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; import org.apache.polaris.service.admin.PolarisServiceImpl; import org.apache.polaris.service.admin.api.PolarisCatalogsApi; @@ -184,7 +185,7 @@ public Map contextVariables() { IcebergRestCatalogApi restApi = new IcebergRestCatalogApi(service); - PolarisMetaStoreManager.CreatePrincipalResult createdPrincipal = + CreatePrincipalResult createdPrincipal = metaStoreManager.createPrincipal( callContext.getPolarisCallContext(), new PrincipalEntity.Builder()