Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,52 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.SecurityContext;
import org.apache.polaris.core.admin.model.AddGrantRequest;
import org.apache.polaris.core.admin.model.Catalog;
import org.apache.polaris.core.admin.model.CatalogRole;
import org.apache.polaris.core.admin.model.CreateCatalogRequest;
import org.apache.polaris.core.admin.model.CreateCatalogRoleRequest;
import org.apache.polaris.core.admin.model.RevokeGrantRequest;
import org.apache.polaris.core.admin.model.UpdateCatalogRequest;
import org.apache.polaris.core.admin.model.UpdateCatalogRoleRequest;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.service.admin.api.PolarisCatalogsApiService;
import org.apache.polaris.service.events.CatalogsServiceEvents;
import org.apache.polaris.service.events.listeners.PolarisEventListener;

@Decorator
@Priority(1000)
public class PolarisCatalogsEventServiceDelegator implements PolarisCatalogsApiService {

@Inject @Delegate PolarisCatalogsApiService delegate;
@Inject PolarisEventListener polarisEventListener;

@Override
public Response createCatalog(
CreateCatalogRequest request, RealmContext realmContext, SecurityContext securityContext) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove instrumentation from #1844 for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in next revision.

// TODO: After changing the API response, we should change this to emit the corresponding event.
return delegate.createCatalog(request, realmContext, securityContext);
}

@Override
public Response deleteCatalog(
String catalogName, RealmContext realmContext, SecurityContext securityContext) {
return delegate.deleteCatalog(catalogName, realmContext, securityContext);
polarisEventListener.onBeforeDeleteCatalog(
new CatalogsServiceEvents.BeforeDeleteCatalogEvent(catalogName));
Response resp = delegate.deleteCatalog(catalogName, realmContext, securityContext);
polarisEventListener.onAfterDeleteCatalog(
new CatalogsServiceEvents.AfterDeleteCatalogEvent(catalogName));
return resp;
}

@Override
public Response getCatalog(
String catalogName, RealmContext realmContext, SecurityContext securityContext) {
return delegate.getCatalog(catalogName, realmContext, securityContext);
polarisEventListener.onBeforeGetCatalog(
new CatalogsServiceEvents.BeforeGetCatalogEvent(catalogName));
Response resp = delegate.getCatalog(catalogName, realmContext, securityContext);
polarisEventListener.onAfterGetCatalog(
new CatalogsServiceEvents.AfterGetCatalogEvent((Catalog) resp.getEntity()));
return resp;
}

@Override
Expand All @@ -64,12 +80,21 @@ public Response updateCatalog(
UpdateCatalogRequest updateRequest,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.updateCatalog(catalogName, updateRequest, realmContext, securityContext);
polarisEventListener.onBeforeUpdateCatalog(
new CatalogsServiceEvents.BeforeUpdateCatalogEvent(catalogName, updateRequest));
Response resp =
delegate.updateCatalog(catalogName, updateRequest, realmContext, securityContext);
polarisEventListener.onAfterUpdateCatalog(
new CatalogsServiceEvents.AfterUpdateCatalogEvent((Catalog) resp.getEntity()));
return resp;
}

@Override
public Response listCatalogs(RealmContext realmContext, SecurityContext securityContext) {
return delegate.listCatalogs(realmContext, securityContext);
polarisEventListener.onBeforeListCatalog(new CatalogsServiceEvents.BeforeListCatalogEvent());
Response resp = delegate.listCatalogs(realmContext, securityContext);
polarisEventListener.onAfterListCatalog(new CatalogsServiceEvents.AfterListCatalogEvent());
return resp;
}

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

Expand All @@ -87,7 +113,13 @@ public Response deleteCatalogRole(
String catalogRoleName,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.deleteCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onBeforeDeleteCatalogRole(
new CatalogsServiceEvents.BeforeDeleteCatalogRoleEvent(catalogName, catalogRoleName));
Response resp =
delegate.deleteCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onAfterDeleteCatalogRole(
new CatalogsServiceEvents.AfterDeleteCatalogRoleEvent(catalogName, catalogRoleName));
return resp;
}

