/*
* 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 .
*/
#include "RAOManager.hpp"
#include "EnterpriseRAOAlgorithm.hpp"
#include "EnterpriseRAOAlgorithmFactory.hpp"
#include "NonConfigurableRAOAlgorithmFactory.hpp"
#include "RAOAlgorithmFactoryFactory.hpp"
#include "catalogue/Catalogue.hpp"
#include "LinearRAOAlgorithm.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
RAOManager::RAOManager() {
}
RAOManager::RAOManager(const RAOParams & config, drive::DriveInterface * drive, cta::catalogue::Catalogue * catalogue):m_raoParams(config),
m_drive(drive), m_catalogue(catalogue){}
RAOManager::RAOManager(const RAOManager& manager){
if(this != &manager){
m_catalogue = manager.m_catalogue;
m_drive = manager.m_drive;
m_enterpriseRaoLimits = manager.m_enterpriseRaoLimits;
m_hasUDS = manager.m_hasUDS;
m_isDriveEnterpriseEnabled = manager.m_isDriveEnterpriseEnabled;
m_maxFilesSupported = manager.m_maxFilesSupported;
m_raoParams = manager.m_raoParams;
}
}
RAOManager& RAOManager::operator=(const RAOManager& manager) {
if(this != &manager){
m_catalogue = manager.m_catalogue;
m_drive = manager.m_drive;
m_enterpriseRaoLimits = manager.m_enterpriseRaoLimits;
m_hasUDS = manager.m_hasUDS;
m_isDriveEnterpriseEnabled = manager.m_isDriveEnterpriseEnabled;
m_maxFilesSupported = manager.m_maxFilesSupported;
m_raoParams = manager.m_raoParams;
}
return *this;
}
RAOManager::~RAOManager() {
}
bool RAOManager::useRAO() const{
return m_raoParams.useRAO();
}
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;
}
cta::catalogue::Catalogue* RAOManager::getCatalogue() const {
return m_catalogue;
}
void RAOManager::disableRAO(){
m_raoParams.disableRAO();
}
void RAOManager::setEnterpriseRAOUdsLimits(const SCSI::Structures::RAO::udsLimits& raoLimits) {
m_enterpriseRaoLimits = raoLimits;
m_maxFilesSupported = raoLimits.maxSupported;
m_hasUDS = true;
m_isDriveEnterpriseEnabled = true;
}
cta::optional RAOManager::getMaxFilesSupported() const{
return m_maxFilesSupported;
}
RAOParams RAOManager::getRAODataConfig() const {
return m_raoParams;
}
std::vector RAOManager::queryRAO(const std::vector> & jobs, cta::log::LogContext & lc){
RAOAlgorithmFactoryFactory raoAlgoFactoryFactory(*this,lc);
std::unique_ptr raoAlgoFactory = raoAlgoFactoryFactory.createAlgorithmFactory();
std::unique_ptr raoAlgo;
std::vector ret;
try {
raoAlgo = raoAlgoFactory->createRAOAlgorithm();
} catch(const cta::exception::Exception & ex){
cta::log::ScopedParamContainer spc(lc);
spc.add("errorMsg",ex.getMessageValue())
.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,"In RAOManager::queryRAO(), failed to instanciate the RAO algorithm, will perform a linear RAO.");
raoAlgo = raoAlgoFactory->createDefaultLinearAlgorithm();
}
try {
ret = raoAlgo->performRAO(jobs);
} catch (const cta::exception::Exception & ex) {
cta::log::ScopedParamContainer spc(lc);
spc.add("errorMsg",ex.getMessageValue())
.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,"In RAOManager::queryRAO(), failed to perform the RAO algorithm, will perform a linear RAO.");
raoAlgo = raoAlgoFactory->createDefaultLinearAlgorithm();
ret = raoAlgo->performRAO(jobs);
}
return ret;
}
}}}}