From dcb9d5b171e79e43d6dd98d7be442a3fcf3813aa Mon Sep 17 00:00:00 2001
From: Cedric CAFFY <cedric.caffy@hotmail.fr>
Date: Wed, 12 Dec 2018 04:02:00 -0500
Subject: [PATCH] "Adding log in read / write start and finish session. These
 logs does not contain the real values of VO and Density"

---
 scheduler/ArchiveMount.cpp                    | 14 ++++++++
 scheduler/ArchiveMount.hpp                    | 12 +++++++
 scheduler/RetrieveMount.cpp                   | 32 +++++++++++++++++++
 scheduler/RetrieveMount.hpp                   | 19 +++++++++++
 scheduler/Scheduler.cpp                       |  1 +
 scheduler/SchedulerDatabase.hpp               |  4 +++
 scheduler/TapeMount.hpp                       |  4 +++
 scheduler/TapeMountDummy.hpp                  |  7 ++++
 .../tapeserver/daemon/DataTransferSession.cpp |  7 ++--
 .../daemon/DataTransferSessionTest.cpp        |  2 ++
 .../daemon/TapeReadSingleThread.cpp           | 15 +++++++--
 .../daemon/TapeReadSingleThread.hpp           | 12 +++++--
 .../daemon/TapeWriteSingleThread.cpp          | 13 ++++++--
 .../daemon/TapeWriteSingleThread.hpp          | 10 +++++-
 tapeserver/daemon/DriveHandler.cpp            |  1 -
 15 files changed, 141 insertions(+), 12 deletions(-)

diff --git a/scheduler/ArchiveMount.cpp b/scheduler/ArchiveMount.cpp
index 8653b35c48..15062002ca 100644
--- a/scheduler/ArchiveMount.cpp
+++ b/scheduler/ArchiveMount.cpp
@@ -68,6 +68,20 @@ std::string cta::ArchiveMount::getPoolName() const {
   return m_dbMount->mountInfo.tapePool;
 }
 
+//------------------------------------------------------------------------------
+// getVo
+//------------------------------------------------------------------------------
+std::string cta::ArchiveMount::getVo() const {
+    return "Alice";//m_dbMount->mountInfo.vo;
+}
+
+//------------------------------------------------------------------------------
+// getVo
+//------------------------------------------------------------------------------
+std::string cta::ArchiveMount::getDensity() const{
+    return "8000GC";//m_dbMount->mountInfo.density;
+}
+
 //------------------------------------------------------------------------------
 // getNbFiles
 //------------------------------------------------------------------------------
