diff --git a/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/create_database.sql b/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/create_database.sql index 4612b4e6c0124364018fd41de3cf72498e626b99..641ec1a72dab42c5d8eeb70110fcdbf1bc6994c7 100644 --- a/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/create_database.sql +++ b/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/create_database.sql @@ -7,33 +7,34 @@ -- LC_COLLATE = 'en_US.UTF-8' -- LC_CTYPE = 'en_US.UTF-8' -- CONNECTION LIMIT = -1; ---CREATE SCHEMA resourceallocation; ---SET SCHEMA 'resourceallocation'; +CREATE SCHEMA virtual_instrument; +CREATE SCHEMA resource_monitoring; +CREATE SCHEMA resource_allocation; --- USE resourceassignment; +-- USE resourceassignment;? BEGIN; --- This is insanity, but will hopefully work -DROP TABLE IF EXISTS resource_group_availability; -DROP TABLE IF EXISTS resource_availability; -DROP TABLE IF EXISTS resource_capacity; -DROP TABLE IF EXISTS resource_claim; -DROP TABLE IF EXISTS resource_claim_status; -DROP TABLE IF EXISTS task; -DROP TABLE IF EXISTS specification; -DROP TABLE IF EXISTS task_type; -DROP TABLE IF EXISTS task_status; -DROP TABLE IF EXISTS resource_group_to_resource_group; -DROP TABLE IF EXISTS resource_to_resource_group; -DROP TABLE IF EXISTS resource_group; -DROP TABLE IF EXISTS resource_group_type; -DROP TABLE IF EXISTS resource; -DROP TABLE IF EXISTS resource_type; -DROP TABLE IF EXISTS unit; --- I can not get this to do something useful instead: SET CONSTRAINTS ALL DEFERRED; - -CREATE TABLE unit ( +-- This is insanity, but works, order needs to be the reverse of the CREATE TABLE statements +DROP TABLE IF EXISTS resource_monitoring.resource_group_availability; +DROP TABLE IF EXISTS resource_monitoring.resource_availability; +DROP TABLE IF EXISTS resource_monitoring.resource_capacity; +DROP TABLE IF EXISTS resource_allocation.resource_claim; +DROP TABLE IF EXISTS resource_allocation.resource_claim_status; +DROP TABLE IF EXISTS resource_allocation.task; +DROP TABLE IF EXISTS resource_allocation.specification; +DROP TABLE IF EXISTS resource_allocation.task_type; +DROP TABLE IF EXISTS resource_allocation.task_status; +DROP TABLE IF EXISTS virtual_instrument.resource_group_to_resource_group; +DROP TABLE IF EXISTS virtual_instrument.resource_to_resource_group; +DROP TABLE IF EXISTS virtual_instrument.resource_group; +DROP TABLE IF EXISTS virtual_instrument.resource_group_type; +DROP TABLE IF EXISTS virtual_instrument.resource; +DROP TABLE IF EXISTS virtual_instrument.resource_type; +DROP TABLE IF EXISTS virtual_instrument.unit; +-- Would like to use this instead, but I can not get it to do something useful: SET CONSTRAINTS ALL DEFERRED; + +CREATE TABLE virtual_instrument.unit ( id serial NOT NULL, units text NOT NULL, PRIMARY KEY (id) @@ -41,7 +42,7 @@ CREATE TABLE unit ( ALTER TABLE unit OWNER TO renting; -CREATE TABLE resource_type ( +CREATE TABLE virtual_instrument.resource_type ( id serial NOT NULL, name text NOT NULL, unit_id integer NOT NULL REFERENCES unit DEFERRABLE INITIALLY IMMEDIATE, @@ -50,7 +51,7 @@ CREATE TABLE resource_type ( ALTER TABLE resource_type OWNER TO renting; -CREATE TABLE resource ( +CREATE TABLE virtual_instrument.resource ( id serial NOT NULL, name text NOT NULL, type_id integer NOT NULL REFERENCES resource_type DEFERRABLE INITIALLY IMMEDIATE, @@ -59,7 +60,7 @@ CREATE TABLE resource ( ALTER TABLE resource OWNER TO renting; -CREATE TABLE resource_group_type ( +CREATE TABLE virtual_instrument.resource_group_type ( id serial NOT NULL, name text NOT NULL, PRIMARY KEY (id) @@ -67,7 +68,7 @@ CREATE TABLE resource_group_type ( ALTER TABLE resource_group_type OWNER TO renting; -CREATE TABLE resource_group ( +CREATE TABLE virtual_instrument.resource_group ( id serial NOT NULL, name text NOT NULL, type_id integer NOT NULL REFERENCES resource_group_type DEFERRABLE INITIALLY IMMEDIATE, @@ -76,7 +77,7 @@ CREATE TABLE resource_group ( ALTER TABLE resource_group OWNER TO renting; -CREATE TABLE resource_to_resource_group ( +CREATE TABLE virtual_instrument.resource_to_resource_group ( id serial NOT NULL, child_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, parent_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, @@ -85,7 +86,7 @@ CREATE TABLE resource_to_resource_group ( ALTER TABLE resource_to_resource_group OWNER TO renting; -CREATE TABLE resource_group_to_resource_group ( +CREATE TABLE virtual_instrument.resource_group_to_resource_group ( id serial NOT NULL, child_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, parent_id integer REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, @@ -94,7 +95,7 @@ CREATE TABLE resource_group_to_resource_group ( ALTER TABLE resource_group_to_resource_group OWNER TO renting; -CREATE TABLE task_status ( +CREATE TABLE resource_allocation.task_status ( id serial NOT NULL, name text NOT NULL, PRIMARY KEY (id) @@ -102,7 +103,7 @@ CREATE TABLE task_status ( ALTER TABLE task_status OWNER TO renting; -CREATE TABLE task_type ( +CREATE TABLE resource_allocation.task_type ( id serial NOT NULL, name text NOT NULL, PRIMARY KEY (id) @@ -110,7 +111,7 @@ CREATE TABLE task_type ( ALTER TABLE task_type OWNER TO renting; -CREATE TABLE specification ( +CREATE TABLE resource_allocation.specification ( id serial NOT NULL, starttime timestamp, endtime timestamp, @@ -120,7 +121,7 @@ CREATE TABLE specification ( ALTER TABLE specification OWNER TO renting; -CREATE TABLE task ( +CREATE TABLE resource_allocation.task ( id serial NOT NULL, mom_id integer, otdb_id integer, @@ -132,7 +133,7 @@ CREATE TABLE task ( ALTER TABLE task OWNER TO renting; -CREATE TABLE resource_claim_status ( +CREATE TABLE resource_allocation.resource_claim_status ( id serial NOT NULL, name text NOT NULL, PRIMARY KEY (id) @@ -140,7 +141,7 @@ CREATE TABLE resource_claim_status ( ALTER TABLE resource_claim_status OWNER TO renting; -CREATE TABLE resource_claim ( +CREATE TABLE resource_allocation.resource_claim ( id serial NOT NULL, resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, task_id integer NOT NULL REFERENCES task DEFERRABLE INITIALLY IMMEDIATE, -- ON DELETE CASCADE, @@ -156,7 +157,7 @@ CREATE TABLE resource_claim ( ALTER TABLE resource_claim OWNER TO renting; -CREATE TABLE resource_capacity ( +CREATE TABLE resource_monitoring.resource_capacity ( id serial NOT NULL, resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, available bigint NOT NULL, @@ -166,7 +167,7 @@ CREATE TABLE resource_capacity ( ALTER TABLE resource_capacity OWNER TO renting; -CREATE TABLE resource_availability ( +CREATE TABLE resource_monitoring.resource_availability ( id serial NOT NULL, resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, available bool NOt NULL, @@ -175,7 +176,7 @@ CREATE TABLE resource_availability ( ALTER TABLE resource_availability OWNER TO renting; -CREATE TABLE resource_group_availability ( +CREATE TABLE resource_monitoring.resource_group_availability ( id serial NOT NULL, resource_group_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, available bool NOt NULL, diff --git a/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/fill_database.sql b/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/fill_database.sql index 691bc376a3af7a0b5eb2cb7fd6ba12192c45dd29..ecde47344a5b016a1ff49b8b4789e3ab254b48be 100644 --- a/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/fill_database.sql +++ b/SAS/ResourceAssignment/ResourceAllocationDatabase/sql/fill_database.sql @@ -1,20 +1,20 @@ BEGIN; -INSERT INTO unit VALUES (0, 'station'),(1, 'bytes'); -INSERT INTO resource_type VALUES (0, 'station', 0),(1, 'storage', 1); -INSERT INTO resource VALUES (0, 'CS001', 0), (1,'CS002', 0), (2, 'cep4_storage', 1); -INSERT INTO resource_group_type VALUES (0, 'stations'),(1, 'cluster'); -INSERT INTO resource_group VALUES (0, 'CORE', 0),(1, 'CEP4', 1); -INSERT INTO resource_to_resource_group VALUES (0, 0, 0),(1, 1, 0), (2, 2, 1); -INSERT INTO resource_group_to_resource_group VALUES (0, 0, NULL),(1, 1, NULL); -INSERT INTO task_status VALUES (0, 'SCHEDULED'),(1, 'CONFLICT'); -INSERT INTO task_type VALUES (0, 'OBSERVATION'),(1, 'PIPELINE'); -INSERT INTO specification VALUES (0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 'key=value'), +INSERT INTO virtual_instrument.unit VALUES (0, 'station'),(1, 'bytes'); +INSERT INTO virtual_instrument.resource_type VALUES (0, 'station', 0),(1, 'storage', 1); +INSERT INTO virtual_instrument.resource VALUES (0, 'CS001', 0), (1,'CS002', 0), (2, 'cep4_storage', 1); +INSERT INTO virtual_instrument.resource_group_type VALUES (0, 'stations'),(1, 'cluster'); +INSERT INTO virtual_instrument.resource_group VALUES (0, 'CORE', 0),(1, 'CEP4', 1); +INSERT INTO virtual_instrument.resource_to_resource_group VALUES (0, 0, 0),(1, 1, 0), (2, 2, 1); +INSERT INTO virtual_instrument.resource_group_to_resource_group VALUES (0, 0, NULL),(1, 1, NULL); +INSERT INTO resource_allocation.task_status VALUES (0, 'SCHEDULED'),(1, 'CONFLICT'); +INSERT INTO resource_allocation.task_type VALUES (0, 'OBSERVATION'),(1, 'PIPELINE'); +INSERT INTO resource_allocation.specification VALUES (0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 'key=value'), (1, '2015-11-05 13:00:00', '2015-11-05 14:00:00', 'key=1'); -INSERT INTO task VALUES (0, 654321, 12345, 0, 0, 0),(1, 765432, 2654321, 1, 1, 1); -INSERT INTO resource_claim_status VALUES (0, 'CLAIMED'),(1, 'ALLOCATED'); -INSERT INTO resource_claim VALUES (0, 0, 0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 0, '2015-11-06 12:00:00', 1), +INSERT INTO resource_allocation.task VALUES (0, 654321, 12345, 0, 0, 0),(1, 765432, 2654321, 1, 1, 1); +INSERT INTO resource_allocation.resource_claim_status VALUES (0, 'CLAIMED'),(1, 'ALLOCATED'); +INSERT INTO resource_allocation.resource_claim VALUES (0, 0, 0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 0, '2015-11-06 12:00:00', 1), (1, 2, 1, '2015-11-05 13:00:00', '2015-11-05 14:00:00', 1, '2015-11-06 12:00:00', 1234); -INSERT INTO resource_capacity VALUES (0, 0, 1, 1), (1, 1, 1,1 ), (2, 2, 15000, 100000); -INSERT INTO resource_availability VALUES (0, 0, TRUE), (1, 1, TRUE), (2, 2, TRUE); -INSERT INTO resource_group_availability VALUES (0, 0, TRUE), (1, 1, TRUE); +INSERT INTO resource_monitoring.resource_capacity VALUES (0, 0, 1, 1), (1, 1, 1,1 ), (2, 2, 15000, 100000); +INSERT INTO resource_monitoring.resource_availability VALUES (0, 0, TRUE), (1, 1, TRUE), (2, 2, TRUE); +INSERT INTO resource_monitoring.resource_group_availability VALUES (0, 0, TRUE), (1, 1, TRUE); COMMIT;