@Test (timeout=180000) public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getMasterRpcServices().getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
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()); }
/** * @deprecated Use {@link Admin#getTableDescriptorsByTableName(List)} instead */ @Deprecated @Override public HTableDescriptor[] getHTableDescriptorsByTableName( List<TableName> tableNames) throws IOException { if (tableNames == null || tableNames.isEmpty()) return new HTableDescriptor[0]; MasterKeepAliveConnection master = getKeepAliveMasterService(); try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableNames); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } }
/** * 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()); }
@Test public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getMasterRpcServices().getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
/** * 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()); }
@Test public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getCoprocessorHost(); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
/** * 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); } }
/** * Creates a protocol buffer GetTableDescriptorsRequest * * @param tableNames * @return a GetTableDescriptorsRequest */ public static GetTableDescriptorsRequest buildGetTableDescriptorsRequest( final List<TableName> tableNames) { GetTableDescriptorsRequest.Builder builder = GetTableDescriptorsRequest.newBuilder(); if (tableNames != null) { for (TableName tableName : tableNames) { builder.addTableNames(ProtobufUtil.toProtoTableName(tableName)); } } return builder.build(); }
/** * Creates a protocol buffer GetTableDescriptorsRequest * * @param pattern The compiled regular expression to match against * @param includeSysTables False to match only against userspace tables * @return a GetTableDescriptorsRequest */ public static GetTableDescriptorsRequest buildGetTableDescriptorsRequest(final Pattern pattern, boolean includeSysTables) { GetTableDescriptorsRequest.Builder builder = GetTableDescriptorsRequest.newBuilder(); if (pattern != null) builder.setRegex(pattern.toString()); builder.setIncludeSysTables(includeSysTables); return builder.build(); }
/** * Creates a protocol buffer GetTableDescriptorsRequest for a single table * * @param tableName the table name * @return a GetTableDescriptorsRequest */ public static GetTableDescriptorsRequest buildGetTableDescriptorsRequest( final TableName tableName) { return GetTableDescriptorsRequest.newBuilder() .addTableNames(ProtobufUtil.toProtoTableName(tableName)) .build(); }
@Override public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) throws IOException { return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection()) { @Override public HTableDescriptor[] call(int callTimeout) throws ServiceException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(controller, req)); } }); }
/** * Get tableDescriptors * @param tableNames List of table names * @return HTD[] the tableDescriptor * @throws IOException if a remote or network exception occurs */ @Override public HTableDescriptor[] getTableDescriptorsByTableName(final List<TableName> tableNames) throws IOException { return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection()) { @Override public HTableDescriptor[] call(int callTimeout) throws Exception { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableNames); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(controller, req)); } }); }
/** * @deprecated Use {@link Admin#listTables()} instead */ @Deprecated @Override public HTableDescriptor[] listTables() throws IOException { MasterKeepAliveConnection master = getKeepAliveMasterService(); try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } }
@Override public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) throws IOException { return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection()) { @Override public HTableDescriptor[] call(int callTimeout) throws ServiceException { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); } }); }
/** * 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()); }
/** * Get tableDescriptors * @param tableNames List of table names * @return HTD[] the tableDescriptor * @throws IOException if a remote or network exception occurs */ @Override public HTableDescriptor[] getTableDescriptorsByTableName(final List<TableName> tableNames) throws IOException { return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection()) { @Override public HTableDescriptor[] call(int callTimeout) throws Exception { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableNames); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); } }); }
/** * @deprecated Use {@link Admin#listTables()} instead */ @Deprecated @Override public HTableDescriptor[] listTables() throws IOException { MasterKeepAliveConnection master = getKeepAliveMasterService(); try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>) null); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } }
/** * {@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()); }
@Override public HTableDescriptor[] listTables() throws IOException { MasterKeepAliveConnection master = getKeepAliveMasterService(); try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } }
@Override public HTableDescriptor[] getHTableDescriptorsByTableName( List<TableName> tableNames) throws IOException { if (tableNames == null || tableNames.isEmpty()) return new HTableDescriptor[0]; MasterKeepAliveConnection master = getKeepAliveMasterService(); try { GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest(tableNames); return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } finally { master.close(); } }