use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class ReferenceCountedACLCacheTest method testWhetherOrderingMatters.
@Test
public void testWhetherOrderingMatters() {
List<ACL> testACL = new ArrayList<ACL>();
testACL.add(new ACL(ZooDefs.Perms.READ, new Id("scheme", "ro")));
testACL.add(new ACL(ZooDefs.Perms.WRITE, new Id("scheme", "rw")));
ReferenceCountedACLCache cache = new ReferenceCountedACLCache();
Long aclId = cache.convertAcls(testACL);
List<ACL> testACL2 = new ArrayList<ACL>();
testACL2.add(new ACL(ZooDefs.Perms.WRITE, new Id("scheme", "rw")));
testACL2.add(new ACL(ZooDefs.Perms.READ, new Id("scheme", "ro")));
assertFalse(aclId.equals(cache.convertAcls(testACL2)));
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class ReferenceCountedACLCacheTest method testPurgeUnused.
@Test
public void testPurgeUnused() throws IOException {
ReferenceCountedACLCache cache = new ReferenceCountedACLCache();
List<ACL> acl1 = createACL("one");
List<ACL> acl2 = createACL("two");
List<ACL> acl3 = createACL("three");
List<ACL> acl4 = createACL("four");
List<ACL> acl5 = createACL("five");
Long aclId1 = convertACLsNTimes(cache, acl1, 1);
Long aclId2 = convertACLsNTimes(cache, acl2, 2);
Long aclId3 = convertACLsNTimes(cache, acl3, 3);
Long aclId4 = convertACLsNTimes(cache, acl4, 4);
Long aclId5 = convertACLsNTimes(cache, acl5, 5);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive archive = BinaryOutputArchive.getArchive(baos);
cache.serialize(archive);
BinaryInputArchive inArchive = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
ReferenceCountedACLCache deserializedCache = new ReferenceCountedACLCache();
deserializedCache.deserialize(inArchive);
callAddUsageNTimes(deserializedCache, aclId1, 1);
callAddUsageNTimes(deserializedCache, aclId2, 2);
deserializedCache.purgeUnused();
assertEquals(2, deserializedCache.size());
assertEquals(aclId1, deserializedCache.convertAcls(acl1));
assertEquals(aclId2, deserializedCache.convertAcls(acl2));
assertFalse(acl3.equals(deserializedCache.convertAcls(acl3)));
assertFalse(acl4.equals(deserializedCache.convertAcls(acl4)));
assertFalse(acl5.equals(deserializedCache.convertAcls(acl5)));
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class FinalRequestProcessorTest method setUp.
@BeforeEach
public void setUp() throws KeeperException.NoNodeException, IOException {
testACLs.clear();
testACLs.addAll(Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("digest", "user:secrethash")), new ACL(ZooDefs.Perms.ADMIN, new Id("digest", "adminuser:adminsecret")), new ACL(ZooDefs.Perms.READ, new Id("world", "anyone"))));
ZooKeeperServer zks = new ZooKeeperServer();
ZKDatabase db = mock(ZKDatabase.class);
String testPath = "/testPath";
when(db.getNode(eq(testPath))).thenReturn(new DataNode());
when(db.getACL(eq(testPath), any(Stat.class))).thenReturn(testACLs);
when(db.aclForNode(any(DataNode.class))).thenReturn(testACLs);
zks.setZKDatabase(db);
processor = new FinalRequestProcessor(zks);
cnxn = mock(ServerCnxn.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) {
replyHeaders[0] = invocationOnMock.getArgument(0);
responseRecord[0] = invocationOnMock.getArgument(1);
return null;
}
}).when(cnxn).sendResponse(any(), any(), anyString());
GetACLRequest getACLRequest = new GetACLRequest();
getACLRequest.setPath(testPath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
getACLRequest.serialize(boa, "request");
baos.close();
bb = ByteBuffer.wrap(baos.toByteArray());
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class SetAclCommand method exec.
@Override
public boolean exec() throws CliException {
String path = args[1];
String aclStr = args[2];
List<ACL> acl = AclParser.parse(aclStr);
int version;
if (cl.hasOption("v")) {
version = Integer.parseInt(cl.getOptionValue("v"));
} else {
version = -1;
}
try {
if (cl.hasOption("R")) {
ZKUtil.visitSubTreeDFS(zk, path, false, (rc, p, ctx, name) -> {
try {
zk.setACL(p, acl, version);
} catch (KeeperException | InterruptedException e) {
out.print(e.getMessage());
}
});
} else {
Stat stat = zk.setACL(path, acl, version);
if (cl.hasOption("s")) {
new StatPrinter(out).print(stat);
}
}
} catch (IllegalArgumentException ex) {
throw new MalformedPathException(ex.getMessage());
} catch (KeeperException | InterruptedException ex) {
throw new CliWrapperException(ex);
}
return false;
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class AclParser method parse.
/**
* parse string into list of ACL
* @param aclString
* @return list of ACL
*/
public static List<ACL> parse(String aclString) {
List<ACL> acl;
String[] acls = aclString.split(",");
acl = new ArrayList<ACL>();
for (String a : acls) {
int firstColon = a.indexOf(':');
int lastColon = a.lastIndexOf(':');
if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) {
System.err.println(a + " does not have the form scheme:id:perm");
continue;
}
ACL newAcl = new ACL();
newAcl.setId(new Id(a.substring(0, firstColon), a.substring(firstColon + 1, lastColon)));
newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
acl.add(newAcl);
}
return acl;
}
Aggregations