From e98578e450a6ce92b7d75ef8864faee38f17cf9c Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Mon, 9 Feb 2015 19:32:37 +0100
Subject: [PATCH] Continuing to implement the ClientApi::archive() method

---
 libs/client/ArchiveJob.cpp    | 42 ++++++++++++++++++++++++
 libs/client/ArchiveJob.hpp    | 60 +++++++++++++++++++++++++++++++++++
 libs/client/ClientAPI.hpp     | 14 ++++++++
 libs/client/MockClientAPI.cpp | 10 ++++++
 libs/client/MockClientAPI.hpp | 13 ++++++++
 5 files changed, 139 insertions(+)

diff --git a/libs/client/ArchiveJob.cpp b/libs/client/ArchiveJob.cpp
index 99f432fb27..51e173507e 100644
--- a/libs/client/ArchiveJob.cpp
+++ b/libs/client/ArchiveJob.cpp
@@ -1,9 +1,25 @@
 #include "ArchiveJob.hpp"
 
+//------------------------------------------------------------------------------
+// JobStateToStr
+//------------------------------------------------------------------------------
+const char *cta::ArchiveJob::JobStateToStr(const JobState enumValue) throw() {
+  switch(enumValue) {
+  case JOBSTATE_NONE   : return "NONE";
+  case JOBSTATE_PENDING: return "PENDING";
+  case JOBSTATE_SUCCESS: return "SUCCESS";
+  case JOBSTATE_ERROR  : return "ERROR";
+  default              : return "UNKNOWN";
+  }
+}
+
 //------------------------------------------------------------------------------
 // constructor
 //------------------------------------------------------------------------------
 cta::ArchiveJob::ArchiveJob():
+  m_state(JOBSTATE_NONE),
+  m_totalNbFileTransfers(0),
+  m_nbFailedFileTransfers(0),
   m_creationTime(time(NULL)) {
 }
 
@@ -12,9 +28,14 @@ cta::ArchiveJob::ArchiveJob():
 //------------------------------------------------------------------------------
 cta::ArchiveJob::ArchiveJob(
   const std::string &id,
+  const JobState state,
+  const uint32_t totalNbFileTransfers,
   const UserIdentity &creator,
   const std::string &comment):
   m_id(id),
