use of org.apache.zookeeper.data.ACL in project fabric8 by jboss-fuse.
the class CreateAction method doExecute.
@Override
protected void doExecute(CuratorFramework curator) throws Exception {
List<ACL> acls = acl == null ? ZooDefs.Ids.OPEN_ACL_UNSAFE : parseACLs(acl);
CreateMode mode;
if (ephemeral && sequential) {
mode = CreateMode.EPHEMERAL_SEQUENTIAL;
} else if (ephemeral) {
mode = CreateMode.EPHEMERAL;
} else if (sequential) {
mode = CreateMode.PERSISTENT_SEQUENTIAL;
} else {
mode = CreateMode.PERSISTENT;
}
String nodeData = data;
if (importUrl) {
nodeData = loadUrl(new URL(data));
}
try {
CreateBuilder createBuilder = curator.create();
if (recursive) {
createBuilder.creatingParentsIfNeeded();
}
BackgroundPathAndBytesable<String> create = createBuilder.withMode(mode).withACL(acls);
if (nodeData == null) {
create.forPath(path);
} else {
create.forPath(path, nodeData.getBytes());
}
} catch (KeeperException.NodeExistsException e) {
if (overwrite) {
curator.setData().forPath(path, nodeData.getBytes());
} else {
throw e;
}
}
}
use of org.apache.zookeeper.data.ACL in project accumulo by apache.
the class ZooReaderWriterTest method testMutateWithBadVersion.
@Test
public void testMutateWithBadVersion() throws Exception {
final String path = "/foo";
final byte[] value = new byte[] { 0 };
final List<ACL> acls = Collections.emptyList();
final byte[] mutatedBytes = new byte[] { 1 };
Mutator mutator = new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
return mutatedBytes;
}
};
Method getDataMethod = ZooReaderWriter.class.getMethod("getData", String.class, boolean.class, Stat.class);
zrw = EasyMock.createMockBuilder(ZooReaderWriter.class).addMockedMethods("getRetryFactory", "getZooKeeper").addMockedMethod(getDataMethod).createMock();
EasyMock.expect(zrw.getRetryFactory()).andReturn(retryFactory).anyTimes();
EasyMock.expect(zrw.getZooKeeper()).andReturn(zk).anyTimes();
Stat stat = new Stat();
zk.create(path, value, acls, CreateMode.PERSISTENT);
EasyMock.expectLastCall().andThrow(new NodeExistsException()).once();
EasyMock.expect(zrw.getData(path, false, stat)).andReturn(new byte[] { 3 }).times(2);
// BadVersionException should retry
EasyMock.expect(zk.setData(path, mutatedBytes, 0)).andThrow(new BadVersionException());
// Let 2nd setData succeed
EasyMock.expect(zk.setData(path, mutatedBytes, 0)).andReturn(null);
EasyMock.replay(zk, zrw, retryFactory, retry);
Assert.assertArrayEquals(new byte[] { 1 }, zrw.mutate(path, value, acls, mutator));
EasyMock.verify(zk, zrw, retryFactory, retry);
}
use of org.apache.zookeeper.data.ACL in project accumulo by apache.
the class ZooReaderWriterTest method testMutateNodeCreationFails.
@Test(expected = SessionExpiredException.class)
public void testMutateNodeCreationFails() throws Exception {
final String path = "/foo";
final byte[] value = new byte[] { 0 };
final List<ACL> acls = Collections.emptyList();
Mutator mutator = new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
return new byte[] { 1 };
}
};
zk.create(path, value, acls, CreateMode.PERSISTENT);
EasyMock.expectLastCall().andThrow(new SessionExpiredException()).once();
EasyMock.expect(retry.canRetry()).andReturn(false);
EasyMock.expect(retry.retriesCompleted()).andReturn(1l).once();
EasyMock.replay(zk, zrw, retryFactory, retry);
zrw.mutate(path, value, acls, mutator);
}
use of org.apache.zookeeper.data.ACL in project accumulo by apache.
the class ZooAuthenticationKeyDistributorTest method testAlreadyAdvertisedKey.
@Test
public void testAlreadyAdvertisedKey() throws Exception {
ZooAuthenticationKeyDistributor distributor = new ZooAuthenticationKeyDistributor(zrw, baseNode);
AuthenticationKey key = new AuthenticationKey(1, 0l, 10l, keyGen.generateKey());
String path = baseNode + "/" + key.getKeyId();
// Attempt to create the directory and fail
expect(zrw.exists(baseNode)).andReturn(true);
expect(zrw.getACL(eq(baseNode), anyObject(Stat.class))).andReturn(Collections.singletonList(new ACL(ZooUtil.PRIVATE.get(0).getPerms(), new Id("digest", "accumulo:DEFAULT"))));
expect(zrw.exists(path)).andReturn(true);
replay(zrw);
distributor.initialize();
distributor.advertise(key);
verify(zrw);
}
use of org.apache.zookeeper.data.ACL in project accumulo by apache.
the class ZooAuthenticationKeyDistributorTest method testAdvertiseKey.
@Test
public void testAdvertiseKey() throws Exception {
ZooAuthenticationKeyDistributor distributor = new ZooAuthenticationKeyDistributor(zrw, baseNode);
AuthenticationKey key = new AuthenticationKey(1, 0l, 10l, keyGen.generateKey());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
key.write(new DataOutputStream(baos));
byte[] serialized = baos.toByteArray();
String path = baseNode + "/" + key.getKeyId();
// Attempt to create the directory and fail
expect(zrw.exists(baseNode)).andReturn(true);
expect(zrw.getACL(eq(baseNode), anyObject(Stat.class))).andReturn(Collections.singletonList(new ACL(ZooUtil.PRIVATE.get(0).getPerms(), new Id("digest", "accumulo:DEFAULT"))));
expect(zrw.exists(path)).andReturn(false);
expect(zrw.putPrivatePersistentData(eq(path), aryEq(serialized), eq(NodeExistsPolicy.FAIL))).andReturn(true);
replay(zrw);
distributor.initialize();
distributor.advertise(key);
verify(zrw);
}
Aggregations