@Override public String createData(String path, byte[] data, CreateMode mode) throws NoSuchElementException, AlreadyExistsException, IOException, KeeperException, InterruptedException { try { return zkClient.create(path, data, mode, true); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.NodeExistsException e) { throw new AlreadyExistsException(path); } catch (InterruptedException e) { throw e; } }
public void atomicUpdate(String path, Function<byte[], byte[]> editor) throws KeeperException, InterruptedException { for (; ; ) { byte[] modified = null; byte[] zkData = null; Stat s = new Stat(); try { if (exists(path, true)) { zkData = getData(path, null, s, true); modified = editor.apply(zkData); if (modified == null) { //no change , no need to persist return; } setData(path, modified, s.getVersion(), true); break; } else { modified = editor.apply(null); if (modified == null) { //no change , no need to persist return; } create(path, modified, CreateMode.PERSISTENT, true); break; } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { continue; } } }
Map properties = new LinkedHashMap(); properties.put(propertyName, propertyValue); client.create(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT, true);
Map<String, String> properties = new LinkedHashMap<>(); properties.put(propertyName, propertyValue); client.create(znodePath, Utils.toJSON(properties), CreateMode.PERSISTENT, true);
@Override public void distribSetUp() throws Exception { super.distribSetUp(); // ignoreException(".*"); if (sliceCount > 0) { System.setProperty("numShards", Integer.toString(sliceCount)); } else { System.clearProperty("numShards"); } if (isSSLMode()) { System.clearProperty("urlScheme"); try (ZkStateReader zkStateReader = new ZkStateReader(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT)) { try { zkStateReader.getZkClient().create(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(Collections.singletonMap("urlScheme", "https")), CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { ZkNodeProps props = ZkNodeProps.load(zkStateReader.getZkClient().getData(ZkStateReader.CLUSTER_PROPS, null, null, true)); zkStateReader.getZkClient().setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus("urlScheme", "https")), true); } } } if (useTlogReplicas()) { log.info("Will use {} replicas unless explicitly asked otherwise", Replica.Type.TLOG); } else { log.info("Will use {} replicas unless explicitly asked otherwise", Replica.Type.NRT); } }
Map properties = new LinkedHashMap(); properties.put(propertyName, propertyValue); getZkClient().create(CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT, true);