/** * 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); } } }
new FullUpdateInitializer(new MockHMSClientFactory(client), conf)) { update = cacheInitializer.getFullHMSSnapshot();
@Test // Test basic operation with small database public void testSimple() throws Exception { HiveTable tab21 = new HiveTable("tab21"); HiveTable tab31 = new HiveTable("tab31").add("part311").add("part312"); HiveDb db3 = new HiveDb("db3", Lists.newArrayList(tab31)); HiveDb db2 = new HiveDb("db2", Lists.newArrayList(tab21)); HiveDb db1 = new HiveDb("db1"); HiveSnapshot snap = new HiveSnapshot().add(db1).add(db2).add(db3); MockClient c = new MockClient(snap); Map<String, Collection<String>> update; try(FullUpdateInitializer cacheInitializer = new FullUpdateInitializer(new MockHMSClientFactory(c), conf)) { update = cacheInitializer.getFullHMSSnapshot(); } Assert.assertEquals(5, update.size()); Assert.assertEquals(Sets.newHashSet("db1"), update.get("db1")); Assert.assertEquals(Sets.newHashSet("db2"), update.get("db2")); Assert.assertEquals(Sets.newHashSet("db3"), update.get("db3")); Assert.assertEquals(Sets.newHashSet("db2/tab21"), update.get("db2.tab21")); Assert.assertEquals(Sets.newHashSet("db3/tab31", "db3/tab31/part311", "db3/tab31/part312"), update.get("db3.tab31")); }
Map<String, Collection<String>> update; try(FullUpdateInitializer cacheInitializer = new FullUpdateInitializer(new MockHMSClientFactory(c), conf)) { update = cacheInitializer.getFullHMSSnapshot();