/** * 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); } } }
@Test public void testCheckMultipleStateCheckSuccess() { SentryStateBank.enableState(TestState.COMPONENT, TestState.FIRST_STATE); SentryStateBank.enableState(TestState.COMPONENT, TestState.SECOND_STATE); assertTrue("Expected both FIRST_STATE and SECOND_STATE to be enabled", SentryStateBank.hasStatesEnabled(TestState.COMPONENT, new HashSet<SentryState>( Arrays.asList(TestState.FIRST_STATE, TestState.SECOND_STATE)))); }
@Test public void testCheckMultipleStateCheckFailure() { SentryStateBank.enableState(TestState.COMPONENT, TestState.FIRST_STATE); assertFalse("Expected only FIRST_STATE to be enabled", SentryStateBank.hasStatesEnabled(TestState.COMPONENT, new HashSet<SentryState>( Arrays.asList(TestState.FIRST_STATE, TestState.SECOND_STATE)))); }
@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); } }
.enableState(SentryServiceState.COMPONENT, SentryServiceState.FULL_UPDATE_RUNNING);
SentryStateBank.enableState(SentryServiceState.COMPONENT, SentryServiceState.SERVICE_RUNNING); thriftServer.serve();
client.connect(); connectedToHms = true; SentryStateBank.enableState(HMSFollowerState.COMPONENT,HMSFollowerState.CONNECTED); } catch (Throwable e) { LOGGER.error("HMSFollower cannot connect to HMS!!", e);
@Test public void testEnableState() { SentryStateBank.enableState(TestState.COMPONENT, TestState.FIRST_STATE); assertTrue("Expected FIRST_STATE to be enabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.FIRST_STATE)); assertFalse("Expected SECOND_STATE to be disabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.SECOND_STATE)); }
SentryStateBank.enableState(FullUpdateInitializerState.COMPONENT, FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS);
@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)); }