From b40274e81ba9474814b849e181adc43f113c1e8a Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Wed, 28 Feb 2018 09:21:38 +0100
Subject: [PATCH] Added Scheduler::checkAndGetNextArchiveFileId()

---
 scheduler/Scheduler.cpp | 21 +++++++++++++++++++++
 scheduler/Scheduler.hpp | 22 ++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/scheduler/Scheduler.cpp b/scheduler/Scheduler.cpp
index 2baf65eea8..22ca8e470d 100644
--- a/scheduler/Scheduler.cpp
+++ b/scheduler/Scheduler.cpp
@@ -84,6 +84,27 @@ void Scheduler::authorizeAdmin(const common::dataStructures::SecurityIdentity &c
   lc.log(log::INFO, "In Scheduler::authorizeAdmin(): success.");
 }
 
+//------------------------------------------------------------------------------
+// checkAndGetNextArchiveFileId
+//------------------------------------------------------------------------------
+uint64_t Scheduler::checkAndGetNextArchiveFileId(const std::string &instanceName,
+  const std::string &storageClassName, const common::dataStructures::UserIdentity &user, log::LogContext &lc) {
+  cta::utils::Timer t;
+  const uint64_t archiveFileId = m_catalogue.checkAndGetNextArchiveFileId(instanceName, storageClassName, user);
+  const auto catalogueTime = t.secs();
+  const auto schedulerDbTime = catalogueTime;
+
+  log::ScopedParamContainer spc(lc);
+  spc.add("instanceName", instanceName)
+     .add("storageClass", storageClassName)
+     .add("fileId", archiveFileId)
+     .add("catalogueTime", catalogueTime)
+     .add("schedulerDbTime", schedulerDbTime);
+  lc.log(log::INFO, "Checked request and got next archive file ID");
+
+  return archiveFileId;
+}
+
 //------------------------------------------------------------------------------
 // queueArchive
 //------------------------------------------------------------------------------
diff --git a/scheduler/Scheduler.hpp b/scheduler/Scheduler.hpp
index 6c2018581d..de3d37266c 100644
--- a/scheduler/Scheduler.hpp
+++ b/scheduler/Scheduler.hpp
@@ -87,6 +87,28 @@ public:
    */
   void ping(log::LogContext & lc);
 
+  /**
+   * Checks the specified archival could take place and returns a new and
+   * unique archive file identifier that can be used by a new archive file
+   * within the catalogue.
+   *
+   * @param diskInstanceName The name of the disk instance to which the
+   * storage class belongs.
+   * @param storageClassName The name of the storage class of the file to be
+   * archived.  The storage class name is only guaranteed to be unique within
+   * its disk instance.  The storage class name will be used by the Catalogue
+   * to determine the destination tape pool for each tape copy.
+   * @param user The user for whom the file is to be archived.  This will be
+   * used by the Catalogue to determine the mount policy to be used when
+   * archiving the file.
+   * @return The new archive file identifier.
+   */
+  uint64_t checkAndGetNextArchiveFileId(
+    const std::string &diskInstanceName,
+    const std::string &storageClassName,
+    const common::dataStructures::UserIdentity &user,
+    log::LogContext &lc);
+
   /** 
    * Queue an archive request and return the CTA file ID. 
    * Throws a UserError exception in case of wrong request parameters (ex. no route to tape)
-- 
GitLab