/** * Convert a {@link DeserializationException} to a more palatable {@link KeeperException}. * Used when can't let a {@link DeserializationException} out w/o changing public API. * @param e Exception to convert * @return Converted exception */ public static KeeperException convert(final DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); return ke; }
/** * Handles InterruptedExceptions in client calls. * @param ie the InterruptedException instance thrown * @throws KeeperException the exception to throw, transformed from the InterruptedException */ public void interruptedException(InterruptedException ie) throws KeeperException { interruptedExceptionNoThrow(ie, true); // Throw a system error exception to let upper level handle it KeeperException keeperException = new KeeperException.SystemErrorException(); keeperException.initCause(ie); throw keeperException; }
/** * Get master address. * Use this instead of {@link #getMasterAddress()} if you do not have an * instance of this tracker in your context. * @param zkw ZKWatcher to use * @return ServerName stored in the the master address znode or null if no * znode present. * @throws KeeperException if a ZooKeeper operation fails * @throws IOException if the address of the ZooKeeper master cannot be retrieved */ public static ServerName getMasterAddress(final ZKWatcher zkw) throws KeeperException, IOException { byte [] data; try { data = ZKUtil.getData(zkw, zkw.getZNodePaths().masterAddressZNode); } catch (InterruptedException e) { throw new InterruptedIOException(); } // TODO javadoc claims we return null in this case. :/ if (data == null){ throw new IOException("Can't get master address from ZooKeeper; znode data == null"); } try { return ProtobufUtil.parseServerNameFrom(data); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
/** * Get master info port. * Use this instead of {@link #getMasterInfoPort()} if you do not have an * instance of this tracker in your context. * @param zkw ZKWatcher to use * @return master info port in the the master address znode or null if no * znode present. * // TODO can't return null for 'int' return type. non-static verison returns 0 * @throws KeeperException if a ZooKeeper operation fails * @throws IOException if the address of the ZooKeeper master cannot be retrieved */ public static int getMasterInfoPort(final ZKWatcher zkw) throws KeeperException, IOException { byte[] data; try { data = ZKUtil.getData(zkw, zkw.getZNodePaths().masterAddressZNode); } catch (InterruptedException e) { throw new InterruptedIOException(); } // TODO javadoc claims we return null in this case. :/ if (data == null) { throw new IOException("Can't get master address from ZooKeeper; znode data == null"); } try { return parse(data).getInfoPort(); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
} catch (IOException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } catch (DeserializationException e) {
private TableState.State getTableStateInZK(ZKWatcher watcher, final TableName tableName) throws KeeperException, IOException, InterruptedException { String znode = ZNodePaths.joinZNode(watcher.getZNodePaths().tableZNode, tableName.getNameAsString()); byte [] data = ZKUtil.getData(watcher, znode); if (data == null || data.length <= 0) { return null; } try { ProtobufUtil.expectPBMagicPrefix(data); ZooKeeperProtos.DeprecatedTableState.Builder builder = ZooKeeperProtos.DeprecatedTableState.newBuilder(); int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, data, magicLen, data.length - magicLen); return TableState.State.valueOf(builder.getState().toString()); } catch (IOException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } catch (DeserializationException e) { throw ZKUtil.convert(e); } } }
/** * Convert a {@link DeserializationException} to a more palatable {@link KeeperException}. * Used when can't let a {@link DeserializationException} out w/o changing public API. * @param e Exception to convert * @return Converted exception */ public static KeeperException convert(final DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); return ke; }
/** * Convert a {@link DeserializationException} to a more palatable {@link KeeperException}. * Used when can't let a {@link DeserializationException} out w/o changing public API. * @param e Exception to convert * @return Converted exception */ public static KeeperException convert(final DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); return ke; }
/** * Convert a {@link DeserializationException} to a more palatable {@link KeeperException}. * Used when can't let a {@link DeserializationException} out w/o changing public API. * @param e Exception to convert * @return Converted exception */ public static KeeperException convert(final DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); return ke; }
/** * Convert a {@link com.alibaba.wasp.DeserializationException} to a more palatable * {@link org.apache.zookeeper.KeeperException}. Used when can't let a * {@link com.alibaba.wasp.DeserializationException} out w/o changing public API. * * @param e * Exception to convert * @return Converted exception */ public static KeeperException convert(final DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); return ke; } }
/** * Handles InterruptedExceptions in client calls. * @param ie the InterruptedException instance thrown * @throws KeeperException the exception to throw, transformed from the InterruptedException */ public void interruptedException(InterruptedException ie) throws KeeperException { interruptedExceptionNoThrow(ie, true); // Throw a system error exception to let upper level handle it KeeperException keeperException = new KeeperException.SystemErrorException(); keeperException.initCause(ie); throw keeperException; }
/** * Get master address. * Use this instead of {@link #getMasterAddress()} if you do not have an * instance of this tracker in your context. * @param zkw ZKWatcher to use * @return ServerName stored in the the master address znode or null if no * znode present. * @throws KeeperException if a ZooKeeper operation fails * @throws IOException if the address of the ZooKeeper master cannot be retrieved */ public static ServerName getMasterAddress(final ZKWatcher zkw) throws KeeperException, IOException { byte [] data; try { data = ZKUtil.getData(zkw, zkw.getZNodePaths().masterAddressZNode); } catch (InterruptedException e) { throw new InterruptedIOException(); } // TODO javadoc claims we return null in this case. :/ if (data == null){ throw new IOException("Can't get master address from ZooKeeper; znode data == null"); } try { return ProtobufUtil.parseServerNameFrom(data); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
/** * Get master address. * Use this instead of {@link #getMasterAddress()} if you do not have an * instance of this tracker in your context. * @param zkw ZooKeeperWatcher to use * @return ServerName stored in the the master address znode or null if no * znode present. * @throws KeeperException * @throws IOException */ public static ServerName getMasterAddress(final ZooKeeperWatcher zkw) throws KeeperException, IOException { byte [] data; try { data = ZKUtil.getData(zkw, zkw.getMasterAddressZNode()); } catch (InterruptedException e) { throw new InterruptedIOException(); } // TODO javadoc claims we return null in this case. :/ if (data == null){ throw new IOException("Can't get master address from ZooKeeper; znode data == null"); } try { return ServerName.parseFrom(data); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
/** * Get master address. Use this instead of {@link #getMasterAddress()} if you * do not have an instance of this tracker in your context. * * @param zkw * ZooKeeperWatcher to use * @return ServerName stored in the the master address znode or null if no * znode present. * @throws org.apache.zookeeper.KeeperException * @throws java.io.IOException */ public static ServerName getMasterAddress(final ZooKeeperWatcher zkw) throws KeeperException, IOException { byte[] data = ZKUtil.getData(zkw, zkw.getMasterAddressZNode()); if (data == null) { throw new IOException( "Can't get master address from ZooKeeper; znode data == null"); } try { return ServerName.parseFrom(data); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
} catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke;
/** * Get master info port. * Use this instead of {@link #getMasterInfoPort()} if you do not have an * instance of this tracker in your context. * @param zkw ZKWatcher to use * @return master info port in the the master address znode or null if no * znode present. * // TODO can't return null for 'int' return type. non-static verison returns 0 * @throws KeeperException if a ZooKeeper operation fails * @throws IOException if the address of the ZooKeeper master cannot be retrieved */ public static int getMasterInfoPort(final ZKWatcher zkw) throws KeeperException, IOException { byte[] data; try { data = ZKUtil.getData(zkw, zkw.getZNodePaths().masterAddressZNode); } catch (InterruptedException e) { throw new InterruptedIOException(); } // TODO javadoc claims we return null in this case. :/ if (data == null) { throw new IOException("Can't get master address from ZooKeeper; znode data == null"); } try { return parse(data).getInfoPort(); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
/** * @param zkw * @param child * @return Null or {@link org.apache.hadoop.hbase.zookeeper.ZKTable.TableState} found in znode. * @throws org.apache.zookeeper.KeeperException */ static ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw, final String child) throws KeeperException { String znode = ZKUtil.joinZNode(zkw.tableZNode, child); byte[] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) return null; try { ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table .newBuilder(); ZooKeeperProtos.Table t = builder.mergeFrom(data, 0, data.length).build(); return t.getState(); } catch (InvalidProtocolBufferException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } } }
/** * Gets table state from ZK. * @param zkw ZooKeeperWatcher instance to use * @param tableName table we're checking * @return Null or {@link ZooKeeperProtos.Table.State} found in znode. * @throws KeeperException */ private ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw, final TableName tableName) throws KeeperException, InterruptedException { String znode = ZKUtil.joinZNode(zkw.tableZNode, tableName.getNameAsString()); byte [] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) return null; try { ProtobufUtil.expectPBMagicPrefix(data); ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder(); int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, data, magicLen, data.length - magicLen); return builder.getState(); } catch (IOException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } catch (DeserializationException e) { throw ZKUtil.convert(e); } }
/** * @param zkw ZooKeeperWatcher instance to use * @param tableName table we're checking * @return Null or {@link ZooKeeperProtos.Table.State} found in znode. * @throws KeeperException */ static ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw, final TableName tableName) throws KeeperException, InterruptedException { String znode = ZKUtil.joinZNode(zkw.tableZNode, tableName.getNameAsString()); byte [] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) return null; try { ProtobufUtil.expectPBMagicPrefix(data); ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder(); int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, data, magicLen, data.length - magicLen); return builder.getState(); } catch (IOException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } catch (DeserializationException e) { throw ZKUtil.convert(e); } } }
private TableState.State getTableStateInZK(ZKWatcher watcher, final TableName tableName) throws KeeperException, IOException, InterruptedException { String znode = ZNodePaths.joinZNode(watcher.getZNodePaths().tableZNode, tableName.getNameAsString()); byte [] data = ZKUtil.getData(watcher, znode); if (data == null || data.length <= 0) { return null; } try { ProtobufUtil.expectPBMagicPrefix(data); ZooKeeperProtos.DeprecatedTableState.Builder builder = ZooKeeperProtos.DeprecatedTableState.newBuilder(); int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, data, magicLen, data.length - magicLen); return TableState.State.valueOf(builder.getState().toString()); } catch (IOException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } catch (DeserializationException e) { throw ZKUtil.convert(e); } } }