Exemple #1
0
def check_reservation_jobs(plt, resource_set, queue_name, all_slot_sets, current_time_sec):
    """Processing of new Advance Reservations"""

    logger.debug("Queue " + queue_name + ": begin processing of new reservations")

    ar_jobs_scheduled = {}

    ar_jobs, ar_jids, nb_ar_jobs = plt.get_waiting_jobs(
        queue_name, 'toSchedule')
    logger.debug("nb_ar_jobs:" + str(nb_ar_jobs))

    if nb_ar_jobs > 0:
        job_security_time = int(config['SCHEDULER_JOB_SECURITY_TIME'])
        plt.get_data_jobs(ar_jobs, ar_jids, resource_set, job_security_time)

        logger.debug("Try and schedule new reservations")
        for jid in ar_jids:
            job = ar_jobs[jid]
            logger.debug(
                "Find resource for Advance Reservation job:" + str(job.id))

            # It is a reservation, we take care only of the first moldable job
            moldable_id, walltime, hy_res_rqts = job.mld_res_rqts[0]

            # test if reservation is too old
            if current_time_sec >= (job.start_time + walltime):
                logger.warn(
                    "[" + str(job.id) + "] Canceling job: reservation is too old")
                set_job_message(job.id, "Reservation too old")
                set_job_state(job.id, 'toError')
                continue
            else:
                if job.start_time < current_time_sec:
                    # TODO update to DB ????
                    job.start_time = current_time_sec

            ss_name = 'default'

            # TODO container
            # if 'inner' in job.types:
            #    ss_name = job.types['inner']

            # TODO: test if container is an AR job

            slots = all_slot_sets[ss_name].slots

            t_e = job.start_time + walltime - job_security_time
            sid_left, sid_right = get_encompassing_slots(
                slots, job.start_time, t_e)

            if job.ts or (job.ph == ALLOW):
                itvs_avail = intersec_ts_ph_itvs_slots(
                    slots, sid_left, sid_right, job)
            else:
                itvs_avail = intersec_itvs_slots(slots, sid_left, sid_right)

            itvs = find_resource_hierarchies_job(
                itvs_avail, hy_res_rqts, resource_set.hierarchy)

            if ('QUOTAS' in config) and (config['QUOTAS'] == 'yes'):
                nb_res = itvs_size(intersec(itvs, resource_set.default_resource_itvs))
                res = check_slots_quotas(slots, sid_left, sid_right, job, nb_res, walltime)
                (quotas_ok, quotas_msg, rule, value) = res
                if not quotas_ok:
                    itvs = []
                    logger.info("Quotas limitaion reached, job:" + str(job.id) +
                                ", " + quotas_msg + ", rule: " + str(rule) +
                                ", value: " + str(value))
                    set_job_state(job.id, 'toError')
                    set_job_message(job.id,
                                    "This advance reservation cannot run due to quotas")

            if itvs == []:
                # not enough resource available
                logger.warn("[" + str(job.id) +
                            "] advance reservation cannot be validated, not enough resources")
                set_job_state(job.id, 'toError')
                set_job_message(job.id, "This advance reservation cannot run")
            else:
                # The reservation can be scheduled
                logger.debug(
                    "[" + str(job.id) + "] advance reservation is validated")
                job.moldable_id = moldable_id
                job.res_set = itvs
                ar_jobs_scheduled[job.id] = job
                # if 'container' in job.types
                #    slot = Slot(1, 0, 0, job.res_set[:], job.start_time,
                #                job.start_time + job.walltime - job_security_time)
                # slot.show()
                #    slots_sets[job.id] = SlotSet(slot)

                set_job_state(job.id, 'toAckReservation')

            set_job_resa_state(job.id, 'Scheduled')

    if ar_jobs_scheduled != []:
        logger.debug("Save AR jobs' assignements in database")
        save_assigns(ar_jobs_scheduled, resource_set)

    logger.debug("Queue " + queue_name + ": end processing of new reservations")
