From f2cdb5eeeb6531e931959c84119c2dc84828935a Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Mon, 3 Aug 2015 09:26:19 +0200
Subject: [PATCH] Fleshed out the Job classes.

The bottom line is the Mount and Job classes shall be passed around the
tapeserverd daemon for two purposes, to carry all the information about
the file copy to be transfered and to provide the notification interface
to the scheduler on which the tapeserverd daemon needs to call methods
to indicate the ends of transfers and mounts.
---
 scheduler/ArchiveJob.cpp    | 46 ++++++++++++-----
 scheduler/ArchiveJob.hpp    | 99 ++++++++++++++++++++++++++++++-------
 scheduler/ArchiveMount.cpp  |  7 +++
 scheduler/ArchiveMount.hpp  | 10 +++-
 scheduler/RetrieveJob.cpp   | 19 ++++---
 scheduler/RetrieveJob.hpp   | 77 +++++++++++++++++++++++------
 scheduler/RetrieveMount.cpp |  7 +++
 scheduler/RetrieveMount.hpp | 10 +++-
 scheduler/TapeJob.cpp       | 13 ++++-
 scheduler/TapeJob.hpp       | 40 +++++++++++++--
 scheduler/TapeMount.hpp     |  9 ++++
 11 files changed, 273 insertions(+), 64 deletions(-)

diff --git a/scheduler/ArchiveJob.cpp b/scheduler/ArchiveJob.cpp
index 5d7cb455cf..ec68642834 100644
--- a/scheduler/ArchiveJob.cpp
+++ b/scheduler/ArchiveJob.cpp
@@ -18,12 +18,6 @@
 
 #include "scheduler/ArchiveJob.hpp"
 
-//------------------------------------------------------------------------------
-// constructor
-//------------------------------------------------------------------------------
-cta::ArchiveJob::ArchiveJob() {
-}
-
 //------------------------------------------------------------------------------
 // destructor
 //------------------------------------------------------------------------------
