/**
   * Convert a ClutserStatus to a protobuf ClusterStatus
   *
   * @return the protobuf ClusterStatus
   */
  public ClusterStatusProtos.ClusterStatus convert() {
    ClusterStatusProtos.ClusterStatus.Builder builder =
        ClusterStatusProtos.ClusterStatus.newBuilder();
    builder.setHbaseVersion(HBaseVersionFileContent.newBuilder().setVersion(getHBaseVersion()));

    for (Map.Entry<ServerName, ServerLoad> entry : liveServers.entrySet()) {
      LiveServerInfo.Builder lsi =
          LiveServerInfo.newBuilder().setServer(ProtobufUtil.toServerName(entry.getKey()));
      lsi.setServerLoad(entry.getValue().obtainServerLoadPB());
      builder.addLiveServers(lsi.build());
    }
    for (ServerName deadServer : getDeadServerNames()) {
      builder.addDeadServers(ProtobufUtil.toServerName(deadServer));
    }
    for (Map.Entry<String, RegionState> rit : getRegionsInTransition().entrySet()) {
      ClusterStatusProtos.RegionState rs = rit.getValue().convert();
      RegionSpecifier.Builder spec =
          RegionSpecifier.newBuilder().setType(RegionSpecifierType.REGION_NAME);
      spec.setValue(ByteString.copyFrom(Bytes.toBytes(rit.getKey())));

      RegionInTransition pbRIT =
          RegionInTransition.newBuilder().setSpec(spec.build()).setRegionState(rs).build();
      builder.addRegionsInTransition(pbRIT);
    }
    builder.setClusterId(new ClusterId(getClusterId()).convert());
    for (String coprocessor : getMasterCoprocessors()) {
      builder.addMasterCoprocessors(HBaseProtos.Coprocessor.newBuilder().setName(coprocessor));
    }
    builder.setMaster(ProtobufUtil.toServerName(getMaster()));
    for (ServerName backup : getBackupMasters()) {
      builder.addBackupMasters(ProtobufUtil.toServerName(backup));
    }
    builder.setBalancerOn(balancerOn);
    return builder.build();
  }
 /**
  * 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 = new HashMap<ServerName, ServerLoad>();
   for (LiveServerInfo lsi : proto.getLiveServersList()) {
     servers.put(ProtobufUtil.toServerName(lsi.getServer()), new ServerLoad(lsi.getServerLoad()));
   }
   Collection<ServerName> deadServers = new LinkedList<ServerName>();
   for (HBaseProtos.ServerName sn : proto.getDeadServersList()) {
     deadServers.add(ProtobufUtil.toServerName(sn));
   }
   Collection<ServerName> backupMasters = new LinkedList<ServerName>();
   for (HBaseProtos.ServerName sn : proto.getBackupMastersList()) {
     backupMasters.add(ProtobufUtil.toServerName(sn));
   }
   final Map<String, RegionState> rit = new HashMap<String, RegionState>();
   for (RegionInTransition region : proto.getRegionsInTransitionList()) {
     String key = new String(region.getSpec().getValue().toByteArray());
     RegionState value = RegionState.convert(region.getRegionState());
     rit.put(key, value);
   }
   final int numMasterCoprocessors = proto.getMasterCoprocessorsCount();
   final String[] 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());
 }
示例#3
0
  @Test(timeout = 300000)
  public void testClusterRequests() throws Exception {

    // sending fake request to master to see how metric value has changed
    RegionServerStatusProtos.RegionServerReportRequest.Builder request =
        RegionServerStatusProtos.RegionServerReportRequest.newBuilder();
    ServerName serverName = cluster.getMaster(0).getServerName();
    request.setServer(ProtobufUtil.toServerName(serverName));

    MetricsMasterSource masterSource = master.getMasterMetrics().getMetricsSource();
    ClusterStatusProtos.ServerLoad sl =
        ClusterStatusProtos.ServerLoad.newBuilder().setTotalNumberOfRequests(10000).build();
    masterSource.init();
    request.setLoad(sl);
    master.getMasterRpcServices().regionServerReport(null, request.build());

    metricsHelper.assertCounter("cluster_requests", 10000, masterSource);

    sl = ClusterStatusProtos.ServerLoad.newBuilder().setTotalNumberOfRequests(15000).build();
    request.setLoad(sl);
    master.getMasterRpcServices().regionServerReport(null, request.build());

    metricsHelper.assertCounter("cluster_requests", 15000, masterSource);

    master.getMasterRpcServices().regionServerReport(null, request.build());

    metricsHelper.assertCounter("cluster_requests", 15000, masterSource);
    master.stopMaster();
  }
示例#4
0
 /**
  * Sets the location of <code>hbase:meta</code> in ZooKeeper to the specified server address.
  *
  * @param zookeeper
  * @param serverName
  * @param replicaId
  * @param state
  * @throws KeeperException
  */
 public static void setMetaLocation(
     ZooKeeperWatcher zookeeper, ServerName serverName, int replicaId, RegionState.State state)
     throws KeeperException {
   LOG.info("Setting hbase:meta region location in ZooKeeper as " + serverName);
   // Make the MetaRegionServer pb and then get its bytes and save this as
   // the znode content.
   MetaRegionServer pbrsr =
       MetaRegionServer.newBuilder()
           .setServer(ProtobufUtil.toServerName(serverName))
           .setRpcVersion(HConstants.RPC_CURRENT_VERSION)
           .setState(state.convert())
           .build();
   byte[] data = ProtobufUtil.prependPBMagic(pbrsr.toByteArray());
   try {
     ZKUtil.setData(zookeeper, zookeeper.getZNodeForReplica(replicaId), data);
   } catch (KeeperException.NoNodeException nne) {
     if (replicaId == HRegionInfo.DEFAULT_REPLICA_ID) {
       LOG.debug("META region location doesn't exist, create it");
     } else {
       LOG.debug("META region location doesn't exist for replicaId " + replicaId + ", create it");
     }
     ZKUtil.createAndWatch(zookeeper, zookeeper.getZNodeForReplica(replicaId), data);
   }
 }