Search in sources :

Example 1 with TableSchema

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema in project hbase by apache.

the class AsyncHBaseAdmin method getTableDescriptor.

@Override
public CompletableFuture<HTableDescriptor> getTableDescriptor(TableName tableName) {
    CompletableFuture<HTableDescriptor> future = new CompletableFuture<>();
    this.<List<TableSchema>>newMasterCaller().action((controller, stub) -> this.<GetTableDescriptorsRequest, GetTableDescriptorsResponse, List<TableSchema>>call(controller, stub, RequestConverter.buildGetTableDescriptorsRequest(tableName), (s, c, req, done) -> s.getTableDescriptors(c, req, done), (resp) -> resp.getTableSchemaList())).call().whenComplete((tableSchemas, error) -> {
        if (error != null) {
            future.completeExceptionally(error);
            return;
        }
        if (!tableSchemas.isEmpty()) {
            future.complete(ProtobufUtil.convertToHTableDesc(tableSchemas.get(0)));
        } else {
            future.completeExceptionally(new TableNotFoundException(tableName.getNameAsString()));
        }
    });
    return future;
}
Also used : GetSchemaAlterStatusRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetSchemaAlterStatusRequest) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) CreateTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateTableResponse) AsyncMetaTableAccessor(org.apache.hadoop.hbase.AsyncMetaTableAccessor) DeleteTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteTableResponse) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) RegionLocations(org.apache.hadoop.hbase.RegionLocations) GetTableDescriptorsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsResponse) IsBalancerEnabledRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsBalancerEnabledRequest) DisableTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DisableTableResponse) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) GetNamespaceDescriptorRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorRequest) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) IsBalancerEnabledResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsBalancerEnabledResponse) ForeignExceptionUtil(org.apache.hadoop.hbase.util.ForeignExceptionUtil) DeleteNamespaceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteNamespaceRequest) CreateNamespaceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceResponse) InterfaceStability(org.apache.hadoop.hbase.classification.InterfaceStability) CreateTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateTableRequest) Pair(org.apache.hadoop.hbase.util.Pair) TruncateTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.TruncateTableRequest) RpcCallback(org.apache.hadoop.hbase.shaded.com.google.protobuf.RpcCallback) ProtobufUtil(org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil) EnableTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableTableRequest) CloseRegionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.CloseRegionRequest) AddColumnResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnResponse) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) MasterService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService) SetBalancerRunningResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetBalancerRunningResponse) List(java.util.List) BalanceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceResponse) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) ModifyNamespaceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyNamespaceRequest) GetTableNamesRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableNamesRequest) BalanceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceRequest) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) InterfaceAudience(org.apache.hadoop.hbase.classification.InterfaceAudience) AdminRequestCallerBuilder(org.apache.hadoop.hbase.client.AsyncRpcRetryingCallerFactory.AdminRequestCallerBuilder) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) META_TABLE_NAME(org.apache.hadoop.hbase.TableName.META_TABLE_NAME) GetTableDescriptorsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsRequest) ModifyColumnRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyColumnRequest) EnableTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableTableResponse) ListNamespaceDescriptorsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsResponse) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) GetProcedureResultRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultRequest) CompletableFuture(java.util.concurrent.CompletableFuture) AddColumnRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnRequest) DeleteTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteTableRequest) GetNamespaceDescriptorResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorResponse) HConstants(org.apache.hadoop.hbase.HConstants) DisableTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DisableTableRequest) BiConsumer(java.util.function.BiConsumer) LinkedList(java.util.LinkedList) ModifyColumnResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyColumnResponse) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) ReadType(org.apache.hadoop.hbase.client.Scan.ReadType) CreateNamespaceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceRequest) SetBalancerRunningRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetBalancerRunningRequest) TableName(org.apache.hadoop.hbase.TableName) TableSchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema) ModifyNamespaceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyNamespaceResponse) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) GetProcedureResultResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultResponse) GetTableNamesResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableNamesResponse) IOException(java.io.IOException) MasterRequestCallerBuilder(org.apache.hadoop.hbase.client.AsyncRpcRetryingCallerFactory.MasterRequestCallerBuilder) ListNamespaceDescriptorsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest) RequestConverter(org.apache.hadoop.hbase.shaded.protobuf.RequestConverter) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) DeleteNamespaceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteNamespaceResponse) TimeUnit(java.util.concurrent.TimeUnit) DeleteColumnRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteColumnRequest) GetSchemaAlterStatusResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetSchemaAlterStatusResponse) CloseRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.CloseRegionResponse) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DeleteColumnResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteColumnResponse) TruncateTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.TruncateTableResponse) Log(org.apache.commons.logging.Log) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) CompletableFuture(java.util.concurrent.CompletableFuture) TableSchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 2 with TableSchema

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema in project hbase by apache.

the class ProtobufUtil method convertToTableSchema.

/**
   * Converts an HTableDescriptor to TableSchema
   * @param htd the HTableDescriptor
   * @return Convert the current {@link HTableDescriptor} into a pb TableSchema instance.
   */
public static TableSchema convertToTableSchema(HTableDescriptor htd) {
    TableSchema.Builder builder = TableSchema.newBuilder();
    builder.setTableName(toProtoTableName(htd.getTableName()));
    for (Map.Entry<Bytes, Bytes> e : htd.getValues().entrySet()) {
        BytesBytesPair.Builder aBuilder = BytesBytesPair.newBuilder();
        aBuilder.setFirst(UnsafeByteOperations.unsafeWrap(e.getKey().get()));
        aBuilder.setSecond(UnsafeByteOperations.unsafeWrap(e.getValue().get()));
        builder.addAttributes(aBuilder.build());
    }
    for (HColumnDescriptor hcd : htd.getColumnFamilies()) {
        builder.addColumnFamilies(convertToColumnFamilySchema(hcd));
    }
    for (Map.Entry<String, String> e : htd.getConfiguration().entrySet()) {
        NameStringPair.Builder aBuilder = NameStringPair.newBuilder();
        aBuilder.setName(e.getKey());
        aBuilder.setValue(e.getValue());
        builder.addConfiguration(aBuilder.build());
    }
    return builder.build();
}
Also used : Bytes(org.apache.hadoop.hbase.util.Bytes) TableSchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair) BytesBytesPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.BytesBytesPair) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with TableSchema

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema in project hbase by apache.

the class HTableDescriptor method parseFrom.

/**
   * @param bytes A pb serialized {@link HTableDescriptor} instance with pb magic prefix
   * @return An instance of {@link HTableDescriptor} made from <code>bytes</code>
   * @throws DeserializationException
   * @throws IOException
   * @see #toByteArray()
   */
public static HTableDescriptor parseFrom(final byte[] bytes) throws DeserializationException, IOException {
    if (!ProtobufUtil.isPBMagicPrefix(bytes)) {
        throw new DeserializationException("Expected PB encoded HTableDescriptor");
    }
    int pblen = ProtobufUtil.lengthOfPBMagic();
    TableSchema.Builder builder = TableSchema.newBuilder();
    TableSchema ts;
    try {
        ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
        ts = builder.build();
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
    return ProtobufUtil.convertToHTableDesc(ts);
}
Also used : TableSchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

TableSchema (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema)3 IOException (java.io.IOException)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 BiConsumer (java.util.function.BiConsumer)1 Pattern (java.util.regex.Pattern)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 AsyncMetaTableAccessor (org.apache.hadoop.hbase.AsyncMetaTableAccessor)1 HConstants (org.apache.hadoop.hbase.HConstants)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 MetaTableAccessor (org.apache.hadoop.hbase.MetaTableAccessor)1