Search in sources :

Example 1 with HCatAccessorException

use of org.apache.oozie.service.HCatAccessorException in project oozie by apache.

the class HCatURIHandler method registerForNotification.

@Override
public void registerForNotification(URI uri, Configuration conf, String user, String actionID) throws URIHandlerException {
    HCatURI hcatURI;
    try {
        hcatURI = new HCatURI(uri);
    } catch (URISyntaxException e) {
        throw new URIHandlerException(ErrorCode.E0906, uri, e);
    }
    HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
    if (!hcatService.isRegisteredForNotification(hcatURI)) {
        HCatClient client = getHCatClient(uri, conf);
        try {
            String topic = client.getMessageBusTopicName(hcatURI.getDb(), hcatURI.getTable());
            if (topic == null) {
                return;
            }
            hcatService.registerForNotification(hcatURI, topic, new HCatMessageHandler(uri.getAuthority()));
        } catch (HCatException e) {
            throw new HCatAccessorException(ErrorCode.E1501, e);
        } finally {
            closeQuietly(client, null, true);
        }
    }
    PartitionDependencyManagerService pdmService = Services.get().get(PartitionDependencyManagerService.class);
    pdmService.addMissingDependency(hcatURI, actionID);
}
Also used : HCatAccessorService(org.apache.oozie.service.HCatAccessorService) HCatClient(org.apache.hive.hcatalog.api.HCatClient) HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) HCatException(org.apache.hive.hcatalog.common.HCatException) URISyntaxException(java.net.URISyntaxException) HCatURI(org.apache.oozie.util.HCatURI) HCatAccessorException(org.apache.oozie.service.HCatAccessorException) PartitionDependencyManagerService(org.apache.oozie.service.PartitionDependencyManagerService)

Example 2 with HCatAccessorException

use of org.apache.oozie.service.HCatAccessorException in project oozie by apache.

the class HCatURIHandler method getHCatClient.

private HCatClientWithToken getHCatClient(URI uri, Configuration conf, String user) throws HCatAccessorException {
    final HiveConf hiveConf = getHiveConf(uri, conf);
    String delegationToken = null;
    try {
        // Get UGI to doAs() as the specified user
        UserGroupInformation ugi = UserGroupInformation.createProxyUser(user, UserGroupInformation.getLoginUser());
        // Define the label for the Delegation Token for the HCat instance.
        hiveConf.set("hive.metastore.token.signature", "HCatTokenSignature");
        if (hiveConf.getBoolean(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname, false)) {
            HCatClient tokenClient = null;
            try {
                // Retrieve Delegation token for HCatalog
                tokenClient = HCatClient.create(hiveConf);
                delegationToken = tokenClient.getDelegationToken(user, UserGroupInformation.getLoginUser().getUserName());
                // Store Delegation token in the UGI
                Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>();
                token.decodeFromUrlString(delegationToken);
                token.setService(new Text(hiveConf.get("hive.metastore.token.signature")));
                ugi.addToken(token);
            } finally {
                if (tokenClient != null) {
                    tokenClient.close();
                }
            }
        }
        XLog.getLog(HCatURIHandler.class).info("Creating HCatClient for user [{0}] login_user [{1}] and server [{2}] ", user, UserGroupInformation.getLoginUser(), hiveConf.get(HiveConf.ConfVars.METASTOREURIS.varname));
        HCatClient hcatClient = ugi.doAs(new PrivilegedExceptionAction<HCatClient>() {

            @Override
            public HCatClient run() throws Exception {
                HCatClient client = HCatClient.create(hiveConf);
                return client;
            }
        });
        HCatClientWithToken clientWithToken = new HCatClientWithToken(hcatClient, delegationToken);
        return clientWithToken;
    } catch (IOException e) {
        throw new HCatAccessorException(ErrorCode.E1501, e.getMessage());
    } catch (Exception e) {
        throw new HCatAccessorException(ErrorCode.E1501, e.getMessage());
    }
}
Also used : DelegationTokenIdentifier(org.apache.hadoop.hive.thrift.DelegationTokenIdentifier) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) HCatAccessorException(org.apache.oozie.service.HCatAccessorException) HCatException(org.apache.hive.hcatalog.common.HCatException) URISyntaxException(java.net.URISyntaxException) HCatAccessorException(org.apache.oozie.service.HCatAccessorException) ConnectionFailureException(org.apache.hive.hcatalog.api.ConnectionFailureException) IOException(java.io.IOException) HCatClient(org.apache.hive.hcatalog.api.HCatClient) HiveConf(org.apache.hadoop.hive.conf.HiveConf) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 3 with HCatAccessorException

use of org.apache.oozie.service.HCatAccessorException in project oozie by apache.

the class HCatURIHandler method exists.

