Search in sources :

Example 1 with RegionInTransition

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition in project hbase by apache.

the class ProtobufUtil method convert.

/**
   * Convert a protobuf ClusterStatus to a ClusterStatus
   *
   * @param proto the protobuf ClusterStatus
   * @return the converted ClusterStatus
   */
public static ClusterStatus convert(ClusterStatusProtos.ClusterStatus proto) {
    Map<ServerName, ServerLoad> servers = null;
    servers = new HashMap<>(proto.getLiveServersList().size());
    for (LiveServerInfo lsi : proto.getLiveServersList()) {
        servers.put(ProtobufUtil.toServerName(lsi.getServer()), new ServerLoad(lsi.getServerLoad()));
    }
    Collection<ServerName> deadServers = null;
    deadServers = new ArrayList<>(proto.getDeadServersList().size());
    for (HBaseProtos.ServerName sn : proto.getDeadServersList()) {
        deadServers.add(ProtobufUtil.toServerName(sn));
    }
    Collection<ServerName> backupMasters = null;
    backupMasters = new ArrayList<>(proto.getBackupMastersList().size());
    for (HBaseProtos.ServerName sn : proto.getBackupMastersList()) {
        backupMasters.add(ProtobufUtil.toServerName(sn));
    }
    Set<RegionState> rit = null;
    rit = new HashSet<>(proto.getRegionsInTransitionList().size());
    for (RegionInTransition region : proto.getRegionsInTransitionList()) {
        RegionState value = RegionState.convert(region.getRegionState());
        rit.add(value);
    }
    String[] masterCoprocessors = null;
    final int numMasterCoprocessors = proto.getMasterCoprocessorsCount();
    masterCoprocessors = new String[numMasterCoprocessors];
    for (int i = 0; i < numMasterCoprocessors; i++) {
        masterCoprocessors[i] = proto.getMasterCoprocessors(i).getName();
    }
    return new ClusterStatus(proto.getHbaseVersion().getVersion(), ClusterId.convert(proto.getClusterId()).toString(), servers, deadServers, ProtobufUtil.toServerName(proto.getMaster()), backupMasters, rit, masterCoprocessors, proto.getBalancerOn());
}
Also used : ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionInTransition(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition) RegionState(org.apache.hadoop.hbase.master.RegionState) LiveServerInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.LiveServerInfo) ServerName(org.apache.hadoop.hbase.ServerName) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 2 with RegionInTransition

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition in project hbase by apache.

the class ProtobufUtil method convert.

/**
   * Convert a ClusterStatus to a protobuf ClusterStatus
   *
   * @return the protobuf ClusterStatus
   */
public static ClusterStatusProtos.ClusterStatus convert(ClusterStatus status) {
    ClusterStatusProtos.ClusterStatus.Builder builder = ClusterStatusProtos.ClusterStatus.newBuilder();
    builder.setHbaseVersion(HBaseVersionFileContent.newBuilder().setVersion(status.getHBaseVersion()));
    if (status.getServers() != null) {
        for (ServerName serverName : status.getServers()) {
            LiveServerInfo.Builder lsi = LiveServerInfo.newBuilder().setServer(ProtobufUtil.toServerName(serverName));
            status.getLoad(serverName);
            lsi.setServerLoad(status.getLoad(serverName).obtainServerLoadPB());
            builder.addLiveServers(lsi.build());
        }
    }
    if (status.getDeadServerNames() != null) {
        for (ServerName deadServer : status.getDeadServerNames()) {
            builder.addDeadServers(ProtobufUtil.toServerName(deadServer));
        }
    }
    if (status.getRegionsInTransition() != null) {
        for (RegionState rit : status.getRegionsInTransition()) {
            ClusterStatusProtos.RegionState rs = rit.convert();
            RegionSpecifier.Builder spec = RegionSpecifier.newBuilder().setType(RegionSpecifierType.REGION_NAME);
            spec.setValue(UnsafeByteOperations.unsafeWrap(rit.getRegion().getRegionName()));
            RegionInTransition pbRIT = RegionInTransition.newBuilder().setSpec(spec.build()).setRegionState(rs).build();
            builder.addRegionsInTransition(pbRIT);
        }
    }
    if (status.getClusterId() != null) {
        builder.setClusterId(new ClusterId(status.getClusterId()).convert());
    }
    if (status.getMasterCoprocessors() != null) {
        for (String coprocessor : status.getMasterCoprocessors()) {
            builder.addMasterCoprocessors(HBaseProtos.Coprocessor.newBuilder().setName(coprocessor));
        }
    }
    if (status.getMaster() != null) {
        builder.setMaster(ProtobufUtil.toServerName(status.getMaster()));
    }
    if (status.getBackupMasters() != null) {
        for (ServerName backup : status.getBackupMasters()) {
            builder.addBackupMasters(ProtobufUtil.toServerName(backup));
        }
    }
    if (status.getBalancerOn() != null) {
        builder.setBalancerOn(status.getBalancerOn());
    }
    return builder.build();
}
Also used : ClusterStatusProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos) ClusterId(org.apache.hadoop.hbase.ClusterId) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier) RegionInTransition(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition) RegionState(org.apache.hadoop.hbase.master.RegionState) LiveServerInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.LiveServerInfo) ServerName(org.apache.hadoop.hbase.ServerName) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Aggregations

ClusterStatus (org.apache.hadoop.hbase.ClusterStatus)2 ServerName (org.apache.hadoop.hbase.ServerName)2 RegionState (org.apache.hadoop.hbase.master.RegionState)2 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)2 LiveServerInfo (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.LiveServerInfo)2 RegionInTransition (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition)2 ClusterId (org.apache.hadoop.hbase.ClusterId)1 ServerLoad (org.apache.hadoop.hbase.ServerLoad)1 ClusterStatusProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos)1 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)1 RegionSpecifier (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)1