Commit c251639e authored by Michael Davis's avatar Michael Davis
Browse files

[migration] Adds VIRTUAL_ORGANIZATION_ID column to STORAGE_CLASS and TAPE_POOL tables

parent 87a0b62a
......@@ -61,7 +61,7 @@ ALTER TABLE Tape_File PARALLEL;
-- Import a tapepool and its tapes from CASTOR
-- Raises constraint_violation if the tapepool and/or some tapes were already imported
CREATE OR REPLACE PROCEDURE importTapePool(inTapePool VARCHAR2, inVO VARCHAR2) AS
CREATE OR REPLACE PROCEDURE importTapePool(inTapePool VARCHAR2, inVO_id INTEGER) AS
varUnused VARCHAR2(100);
CONSTRAINT_VIOLATED EXCEPTION;
PRAGMA EXCEPTION_INIT(CONSTRAINT_VIOLATED, -1);
......@@ -87,13 +87,13 @@ BEGIN
BEGIN
SELECT Tape_Pool_id_seq.NEXTVAL INTO varTapePoolId FROM Dual;
INSERT INTO Tape_Pool (tape_pool_id, tape_pool_name, vo, nb_partial_tapes, is_encrypted, user_comment,
INSERT INTO Tape_Pool (tape_pool_id, tape_pool_name, virtual_organization_id, nb_partial_tapes, is_encrypted, user_comment,
creation_log_user_name, creation_log_host_name, creation_log_time, last_update_user_name,
last_update_host_name, last_update_time)
VALUES (
varTapePoolId,
inTapePool,
inVO,
inVO_id,
0, -- nb_partial_tapes, to be filled afterwards
'0', -- is_encrypted is assumed false in CASTOR
'Imported from CASTOR',
......@@ -103,7 +103,7 @@ BEGIN
EXCEPTION WHEN CONSTRAINT_VIOLATED THEN
-- The TapePool is already present, typically because of a previous import: override some values
UPDATE Tape_Pool SET
vo = inVO,
virtual_organization_id = inVO_id,
user_comment = 'Re-imported from CASTOR',
last_update_user_name = 'CASTOR',
last_update_host_name = 'CASTOR',
......@@ -171,7 +171,7 @@ END;
-- Insert the file-level metadata for the given migration
CREATE OR REPLACE PROCEDURE populateCTAFilesFromCASTOR(inEOSCTAInstance VARCHAR2, inTapePool VARCHAR2) AS
CREATE OR REPLACE PROCEDURE populateCTAFilesFromCASTOR(inEOSCTAInstance VARCHAR2, inTapePool VARCHAR2, inVO_id INTEGER) AS
CONSTRAINT_VIOLATED EXCEPTION;
PRAGMA EXCEPTION_INIT(CONSTRAINT_VIOLATED, -1);
varIs2ndCopy INTEGER;
......@@ -184,14 +184,15 @@ BEGIN
WHERE classid IN
(SELECT classid FROM CNS_CTAFilesHelper)) LOOP
BEGIN
INSERT INTO Storage_Class (storage_class_id,
storage_class_name, nb_copies, user_comment,
INSERT INTO Storage_Class (storage_class_id, storage_class_name, nb_copies,
virtual_organization_id, user_comment,
creation_log_user_name, creation_log_host_name, creation_log_time,
last_update_user_name, last_update_host_name, last_update_time)
VALUES (
c.classid,
c.classname,
c.nbcopies,
inVO_id,
'Imported from CASTOR',
'CASTOR', 'CASTOR', CNS_getTime(),
'CASTOR', 'CASTOR', CNS_getTime()
......@@ -200,6 +201,7 @@ BEGIN
UPDATE Storage_Class SET -- it is already present, update it with the current values
storage_class_name = c.classname,
nb_copies = c.nbcopies,
virtual_organization_id = inVO_id,
user_comment = 'Re-imported from CASTOR',
last_update_user_name = 'CASTOR',
last_update_host_name = 'CASTOR',
......@@ -277,6 +279,7 @@ END;
-- Entry point to import metadata from the CASTOR namespace
CREATE OR REPLACE PROCEDURE importFromCASTOR(inTapePool VARCHAR2, inVO VARCHAR2, inEOSCTAInstance VARCHAR2, inZeroBytes IN INTEGER, inDryRun INTEGER) AS
nbFiles INTEGER;
inVO_id INTEGER;
varTapePool VARCHAR2(100) := inTapePool;
var2ndTapePool VARCHAR2(100) := NULL;
BEGIN
......@@ -289,6 +292,13 @@ BEGIN
IF inZeroBytes = 1 THEN
varTapePool := upper(inVO) || '::*'; -- made-up convention for logging purposes
END IF;
-- get Virtual Organization ID (VO table must be pre-filled using 'cta-admin vo add ...')
SELECT VIRTUAL_ORGANIZATION_ID INTO inVO_id FROM VIRTUAL_ORGANIZATION WHERE VIRTUAL_ORGANIZATION_NAME = inVO;
IF NOT FOUND THEN
raise_application_error(-20000, 'Virtual organization ' || inVO || ' not found in VIRTUAL_ORGANIZATION table.');
END IF;
IF inDryRun = 0 THEN
CNS_ctaLog(varTapePool, 'CASTOR metadata import started');
ELSE
......@@ -301,9 +311,9 @@ BEGIN
-- extract all directories metadata
CNS_dirsForCTAExport(inTapePool);
-- import tapes; can raise exceptions
importTapePool(inTapePool, inVO);
importTapePool(inTapePool, inVO_id);
IF var2ndTapePool IS NOT NULL THEN
importTapePool(var2ndTapePool, inVO);
importTapePool(var2ndTapePool, inVO_id);
END IF;
ELSE
-- 0-byte files are special as they do not belong to any tape pool
......@@ -312,7 +322,7 @@ BEGIN
CNS_dirsForCTAExport(varTapePool);
END IF;
-- import metadata into the CTA catalogue
populateCTAFilesFromCASTOR(inEOSCTAInstance, varTapePool);
populateCTAFilesFromCASTOR(inEOSCTAInstance, varTapePool, inVO_id);
IF inDryRun = 0 THEN
CNS_ctaLog(varTapePool, 'CASTOR metadata import completed successfully');
ELSE
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment