Search in sources :

Example 56 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class RestoreSnapshotProcedure method prepareRestore.

/**
   * Action before any real action of restoring from snapshot.
   * @param env MasterProcedureEnv
   * @throws IOException
   */
private void prepareRestore(final MasterProcedureEnv env) throws IOException {
    final TableName tableName = getTableName();
    // Checks whether the table exists
    if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) {
        throw new TableNotFoundException(tableName);
    }
    // Check whether table is disabled.
    env.getMasterServices().checkTableModifiable(tableName);
    // Check that we have at least 1 CF
    if (modifiedHTableDescriptor.getColumnFamilyCount() == 0) {
        throw new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family.");
    }
    if (!getTableName().isSystemTable()) {
        // Table already exist. Check and update the region quota for this table namespace.
        final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem();
        SnapshotManifest manifest = SnapshotManifest.open(env.getMasterConfiguration(), mfs.getFileSystem(), SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, mfs.getRootDir()), snapshot);
        int snapshotRegionCount = manifest.getRegionManifestsMap().size();
        int tableRegionCount = ProcedureSyncWait.getMasterQuotaManager(env).getRegionCountOfTable(tableName);
        if (snapshotRegionCount > 0 && tableRegionCount != snapshotRegionCount) {
            ProcedureSyncWait.getMasterQuotaManager(env).checkAndUpdateNamespaceRegionQuota(tableName, snapshotRegionCount);
        }
    }
}
Also used : MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) TableName(org.apache.hadoop.hbase.TableName) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) SnapshotManifest(org.apache.hadoop.hbase.snapshot.SnapshotManifest) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 57 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class VisibilityController method preGetOp.

