Search in sources :

Example 6 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method alterFunction.

@Override
public void alterFunction(String dbName, String funcName, Function newFunction) throws InvalidObjectException, MetaException {
    boolean success = false;
    try {
        openTransaction();
        funcName = HiveStringUtils.normalizeIdentifier(funcName);
        dbName = HiveStringUtils.normalizeIdentifier(dbName);
        MFunction newf = convertToMFunction(newFunction);
        if (newf == null) {
            throw new InvalidObjectException("new function is invalid");
        }
        MFunction oldf = getMFunction(dbName, funcName);
        if (oldf == null) {
            throw new MetaException("function " + funcName + " doesn't exist");
        }
        // For now only alter name, owner, class name, type
        oldf.setFunctionName(HiveStringUtils.normalizeIdentifier(newf.getFunctionName()));
        oldf.setDatabase(newf.getDatabase());
        oldf.setOwnerName(newf.getOwnerName());
        oldf.setOwnerType(newf.getOwnerType());
        oldf.setClassName(newf.getClassName());
        oldf.setFunctionType(newf.getFunctionType());
        // commit the changes
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
}
Also used : MFunction(org.apache.hadoop.hive.metastore.model.MFunction) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 7 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method revokeRole.

@Override
public boolean revokeRole(Role role, String userName, PrincipalType principalType, boolean grantOption) throws MetaException, NoSuchObjectException {
    boolean success = false;
    try {
        openTransaction();
        MRoleMap roleMember = getMSecurityUserRoleMap(userName, principalType, role.getRoleName());
        if (grantOption) {
            // Revoke with grant option - only remove the grant option but keep the role.
            if (roleMember.getGrantOption()) {
                roleMember.setGrantOption(false);
            } else {
                throw new MetaException("User " + userName + " does not have grant option with role " + role.getRoleName());
            }
        } else {
            // No grant option in revoke, remove the whole role.
            pm.deletePersistent(roleMember);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 8 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method alterPartition.

@Override
public void alterPartition(String dbname, String name, List<String> part_vals, Partition newPart) throws InvalidObjectException, MetaException {
    boolean success = false;
    Exception e = null;
    try {
        openTransaction();
        alterPartitionNoTxn(dbname, name, part_vals, newPart);
        // commit the changes
        success = commitTransaction();
    } catch (Exception exception) {
        e = exception;
    } finally {
        if (!success) {
            rollbackTransaction();
            MetaException metaException = new MetaException("The transaction for alter partition did not commit successfully.");
            if (e != null) {
                metaException.initCause(e);
            }
            throw metaException;
        }
    }
}
Also used : JDOException(javax.jdo.JDOException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 9 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method revokePrivileges.

@Override
public boolean revokePrivileges(PrivilegeBag privileges, boolean grantOption) throws InvalidObjectException, MetaException, NoSuchObjectException {
    boolean committed = false;
    try {
        openTransaction();
        List<Object> persistentObjs = new ArrayList<Object>();
        List<HiveObjectPrivilege> privilegeList = privileges.getPrivileges();
        if (privilegeList != null && privilegeList.size() > 0) {
            Iterator<HiveObjectPrivilege> privIter = privilegeList.iterator();
            while (privIter.hasNext()) {
                HiveObjectPrivilege privDef = privIter.next();
                HiveObjectRef hiveObject = privDef.getHiveObject();
                String privilegeStr = privDef.getGrantInfo().getPrivilege();
                if (privilegeStr == null || privilegeStr.trim().equals("")) {
                    continue;
                }
                String[] privs = privilegeStr.split(",");
                String userName = privDef.getPrincipalName();
                PrincipalType principalType = privDef.getPrincipalType();
                if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) {
                    List<MGlobalPrivilege> mSecUser = this.listPrincipalMGlobalGrants(userName, principalType);
                    boolean found = false;
                    if (mSecUser != null) {
                        for (String privilege : privs) {
                            for (MGlobalPrivilege userGrant : mSecUser) {
                                String userGrantPrivs = userGrant.getPrivilege();
                                if (privilege.equals(userGrantPrivs)) {
                                    found = true;
                                    if (grantOption) {
                                        if (userGrant.getGrantOption()) {
                                            userGrant.setGrantOption(false);
                                        } else {
                                            throw new MetaException("User " + userName + " does not have grant option with privilege " + privilege);
                                        }
                                    }
                                    persistentObjs.add(userGrant);
                                    break;
                                }
                            }
                            if (!found) {
                                throw new InvalidObjectException("No user grant found for privileges " + privilege);
                            }
                        }
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.DATABASE) {
                    MDatabase dbObj = getMDatabase(hiveObject.getDbName());
                    if (dbObj != null) {
                        String db = hiveObject.getDbName();
                        boolean found = false;
                        List<MDBPrivilege> dbGrants = this.listPrincipalMDBGrants(userName, principalType, db);
                        for (String privilege : privs) {
                            for (MDBPrivilege dbGrant : dbGrants) {
                                String dbGrantPriv = dbGrant.getPrivilege();
                                if (privilege.equals(dbGrantPriv)) {
                                    found = true;
                                    if (grantOption) {
                                        if (dbGrant.getGrantOption()) {
                                            dbGrant.setGrantOption(false);
                                        } else {
                                            throw new MetaException("User " + userName + " does not have grant option with privilege " + privilege);
                                        }
                                    }
                                    persistentObjs.add(dbGrant);
                                    break;
                                }
                            }
                            if (!found) {
                                throw new InvalidObjectException("No database grant found for privileges " + privilege + " on database " + db);
                            }
                        }
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.TABLE) {
                    boolean found = false;
                    List<MTablePrivilege> tableGrants = this.listAllMTableGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName());
                    for (String privilege : privs) {
                        for (MTablePrivilege tabGrant : tableGrants) {
                            String tableGrantPriv = tabGrant.getPrivilege();
                            if (privilege.equalsIgnoreCase(tableGrantPriv)) {
                                found = true;
                                if (grantOption) {
                                    if (tabGrant.getGrantOption()) {
                                        tabGrant.setGrantOption(false);
                                    } else {
                                        throw new MetaException("User " + userName + " does not have grant option with privilege " + privilege);
                                    }
                                }
                                persistentObjs.add(tabGrant);
                                break;
                            }
                        }
                        if (!found) {
                            throw new InvalidObjectException("No grant (" + privilege + ") found " + " on table " + hiveObject.getObjectName() + ", database is " + hiveObject.getDbName());
                        }
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.PARTITION) {
                    boolean found = false;
                    Table tabObj = this.getTable(hiveObject.getDbName(), hiveObject.getObjectName());
                    String partName = null;
                    if (hiveObject.getPartValues() != null) {
                        partName = Warehouse.makePartName(tabObj.getPartitionKeys(), hiveObject.getPartValues());
                    }
                    List<MPartitionPrivilege> partitionGrants = this.listPrincipalMPartitionGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName(), partName);
                    for (String privilege : privs) {
                        for (MPartitionPrivilege partGrant : partitionGrants) {
                            String partPriv = partGrant.getPrivilege();
                            if (partPriv.equalsIgnoreCase(privilege)) {
                                found = true;
                                if (grantOption) {
                                    if (partGrant.getGrantOption()) {
                                        partGrant.setGrantOption(false);
                                    } else {
                                        throw new MetaException("User " + userName + " does not have grant option with privilege " + privilege);
                                    }
                                }
                                persistentObjs.add(partGrant);
                                break;
                            }
                        }
                        if (!found) {
                            throw new InvalidObjectException("No grant (" + privilege + ") found " + " on table " + tabObj.getTableName() + ", partition is " + partName + ", database is " + tabObj.getDbName());
                        }
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.COLUMN) {
                    Table tabObj = this.getTable(hiveObject.getDbName(), hiveObject.getObjectName());
                    String partName = null;
                    if (hiveObject.getPartValues() != null) {
                        partName = Warehouse.makePartName(tabObj.getPartitionKeys(), hiveObject.getPartValues());
                    }
                    if (partName != null) {
                        List<MPartitionColumnPrivilege> mSecCol = listPrincipalMPartitionColumnGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName(), partName, hiveObject.getColumnName());
                        boolean found = false;
                        if (mSecCol != null) {
                            for (String privilege : privs) {
                                for (MPartitionColumnPrivilege col : mSecCol) {
                                    String colPriv = col.getPrivilege();
                                    if (colPriv.equalsIgnoreCase(privilege)) {
                                        found = true;
                                        if (grantOption) {
                                            if (col.getGrantOption()) {
                                                col.setGrantOption(false);
                                            } else {
                                                throw new MetaException("User " + userName + " does not have grant option with privilege " + privilege);
                                            }
                                        }
                                        persistentObjs.add(col);
                                        break;
                                    }
                                }
                                if (!found) {
                                    throw new InvalidObjectException("No grant (" + privilege + ") found " + " on table " + tabObj.getTableName() + ", partition is " + partName + ", column name = " + hiveObject.getColumnName() + ", database is " + tabObj.getDbName());
                                }
                            }
                        }
                    } else {
                        List<MTableColumnPrivilege> mSecCol = listPrincipalMTableColumnGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName(), hiveObject.getColumnName());
                        boolean found = false;
                        if (mSecCol != null) {
                            for (String privilege : privs) {
                                for (MTableColumnPrivilege col : mSecCol) {
                                    String colPriv = col.getPrivilege();
                                    if (colPriv.equalsIgnoreCase(privilege)) {
                                        found = true;
                                        if (grantOption) {
                                            if (col.getGrantOption()) {
                                                col.setGrantOption(false);
                                            } else {
                                                throw new MetaException("User " + userName + " does not have grant option with privilege " + privilege);
                                            }
                                        }
                                        persistentObjs.add(col);
                                        break;
                                    }
                                }
                                if (!found) {
                                    throw new InvalidObjectException("No grant (" + privilege + ") found " + " on table " + tabObj.getTableName() + ", column name = " + hiveObject.getColumnName() + ", database is " + tabObj.getDbName());
                                }
                            }
                        }
                    }
                }
            }
        }
        if (persistentObjs.size() > 0) {
            if (grantOption) {
            // If grant option specified, only update the privilege, don't remove it.
            // Grant option has already been removed from the privileges in the section above
            } else {
                pm.deletePersistentAll(persistentObjs);
            }
        }
        committed = commitTransaction();
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
    }
    return committed;
}
Also used : ArrayList(java.util.ArrayList) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Table(org.apache.hadoop.hive.metastore.api.Table) MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) MTable(org.apache.hadoop.hive.metastore.model.MTable) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) MDBPrivilege(org.apache.hadoop.hive.metastore.model.MDBPrivilege) MGlobalPrivilege(org.apache.hadoop.hive.metastore.model.MGlobalPrivilege) MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege)

Example 10 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method addPartitions.

@Override
public boolean addPartitions(String dbName, String tblName, List<Partition> parts) throws InvalidObjectException, MetaException {
    boolean success = false;
    openTransaction();
    try {
        List<MTablePrivilege> tabGrants = null;
        List<MTableColumnPrivilege> tabColumnGrants = null;
        MTable table = this.getMTable(dbName, tblName);
        if ("TRUE".equalsIgnoreCase(table.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) {
            tabGrants = this.listAllTableGrants(dbName, tblName);
            tabColumnGrants = this.listTableAllColumnGrants(dbName, tblName);
        }
        List<Object> toPersist = new ArrayList<Object>();
        for (Partition part : parts) {
            if (!part.getTableName().equals(tblName) || !part.getDbName().equals(dbName)) {
                throw new MetaException("Partition does not belong to target table " + dbName + "." + tblName + ": " + part);
            }
            MPartition mpart = convertToMPart(part, true);
            toPersist.add(mpart);
            int now = (int) (System.currentTimeMillis() / 1000);
            if (tabGrants != null) {
                for (MTablePrivilege tab : tabGrants) {
                    toPersist.add(new MPartitionPrivilege(tab.getPrincipalName(), tab.getPrincipalType(), mpart, tab.getPrivilege(), now, tab.getGrantor(), tab.getGrantorType(), tab.getGrantOption()));
                }
            }
            if (tabColumnGrants != null) {
                for (MTableColumnPrivilege col : tabColumnGrants) {
                    toPersist.add(new MPartitionColumnPrivilege(col.getPrincipalName(), col.getPrincipalType(), mpart, col.getColumnName(), col.getPrivilege(), now, col.getGrantor(), col.getGrantorType(), col.getGrantOption()));
                }
            }
        }
        if (toPersist.size() > 0) {
            pm.makePersistentAll(toPersist);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MPartition(org.apache.hadoop.hive.metastore.model.MPartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) ArrayList(java.util.ArrayList) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) MTable(org.apache.hadoop.hive.metastore.model.MTable) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Aggregations

MetaException (org.apache.hadoop.hive.metastore.api.MetaException)232 IOException (java.io.IOException)97 ArrayList (java.util.ArrayList)66 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)55 TException (org.apache.thrift.TException)50 Table (org.apache.hadoop.hive.metastore.api.Table)43 Partition (org.apache.hadoop.hive.metastore.api.Partition)37 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)33 Path (org.apache.hadoop.fs.Path)32 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)21 Database (org.apache.hadoop.hive.metastore.api.Database)20 SQLException (java.sql.SQLException)19 List (java.util.List)19 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)18 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)17 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)17 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)17 HashMap (java.util.HashMap)16 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)15 Connection (java.sql.Connection)14