本文整理汇总了Java中org.apache.zookeeper.Op.create方法的典型用法代码示例。如果您正苦于以下问题:Java Op.create方法的具体用法?Java Op.create怎么用?Java Op.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.Op
的用法示例。
在下文中一共展示了Op.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testChRootCreateDelete
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
@Test
public void testChRootCreateDelete() throws Exception {
// creating the subtree for chRoot clients.
String chRoot = createNameSpace();
// Creating child using chRoot client.
zk_chroot = createClient(this.hostPort + chRoot);
Op createChild = Op.create("/myid", new byte[0],
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
multi(zk_chroot, Arrays.asList(createChild));
Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk
.exists(chRoot + "/myid", false));
Assert.assertNotNull("zNode is not created under chroot:" + chRoot,
zk_chroot.exists("/myid", false));
Assert.assertNull("zNode is created directly under '/', ignored configured chroot",
zk.exists("/myid", false));
// Deleting child using chRoot client.
Op deleteChild = Op.delete("/myid", 0);
multi(zk_chroot, Arrays.asList(deleteChild));
Assert.assertNull("zNode exists under chroot:" + chRoot, zk.exists(
chRoot + "/myid", false));
Assert.assertNull("zNode exists under chroot:" + chRoot, zk_chroot
.exists("/myid", false));
}
示例2: toZooKeeperOp
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
/**
* Convert from ZKUtilOp to ZKOp
*/
private static Op toZooKeeperOp(ZooKeeperWatcher zkw, ZKUtilOp op)
throws UnsupportedOperationException {
if(op == null) return null;
if (op instanceof CreateAndFailSilent) {
CreateAndFailSilent cafs = (CreateAndFailSilent)op;
return Op.create(cafs.getPath(), cafs.getData(), createACL(zkw, cafs.getPath()),
CreateMode.PERSISTENT);
} else if (op instanceof DeleteNodeFailSilent) {
DeleteNodeFailSilent dnfs = (DeleteNodeFailSilent)op;
return Op.delete(dnfs.getPath(), -1);
} else if (op instanceof SetData) {
SetData sd = (SetData)op;
return Op.setData(sd.getPath(), sd.getData(), -1);
} else {
throw new UnsupportedOperationException("Unexpected ZKUtilOp type: "
+ op.getClass().getName());
}
}
示例3: testChRootCreateDelete
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
@Test
public void testChRootCreateDelete() throws Exception {
// creating the subtree for chRoot clients.
String chRoot = createNameSpace();
// Creating child using chRoot client.
zk_chroot = createClient(this.hostPort + chRoot);
Op createChild = Op.create("/myid", new byte[0],
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk_chroot.multi(Arrays.asList(createChild));
Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk
.exists(chRoot + "/myid", false));
Assert.assertNotNull("zNode is not created under chroot:" + chRoot,
zk_chroot.exists("/myid", false));
Assert.assertNull("zNode is created directly under '/', ignored configured chroot",
zk.exists("/myid", false));
// Deleting child using chRoot client.
Op deleteChild = Op.delete("/myid", 0);
zk_chroot.multi(Arrays.asList(deleteChild));
Assert.assertNull("zNode exists under chroot:" + chRoot, zk.exists(
chRoot + "/myid", false));
Assert.assertNull("zNode exists under chroot:" + chRoot, zk_chroot
.exists("/myid", false));
}
示例4: createNameSpace
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
private String createNameSpace() throws InterruptedException,
KeeperException {
// creating the subtree for chRoot clients.
String chRoot = "/appsX";
Op createChRoot = Op.create(chRoot, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
multi(zk, Arrays.asList(createChRoot));
return chRoot;
}
示例5: testMulti
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
@Test
public void testMulti()
throws IOException, KeeperException, InterruptedException {
Op createTtl = Op.create("/a", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, 100);
Op createTtlSequential = Op.create("/b", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 200);
Op createNonTtl = Op.create("/c", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
List<OpResult> results = zk.multi(Arrays.asList(createTtl, createTtlSequential, createNonTtl));
String sequentialPath = ((OpResult.CreateResult)results.get(1)).getPath();
final AtomicLong fakeElapsed = new AtomicLong(0);
ContainerManager containerManager = newContainerManager(fakeElapsed);
containerManager.checkContainers();
Assert.assertNotNull("node should not have been deleted yet", zk.exists("/a", false));
Assert.assertNotNull("node should not have been deleted yet", zk.exists(sequentialPath, false));
Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));
fakeElapsed.set(110);
containerManager.checkContainers();
Assert.assertNull("node should have been deleted", zk.exists("/a", false));
Assert.assertNotNull("node should not have been deleted yet", zk.exists(sequentialPath, false));
Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));
fakeElapsed.set(210);
containerManager.checkContainers();
Assert.assertNull("node should have been deleted", zk.exists("/a", false));
Assert.assertNull("node should have been deleted", zk.exists(sequentialPath, false));
Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));
}
示例6: createNameSpace
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
private String createNameSpace() throws InterruptedException,
KeeperException {
// creating the subtree for chRoot clients.
String chRoot = "/appsX";
Op createChRoot = Op.create(chRoot, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
zk.multi(Arrays.asList(createChRoot));
return chRoot;
}
示例7: createLogSegment
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
@Override
public void createLogSegment(Transaction<Object> txn, LogSegmentMetadata segment) {
byte[] finalisedData = segment.getFinalisedData().getBytes(UTF_8);
Op createOp = Op.create(
segment.getZkPath(),
finalisedData,
zkc.getDefaultACL(),
CreateMode.PERSISTENT);
txn.addOp(DefaultZKOp.of(createOp));
}
示例8: initInternal
import org.apache.zookeeper.Op; //导入方法依赖的package包/类
@Override
public synchronized void initInternal(Configuration conf) throws Exception {
zkHostPort = conf.get(YarnConfiguration.RM_ZK_ADDRESS);
if (zkHostPort == null) {
throw new YarnRuntimeException("No server address specified for " +
"zookeeper state store for Resource Manager recovery. " +
YarnConfiguration.RM_ZK_ADDRESS + " is not configured.");
}
numRetries =
conf.getInt(YarnConfiguration.RM_ZK_NUM_RETRIES,
YarnConfiguration.DEFAULT_ZK_RM_NUM_RETRIES);
znodeWorkingPath =
conf.get(YarnConfiguration.ZK_RM_STATE_STORE_PARENT_PATH,
YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH);
zkSessionTimeout =
conf.getInt(YarnConfiguration.RM_ZK_TIMEOUT_MS,
YarnConfiguration.DEFAULT_RM_ZK_TIMEOUT_MS);
if (HAUtil.isHAEnabled(conf)) {
zkRetryInterval = zkSessionTimeout / numRetries;
} else {
zkRetryInterval =
conf.getLong(YarnConfiguration.RM_ZK_RETRY_INTERVAL_MS,
YarnConfiguration.DEFAULT_RM_ZK_RETRY_INTERVAL_MS);
}
zkResyncWaitTime = zkRetryInterval * numRetries;
zkAcl = RMZKUtils.getZKAcls(conf);
zkAuths = RMZKUtils.getZKAuths(conf);
zkRootNodePath = getNodePath(znodeWorkingPath, ROOT_ZNODE_NAME);
rmAppRoot = getNodePath(zkRootNodePath, RM_APP_ROOT);
/* Initialize fencing related paths, acls, and ops */
fencingNodePath = getNodePath(zkRootNodePath, FENCING_LOCK);
createFencingNodePathOp = Op.create(fencingNodePath, new byte[0], zkAcl,
CreateMode.PERSISTENT);
deleteFencingNodePathOp = Op.delete(fencingNodePath, -1);
if (HAUtil.isHAEnabled(conf)) {
String zkRootNodeAclConf = HAUtil.getConfValueForRMInstance
(YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL, conf);
if (zkRootNodeAclConf != null) {
zkRootNodeAclConf = ZKUtil.resolveConfIndirection(zkRootNodeAclConf);
try {
zkRootNodeAcl = ZKUtil.parseACLs(zkRootNodeAclConf);
} catch (ZKUtil.BadAclFormatException bafe) {
LOG.error("Invalid format for " +
YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL);
throw bafe;
}
} else {
useDefaultFencingScheme = true;
zkRootNodeAcl = constructZkRootNodeACL(conf, zkAcl);
}
}
rmDTSecretManagerRoot =
getNodePath(zkRootNodePath, RM_DT_SECRET_MANAGER_ROOT);
dtMasterKeysRootPath = getNodePath(rmDTSecretManagerRoot,
RM_DT_MASTER_KEYS_ROOT_ZNODE_NAME);
delegationTokensRootPath = getNodePath(rmDTSecretManagerRoot,
RM_DELEGATION_TOKENS_ROOT_ZNODE_NAME);
dtSequenceNumberPath = getNodePath(rmDTSecretManagerRoot,
RM_DT_SEQUENTIAL_NUMBER_ZNODE_NAME);
amrmTokenSecretManagerRoot =
getNodePath(zkRootNodePath, AMRMTOKEN_SECRET_MANAGER_ROOT);
}