List of usage examples for org.apache.zookeeper Op getPath
public String getPath()
From source file:com.navercorp.nbasearc.confmaster.server.ZooKeeperHolder.java
License:Apache License
public List<OpResult> multi(Iterable<Op> ops) throws MgmtZooKeeperException { try {/*from www . j a v a 2 s . co m*/ for (Op op : ops) { if (op.getType() == create || op.getType() == delete || op.getType() == setData) { ThreadLocalVariableHolder.checkPermission(op.getPath(), WRITE); } else if (op.getType() == getData || op.getType() == exists || op.getType() == getChildren) { ThreadLocalVariableHolder.checkPermission(op.getPath(), READ); } } return zk.multi(ops); } catch (KeeperException e) { Logger.error("Multi operation fail. {}, {}", e.getPath(), ops, e); throw new MgmtZooKeeperException(e); } catch (InterruptedException e) { Logger.error("Multi operation fail. {}", ops, e); throw new MgmtZooKeeperException(e); } }
From source file:org.lab.mars.onem2m.ZooKeeper.java
License:Apache License
private Op withRootPrefix(Op op) { if (null != op.getPath()) { final String serverPath = prependChroot(op.getPath()); if (!op.getPath().equals(serverPath)) { return op.withChroot(serverPath); }//from w ww . j a va 2 s .c o m } return op; }
From source file:org.midonet.midolman.state.ZkManager.java
License:Apache License
public List<OpResult> multiDedup(List<Op> ops) throws StateAccessException { Set<String> paths = new HashSet<String>(ops.size()); List<Op> dedupOps = new ArrayList<Op>(ops.size()); for (Op op : ops) { String path = op.getPath(); if (!paths.contains(path)) { paths.add(path);//from ww w .j av a2s . c om dedupOps.add(op); } } return multi(dedupOps); }
From source file:org.midonet.midolman.state.ZkManager.java
License:Apache License
private String getMultiErrorMessage(List<Op> ops, KeeperException ex) { List<OpResult> results = ex.getResults(); if (results == null || results.isEmpty()) { return "executing multi ops: " + ex.getMessage(); }/* ww w . ja v a 2 s . c om*/ StringBuilder msg = new StringBuilder("executing multi ops: "); // Use counter to iterate through op and result lists in parallel. for (int i = 0; i < results.size(); i++) { OpResult result = results.get(i); if (result instanceof OpResult.ErrorResult) { int errorCode = ((OpResult.ErrorResult) result).getErr(); if (errorCode != 0) { Op operation = ops.get(i); msg.append("\r\n\t\t"); msg.append(operation.getPath()); msg.append(" failed with error code: "); msg.append(errorCode); } } } return msg.toString(); }
From source file:org.midonet.midolman.state.ZkOpList.java
License:Apache License
private static String getOpDesc(Op op) { return ZooDefs.opNames[op.getType()] + " " + op.getPath(); }
From source file:org.midonet.midolman.state.ZkOpList.java
License:Apache License
private static int remove(List<Op> ops, String path) { int cnt = 0;// w w w . j a v a 2 s . co m for (Iterator<Op> it = ops.iterator(); it.hasNext();) { Op op = it.next(); if (op.getPath().equals(path)) { logger.warn("Removing path Op: {}.", getOpDesc(op)); it.remove(); cnt++; } } return cnt; }
From source file:org.midonet.midolman.state.ZkOpList.java
License:Apache License
private void addChildrenDelOps(String rootPath) throws StateAccessException { List<Op> ops = this.zkManager.getRecursiveDeleteOps(rootPath); for (Op op : ops) { String path = op.getPath(); if (!this.deleteOps.containsKey(path)) { this.deleteOps.put(path, op); }//from w w w. java2 s.c o m } }
From source file:org.midonet.midolman.state.ZkOpList.java
License:Apache License
private void tryCommit(int delRetries) throws StateAccessException { logger.debug("Trying commit with delete retries: {}", delRetries); dump();//from w w w . j a v a 2 s . c o m List<Op> ops = combine(); try { this.zkManager.multi(ops); } catch (NoStatePathException ex) { // For deletion, if a node was deleted, just skip it and retry. Op errorOp = getErrorDelOpOrThrow(ex, ops); removeStartsWith(this.deleteOps, errorOp.getPath()); tryCommit(delRetries); } catch (NodeNotEmptyStateException ex) { // For deletion, if a child node was added, try to re-fetch all // children from the parent node and try again, but with a limit on // the number of retries. Op errorOp = getErrorDelOpOrThrow(ex, ops); delRetries = decrementOrThrow(delRetries, ex); addChildrenDelOps(errorOp.getPath()); tryCommit(delRetries); } }
From source file:org.midonet.midolman.state.ZkOpList.java
License:Apache License
/** * Add an Op object./* w w w. ja v a 2 s . c o m*/ * * For delete Op, all the previously added updated and delete Ops are * replaced by this one. If there was a create Op prior to it, delete Op is * not added, and the create Op is removed. * * For create Op, if another create Op already exists, this replaces it. * * @param op Op object to add */ public void add(Op op) { Preconditions.checkNotNull(op); Preconditions.checkArgument(validOpType(op.getType())); int type = op.getType(); if (type == ZooDefs.OpCode.delete) { // Remove any updates previously added remove(this.updateOps, op.getPath()); // Remove any create added but if there was a create, there is no // need to add the delete Op if (this.createOps.containsKey(op.getPath())) { this.createOps.remove(op.getPath()); return; } // Replace any delete previously added this.deleteOps.put(op.getPath(), op); } else if (type == ZooDefs.OpCode.create) { // Replace the previously added create this.createOps.put(op.getPath(), op); } else if (type == ZooDefs.OpCode.setData) { // For updates, just add to the list this.updateOps.add(op); } }