Java Code Examples for org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos#ServerName

The following examples show how to use org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos#ServerName . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a ServerName to a protocol buffer ServerName
 *
 * @param serverName the ServerName to convert
 * @return the converted protocol buffer ServerName
 * @see #toServerName(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ServerName)
 */
public static HBaseProtos.ServerName toServerName(final ServerName serverName) {
  if (serverName == null) {
    return null;
  }
  HBaseProtos.ServerName.Builder builder =
    HBaseProtos.ServerName.newBuilder();
  builder.setHostName(serverName.getHostname());
  if (serverName.getPort() >= 0) {
    builder.setPort(serverName.getPort());
  }
  if (serverName.getStartcode() >= 0) {
    builder.setStartCode(serverName.getStartcode());
  }
  return builder.build();
}
 
Example 2
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public MasterProtos.ScheduleServerCrashProcedureResponse scheduleServerCrashProcedure(
    RpcController controller, MasterProtos.ScheduleServerCrashProcedureRequest request)
    throws ServiceException {
  List<Long> pids = new ArrayList<>();
  for (HBaseProtos.ServerName sn: request.getServerNameList()) {
    ServerName serverName = ProtobufUtil.toServerName(sn);
    LOG.info("{} schedule ServerCrashProcedure for {}",
        this.master.getClientIdAuditPrefix(), serverName);
    if (shouldSubmitSCP(serverName)) {
      pids.add(this.master.getServerManager().expireServer(serverName, true));
    } else {
      pids.add(Procedure.NO_PROC_ID);
    }
  }
  return MasterProtos.ScheduleServerCrashProcedureResponse.newBuilder().addAllPid(pids).build();
}
 
Example 3
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) {
  List<HBaseProtos.TableName> tables = new ArrayList<>(pojo.getTables().size());
  for (TableName arg : pojo.getTables()) {
    tables.add(ProtobufUtil.toProtoTableName(arg));
  }
  List<HBaseProtos.ServerName> hostports = new ArrayList<>(pojo.getServers().size());
  for (Address el : pojo.getServers()) {
    hostports.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
        .setPort(el.getPort()).build());
  }
  List<NameStringPair> configuration = pojo.getConfiguration().entrySet()
      .stream().map(entry -> NameStringPair.newBuilder()
          .setName(entry.getKey()).setValue(entry.getValue()).build())
      .collect(Collectors.toList());
  return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName()).addAllServers(hostports)
      .addAllTables(tables).addAllConfiguration(configuration).build();
}
 
Example 4
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public RemoveServersResponse removeServers(RpcController controller,
    RemoveServersRequest request) throws ServiceException {
  RemoveServersResponse.Builder builder = RemoveServersResponse.newBuilder();
  Set<Address> servers = Sets.newHashSet();
  for (HBaseProtos.ServerName el : request.getServersList()) {
    servers.add(Address.fromParts(el.getHostName(), el.getPort()));
  }
  LOG.info(master.getClientIdAuditPrefix() + " remove decommissioned servers from rsgroup: " +
      servers);
  try {
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().preRemoveServers(servers);
    }
    master.getRSGroupInfoManager().removeServers(servers);
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().postRemoveServers(servers);
    }
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return builder.build();
}
 
Example 5
Source File: RSGroupAdminServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void moveServers(RpcController controller, MoveServersRequest request,
    RpcCallback<MoveServersResponse> done) {
  MoveServersResponse.Builder builder = MoveServersResponse.newBuilder();
  Set<Address> hostPorts = Sets.newHashSet();
  for (HBaseProtos.ServerName el : request.getServersList()) {
    hostPorts.add(Address.fromParts(el.getHostName(), el.getPort()));
  }
  LOG.info(master.getClientIdAuditPrefix() + " move servers " + hostPorts + " to rsgroup " +
      request.getTargetGroup());
  try {
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().preMoveServers(hostPorts, request.getTargetGroup());
    }
    rsGroupInfoManager.moveServers(hostPorts, request.getTargetGroup());
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().postMoveServers(hostPorts, request.getTargetGroup());
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  }
  done.run(builder.build());
}
 
