RAOManager.cpp 5.42 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
19
20
21
 */


#include "RAOManager.hpp"
#include "EnterpriseRAOAlgorithm.hpp"
#include "EnterpriseRAOAlgorithmFactory.hpp"
22
#include "NonConfigurableRAOAlgorithmFactory.hpp"
23
#include "RAOAlgorithmFactoryFactory.hpp"
24
#include "catalogue/Catalogue.hpp"
25
#include "LinearRAOAlgorithm.hpp"
26
#include "common/Timer.hpp"
27
28
29

namespace castor { namespace tape { namespace tapeserver { namespace rao {
  
30
31
RAOManager::RAOManager() {

32
}
33
  
34
RAOManager::RAOManager(const RAOParams & config, drive::DriveInterface * drive, cta::catalogue::Catalogue * catalogue):m_raoParams(config), 
35
  m_drive(drive), m_catalogue(catalogue){}
36
37
38

RAOManager::RAOManager(const RAOManager& manager){
  if(this != &manager){
39
    m_catalogue = manager.m_catalogue;
40
41
42
    m_drive = manager.m_drive;
    m_enterpriseRaoLimits = manager.m_enterpriseRaoLimits;
    m_hasUDS = manager.m_hasUDS;
43
    m_isDriveEnterpriseEnabled = manager.m_isDriveEnterpriseEnabled;
44
    m_maxFilesSupported = manager.m_maxFilesSupported;
45
    m_raoParams = manager.m_raoParams;
46
47
48
49
50
  }
}

RAOManager& RAOManager::operator=(const RAOManager& manager) {
  if(this != &manager){
51
    m_catalogue = manager.m_catalogue;
52
53
54
    m_drive = manager.m_drive;
    m_enterpriseRaoLimits = manager.m_enterpriseRaoLimits;
    m_hasUDS = manager.m_hasUDS;
55
    m_isDriveEnterpriseEnabled = manager.m_isDriveEnterpriseEnabled;
56
    m_maxFilesSupported = manager.m_maxFilesSupported;
57
    m_raoParams = manager.m_raoParams;
58
59
60
61
62
63
64
65
66
  }
  return *this;
}


RAOManager::~RAOManager() {
}

bool RAOManager::useRAO() const{
67
  return m_raoParams.useRAO();
68
69
70
71
72
73
74
75
76
77
78
79
80
81
}

bool RAOManager::hasUDS() const {
  return m_hasUDS;
}

bool RAOManager::isDriveEnterpriseEnabled() const {
  return m_isDriveEnterpriseEnabled;
}

castor::tape::tapeserver::drive::DriveInterface* RAOManager::getDrive() const {
  return m_drive;
}

82
83
84
85
cta::catalogue::Catalogue* RAOManager::getCatalogue() const {
  return m_catalogue;
}

86
87

void RAOManager::disableRAO(){
88
  m_raoParams.disableRAO();
89
90
91
92
93
94
95
96
97
98
99
100
101
}

void RAOManager::setEnterpriseRAOUdsLimits(const SCSI::Structures::RAO::udsLimits& raoLimits) {
  m_enterpriseRaoLimits = raoLimits;
  m_maxFilesSupported = raoLimits.maxSupported;
  m_hasUDS = true;
  m_isDriveEnterpriseEnabled = true;
}

cta::optional<uint64_t> RAOManager::getMaxFilesSupported() const{
  return m_maxFilesSupported;
}

102
RAOParams RAOManager::getRAOParams() const {
103
  return m_raoParams;
104
105
106
}

std::vector<uint64_t> RAOManager::queryRAO(const std::vector<std::unique_ptr<cta::RetrieveJob>> & jobs, cta::log::LogContext & lc){
107
  cta::utils::Timer totalTimer;
108
  RAOAlgorithmFactoryFactory raoAlgoFactoryFactory(*this,lc);
109
110
111
112
113
114
  std::unique_ptr<RAOAlgorithmFactory> raoAlgoFactory = raoAlgoFactoryFactory.createAlgorithmFactory();
  std::unique_ptr<RAOAlgorithm> raoAlgo;
  std::vector<uint64_t> ret;
  try {
    raoAlgo = raoAlgoFactory->createRAOAlgorithm();
  } catch(const cta::exception::Exception & ex){
115
    this->logWarningAfterRAOOperationFailed("In RAOManager::queryRAO(), failed to instanciate the RAO algorithm, will perform a linear RAO.",ex.getMessageValue(),lc);
116
117
118
119
120
    raoAlgo = raoAlgoFactory->createDefaultLinearAlgorithm();
  }
  try {
    ret = raoAlgo->performRAO(jobs);
  } catch (const cta::exception::Exception & ex) {
121
122
123
124
125
    this->logWarningAfterRAOOperationFailed("In RAOManager::queryRAO(), failed to perform the RAO algorithm, will perform a linear RAO.",ex.getMessageValue(),lc);
    raoAlgo = raoAlgoFactory->createDefaultLinearAlgorithm();
    ret = raoAlgo->performRAO(jobs);
  } catch(const std::exception &ex2){
    this->logWarningAfterRAOOperationFailed("In RAOManager::queryRAO(), failed to perform the RAO algorithm after a standard exception, will perform a linear RAO.",std::string(ex2.what()),lc);
126
127
128
    raoAlgo = raoAlgoFactory->createDefaultLinearAlgorithm();
    ret = raoAlgo->performRAO(jobs);
  }
129
130
  cta::log::ScopedParamContainer spc(lc);
  spc.add("executedRAOAlgorithm",raoAlgo->getName());
131
132
133
  cta::log::TimingList raoTimingList = raoAlgo->getRAOTimings();
  raoTimingList.insertAndReset("totalTime",totalTimer);
  raoTimingList.addToLog(spc);
134
  lc.log(cta::log::INFO, "In RAOManager::queryRAO(), successfully performed RAO.");
135
  return ret;
136
137
}

138
139
140
141
142
143
144
145
146
147
void RAOManager::logWarningAfterRAOOperationFailed(const std::string & warningMsg, const std::string & exceptionMsg, cta::log::LogContext & lc) const{
  cta::log::ScopedParamContainer spc(lc);
  spc.add("errorMsg",exceptionMsg)
     .add("raoAlgorithmName",m_raoParams.getRAOAlgorithmName())
     .add("raoAlgorithmOptions",m_raoParams.getRAOAlgorithmOptions().getOptionsString())
     .add("useRAO",m_raoParams.useRAO())
     .add("vid",m_raoParams.getMountedVid());
  lc.log(cta::log::WARNING,warningMsg);
}

148
149

}}}}