Ejemplo n.º 1
0
def delete_calc(user_id, project_codename, calc_name):
    running_calc_status = [STATUS_PENDING, STATUS_RUNNING]

    project = projects.get_project(user_id, project_codename)
    if not project:
        raise RuntimeError("Unknown project " + project_codename)
    g_db = core.api_util.DatabaseContext.get_conn()
    calculations = g_db.execute(
        """SELECT * 
                                     FROM calculations 
                                    WHERE project_uid = %s 
                                      AND name = %s 
                                      AND delete_date IS NULL""",
        [project_codename, calc_name]).fetchall()

    # Cancelling jobs
    running_job_ids = []
    for calc in calculations:
        if calc['status'] in running_calc_status and calc['job_id'] is not None:
            running_job_ids.append(calc['job_id'])
    if running_job_ids:
        log.info("Killing jobs " + repr(running_job_ids) +
                 " from deleting calc " + calc_name + "of project " +
                 project_codename)
        jobs.cancel_jobs(running_job_ids)

    for calc in calculations:
        status_file_id = calc['status_file_id']
        result_file_id = calc['result_file_id']
        iterations_file_id = calc['iterations_file_id']
        reduce_file_id = calc['reduce_file_id']
        internal_file_id = calc['internal_file_id']
        if status_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              status_file_id)
        if result_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              result_file_id)
        if iterations_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              iterations_file_id)
        if reduce_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              reduce_file_id)
        if internal_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              internal_file_id)
        pg_util.delete_with_date(g_db, "calculations", calc['id'])
Ejemplo n.º 2
0
def remove_file_from_project(user_id, project_codename, file_id):
    project = get_project(user_id, project_codename)
    if not project:
        return
    g_db = core.api_util.DatabaseContext.get_conn()
    project_file = g_db.execute(
        """SELECT * 
                                     FROM project_files 
                                    WHERE id = %s 
                                      AND project_uid = %s 
                                      AND delete_date IS NULL""",
        [file_id, project_codename]).fetchone()
    if not project_file:
        return
    storage = core.api_util.get_storage(project['storage'])
    if storage.file_exists(project_file["filename"]):
        storage.delete_file(project_file["filename"])
    pg_util.delete_with_date(g_db, "project_files", file_id)
Ejemplo n.º 3
0
def delete_mesh(user_id, project_codename, mesh_name):
    running_calc_status = [calc.STATUS_PENDING, calc.STATUS_RUNNING]
    running_mesh_status = [STATUS_PENDING, STATUS_RUNNING]

    project = projects.get_project(user_id, project_codename)
    if not project:
        raise RuntimeError("Unknown project " + project_codename)
    g_db = core.api_util.DatabaseContext.get_conn()
    proj_meshes = g_db.execute(
        """SELECT * FROM meshes WHERE project_uid = %s AND name = %s AND delete_date IS NULL""",
        [project_codename, mesh_name]).fetchall()

    # Cancelling computations
    mesh_ids = [m['id'] for m in proj_meshes]
    if not mesh_ids:
        return
    calculations = g_db.execute(
        """SELECT * 
                                     FROM calculations 
                                    WHERE project_uid = %s
                                      AND mesh_id IN (""" +
        ", ".join(["%s"] * len(mesh_ids)) + """) 
                                      AND delete_date IS NULL""",
        [project_codename] + mesh_ids).fetchall()
    running_job_ids = [
        m['job_id'] for m in proj_meshes if m['status'] in running_mesh_status
    ]
    running_job_ids += [
        c['job_id'] for c in calculations if c['status'] in running_calc_status
    ]
    if running_job_ids:
        log.info("killing jobs " + repr(running_job_ids) +
                 " from deleting mesh " + mesh_name + " of project " +
                 project_codename)
        jobs.cancel_jobs(running_job_ids)

    # Cleaning calculations
    for proj_calc in calculations:
        status_file_id = proj_calc['status_file_id']
        result_file_id = proj_calc['result_file_id']
        iterations_file_id = proj_calc['iterations_file_id']
        reduce_file_id = proj_calc['reduce_file_id']
        internal_file_id = proj_calc['internal_file_id']
        if status_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              status_file_id)
        if result_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              result_file_id)
        if iterations_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              iterations_file_id)
        if reduce_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              reduce_file_id)
        if internal_file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              internal_file_id)
        pg_util.delete_with_date(g_db, "calculations", proj_calc['id'])

    # Cleaning meshes
    for proj_mesh in proj_meshes:
        file_id = proj_mesh['result_file_id']
        if file_id is not None:
            projects.remove_file_from_project(user_id, project_codename,
                                              file_id)
        pg_util.delete_with_date(g_db, "meshes", proj_mesh['id'])