+  m_state(state),
+  m_totalNbFileTransfers(totalNbFileTransfers),
+  m_nbFailedFileTransfers(0),
   m_creationTime(time(NULL)),
   m_creator(creator),
   m_comment(comment) {
@@ -27,6 +48,27 @@ const std::string &cta::ArchiveJob::getId() const throw() {
   return m_id;
 }
 
+//------------------------------------------------------------------------------
+// getState
+//------------------------------------------------------------------------------
+cta::ArchiveJob::JobState cta::ArchiveJob::getState() const throw() {
+  return m_state;
+} 
+
+//------------------------------------------------------------------------------
+// getTotalNbFileTransfers
+//------------------------------------------------------------------------------
+uint32_t cta::ArchiveJob::getTotalNbFileTransfers() const throw() {
+  return m_totalNbFileTransfers;
+}
+
+//------------------------------------------------------------------------------
+// getNbFailedFileTransfers
+//------------------------------------------------------------------------------
+uint32_t cta::ArchiveJob::getNbFailedFileTransfers() const throw() {
+  return m_nbFailedFileTransfers;
+}
+
 //------------------------------------------------------------------------------
 // getCreationTime
 //------------------------------------------------------------------------------
diff --git a/libs/client/ArchiveJob.hpp b/libs/client/ArchiveJob.hpp
index 40cc065765..24d400fe8d 100644
--- a/libs/client/ArchiveJob.hpp
+++ b/libs/client/ArchiveJob.hpp
@@ -2,6 +2,7 @@
 
 #include "UserIdentity.hpp"
 
+#include <stdint.h>
 #include <string>
 
 namespace cta {
@@ -12,6 +13,24 @@ namespace cta {
 class ArchiveJob {
 public:
 
+  /**
+   * Enumeration of the possible states of an archive job.
+   */
+  enum JobState {
+    JOBSTATE_NONE,
+    JOBSTATE_PENDING,
+    JOBSTATE_SUCCESS,
+    JOBSTATE_ERROR};
+
+  /**
+   * Thread safe method that returns the string representation of the
+   * enumeration value.
+   *
+   * @param enumValue The enumeration value.
+   * @return The string representation.
+   */
+  static const char *JobStateToStr(const JobState enumValue) throw();
+
   /**
    * Constructor.
    */
@@ -21,11 +40,16 @@ public:
    * Constructor.
    *
    * @param id The identification string of the archive job.
+   * @param state The state of the archive job.
+   * @param totalNbFileTransfers The total number of file transfers
+   * represented by the archive job.
    * @param creator The identity of the user that created the archive job.
    * @param comment The comment describing the archive job.
    */
   ArchiveJob(
     const std::string &id,
+    const JobState state,
+    const uint32_t totalNbFileTransfers,
     const UserIdentity &creator,
     const std::string &comment);
 
@@ -36,6 +60,27 @@ public:
    */
   const std::string &getId() const throw();
 
+  /**
+   * Returns the state of the archive job.
+   *
+   * @return The state of the archive job.
+   */
+  JobState getState() const throw();
+
+  /**
+   * Returns the total number of file transfers represented by the archive job.
+   *
+   * @return The total number of file transfers represented by the archive job.
+   */
+  uint32_t getTotalNbFileTransfers() const throw();
+
+  /**
+   * Returns the number of failed file transfers.
+   *
+   * @return The number of failed file transfers.
+   */
+  uint32_t getNbFailedFileTransfers() const throw();
+
   /**
    * Returns the time when the archive job was created.
    *
@@ -64,6 +109,21 @@ private:
    */
   std::string m_id;
 
+  /**
+   * The state of the archive job.
+   */
+  JobState m_state;
+
+  /**
+   * The total number of file transfers repesented by this archive job.
+   */
+  uint32_t m_totalNbFileTransfers;
+
+  /**
+   * The number of failed file transfers.
+   */
+  uint32_t m_nbFailedFileTransfers;
+
   /**
    * The time when the archive job was created.
    */
diff --git a/libs/client/ClientAPI.hpp b/libs/client/ClientAPI.hpp
index ce6747b173..a1060de792 100644
--- a/libs/client/ClientAPI.hpp
+++ b/libs/client/ClientAPI.hpp
@@ -1,5 +1,6 @@
 #pragma once
 
+#include "ArchiveJob.hpp"
 #include "DirectoryIterator.hpp"
 #include "MigrationRoute.hpp"
 #include "SecurityIdentity.hpp"
@@ -289,6 +290,19 @@ public:
     const std::list<std::string> &srcUrls,
     const std::string &dst) = 0;
 
+  /**
+   * Gets the current list of archive jobs associated with the specified tape
+   * pool.
+   *
+   * @param requester The identity of the user requesting the list.
+   * @param tapePoolName The name of the tape pool.
+   * @return The list of jobs sorted by creation time in ascending order
+   * (oldest first).
+   */
+  virtual std::list<ArchiveJob> getArchiveJobs(
+    const SecurityIdentity &requester,
+    const std::string &tapePoolName) = 0;
+
 }; // class ClientAPI
 
 } // namespace cta
diff --git a/libs/client/MockClientAPI.cpp b/libs/client/MockClientAPI.cpp
index 14795cc733..621b443a6b 100644
--- a/libs/client/MockClientAPI.cpp
+++ b/libs/client/MockClientAPI.cpp
@@ -681,3 +681,13 @@ void cta::MockClientAPI::checkUserIsAuthorisedToArchive(
   const FileSystemNode &dstDir) {
   // TO BE DONE
 }
+
+//------------------------------------------------------------------------------
+// getArchiveJobs
+//------------------------------------------------------------------------------
+std::list<cta::ArchiveJob> cta::MockClientAPI::getArchiveJobs(
+  const SecurityIdentity &requester,
+  const std::string &tapePoolName) {
+  std::list<cta::ArchiveJob> jobs;
+  return jobs;
+}
diff --git a/libs/client/MockClientAPI.hpp b/libs/client/MockClientAPI.hpp
index 2a7689ce9f..1098152601 100644
--- a/libs/client/MockClientAPI.hpp
+++ b/libs/client/MockClientAPI.hpp
@@ -291,6 +291,19 @@ public:
     const std::list<std::string> &srcUrls,
     const std::string &dst);
 
+  /**
+   * Gets the current list of archive jobs associated with the specified tape
+   * pool.
+   *
+   * @param requester The identity of the user requesting the list.
+   * @param tapePoolName The name of the tape pool.
+   * @return The list of jobs sorted by creation time in ascending order
+   * (oldest first).
+   */
+  std::list<ArchiveJob> getArchiveJobs(
+    const SecurityIdentity &requester,
+    const std::string &tapePoolName);
+
 protected:
 
   /**
-- 
GitLab