Example 6
Source File: RSGroupAdminServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void removeServers(RpcController controller, RemoveServersRequest request,
    RpcCallback<RemoveServersResponse> done) {
  RemoveServersResponse.Builder builder = RemoveServersResponse.newBuilder();
  Set<Address> servers = Sets.newHashSet();
  for (HBaseProtos.ServerName el : request.getServersList()) {
    servers.add(Address.fromParts(el.getHostName(), el.getPort()));
  }
  LOG.info(
    master.getClientIdAuditPrefix() + " remove decommissioned servers from rsgroup: " + servers);
  try {
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().preRemoveServers(servers);
    }
    rsGroupInfoManager.removeServers(servers);
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().postRemoveServers(servers);
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  }
  done.run(builder.build());
}
 
Example 7
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ServerName from the passed in data bytes.
 * @param data Data with a serialize server name in it; can handle the old style servername where
 *          servername was host and port. Works too with data that begins w/ the pb 'PBUF' magic
 *          and that is then followed by a protobuf that has a serialized {@link ServerName} in
 *          it.
 * @return Returns null if <code>data</code> is null else converts passed data to a ServerName
 *         instance.
 */
public static ServerName toServerName(final byte[] data) throws DeserializationException {
  if (data == null || data.length <= 0) {
    return null;
  }
  if (ProtobufMagic.isPBMagicPrefix(data)) {
    int prefixLen = ProtobufMagic.lengthOfPBMagic();
    try {
      ZooKeeperProtos.Master rss =
        ZooKeeperProtos.Master.parser().parseFrom(data, prefixLen, data.length - prefixLen);
      HBaseProtos.ServerName sn = rss.getMaster();
      return ServerName.valueOf(sn.getHostName(), sn.getPort(), sn.getStartCode());
    } catch (/* InvalidProtocolBufferException */IOException e) {
      // A failed parse of the znode is pretty catastrophic. Rather than loop
      // retrying hoping the bad bytes will changes, and rather than change
      // the signature on this method to add an IOE which will send ripples all
      // over the code base, throw a RuntimeException. This should "never" happen.
      // Fail fast if it does.
      throw new DeserializationException(e);
    }
  }
  // The str returned could be old style -- pre hbase-1502 -- which was
  // hostname and port seperated by a colon rather than hostname, port and
  // startcode delimited by a ','.
  String str = Bytes.toString(data);
  int index = str.indexOf(ServerName.SERVERNAME_SEPARATOR);
  if (index != -1) {
    // Presume its ServerName serialized with versioned bytes.
    return ServerName.parseVersionedServerName(data);
  }
  // Presume it a hostname:port format.
  String hostname = Addressing.parseHostname(str);
  int port = Addressing.parsePort(str);
  return ServerName.valueOf(hostname, port, -1L);
}
 
Example 8
Source File: HBCK2.java    From hbase-operator-tools with Apache License 2.0 5 votes vote down vote up
List<Long> scheduleRecoveries(Hbck hbck, String[] args) throws IOException {
  List<HBaseProtos.ServerName> serverNames = new ArrayList<>();
  for (String serverName: args) {
    serverNames.add(parseServerName(serverName));
  }
  return hbck.scheduleServerCrashProcedure(serverNames);
}
 
Example 9
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a protocol buffer ServerName to a ServerName
 *
 * @param proto the protocol buffer ServerName to convert
 * @return the converted ServerName
 */
public static ServerName toServerName(final HBaseProtos.ServerName proto) {
  if (proto == null) return null;
  String hostName = proto.getHostName();
  long startCode = -1;
  int port = -1;
  if (proto.hasPort()) {
    port = proto.getPort();
  }
  if (proto.hasStartCode()) {
    startCode = proto.getStartCode();
  }
  return ServerName.valueOf(hostName, port, startCode);
}
 
