SentryPolicyStoreProcessor implements SentryPolicyService.Iface { @Override public TSentryHmsEventNotificationResponse sentry_notify_hms_event (TSentryHmsEventNotification request) throws TException { TSentryHmsEventNotificationResponse response = new TSentryHmsEventNotificationResponse(); EventType eventType = EventType.valueOf(request.getEventType()); try (Timer.Context timerContext = sentryMetrics.notificationProcessTimer.time()) { switch (eventType) { case CREATE_DATABASE: case CREATE_TABLE: if(request.getId() > 0) { response.setId(syncEventId(request.getId())); } else { response.setId(0L); } grantOwnerPrivilege(request); break; case DROP_DATABASE: case DROP_TABLE: if(request.getId() > 0) { response.setId(syncEventId(request.getId())); } else { response.setId(0L); } break; case ALTER_TABLE: if(request.getId() > 0) { response.setId(syncEventId(request.getId())); } else { response.setId(0L); } updateOwnerPrivilege(request); break; default: LOGGER.info("Processing HMS Event of Type: " + eventType.toString() + " skipped"); } response.setStatus(Status.OK()); } catch (SentryNoSuchObjectException e) { String msg = request.getOwnerType().toString() + ": " + request.getOwnerName() + " doesn't exist"; LOGGER.error(msg, e); response.setStatus(Status.NoSuchObject(msg, e)); } catch (SentryInvalidInputException e) { LOGGER.error(e.getMessage(), e); response.setStatus(Status.InvalidInput(e.getMessage(), e)); } catch (SentryThriftAPIMismatchException e) { LOGGER.error(e.getMessage(), e); response.setStatus(Status.THRIFT_VERSION_MISMATCH(e.getMessage(), e)); } catch (Exception e) { String msg = "Unknown error for request: " + request + ", message: " + e.getMessage(); LOGGER.error(msg, e); response.setStatus(Status.RuntimeError(msg, e)); } return response; } SentryPolicyStoreProcessor(String name,
        Configuration conf, SentryStoreInterface store); void stop(); void registerPlugin(SentryPolicyStorePlugin plugin); @VisibleForTesting Configuration getSentryStoreConf(); @Override TIsSentryAdminResponse is_sentry_admin(TIsSentryAdminRequest request); @Override TCreateSentryRoleResponse create_sentry_role(
    TCreateSentryRoleRequest request); @Override TAlterSentryRoleGrantPrivilegeResponse alter_sentry_role_grant_privilege(TAlterSentryRoleGrantPrivilegeRequest request); @Override TAlterSentryRoleRevokePrivilegeResponse alter_sentry_role_revoke_privilege(TAlterSentryRoleRevokePrivilegeRequest request); @Override TDropSentryRoleResponse drop_sentry_role(
    TDropSentryRoleRequest request); @Override TAlterSentryRoleAddGroupsResponse alter_sentry_role_add_groups(
    TAlterSentryRoleAddGroupsRequest request); @Override TAlterSentryRoleAddUsersResponse alter_sentry_role_add_users(
      TAlterSentryRoleAddUsersRequest request); @Override TAlterSentryRoleDeleteUsersResponse alter_sentry_role_delete_users(
      TAlterSentryRoleDeleteUsersRequest request); @Override TAlterSentryRoleDeleteGroupsResponse alter_sentry_role_delete_groups(
    TAlterSentryRoleDeleteGroupsRequest request); @Override TListSentryRolesResponse list_sentry_roles_by_group(
    TListSentryRolesRequest request); TListSentryRolesResponse list_sentry_roles_by_user(TListSentryRolesForUserRequest request); @Override TListSentryPrivilegesResponse list_sentry_privileges_by_role(
      TListSentryPrivilegesRequest request); @Override TListSentryPrivilegesResponse list_sentry_privileges_by_user(
    TListSentryPrivilegesRequest request); @Override TListSentryPrivilegesResponse list_sentry_privileges_by_user_and_itsgroups(
          TListSentryPrivilegesRequest request); @Override TListSentryPrivilegesForProviderResponse list_sentry_privileges_for_provider(
      TListSentryPrivilegesForProviderRequest request); static Set<String> getGroupsFromUserName(Configuration conf,
      String userName); @Override TDropPrivilegesResponse drop_sentry_privilege(
      TDropPrivilegesRequest request); @Override TRenamePrivilegesResponse rename_sentry_privilege(
      TRenamePrivilegesRequest request); @Override TListSentryPrivilegesByAuthResponse list_sentry_privileges_by_authorizable(
      TListSentryPrivilegesByAuthRequest request); @Override TListSentryPrivilegesByAuthUserResponse list_sentry_privileges_by_authorizable_and_user(
      TListSentryPrivilegesByAuthUserRequest request); @Override TSentryConfigValueResponse get_sentry_config_value(
          TSentryConfigValueRequest request); @Override @SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop") TSentryExportMappingDataResponse export_sentry_mapping_data(
      TSentryExportMappingDataRequest request); @Override TSentryImportMappingDataResponse import_sentry_mapping_data(
      TSentryImportMappingDataRequest request); @Override TSentrySyncIDResponse sentry_sync_notifications(TSentrySyncIDRequest request); @Override TSentryHmsEventNotificationResponse sentry_notify_hms_event(TSentryHmsEventNotification request); @Override TSentryPrivilegesResponse list_roles_privileges(TSentryPrivilegesRequest request); @Override TSentryPrivilegesResponse list_users_privileges(TSentryPrivilegesRequest request);  }
@Test public void testNotificationSync() throws Exception { SentryPolicyStoreProcessor sentryServiceHandler = new SentryPolicyStoreProcessor(ApiConstants.SentryPolicyServiceConstants.SENTRY_POLICY_SERVICE_NAME, conf, sentryStore); TSentryAuthorizable authorizable = new TSentryAuthorizable(); authorizable.setDb(DBNAME); TSentryHmsEventNotification notification = new TSentryHmsEventNotification(); notification.setId(1L); notification.setOwnerType(TSentryPrincipalType.ROLE); notification.setOwnerName(OWNER); notification.setAuthorizable(authorizable); notification.setEventType(EventType.CREATE_DATABASE.toString()); sentryServiceHandler.sentry_notify_hms_event(notification); Mockito.verify( sentryStore, Mockito.times(1) ).getCounterWait(); Mockito.verify(counterWait, Mockito.times(1)).waitFor(1L); SentryStateBank.enableState(FullUpdateInitializerState.COMPONENT, FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS); sentryServiceHandler.sentry_notify_hms_event(notification); Mockito.reset(sentryStore); Mockito.reset(counterWait); Mockito.verify( sentryStore, Mockito.times(0) ).getCounterWait(); Mockito.verify(counterWait, Mockito.times(0)).waitFor(1L); }