List of usage examples for org.apache.hadoop.fs.permission AclEntry toString
@Override
@InterfaceStability.Unstable
public String toString()
From source file:com.bigstep.datalake.JsonUtil.java
License:Apache License
/** Convert a AclStatus object to a Json string. */ public static String toJsonString(final AclStatus status) { if (status == null) { return null; }/*from w w w. j a va 2 s . c o m*/ final Map<String, Object> m = new TreeMap<String, Object>(); m.put("owner", status.getOwner()); m.put("group", status.getGroup()); m.put("stickyBit", status.isStickyBit()); final List<String> stringEntries = new ArrayList<>(); for (AclEntry entry : status.getEntries()) { stringEntries.add(entry.toString()); } m.put("entries", stringEntries); FsPermission perm = status.getPermission(); if (perm != null) { m.put("permission", toString(perm)); if (perm.getAclBit()) { m.put("aclBit", true); } if (perm.getEncryptedBit()) { m.put("encBit", true); } } final Map<String, Map<String, Object>> finalMap = new TreeMap<String, Map<String, Object>>(); finalMap.put(AclStatus.class.getSimpleName(), m); Gson gson = new Gson(); return gson.toJson(finalMap); }
From source file:org.apache.sentry.tests.e2e.hdfs.TestDbHdfsBase.java
License:Apache License
/** * Verify extended acl entries are correctly synced up * @param expectedAcls/*from w w w . jav a 2 s . co m*/ * @param pathLoc * @param recursive * @throws Exception */ private void verifyAclsHelper(List<AclEntry> expectedAcls, String pathLoc, boolean recursive) throws Exception { int retry = 0; Path path = new Path(pathLoc); LOGGER.info("expectedAcls of [" + pathLoc + "] = " + expectedAcls.toString()); // Syncing up acls takes some time so make validation in a loop while (retry < NUM_RETRIES_FOR_ACLS) { AclStatus aclStatus = fileSystem.getAclStatus(path); List<AclEntry> actualAcls = new ArrayList<>(aclStatus.getEntries()); LOGGER.info("[" + retry + "] actualAcls of [" + pathLoc + "] = " + actualAcls.toString()); retry += 1; if (!actualAcls.isEmpty() && !actualAcls.contains(expectedAcls.get(expectedAcls.size() - 1))) { Thread.sleep(WAIT_SECS_FOR_ACLS); } else { for (AclEntry expected : expectedAcls) { assertTrue("Fail to find aclEntry: " + expected.toString(), actualAcls.contains(expected)); } break; } } assertThat(retry, lessThan(NUM_RETRIES_FOR_ACLS)); if (recursive && fileSystem.getFileStatus(path).isDirectory()) { FileStatus[] children = fileSystem.listStatus(path); for (FileStatus fs : children) { verifyAclsRecursive(expectedAcls, fs.getPath().toString(), recursive); } } }
From source file:org.apache.sentry.tests.e2e.hdfs.TestDbHdfsBase.java
License:Apache License
/** * Verify there is no specified acls gotten synced up in the path status * @param noAcls//w ww . ja va2 s . c o m * @param pathLoc * @param recursive * @throws Exception */ private void verifyNoAclHelper(List<AclEntry> noAcls, String pathLoc, boolean recursive) throws Exception { int retry = 0; // Retry a couple of times in case the incorrect acls take time to be synced up while (retry < NUM_RETRIES_FOR_ACLS) { Path path = new Path(pathLoc); AclStatus aclStatus = fileSystem.getAclStatus(path); List<AclEntry> actualAcls = new ArrayList<>(aclStatus.getEntries()); LOGGER.info("[" + retry + "] actualAcls of [" + pathLoc + "] = " + actualAcls.toString()); Thread.sleep(1000); // wait for syncup retry += 1; for (AclEntry acl : actualAcls) { if (noAcls.contains(acl)) { fail("Path [ " + pathLoc + " ] should not contain " + acl.toString()); } } } Path path = new Path(pathLoc); if (recursive && fileSystem.getFileStatus(path).isDirectory()) { FileStatus[] children = fileSystem.listStatus(path); for (FileStatus fs : children) { verifyNoAclRecursive(noAcls, fs.getPath().toString(), recursive); } } }