Example 10
Source File: RequestConverter.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static RemoveServersRequest buildRemoveServersRequest(Set<Address> servers) {
  Set<HBaseProtos.ServerName> hostPorts = Sets.newHashSet();
  for(Address el: servers) {
    hostPorts.add(HBaseProtos.ServerName.newBuilder()
        .setHostName(el.getHostname())
        .setPort(el.getPort())
        .build());
  }
  return RemoveServersRequest.newBuilder()
      .addAllServers(hostPorts)
      .build();
}
 
Example 11
Source File: RequestConverter.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static List<HBaseProtos.ServerName> toProtoServerNames(List<ServerName> servers) {
  List<HBaseProtos.ServerName> pbServers = new ArrayList<>(servers.size());
  for (ServerName server : servers) {
    pbServers.add(ProtobufUtil.toServerName(server));
  }
  return pbServers;
}
 
Example 12
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Get the Meta region state from the passed data bytes. Can handle both old and new style
 * server names.
 * @param data protobuf serialized data with meta server name.
 * @param replicaId replica ID for this region
 * @return RegionState instance corresponding to the serialized data.
 * @throws DeserializationException if the data is invalid.
 */
public static RegionState parseMetaRegionStateFrom(final byte[] data, int replicaId)
    throws DeserializationException {
  RegionState.State state = RegionState.State.OPEN;
  ServerName serverName;
  if (data != null && data.length > 0 && ProtobufUtil.isPBMagicPrefix(data)) {
    try {
      int prefixLen = ProtobufUtil.lengthOfPBMagic();
      ZooKeeperProtos.MetaRegionServer rl =
          ZooKeeperProtos.MetaRegionServer.parser().parseFrom(data, prefixLen,
              data.length - prefixLen);
      if (rl.hasState()) {
        state = RegionState.State.convert(rl.getState());
      }
      HBaseProtos.ServerName sn = rl.getServer();
      serverName = ServerName.valueOf(
          sn.getHostName(), sn.getPort(), sn.getStartCode());
    } catch (InvalidProtocolBufferException e) {
      throw new DeserializationException("Unable to parse meta region location");
    }
  } else {
    // old style of meta region location?
    serverName = parseServerNameFrom(data);
  }
  if (serverName == null) {
    state = RegionState.State.OFFLINE;
  }
  return new RegionState(RegionReplicaUtil.getRegionInfoForReplica(
      RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId), state, serverName);
}
 
Example 13
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Move given set of servers to the specified target RegionServer group.
 */
public void moveServers(Set<Address> servers, String targetGroup) throws IOException {
  Set<HBaseProtos.ServerName> hostPorts = Sets.newHashSet();
  for (Address el : servers) {
    hostPorts.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
      .setPort(el.getPort()).build());
  }
  MoveServersRequest request =
    MoveServersRequest.newBuilder().setTargetGroup(targetGroup).addAllServers(hostPorts).build();
  try {
    stub.moveServers(null, request);
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 14
Source File: RSGroupAdminServiceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void moveServersAndTables(RpcController controller, MoveServersAndTablesRequest request,
    RpcCallback<MoveServersAndTablesResponse> done) {
  MoveServersAndTablesResponse.Builder builder = MoveServersAndTablesResponse.newBuilder();
  Set<Address> hostPorts = Sets.newHashSet();
  for (HBaseProtos.ServerName el : request.getServersList()) {
    hostPorts.add(Address.fromParts(el.getHostName(), el.getPort()));
  }
  Set<TableName> tables = new HashSet<>(request.getTableNameList().size());
  for (HBaseProtos.TableName tableName : request.getTableNameList()) {
    tables.add(ProtobufUtil.toTableName(tableName));
  }
  LOG.info(master.getClientIdAuditPrefix() + " move servers " + hostPorts + " and tables " +
      tables + " to rsgroup" + request.getTargetGroup());
  try {
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().preMoveServersAndTables(hostPorts, tables,
        request.getTargetGroup());
    }
    rsGroupInfoManager.moveServers(hostPorts, request.getTargetGroup());
    moveTablesAndWait(tables, request.getTargetGroup());
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().postMoveServersAndTables(hostPorts, tables,
        request.getTargetGroup());
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  }
  done.run(builder.build());
}
 