private boolean exists(URI uri, HCatClient client, boolean closeClient) throws HCatAccessorException {
    try {
        boolean flag;
        HCatURI hcatURI = new HCatURI(uri.toString());
        if (!hcatURI.getPartitionMap().isEmpty()) {
            List<HCatPartition> partitions = client.getPartitions(hcatURI.getDb(), hcatURI.getTable(), hcatURI.getPartitionMap());
            flag = partitions != null && !partitions.isEmpty();
        } else {
            List<String> tables = client.listTableNamesByPattern(hcatURI.getDb(), hcatURI.getTable());
            flag = tables != null && !tables.isEmpty();
        }
        return (flag);
    } catch (ConnectionFailureException e) {
        throw new HCatAccessorException(ErrorCode.E1501, e);
    } catch (HCatException e) {
        throw new HCatAccessorException(ErrorCode.E0902, e);
    } catch (URISyntaxException e) {
        throw new HCatAccessorException(ErrorCode.E0902, e);
    } finally {
        closeQuietly(client, null, closeClient);
    }
}
Also used : ConnectionFailureException(org.apache.hive.hcatalog.api.ConnectionFailureException) HCatException(org.apache.hive.hcatalog.common.HCatException) URISyntaxException(java.net.URISyntaxException) HCatURI(org.apache.oozie.util.HCatURI) HCatAccessorException(org.apache.oozie.service.HCatAccessorException) HCatPartition(org.apache.hive.hcatalog.api.HCatPartition)

Example 4 with HCatAccessorException

use of org.apache.oozie.service.HCatAccessorException in project oozie by apache.

the class HCatURIHandler method delete.

@Override
public void delete(URI uri, Configuration conf, String user) throws URIHandlerException {
    HCatClientWithToken client = null;
    HCatClient hCatClient = null;
    try {
        HCatURI hcatUri = new HCatURI(uri);
        client = getHCatClient(uri, conf, user);
        hCatClient = client.getHCatClient();
        if (!hcatUri.getPartitionMap().isEmpty()) {
            hCatClient.dropPartitions(hcatUri.getDb(), hcatUri.getTable(), hcatUri.getPartitionMap(), true);
        } else {
            hCatClient.dropTable(hcatUri.getDb(), hcatUri.getTable(), true);
        }
    } catch (URISyntaxException e) {
        throw new HCatAccessorException(ErrorCode.E1501, e);
    } catch (HCatException e) {
        throw new HCatAccessorException(ErrorCode.E1501, e);
    } finally {
        closeQuietly(hCatClient, client != null ? client.getDelegationToken() : null, true);
    }
}
Also used : HCatClient(org.apache.hive.hcatalog.api.HCatClient) HCatException(org.apache.hive.hcatalog.common.HCatException) URISyntaxException(java.net.URISyntaxException) HCatURI(org.apache.oozie.util.HCatURI) HCatAccessorException(org.apache.oozie.service.HCatAccessorException)

Example 5 with HCatAccessorException

use of org.apache.oozie.service.HCatAccessorException in project oozie by apache.

the class HCatURIHandler method getMetastoreConnectURI.

private String getMetastoreConnectURI(URI uri) throws HCatAccessorException {
    String metastoreURI;
    // For unit tests
    if (uri.getAuthority().equals("unittest-local")) {
        metastoreURI = "";
    } else {
        // Hardcoding hcat to thrift mapping till support for webhcat(templeton)
        // is added
        HCatURI hCatURI;
        try {
            hCatURI = new HCatURI(uri.toString());
            metastoreURI = hCatURI.getServerEndPointWithScheme("thrift");
        } catch (URISyntaxException e) {
            throw new HCatAccessorException(ErrorCode.E0902, e);
        }
    }
    return metastoreURI;
}
Also used : URISyntaxException(java.net.URISyntaxException) HCatURI(org.apache.oozie.util.HCatURI) HCatAccessorException(org.apache.oozie.service.HCatAccessorException)

Aggregations

URISyntaxException (java.net.URISyntaxException)5 HCatAccessorException (org.apache.oozie.service.HCatAccessorException)5 HCatException (org.apache.hive.hcatalog.common.HCatException)4 HCatURI (org.apache.oozie.util.HCatURI)4 HCatClient (org.apache.hive.hcatalog.api.HCatClient)3 ConnectionFailureException (org.apache.hive.hcatalog.api.ConnectionFailureException)2 IOException (java.io.IOException)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 DelegationTokenIdentifier (org.apache.hadoop.hive.thrift.DelegationTokenIdentifier)1 Text (org.apache.hadoop.io.Text)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 Token (org.apache.hadoop.security.token.Token)1 HCatPartition (org.apache.hive.hcatalog.api.HCatPartition)1 HCatMessageHandler (org.apache.oozie.dependency.hcat.HCatMessageHandler)1 HCatAccessorService (org.apache.oozie.service.HCatAccessorService)1 PartitionDependencyManagerService (org.apache.oozie.service.PartitionDependencyManagerService)1