Skip to content

Commit fb98809

Browse files
committed
Fix test and catalog
1 parent f69af88 commit fb98809

File tree

2 files changed

+40
-81
lines changed

2 files changed

+40
-81
lines changed

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolicyCatalogTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,7 @@ public void before(TestInfo testInfo) {
247247
isA(AwsStorageConfigurationInfo.class)))
248248
.thenReturn((PolarisStorageIntegration) storageIntegration);
249249

250-
this.policyCatalog =
251-
new PolicyCatalog(
252-
entityManager,
253-
metaStoreManager,
254-
callContext,
255-
passthroughView,
256-
securityContext,
257-
taskExecutor);
250+
this.policyCatalog = new PolicyCatalog(metaStoreManager, callContext, passthroughView);
258251
this.icebergCatalog =
259252
new IcebergCatalog(
260253
entityManager,

service/common/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalog.java

Lines changed: 39 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.polaris.service.catalog.policy;
2020

21-
import jakarta.ws.rs.core.SecurityContext;
2221
import java.util.List;
2322
import java.util.Map;
2423
import java.util.Optional;
@@ -32,7 +31,6 @@
3231
import org.apache.polaris.core.entity.PolarisEntity;
3332
import org.apache.polaris.core.entity.PolarisEntitySubType;
3433
import org.apache.polaris.core.entity.PolarisEntityType;
35-
import org.apache.polaris.core.persistence.PolarisEntityManager;
3634
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
3735
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
3836
import org.apache.polaris.core.persistence.dao.entity.DropEntityResult;
@@ -42,7 +40,6 @@
4240
import org.apache.polaris.core.policy.exceptions.NoSuchPolicyException;
4341
import org.apache.polaris.core.policy.exceptions.PolicyVersionMismatchException;
4442
import org.apache.polaris.core.policy.validator.PolicyValidators;
45-
import org.apache.polaris.service.task.TaskExecutor;
4643
import org.apache.polaris.service.types.Policy;
4744
import org.apache.polaris.service.types.PolicyIdentifier;
4845
import org.slf4j.Logger;
@@ -51,36 +48,58 @@
5148
public class PolicyCatalog {
5249
private static final Logger LOGGER = LoggerFactory.getLogger(PolicyCatalog.class);
5350

54-
private final PolarisEntityManager entityManager;
5551
private final CallContext callContext;
5652
private final PolarisResolutionManifestCatalogView resolvedEntityView;
5753
private final CatalogEntity catalogEntity;
58-
private final TaskExecutor taskExecutor;
59-
private final SecurityContext securityContext;
60-
private final String catalogName;
6154
private long catalogId = -1;
6255
private PolarisMetaStoreManager metaStoreManager;
6356

6457
public PolicyCatalog(
65-
PolarisEntityManager entityManager,
6658
PolarisMetaStoreManager metaStoreManager,
6759
CallContext callContext,
68-
PolarisResolutionManifestCatalogView resolvedEntityView,
69-
SecurityContext securityContext,
70-
TaskExecutor taskExecutor) {
71-
// TODO: clean out unecessary fields
72-
this.entityManager = entityManager;
60+
PolarisResolutionManifestCatalogView resolvedEntityView) {
7361
this.callContext = callContext;
7462
this.resolvedEntityView = resolvedEntityView;
7563
this.catalogEntity =
7664
CatalogEntity.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());
77-
this.securityContext = securityContext;
78-
this.taskExecutor = taskExecutor;
7965
this.catalogId = catalogEntity.getId();
80-
this.catalogName = catalogEntity.getName();
8166
this.metaStoreManager = metaStoreManager;
8267
}
8368

69+
public Policy createPolicy(
70+
PolicyIdentifier policyIdentifier, String type, String description, String content) {
71+
PolarisResolvedPathWrapper resolvedPolicyEntities =
72+
resolvedEntityView.getPassthroughResolvedPath(
73+
policyIdentifier, PolarisEntityType.POLICY, PolarisEntitySubType.NULL_SUBTYPE);
74+
75+
PolicyEntity entity =
76+
PolicyEntity.of(
77+
resolvedPolicyEntities == null ? null : resolvedPolicyEntities.getRawLeafEntity());
78+
79+
if (entity == null) {
80+
PolicyType policyType = PolicyType.fromName(type);
81+
if (policyType == null) {
82+
throw new BadRequestException("Unknown policy type: %s", type);
83+
}
84+
85+
entity =
86+
new PolicyEntity.Builder(
87+
policyIdentifier.namespace(), policyIdentifier.name(), policyType)
88+
.setCatalogId(catalogId)
89+
.setDescription(description)
90+
.setContent(content)
91+
.setId(getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId())
92+
.build();
93+
94+
PolicyValidators.validate(entity);
95+
96+
} else {
97+
throw new AlreadyExistsException("Policy already exists %s", policyIdentifier);
98+
}
99+
100+
return constructPolicy(createPolicyEntity(policyIdentifier, entity));
101+
}
102+
84103
public List<PolicyIdentifier> listPolicies(Namespace namespace, PolicyType policyType) {
85104
PolarisResolvedPathWrapper resolvedEntities = resolvedEntityView.getResolvedPath(namespace);
86105
if (resolvedEntities == null) {
@@ -120,60 +139,13 @@ public List<PolicyIdentifier> listPolicies(Namespace namespace, PolicyType polic
120139
.toList();
121140
}
122141

123-
public Policy createPolicy(
124-
PolicyIdentifier policyIdentifier, String type, String description, String content) {
125-
PolarisResolvedPathWrapper resolvedParent =
126-
resolvedEntityView.getResolvedPath(policyIdentifier.namespace());
127-
if (resolvedParent == null) {
128-
// Illegal state because the namespace should've already been in the static resolution set.
129-
throw new IllegalStateException(
130-
String.format(
131-
"Failed to fetch resolved parent for PolicyIdentifier '%s'", policyIdentifier));
132-
}
133-
PolarisResolvedPathWrapper resolvedPolicyEntities =
134-
resolvedEntityView.getPassthroughResolvedPath(
135-
policyIdentifier, PolarisEntityType.POLICY, PolarisEntitySubType.NULL_SUBTYPE);
136-
137-
PolicyEntity entity =
138-
PolicyEntity.of(
139-
resolvedPolicyEntities == null ? null : resolvedPolicyEntities.getRawLeafEntity());
140-
141-
if (entity == null) {
142-
PolicyType policyType = PolicyType.fromName(type);
143-
if (policyType == null) {
144-
throw new BadRequestException("Unknown policy type: %s", type);
145-
}
146-
147-
entity =
148-
new PolicyEntity.Builder(
149-
policyIdentifier.namespace(), policyIdentifier.name(), policyType)
150-
.setCatalogId(catalogEntity.getId())
151-
.setDescription(description)
152-
.setContent(content)
153-
.setId(getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId())
154-
.build();
155-
156-
PolicyValidators.validate(entity);
157-
158-
} else {
159-
throw new AlreadyExistsException("Policy already exists %s", policyIdentifier);
160-
}
161-
162-
return constructPolicy(createPolicyEntity(policyIdentifier, entity));
163-
}
164-
165142
public Policy loadPolicy(PolicyIdentifier policyIdentifier) {
166143
PolarisResolvedPathWrapper resolvedEntities =
167144
resolvedEntityView.getPassthroughResolvedPath(
168145
policyIdentifier, PolarisEntityType.POLICY, PolarisEntitySubType.NULL_SUBTYPE);
169146

170-
PolicyEntity policy = null;
171-
172-
if (resolvedEntities != null) {
173-
if (resolvedEntities.getRawLeafEntity().getType() == PolarisEntityType.POLICY) {
174-
policy = PolicyEntity.of(resolvedEntities.getRawLeafEntity());
175-
}
176-
}
147+
PolicyEntity policy =
148+
PolicyEntity.of(resolvedEntities == null ? null : resolvedEntities.getRawLeafEntity());
177149

178150
if (policy == null) {
179151
throw new NoSuchPolicyException(String.format("Policy does not exist: %s", policyIdentifier));
@@ -190,13 +162,8 @@ public Policy updatePolicy(
190162
resolvedEntityView.getPassthroughResolvedPath(
191163
policyIdentifier, PolarisEntityType.POLICY, PolarisEntitySubType.NULL_SUBTYPE);
192164

193-
PolicyEntity policy = null;
194-
195-
if (resolvedEntities != null) {
196-
if (resolvedEntities.getRawLeafEntity().getType() == PolarisEntityType.POLICY) {
197-
policy = PolicyEntity.of(resolvedEntities.getRawLeafEntity());
198-
}
199-
}
165+
PolicyEntity policy =
166+
PolicyEntity.of(resolvedEntities == null ? null : resolvedEntities.getRawLeafEntity());
200167

201168
if (policy == null) {
202169
throw new NoSuchPolicyException(String.format("Policy does not exist: %s", policyIdentifier));
@@ -265,7 +232,6 @@ private PolicyEntity createPolicyEntity(PolicyIdentifier identifier, PolarisEnti
265232

266233
List<PolarisEntity> catalogPath = resolvedParent.getRawFullPath();
267234
if (entity.getParentId() <= 0) {
268-
// TODO: Validate catalogPath size is at least 1 for catalog entity?
269235
entity =
270236
new PolarisEntity.Builder(entity)
271237
.setParentId(resolvedParent.getRawLeafEntity().getId())

0 commit comments

Comments
 (0)