RAOAlgorithmFactoryFactory.cpp 2.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2019  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 "RAOAlgorithmFactoryFactory.hpp"
#include "common/log/LogContext.hpp"
#include "EnterpriseRAOAlgorithmFactory.hpp"
#include "NoParamRAOAlgorithmFactory.hpp"

namespace castor { namespace tape { namespace tapeserver { namespace rao {

RAOAlgorithmFactoryFactory::RAOAlgorithmFactoryFactory(RAOManager & raoManager, cta::log::LogContext & lc):m_raoManager(raoManager), m_lc(lc) {
}

std::unique_ptr<RAOAlgorithmFactory> RAOAlgorithmFactoryFactory::createAlgorithmFactory() {
  std::unique_ptr<RAOAlgorithmFactory> ret;
  auto maxFilesSupported = m_raoManager.getMaxFilesSupported();
  if(m_raoManager.isDriveEnterpriseEnabled()) {
    if(m_raoManager.hasUDS() && maxFilesSupported){
      //We successfully queried the max limits UDS of the drive, we then return an Enterprise RAO factory
      ret.reset(new EnterpriseRAOAlgorithmFactory(m_raoManager.getDrive(),maxFilesSupported.value()));
    } 
  } else {
    //We will instanciate a CTA RAO algorithm
    RAOConfig::RAOAlgorithmType raoAlgoType;
    try {
      raoAlgoType = m_raoManager.getConfig().getAlgorithmType();
    } catch (const cta::exception::Exception & ex) {
      //We failed to determine the RAOAlgorithmType, we use the linear algorithm by default
      //log a warning
      std::string msg = "In RAOAlgorithmFactoryFactory::createAlgorithmFactory(), unable to determine the RAO algorithm to use, the algorithm name provided"
        " in the tapeserver configuration is " + m_raoManager.getConfig().getRAOAlgorithmName() + " the available algorithm names are " + m_raoManager.getConfig().getCTARAOAlgorithmNameAvailable()
        + ". We will apply a linear algorithm instead.";
      m_lc.log(cta::log::WARNING, msg);
      raoAlgoType = RAOConfig::RAOAlgorithmType::linear;
    }
    switch(raoAlgoType){
      case RAOConfig::RAOAlgorithmType::linear:
      case RAOConfig::RAOAlgorithmType::random:
      {
        ret.reset(new NoParamRAOAlgorithmFactory(raoAlgoType));
        break;
      }
      case RAOConfig::RAOAlgorithmType::sltf:
      default:
        break;
    }
  }
  return ret;
}


RAOAlgorithmFactoryFactory::~RAOAlgorithmFactoryFactory() {
}

}}}}