Search in sources :

Example 1 with JobState

use of org.apache.hive.hcatalog.templeton.tool.JobState in project hive by apache.

the class CompleteDelegator method run.

public CompleteBean run(String id, String jobStatus) throws CallbackFailedException, IOException {
    if (id == null)
        acceptWithError("No jobid given");
    JobState state = null;
    /* we don't want to cancel the delegation token if we think the callback is going to
     to be retried, for example, because the job is not complete yet */
    boolean cancelMetastoreToken = false;
    try {
        state = new JobState(id, Main.getAppConfigInstance());
        if (state.getCompleteStatus() == null)
            failed("Job not yet complete. jobId=" + id + " Status from JobTracker=" + jobStatus, null);
        Long notified = state.getNotifiedTime();
        if (notified != null) {
            cancelMetastoreToken = true;
            return acceptWithError("Callback already run for jobId=" + id + " at " + new Date(notified));
        }
        String callback = state.getCallback();
        if (callback == null) {
            cancelMetastoreToken = true;
            return new CompleteBean("No callback registered");
        }
        try {
            doCallback(state.getId(), callback);
            cancelMetastoreToken = true;
        } catch (Exception e) {
            failed("Callback failed " + callback + " for " + id, e);
        }
        state.setNotifiedTime(System.currentTimeMillis());
        return new CompleteBean("Callback sent");
    } finally {
        state.close();
        IMetaStoreClient client = null;
        try {
            if (cancelMetastoreToken) {
                String metastoreTokenStrForm = DelegationTokenCache.getStringFormTokenCache().getDelegationToken(id);
                if (metastoreTokenStrForm != null) {
                    client = HCatUtil.getHiveMetastoreClient(new HiveConf());
                    client.cancelDelegationToken(metastoreTokenStrForm);
                    LOG.debug("Cancelled token for jobId=" + id + " status from JT=" + jobStatus);
                    DelegationTokenCache.getStringFormTokenCache().removeDelegationToken(id);
                }
            }
        } catch (Exception ex) {
            LOG.warn("Failed to cancel metastore delegation token for jobId=" + id, ex);
        } finally {
            HCatUtil.closeHiveClientQuietly(client);
        }
    }
}
Also used : JobState(org.apache.hive.hcatalog.templeton.tool.JobState) HiveConf(org.apache.hadoop.hive.conf.HiveConf) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) Date(java.util.Date) IOException(java.io.IOException)

Example 2 with JobState

use of org.apache.hive.hcatalog.templeton.tool.JobState in project hive by apache.

the class DeleteDelegator method run.

public QueueStatusBean run(String user, String id) throws NotAuthorizedException, BadParam, IOException, InterruptedException {
    UserGroupInformation ugi = UgiFactory.getUgi(user);
    WebHCatJTShim tracker = null;
    JobState state = null;
    try {
        tracker = ShimLoader.getHadoopShims().getWebHCatShim(appConf, ugi);
        JobID jobid = StatusDelegator.StringToJobID(id);
        if (jobid == null)
            throw new BadParam("Invalid jobid: " + id);
        tracker.killJob(jobid);
        state = new JobState(id, Main.getAppConfigInstance());
        List<JobState> children = state.getChildren();
        if (children != null) {
            for (JobState child : children) {
                try {
                    tracker.killJob(StatusDelegator.StringToJobID(child.getId()));
                } catch (IOException e) {
                    LOG.warn("templeton: fail to kill job " + child.getId());
                }
            }
        }
        return StatusDelegator.makeStatus(tracker, jobid, state);
    } catch (IllegalStateException e) {
        throw new BadParam(e.getMessage());
    } finally {
        if (tracker != null)
            tracker.close();
        if (state != null)
            state.close();
    }
}
Also used : WebHCatJTShim(org.apache.hadoop.hive.shims.HadoopShims.WebHCatJTShim) JobState(org.apache.hive.hcatalog.templeton.tool.JobState) IOException(java.io.IOException) JobID(org.apache.hadoop.mapred.JobID) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 3 with JobState

use of org.apache.hive.hcatalog.templeton.tool.JobState in project hive by apache.

the class StatusDelegator method getJobStatus.

public QueueStatusBean getJobStatus(String user, String id) throws NotAuthorizedException, BadParam, IOException, InterruptedException {
    WebHCatJTShim tracker = null;
    JobState state = null;
    try {
        UserGroupInformation ugi = UgiFactory.getUgi(user);
        tracker = ShimLoader.getHadoopShims().getWebHCatShim(appConf, ugi);
        JobID jobid = StatusDelegator.StringToJobID(id);
        if (jobid == null)
            throw new BadParam("Invalid jobid: " + id);
        state = new JobState(id, Main.getAppConfigInstance());
        return StatusDelegator.makeStatus(tracker, jobid, state);
    } catch (IllegalStateException e) {
        throw new BadParam(e.getMessage());
    } finally {
        if (tracker != null)
            tracker.close();
        if (state != null)
            state.close();
    }
}
Also used : WebHCatJTShim(org.apache.hadoop.hive.shims.HadoopShims.WebHCatJTShim) JobState(org.apache.hive.hcatalog.templeton.tool.JobState) JobID(org.apache.hadoop.mapred.JobID) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 4 with JobState

use of org.apache.hive.hcatalog.templeton.tool.JobState in project hive by apache.

the class LauncherDelegator method registerJob.

public void registerJob(String id, String user, String callback, Map<String, Object> userArgs) throws IOException {
    JobState state = null;
    try {
        state = new JobState(id, Main.getAppConfigInstance());
        state.setUser(user);
        state.setCallback(callback);
        state.setUserArgs(userArgs);
    } finally {
        if (state != null)
            state.close();
    }
}
Also used : JobState(org.apache.hive.hcatalog.templeton.tool.JobState)

Aggregations

JobState (org.apache.hive.hcatalog.templeton.tool.JobState)4 IOException (java.io.IOException)2 WebHCatJTShim (org.apache.hadoop.hive.shims.HadoopShims.WebHCatJTShim)2 JobID (org.apache.hadoop.mapred.JobID)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 Date (java.util.Date)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)1