From 43dc6bcd333675fbc44adbb50ef4c3782bdec614 Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Wed, 1 Jul 2015 17:29:46 +0200
Subject: [PATCH] Added create delete and update storage class methods to
 NameServer

---
 nameserver/MockNameServer.cpp |  24 ++++++
 nameserver/MockNameServer.hpp |   6 ++
 nameserver/NameServer.hpp     |  41 ++++++++++
 scheduler/MountRequest.cpp    |  49 ++++++++++++
 scheduler/MountRequest.hpp    |  85 ++++++++++++++++++++
 scheduler/Scheduler.cpp       |   3 +-
 scheduler/Scheduler.hpp       | 146 +++++++++++++++++-----------------
 scheduler/SchedulerTest.cpp   |   3 +-
 scheduler/TapeSession.cpp     |  25 ++++++
 scheduler/TapeSession.hpp     |  36 +++++++++
 10 files changed, 342 insertions(+), 76 deletions(-)
 create mode 100644 scheduler/MountRequest.cpp
 create mode 100644 scheduler/MountRequest.hpp
 create mode 100644 scheduler/TapeSession.cpp
 create mode 100644 scheduler/TapeSession.hpp

diff --git a/nameserver/MockNameServer.cpp b/nameserver/MockNameServer.cpp
index 5fd321dcc4..64a51b1e51 100644
--- a/nameserver/MockNameServer.cpp
+++ b/nameserver/MockNameServer.cpp
@@ -108,6 +108,30 @@ bool cta::MockNameServer::dirExists(const SecurityIdentity &requester,
   return true;
 }
 
+//------------------------------------------------------------------------------
+// createStorageClass
+//------------------------------------------------------------------------------
+void cta::MockNameServer::createStorageClass(const SecurityIdentity &requester,
+  const std::string &name, const uint16_t nbCopies) {
+  throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
+}
+  
+//------------------------------------------------------------------------------
+// deleteStorageClass
+//------------------------------------------------------------------------------
+void cta::MockNameServer::deleteStorageClass(const SecurityIdentity &requester,
+  const std::string &name) {
+  throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
+}
+ 
+//------------------------------------------------------------------------------
+// updateStorageClass
+//------------------------------------------------------------------------------
+void cta::MockNameServer::updateStorageClass(const SecurityIdentity &requester,
+  const std::string &name, const uint16_t nbCopies) {
+  throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
+}
+
 //------------------------------------------------------------------------------
 // assertStorageClassIsNotInUse
 //------------------------------------------------------------------------------
diff --git a/nameserver/MockNameServer.hpp b/nameserver/MockNameServer.hpp
index 323b9b39bf..425e18a339 100644
--- a/nameserver/MockNameServer.hpp
+++ b/nameserver/MockNameServer.hpp
@@ -45,6 +45,12 @@ public:
    * Destructor.
    */
   ~MockNameServer() throw();  
+
+  void createStorageClass(const SecurityIdentity &requester, const std::string &name, const uint16_t nbCopies); 
+
+  void deleteStorageClass(const SecurityIdentity &requester, const std::string &name);
+
+  void updateStorageClass(const SecurityIdentity &requester, const std::string &name, const uint16_t nbCopies);
   
   void setDirStorageClass(const SecurityIdentity &requester, const std::string &path, const std::string &storageClassName);
   
diff --git a/nameserver/NameServer.hpp b/nameserver/NameServer.hpp
index a0ed26b774..be9a6f6214 100644
--- a/nameserver/NameServer.hpp
+++ b/nameserver/NameServer.hpp
@@ -97,6 +97,47 @@ public:
     const SecurityIdentity &requester,
     const std::string &path) const = 0;
 
