static HTableDescriptor getTableDescriptor(final TableName tableName, HConnection connection, RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, int operationTimeout) throws TableNotFoundException, IOException { if (tableName == null) return null; HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(connection) { @Override public HTableDescriptor call(int callTimeout) throws ServiceException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); GetTableDescriptorsResponse htds; GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableName); htds = master.getTableDescriptors(controller, req); if (!htds.getTableSchemaList().isEmpty()) { return HTableDescriptor.convert(htds.getTableSchemaList().get(0)); } return null; } }, rpcCallerFactory, operationTimeout); if (htd != null) { return htd; } throw new TableNotFoundException(tableName.getNameAsString()); }
/** * Connects to the master to get the table descriptor. * @param tableName table name * @throws IOException if the connection to master fails or if the table * is not found. * @deprecated Use {@link Admin#getTableDescriptor(TableName)} instead */ @Deprecated @Override public HTableDescriptor getHTableDescriptor(final TableName tableName) throws IOException { if (tableName == null) return null; MasterKeepAliveConnection master = getKeepAliveMasterService(); GetTableDescriptorsResponse htds; try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableName); htds = master.getTableDescriptors(null, req); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } if (!htds.getTableSchemaList().isEmpty()) { return HTableDescriptor.convert(htds.getTableSchemaList().get(0)); } throw new TableNotFoundException(tableName.getNameAsString()); }
/** * Connects to the master to get the table descriptor. * * @param tableName table name * @throws IOException if the connection to master fails or if the table * is not found. * @deprecated Use {@link Admin#getTableDescriptor(TableName)} instead */ @Deprecated @Override public HTableDescriptor getHTableDescriptor(final TableName tableName) throws IOException { if (tableName == null) return null; MasterKeepAliveConnection master = getKeepAliveMasterService(); GetTableDescriptorsResponse htds; try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableName); htds = master.getTableDescriptors(null, req); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } if (!htds.getTableSchemaList().isEmpty()) { return HTableDescriptor.convert(htds.getTableSchemaList().get(0)); } throw new TableNotFoundException(tableName.getNameAsString()); }
/** * Connects to the master to get the table descriptor. * @param tableName table name * @return * @throws IOException if the connection to master fails or if the table * is not found. */ @Override public HTableDescriptor getHTableDescriptor(final TableName tableName) throws IOException { if (tableName == null) return null; if (tableName.equals(TableName.META_TABLE_NAME)) { return HTableDescriptor.META_TABLEDESC; } MasterKeepAliveConnection master = getKeepAliveMasterService(); GetTableDescriptorsResponse htds; try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableName); htds = master.getTableDescriptors(null, req); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } if (!htds.getTableSchemaList().isEmpty()) { return HTableDescriptor.convert(htds.getTableSchemaList().get(0)); } throw new TableNotFoundException(tableName.getNameAsString()); }
/** * Get list of TableDescriptors for requested tables. * @param c Unused (set to null). * @param req GetTableDescriptorsRequest that contains: * - tableNames: requested tables, or if empty, all are requested * @return GetTableDescriptorsResponse * @throws ServiceException */ @Override public GetTableDescriptorsResponse getTableDescriptors(RpcController c, GetTableDescriptorsRequest req) throws ServiceException { try { master.checkInitialized(); final String regex = req.hasRegex() ? req.getRegex() : null; final String namespace = req.hasNamespace() ? req.getNamespace() : null; List<TableName> tableNameList = null; if (req.getTableNamesCount() > 0) { tableNameList = new ArrayList<TableName>(req.getTableNamesCount()); for (HBaseProtos.TableName tableNamePB: req.getTableNamesList()) { tableNameList.add(ProtobufUtil.toTableName(tableNamePB)); } } List<HTableDescriptor> descriptors = master.listTableDescriptors(namespace, regex, tableNameList, req.getIncludeSysTables()); GetTableDescriptorsResponse.Builder builder = GetTableDescriptorsResponse.newBuilder(); if (descriptors != null && descriptors.size() > 0) { // Add the table descriptors to the response for (HTableDescriptor htd: descriptors) { builder.addTableSchema(htd.convert()); } } return builder.build(); } catch (IOException ioe) { throw new ServiceException(ioe); } }
/** * Get HTableDescriptor[] from GetTableDescriptorsResponse protobuf * * @param proto the GetTableDescriptorsResponse * @return HTableDescriptor[] */ public static HTableDescriptor[] getHTableDescriptorArray(GetTableDescriptorsResponse proto) { if (proto == null) return null; HTableDescriptor[] ret = new HTableDescriptor[proto.getTableSchemaCount()]; for (int i = 0; i < proto.getTableSchemaCount(); ++i) { ret[i] = HTableDescriptor.convert(proto.getTableSchema(i)); } return ret; }
/** * Method for getting the tableDescriptor * @param tableName as a byte [] * @return the tableDescriptor * @throws TableNotFoundException * @throws IOException if a remote or network exception occurs */ @Override public HTableDescriptor getTableDescriptor(final TableName tableName) throws TableNotFoundException, IOException { if (tableName == null) return null; if (tableName.equals(TableName.META_TABLE_NAME)) { return HTableDescriptor.META_TABLEDESC; } HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(getConnection()) { @Override public HTableDescriptor call(int callTimeout) throws ServiceException { GetTableDescriptorsResponse htds; GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableName); htds = master.getTableDescriptors(null, req); if (!htds.getTableSchemaList().isEmpty()) { return HTableDescriptor.convert(htds.getTableSchemaList().get(0)); } return null; } }); if (htd != null) { return htd; } throw new TableNotFoundException(tableName.getNameAsString()); }
/** * {@inheritDoc} */ @Override public HTableDescriptor getTableDescriptor() throws IOException { // TODO: This is the same as HBaseAdmin.getTableDescriptor(). Only keep one. if (tableName == null) return null; if (tableName.equals(TableName.META_TABLE_NAME)) { return HTableDescriptor.META_TABLEDESC; } HTableDescriptor htd = executeMasterCallable( new MasterCallable<HTableDescriptor>(getConnection()) { @Override public HTableDescriptor call(int callTimeout) throws ServiceException { GetTableDescriptorsResponse htds; GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableName); htds = master.getTableDescriptors(null, req); if (!htds.getTableSchemaList().isEmpty()) { return HTableDescriptor.convert(htds.getTableSchemaList().get(0)); } return null; } }); if (htd != null) { return new UnmodifyableHTableDescriptor(htd); } throw new TableNotFoundException(tableName.getNameAsString()); }