Ejemplo n.º 4
0
def delete_user(user_id):
    g_db = core.api_util.DatabaseContext.get_conn()
    pg_util.delete_with_date(g_db, "users", user_id)
Ejemplo n.º 5
0
def delete_project(user_id, project_codename):
    project = get_project(user_id, project_codename, include_deleted=True)
    if not project:
        raise RuntimeError("Unknown project " + project_codename)

    # Canceling all running jobs
    running_status = [
        jobs.JOB_STATUS_PENDING, jobs.JOB_STATUS_LAUNCHING,
        jobs.JOB_STATUS_RUNNING
    ]
    query = "SELECT id FROM jobs WHERE project_uid = %s AND status IN (" + ", ".join(
        ["%s"] * len(running_status)) + ")"
    g_db = core.api_util.DatabaseContext.get_conn()
    running_jobs = g_db.execute(query, [project_codename] +
                                running_status).fetchall()
    running_job_ids = [job['id'] for job in running_jobs]
    if running_job_ids:
        log.info("killing jobs " + repr(running_job_ids) +
                 " from deleting project " + project_codename)
        jobs.cancel_jobs(running_job_ids)

    # Cleaning calculations
    calculations = g_db.execute(
        """SELECT * 
                                     FROM calculations 
                                    WHERE project_uid = %s 
                                      AND delete_date IS NULL""",
        [project_codename]).fetchall()
    for calc in calculations:
        status_file_id = calc['status_file_id']
        result_file_id = calc['result_file_id']
        iterations_file_id = calc['iterations_file_id']
        reduce_file_id = calc['reduce_file_id']
        internal_file_id = calc['internal_file_id']
        if status_file_id is not None:
            remove_file_from_project(user_id, project_codename, status_file_id)
        if result_file_id is not None:
            remove_file_from_project(user_id, project_codename, result_file_id)
        if iterations_file_id is not None:
            remove_file_from_project(user_id, project_codename,
                                     iterations_file_id)
        if reduce_file_id is not None:
            remove_file_from_project(user_id, project_codename, reduce_file_id)
        if internal_file_id is not None:
            remove_file_from_project(user_id, project_codename,
                                     internal_file_id)
        pg_util.delete_with_date(g_db, "calculations", calc['id'])

    # Cleaning meshes
    meshes = g_db.execute(
        "SELECT * FROM meshes WHERE project_uid = %s AND delete_date IS NULL",
        [project_codename]).fetchall()
    for mesh in meshes:
        file_id = mesh['result_file_id']
        if file_id is not None:
            remove_file_from_project(user_id, project_codename, file_id)
        pg_util.delete_with_date(g_db, "meshes", mesh['id'])

    # Cleaning project itself
    anal_file = get_file_by_key(user_id, project_codename,
                                PROJECT_FILE_ANALYSED)
    if anal_file:
        remove_file_from_project(user_id, project_codename, anal_file['id'])
    project_file = get_file_by_key(user_id, project_codename, PROJECT_FILE_RAW)
    if project_file:
        remove_file_from_project(user_id, project_codename, project_file['id'])
    pg_util.hist_remove(g_db, "projects", [('uid', "=", project_codename)])