@@ -34,13 +28,35 @@ cta::ArchiveJob::~ArchiveJob() throw() {
 // constructor
 //------------------------------------------------------------------------------
 cta::ArchiveJob::ArchiveJob(
+// NOT YET DECIDED
+//ArchiveMount &mount,
   const std::string &tapePoolName,
+  const uint64_t fileSize,
   const std::string &id,
   const std::string &userRequestId,
   const uint32_t copyNb,
-  const std::string &remoteFile):
-  TapeJob(id, userRequestId, copyNb, remoteFile),
-  m_tapePoolName(tapePoolName) {
+  const std::string &remoteFile,
+  const uint64_t castorNsFileId):
+  TapeJob(id, userRequestId, copyNb, remoteFile, castorNsFileId),
+// NOT YET DECIDED
+//  m_mount(mount),
+  m_tapePoolName(tapePoolName),
+  m_fileSize(fileSize) {
+}
+
+//------------------------------------------------------------------------------
+// getMount
+//------------------------------------------------------------------------------
+// NOT YET DECIDED
+//cta::ArchiveMount &cta::ArchiveJob::getMount() {
+//  return m_mount;
+//}
+
+//------------------------------------------------------------------------------
+// getMount
+//------------------------------------------------------------------------------
+cta::ArchiveMount &cta::ArchiveJob::getMount() const {
+  return m_mount;
 }
 
 //------------------------------------------------------------------------------
@@ -50,16 +66,24 @@ const std::string &cta::ArchiveJob::getTapePoolName() const throw() {
   return m_tapePoolName;
 }
 
+//------------------------------------------------------------------------------
+// getFileSize
+//------------------------------------------------------------------------------
+uint64_t cta::ArchiveJob::getFileSize() const throw() {
+  return m_fileSize;
+}
+
 //------------------------------------------------------------------------------
 // complete
 //------------------------------------------------------------------------------
-void cta::ArchiveJob::complete() {
+void cta::ArchiveJob::complete(const uint32_t checksumOfTransfer,
+    const uint64_t fileSizeOfTransfer) {
 }
   
 //------------------------------------------------------------------------------
 // failed
 //------------------------------------------------------------------------------
-void cta::ArchiveJob::failed() {
+void cta::ArchiveJob::failed(const std::exception &ex) {
 }
   
 //------------------------------------------------------------------------------
diff --git a/scheduler/ArchiveJob.hpp b/scheduler/ArchiveJob.hpp
index d485ff94a5..14d9f4c485 100644
--- a/scheduler/ArchiveJob.hpp
+++ b/scheduler/ArchiveJob.hpp
@@ -26,41 +26,71 @@
 namespace cta {
   // Forward declaration
   // class ArchivePath; 
+  class ArchiveMount;
   class RemotePathAndStatus;
 
 /**
  * Class representing the transfer of a single copy of a remote file to tape.
  */
 class ArchiveJob: public TapeJob {
-  friend class ArchiveMount;
-private:
-  /**
-   * Constructor. It is private as the ArchiveJob is generated by the 
-   * ArchiveMount.
-   */
-  ArchiveJob();
 
-public:
   /**
-   * Destructor.
+   * The ArchiveMount class is a friend so that it can call the private
+   * constructor of ArchiveJob.
    */
-  ~ArchiveJob() throw();
+  friend class ArchiveMount;
+
+private:
 
   /**
-   * Constructor.
+   * Constructor. It is private as the ArchiveJob is generated by the 
+   * ArchiveMount.
    *
+//   NOT YET DECIDED
+   * @param archiveMount The mount to which the job belongs.
    * @param tapePoolName The name of the destination tape pool.
+   * @param fileSize The size of the file to be archived in bytes.
    * @param id The identifier of the tape job.
    * @param userRequestId The identifier of the associated user request.
    * @param copyNb The copy number.
    * @param remoteFile The URL of the remote source file.
+   * @param castorNsFileId The CASTOR name server identifier of the file in the
+   * archive namespace that depending on the direction of the data transfer may
+   * be either the source or the destination of the tape job.
    */
   ArchiveJob(
+//  NOT YET DECIDED
+//  ArchiveMount &archiveMount,
     const std::string &tapePoolName,
+    const uint64_t fileSize,
     const std::string &id,
     const std::string &userRequestId,
     const uint32_t copyNb,
-    const std::string &remoteFile);
+    const std::string &remoteFile,
+    const uint64_t castorNsFileId);
+
+public:
+
+  /**
+   * Destructor.
+   */
+  ~ArchiveJob() throw();
+
+  /**
+   * Returns the mount to which this job belongs.
+   *
+   * @return the mount to which this job belongs.
+   */
+// TO BE DECIDED
+//ArchiveMount &getMount() const;
+
+  /**
+   * Returns the mount to which this job belongs.
+   *
+   * @return the mount to which this job belongs.
+   */
+  // NO YET DECIDED
+  //ArchiveMount &getMount();
 
   /**
    * Returns the name of the destination tape pool.
@@ -68,30 +98,63 @@ public:
    * @return the name of the destination tape pool.
    */
   const std::string &getTapePoolName() const throw();
-  
+
+  /**
+   * Returns the size of the file to be archived in bytes.
+   *
+   * @return The size of the file to be archived in bytes.
+   */
+  uint64_t getFileSize() const throw();
+
+  /**
+   * Returns the The URL of the remote source file.
+   *
+   * @return The The URL of the remote source file.
+   */
+  std::string getRemoteFile() const throw();
+
   /**
    * Indicates that the job was successful
+   *
+   * @param checksumOfTransfer The adler-32 checksum of the file as calculated
+   * during the execution of the job.
+   * @param fileSizeOfTransfer The size of the file as calculated during the
+   * execution of the job.
    */
-  void complete();
-  
+  virtual void complete(const uint32_t checksumOfTransfer,
+    const uint64_t fileSizeOfTransfer);
+
   /**
    * Indicates that the job failed
+   *
+   * @param ex The reason for the failure.
    */
-  void failed();
-  
+  virtual void failed(const std::exception &ex);
+
   /**
    * Indicates that the job should be tried again (typically reaching the end 
    * of the tape).
    */
-  void retry();
+  virtual void retry();
 
 private:
 
+  /**
+   * The mount to which the job belongs.
+   */
+// NOT YET DECIDED
+//ArchiveMount &m_mount;
+
   /**
    * The name of the destination tape pool.
    */
   std::string m_tapePoolName;
 
+  /**
+   * The size of the file to be archived in bytes.
+   */
+  uint64_t m_fileSize;
+
 }; // class ArchiveJob
 
 } // namespace cta
diff --git a/scheduler/ArchiveMount.cpp b/scheduler/ArchiveMount.cpp
index 57a86cdb0e..30df27f7c0 100644
--- a/scheduler/ArchiveMount.cpp
+++ b/scheduler/ArchiveMount.cpp
@@ -38,6 +38,13 @@ cta::MountType::Enum cta::ArchiveMount::getMountType() const throw() {
   return MountType::ARCHIVE;
 }
 
+//------------------------------------------------------------------------------
+// getVid
+//------------------------------------------------------------------------------
+std::string cta::ArchiveMount::getVid() const throw() {
+  return "UNKNOWN_VID_FOR_ARCHIVE_MOUNT";
+}
+
 //------------------------------------------------------------------------------
 // finish
 //------------------------------------------------------------------------------
diff --git a/scheduler/ArchiveMount.hpp b/scheduler/ArchiveMount.hpp
index b57e99fe04..5691b22366 100644
--- a/scheduler/ArchiveMount.hpp
+++ b/scheduler/ArchiveMount.hpp
@@ -28,7 +28,6 @@
 
 namespace cta {
   
-  class ArchiveMount;
   /**
    * The class driving a retrieve mount.
    * The class only has private constructors as it is instanciated by
@@ -55,7 +54,14 @@ namespace cta {
      *
      * @return The type of this tape mount.
      */
-    MountType::Enum getMountType() const throw();
+    virtual MountType::Enum getMountType() const throw();
+
+    /**
+     * Returns the volume identifier of the tape to be mounted.
+     *
+     * @return The volume identifier of the tape to be mounted.
+     */
+    virtual std::string getVid() const throw();
 
     /**
      * Notifies the scheduler that the session is finished 
diff --git a/scheduler/RetrieveJob.cpp b/scheduler/RetrieveJob.cpp
index b18abb21c3..b2935feedc 100644
--- a/scheduler/RetrieveJob.cpp
+++ b/scheduler/RetrieveJob.cpp
@@ -18,12 +18,6 @@
 
 #include "scheduler/RetrieveJob.hpp"
 
-//------------------------------------------------------------------------------
-// constructor
-//------------------------------------------------------------------------------
-cta::RetrieveJob::RetrieveJob() {
-}
-
 //------------------------------------------------------------------------------
 // destructor
 //------------------------------------------------------------------------------
@@ -34,25 +28,30 @@ cta::RetrieveJob::~RetrieveJob() throw() {
 // constructor
 //------------------------------------------------------------------------------
 cta::RetrieveJob::RetrieveJob(
+// TO BE DECIDED
+//RetrieveMount &mount,
   const TapeCopyLocation &tapeFile,
   const std::string &id, 
   const std::string &userRequestId,
   const uint32_t copyNb,
-  const std::string &remoteFile):
-  TapeJob(id, userRequestId, copyNb, remoteFile),
+  const std::string &remoteFile,
+  const uint64_t castorNsFileId):
+  TapeJob(id, userRequestId, copyNb, remoteFile, castorNsFileId),
+  m_mount(mount),
   tapeFile(tapeFile) {
 }
 
 //------------------------------------------------------------------------------
 // complete
 //------------------------------------------------------------------------------
-void cta::RetrieveJob::complete() {
+void cta::RetrieveJob::complete(const uint32_t checksumOfTransfer, 
+  const uint64_t fileSizeOfTransfer) {
 }
   
 //------------------------------------------------------------------------------
 // failed
 //------------------------------------------------------------------------------
-void cta::RetrieveJob::failed() {
+void cta::RetrieveJob::failed(const std::exception &ex) {
 }
   
 //------------------------------------------------------------------------------
diff --git a/scheduler/RetrieveJob.hpp b/scheduler/RetrieveJob.hpp
index 7937e0dddf..b7326f6a86 100644
--- a/scheduler/RetrieveJob.hpp
+++ b/scheduler/RetrieveJob.hpp
@@ -1,5 +1,5 @@
 /*
- * The CERN Tape Archive (CTA) project
+ * The CERN Tape Retrieve (CTA) project
  * Copyright (C) 2015  CERN
  *
  * This program is free software: you can redistribute it and/or modify
@@ -25,47 +25,86 @@
 
 namespace cta {
 
+class RetrieveMount;
+
 /**
  * The transfer of a single copy of a tape file to a remote file.
  */
-struct RetrieveJob: public TapeJob {
-public:
-
+class RetrieveJob: public TapeJob {
   /**
-   * Constructor.
+   * The RetrieveMount class is a friend so that it can call the private
+   * constructor of RetrieveJob.
    */
-  RetrieveJob();
+  friend class RetrieveMount;
 
-  /**
-   * Destructor.
-   */
-  ~RetrieveJob() throw();
+private:
 
   /**
-   * Constructor.
+   * Constructor. It is private as the ArchiveJob is generated by the 
+   * RetrieveMount.
    *
+// TO BE DECIDED
+   * @param mount The mount to which the job belongs.
    * @param tapeFile The location of the source tape file.
    * @param id The identifier of the tape job.
    * @param userRequestId The identifier of the associated user request.
    * @param copyNb The copy number.
    * @param remoteFile The URL of the destination source file.
+   * @param castorNsFileId The CASTOR name server identifier of the file in the
+   * archive namespace that depending on the direction of the data transfer may
+   * be either the source or the destination of the tape job.
    */
   RetrieveJob(
+// TO BE DECIDED
+//  RetrieveMount &mount,
     const TapeCopyLocation &tapeFile,
     const std::string &id,
     const std::string &userRequestId,
     const uint32_t copyNb,
-    const std::string &remoteFile);
+    const std::string &remoteFile,
+    const uint64_t castorNsFileId);
+
+public:
+
+  /**
+   * Destructor.
+   */
+  ~RetrieveJob() throw();
+
+
+  /**
+   * Returns the mount to which this job belongs.
+   *
+   * @return the mount to which this job belongs.
+   */
+// TO BE DECIDED
+//RetrieveMount &getMount() const;
+
+  /**
+   * Returns the mount to which this job belongs.
+   *
+   * @return the mount to which this job belongs.
+   */
+// TO BE DECIDED
+//RetrieveMount &getMount();
 
   /**
    * Indicates that the job was successful
+   *
+   * @param checksumOfTransfer The adler-32 checksum of the file as calculated
+   * during the execution of the job.
+   * @param fileSizeOfTransfer The size of the file as calculated during the
+   * execution of the job.
    */
-  void complete();
+  virtual void complete(const uint32_t checksumOfTransfer,
+    const uint64_t fileSizeOfTransfer);
   
   /**
    * Indicates that the job failed
+   *
+   * @param ex The reason for the failure.
    */
-  void failed();
+  virtual void failed(const std::exception &ex);
   
   /**
    * Indicates that the job should be tried again (typically reaching the end 
@@ -73,6 +112,16 @@ public:
    */
   void retry();
 
+private:
+
+  /**
+   * The mount to which the job belongs.
+   */
+// TO BE DECIDED
+//RetrieveMount &m_mount;
+
+public:
+
   /**
    * The location of the source tape file.
    */
diff --git a/scheduler/RetrieveMount.cpp b/scheduler/RetrieveMount.cpp
index 04c2230591..42f89fd374 100644
--- a/scheduler/RetrieveMount.cpp
+++ b/scheduler/RetrieveMount.cpp
@@ -38,6 +38,13 @@ cta::MountType::Enum cta::RetrieveMount::getMountType() const throw() {
   return MountType::ARCHIVE;
 }
 
+//------------------------------------------------------------------------------
+// getVid
+//------------------------------------------------------------------------------
+std::string cta::RetrieveMount::getVid() const throw() {
+  return "UNKNOWN_VID_FOR_RETRIEVE_MOUNT";
+}
+
 //------------------------------------------------------------------------------
 // finish
 //------------------------------------------------------------------------------
diff --git a/scheduler/RetrieveMount.hpp b/scheduler/RetrieveMount.hpp
index b4d541fdd9..2174df0c45 100644
--- a/scheduler/RetrieveMount.hpp
+++ b/scheduler/RetrieveMount.hpp
@@ -28,7 +28,6 @@
 
 namespace cta {
   
-  class RetrieveMount;
   /**
    * The class driving a retrieve mount.
    * The class only has private constructors as it is instanciated by
@@ -55,7 +54,14 @@ namespace cta {
      *
      * @return The type of this tape mount.
      */
-    MountType::Enum getMountType() const throw();
+    virtual MountType::Enum getMountType() const throw();
+
+    /**
+     * Returns the volume identifier of the tape to be mounted.
+     *
+     * @return The volume identifier of the tape to be mounted.
+     */
+    virtual std::string getVid() const throw();
 
     /**
      * Notifies the scheduler that the session is finished 
diff --git a/scheduler/TapeJob.cpp b/scheduler/TapeJob.cpp
index 2157b48bd8..606260a365 100644
--- a/scheduler/TapeJob.cpp
+++ b/scheduler/TapeJob.cpp
@@ -38,11 +38,13 @@ cta::TapeJob::TapeJob(
   const std::string &id,
   const std::string &userRequestId,
   const uint32_t copyNb,
-  const std::string &remoteFile):
+  const std::string &remoteFile,
+  const uint64_t castorNsFileId):
   m_id(id),
   m_userRequestId(userRequestId),
   m_copyNb(copyNb),
-  m_remoteFile(remoteFile) {
+  m_remoteFile(remoteFile),
+  m_castorNsFileId(castorNsFileId) {
 }
 
 //------------------------------------------------------------------------------
@@ -72,3 +74,10 @@ uint32_t cta::TapeJob::getCopyNb() const throw() {
 const std::string &cta::TapeJob::getRemoteFile() const throw() {
   return m_remoteFile;
 }
+
+//------------------------------------------------------------------------------
+// getCastorNsFileId
+//------------------------------------------------------------------------------
+uint64_t cta::TapeJob::getCastorNsFileId() const throw() {
+  return m_castorNsFileId;
+}
diff --git a/scheduler/TapeJob.hpp b/scheduler/TapeJob.hpp
index bf2f7a7713..30c4c17f6e 100644
--- a/scheduler/TapeJob.hpp
+++ b/scheduler/TapeJob.hpp
@@ -48,12 +48,16 @@ public:
    * @param remoteFile The URL of the remote file that depending on the
    * direction of the data transfer may be either the source or the
    * destination of the tape job.
+   * @param castorNsFileId The CASTOR name server identifier of the file in the
+   * archive namespace that depending on the direction of the data transfer may
+   * be either the source or the destination of the tape job.
    */
   TapeJob(
     const std::string &id,
     const std::string &userRequestId,
     const uint32_t copyNb,
-    const std::string &remoteFile);
+    const std::string &remoteFile,
+    const uint64_t castorNsFileId);
 
   /**
    * Returns the identifier of the tape job.
@@ -87,16 +91,35 @@ public:
    */
   const std::string &getRemoteFile() const throw();
 
+  /**
+   * Returns The CASTOR name server identifier of the file in the archive
+   * namespace that depending on the direction of the data transfer may be
+   * either the source or the destination of the tape job.
+   *
+   * @return The CASTOR name server identifier of the file in the archive
+   * namespace that depending on the direction of the data transfer may be
+   * either the source or the destination of the tape job.
+   */
+  uint64_t getCastorNsFileId() const throw();
+
   /**
    * Indicates that the job was successful
+   *
+   * @param checksumOfTransfer The adler-32 checksum of the file as calculated
+   * during the execution of the job.
+   * @param fileSizeOfTransfer The size of the file as calculated during the
+   * execution of the job.
    */
-  virtual void complete() = 0;
-  
+  virtual void complete(const uint32_t checksumOfTransfer,
+    const uint64_t fileSizeOfTransfer) = 0;
+ 
   /**
    * Indicates that the job failed
+   *
+   * @param ex The reason for the failure.
    */
-  virtual void failed() = 0;
-  
+  virtual void failed(const std::exception &ex) = 0;
+
   /**
    * Indicates that the job should be tried again (typically reaching the end 
    * of the tape).
@@ -126,6 +149,13 @@ private:
    */
   std::string m_remoteFile;
 
+  /**
+   * The CASTOR name server identifier of the file in the archive
+   * namespace that depending on the direction of the data transfer may be
+   * either the source or the destination of the tape job.
+   */
+  uint64_t m_castorNsFileId;
+
 }; // class TapeJob
 
 } // namespace cta
diff --git a/scheduler/TapeMount.hpp b/scheduler/TapeMount.hpp
index c905883bcb..5a520484e5 100644
--- a/scheduler/TapeMount.hpp
+++ b/scheduler/TapeMount.hpp
@@ -20,6 +20,8 @@
 
 #include "scheduler/MountType.hpp"
 
+#include <string>
+
 namespace cta {
   /**
    * A placeholder class from which will derive ArchiveSession and RetriveSession.
@@ -35,6 +37,13 @@ namespace cta {
      */
     virtual MountType::Enum getMountType() const throw() = 0;
 
+    /**
+     * Returns the volume identifier of the tape to be mounted.
+     *
+     * @return The volume identifier of the tape to be mounted.
+     */
+    virtual std::string getVid() const throw() = 0;
+
     /**
      * Notifies the scheduler that the session is finished 
      */
-- 
GitLab