Exemple #1
0
def check_job_execution_cancel(job_id, **kwargs):
    ctx = context.current()
    je = conductor.job_execution_get(ctx, job_id)

    if je.tenant_id != ctx.tenant_id:
        raise ex.CancelingFailed(
            _("Job execution with id '%s' cannot be canceled "
              "because it wasn't created in this tenant") % job_id)

    if je.is_protected:
        raise ex.CancelingFailed(
            _("Job Execution with id '%s' cannot be canceled "
              "because it's marked as protected") % job_id)
Exemple #2
0
def cancel_job(job_execution_id):
    ctx = context.ctx()
    job_execution = conductor.job_execution_get(ctx, job_execution_id)
    if job_execution.info['status'] in edp.JOB_STATUSES_TERMINATED:
        return job_execution
    cluster = conductor.cluster_get(ctx, job_execution.cluster_id)
    if cluster is None:
        return job_execution
    engine = _get_job_engine(cluster, job_execution)
    if engine is not None:
        job_execution = conductor.job_execution_update(
            ctx, job_execution_id,
            {'info': {
                'status': edp.JOB_STATUS_TOBEKILLED
            }})

        timeout = CONF.job_canceling_timeout
        s_time = timeutils.utcnow()
        while timeutils.delta_seconds(s_time, timeutils.utcnow()) < timeout:
            if job_execution.info['status'] not in edp.JOB_STATUSES_TERMINATED:
                try:
                    job_info = engine.cancel_job(job_execution)
                except Exception as ex:
                    job_info = None
                    LOG.exception(
                        _LE("Error during cancel of job execution %(job)s: "
                            "%(error)s"), {
                                'job': job_execution.id,
                                'error': ex
                            })
                if job_info is not None:
                    job_execution = _write_job_status(job_execution, job_info)
                    LOG.info(_LI("Job execution %s was canceled successfully"),
                             job_execution.id)
                    return job_execution
                context.sleep(3)
                job_execution = conductor.job_execution_get(
                    ctx, job_execution_id)
                if not job_execution:
                    LOG.info(
                        _LI("Job execution %(job_exec_id)s was deleted. "
                            "Canceling current operation."),
                        {'job_exec_id': job_execution_id})
                    return job_execution
            else:
                LOG.info(
                    _LI("Job execution status %(job)s: %(status)s"), {
                        'job': job_execution.id,
                        'status': job_execution.info['status']
                    })
                return job_execution
        else:
            raise e.CancelingFailed(
                _('Job execution %s was not canceled') % job_execution.id)
Exemple #3
0
def cancel_job(job_execution_id):
    ctx = context.ctx()
    job_execution = conductor.job_execution_get(ctx, job_execution_id)
    if job_execution.info['status'] in edp.JOB_STATUSES_TERMINATED:
        LOG.info(
            _LI("Job execution is already finished and shouldn't be"
                " canceled"))
        return job_execution
    cluster = conductor.cluster_get(ctx, job_execution.cluster_id)
    if cluster is None:
        LOG.info(_LI("Can not cancel this job on a non-existant cluster."))
        return job_execution
    engine = get_job_engine(cluster, job_execution)
    if engine is not None:
        job_execution = conductor.job_execution_update(
            ctx, job_execution_id,
            {'info': {
                'status': edp.JOB_STATUS_TOBEKILLED
            }})

        timeout = CONF.job_canceling_timeout
        s_time = timeutils.utcnow()
        while timeutils.delta_seconds(s_time, timeutils.utcnow()) < timeout:
            if job_execution.info['status'] not in edp.JOB_STATUSES_TERMINATED:
                try:
                    job_info = engine.cancel_job(job_execution)
                except Exception as ex:
                    job_info = None
                    LOG.warning(
                        _LW("Error during cancel of job execution: "
                            "{error}").format(error=ex))
                if job_info is not None:
                    job_execution = _write_job_status(job_execution, job_info)
                    LOG.info(_LI("Job execution was canceled successfully"))
                    return job_execution
                context.sleep(3)
                job_execution = conductor.job_execution_get(
                    ctx, job_execution_id)
                if not job_execution:
                    LOG.info(
                        _LI("Job execution was deleted. "
                            "Canceling current operation."))
                    return job_execution
            else:
                LOG.info(
                    _LI("Job execution status: {status}").format(
                        status=job_execution.info['status']))
                return job_execution
        else:
            raise e.CancelingFailed(
                _('Job execution %s was not canceled') % job_execution.id)