Skip to content

Separate Polaris Entities #1128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest;
import org.apache.polaris.core.persistence.PolarisTestMetaStoreManager;
import org.apache.polaris.core.persistence.transactional.PolarisMetaStoreManagerImpl;
import org.apache.polaris.core.persistence.dao.PolarisDaoManager;
import org.apache.polaris.jpa.models.ModelPrincipalSecrets;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -104,7 +104,11 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
new PolarisEclipseLinkMetaStoreSessionImpl(
store, Mockito.mock(), () -> "realm", null, "polaris", RANDOM_SECRETS);
return new PolarisTestMetaStoreManager(
new PolarisMetaStoreManagerImpl(),
// TODO: Currently, EclipseLinkMetaStoreManager resides within a persistence implementation
// layer, below the DAO layer, and ideally shouldn't directly invoke DAO classes. The change
// is temporarily for refactor verification purposes.
// We should identify a cleaner testing strategy moving forward.
new PolarisDaoManager(),
new PolarisCallContext(
session,
diagServices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
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.PolarisDaoManager;
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 Expand Up @@ -94,7 +94,7 @@ private void initializeForRealm(
realmContext.getRealmIdentifier(),
() -> createMetaStoreSession(backingStore, realmContext, rootCredentialsSet, diagnostics));

PolarisMetaStoreManager metaStoreManager = new PolarisMetaStoreManagerImpl();
PolarisMetaStoreManager metaStoreManager = new PolarisDaoManager();
metaStoreManagerMap.put(realmContext.getRealmIdentifier(), metaStoreManager);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 jakarta.annotation.Nullable;
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.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;

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

@Nonnull
EntityResult updateEntityPropertiesIfNotChanged(
@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity);

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

// TODO this should return a type-specific entity result, e.g., CatalogEntityResult
@Nonnull
EntityResult readEntityByName(@Nonnull PolarisCallContext callCtx, @Nonnull String name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I put in the comment and dev mail list, the type-specific return entity refactor will come later.


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

@Nonnull
ListEntitiesResult listEntities(@Nonnull PolarisCallContext callCtx);

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

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

@Nonnull
ResolvedEntityResult refreshResolvedEntity(
@Nonnull PolarisCallContext callCtx,
int entityVersion,
int entityGrantRecordsVersion,
long entityId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 jakarta.annotation.Nullable;
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;

public interface CatalogRoleDao {
@Nonnull
EntityResult readEntityByName(
@Nonnull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull 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,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisBaseEntity entity);

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

@Nonnull
DropEntityResult dropEntityIfExists(
@Nonnull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisEntityCore entityToDrop,
@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