List of usage examples for org.apache.zookeeper KeeperException getResults
public List<OpResult> getResults()
From source file:com.twitter.distributedlog.impl.federated.FederatedZKLogMetadataStore.java
License:Apache License
void createLogInNamespaceSync(URI uri, String logName) throws InterruptedException, IOException, KeeperException { Transaction txn = zkc.get().transaction(); // we don't have the zk version yet. set it to 0 instead of -1, to prevent non CAS operation. int zkVersion = null == zkSubnamespacesVersion.get() ? 0 : zkSubnamespacesVersion.get(); txn.setData(zkSubnamespacesPath, uri.getPath().getBytes(UTF_8), zkVersion); String logPath = uri.getPath() + "/" + logName; txn.create(logPath, new byte[0], zkc.getDefaultACL(), CreateMode.PERSISTENT); try {//from w ww . j a v a 2s . c o m txn.commit(); // if the transaction succeed, the zk version is advanced setZkSubnamespacesVersion(zkVersion + 1); } catch (KeeperException ke) { List<OpResult> opResults = ke.getResults(); OpResult createResult = opResults.get(1); if (createResult instanceof OpResult.ErrorResult) { OpResult.ErrorResult errorResult = (OpResult.ErrorResult) createResult; if (Code.NODEEXISTS.intValue() == errorResult.getErr()) { throw new LogExistsException("Log " + logName + " already exists"); } } OpResult setResult = opResults.get(0); if (setResult instanceof OpResult.ErrorResult) { OpResult.ErrorResult errorResult = (OpResult.ErrorResult) setResult; if (Code.BADVERSION.intValue() == errorResult.getErr()) { throw KeeperException.create(Code.BADVERSION); } } throw new ZKException("ZK exception in creating log " + logName + " in " + uri, ke); } }
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(); }/* w w w . j a v a2s. c o m*/ 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.ZkNatBlockAllocator.java
License:Apache License
private void ensureIpPath(final NatRange natRange, final Callback<NatBlock, Exception> callback) { String path = paths.getNatIpPath(natRange.deviceId, natRange.ip); final List<Op> dirs = new ArrayList<>(NatBlock.TOTAL_BLOCKS + 1); dirs.add(Op.create(path, null, acl, CreateMode.PERSISTENT)); initializeBlockDirectories(dirs, natRange); reactor.submit(new Runnable() { @Override/* ww w .j a va 2s . c om*/ public void run() { try { zk.getZooKeeper().multi(dirs); allocateBlockInRange(natRange, callback); } catch (InterruptedException ignored) { } catch (KeeperException e) { int error = e.getResults().get(0).getType(); if (error == KeeperException.Code.NODEEXISTS.intValue()) { allocateBlockInRange(natRange, callback); } else { callback.onError(e); } } } }); }
From source file:org.midonet.midolman.state.ZkUtil.java
License:Apache License
/** * Retrieve the Op object corresponding to the erroneous OpResult. * Error results and ops arguments must have the same size. * * @param ex KeeperException to get the OpResult list from * @param ops Op list submitted to mutli * @return Op that failed// w ww. ja v a 2 s.c o m */ public static Op getErrorOp(KeeperException ex, List<Op> ops) { Preconditions.checkNotNull(ex); Preconditions.checkNotNull(ops); return getErrorOp(ex.getResults(), ops); }