Skip to content

Commit

Permalink
All tests passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yufei Gu committed Mar 9, 2025
1 parent e6d553c commit 1db510d
Show file tree
Hide file tree
Showing 33 changed files with 2,336 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.polaris.core.persistence.dao.PolarisMetastoreManagerDao;
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;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,70 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.polaris.core.persistence.dao;

import jakarta.annotation.Nonnull;
import java.util.List;
import java.util.Map;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityCore;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult;
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.dao.entity.ResolvedEntityResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface CatalogDao {
CreateCatalogResult createCatalog(@NotNull PolarisCallContext callCtx, @NotNull PolarisBaseEntity catalog, @NotNull List<PolarisEntityCore> principalRoles);
CreateCatalogResult createCatalog(
@NotNull PolarisCallContext callCtx,
@NotNull PolarisBaseEntity catalog,
@NotNull List<PolarisEntityCore> principalRoles);

// TODO this should return a type-specific entity result, e.g., CatalogEntityResult
@NotNull
EntityResult readEntityByName(
@NotNull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@NotNull String name);

@Nonnull
EntityResult loadEntity(@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId);

@Nonnull
ListEntitiesResult listEntities(@Nonnull PolarisCallContext callCtx);

@Nonnull
EntityResult updateEntityPropertiesIfNotChanged(
@Nonnull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisBaseEntity entity);

@Nonnull
DropEntityResult dropEntityIfExists(
@Nonnull PolarisCallContext callCtx,
@Nonnull PolarisEntityCore entityToDrop,
@Nullable Map<String, String> cleanupProperties,
boolean cleanup);

@Nonnull
ResolvedEntityResult loadResolvedEntityById(
@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId);

// TODO this should return a type-specific entity result, e.g., CatalogEntityResult
@NotNull
EntityResult readEntityByName(@NotNull PolarisCallContext callCtx, @Nullable List<PolarisEntityCore> catalogPath, @NotNull String name);
@Nonnull
ResolvedEntityResult loadResolvedEntityByName(
@Nonnull PolarisCallContext callCtx,
long entityCatalogId,
long parentId,
@Nonnull String entityName);

// TODO this should return a type-specific entity result
@Nonnull
ListEntitiesResult listEntities(@Nonnull PolarisCallContext callCtx);
@Nonnull
ResolvedEntityResult refreshResolvedEntity(
@Nonnull PolarisCallContext callCtx,
int entityVersion,
int entityGrantRecordsVersion,
long entityCatalogId,
long entityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,71 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.polaris.core.persistence.dao;

import jakarta.annotation.Nonnull;
import java.util.List;
import java.util.Map;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityCore;
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.dao.entity.ResolvedEntityResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface CatalogRoleDao {
@NotNull
EntityResult readEntityByName(
@NotNull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@NotNull String name);

@Nonnull
EntityResult loadEntity(@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId);

@Nonnull
ListEntitiesResult listEntities(
@Nonnull PolarisCallContext callCtx, @Nullable List<PolarisEntityCore> catalogPath);

@Nonnull
ResolvedEntityResult loadResolvedEntityById(
@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId);

@Nonnull
ResolvedEntityResult loadResolvedEntityByName(
@Nonnull PolarisCallContext callCtx,
long entityCatalogId,
long parentId,
@Nonnull String entityName);

@Nonnull
ResolvedEntityResult refreshResolvedEntity(
@Nonnull PolarisCallContext callCtx,
int entityVersion,
int entityGrantRecordsVersion,
long entityCatalogId,
long entityId);

@Nonnull
EntityResult createEntityIfNotExists(
@Nonnull PolarisCallContext callCtx,
@jakarta.annotation.Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisBaseEntity entity);

@Nonnull
EntityResult updateEntityPropertiesIfNotChanged(
@Nonnull PolarisCallContext callCtx,
@jakarta.annotation.Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisBaseEntity entity);

@Nonnull
DropEntityResult dropEntityIfExists(
@Nonnull PolarisCallContext callCtx,
@jakarta.annotation.Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisEntityCore entityToDrop,
@jakarta.annotation.Nullable Map<String, String> cleanupProperties,
boolean cleanup);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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;

import jakarta.annotation.Nonnull;
import java.util.List;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.entity.PolarisEntityId;
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.EntityResult;
import org.apache.polaris.core.persistence.dao.entity.GenerateEntityIdResult;
import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult;

public interface CommonDao {
/**
* Generate a new unique id that can be used by the Polaris client when it needs to create a new
* entity
*
* @param callCtx call context
* @return the newly created id, not expected to fail
*/
@Nonnull
GenerateEntityIdResult generateNewEntityId(@Nonnull PolarisCallContext callCtx);

/**
* Bootstrap the Polaris service, creating the root catalog, root principal, and associated
* service admin role. Will fail if the service has already been bootstrapped.
*
* @param callCtx call context
* @return the result of the bootstrap attempt
*/
@Nonnull
BaseResult bootstrapPolarisService(@Nonnull PolarisCallContext callCtx);

/**
* Purge all metadata associated with the Polaris service, resetting the metastore to the state it
* was in prior to bootstrapping.
*
* <p>*************************** WARNING ************************
*
* <p>This will destroy whatever Polaris metadata exists in the metastore
*
* @param callCtx call context
* @return always success or unexpected error
*/
@Nonnull
BaseResult purge(@Nonnull PolarisCallContext callCtx);

/** For ROOT only */
@Nonnull
ResolvedEntityResult loadResolvedEntityByName(
@Nonnull PolarisCallContext callCtx,
long entityCatalogId,
long parentId,
@Nonnull String entityName);

@Nonnull
ChangeTrackingResult loadEntitiesChangeTracking(
@Nonnull PolarisCallContext callCtx, @Nonnull List<PolarisEntityId> entityIds);

/** For ROOT only */
@Nonnull
ResolvedEntityResult refreshResolvedEntity(
@Nonnull PolarisCallContext callCtx,
int entityVersion,
int entityGrantRecordsVersion,
long entityCatalogId,
long entityId);

/**
* only for NULL_TYPE, looks like this is only used by Tests. We could remove this method if it is
* only used by tests.
*/
@Nonnull
EntityResult loadEntity(@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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;

import jakarta.annotation.Nonnull;
import java.util.Set;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.storage.PolarisCredentialVendor;
import org.apache.polaris.core.storage.PolarisStorageActions;

/** This seems not necessarily to be a DAO, keep it here for future refactor */
public interface CredentialVendorDao {
/**
* Get a sub-scoped credentials for an entity against the provided allowed read and write
* locations.
*
* @param callCtx the polaris call context
* @param catalogId the catalog id
* @param entityId the entity id
* @param allowListOperation whether to allow LIST operation on the allowedReadLocations and
* allowedWriteLocations
* @param allowedReadLocations a set of allowed to read locations
* @param allowedWriteLocations a set of allowed to write locations
* @return an enum map containing the scoped credentials
*/
@Nonnull
PolarisCredentialVendor.ScopedCredentialsResult getSubscopedCredsForEntity(
@Nonnull PolarisCallContext callCtx,
long catalogId,
long entityId,
PolarisEntityType entityType,
boolean allowListOperation,
@Nonnull Set<String> allowedReadLocations,
@Nonnull Set<String> allowedWriteLocations);

/**
* Validate whether the entity has access to the locations with the provided target operations
*
* @param callCtx the polaris call context
* @param catalogId the catalog id
* @param entityId the entity id
* @param actions a set of operation actions: READ/WRITE/LIST/DELETE/ALL
* @param locations a set of locations to verify
* @return a Map of {@code <location, validate result>}, a validate result value looks like this
* <pre>
* {
* "status" : "failure",
* "actions" : {
* "READ" : {
* "message" : "The specified file was not found",
* "status" : "failure"
* },
* "DELETE" : {
* "message" : "One or more objects could not be deleted (Status Code: 200; Error Code: null)",
* "status" : "failure"
* },
* "LIST" : {
* "status" : "success"
* },
* "WRITE" : {
* "message" : "Access Denied (Status Code: 403; Error Code: AccessDenied)",
* "status" : "failure"
* }
* },
* "message" : "Some of the integration checks failed. Check the Polaris documentation for more information."
* }
* </pre>
*/
@Nonnull
PolarisCredentialVendor.ValidateAccessResult validateAccessToLocations(
@Nonnull PolarisCallContext callCtx,
long catalogId,
long entityId,
PolarisEntityType entityType,
@Nonnull Set<PolarisStorageActions> actions,
@Nonnull Set<String> locations);
}
Loading

0 comments on commit 1db510d

Please sign in to comment.