Exemple #2
0
def find_first_suitable_contiguous_slots(slots_set, job, res_rqt, hy, min_start_time):
    '''find first_suitable_contiguous_slot '''

    (mld_id, walltime, hy_res_rqts) = res_rqt

    itvs = []

    slots = slots_set.slots
    cache = slots_set.cache
    # flag to control cache update for considered entry
    no_cache = False
    # updated_cache = False
    sid_left = 1
    if min_start_time < 0:
        # to not always begin by the first slots ( O(n^2) )
        # TODO cache_by_container/inner + moldable + time_sharing(?)
        if job.key_cache and (job.key_cache[mld_id] in cache):
            sid_left = cache[job.key_cache[mld_id]]
            # print("cache hit...... ", sid_left)
            # else:
            # print("cache miss :(")

    else:
        while slots[sid_left].b < min_start_time:
            sid_left = slots[sid_left].next
        # satisfy job dependencies converted in min start_time

    # sid_left = 1 # TODO no cache

    sid_right = sid_left
    slot_e = slots[sid_right].e

    # print('first sid_left', sid_left)

    while True:
        # find next contiguous slots_time
        # print("A: job.id:", job.id, "sid_left:", sid_left, "sid_right:",)
        # sid_right

        if sid_left != 0 and sid_right != 0:
            slot_b = slots[sid_left].b
        else:
            # TODO error
            # print("TODO error can't schedule job.id:", job.id)
            logger.info(
                "can't schedule job with id:" + str(job.id) + ", due resources")
            return ([], -1, -1)

        while ((slot_e - slot_b + 1) < walltime):
            sid_right = slots[sid_right].next
            if sid_right != 0:
                slot_e = slots[sid_right].e
            else:
                logger.info(
                    "can't schedule job with id:" + str(job.id) + ", due time")
                return ([], -1, -1)

        #        if not updated_cache and (slots[sid_left].itvs != []):
        #            cache[walltime] = sid_left
        #            updated_cache = True

        if job.ts or (job.ph == ALLOW):
            itvs_avail = intersec_ts_ph_itvs_slots(
                slots, sid_left, sid_right, job)
        else:
            itvs_avail = intersec_itvs_slots(slots, sid_left, sid_right)
        # print("itvs_avail", itvs_avail, "h_res_req", hy_res_rqts, "hy", hy)
        if job.find:
            beginning_slotset = True if (sid_left == 1) and (slots_set.begin == slots[1].b) else False
            # Use specialized find resource function
            itvs = job.find_func(itvs_avail, hy_res_rqts, hy, beginning_slotset,
                                 *job.find_args, **job.find_kwargs)
        else:
            itvs = find_resource_hierarchies_job(itvs_avail, hy_res_rqts, hy)

        if itvs != []:
            if ('QUOTAS' in config) and (config['QUOTAS'] == 'yes'):
                nb_res = itvs_size(intersec(itvs, rs.default_resource_itvs))
                res = check_slots_quotas(slots, sid_left, sid_right, job, nb_res, walltime)
                (quotas_ok, quotas_msg, rule, value) = res
                if not quotas_ok:
                    logger.info("Quotas limitaion reached, job:" + str(job.id) +
                                ", " + quotas_msg + ", rule: " + str(rule) +
                                ", value: " + str(value))
                    # quotas limitation trigger therefore disable cache update for this entry
                    no_cache = True
                else:
                    break
            else:
                break

        sid_left = slots[sid_left].next

    if job.key_cache and (min_start_time < 0) and (not no_cache):  # and (not job.deps):
        cache[job.key_cache[mld_id]] = sid_left
        #        print("cache: update entry ",  job.key_cache[mld_id], " with ", sid_left)
        # else:
        # print("cache: not updated ", job.key_cache, min_start_time, job.deps)

    return (itvs, sid_left, sid_right)