/** * Copy one Writable to another. Copies bytes using data streams. * @param src Source Writable * @param tgt Target Writable * @return The target Writable. * @throws IOException e */ public static Writable copyWritable(final Writable src, final Writable tgt) throws IOException { return copyWritable(getBytes(src), tgt); }
/** * Put a bunch of Writables as bytes all into the one byte array. * @param ws writable * @return The bytes of <code>w</code> gotten by running its * {@link Writable#write(java.io.DataOutput)} method. * @throws IOException e */ public static byte [] getBytes(final Writable... ws) throws IOException { List<byte []> bytes = new ArrayList<>(ws.length); int size = 0; for (Writable w: ws) { byte [] b = getBytes(w); size += b.length; bytes.add(b); } byte [] result = new byte[size]; int offset = 0; for (byte [] b: bytes) { System.arraycopy(b, 0, result, offset, b.length); offset += b.length; } return result; }
public void addKeyToZK(AuthenticationKey key) { String keyZNode = getKeyNode(key.getKeyId()); try { byte[] keyData = Writables.getBytes(key); // TODO: is there any point in retrying beyond what ZK client does? ZKUtil.createSetData(watcher, keyZNode, keyData); } catch (KeeperException ke) { LOG.error(HBaseMarkers.FATAL, "Unable to synchronize master key "+key.getKeyId()+ " to znode "+keyZNode, ke); watcher.abort("Unable to synchronize secret key "+ key.getKeyId()+" in zookeeper", ke); } catch (IOException ioe) { // this can only happen from an error serializing the key watcher.abort("Failed serializing key "+key.getKeyId(), ioe); } }
public void updateKeyInZK(AuthenticationKey key) { String keyZNode = getKeyNode(key.getKeyId()); try { byte[] keyData = Writables.getBytes(key); try { ZKUtil.updateExistingNodeData(watcher, keyZNode, keyData, -1); } catch (KeeperException.NoNodeException ne) { // node was somehow removed, try adding it back ZKUtil.createSetData(watcher, keyZNode, keyData); } } catch (KeeperException ke) { LOG.error(HBaseMarkers.FATAL, "Unable to update master key "+key.getKeyId()+ " in znode "+keyZNode); watcher.abort("Unable to synchronize secret key "+ key.getKeyId()+" in zookeeper", ke); } catch (IOException ioe) { // this can only happen from an error serializing the key watcher.abort("Failed serializing key "+key.getKeyId(), ioe); } }
@Override public byte[] toByteArray() throws IOException { return Writables.getBytes(this); }
@Override public byte[] toByteArray() throws IOException { return Writables.getBytes(this); }
@Override public byte[] toByteArray() throws IOException { return Writables.getBytes(this); }
@Override public byte[] toByteArray() throws IOException { return Writables.getBytes(this); }
@Override public byte[] toByteArray() throws IOException { return Writables.getBytes(this); }
@Test public void testRefreshKeys() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); ZKWatcher zk = newZK(conf, "127.0.0.1", new MockAbortable()); AuthenticationTokenSecretManager keyManager = new AuthenticationTokenSecretManager(conf, zk, "127.0.0.1", 60 * 60 * 1000, 60 * 1000); ZKSecretWatcher watcher = new ZKSecretWatcher(conf, zk, keyManager); ZKUtil.deleteChildrenRecursively(zk, watcher.getKeysParentZNode()); Integer[] keys = { 1, 2, 3, 4, 5, 6 }; for (Integer key : keys) { AuthenticationKey ak = new AuthenticationKey(key, System.currentTimeMillis() + 600 * 1000, null); ZKUtil.createWithParents(zk, ZNodePaths.joinZNode(watcher.getKeysParentZNode(), key.toString()), Writables.getBytes(ak)); } Assert.assertNull(keyManager.getCurrentKey()); watcher.refreshKeys(); for (Integer key : keys) { Assert.assertNotNull(keyManager.getKey(key.intValue())); } } }
/** * Copy one Writable to another. Copies bytes using data streams. * @param src Source Writable * @param tgt Target Writable * @return The target Writable. * @throws IOException e */ public static Writable copyWritable(final Writable src, final Writable tgt) throws IOException { return copyWritable(getBytes(src), tgt); }
/** * Put a bunch of Writables as bytes all into the one byte array. * @param ws writable * @return The bytes of <code>w</code> gotten by running its * {@link Writable#write(java.io.DataOutput)} method. * @throws IOException e */ public static byte [] getBytes(final Writable... ws) throws IOException { List<byte []> bytes = new ArrayList<>(ws.length); int size = 0; for (Writable w: ws) { byte [] b = getBytes(w); size += b.length; bytes.add(b); } byte [] result = new byte[size]; int offset = 0; for (byte [] b: bytes) { System.arraycopy(b, 0, result, offset, b.length); offset += b.length; } return result; }
private static Put addRegionInfo(final Put p, final HRegionInfo hri) throws IOException { p.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables.getBytes(hri)); return p; }
private static int tickleNodeSplit(ZooKeeperWatcher zkw, HRegionInfo parent, HRegionInfo a, HRegionInfo b, ServerName serverName, final int znodeVersion) throws KeeperException, IOException { byte [] payload = Writables.getBytes(a, b); return ZKAssign.transitionNode(zkw, parent, serverName, EventType.RS_ZK_REGION_SPLIT, EventType.RS_ZK_REGION_SPLIT, znodeVersion, payload); } }
/** * Copy one Writable to another. Copies bytes using data streams. * @param src Source Writable * @param tgt Target Writable * @return The target Writable. * @throws IOException e */ public static Writable copyWritable(final Writable src, final Writable tgt) throws IOException { return copyWritable(getBytes(src), tgt); }
private static Put makePutFromRegionInfo(HRegionInfo regionInfo) throws IOException { Put put = new Put(regionInfo.getRegionName()); put.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables.getBytes(regionInfo)); return put; }
/** * Copy one Writable to another. Copies bytes using data streams. * @param src Source Writable * @param tgt Target Writable * @return The target Writable. * @throws IOException e */ public static Writable copyWritable(final Writable src, final Writable tgt) throws IOException { return copyWritable(getBytes(src), tgt); }
/** * Copy one Writable to another. Copies bytes using data streams. * @param src Source Writable * @param tgt Target Writable * @return The target Writable. * @throws IOException e */ public static Writable copyWritable(final Writable src, final Writable tgt) throws IOException { return copyWritable(getBytes(src), tgt); }
static void checkSplit(final Result r, final Put p, final byte [] which) throws IOException { byte [] hriSplitBytes = getBytes(r, which); if (!isMigrated(hriSplitBytes)) { // This will convert the HRI from 090 to 092 HRI. HRegionInfo hri = Writables.getHRegionInfo(hriSplitBytes); p.add(HConstants.CATALOG_FAMILY, which, Writables.getBytes(hri)); } }
/** * Puts the specified HRegionInfo into META. */ public static void fixMetaHoleOnline(Configuration conf, HRegionInfo hri) throws IOException { Put p = new Put(hri.getRegionName()); p.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables.getBytes(hri)); HTable meta = new HTable(conf, HConstants.META_TABLE_NAME); meta.put(p); meta.close(); }