Example 15
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) {
  RSGroupInfo rsGroupInfo = new RSGroupInfo(proto.getName());
  for (HBaseProtos.ServerName el : proto.getServersList()) {
    rsGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
  }
  for (HBaseProtos.TableName pTableName : proto.getTablesList()) {
    rsGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
  }
  proto.getConfigurationList().forEach(pair ->
      rsGroupInfo.setConfiguration(pair.getName(), pair.getValue()));
  return rsGroupInfo;
}
 
Example 16
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public ClearDeadServersResponse clearDeadServers(RpcController controller,
    ClearDeadServersRequest request) throws ServiceException {
  LOG.debug(master.getClientIdAuditPrefix() + " clear dead region servers.");
  ClearDeadServersResponse.Builder response = ClearDeadServersResponse.newBuilder();
  try {
    master.checkInitialized();
    if (master.cpHost != null) {
      master.cpHost.preClearDeadServers();
    }

    if (master.getServerManager().areDeadServersInProgress()) {
      LOG.debug("Some dead server is still under processing, won't clear the dead server list");
      response.addAllServerName(request.getServerNameList());
    } else {
      DeadServer deadServer = master.getServerManager().getDeadServers();
      Set<Address> clearedServers = new HashSet<>();
      for (HBaseProtos.ServerName pbServer : request.getServerNameList()) {
        ServerName server = ProtobufUtil.toServerName(pbServer);
        if (!deadServer.removeDeadServer(server)) {
          response.addServerName(pbServer);
        } else {
          clearedServers.add(server.getAddress());
        }
      }
      master.getRSGroupInfoManager().removeServers(clearedServers);
      LOG.info("Remove decommissioned servers {} from RSGroup done", clearedServers);
    }

    if (master.cpHost != null) {
      master.cpHost.postClearDeadServers(
          ProtobufUtil.toServerNameList(request.getServerNameList()),
          ProtobufUtil.toServerNameList(response.getServerNameList()));
    }
  } catch (IOException io) {
    throw new ServiceException(io);
  }
  return response.build();
}
 
Example 17
Source File: SplitLogTask.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @return This instance serialized into a byte array
 * @see #parseFrom(byte[])
 */
public byte [] toByteArray() {
  // First create a pb ServerName.  Then create a ByteString w/ the TaskState
  // bytes in it.  Finally create a SplitLogTaskState passing in the two
  // pbs just created.
  HBaseProtos.ServerName snpb = ProtobufUtil.toServerName(this.originServer);
  ZooKeeperProtos.SplitLogTask slts =
    ZooKeeperProtos.SplitLogTask.newBuilder().setServerName(snpb).setState(this.state).build();
  return ProtobufUtil.prependPBMagic(slts.toByteArray());
}
 
Example 18
Source File: MockRegionServerServices.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void updateRegionFavoredNodesMapping(String encodedRegionName,
    List<HBaseProtos.ServerName> favoredNodes) {
}
 
Example 19
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Convert a list of protocol buffer ServerName to a list of ServerName
 * @param proto protocol buffer ServerNameList
 * @return a list of ServerName
 */
public static List<ServerName> toServerNameList(
        List<HBaseProtos.ServerName> proto) {
  return proto.stream().map(ProtobufUtil::toServerName)
          .collect(Collectors.toList());
}
 
Example 20
Source File: HBCK2.java    From hbase-operator-tools with Apache License 2.0 4 votes vote down vote up
private HBaseProtos.ServerName parseServerName(String serverName) {
  ServerName sn = ServerName.parseServerName(serverName);
  return HBaseProtos.ServerName.newBuilder().setHostName(sn.getHostname()).
      setPort(sn.getPort()).setStartCode(sn.getStartcode()).build();
}