Search in sources :

Example 91 with ACL

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)));
}
Also used : ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) Test(org.junit.jupiter.api.Test)

Example 92 with ACL

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)));
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) ByteArrayInputStream(java.io.ByteArrayInputStream) ACL(org.apache.zookeeper.data.ACL) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 93 with ACL

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());
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) GetACLRequest(org.apache.zookeeper.proto.GetACLRequest) ACL(org.apache.zookeeper.data.ACL) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Stat(org.apache.zookeeper.data.Stat) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Id(org.apache.zookeeper.data.Id) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 94 with ACL

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;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ACL(org.apache.zookeeper.data.ACL) KeeperException(org.apache.zookeeper.KeeperException)

Example 95 with ACL

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;
}
Also used : ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

Aggregations

ACL (org.apache.zookeeper.data.ACL)215 Id (org.apache.zookeeper.data.Id)85 ArrayList (java.util.ArrayList)61 Test (org.junit.Test)56 Stat (org.apache.zookeeper.data.Stat)45 KeeperException (org.apache.zookeeper.KeeperException)35 Test (org.testng.annotations.Test)32 CuratorFramework (org.apache.curator.framework.CuratorFramework)20 Test (org.junit.jupiter.api.Test)18 Configuration (org.apache.hadoop.conf.Configuration)17 ZooKeeper (org.apache.zookeeper.ZooKeeper)16 ACLProvider (org.apache.curator.framework.api.ACLProvider)15 List (java.util.List)11 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)8 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 HashMap (java.util.HashMap)6 CreateMode (org.apache.zookeeper.CreateMode)6