public Object getFieldValue(_Fields field) { switch (field) { case ROOT_ID: return Integer.valueOf(getRootId()); case NODE_MAP: return getNodeMap(); } throw new IllegalStateException(); }
@Override public HMSPaths initializeFromDump(TPathsDump pathDump) { HMSPaths hmsPaths = new HMSPaths(this.hmsPaths.getPrefixes()); TPathEntry tRootEntry = pathDump.getNodeMap().get(pathDump.getRootId()); Entry rootEntry = hmsPaths.getRootEntry(); Map<String, Set<Entry>> authzObjToPath = new HashMap<String, Set<Entry>>(); cloneToEntry(tRootEntry, rootEntry, pathDump.getNodeMap(), authzObjToPath, rootEntry.getType() == EntryType.PREFIX); hmsPaths.setRootEntry(rootEntry); hmsPaths.setAuthzObjToPathMapping(authzObjToPath); return hmsPaths; }
/** * Test retrieveFullPathsImageUpdate() when no image is present. * @throws Exception */ @Test public void testRetrieveEmptyPathImage() throws Exception { String[] prefixes = {}; PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsUpdate tPathsUpdate = pathsUpdate.toThrift(); TPathsDump pathDump = tPathsUpdate.getPathsDump(); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap(); assertEquals(1, nodeMap.size()); System.out.printf(nodeMap.toString()); }
TPathsUpdate tPathsUpdate = pathsUpdate.toThrift(); TPathsDump pathDump = tPathsUpdate.getPathsDump(); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap(); System.out.printf(nodeMap.toString()); assertEquals(6, nodeMap.size());
TPathsDump pathDump = pathsUpdate.toThrift().getPathsDump(); assertNotNull(pathDump); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap(); int nodeCount = prefixSize + dbCount + (dbCount * tableCount) + (dbCount * tableCount * partitionCount);
PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathImage = new HashMap<>();
assertEquals(1, pathsUpdate.getImgNum()); TPathsDump pathDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap();
TPathsUpdate tPathsUpdate = pathsUpdate.toThrift(); TPathsDump pathDump = tPathsUpdate.getPathsDump(); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap(); assertEquals(7, nodeMap.size()); tPathsUpdate = pathsUpdate.toThrift(); pathDump = tPathsUpdate.getPathsDump(); nodeMap = pathDump.getNodeMap(); assertEquals(7, nodeMap.size()); tPathsUpdate = pathsUpdate.toThrift(); pathDump = tPathsUpdate.getPathsDump(); nodeMap = pathDump.getNodeMap(); assertEquals(7, nodeMap.size());
PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap(); assertEquals(4, nodeMap.size()); int rootId = pathDump.getRootId();
PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathsImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathsImage = new HashMap<>();
PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathImage = new HashMap<>();
@Test public void testIsAuthzPathsMappingEmpty() throws Exception { // Add "db1.table1" authzObj UniquePathsUpdate addUpdate = new UniquePathsUpdate("u1",1, false); addUpdate.newPathChange("db1.table"). addToAddPaths(Arrays.asList("db1", "tbl1")); addUpdate.newPathChange("db1.table"). addToAddPaths(Arrays.asList("db1", "tbl2")); // Persist an empty image so that we can add paths to it. sentryStore.persistFullPathsImage(new HashMap<String, Collection<String>>(), 0); assertEquals(sentryStore.isAuthzPathsMappingEmpty(), true); sentryStore.addAuthzPathsMapping("db1.table", Sets.newHashSet("db1/tbl1", "db1/tbl2"), addUpdate); String[]prefixes = {"/"}; PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathImage = new HashMap<>(); buildPathsImageMap(nodeMap, root, "", pathImage, false); assertEquals("/", root.getPathElement()); assertEquals(4, nodeMap.size());//Tree size assertEquals(1, pathImage.size()); assertEquals(2, pathImage.get("db1.table").size()); assertEquals(2, sentryStore.getMPaths().size()); assertEquals(sentryStore.isAuthzPathsMappingEmpty(), false); sentryStore.clearAllTables(); assertEquals(sentryStore.isAuthzPathsMappingEmpty(), true); }
PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathsImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathsImage = new HashMap<>();
PathsUpdate pathsUpdate = localSentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathImage = new HashMap<>(); pathsUpdate = localSentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathImage = new HashMap<>(); pathsUpdate = localSentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathImage = new HashMap<>();
PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathsImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathsImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathsImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathsImage = new HashMap<>();
PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsDump pathsDump = pathsUpdate.toThrift().getPathsDump(); Map<Integer, TPathEntry>nodeMap = pathsDump.getNodeMap(); TPathEntry root = nodeMap.get(pathsDump.getRootId()); Map<String, Collection<String>> pathImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathImage = new HashMap<>(); pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); pathsDump = pathsUpdate.toThrift().getPathsDump(); nodeMap = pathsDump.getNodeMap(); root = nodeMap.get(pathsDump.getRootId()); pathImage = new HashMap<>();