18
18
*/
19
19
package org .apache .polaris .service .catalog .policy ;
20
20
21
- import jakarta .ws .rs .core .SecurityContext ;
22
21
import java .util .List ;
23
22
import java .util .Map ;
24
23
import java .util .Optional ;
32
31
import org .apache .polaris .core .entity .PolarisEntity ;
33
32
import org .apache .polaris .core .entity .PolarisEntitySubType ;
34
33
import org .apache .polaris .core .entity .PolarisEntityType ;
35
- import org .apache .polaris .core .persistence .PolarisEntityManager ;
36
34
import org .apache .polaris .core .persistence .PolarisMetaStoreManager ;
37
35
import org .apache .polaris .core .persistence .PolarisResolvedPathWrapper ;
38
36
import org .apache .polaris .core .persistence .dao .entity .DropEntityResult ;
42
40
import org .apache .polaris .core .policy .exceptions .NoSuchPolicyException ;
43
41
import org .apache .polaris .core .policy .exceptions .PolicyVersionMismatchException ;
44
42
import org .apache .polaris .core .policy .validator .PolicyValidators ;
45
- import org .apache .polaris .service .task .TaskExecutor ;
46
43
import org .apache .polaris .service .types .Policy ;
47
44
import org .apache .polaris .service .types .PolicyIdentifier ;
48
45
import org .slf4j .Logger ;
51
48
public class PolicyCatalog {
52
49
private static final Logger LOGGER = LoggerFactory .getLogger (PolicyCatalog .class );
53
50
54
- private final PolarisEntityManager entityManager ;
55
51
private final CallContext callContext ;
56
52
private final PolarisResolutionManifestCatalogView resolvedEntityView ;
57
53
private final CatalogEntity catalogEntity ;
58
- private final TaskExecutor taskExecutor ;
59
- private final SecurityContext securityContext ;
60
- private final String catalogName ;
61
54
private long catalogId = -1 ;
62
55
private PolarisMetaStoreManager metaStoreManager ;
63
56
64
57
public PolicyCatalog (
65
- PolarisEntityManager entityManager ,
66
58
PolarisMetaStoreManager metaStoreManager ,
67
59
CallContext callContext ,
68
- PolarisResolutionManifestCatalogView resolvedEntityView ,
69
- SecurityContext securityContext ,
70
- TaskExecutor taskExecutor ) {
71
- // TODO: clean out unecessary fields
72
- this .entityManager = entityManager ;
60
+ PolarisResolutionManifestCatalogView resolvedEntityView ) {
73
61
this .callContext = callContext ;
74
62
this .resolvedEntityView = resolvedEntityView ;
75
63
this .catalogEntity =
76
64
CatalogEntity .of (resolvedEntityView .getResolvedReferenceCatalogEntity ().getRawLeafEntity ());
77
- this .securityContext = securityContext ;
78
- this .taskExecutor = taskExecutor ;
79
65
this .catalogId = catalogEntity .getId ();
80
- this .catalogName = catalogEntity .getName ();
81
66
this .metaStoreManager = metaStoreManager ;
82
67
}
83
68
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
+
84
103
public List <PolicyIdentifier > listPolicies (Namespace namespace , PolicyType policyType ) {
85
104
PolarisResolvedPathWrapper resolvedEntities = resolvedEntityView .getResolvedPath (namespace );
86
105
if (resolvedEntities == null ) {
@@ -120,60 +139,13 @@ public List<PolicyIdentifier> listPolicies(Namespace namespace, PolicyType polic
120
139
.toList ();
121
140
}
122
141
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
-
165
142
public Policy loadPolicy (PolicyIdentifier policyIdentifier ) {
166
143
PolarisResolvedPathWrapper resolvedEntities =
167
144
resolvedEntityView .getPassthroughResolvedPath (
168
145
policyIdentifier , PolarisEntityType .POLICY , PolarisEntitySubType .NULL_SUBTYPE );
169
146
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 ());
177
149
178
150
if (policy == null ) {
179
151
throw new NoSuchPolicyException (String .format ("Policy does not exist: %s" , policyIdentifier ));
@@ -190,13 +162,8 @@ public Policy updatePolicy(
190
162
resolvedEntityView .getPassthroughResolvedPath (
191
163
policyIdentifier , PolarisEntityType .POLICY , PolarisEntitySubType .NULL_SUBTYPE );
192
164
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 ());
200
167
201
168
if (policy == null ) {
202
169
throw new NoSuchPolicyException (String .format ("Policy does not exist: %s" , policyIdentifier ));
@@ -265,7 +232,6 @@ private PolicyEntity createPolicyEntity(PolicyIdentifier identifier, PolarisEnti
265
232
266
233
List <PolarisEntity > catalogPath = resolvedParent .getRawFullPath ();
267
234
if (entity .getParentId () <= 0 ) {
268
- // TODO: Validate catalogPath size is at least 1 for catalog entity?
269
235
entity =
270
236
new PolarisEntity .Builder (entity )
271
237
.setParentId (resolvedParent .getRawLeafEntity ().getId ())
0 commit comments