+  /**
+   * Creates the specified storage class.
+   *
+   * @param requester The identity of the user requesting the creation of the
+   * storage class.
+   * @param name The name of the storage class.
+   * @param nbCopies The number of copies a file associated with this storage
+   * class should have on tape.
+   * @param comment The comment describing the storage class.
+   */
+  virtual void createStorageClass(
+    const SecurityIdentity &requester,
+    const std::string &name,
+    const uint16_t nbCopies) = 0;
+
+  /**
+   * Deletes the specified storage class.
+   *
+   * @param requester The identity of the user requesting the deletion of the
+   * storage class.
+   * @param name The name of the storage class.
+   */
+  virtual void deleteStorageClass(
+    const SecurityIdentity &requester,
+    const std::string &name) = 0;
+
+  /**
+   * Updates the specified storage class with the specified number of tape
+   * copies.
+   *
+   * @param requester The identity of the user requesting the deletion of the
+   * storage class.
+   * @param name The name of the storage class.
+   * @param nbCopies The number of copies a file associated with this storage
+   * class should have on tape.
+   */
+  virtual void updateStorageClass(
+    const SecurityIdentity &requester,
+    const std::string &name,
+    const uint16_t nbCopies) = 0;
+
   /**
    * Sets the storage class of the specified directory to the specified value.
    *
diff --git a/scheduler/MountRequest.cpp b/scheduler/MountRequest.cpp
new file mode 100644
index 0000000000..b28a334e39
--- /dev/null
+++ b/scheduler/MountRequest.cpp
@@ -0,0 +1,49 @@
+/*
+ * The CERN Tape Archive (CTA) project
+ * Copyright (C) 2015  CERN
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "scheduler/MountRequest.hpp"
+
+//------------------------------------------------------------------------------
+// transferTypeToStr
+//------------------------------------------------------------------------------
+const char *cta::MountRequest::transferTypeToStr(const EntryType enumValue)
+  throw() {
+  switch(enumValue) {
+  case TRANSFERTYPE_NONE     : return "NONE";
+  case TRANSFERTYPE_ARCHIVAL : return "ARCHIVAL";
+  case TRANSFERTYPE_RETRIEVAL: return "RETRIEVAL";
+  default                    : return "UNKNOWN";
+}
+
+//------------------------------------------------------------------------------
+// constructor
+//------------------------------------------------------------------------------
+cta::MountRequest::MountRequest(): m_transferType(TRANSFERTYPE_NONE) {
+}
+
+//------------------------------------------------------------------------------
+// constructor
+//------------------------------------------------------------------------------
+cta::MountRequest::MountRequest(
+  const std::string &mountId,
+  const std::string &vid,
+  const TransferType transferType):
+  mountId(mountId),
+  vid(vid),
+  transferType(transferType) {
+}
diff --git a/scheduler/MountRequest.hpp b/scheduler/MountRequest.hpp
new file mode 100644
index 0000000000..f7c9b62308
--- /dev/null
+++ b/scheduler/MountRequest.hpp
@@ -0,0 +1,85 @@
+/*
+ * The CERN Tape Archive (CTA) project
+ * Copyright (C) 2015  CERN
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace cta {
+
+/**
+ * A request to mount a tape in a tape drive in order to start a data transfer
+ * session.
+ */
+struct MountRequest {
+
+  /**
+   * Enumeration of the possible transfer types for a tape mount, either all
+   * archivals or all retrievals.
+   */
+  enum TransferType {
+    TRANSFERTYPE_NONE,
+    TRANSFERTYPE_ARCHIVAL,
+    TRANSFERTYPE_RETRIEVAL
+  };
+
+  /**
+   * Thread safe method that returns the string representation of the specified
+   * enumeration value.
+   *
+   * @param enumValue The integer value of the type.
+   * @return The string representation.
+   */
+  static const char *transferTypeToStr(const TransferType enumValue) throw();
+
+  /**
+   * Constructor.
+   */
+  MountRequest();
+
+  /**
+   * Constructor.
+   *
+   * @param mountId The identifier of the mount.
+   * @param vid The volume identifier of the tape to be mounted.
+   * @param transferType The type of transfers to be carried out, either
+   * all archivals or all retrievals.
+   */
+  MountRequest(
+    const std::string &mountId,
+    const std::string &vid,
+    const TransferType transferType);
+
+  /**
+   * The identifier of the mount.
+   */
+  std::string mountId;
+
+  /**
+   * The volume identifier of the tape to be mounted.
+   */
+  std::string vid;
+
+  /**
+   * The type of transfers to be carried out, either archivals or retrievals.
+   */
+  TransferType transferType;
+
+}; // class MountRequest
+
+} // namespace cta
diff --git a/scheduler/Scheduler.cpp b/scheduler/Scheduler.cpp
index a020efa25f..e2a9a0d720 100644
--- a/scheduler/Scheduler.cpp
+++ b/scheduler/Scheduler.cpp
@@ -705,7 +705,8 @@ void cta::Scheduler::queueRetrieveRequest(
 //------------------------------------------------------------------------------
 // getNextMount
 //------------------------------------------------------------------------------
-cta::TapeMount *cta::Scheduler::getNextMount(const std::string &driveName) {
+cta::MountRequest *cta::Scheduler::getNextMount(
+  const std::string &logicalLibraryName) {
   return NULL;
 }
 
diff --git a/scheduler/Scheduler.hpp b/scheduler/Scheduler.hpp
index 4b4e405d08..70a4f41c8b 100644
--- a/scheduler/Scheduler.hpp
+++ b/scheduler/Scheduler.hpp
@@ -47,7 +47,6 @@ class SchedulerDatabase;
 class SecurityIdentity;
 class StorageClass;
 class Tape;
-class TapeMount;
 class TapePool;
 class UserIdentity;
 
@@ -622,6 +621,78 @@ public:
     const std::list<std::string> &archiveFiles,
     const std::string &remoteFileOrDir);
 
+  /**
+   * Returns the next tape mount for the specified logical liubrary.
+   *
+   * @param logicalLibraryName The name of the logical library.
+   * @return The next tape mount or NULL if there is currently no work to bei
+   * done.
+   */
+  MountRequest *getNextMount(const std::string &logicalLibraryName);
+
+  /**
+   * Notifies the scheduler that the specified tape mount is over.
+   *
+   * @param mountId The identifier of the tape mount.
+   */
+  void finishedMount(const std::string &mountId);
+
+  /**
+   * Returns the next file transfer to be carried out for the specified tape
+   * mount or NULL if there is no more work to be done.
+   *
+   * @param mountId The identifier of the tape mount.
+   * @return The next file transfer to be carried out for the specified tape
+   * mount or NULL if there is no more work to be done.
+   */
+  ArchivalFileTransfer *getNextArchival(const std::string &mountId);
+
+  /**
+   * Notifies the scheduler that the specified file transfer has been completed
+   * successfully.
+   *
+   * @param transferId The identifier of the file transfer.
+   */
+  void archivalSuccessful(const std::string &transferId);
+
+  /**
+   * Notifies the scheduler that the specified file transfer has failed.
+   *
+   * @param transferId The identifier of the file transfer.
+   * @param failureType The type of failure.
+   * @param errorMessage Human readable description of the failure.
+   */
+  void archivalFailed(const std::string &transferId,
+    const TransferFailure failureType, const std::string &errorMessage);
+
+  /**
+   * Returns the next file transfer to be carried out for the specified tape
+   * mount or NULL if there is no more work to be done.
+   *
+   * @param mountId The identifier of the tape mount.
+   * @return The next file transfer to be carried out for the specified tape
+   * mount or NULL if there is no more work to be done.
+   */
+  RetrievalFileTransfer *getNextRetrieval(const std::string &mountId);
+
+  /**
+   * Notifies the scheduler that the specified file transfer has been completed
+   * successfully.
+   *
+   * @param transferId The identifier of the file transfer.
+   */
+  void retrievalSucceeded(const std::string &transferId);
+
+  /**
+   * Notifies the scheduler that the specified file transfer has failed.
+   *
+   * @param transferId The identifier of the file transfer.
+   * @param failureType The type of failure.
+   * @param errorMessage Human readable description of the failure.
+   */
+  void retrievalFailed(const std::string &transferId,
+    const TransferFailure failureType, const std::string &errorMessage);
+
 private:
 
   /**
@@ -733,79 +804,6 @@ private:
   std::map<uint16_t, std::string> createCopyNbToPoolMap(
     const std::list<ArchivalRoute> &routes) const;
 
-  /**
-   * Returns the next tape mount for the specified tape drive or NULL if there
-   * is currently no work to be done.
-   *
-   * @param driveName The name of the tape drive.
-   * @return The next tape mount for the specified tape drive or NULL if there
-   * is currently no work to be done.
-   */
-  TapeMount *getNextMount(const std::string &driveName);
-
-  /**
-   * Notifies the scheduler that the specified tape mount is over.
-   *
-   * @param mountId The identifier of the tape mount.
-   */
-  void finishedMount(const std::string &mountId);
-
-  /**
-   * Returns the next file transfer to be carried out for the specified tape
-   * mount or NULL if there is no more work to be done.
-   *
-   * @param mountId The identifier of the tape mount.
-   * @return The next file transfer to be carried out for the specified tape
-   * mount or NULL if there is no more work to be done.
-   */
-  ArchivalFileTransfer *getNextArchival(const std::string &mountId);
-
-  /**
-   * Notifies the scheduler that the specified file transfer has been completed
-   * successfully.
-   *
-   * @param transferId The identifier of the file transfer.
-   */
-  void archivalSuccessful(const std::string &transferId);
-
-  /**
-   * Notifies the scheduler that the specified file transfer has failed.
-   *
-   * @param transferId The identifier of the file transfer.
-   * @param failureType The type of failure.
-   * @param errorMessage Human readable description of the failure.
-   */
-  void archivalFailed(const std::string &transferId,
-    const TransferFailure failureType, const std::string &errorMessage);
-
-  /**
-   * Returns the next file transfer to be carried out for the specified tape
-   * mount or NULL if there is no more work to be done.
-   *
-   * @param mountId The identifier of the tape mount.
-   * @return The next file transfer to be carried out for the specified tape
-   * mount or NULL if there is no more work to be done.
-   */
-  RetrievalFileTransfer *getNextRetrieval(const std::string &mountId);
-
-  /**
-   * Notifies the scheduler that the specified file transfer has been completed
-   * successfully.
-   *
-   * @param transferId The identifier of the file transfer.
-   */
-  void retrievalSucceeded(const std::string &transferId);
-
-  /**
-   * Notifies the scheduler that the specified file transfer has failed.
-   *
-   * @param transferId The identifier of the file transfer.
-   * @param failureType The type of failure.
-   * @param errorMessage Human readable description of the failure.
-   */
-  void retrievalFailed(const std::string &transferId,
-    const TransferFailure failureType, const std::string &errorMessage);
-
 }; // class Scheduler
 
 } // namespace cta
