@Override public void close() { if (client != null) { // Close any outstanding connections to HMS try { client.disconnect(); SentryStateBank.disableState(HMSFollowerState.COMPONENT,HMSFollowerState.CONNECTED); } catch (Exception failure) { LOGGER.error("Failed to close the Sentry Hms Client", failure); } } notificationFetcher.close(); }
/** * Retrieve a Hive full snapshot from HMS. * * @return HMS snapshot. Snapshot consists of a mapping from auth object name to the set of paths * corresponding to that name. */ private Map<String, Collection<String>> fetchFullUpdate() throws Exception{ String logMessage = "Request full HMS snapshot"; LOGGER.info(logMessage); System.out.println(SentryServiceUtil.getCurrentTimeStampWithMessage(logMessage)); try (FullUpdateInitializer updateInitializer = new FullUpdateInitializer(hiveConnectionFactory, conf); Context context = updateTimer.time()) { SentryStateBank.enableState(FullUpdateInitializerState.COMPONENT,FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS); Map<String, Collection<String>> pathsUpdate = updateInitializer.getFullHMSSnapshot(); logMessage = "Obtained full HMS snapshot"; LOGGER.info(logMessage); System.out.println(SentryServiceUtil.getCurrentTimeStampWithMessage(logMessage)); return pathsUpdate; } catch (Exception exception) { failedSnapshotsCount.inc(); LOGGER.error("Snapshot created failed ", exception); throw exception; } finally { SentryStateBank.disableState(FullUpdateInitializerState.COMPONENT,FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS); } } }
exception.ifExceptionThrow(); SentryStateBank.disableState(SentryServiceState.COMPONENT,SentryServiceState.SERVICE_RUNNING); LOGGER.info("Stopped...");
@Override public void run() { SentryStateBank.enableState(HMSFollowerState.COMPONENT,HMSFollowerState.STARTED); long lastProcessedNotificationId; try { try { // Initializing lastProcessedNotificationId based on the latest persisted notification ID. lastProcessedNotificationId = sentryStore.getLastProcessedNotificationID(); } catch (Exception e) { LOGGER.error("Failed to get the last processed notification id from sentry store, " + "Skipping the processing", e); return; } // Wake any clients connected to this service waiting for HMS already processed notifications. wakeUpWaitingClientsForSync(lastProcessedNotificationId); // Only the leader should listen to HMS updates if (!isLeader()) { // Close any outstanding connections to HMS close(); return; } syncupWithHms(lastProcessedNotificationId); } finally { SentryStateBank.disableState(HMSFollowerState.COMPONENT,HMSFollowerState.STARTED); } }
} finally { SentryStateBank .disableState(SentryServiceState.COMPONENT, SentryServiceState.FULL_UPDATE_RUNNING);
@Test public void testStatesGetDisabled() { SentryStateBank.enableState(TestState.COMPONENT, TestState.FIRST_STATE); assertTrue("Expected FIRST_STATE to be enabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.FIRST_STATE)); SentryStateBank.disableState(TestState.COMPONENT, TestState.FIRST_STATE); assertFalse("Expected FIRST_STATE to be disabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.FIRST_STATE)); }