diff --git a/scheduler/ArchiveMount.hpp b/scheduler/ArchiveMount.hpp
index a74d1a62e6..8d7c29c1ef 100644
--- a/scheduler/ArchiveMount.hpp
+++ b/scheduler/ArchiveMount.hpp
@@ -141,6 +141,18 @@ namespace cta {
      */
     std::string getPoolName() const;
     
+    /**
+     * Returns the virtual organization of the tape to be mounted
+     * @return the vo of the tape to be mounted
+     */
+    std::string getVo() const;
+    
+    /**
+     * Returns the density (e.g : 8000GC) of the tape to be mounted
+     * @return the density of the tape to be mounted
+     */
+    std::string getDensity() const;
+    
     /**
      * Returns the mount transaction id.
      *
diff --git a/scheduler/RetrieveMount.cpp b/scheduler/RetrieveMount.cpp
index 42f852a69d..fa0393eb7d 100644
--- a/scheduler/RetrieveMount.cpp
+++ b/scheduler/RetrieveMount.cpp
@@ -66,6 +66,38 @@ std::string cta::RetrieveMount::getMountTransactionId() const{
   return id.str();
 }
 
+//------------------------------------------------------------------------------
+// getMountTapePool()
+//------------------------------------------------------------------------------
+std::string cta::RetrieveMount::getPoolName() const{
+  std::stringstream sTapePool;
+  if (!m_dbMount.get())
+    throw exception::Exception("In cta::RetrieveMount::getPoolName(): got NULL dbMount");
+  sTapePool << m_dbMount->mountInfo.tapePool;
+  return sTapePool.str();
+}
+
+//------------------------------------------------------------------------------
+// getVo()
+//------------------------------------------------------------------------------
+std::string cta::RetrieveMount::getVo() const
+{
+    std::stringstream sVo;
+    if(!m_dbMount.get())
+        throw exception::Exception("In cta::RetrieveMount::getVo(): got NULL dbMount");
+    sVo<<"Alice";//m_dbMount->mountInfo.vo;
+    return sVo.str();
+}
+
+std::string cta::RetrieveMount::getDensity() const
+{
+    std::stringstream sDensity;
+    if(!m_dbMount.get())
+        throw exception::Exception("In cta::RetrieveMount::getDensity(): got NULL dbMount");
+    sDensity<<"8000GC";//m_dbMount->mountInfo.density;
+    return sDensity.str();
+}
+
 //------------------------------------------------------------------------------
 // getNextJobBatch()
 //------------------------------------------------------------------------------
diff --git a/scheduler/RetrieveMount.hpp b/scheduler/RetrieveMount.hpp
index 3505542bf0..c90efa65ff 100644
--- a/scheduler/RetrieveMount.hpp
+++ b/scheduler/RetrieveMount.hpp
@@ -83,6 +83,25 @@ namespace cta {
      */
     uint32_t getNbFiles() const override;
     
+     /**
+     * Returns the tape pool of the tape to be mounted
+     * @return The tape pool of the tape to be mounted
+     */
+    std::string getPoolName() const;
+    
+    /**
+     * Returns the virtual organization in which the tape
+     * belongs
+     * @return the vo in which the tape belongs
+     */
+    std::string getVo() const;
+    
+    /**
+     * Returns the density (e.g : 8000GC) of the tape
+     * @return de density of the tape
+     */
+    std::string getDensity() const;
+    
     /**
      * Report a drive status change
      */
diff --git a/scheduler/Scheduler.cpp b/scheduler/Scheduler.cpp
index 851a72538d..751d8de11b 100644
--- a/scheduler/Scheduler.cpp
+++ b/scheduler/Scheduler.cpp
@@ -851,6 +851,7 @@ std::unique_ptr<TapeMount> Scheduler::getNextMount(const std::string &logicalLib
             } catch (...) {}
             schedulerDbTime = getMountInfoTime + queueTrimingTime + mountCreationTime + driveStatusSetTime;
             catalogueTime = getTapeInfoTime + getTapeForWriteTime;
+            
             params.add("tapepool", m->tapePool)
                   .add("vid", t.vid)
                   .add("mountType", common::dataStructures::toString(m->type))
diff --git a/scheduler/SchedulerDatabase.hpp b/scheduler/SchedulerDatabase.hpp
index 5bbc23ee71..d804d9079f 100644
--- a/scheduler/SchedulerDatabase.hpp
+++ b/scheduler/SchedulerDatabase.hpp
@@ -144,6 +144,8 @@ public:
       std::string vid;
       std::string logicalLibrary;
       std::string tapePool;
+      std::string vo;
+      std::string density;
       std::string drive;
       std::string host;
       uint64_t mountId;
@@ -298,6 +300,8 @@ public:
       std::string vid;
       std::string logicalLibrary;
       std::string tapePool;
+      std::string vo;
+      std::string density;
       std::string drive;
       std::string host;
       uint64_t mountId;
diff --git a/scheduler/TapeMount.hpp b/scheduler/TapeMount.hpp
index 61a0eda6c8..b00a0d86e9 100644
--- a/scheduler/TapeMount.hpp
+++ b/scheduler/TapeMount.hpp
@@ -59,6 +59,10 @@ namespace cta {
      * @return The mount transaction id.
      */
     virtual uint32_t getNbFiles() const = 0;
+    
+    virtual std::string getVo() const = 0;
+    
+    virtual std::string getDensity() const = 0;
 
     /**
      * Indicates that the mount was aborted.
diff --git a/scheduler/TapeMountDummy.hpp b/scheduler/TapeMountDummy.hpp
index c2b6b38e25..925ee3e824 100644
--- a/scheduler/TapeMountDummy.hpp
+++ b/scheduler/TapeMountDummy.hpp
@@ -41,6 +41,13 @@ class TapeMountDummy: public TapeMount {
   std::string getVid() const override {
     throw exception::Exception("In DummyTapeMount::getNbFiles() : not implemented");
   }
+  std::string getVo() const override{
+      throw exception::Exception("In DummyTapeMount::getVo() : not implemented");
+  }
+  
+  std::string getDensity() const override {
+      throw exception::Exception("In DummyTapeMount::getDensity() : not implemented");
+  }
   void setDriveStatus(cta::common::dataStructures::DriveStatus status) override {}
   void setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) override {};
 };
diff --git a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSession.cpp b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSession.cpp
index bf4b996c19..1df1baa447 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSession.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSession.cpp
@@ -233,7 +233,7 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
     
     TapeReadSingleThread trst(*drive, m_mc, tsr, m_volInfo, 
         m_castorConf.bulkRequestRecallMaxFiles,m_capUtils,rwd,lc,rrp,
-        m_castorConf.useLbp, m_castorConf.useRAO, m_castorConf.externalEncryptionKeyScript);
+        m_castorConf.useLbp, m_castorConf.useRAO, m_castorConf.externalEncryptionKeyScript,*retrieveMount);
     DiskWriteThreadPool dwtp(m_castorConf.nbDiskThreads,
         rrp,
         rwd,
@@ -315,7 +315,6 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
   if (!drive.get()) return MARK_DRIVE_AS_UP;
   // Once we got hold of the drive, we can run the session
   {
-    
     //dereferencing configLine is safe, because if configLine were not valid, 
     //then findDrive would have return NULL and we would have not end up there
     TapeServerReporter tsr(m_intialProcess, m_driveConfig, m_hostname,m_volInfo,lc);
@@ -335,7 +334,9 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
         m_castorConf.maxFilesBeforeFlush,
         m_castorConf.maxBytesBeforeFlush,
         m_castorConf.useLbp,
-        m_castorConf.externalEncryptionKeyScript);
+        m_castorConf.externalEncryptionKeyScript,
+        *archiveMount);
+ 
     DiskReadThreadPool drtp(m_castorConf.nbDiskThreads,
         m_castorConf.bulkRequestMigrationMaxFiles,
         m_castorConf.bulkRequestMigrationMaxBytes,
diff --git a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp
index 099b201fdf..71e3cd0061 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp
@@ -503,6 +503,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionGooddayRecall) {
   // 10) Check logs
   std::string logToCheck = logger.getLog();
   logToCheck += "";
+  std::cout<<"log to check = "<<logToCheck;
   ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" "
                                                "mountTotalCorrectedReadErrors=\"5\" mountTotalReadBytesProcessed=\"4096\" "
                                                "mountTotalUncorrectedReadErrors=\"1\" mountTotalNonMediumErrorCounts=\"2\""));
@@ -1686,6 +1687,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionTapeFullMigration) {
   // Check logs for drive statistics
   std::string logToCheck = logger.getLog();
   logToCheck += "";
+  std::cout<<logToCheck<<std::endl;
   ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" "
                                                "mountTotalCorrectedWriteErrors=\"5\" mountTotalUncorrectedWriteErrors=\"1\" " 
                                                "mountTotalWriteBytesProcessed=\"4096\" mountTotalNonMediumErrorCounts=\"2\""));
diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp
index 0de8c39fb2..7025bce15d 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp
@@ -37,14 +37,16 @@ castor::tape::tapeserver::daemon::TapeReadSingleThread::TapeReadSingleThread(
   RecallReportPacker &rrp,
   const bool useLbp,
   const bool useRAO,
-  const std::string & externalEncryptionKeyScript) :
+  const std::string & externalEncryptionKeyScript,
+  const cta::RetrieveMount& retrieveMount) :
   TapeSingleThreadInterface<TapeReadTask>(drive, mc, initialProcess, volInfo,
     capUtils, lc, externalEncryptionKeyScript),
   m_maxFilesRequest(maxFilesRequest),
   m_watchdog(watchdog),
   m_rrp(rrp),
   m_useLbp(useLbp),
-  m_useRAO(useRAO) {}
+  m_useRAO(useRAO),
+  m_retrieveMount(retrieveMount){}
 
 //------------------------------------------------------------------------------
 //TapeCleaning::~TapeCleaning()
@@ -175,6 +177,11 @@ castor::tape::tapeserver::daemon::TapeReadSingleThread::openReadSession() {
   try{
     std::unique_ptr<castor::tape::tapeFile::ReadSession> rs(
     new castor::tape::tapeFile::ReadSession(m_drive,m_volInfo, m_useLbp));
+    cta::log::ScopedParamContainer params(m_logContext);
+    params.add("vo",m_retrieveMount.getVo());
+    params.add("capacity",m_retrieveMount.getDensity());
+    params.add("tapePoolName",m_retrieveMount.getPoolName());
+    params.add("dgn",m_drive.config.logicalLibrary);
     m_logContext.log(cta::log::DEBUG, "Created tapeFile::ReadSession with success");
     
     return rs;
@@ -329,6 +336,10 @@ void castor::tape::tapeserver::daemon::TapeReadSingleThread::run() {
     // The session completed successfully, and the cleaner (unmount) executed
     // at the end of the previous block. Log the results.
     cta::log::ScopedParamContainer params(m_logContext);
+    params.add("vo",m_retrieveMount.getVo());
+    params.add("capacity",m_retrieveMount.getDensity());
+    params.add("tapePoolName",m_retrieveMount.getPoolName());
+    params.add("dgn",m_drive.config.logicalLibrary);
     params.add("status", "success");
     m_stats.totalTime = totalTimer.secs();
     logWithStat(cta::log::INFO, "Tape thread complete",
diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.hpp b/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.hpp
index f686faa39c..71bc25db50 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.hpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.hpp
@@ -68,7 +68,8 @@ public:
           RecallReportPacker &rrp,
           const bool useLbp,
           const bool useRAO,
-          const std::string & externalEncryptionKeyScript);
+          const std::string & externalEncryptionKeyScript,
+          const cta::RetrieveMount &retrieveMount);
    
   /**
    * Set the task injector. Has to be done that way (and not in the constructor)
@@ -152,11 +153,18 @@ private:
    * Access Order
    */
   bool m_useRAO;
+  
+  /**
+   * The retrieve mount object to get the VO, the tape pool and the density of the tape
+   * on which we are reading
+   */
+  const cta::RetrieveMount& m_retrieveMount;
+  
   /// Helper virtual function to access the watchdog from parent class
   virtual void countTapeLogError(const std::string & error) { 
     m_watchdog.addToErrorCount(error);
   }
-
+  
 protected:
   /**
    * Logs SCSI metrics for read session.
diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp
index cf7a9e12c0..3f21154796 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp
@@ -37,7 +37,8 @@ castor::tape::tapeserver::drive::DriveInterface & drive,
         MigrationReportPacker & repPacker,
         cta::server::ProcessCap &capUtils,
         uint64_t filesBeforeFlush, uint64_t bytesBeforeFlush,
-        const bool useLbp, const std::string & externalEncryptionKeyScript):
+        const bool useLbp, const std::string & externalEncryptionKeyScript,
+        const cta::ArchiveMount & archiveMount):
         TapeSingleThreadInterface<TapeWriteTask>(drive, mc, tsr, volInfo, 
           capUtils, lc, externalEncryptionKeyScript),
         m_filesBeforeFlush(filesBeforeFlush),
@@ -47,7 +48,8 @@ castor::tape::tapeserver::drive::DriveInterface & drive,
         m_lastFseq(-1),
         m_compress(true),
         m_useLbp(useLbp),
-        m_watchdog(mwd){}
+        m_watchdog(mwd),
+        m_archiveMount(archiveMount){}
 
 //------------------------------------------------------------------------------
 //TapeCleaning::~TapeCleaning()
@@ -163,7 +165,7 @@ castor::tape::tapeserver::daemon::TapeWriteSingleThread::openWriteSession() {
   ScopedParam sp[]={
     ScopedParam(m_logContext, Param("lastFseq", m_lastFseq)),
     ScopedParam(m_logContext, Param("compression", m_compress)),
-    ScopedParam(m_logContext, Param("useLbp", m_useLbp))
+    ScopedParam(m_logContext, Param("useLbp", m_useLbp)),
   };
   tape::utils::suppresUnusedVariable(sp);
   try {
@@ -171,6 +173,11 @@ castor::tape::tapeserver::daemon::TapeWriteSingleThread::openWriteSession() {
     new castor::tape::tapeFile::WriteSession(m_drive, m_volInfo, m_lastFseq,
       m_compress, m_useLbp)
     );
+    cta::log::ScopedParamContainer params(m_logContext);
+    params.add("vo",m_archiveMount.getVo());
+    params.add("capacity",m_archiveMount.getDensity());
+    params.add("tapePoolName",m_archiveMount.getPoolName());
+    params.add("dgn",m_drive.config.logicalLibrary);
     m_logContext.log(cta::log::INFO, "Tape Write session session successfully started");
   }
   catch (cta::exception::Exception & e) {
diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.hpp b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.hpp
index 9cdcc841e0..b92622b979 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.hpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.hpp
@@ -69,7 +69,8 @@ public:
     MigrationReportPacker & repPacker,
     cta::server::ProcessCap &capUtils,
     uint64_t filesBeforeFlush, uint64_t bytesBeforeFlush, const bool useLbp,
-    const std::string & externalEncryptionKeyScript);
+    const std::string & externalEncryptionKeyScript,
+    const cta::ArchiveMount & archiveMount);
   
   /**
    * 
@@ -189,6 +190,13 @@ private:
    */
   MigrationWatchDog & m_watchdog;
   
+  /**
+   * Reference to the archive mount object that
+   * stores the virtual organization (vo) of the tape, the tape pool in which the tape is
+   * and the density of the tape
+   */
+  const cta::ArchiveMount & m_archiveMount;
+  
 protected:
   /***
    * Helper virtual function to access the watchdog from parent class
diff --git a/tapeserver/daemon/DriveHandler.cpp b/tapeserver/daemon/DriveHandler.cpp
index b81e37be37..2e32f5e205 100644
--- a/tapeserver/daemon/DriveHandler.cpp
+++ b/tapeserver/daemon/DriveHandler.cpp
@@ -1080,7 +1080,6 @@ int DriveHandler::runChild() {
         return castor::tape::tapeserver::daemon::Session::MARK_DRIVE_AS_DOWN;
       }
     }
-  
     castor::tape::tapeserver::daemon::DataTransferSession dataTransferSession(
       cta::utils::getShortHostname(),
       lc.logger(),
-- 
GitLab