RAOAlgorithmFactoryFactory.cpp 3.02 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
/*
 * 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"
23
24
#include "NonConfigurableRAOAlgorithmFactory.hpp"
#include "ConfigurableRAOAlgorithmFactory.hpp"
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

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 {
40
    RAOParams raoData = m_raoManager.getRAODataConfig();
41
    //We will instanciate a CTA RAO algorithm
42
    RAOParams::RAOAlgorithmType raoAlgoType;
43
    try {
44
      raoAlgoType = raoData.getAlgorithmType();
45
46
47
48
    } 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"
49
        " in the tapeserver configuration is " + raoData.getRAOAlgorithmName() + " the available algorithm names are " + raoData.getCTARAOAlgorithmNameAvailable()
50
51
        + ". We will apply a linear algorithm instead.";
      m_lc.log(cta::log::WARNING, msg);
52
      raoAlgoType = RAOParams::RAOAlgorithmType::linear;
53
54
    }
    switch(raoAlgoType){
55
56
      case RAOParams::RAOAlgorithmType::linear:
      case RAOParams::RAOAlgorithmType::random:
57
      {
58
59
60
        ret.reset(new NonConfigurableRAOAlgorithmFactory(raoAlgoType));
        break;
      }
61
      case RAOParams::RAOAlgorithmType::sltf:
62
63
      { 
        ret.reset(new ConfigurableRAOAlgorithmFactory(m_raoManager.getDrive(),m_raoManager.getCatalogue(), raoData));
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        break;
      }
      default:
        break;
    }
  }
  return ret;
}


RAOAlgorithmFactoryFactory::~RAOAlgorithmFactoryFactory() {
}

}}}}