@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException {
    if (!initialized) {
        throw new VisibilityControllerNotReadyException("VisibilityController not yet initialized");
    }
    // Nothing useful to do if authorization is not enabled
    if (!authorizationEnabled) {
        return;
    }
    Region region = e.getEnvironment().getRegion();
    Authorizations authorizations = null;
    try {
        authorizations = get.getAuthorizations();
    } catch (DeserializationException de) {
        throw new IOException(de);
    }
    if (authorizations == null) {
        // No Authorizations present for this scan/Get!
        // In case of system tables other than "labels" just scan with out visibility check and
        // filtering. Checking visibility labels for META and NAMESPACE table is not needed.
        TableName table = region.getRegionInfo().getTable();
        if (table.isSystemTable() && !table.equals(LABELS_TABLE_NAME)) {
            return;
        }
    }
    Filter visibilityLabelFilter = VisibilityUtils.createVisibilityLabelFilter(e.getEnvironment().getRegion(), authorizations);
    if (visibilityLabelFilter != null) {
        Filter filter = get.getFilter();
        if (filter != null) {
            get.setFilter(new FilterList(filter, visibilityLabelFilter));
        } else {
            get.setFilter(visibilityLabelFilter);
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Filter(org.apache.hadoop.hbase.filter.Filter) Region(org.apache.hadoop.hbase.regionserver.Region) FilterList(org.apache.hadoop.hbase.filter.FilterList) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 58 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class ExportSnapshot method getSnapshotFiles.

// ==========================================================================
//  Input Format
// ==========================================================================
/**
   * Extract the list of files (HFiles/WALs) to copy using Map-Reduce.
   * @return list of files referenced by the snapshot (pair of path and size)
   */
private static List<Pair<SnapshotFileInfo, Long>> getSnapshotFiles(final Configuration conf, final FileSystem fs, final Path snapshotDir) throws IOException {
    SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
    final List<Pair<SnapshotFileInfo, Long>> files = new ArrayList<>();
    final TableName table = TableName.valueOf(snapshotDesc.getTable());
    // Get snapshot files
    LOG.info("Loading Snapshot '" + snapshotDesc.getName() + "' hfile list");
    SnapshotReferenceUtil.visitReferencedFiles(conf, fs, snapshotDir, snapshotDesc, new SnapshotReferenceUtil.SnapshotVisitor() {

        @Override
        public void storeFile(final HRegionInfo regionInfo, final String family, final SnapshotRegionManifest.StoreFile storeFile) throws IOException {
            // for storeFile.hasReference() case, copied as part of the manifest
            if (!storeFile.hasReference()) {
                String region = regionInfo.getEncodedName();
                String hfile = storeFile.getName();
                Path path = HFileLink.createPath(table, region, family, hfile);
                SnapshotFileInfo fileInfo = SnapshotFileInfo.newBuilder().setType(SnapshotFileInfo.Type.HFILE).setHfile(path.toString()).build();
                long size;
                if (storeFile.hasFileSize()) {
                    size = storeFile.getFileSize();
                } else {
                    size = HFileLink.buildFromHFileLinkPattern(conf, path).getFileStatus(fs).getLen();
                }
                files.add(new Pair<>(fileInfo, size));
            }
        }
    });
    return files;
}
Also used : Path(org.apache.hadoop.fs.Path) ArrayList(java.util.ArrayList) SnapshotRegionManifest(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription) IOException(java.io.IOException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) SnapshotFileInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotFileInfo) Pair(org.apache.hadoop.hbase.util.Pair)

Example 59 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class VisibilityController method postInstantiateDeleteTracker.

@Override
public DeleteTracker postInstantiateDeleteTracker(ObserverContext<RegionCoprocessorEnvironment> ctx, DeleteTracker delTracker) throws IOException {
    // Nothing to do if we are not filtering by visibility
    if (!authorizationEnabled) {
        return delTracker;
    }
    Region region = ctx.getEnvironment().getRegion();
    TableName table = region.getRegionInfo().getTable();
    if (table.isSystemTable()) {
        return delTracker;
    }
    // but also on the visibility expression matching.
    return new VisibilityScanDeleteTracker();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Region(org.apache.hadoop.hbase.regionserver.Region)

Example 60 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class AccessController method checkPermissions.

@Override
public void checkPermissions(RpcController controller, AccessControlProtos.CheckPermissionsRequest request, RpcCallback<AccessControlProtos.CheckPermissionsResponse> done) {
    Permission[] permissions = new Permission[request.getPermissionCount()];
    for (int i = 0; i < request.getPermissionCount(); i++) {
        permissions[i] = AccessControlUtil.toPermission(request.getPermission(i));
    }
    AccessControlProtos.CheckPermissionsResponse response = null;
    try {
        User user = RpcServer.getRequestUser();
        TableName tableName = regionEnv.getRegion().getTableDesc().getTableName();
        for (Permission permission : permissions) {
            if (permission instanceof TablePermission) {
                // Check table permissions
                TablePermission tperm = (TablePermission) permission;
                for (Action action : permission.getActions()) {
                    if (!tperm.getTableName().equals(tableName)) {
                        throw new CoprocessorException(AccessController.class, String.format("This method " + "can only execute at the table specified in TablePermission. " + "Table of the region:%s , requested table:%s", tableName, tperm.getTableName()));
                    }
                    Map<byte[], Set<byte[]>> familyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
                    if (tperm.getFamily() != null) {
                        if (tperm.getQualifier() != null) {
                            Set<byte[]> qualifiers = Sets.newTreeSet(Bytes.BYTES_COMPARATOR);
                            qualifiers.add(tperm.getQualifier());
                            familyMap.put(tperm.getFamily(), qualifiers);
                        } else {
                            familyMap.put(tperm.getFamily(), null);
                        }
                    }
                    AuthResult result = permissionGranted("checkPermissions", user, action, regionEnv, familyMap);
                    logResult(result);
                    if (!result.isAllowed()) {
                        // effective permissions, so throw unconditionally
                        throw new AccessDeniedException("Insufficient permissions (table=" + tableName + (familyMap.size() > 0 ? ", family: " + result.toFamilyString() : "") + ", action=" + action.toString() + ")");
                    }
                }
            } else {
                for (Action action : permission.getActions()) {
                    AuthResult result;
                    if (authManager.authorize(user, action)) {
                        result = AuthResult.allow("checkPermissions", "Global action allowed", user, action, null, null);
                    } else {
                        result = AuthResult.deny("checkPermissions", "Global action denied", user, action, null, null);
                    }
                    logResult(result);
                    if (!result.isAllowed()) {
                        // effective permissions, so throw unconditionally
                        throw new AccessDeniedException("Insufficient permissions (action=" + action.toString() + ")");
                    }
                }
            }
        }
        response = AccessControlProtos.CheckPermissionsResponse.getDefaultInstance();
    } catch (IOException ioe) {
        CoprocessorRpcUtils.setControllerException(controller, ioe);
    }
    done.run(response);
}
Also used : PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Action(org.apache.hadoop.hbase.security.access.Permission.Action) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) User(org.apache.hadoop.hbase.security.User) Set(java.util.Set) TreeSet(java.util.TreeSet) ImmutableSet(com.google.common.collect.ImmutableSet) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TreeMap(java.util.TreeMap) ReplicationEndpoint(org.apache.hadoop.hbase.replication.ReplicationEndpoint) AccessControlProtos(org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos) TableName(org.apache.hadoop.hbase.TableName) CoprocessorException(org.apache.hadoop.hbase.coprocessor.CoprocessorException)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1033 Test (org.junit.Test)695 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)257 Table (org.apache.hadoop.hbase.client.Table)228 IOException (java.io.IOException)225 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)215 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)203 Result (org.apache.hadoop.hbase.client.Result)125 ArrayList (java.util.ArrayList)120 Put (org.apache.hadoop.hbase.client.Put)118 Path (org.apache.hadoop.fs.Path)113 Connection (org.apache.hadoop.hbase.client.Connection)103 Scan (org.apache.hadoop.hbase.client.Scan)98 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)89 ServerName (org.apache.hadoop.hbase.ServerName)85 Admin (org.apache.hadoop.hbase.client.Admin)85 Cell (org.apache.hadoop.hbase.Cell)77 HashMap (java.util.HashMap)75 Delete (org.apache.hadoop.hbase.client.Delete)66 InterruptedIOException (java.io.InterruptedIOException)63