diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb.py b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb.py index 45d8631f0ba586b341a5d2951930a9be8cab2cd4..eaf905ac66bc2240727299706f8d25adaf576778 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb.py +++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb.py @@ -1375,7 +1375,7 @@ class RADatabase: def get_conflicting_overlapping_claims(self, claim_id): '''returns a list of claimed claims which overlap with given claim and which prevent the given claim to be claimed (cause it to be in conflict)''' - query = '''SELECT * from resource_monitoring.get_conflicting_overlapping_claims(%s)''' + query = '''SELECT * from resource_allocation.get_conflicting_overlapping_claims(%s)''' return list(self._executeQuery(query, (claim_id,), fetch=_FETCH_ALL)) def get_conflicting_overlapping_tasks(self, claim_id): @@ -1390,7 +1390,7 @@ class RADatabase: else: claim_status_id = claim_status - query = '''SELECT * from resource_monitoring.get_max_resource_usage_between(%s, %s, %s, %s)''' + query = '''SELECT * from resource_allocation.get_max_resource_usage_between(%s, %s, %s, %s)''' result = self._executeQuery(query, (resource_id, claim_status_id, lower_bound, upper_bound), fetch=_FETCH_ONE) if result and result.get('usage') is not None: @@ -1400,7 +1400,7 @@ class RADatabase: def get_resource_claimable_capacity(self, resource_id, lower_bound, upper_bound): '''get the claimable capacity for the given resource within the timewindow given by lower_bound and upper_bound. this is the resource's available capacity (total-used) minus the maximum allocated usage in that timewindow.''' - query = '''SELECT * from resource_monitoring.get_resource_claimable_capacity_between(%s, %s, %s)''' + query = '''SELECT * from resource_allocation.get_resource_claimable_capacity_between(%s, %s, %s)''' result = self._executeQuery(query, (resource_id, lower_bound, upper_bound), fetch=_FETCH_ONE) if result: return result.get('get_resource_claimable_capacity_between', 0) @@ -1408,7 +1408,7 @@ class RADatabase: def rebuild_resource_usages_table_from_claims(self): '''(re)builds the resource_usages table from all currently known resource_claims''' - query = '''SELECT * from resource_monitoring.rebuild_resource_usages_table_from_claims()''' + query = '''SELECT * from resource_allocation.rebuild_resource_usages_table_from_claims()''' self._executeQuery(query, fetch=_FETCH_NONE) def insertSpecificationAndTask(self, mom_id, otdb_id, task_status, task_type, starttime, endtime, content, cluster, commit=True): @@ -1560,7 +1560,7 @@ class RADatabase: :return: a nested dict with resource_id at the first level, then claim_status(name) at the second level, and then a list of time ordered usages. """ usages_per_resource = {} - query = '''SELECT * from resource_monitoring.resource_usage''' + query = '''SELECT * from resource_allocation.resource_usage''' conditions = [] qargs = [] diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql index ed70c42566c3596740f78e3f3f85986136e4561b..4b7ae66d01fb0adfb2c39e4f11bb701c1d2b545e 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql +++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql @@ -341,7 +341,7 @@ BEGIN TRUNCATE TABLE resource_allocation.resource_usage RESTART IDENTITY CASCADE; FOR claim IN SELECT * FROM resource_allocation.resource_claim LOOP - PERFORM resource_monitoring.process_new_claim_into_resource_usages(claim); + PERFORM resource_allocation.process_new_claim_into_resource_usages(claim); END LOOP; END; $$ LANGUAGE plpgsql; @@ -378,10 +378,10 @@ BEGIN -- both usage_at_start and usage_at_end should exist (NOT NULL) IF usage_at_start IS NULL THEN - RAISE EXCEPTION 'resource_monitoring.on_delete_claim_update_resource_usages: usage_at_start should not be NULL.'; + RAISE EXCEPTION 'resource_allocation.on_delete_claim_update_resource_usages: usage_at_start should not be NULL.'; END IF; IF usage_at_end IS NULL THEN - RAISE EXCEPTION 'resource_monitoring.on_delete_claim_update_resource_usages: usage_at_end should not be NULL.'; + RAISE EXCEPTION 'resource_allocation.on_delete_claim_update_resource_usages: usage_at_end should not be NULL.'; END IF; IF usage_at_start.usage = old_claim.claim_size THEN @@ -487,7 +487,7 @@ DECLARE max_resource_usage_value int; available_capacity bigint; BEGIN - SELECT * FROM resource_monitoring.get_max_resource_usage_between(_resource_id, claimed_status_id, _lower, _upper) INTO max_resource_usage; + SELECT * FROM resource_allocation.get_max_resource_usage_between(_resource_id, claimed_status_id, _lower, _upper) INTO max_resource_usage; IF max_resource_usage IS NULL THEN max_resource_usage_value := 0; @@ -514,7 +514,7 @@ DECLARE overlapping_claims_min_starttime timestamp; overlapping_claims_max_endtime timestamp; BEGIN - -- this function is quite similar to resource_monitoring.get_conflicting_overlapping_claims + -- this function is quite similar to resource_allocation.get_conflicting_overlapping_claims -- for performance reasons we repeat the common code here instead of wrapping the common code in a function --get all overlapping_claims, whether they cause a conflict or not. @@ -534,7 +534,7 @@ BEGIN SELECT max(starttime) FROM overlapping_claims INTO overlapping_claims_max_endtime; -- get the free free_claimable_capacity for this resource for the full overlapping claim time window - SELECT * FROM resource_monitoring.get_resource_claimable_capacity_between(claim.resource_id, overlapping_claims_min_starttime, overlapping_claims_max_endtime) INTO free_claimable_capacity; + SELECT * FROM resource_allocation.get_resource_claimable_capacity_between(claim.resource_id, overlapping_claims_min_starttime, overlapping_claims_max_endtime) INTO free_claimable_capacity; return claim.claim_size > free_claimable_capacity; END; @@ -556,7 +556,7 @@ BEGIN LIMIT 1 INTO claim; - RETURN QUERY SELECT * FROM resource_monitoring.get_conflicting_overlapping_claims(claim); + RETURN QUERY SELECT * FROM resource_allocation.get_conflicting_overlapping_claims(claim); END; $$ LANGUAGE plpgsql; ALTER FUNCTION resource_allocation.get_conflicting_overlapping_claims(claim_id int) OWNER TO resourceassignment; @@ -571,7 +571,7 @@ $$ DECLARE claim_claimed_status_id int := 1; --beware: hard coded instead of lookup for performance BEGIN - -- this function is quite similar to resource_monitoring.has_conflict_with_overlapping_claims + -- this function is quite similar to resource_allocation.has_conflict_with_overlapping_claims -- for performance reasons we repeat the common code here instead of wrapping the common code in a function --get all overlapping_claims, whether they cause a conflict or not. @@ -588,7 +588,7 @@ BEGIN RETURN QUERY SELECT * FROM overlapping_claims oc - WHERE (SELECT * FROM resource_monitoring.get_resource_claimable_capacity_between(claim.resource_id, oc.starttime, oc.endtime)) < claim.claim_size; + WHERE (SELECT * FROM resource_allocation.get_resource_claimable_capacity_between(claim.resource_id, oc.starttime, oc.endtime)) < claim.claim_size; END; $$ LANGUAGE plpgsql; ALTER FUNCTION resource_allocation.get_conflicting_overlapping_claims(claim resource_allocation.resource_claim) OWNER TO resourceassignment; @@ -637,7 +637,7 @@ BEGIN OLD.starttime <> NEW.starttime OR OLD.endtime <> NEW.endtime)) THEN --check if claim fits or has conflicts - SELECT * FROM resource_monitoring.has_conflict_with_overlapping_claims(NEW) INTO claim_has_conflicts; + SELECT * FROM resource_allocation.has_conflict_with_overlapping_claims(NEW) INTO claim_has_conflicts; IF claim_has_conflicts AND NEW.status_id <> claim_conflict_status_id THEN -- conflict with others, so set claim status to conflict @@ -687,12 +687,12 @@ DECLARE BEGIN IF TG_OP = 'UPDATE' OR TG_OP = 'DELETE' THEN --update the resource usages affected by this claim - PERFORM resource_monitoring.process_old_claim_outof_resource_usages(OLD); + PERFORM resource_allocation.process_old_claim_outof_resource_usages(OLD); END IF; IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN --update the resource usages affected by this claim - PERFORM resource_monitoring.process_new_claim_into_resource_usages(NEW); + PERFORM resource_allocation.process_new_claim_into_resource_usages(NEW); END IF; -- in the before trigger function, everything on the claim has been checked and adapted. @@ -722,7 +722,7 @@ BEGIN AND rc.starttime <= OLD.endtime LOOP --check if claim fits or has conflicts - SELECT * FROM resource_monitoring.has_conflict_with_overlapping_claims(affected_claim) INTO claim_has_conflicts; + SELECT * FROM resource_allocation.has_conflict_with_overlapping_claims(affected_claim) INTO claim_has_conflicts; IF NOT claim_has_conflicts THEN -- no conflict (anymore) with others, so set claim status to tentative @@ -743,7 +743,7 @@ BEGIN AND rc.starttime <= NEW.endtime LOOP --check if claim fits or has conflicts - SELECT * FROM resource_monitoring.has_conflict_with_overlapping_claims(affected_claim) INTO claim_has_conflicts; + SELECT * FROM resource_allocation.has_conflict_with_overlapping_claims(affected_claim) INTO claim_has_conflicts; IF claim_has_conflicts THEN -- new conflict for affected_claim because this NEW claim is now claimed diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/tests/t_radb.py b/SAS/ResourceAssignment/ResourceAssignmentDatabase/tests/t_radb.py index 6af9fb642f72dbbdde60a9e4868f06f9033a8616..b572e52ff92b59c5b39449b00199cb46d06d6599 100755 --- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/tests/t_radb.py +++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/tests/t_radb.py @@ -491,7 +491,7 @@ class ResourceAssignmentDatabaseTest(unittest.TestCase): # suppose the resource_usages table is broken for some reason, fix it.... # break it first... - self._execute_query('TRUNCATE TABLE resource_monitoring.resource_usage;') + self._execute_query('TRUNCATE TABLE resource_allocation.resource_usage;') #check that it's broken self.assertNotEqual(40, self.radb.get_max_resource_usage_between(117, task1['starttime'], task1['starttime'], 'claimed')['usage']) #fix it