/** * @param bytes A pb serialized {@link ClusterId} instance with pb magic prefix * @return An instance of {@link ClusterId} made from <code>bytes</code> * @throws DeserializationException * @see #toByteArray() */ public static ClusterId parseFrom(final byte [] bytes) throws DeserializationException { if (ProtobufUtil.isPBMagicPrefix(bytes)) { int pblen = ProtobufUtil.lengthOfPBMagic(); ClusterIdProtos.ClusterId.Builder builder = ClusterIdProtos.ClusterId.newBuilder(); ClusterIdProtos.ClusterId cid = null; try { ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen); cid = builder.build(); } catch (IOException e) { throw new DeserializationException(e); } return convert(cid); } else { // Presume it was written out this way, the old way. return new ClusterId(Bytes.toString(bytes)); } }
public static void setClusterId(ZKWatcher watcher, ClusterId id) throws KeeperException { ZKUtil.createSetData(watcher, watcher.getZNodePaths().clusterIdZNode, id.toByteArray()); }
/** * @param cid * @return A {@link ClusterId} made from the passed in <code>cid</code> */ public static ClusterId convert(final ClusterIdProtos.ClusterId cid) { return new ClusterId(cid.getClusterId()); }
@Override protected void chore() { if (!isConnected()) { return; } List<ServerName> sns = generateDeadServersListToSend(); if (sns.isEmpty()) { // Nothing to send. Done. return; } final long curTime = EnvironmentEdgeManager.currentTime(); if (lastMessageTime > curTime - messagePeriod) { // We already sent something less than 10 second ago. Done. return; } // Ok, we're going to send something then. lastMessageTime = curTime; // We're reusing an existing protobuf message, but we don't send everything. // This could be extended in the future, for example if we want to send stuff like the // hbase:meta server name. publisher.publish(ClusterMetricsBuilder.newBuilder() .setHBaseVersion(VersionInfo.getVersion()) .setClusterId(master.getMasterFileSystem().getClusterId().toString()) .setMasterName(master.getServerName()) .setDeadServerNames(sns) .build()); }
/** * @return The clusterid serialized using pb w/ pb magic prefix */ public byte [] toByteArray() { return ProtobufUtil.prependPBMagic(convert().toByteArray()); }
FSUtils.setClusterId(fs, rd, new ClusterId(), c.getInt(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000));
status.setStatus("Publishing Cluster ID " + clusterId + " in ZooKeeper"); ZKClusterId.setClusterId(this.zooKeeper, fileSystemManager.getClusterId()); this.clusterId = clusterId.toString();
/** * @return The clusterid serialized using pb w/ pb magic prefix */ public byte [] toByteArray() { return ProtobufUtil.prependPBMagic(convert().toByteArray()); }
public static String readClusterIdZNode(ZKWatcher watcher) throws KeeperException { if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().clusterIdZNode) != -1) { byte [] data; try { data = ZKUtil.getData(watcher, watcher.getZNodePaths().clusterIdZNode); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return null; } if (data != null) { try { return ClusterId.parseFrom(data).toString(); } catch (DeserializationException e) { throw ZKUtil.convert(e); } } } return null; }
private static String initPeerClusterState(String baseZKNode) throws IOException, KeeperException { // Add a dummy region server and set up the cluster id Configuration testConf = new Configuration(conf); testConf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, baseZKNode); ZKWatcher zkw1 = new ZKWatcher(testConf, "test1", null); String fakeRs = ZNodePaths.joinZNode(zkw1.getZNodePaths().rsZNode, "hostname1.example.org:1234"); ZKUtil.createWithParents(zkw1, fakeRs); ZKClusterId.setClusterId(zkw1, new ClusterId()); return ZKConfig.getZooKeeperClusterKey(testConf); }
master.getMasterFileSystem().getClusterId().toString(), null, sns,
s.write(clusterId.toByteArray()); s.close(); s = null;
/** * @return The clusterid serialized using pb w/ pb magic prefix */ public byte [] toByteArray() { return ProtobufUtil.prependPBMagic(convert().toByteArray()); }