public String createNode(CuratorFramework zk, String path, byte[] data, org.apache.zookeeper.CreateMode mode) throws Exception { String normPath = PathUtils.normalize_path(path); return zk.create().withMode(mode).withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath(normPath, data); }
/** * A helper method that sets a field value. * @throws java.lang.Exception */ private void setFieldData(Type type, String id, String name, String val) throws Exception { try { zk.create().withMode(CreateMode.PERSISTENT).withACL(Ids.OPEN_ACL_UNSAFE) .forPath(makeFieldZnode(type, id, name), val.getBytes(ENCODING)); } catch (KeeperException.NodeExistsException e) { zk.setData().forPath(makeFieldZnode(type, id, name), val.getBytes(ENCODING)); } }
/** * Create the parent znode for this job state. */ public void create() throws IOException { try { zk.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT) .withACL(Ids.OPEN_ACL_UNSAFE).forPath(job_trackingroot); } catch (KeeperException.NodeExistsException e) { //root must exist already } catch (Exception e) { throw new IOException("Unable to create parent nodes"); } try { trackingnode = zk.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL) .withACL(Ids.OPEN_ACL_UNSAFE).forPath(makeTrackingZnode(), jobid.getBytes()); } catch (Exception e) { throw new IOException("Unable to create " + makeTrackingZnode()); } } public void delete() throws IOException {
@Override public int addMasterKey(String s) { String keysPath = rootNode + NODE_KEYS + "/"; CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).withACL(newNodeAcl) .forPath(keysPath, s.getBytes()); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + keysPath, e); } LOGGER.info("Added key {}", newNode); return getSeq(newNode); }
/** * Create a path if it does not already exist ("mkdir -p") * @param path string with '/' separator * @param acl list of ACL entries * @throws TokenStoreException */ public void ensurePath(String path, List<ACL> acl) throws TokenStoreException { try { CuratorFramework zk = getSession(); String node = zk.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT) .withACL(acl).forPath(path); LOGGER.info("Created path: {} ", node); } catch (KeeperException.NodeExistsException e) { // node already exists } catch (Exception e) { throw new TokenStoreException("Error creating path " + path, e); } }
/** * Create a ZNode. * @param path Path of the ZNode. * @param zkAcl ACL for the node. * @return If the ZNode was created. * @throws Exception If it cannot contact Zookeeper. */ public boolean create(final String path, List<ACL> zkAcl) throws Exception { boolean created = false; if (!exists(path)) { curator.create() .withMode(CreateMode.PERSISTENT) .withACL(zkAcl) .forPath(path, null); created = true; } return created; }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) { byte[] tokenBytes = MetastoreDelegationTokenSupport.encodeDelegationTokenInformation(token); String tokenPath = getTokenPath(tokenIdentifier); CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT).withACL(newNodeAcl) .forPath(tokenPath, tokenBytes); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + tokenPath, e); } LOGGER.info("Added token: {}", newNode); return true; }
.withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath(BLOBSTORE_MAX_KEY_SEQUENCE_SUBTREE + "/" + key); zkClient.setData().forPath(BLOBSTORE_MAX_KEY_SEQUENCE_SUBTREE + "/" + key, ByteBuffer.allocate(INT_CAPACITY).putInt(INITIAL_SEQUENCE_NUMBER).array());
boolean wasCreated = false; try { zk.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).withACL(Ids.OPEN_ACL_UNSAFE).forPath(makeZnode(type, id)); wasCreated = true;
@Override public BackgroundPathAndBytesable<T> withACL(List<ACL> aclList) { return new BackgroundPathAndBytesableDecorator<>(inner.withACL(aclList)); }
/** * Check whether znode is exist in given path if not create a new znode * @param curatorClient - zookeeper instance * @param path - path to check znode * @throws KeeperException * @throws InterruptedException */ private static void checkAndCreateZNode(CuratorFramework curatorClient , String path) throws Exception { if (curatorClient.checkExists().forPath(path) == null) { // if znode doesn't exist if (path.lastIndexOf("/") > 1) { // recursively traverse to parent znode and check parent exist checkAndCreateZNode(curatorClient, (path.substring(0, path.lastIndexOf("/")))); } curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath(path); } } }
private static void copyChildren(CuratorFramework curatorClient, String oldPath, String newPath, int depth) throws Exception { for (String childNode : curatorClient.getChildren().forPath(oldPath)) { String oldChildPath = oldPath + File.separator + childNode; Stat stat = curatorClient.checkExists().forPath(oldChildPath); // no need to check exists String newChildPath = newPath + File.separator + childNode; log.info("Creating new znode: " + newChildPath); curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) .forPath(newChildPath, curatorClient.getData().storingStatIn(stat).forPath(oldChildPath)); if (--depth > 0) { copyChildren(curatorClient, oldChildPath, newChildPath, depth); } } }
/** * A helper method that sets a field value. * @throws java.lang.Exception */ private void setFieldData(Type type, String id, String name, String val) throws Exception { try { zk.create().withMode(CreateMode.PERSISTENT).withACL(Ids.OPEN_ACL_UNSAFE) .forPath(makeFieldZnode(type, id, name), val.getBytes(ENCODING)); } catch (KeeperException.NodeExistsException e) { zk.setData().forPath(makeFieldZnode(type, id, name), val.getBytes(ENCODING)); } }
public String createNode(CuratorFramework zk, String path, byte[] data , CreateMode mode) throws Exception { String npath = PathUtils.normalize_path(path); return zk.create().withMode(mode).withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath(npath,data); }
@Override public int addMasterKey(String s) { String keysPath = rootNode + NODE_KEYS + "/"; CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).withACL(newNodeAcl) .forPath(keysPath, s.getBytes()); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + keysPath, e); } LOGGER.info("Added key {}", newNode); return getSeq(newNode); }
@Override public int addMasterKey(String s) { String keysPath = rootNode + NODE_KEYS + "/"; CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).withACL(newNodeAcl) .forPath(keysPath, s.getBytes()); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + keysPath, e); } LOGGER.info("Added key {}", newNode); return getSeq(newNode); }
public String createSequentailNode(CuratorFramework zk, String path, byte[] data ) throws Exception { String npath = PathUtils.normalize_path(path); String parent = PathUtils.parent_path(path); if ( !existsNode(zk,parent,false) ) { createNode(zk,parent,"".getBytes()); } return zk.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath(npath,data); }
@Override public int addMasterKey(String s) { String keysPath = rootNode + NODE_KEYS + "/"; CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).withACL(newNodeAcl) .forPath(keysPath, s.getBytes()); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + keysPath, e); } LOGGER.info("Added key {}", newNode); return getSeq(newNode); }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) { byte[] tokenBytes = HiveDelegationTokenSupport.encodeDelegationTokenInformation(token); String tokenPath = getTokenPath(tokenIdentifier); CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT).withACL(newNodeAcl) .forPath(tokenPath, tokenBytes); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + tokenPath, e); } LOGGER.info("Added token: {}", newNode); return true; }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) { byte[] tokenBytes = HiveDelegationTokenSupport.encodeDelegationTokenInformation(token); String tokenPath = getTokenPath(tokenIdentifier); CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT).withACL(newNodeAcl) .forPath(tokenPath, tokenBytes); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + tokenPath, e); } LOGGER.info("Added token: {}", newNode); return true; }