/** * Writes a set of permissions as {@link org.apache.hadoop.io.Writable} instances and returns the * resulting byte array. Writes a set of permission [user: table permission] */ public static byte[] writePermissionsAsBytes(ListMultimap<String, UserPermission> perms, Configuration conf) { return ProtobufUtil.prependPBMagic(AccessControlUtil.toUserTablePermissions(perms).toByteArray()); }
/** * Creates the labels data to be written to zookeeper. * @param existingLabels * @return Bytes form of labels and their ordinal details to be written to zookeeper. */ public static byte[] getDataToWriteToZooKeeper(Map<String, Integer> existingLabels) { VisibilityLabelsRequest.Builder visReqBuilder = VisibilityLabelsRequest.newBuilder(); for (Entry<String, Integer> entry : existingLabels.entrySet()) { VisibilityLabel.Builder visLabBuilder = VisibilityLabel.newBuilder(); visLabBuilder.setLabel(ByteString.copyFrom(Bytes.toBytes(entry.getKey()))); visLabBuilder.setOrdinal(entry.getValue()); visReqBuilder.addVisLabel(visLabBuilder.build()); } return ProtobufUtil.prependPBMagic(visReqBuilder.build().toByteArray()); }
/** * Creates the user auth data to be written to zookeeper. * @param userAuths * @return Bytes form of user auths details to be written to zookeeper. */ public static byte[] getUserAuthsDataToWriteToZooKeeper(Map<String, List<Integer>> userAuths) { MultiUserAuthorizations.Builder builder = MultiUserAuthorizations.newBuilder(); for (Entry<String, List<Integer>> entry : userAuths.entrySet()) { UserAuthorizations.Builder userAuthsBuilder = UserAuthorizations.newBuilder(); userAuthsBuilder.setUser(ByteString.copyFrom(Bytes.toBytes(entry.getKey()))); for (Integer label : entry.getValue()) { userAuthsBuilder.addAuth(label); } builder.addUserAuths(userAuthsBuilder.build()); } return ProtobufUtil.prependPBMagic(builder.build().toByteArray()); }
zkOps.add(ZKUtil.ZKUtilOp.deleteNodeFailSilent(znode)); zkOps.add(ZKUtil.ZKUtilOp.createAndFailSilent(znode, ProtobufUtil.prependPBMagic(proto.toByteArray())));
private void updateZooKeeper(TableState tableState) throws IOException { if (tableState == null) { return; } String znode = ZNodePaths.joinZNode(this.master.getZooKeeper().getZNodePaths().tableZNode, tableState.getTableName().getNameAsString()); try { // Make sure znode exists. if (ZKUtil.checkExists(this.master.getZooKeeper(), znode) == -1) { ZKUtil.createAndFailSilent(this.master.getZooKeeper(), znode); } // Now set newState ZooKeeperProtos.DeprecatedTableState.Builder builder = ZooKeeperProtos.DeprecatedTableState.newBuilder(); builder.setState( ZooKeeperProtos.DeprecatedTableState.State.valueOf(tableState.getState().toString())); byte[] data = ProtobufUtil.prependPBMagic(builder.build().toByteArray()); ZKUtil.setData(this.master.getZooKeeper(), znode, data); } catch (KeeperException e) { // Only hbase1 clients suffer if this fails. LOG.warn("Failed setting table state to zookeeper mirrored for hbase-1.x clients", e); } }
/** * @return This instance serialized into a byte array * @see #parseFrom(byte[]) */ public byte [] toByteArray() { return ProtobufUtil.prependPBMagic(this.rt.toByteArray()); } }
/** * Use this when writing to a stream and you want to use the pb mergeDelimitedFrom * (w/o the delimiter, pb reads to EOF which may not be what you want). * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException */ byte [] toByteArray() throws IOException { return ProtobufUtil.prependPBMagic(convert().toByteArray()); }
/** * @return This instance serialized with pb with pb magic prefix * @see #parseFrom(byte[]) */ public byte [] toByteArray() { return ProtobufUtil.prependPBMagic(convert().toByteArray()); }
/** * @param peerConfig * @return Serialized protobuf of <code>peerConfig</code> with pb magic prefix prepended suitable * for use as content of a this.peersZNode; i.e. the content of PEER_ID znode under * /hbase/replication/peers/PEER_ID */ private static byte[] toByteArray(final ReplicationPeerConfig peerConfig) { byte[] bytes = convert(peerConfig).toByteArray(); return ProtobufUtil.prependPBMagic(bytes); }
/** * @return The clusterid serialized using pb w/ pb magic prefix */ public byte [] toByteArray() { return ProtobufUtil.prependPBMagic(convert().toByteArray()); }
/** * @return This instance serialized with pb with pb magic prefix * @see #parseFrom(byte[]) */ public byte [] toByteArray() { return ProtobufUtil.prependPBMagic(convert().toByteArray()); }
/** * @return Content of the clusterup znode as a serialized pb with the pb * magic as prefix. */ static byte [] toByteArray() { ZooKeeperProtos.ClusterUp.Builder builder = ZooKeeperProtos.ClusterUp.newBuilder(); builder.setStartDate(new java.util.Date().toString()); return ProtobufUtil.prependPBMagic(builder.build().toByteArray()); } }
private void migrateClusterKeyToPB(ZooKeeperWatcher zkw, String peerZnode, byte[] data) throws KeeperException, NoNodeException { ReplicationPeer peer = ZooKeeperProtos.ReplicationPeer.newBuilder() .setClusterkey(Bytes.toString(data)).build(); ZKUtil.setData(zkw, peerZnode, ProtobufUtil.prependPBMagic(peer.toByteArray())); }
/** * Create the content to write into the ${HBASE_ROOTDIR}/hbase.version file. * @param version Version to persist * @return Serialized protobuf with <code>version</code> content and a bit of pb magic for a prefix. */ static byte [] toVersionByteArray(final String version) { FSProtos.HBaseVersionFileContent.Builder builder = FSProtos.HBaseVersionFileContent.newBuilder(); return ProtobufUtil.prependPBMagic(builder.setVersion(version).build().toByteArray()); }
private byte [] toByteArray(boolean isBalancerOn) { LoadBalancerProtos.LoadBalancerState.Builder builder = LoadBalancerProtos.LoadBalancerState.newBuilder(); builder.setBalancerOn(isBalancerOn); return ProtobufUtil.prependPBMagic(builder.build().toByteArray()); }
/** * @param lockOwner * @return Serialized protobuf of <code>lockOwner</code> with pb magic prefix prepended suitable * for use as content of an replication lock during region server fail over. */ static byte[] lockToByteArray(final String lockOwner) { byte[] bytes = ZooKeeperProtos.ReplicationLock.newBuilder().setLockOwner(lockOwner).build().toByteArray(); return ProtobufUtil.prependPBMagic(bytes); } }
/** * @param state * @return Serialized protobuf of <code>state</code> with pb magic prefix prepended suitable for * use as content of a peer-state znode under a peer cluster id as in * /hbase/replication/peers/PEER_ID/peer-state. */ protected static byte[] toByteArray(final ZooKeeperProtos.ReplicationState.State state) { byte[] bytes = ZooKeeperProtos.ReplicationState.newBuilder().setState(state).build().toByteArray(); return ProtobufUtil.prependPBMagic(bytes); }
/** * @param position * @return Serialized protobuf of <code>position</code> with pb magic prefix prepended suitable * for use as content of an wal position in a replication queue. */ public static byte[] positionToByteArray(final long position) { byte[] bytes = ZooKeeperProtos.ReplicationHLogPosition.newBuilder().setPosition(position) .build().toByteArray(); return ProtobufUtil.prependPBMagic(bytes); }
/** * @param position * @return Serialized protobuf of <code>position</code> with pb magic prefix prepended suitable * for use as content of an wal position in a replication queue. */ public static byte[] positionToByteArray(final long position) { byte[] bytes = ZooKeeperProtos.ReplicationHLogPosition.newBuilder().setPosition(position) .build().toByteArray(); return ProtobufUtil.prependPBMagic(bytes); }
private void createMyEphemeralNode() throws KeeperException, IOException { RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder(); rsInfo.setInfoPort(infoServer != null ? infoServer.getPort() : -1); rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo()); byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray()); ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data); }