Ejemplo n.º 1
0
def projects_notebook_build(notebook_job_id):
    notebook_job = get_valid_notebook(notebook_job_id=notebook_job_id)
    if not notebook_job:
        _logger.warning('Notebook %s does not exist anymore.', notebook_job_id)
        return None

    if not JobLifeCycle.can_transition(status_from=notebook_job.last_status,
                                       status_to=JobLifeCycle.BUILDING):
        _logger.info('Notebook `%s` cannot transition from `%s` to `%s`.',
                     notebook_job, notebook_job.last_status, JobLifeCycle.BUILDING)
        return

    build_job, image_exists, build_status = dockerizer_scheduler.create_build_job(
        user=notebook_job.user,
        project=notebook_job.project,
        config=notebook_job.specification.build,
        code_reference=notebook_job.code_reference)

    notebook_job.build_job = build_job
    notebook_job.save()
    if image_exists:
        # The image already exists, so we can start the experiment right away
        celery_app.send_task(
            SchedulerCeleryTasks.PROJECTS_NOTEBOOK_START,
            kwargs={'notebook_job_id': notebook_job_id})
        return

    if not build_status:
        notebook_job.set_status(JobLifeCycle.FAILED, message='Could not start build process.')
        return

    # Update job status to show that its building docker image
    notebook_job.set_status(JobLifeCycle.BUILDING, message='Building container')
Ejemplo n.º 2
0
def projects_notebook_stop(self,
                           project_name,
                           project_uuid,
                           notebook_job_name,
                           notebook_job_uuid,
                           update_status=True,
                           collect_logs=False,
                           message=None):
    deleted = notebook_scheduler.stop_notebook(
        project_name=project_name,
        project_uuid=project_uuid,
        notebook_job_name=notebook_job_name,
        notebook_job_uuid=notebook_job_uuid)

    if not deleted and self.request.retries < 2:
        _logger.info('Trying again to delete job `%s`.', notebook_job_name)
        self.retry(countdown=Intervals.EXPERIMENTS_SCHEDULER)
        return

    if not update_status:
        return

    notebook = get_valid_notebook(notebook_job_uuid=notebook_job_uuid, include_deleted=True)
    if not notebook:
        return None

    # Update notebook status to show that its stopped
    notebook.set_status(status=JobLifeCycle.STOPPED,
                        message=message or 'Notebook was stopped')
Ejemplo n.º 3
0
def projects_notebook_schedule_deletion(notebook_job_id, immediate=False):
    notebook_job = get_valid_notebook(notebook_job_id=notebook_job_id, include_deleted=True)
    if not notebook_job:
        return None

    notebook_job.archive()

    if notebook_job.is_stoppable:
        project = notebook_job.project
        workers.send(
            SchedulerCeleryTasks.PROJECTS_NOTEBOOK_STOP,
            kwargs={
                'project_name': project.unique_name,
                'project_uuid': project.uuid.hex,
                'notebook_job_name': notebook_job.unique_name,
                'notebook_job_uuid': notebook_job.uuid.hex,
                'update_status': True,
                'collect_logs': False,
                'is_managed': notebook_job.is_managed,
                'message': 'Notebook is scheduled for deletion.'
            })

    if immediate:
        workers.send(
            SchedulerCeleryTasks.DELETE_ARCHIVED_NOTEBOOK_JOB,
            kwargs={'job_id': notebook_job_id},
            countdown=conf.get(SCHEDULER_GLOBAL_COUNTDOWN_DELAYED))
Ejemplo n.º 4
0
def projects_notebook_start(notebook_job_id):
    notebook_job = get_valid_notebook(notebook_job_id=notebook_job_id)
    if not notebook_job:
        return None

    if not JobLifeCycle.can_transition(status_from=notebook_job.last_status,
                                       status_to=JobLifeCycle.SCHEDULED):
        _logger.info('Notebook `%s` cannot transition from `%s` to `%s`.',
                     notebook_job.unique_name, notebook_job.last_status, JobLifeCycle.SCHEDULED)

    notebook_scheduler.start_notebook(notebook_job)
Ejemplo n.º 5
0
def projects_notebook_start(notebook_job_id):
    notebook_job = get_valid_notebook(notebook_job_id=notebook_job_id)
    if not notebook_job:
        _logger.warning('Notebook %s does not exist anymore.', notebook_job_id)
        return None

    if not JobLifeCycle.can_transition(status_from=notebook_job.last_status,
                                       status_to=JobLifeCycle.SCHEDULED):
        _logger.info('Notebook `%s` cannot transition from `%s` to `%s`.',
                     notebook_job.unique_name, notebook_job.last_status, JobLifeCycle.SCHEDULED)

    notebook_scheduler.start_notebook(notebook_job)
Ejemplo n.º 6
0
def projects_notebook_schedule_deletion(notebook_job_id):
    notebook_job = get_valid_notebook(notebook_job_id=notebook_job_id, include_deleted=True)
    if not notebook_job:
        return None

    notebook_job.archive()

    if notebook_job.is_running:
        project = notebook_job.project
        celery_app.send_task(
            SchedulerCeleryTasks.PROJECTS_NOTEBOOK_STOP,
            kwargs={
                'project_name': project.unique_name,
                'project_uuid': project.uuid.hex,
                'notebook_job_name': notebook_job.unique_name,
                'notebook_job_uuid': notebook_job.uuid.hex,
                'update_status': True,
                'collect_logs': False,
                'message': 'Notebook is scheduled for deletion.'
            })
Ejemplo n.º 7
0
def projects_notebook_stop(project_name,
                           project_uuid,
                           notebook_job_name,
                           notebook_job_uuid,
                           update_status=True):
    notebook_scheduler.stop_notebook(project_name=project_name,
                                     project_uuid=project_uuid,
                                     notebook_job_name=notebook_job_name,
                                     notebook_job_uuid=notebook_job_uuid)

    if not update_status:
        return

    notebook = get_valid_notebook(notebook_job_uuid=notebook_job_uuid)
    if not notebook:
        return None

    # Update notebook status to show that its stopped
    notebook.set_status(status=JobLifeCycle.STOPPED,
                        message='Notebook was stopped')
Ejemplo n.º 8
0
def projects_notebook_stop(notebook_job_id):
    notebook = get_valid_notebook(notebook_job_id=notebook_job_id)
    if not notebook:
        return None

    notebook_scheduler.stop_notebook(notebook, update_status=True)