def test_filter_on_type_SINGLE_no_window_one_request(self):
        windows = [()]
        rg1, _ = self.create_request_group(windows, operator='single')

        running_request_ids = []
        received_rg_list = filter_on_type([rg1], running_request_ids)
        assert_equal(len(received_rg_list), 0)
    def test_filter_on_type_ONEOF_neither_request_has_windows(self):
        windows = [(), ()]
        rg1, window_list = self.create_request_group(windows, operator='oneof')

        running_request_ids = []
        received_rg_list = filter_on_type([rg1], running_request_ids)
        assert_equal(len(received_rg_list), 0)
 def test_filter_on_type_SINGLE_no_windows_but_running(self):
     windows = [()]
     rg1, window_list = self.create_request_group(windows, operator='single')
     rg_list = [rg1]
     assert_equal(1, len(rg_list))
     assert_equal(1, len(rg_list[0].requests))
     assert_equal(0, rg_list[0].requests[0].windows.size())
     running_request_ids = [5]
     received_rg_list = filter_on_type([rg1], running_request_ids)
     assert_equal(len(received_rg_list), 1)
    def test_filter_on_type_ONEOF_one_request_has_no_windows(self):
        window_dict1 = {
            'start': "2013-03-01T00:00:00Z",
            'end': "2013-03-01T00:30:00Z",
        }
        windows = [(window_dict1,), ()]
        rg1, window_list = self.create_request_group(windows, operator='oneof')

        running_request_ids = []
        received_rg_list = filter_on_type([rg1], running_request_ids)
        assert_equal(len(received_rg_list), 1)
Exemplo n.º 5
0
def filter_on_scheduling_horizon(request_groups, scheduling_horizon):
    '''Filter out windows in user requests that extend beyond the scheduling
       horizon for types (single, many)
    '''
    rgs_by_type = filter_compounds_by_type(request_groups)
    log.info("Identified %s, %s, %s, %s" % (pl(len(rgs_by_type['single']), 'single'),
                                            pl(len(rgs_by_type['many']), 'many'),
                                            pl(len(rgs_by_type['and']), 'and'),
                                            pl(len(rgs_by_type['oneof']), 'oneof')))

    # Filter windows that are beyond the short-term scheduling horizon
    log.info("Filtering RGs of type 'single' and 'many' based on scheduling horizon (%s)" % scheduling_horizon)
    horizon_limited_rgs = rgs_by_type['single'] + rgs_by_type['many']
    horizon_limited_rgs = truncate_upper_crossing_windows(horizon_limited_rgs, horizon=scheduling_horizon)
    horizon_limited_rgs = filter_out_future_windows(horizon_limited_rgs, horizon=scheduling_horizon)
    # TODO: Add the duration filter here?
    # Clean up Requests without any windows
    horizon_limited_rgs = filter_on_type(horizon_limited_rgs)
    # Many's may have children with no windows that should be removed from consideration
    drop_empty_requests(horizon_limited_rgs)
    log.info("After filtering, %d horizon-limited rgs remain" % len(horizon_limited_rgs))

    # Compounds (and/oneof) are not constrained to the short-term scheduling horizon
    # TODO: Remove this block after review
    log.info("Filtering compound RGs of type 'and' and 'oneof', not constrained by scheduling horizon")
    unlimited_rgs = rgs_by_type['and'] + rgs_by_type['oneof']
    unlimited_rgs = truncate_upper_crossing_windows(unlimited_rgs)
    unlimited_rgs = filter_out_future_windows(unlimited_rgs)

    # TODO: it's possible that one-ofs and ands may have these windowless 
    # children at this point from requests that crossed the semester boundary
    # might need to drop empty requests before filtering on type   

    # Clean up Requests without any windows
    unlimited_rgs = filter_on_type(unlimited_rgs)
    log.info("After filtering, %d unlimited RGs remain" % len(unlimited_rgs))

    remaining_rgs = horizon_limited_rgs + unlimited_rgs

    return remaining_rgs
 def test_filter_on_type_NON_SINGLE_both_requests_no_windows_but_running(self):
     for operator in ('and', 'many', 'oneof'):
         windows = [(), ()]
         rg1, window_list = self.create_request_group(windows, operator=operator)
         rg_list = [rg1]
         assert_equal(1, len(rg_list))
         assert_equal(2, len(rg_list[0].requests))
         assert_equal(0, rg_list[0].requests[0].windows.size())
         assert_equal(0, rg_list[0].requests[1].windows.size())
         running_request_ids = [5, 6]
         received_rg_list = filter_on_type([rg1], running_request_ids)
         assert_equal(len(received_rg_list), 1,
                      msg="Request Group should not be filtered for operator '%s'" % operator)
         assert_equal(2, len(rg_list[0].requests),
                      msg="Requests should not be filtered from request group with operator '%s'" % operator)
    def test_filter_on_type_SINGLE_two_windows_one_request(self):
        window_dict1 = {
            'start': "2013-03-01T00:00:00Z",
            'end': "2013-03-01T00:30:00Z",
        }
        window_dict2 = {
            'start': "2013-03-01T00:00:00Z",
            'end': "2013-03-01T00:30:00Z",
        }
        windows = [(window_dict1, window_dict2)]
        rg1, window_list = self.create_request_group(windows, operator='single')

        running_request_ids = []
        received_rg_list = filter_on_type([rg1], running_request_ids)
        assert_equal(len(received_rg_list), 1)
    def test_filter_on_type_AND_both_requests_have_windows(self):
        window_dict1 = {
            'start': "2013-03-01T00:00:00Z",
            'end': "2013-03-01T00:30:00Z",
        }
        window_dict2 = {
            'start': "2013-03-01T00:00:00Z",
            'end': "2013-03-01T00:30:00Z",
        }
        windows = [(window_dict1,), (window_dict2,)]
        rg1, _ = self.create_request_group(windows, operator='and')

        running_request_ids = []
        received_rg_list = filter_on_type([rg1], running_request_ids)
        assert_equal(len(received_rg_list), 1)
Exemplo n.º 9
0
def filter_for_kernel(request_groups, visibility_for_resource, downtime_intervals, semester_start, semester_end,
                      scheduling_horizon):
    '''After throwing out and marking RGs as UNSCHEDULABLE, reduce windows by
       considering dark time and target visibility. Remove any RGs that are now too
       small to hold their duration after this consideration, so they are not passed
       to the kernel.
       NOTE: We do this as an explicit additional filtering step, because we do not
       want to set the UNSCHEDULABLE flag for these Requests. This is because the
       step is network-dependent; if the network subsequently changes (e.g. a
       telescope becomes available), then the Request may then be schedulable.'''
    # trim windows to scheduling horizon, expiry, or end of semester and filter
    rgs = filter_on_scheduling_horizon(request_groups, scheduling_horizon)

    # Filter on rise_set/airmass/downtime intervals
    rgs = filter_on_visibility(rgs, visibility_for_resource, downtime_intervals, semester_start, semester_end)

    # Clean up now impossible Requests
    rgs = filter_on_duration(rgs)
    # TODO: Do we need to drop empty requests here before carrying on?
    rgs = filter_on_type(rgs, [])

    return rgs