diff --git a/scheduler/SchedulerTest.cpp b/scheduler/SchedulerTest.cpp
index 48ed5bc266..0d5a9dad5c 100644
--- a/scheduler/SchedulerTest.cpp
+++ b/scheduler/SchedulerTest.cpp
@@ -28,6 +28,7 @@
 #include "scheduler/ArchiveToTapeCopyRequest.hpp"
 #include "scheduler/LogicalLibrary.hpp"
 #include "scheduler/MockSchedulerDatabaseFactory.hpp"
+#include "scheduler/MountRequest.hpp"
 #include "scheduler/Scheduler.hpp"
 #include "scheduler/SchedulerDatabase.hpp"
 #include "scheduler/SecurityIdentity.hpp"
@@ -2377,7 +2378,7 @@ TEST_P(SchedulerTest, archive_and_retrieve_new_file) {
   }
 
   // Emulate a tape server by ask for a mount and then a file
-
+  //const MountRequest *mount = scheduler.getNextMount(libraryName);
 
   {
     std::list<std::string> archiveFiles;
diff --git a/scheduler/TapeSession.cpp b/scheduler/TapeSession.cpp
new file mode 100644
index 0000000000..e7c807974b
--- /dev/null
+++ b/scheduler/TapeSession.cpp
@@ -0,0 +1,25 @@
+/*
+ * The CERN Tape Archive (CTA) project
+ * Copyright (C) 2015  CERN
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "scheduler/TapeSession.hpp"
+
+//------------------------------------------------------------------------------
+// constructor
+//------------------------------------------------------------------------------
+cta::TapeSession::TapeSession() {
+}
diff --git a/scheduler/TapeSession.hpp b/scheduler/TapeSession.hpp
new file mode 100644
index 0000000000..c31531db9b
--- /dev/null
+++ b/scheduler/TapeSession.hpp
@@ -0,0 +1,36 @@
+/*
+ * The CERN Tape Archive (CTA) project
+ * Copyright (C) 2015  CERN
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+namespace cta {
+
+/**
+ * The description of a tape session.
+ */
+class TapeSession {
+public:
+
+  /**
+   * Constructor.
+   */
+  TapeSession();
+
+}; // class TapeSession
+
+} // namespace cta
-- 
GitLab