@Override
Expand All @@ -96,7 +128,14 @@ public Response getCatalogRole(
String catalogRoleName,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.getCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onBeforeGetCatalogRole(
new CatalogsServiceEvents.BeforeGetCatalogRoleEvent(catalogName, catalogRoleName));
Response resp =
delegate.getCatalogRole(catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onAfterGetCatalogRole(
new CatalogsServiceEvents.AfterGetCatalogRoleEvent(
catalogName, (CatalogRole) resp.getEntity()));
return resp;
}

@Override
Expand All @@ -106,14 +145,27 @@ public Response updateCatalogRole(
UpdateCatalogRoleRequest updateRequest,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.updateCatalogRole(
catalogName, catalogRoleName, updateRequest, realmContext, securityContext);
polarisEventListener.onBeforeUpdateCatalogRole(
new CatalogsServiceEvents.BeforeUpdateCatalogRoleEvent(
catalogName, catalogRoleName, updateRequest));
Response resp =
delegate.updateCatalogRole(
catalogName, catalogRoleName, updateRequest, realmContext, securityContext);
polarisEventListener.onAfterUpdateCatalogRole(
new CatalogsServiceEvents.AfterUpdateCatalogRoleEvent(
catalogName, (CatalogRole) resp.getEntity()));
return resp;
}

@Override
public Response listCatalogRoles(
String catalogName, RealmContext realmContext, SecurityContext securityContext) {
return delegate.listCatalogRoles(catalogName, realmContext, securityContext);
polarisEventListener.onAfterListCatalogRoles(
new CatalogsServiceEvents.AfterListCatalogRolesEvent(catalogName));
Response resp = delegate.listCatalogRoles(catalogName, realmContext, securityContext);
polarisEventListener.onBeforeListCatalogRoles(
new CatalogsServiceEvents.BeforeListCatalogRolesEvent(catalogName));
return resp;
}

@Override
Expand All @@ -123,6 +175,7 @@ public Response addGrantToCatalogRole(
AddGrantRequest grantRequest,
RealmContext realmContext,
SecurityContext securityContext) {
// TODO: After changing the API response, we should change this to emit the corresponding event.
return delegate.addGrantToCatalogRole(
catalogName, catalogRoleName, grantRequest, realmContext, securityContext);
}
Expand All @@ -135,6 +188,7 @@ public Response revokeGrantFromCatalogRole(
RevokeGrantRequest grantRequest,
RealmContext realmContext,
SecurityContext securityContext) {
// TODO: After changing the API response, we should change this to emit the corresponding event.
return delegate.revokeGrantFromCatalogRole(
catalogName, catalogRoleName, cascade, grantRequest, realmContext, securityContext);
}
Expand All @@ -145,8 +199,16 @@ public Response listAssigneePrincipalRolesForCatalogRole(
String catalogRoleName,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.listAssigneePrincipalRolesForCatalogRole(
catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onBeforeListAssigneePrincipalRolesForCatalogRole(
new CatalogsServiceEvents.BeforeListAssigneePrincipalRolesForCatalogRoleEvent(
catalogName, catalogRoleName));
Response resp =
delegate.listAssigneePrincipalRolesForCatalogRole(
catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onAfterListAssigneePrincipalRolesForCatalogRole(
new CatalogsServiceEvents.AfterListAssigneePrincipalRolesForCatalogRoleEvent(
catalogName, catalogRoleName));
return resp;
}

@Override
Expand All @@ -155,7 +217,14 @@ public Response listGrantsForCatalogRole(
String catalogRoleName,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.listGrantsForCatalogRole(
catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onBeforeListGrantsForCatalogRole(
new CatalogsServiceEvents.BeforeListGrantsForCatalogRoleEvent(
catalogName, catalogRoleName));
Response resp =
delegate.listGrantsForCatalogRole(
catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onAfterListGrantsForCatalogRole(
new CatalogsServiceEvents.AfterListGrantsForCatalogRoleEvent(catalogName, catalogRoleName));
return resp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,50 @@
import jakarta.ws.rs.core.SecurityContext;
import org.apache.polaris.core.admin.model.CreatePrincipalRoleRequest;
import org.apache.polaris.core.admin.model.GrantCatalogRoleRequest;
import org.apache.polaris.core.admin.model.PrincipalRole;
import org.apache.polaris.core.admin.model.UpdatePrincipalRoleRequest;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.service.admin.api.PolarisPrincipalRolesApiService;
import org.apache.polaris.service.events.PrincipalRolesServiceEvents;
import org.apache.polaris.service.events.listeners.PolarisEventListener;

@Decorator
@Priority(1000)
public class PolarisPrincipalRolesEventServiceDelegator implements PolarisPrincipalRolesApiService {

@Inject @Delegate PolarisPrincipalRolesApiService delegate;
@Inject PolarisEventListener polarisEventListener;

@Override
public Response createPrincipalRole(
CreatePrincipalRoleRequest request,
RealmContext realmContext,
SecurityContext securityContext) {
// TODO: After changing the API response, we should change this to emit the corresponding event.
return delegate.createPrincipalRole(request, realmContext, securityContext);
}

@Override
public Response deletePrincipalRole(
String principalRoleName, RealmContext realmContext, SecurityContext securityContext) {
return delegate.deletePrincipalRole(principalRoleName, realmContext, securityContext);
polarisEventListener.onBeforeDeletePrincipalRole(
new PrincipalRolesServiceEvents.BeforeDeletePrincipalRoleEvent(principalRoleName));
Response resp = delegate.deletePrincipalRole(principalRoleName, realmContext, securityContext);
polarisEventListener.onAfterDeletePrincipalRole(
new PrincipalRolesServiceEvents.AfterDeletePrincipalRoleEvent(principalRoleName));
return resp;
}

@Override
public Response getPrincipalRole(
String principalRoleName, RealmContext realmContext, SecurityContext securityContext) {
return delegate.getPrincipalRole(principalRoleName, realmContext, securityContext);
polarisEventListener.onBeforeGetPrincipalRole(
new PrincipalRolesServiceEvents.BeforeGetPrincipalRoleEvent(principalRoleName));
Response resp = delegate.getPrincipalRole(principalRoleName, realmContext, securityContext);
polarisEventListener.onAfterGetPrincipalRole(
new PrincipalRolesServiceEvents.AfterGetPrincipalRoleEvent(
(PrincipalRole) resp.getEntity()));
return resp;
}

@Override
Expand All @@ -63,13 +79,26 @@ public Response updatePrincipalRole(
UpdatePrincipalRoleRequest updateRequest,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.updatePrincipalRole(
principalRoleName, updateRequest, realmContext, securityContext);
polarisEventListener.onBeforeUpdatePrincipalRole(
new PrincipalRolesServiceEvents.BeforeUpdatePrincipalRoleEvent(
principalRoleName, updateRequest));
Response resp =
delegate.updatePrincipalRole(
principalRoleName, updateRequest, realmContext, securityContext);
polarisEventListener.onAfterUpdatePrincipalRole(
new PrincipalRolesServiceEvents.AfterUpdatePrincipalRoleEvent(
(PrincipalRole) resp.getEntity()));
return resp;
}

@Override
public Response listPrincipalRoles(RealmContext realmContext, SecurityContext securityContext) {
return delegate.listPrincipalRoles(realmContext, securityContext);
polarisEventListener.onBeforeListPrincipalRoles(
new PrincipalRolesServiceEvents.BeforeListPrincipalRolesEvent());
Response resp = delegate.listPrincipalRoles(realmContext, securityContext);
polarisEventListener.onAfterListPrincipalRoles(
new PrincipalRolesServiceEvents.AfterListPrincipalRolesEvent());
return resp;
}

@Override
Expand All @@ -79,8 +108,16 @@ public Response assignCatalogRoleToPrincipalRole(
GrantCatalogRoleRequest request,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.assignCatalogRoleToPrincipalRole(
principalRoleName, catalogName, request, realmContext, securityContext);
polarisEventListener.onBeforeAssignCatalogRoleToPrincipalRole(
new PrincipalRolesServiceEvents.BeforeAssignCatalogRoleToPrincipalRoleEvent(
principalRoleName, catalogName, request.getCatalogRole().getName()));
Response resp =
delegate.assignCatalogRoleToPrincipalRole(
principalRoleName, catalogName, request, realmContext, securityContext);
polarisEventListener.onAfterAssignCatalogRoleToPrincipalRole(
new PrincipalRolesServiceEvents.AfterAssignCatalogRoleToPrincipalRoleEvent(
principalRoleName, catalogName, request.getCatalogRole().getName()));
return resp;
}

@Override
Expand All @@ -90,15 +127,31 @@ public Response revokeCatalogRoleFromPrincipalRole(
String catalogRoleName,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.revokeCatalogRoleFromPrincipalRole(
principalRoleName, catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onBeforeRevokeCatalogRoleFromPrincipalRole(
new PrincipalRolesServiceEvents.BeforeRevokeCatalogRoleFromPrincipalRoleEvent(
principalRoleName, catalogName, catalogRoleName));
Response resp =
delegate.revokeCatalogRoleFromPrincipalRole(
principalRoleName, catalogName, catalogRoleName, realmContext, securityContext);
polarisEventListener.onAfterRevokeCatalogRoleFromPrincipalRole(
new PrincipalRolesServiceEvents.AfterRevokeCatalogRoleFromPrincipalRoleEvent(
principalRoleName, catalogName, catalogRoleName));
return resp;
}

@Override
public Response listAssigneePrincipalsForPrincipalRole(
String principalRoleName, RealmContext realmContext, SecurityContext securityContext) {
return delegate.listAssigneePrincipalsForPrincipalRole(
principalRoleName, realmContext, securityContext);
polarisEventListener.onBeforeListAssigneePrincipalsForPrincipalRole(
new PrincipalRolesServiceEvents.BeforeListAssigneePrincipalsForPrincipalRoleEvent(
principalRoleName));
Response resp =
delegate.listAssigneePrincipalsForPrincipalRole(
principalRoleName, realmContext, securityContext);
polarisEventListener.onAfterListAssigneePrincipalsForPrincipalRole(
new PrincipalRolesServiceEvents.AfterListAssigneePrincipalsForPrincipalRoleEvent(
principalRoleName));
return resp;
}

@Override
Expand All @@ -107,7 +160,15 @@ public Response listCatalogRolesForPrincipalRole(
String catalogName,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.listCatalogRolesForPrincipalRole(
principalRoleName, catalogName, realmContext, securityContext);
polarisEventListener.onBeforeListCatalogRolesForPrincipalRole(
new PrincipalRolesServiceEvents.BeforeListCatalogRolesForPrincipalRoleEvent(
principalRoleName, catalogName));
Response resp =
delegate.listCatalogRolesForPrincipalRole(
principalRoleName, catalogName, realmContext, securityContext);
polarisEventListener.onAfterListCatalogRolesForPrincipalRole(
new PrincipalRolesServiceEvents.AfterListCatalogRolesForPrincipalRoleEvent(
principalRoleName, catalogName));
return resp;
}
}
Loading