RAOParams.cpp 3.11 KB
Newer Older
1
/*
2
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2003-2021 CERN
4
5
6
7
 * @license        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.
8
 *
9
10
11
12
 *                 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.
13
 *
14
15
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
 */

18
#include "RAOParams.hpp"
19
20
21
22
23
#include "common/exception/Exception.hpp"
#include "common/utils/utils.hpp"

namespace castor { namespace tape { namespace tapeserver { namespace rao {
  
24
25
26
27
const std::map<std::string,RAOParams::RAOAlgorithmType> RAOParams::c_raoAlgoStringTypeMap = {
  {"linear",RAOParams::RAOAlgorithmType::linear},
  {"random",RAOParams::RAOAlgorithmType::random},
  {"sltf",RAOParams::RAOAlgorithmType::sltf}
28
29
};  

30
RAOParams::RAOParams():m_useRAO(false){}
31

32
RAOParams::RAOParams(const bool useRAO, const std::string& raoAlgorithmName, const std::string & raoAlgorithmOptions, const std::string & vid):m_useRAO(useRAO), m_raoAlgorithmName(raoAlgorithmName), 
33
34
35
36
    m_raoAlgorithmOptions(raoAlgorithmOptions), m_vid(vid) {

}

37
RAOParams::RAOParams(const RAOParams& other) {
38
39
40
41
42
43
44
45
  if(this != &other){
    m_useRAO = other.m_useRAO;
    m_raoAlgorithmName = other.m_raoAlgorithmName;
    m_raoAlgorithmOptions = other.m_raoAlgorithmOptions;
    m_vid = other.m_vid;
  }
}

46
RAOParams& RAOParams::operator=(const RAOParams& other) {
47
48
49
50
51
52
53
54
55
  if(this != &other){
    m_useRAO = other.m_useRAO;
    m_raoAlgorithmName = other.m_raoAlgorithmName;
    m_raoAlgorithmOptions = other.m_raoAlgorithmOptions;
    m_vid = other.m_vid;
  }
  return *this;
}

56
bool RAOParams::useRAO() const {
57
58
59
  return m_useRAO;
}

60
std::string RAOParams::getRAOAlgorithmName() const {
61
62
63
  return m_raoAlgorithmName;
}

64
RAOOptions RAOParams::getRAOAlgorithmOptions() const {
65
66
67
  return m_raoAlgorithmOptions;
}

68
void RAOParams::disableRAO(){
69
70
71
  m_useRAO = false;
}

72
RAOParams::RAOAlgorithmType RAOParams::getAlgorithmType() const {
73
74
75
76
77
78
79
  try {
    return c_raoAlgoStringTypeMap.at(m_raoAlgorithmName);  
  } catch (const std::out_of_range &){
    throw cta::exception::Exception("The algorithm name provided by the RAO configuration does not match any RAO algorithm type.");
  }
}

80
std::string RAOParams::getCTARAOAlgorithmNameAvailable() const {
81
82
83
84
85
86
87
88
89
90
91
  std::string ret;
  for(auto & kv: c_raoAlgoStringTypeMap){
    ret += kv.first + " ";
  }
  if(ret.size()){
    //remove last space
    ret.resize(ret.size()-1);
  }
  return ret;
}

92
std::string RAOParams::getMountedVid() const {
93
94
95
96
97
98
99
100
101
102
103
  if(m_vid.empty()){
    throw cta::exception::Exception("In RAOData::getMountedVid(), no mounted vid found.");
  }
  return m_vid;
}





}}}}