Skip to content

Commit 553cb06

Browse files
authored
Service: Add Events for PolarisServiceImpl APIs (#2482)
1 parent 72e02c9 commit 553cb06

File tree

11 files changed

+801
-66
lines changed

11 files changed

+801
-66
lines changed

runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisCatalogsEventServiceDelegator.java

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,52 @@
2626
import jakarta.ws.rs.core.Response;
2727
import jakarta.ws.rs.core.SecurityContext;
2828
import org.apache.polaris.core.admin.model.AddGrantRequest;
29+
import org.apache.polaris.core.admin.model.Catalog;
30+
import org.apache.polaris.core.admin.model.CatalogRole;
2931
import org.apache.polaris.core.admin.model.CreateCatalogRequest;
3032
import org.apache.polaris.core.admin.model.CreateCatalogRoleRequest;
3133
import org.apache.polaris.core.admin.model.RevokeGrantRequest;
3234
import org.apache.polaris.core.admin.model.UpdateCatalogRequest;
3335
import org.apache.polaris.core.admin.model.UpdateCatalogRoleRequest;
3436
import org.apache.polaris.core.context.RealmContext;
3537
import org.apache.polaris.service.admin.api.PolarisCatalogsApiService;
38+
import org.apache.polaris.service.events.CatalogsServiceEvents;
39+
import org.apache.polaris.service.events.listeners.PolarisEventListener;
3640

3741
@Decorator
3842
@Priority(1000)
3943
public class PolarisCatalogsEventServiceDelegator implements PolarisCatalogsApiService {
4044

4145
@Inject @Delegate PolarisCatalogsApiService delegate;
46+
@Inject PolarisEventListener polarisEventListener;
4247

4348
@Override
4449
public Response createCatalog(
4550
CreateCatalogRequest request, RealmContext realmContext, SecurityContext securityContext) {
51+
// TODO: After changing the API response, we should change this to emit the corresponding event.
4652
return delegate.createCatalog(request, realmContext, securityContext);
4753
}
4854

4955
@Override
5056
public Response deleteCatalog(
5157
String catalogName, RealmContext realmContext, SecurityContext securityContext) {
52-
return delegate.deleteCatalog(catalogName, realmContext, securityContext);
58+
polarisEventListener.onBeforeDeleteCatalog(
59+
new CatalogsServiceEvents.BeforeDeleteCatalogEvent(catalogName));
60+
Response resp = delegate.deleteCatalog(catalogName, realmContext, securityContext);
61+
polarisEventListener.onAfterDeleteCatalog(
62+
new CatalogsServiceEvents.AfterDeleteCatalogEvent(catalogName));
63+
return resp;
5364
}
5465

5566
@Override
5667
public Response getCatalog(
5768
String catalogName, RealmContext realmContext, SecurityContext securityContext) {
58-
return delegate.getCatalog(catalogName, realmContext, securityContext);
69+
polarisEventListener.onBeforeGetCatalog(
70+
new CatalogsServiceEvents.BeforeGetCatalogEvent(catalogName));
71+
Response resp = delegate.getCatalog(catalogName, realmContext, securityContext);
72+
polarisEventListener.onAfterGetCatalog(
73+
new CatalogsServiceEvents.AfterGetCatalogEvent((Catalog) resp.getEntity()));
74+
return resp;
5975
}
6076

6177
@Override
@@ -64,12 +80,21 @@ public Response updateCatalog(
6480
UpdateCatalogRequest updateRequest,
6581
RealmContext realmContext,
6682
SecurityContext securityContext) {
67-
return delegate.updateCatalog(catalogName, updateRequest, realmContext, securityContext);
83+
polarisEventListener.onBeforeUpdateCatalog(
84+
new CatalogsServiceEvents.BeforeUpdateCatalogEvent(catalogName, updateRequest));
85+
Response resp =
86+
delegate.updateCatalog(catalogName, updateRequest, realmContext, securityContext);
87+
polarisEventListener.onAfterUpdateCatalog(
88+
new CatalogsServiceEvents.AfterUpdateCatalogEvent((Catalog) resp.getEntity()));
89+
return resp;
6890
}
6991

7092
@Override
7193
public Response listCatalogs(RealmContext realmContext, SecurityContext securityContext) {
72-
return delegate.listCatalogs(realmContext, securityContext);
94+
polarisEventListener.onBeforeListCatalog(new CatalogsServiceEvents.BeforeListCatalogEvent());
95+
Response resp = delegate.listCatalogs(realmContext, securityContext);
96+
polarisEventListener.onAfterListCatalog(new CatalogsServiceEvents.AfterListCatalogEvent());
97+
return resp;
7398
}
7499

75100
@Override
@@ -78,6 +103,7 @@ public Response createCatalogRole(
78103
CreateCatalogRoleRequest request,
79104
RealmContext realmContext,
80105
SecurityContext securityContext) {
106+
// TODO: After changing the API response, we should change this to emit the corresponding event.
81107
return delegate.createCatalogRole(catalogName, request, realmContext, securityContext);
82108
}
83109

@@ -87,7 +113,13 @@ public Response deleteCatalogRole(
87113
String catalogRoleName,
88114
RealmContext realmContext,
89115
SecurityContext securityContext) {
90-
return delegate.deleteCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
116+
polarisEventListener.onBeforeDeleteCatalogRole(
117+
new CatalogsServiceEvents.BeforeDeleteCatalogRoleEvent(catalogName, catalogRoleName));
118+
Response resp =
119+
delegate.deleteCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
120+
polarisEventListener.onAfterDeleteCatalogRole(
121+
new CatalogsServiceEvents.AfterDeleteCatalogRoleEvent(catalogName, catalogRoleName));
122+
return resp;
91123
}
92124

93125
@Override
@@ -96,7 +128,14 @@ public Response getCatalogRole(
96128
String catalogRoleName,
97129
RealmContext realmContext,
98130
SecurityContext securityContext) {
99-
return delegate.getCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
131+
polarisEventListener.onBeforeGetCatalogRole(
132+
new CatalogsServiceEvents.BeforeGetCatalogRoleEvent(catalogName, catalogRoleName));
133+
Response resp =
134+
delegate.getCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
135+
polarisEventListener.onAfterGetCatalogRole(
136+
new CatalogsServiceEvents.AfterGetCatalogRoleEvent(
137+
catalogName, (CatalogRole) resp.getEntity()));
138+
return resp;
100139
}
101140

102141
@Override
@@ -106,14 +145,27 @@ public Response updateCatalogRole(
106145
UpdateCatalogRoleRequest updateRequest,
107146
RealmContext realmContext,
108147
SecurityContext securityContext) {
109-
return delegate.updateCatalogRole(
110-
catalogName, catalogRoleName, updateRequest, realmContext, securityContext);
148+
polarisEventListener.onBeforeUpdateCatalogRole(
149+
new CatalogsServiceEvents.BeforeUpdateCatalogRoleEvent(
150+
catalogName, catalogRoleName, updateRequest));
151+
Response resp =
152+
delegate.updateCatalogRole(
153+
catalogName, catalogRoleName, updateRequest, realmContext, securityContext);
154+
polarisEventListener.onAfterUpdateCatalogRole(
155+
new CatalogsServiceEvents.AfterUpdateCatalogRoleEvent(
156+
catalogName, (CatalogRole) resp.getEntity()));
157+
return resp;
111158
}
112159

113160
@Override
114161
public Response listCatalogRoles(
115162
String catalogName, RealmContext realmContext, SecurityContext securityContext) {
116-
return delegate.listCatalogRoles(catalogName, realmContext, securityContext);
163+
polarisEventListener.onAfterListCatalogRoles(
164+
new CatalogsServiceEvents.AfterListCatalogRolesEvent(catalogName));
165+
Response resp = delegate.listCatalogRoles(catalogName, realmContext, securityContext);
166+
polarisEventListener.onBeforeListCatalogRoles(
167+
new CatalogsServiceEvents.BeforeListCatalogRolesEvent(catalogName));
168+
return resp;
117169
}
118170

119171
@Override
@@ -123,6 +175,7 @@ public Response addGrantToCatalogRole(
123175
AddGrantRequest grantRequest,
124176
RealmContext realmContext,
125177
SecurityContext securityContext) {
178+
// TODO: After changing the API response, we should change this to emit the corresponding event.
126179
return delegate.addGrantToCatalogRole(
127180
catalogName, catalogRoleName, grantRequest, realmContext, securityContext);
128181
}
@@ -135,6 +188,7 @@ public Response revokeGrantFromCatalogRole(
135188
RevokeGrantRequest grantRequest,
136189
RealmContext realmContext,
137190
SecurityContext securityContext) {
191+
// TODO: After changing the API response, we should change this to emit the corresponding event.
138192
return delegate.revokeGrantFromCatalogRole(
139193
catalogName, catalogRoleName, cascade, grantRequest, realmContext, securityContext);
140194
}
@@ -145,8 +199,16 @@ public Response listAssigneePrincipalRolesForCatalogRole(
145199
String catalogRoleName,
146200
RealmContext realmContext,
147201
SecurityContext securityContext) {
148-
return delegate.listAssigneePrincipalRolesForCatalogRole(
149-
catalogName, catalogRoleName, realmContext, securityContext);
202+
polarisEventListener.onBeforeListAssigneePrincipalRolesForCatalogRole(
203+
new CatalogsServiceEvents.BeforeListAssigneePrincipalRolesForCatalogRoleEvent(
204+
catalogName, catalogRoleName));
205+
Response resp =
206+
delegate.listAssigneePrincipalRolesForCatalogRole(
207+
catalogName, catalogRoleName, realmContext, securityContext);
208+
polarisEventListener.onAfterListAssigneePrincipalRolesForCatalogRole(
209+
new CatalogsServiceEvents.AfterListAssigneePrincipalRolesForCatalogRoleEvent(
210+
catalogName, catalogRoleName));
211+
return resp;
150212
}
151213

152214
@Override
@@ -155,7 +217,14 @@ public Response listGrantsForCatalogRole(
155217
String catalogRoleName,
156218
RealmContext realmContext,
157219
SecurityContext securityContext) {
158-
return delegate.listGrantsForCatalogRole(
159-
catalogName, catalogRoleName, realmContext, securityContext);
220+
polarisEventListener.onBeforeListGrantsForCatalogRole(
221+
new CatalogsServiceEvents.BeforeListGrantsForCatalogRoleEvent(
222+
catalogName, catalogRoleName));
223+
Response resp =
224+
delegate.listGrantsForCatalogRole(
225+
catalogName, catalogRoleName, realmContext, securityContext);
226+
polarisEventListener.onAfterListGrantsForCatalogRole(
227+
new CatalogsServiceEvents.AfterListGrantsForCatalogRoleEvent(catalogName, catalogRoleName));
228+
return resp;
160229
}
161230
}

runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisPrincipalRolesEventServiceDelegator.java

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,50 @@
2727
import jakarta.ws.rs.core.SecurityContext;
2828
import org.apache.polaris.core.admin.model.CreatePrincipalRoleRequest;
2929
import org.apache.polaris.core.admin.model.GrantCatalogRoleRequest;
30+
import org.apache.polaris.core.admin.model.PrincipalRole;
3031
import org.apache.polaris.core.admin.model.UpdatePrincipalRoleRequest;
3132
import org.apache.polaris.core.context.RealmContext;
3233
import org.apache.polaris.service.admin.api.PolarisPrincipalRolesApiService;
34+
import org.apache.polaris.service.events.PrincipalRolesServiceEvents;
35+
import org.apache.polaris.service.events.listeners.PolarisEventListener;
3336

3437
@Decorator
3538
@Priority(1000)
3639
public class PolarisPrincipalRolesEventServiceDelegator implements PolarisPrincipalRolesApiService {
3740

3841
@Inject @Delegate PolarisPrincipalRolesApiService delegate;
42+
@Inject PolarisEventListener polarisEventListener;
3943

4044
@Override
4145
public Response createPrincipalRole(
4246
CreatePrincipalRoleRequest request,
4347
RealmContext realmContext,
4448
SecurityContext securityContext) {
49+
// TODO: After changing the API response, we should change this to emit the corresponding event.
4550
return delegate.createPrincipalRole(request, realmContext, securityContext);
4651
}
4752

4853
@Override
4954
public Response deletePrincipalRole(
5055
String principalRoleName, RealmContext realmContext, SecurityContext securityContext) {
51-
return delegate.deletePrincipalRole(principalRoleName, realmContext, securityContext);
56+
polarisEventListener.onBeforeDeletePrincipalRole(
57+
new PrincipalRolesServiceEvents.BeforeDeletePrincipalRoleEvent(principalRoleName));
58+
Response resp = delegate.deletePrincipalRole(principalRoleName, realmContext, securityContext);
59+
polarisEventListener.onAfterDeletePrincipalRole(
60+
new PrincipalRolesServiceEvents.AfterDeletePrincipalRoleEvent(principalRoleName));
61+
return resp;
5262
}
5363

5464
@Override
5565
public Response getPrincipalRole(
5666
String principalRoleName, RealmContext realmContext, SecurityContext securityContext) {
57-
return delegate.getPrincipalRole(principalRoleName, realmContext, securityContext);
67+
polarisEventListener.onBeforeGetPrincipalRole(
68+
new PrincipalRolesServiceEvents.BeforeGetPrincipalRoleEvent(principalRoleName));
69+
Response resp = delegate.getPrincipalRole(principalRoleName, realmContext, securityContext);
70+
polarisEventListener.onAfterGetPrincipalRole(
71+
new PrincipalRolesServiceEvents.AfterGetPrincipalRoleEvent(
72+
(PrincipalRole) resp.getEntity()));
73+
return resp;
5874
}
5975

6076
@Override
@@ -63,13 +79,26 @@ public Response updatePrincipalRole(
6379
UpdatePrincipalRoleRequest updateRequest,
6480
RealmContext realmContext,
6581
SecurityContext securityContext) {
66-
return delegate.updatePrincipalRole(
67-
principalRoleName, updateRequest, realmContext, securityContext);
82+
polarisEventListener.onBeforeUpdatePrincipalRole(
83+
new PrincipalRolesServiceEvents.BeforeUpdatePrincipalRoleEvent(
84+
principalRoleName, updateRequest));
85+
Response resp =
86+
delegate.updatePrincipalRole(
87+
principalRoleName, updateRequest, realmContext, securityContext);
88+
polarisEventListener.onAfterUpdatePrincipalRole(
89+
new PrincipalRolesServiceEvents.AfterUpdatePrincipalRoleEvent(
90+
(PrincipalRole) resp.getEntity()));
91+
return resp;
6892
}
6993

7094
@Override
7195
public Response listPrincipalRoles(RealmContext realmContext, SecurityContext securityContext) {
72-
return delegate.listPrincipalRoles(realmContext, securityContext);
96+
polarisEventListener.onBeforeListPrincipalRoles(
97+
new PrincipalRolesServiceEvents.BeforeListPrincipalRolesEvent());
98+
Response resp = delegate.listPrincipalRoles(realmContext, securityContext);
99+
polarisEventListener.onAfterListPrincipalRoles(
100+
new PrincipalRolesServiceEvents.AfterListPrincipalRolesEvent());
101+
return resp;
73102
}
74103

75104
@Override
@@ -79,8 +108,16 @@ public Response assignCatalogRoleToPrincipalRole(
79108
GrantCatalogRoleRequest request,
80109
RealmContext realmContext,
81110
SecurityContext securityContext) {
82-
return delegate.assignCatalogRoleToPrincipalRole(
83-
principalRoleName, catalogName, request, realmContext, securityContext);
111+
polarisEventListener.onBeforeAssignCatalogRoleToPrincipalRole(
112+
new PrincipalRolesServiceEvents.BeforeAssignCatalogRoleToPrincipalRoleEvent(
113+
principalRoleName, catalogName, request.getCatalogRole().getName()));
114+
Response resp =
115+
delegate.assignCatalogRoleToPrincipalRole(
116+
principalRoleName, catalogName, request, realmContext, securityContext);
117+
polarisEventListener.onAfterAssignCatalogRoleToPrincipalRole(
118+
new PrincipalRolesServiceEvents.AfterAssignCatalogRoleToPrincipalRoleEvent(
119+
principalRoleName, catalogName, request.getCatalogRole().getName()));
120+
return resp;
84121
}
85122

86123
@Override
@@ -90,15 +127,31 @@ public Response revokeCatalogRoleFromPrincipalRole(
90127
String catalogRoleName,
91128
RealmContext realmContext,
92129
SecurityContext securityContext) {
93-
return delegate.revokeCatalogRoleFromPrincipalRole(
94-
principalRoleName, catalogName, catalogRoleName, realmContext, securityContext);
130+
polarisEventListener.onBeforeRevokeCatalogRoleFromPrincipalRole(
131+
new PrincipalRolesServiceEvents.BeforeRevokeCatalogRoleFromPrincipalRoleEvent(
132+
principalRoleName, catalogName, catalogRoleName));
133+
Response resp =
134+
delegate.revokeCatalogRoleFromPrincipalRole(
135+
principalRoleName, catalogName, catalogRoleName, realmContext, securityContext);
136+
polarisEventListener.onAfterRevokeCatalogRoleFromPrincipalRole(
137+
new PrincipalRolesServiceEvents.AfterRevokeCatalogRoleFromPrincipalRoleEvent(
138+
principalRoleName, catalogName, catalogRoleName));
139+
return resp;
95140
}
96141

97142
@Override
98143
public Response listAssigneePrincipalsForPrincipalRole(
99144
String principalRoleName, RealmContext realmContext, SecurityContext securityContext) {
100-
return delegate.listAssigneePrincipalsForPrincipalRole(
101-
principalRoleName, realmContext, securityContext);
145+
polarisEventListener.onBeforeListAssigneePrincipalsForPrincipalRole(
146+
new PrincipalRolesServiceEvents.BeforeListAssigneePrincipalsForPrincipalRoleEvent(
147+
principalRoleName));
148+
Response resp =
149+
delegate.listAssigneePrincipalsForPrincipalRole(
150+
principalRoleName, realmContext, securityContext);
151+
polarisEventListener.onAfterListAssigneePrincipalsForPrincipalRole(
152+
new PrincipalRolesServiceEvents.AfterListAssigneePrincipalsForPrincipalRoleEvent(
153+
principalRoleName));
154+
return resp;
102155
}
103156

104157
@Override
@@ -107,7 +160,15 @@ public Response listCatalogRolesForPrincipalRole(
107160
String catalogName,
108161
RealmContext realmContext,
109162
SecurityContext securityContext) {
110-
return delegate.listCatalogRolesForPrincipalRole(
111-
principalRoleName, catalogName, realmContext, securityContext);
163+
polarisEventListener.onBeforeListCatalogRolesForPrincipalRole(
164+
new PrincipalRolesServiceEvents.BeforeListCatalogRolesForPrincipalRoleEvent(
165+
principalRoleName, catalogName));
166+
Response resp =
167+
delegate.listCatalogRolesForPrincipalRole(
168+
principalRoleName, catalogName, realmContext, securityContext);
169+
polarisEventListener.onAfterListCatalogRolesForPrincipalRole(
170+
new PrincipalRolesServiceEvents.AfterListCatalogRolesForPrincipalRoleEvent(
171+
principalRoleName, catalogName));
172+
return resp;
112173
}
113174
}

0 commit comments

Comments
 (0)