Commit 29d241ec authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[rao_lto] WIP, added files position estimator structure, catalogue getMediaTypeByVid method

parent d0038957
......@@ -351,6 +351,14 @@ public:
* @return All tape media types.
*/
virtual std::list<MediaTypeWithLogs> getMediaTypes() const = 0;
/**
* Return the media type associated to the tape corresponding to the
* vid passed in parameter
* @param vid the vid of the tape to return its media type
* @return the media type associated to the tape corresponding to the vid passed in parameter
*/
virtual MediaType getMediaTypeByVid(const std::string & vid) const = 0;
/**
* Modifies the name of the specified tape media type.
......
......@@ -175,6 +175,10 @@ public:
std::list<MediaTypeWithLogs> getMediaTypes() const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getMediaTypes();}, m_maxTriesToConnect);
}
MediaType getMediaTypeByVid(const std::string & vid) const override {
return retryOnLostConnection(m_log,[&]{return m_catalogue->getMediaTypeByVid(vid);}, m_maxTriesToConnect);
}
void modifyMediaTypeName(const common::dataStructures::SecurityIdentity &admin, const std::string &currentName, const std::string &newName) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyMediaTypeName(admin, currentName, newName);}, m_maxTriesToConnect);
......
......@@ -1682,6 +1682,42 @@ TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeComment_nonExistentMediaType)
ASSERT_THROW(m_catalogue->modifyMediaTypeComment(m_admin, name, comment), exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, getMediaTypeByVid_nonExistentTape) {
using namespace cta;
ASSERT_THROW(m_catalogue->getMediaTypeByVid("DOES_NOT_EXIST"),exception::Exception);
}
TEST_P(cta_catalogue_CatalogueTest, getMediaTypeByVid) {
using namespace cta;
using namespace cta;
const bool logicalLibraryIsDisabled= false;
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
m_catalogue->createMediaType(m_admin, m_mediaType);
m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
m_catalogue->createVirtualOrganization(m_admin, m_vo);
m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
m_catalogue->createTape(m_admin, m_tape1);
auto tapeMediaType = m_catalogue->getMediaTypeByVid(m_tape1.vid);
ASSERT_EQ(m_mediaType.name, tapeMediaType.name);
ASSERT_EQ(m_mediaType.capacityInBytes, tapeMediaType.capacityInBytes);
ASSERT_EQ(m_mediaType.cartridge, tapeMediaType.cartridge);
ASSERT_EQ(m_mediaType.comment, tapeMediaType.comment);
ASSERT_EQ(m_mediaType.maxLPos, tapeMediaType.maxLPos);
ASSERT_EQ(m_mediaType.minLPos, tapeMediaType.minLPos);
ASSERT_EQ(m_mediaType.nbWraps, tapeMediaType.nbWraps);
ASSERT_EQ(m_mediaType.primaryDensityCode, tapeMediaType.primaryDensityCode);
ASSERT_EQ(m_mediaType.secondaryDensityCode, tapeMediaType.secondaryDensityCode);
}
TEST_P(cta_catalogue_CatalogueTest, createTapePool) {
using namespace cta;
......
......@@ -46,6 +46,7 @@ public:
void createMediaType(const common::dataStructures::SecurityIdentity &admin, const MediaType &mediaType) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void deleteMediaType(const std::string &name) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
std::list<MediaTypeWithLogs> getMediaTypes() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
MediaType getMediaTypeByVid(const std::string & vid) const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyMediaTypeName(const common::dataStructures::SecurityIdentity &admin, const std::string &currentName, const std::string &newName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyMediaTypeCartridge(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &cartridge) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyMediaTypeCapacityInBytes(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t capacityInBytes) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -1263,6 +1263,56 @@ std::list<MediaTypeWithLogs> RdbmsCatalogue::getMediaTypes() const {
}
}
MediaType RdbmsCatalogue::getMediaTypeByVid(const std::string& vid) const {
try {
std::list<MediaTypeWithLogs> mediaTypes;
const char *const sql =
"SELECT" "\n"
"MEDIA_TYPE_NAME AS MEDIA_TYPE_NAME," "\n"
"CARTRIDGE AS CARTRIDGE," "\n"
"CAPACITY_IN_BYTES AS CAPACITY_IN_BYTES," "\n"
"PRIMARY_DENSITY_CODE AS PRIMARY_DENSITY_CODE," "\n"
"SECONDARY_DENSITY_CODE AS SECONDARY_DENSITY_CODE," "\n"
"NB_WRAPS AS NB_WRAPS," "\n"
"MIN_LPOS AS MIN_LPOS," "\n"
"MAX_LPOS AS MAX_LPOS," "\n"
"MEDIA_TYPE.USER_COMMENT AS USER_COMMENT " "\n"
"FROM" "\n"
"MEDIA_TYPE " "\n"
"INNER JOIN TAPE " "\n"
"ON MEDIA_TYPE.MEDIA_TYPE_ID = TAPE.MEDIA_TYPE_ID " "\n"
"WHERE " "\n"
"TAPE.VID = :VID" "\n";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql);
stmt.bindString(":VID",vid);
auto rset = stmt.executeQuery();
if(rset.next()){
MediaType mediaType;
mediaType.name = rset.columnString("MEDIA_TYPE_NAME");
mediaType.cartridge = rset.columnString("CARTRIDGE");
mediaType.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES");
mediaType.primaryDensityCode = rset.columnOptionalUint8("PRIMARY_DENSITY_CODE");
mediaType.secondaryDensityCode = rset.columnOptionalUint8("SECONDARY_DENSITY_CODE");
mediaType.nbWraps = rset.columnOptionalUint32("NB_WRAPS");
mediaType.minLPos = rset.columnOptionalUint64("MIN_LPOS");
mediaType.maxLPos = rset.columnOptionalUint64("MAX_LPOS");
mediaType.comment = rset.columnString("USER_COMMENT");
return mediaType;
} else {
throw exception::Exception("The tape vid "+vid+" does not exist.");
}
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// modifyMediaTypeName
//------------------------------------------------------------------------------
......
......@@ -302,6 +302,15 @@ public:
* @return All tape media types.
*/
std::list<MediaTypeWithLogs> getMediaTypes() const override;
/**
* Return the media type associated to the tape corresponding to the
* vid passed in parameter
*
* @param vid the vid of the tape to return its media type
* @return the media type associated to the tape corresponding to the vid passed in parameter
*/
MediaType getMediaTypeByVid(const std::string & vid) const override;
/**
* Modifies the name of the specified tape media type.
......
......@@ -1940,4 +1940,8 @@ reportRetrieveJobsBatch(std::list<std::unique_ptr<RetrieveJob>> & retrieveJobsBa
lc.log(log::ERR, "In Scheduler::reportRetrieveJobsBatch(): reported a batch of retrieve jobs.");
}
cta::catalogue::Catalogue & Scheduler::getCatalogue(){
return m_catalogue;
}
} // namespace cta
......@@ -438,6 +438,8 @@ public:
double getRepackRequestExpansionTimeLimit() const;
cta::catalogue::Catalogue & getCatalogue();
private:
/**
......
......@@ -4,7 +4,7 @@ include_directories(${PROJECT_SOURCE_DIR}/tapeserver)
include_directories(${PROJECT_SOURCE_DIR}/tapeserver/h)
set(CTARAO_LIBRARY_SRCS
RAOConfig.cpp
RAOConfigurationData.cpp
RAOManager.cpp
RAOAlgorithm.cpp
EnterpriseRAOAlgorithm.cpp
......@@ -12,8 +12,16 @@ set(CTARAO_LIBRARY_SRCS
EnterpriseRAOAlgorithmFactory.cpp
LinearRAOAlgorithm.cpp
RandomRAOAlgorithm.cpp
NoParamRAOAlgorithmFactory.cpp
NonConfigurableRAOAlgorithmFactory.cpp
ConfigurableRAOAlgorithmFactory.cpp
RAOAlgorithmFactoryFactory.cpp
SLTFRAOAlgorithm.cpp
RAOOptions.cpp
CostHeuristic.cpp
FilePosition.cpp
Position.cpp
FilePositionEstimator.cpp
InterpolationFilePositionEstimator.cpp
)
add_library (ctarao SHARED
......
/*
* 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 "ConfigurableRAOAlgorithmFactory.hpp"
#include "SLTFRAOAlgorithm.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
ConfigurableRAOAlgorithmFactory::ConfigurableRAOAlgorithmFactory(drive::DriveInterface * drive, cta::catalogue::Catalogue * catalogue, const RAOConfigurationData & raoConfigurationData):m_drive(drive),
m_catalogue(catalogue), m_raoConfigurationData(raoConfigurationData){}
ConfigurableRAOAlgorithmFactory::~ConfigurableRAOAlgorithmFactory() {
}
std::unique_ptr<RAOAlgorithm> ConfigurableRAOAlgorithmFactory::createRAOAlgorithm() {
std::unique_ptr<RAOAlgorithm> ret;
switch(m_raoConfigurationData.getAlgorithmType()){
case RAOConfigurationData::RAOAlgorithmType::sltf:{
SLTFRAOAlgorithm::Builder builder(m_raoConfigurationData,m_drive,m_catalogue);
ret.reset(builder.build().release());
break;
}
default:
throw cta::exception::Exception("Unknown type of ConfigurableRAOAlgorithm. Existing types are : sltf");
break;
}
return ret;
}
}}}}
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include "RAOConfigurationData.hpp"
#include "RAOAlgorithmFactory.hpp"
#include "castor/tape/tapeserver/drive/DriveInterface.hpp"
#include "RAOManager.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class ConfigurableRAOAlgorithmFactory : public RAOAlgorithmFactory{
public:
ConfigurableRAOAlgorithmFactory(drive::DriveInterface * drive, cta::catalogue::Catalogue * catalogue, const RAOConfigurationData & raoConfigurationData);
std::unique_ptr<RAOAlgorithm> createRAOAlgorithm() override;
virtual ~ConfigurableRAOAlgorithmFactory();
private:
drive::DriveInterface * m_drive;
cta::catalogue::Catalogue * m_catalogue;
RAOConfigurationData m_raoConfigurationData;
};
}}}}
/*
* 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 "CostHeuristic.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
CostHeuristic::CostHeuristic() {
}
CostHeuristic::CostHeuristic(const CostHeuristic& orig) {
}
CostHeuristic::~CostHeuristic() {
}
}}}}
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class CostHeuristic {
public:
CostHeuristic();
CostHeuristic(const CostHeuristic& orig);
virtual ~CostHeuristic();
private:
};
}}}}
\ No newline at end of file
/*
* 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 "FilePosition.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
FilePosition::FilePosition() {
}
FilePosition::~FilePosition() {
}
void FilePosition::setStartPosition(const Position & startPosition) {
m_startPosition = startPosition;
}
void FilePosition::setEndPosition(const Position& endPosition) {
m_endPosition = endPosition;
}
Position FilePosition::getStartPosition() const {
return m_startPosition;
}
Position FilePosition::getEndPosition() const {
return m_endPosition;
}
}}}}
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include "Position.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class FilePosition {
public:
FilePosition();
void setStartPosition(const Position & startPosition);
void setEndPosition(const Position & endPosition);
Position getStartPosition() const;
Position getEndPosition() const;
virtual ~FilePosition();
private:
Position m_startPosition;
Position m_endPosition;
};
}}}}
\ No newline at end of file
/*
* 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 "FilePositionEstimator.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
FilePositionEstimator::FilePositionEstimator() {
}
FilePositionEstimator::~FilePositionEstimator() {
}
}}}}
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include "FilePosition.hpp"
#include "scheduler/RetrieveJob.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class FilePositionEstimator {
public:
FilePositionEstimator();
virtual FilePosition getFilePosition(const cta::RetrieveJob & job) const = 0;
virtual ~FilePositionEstimator();
private:
};
}}}}
\ No newline at end of file
/*
* 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 "InterpolationFilePositionEstimator.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
InterpolationFilePositionEstimator::InterpolationFilePositionEstimator(const std::vector<drive::endOfWrapPosition> & endOfWrapPositions,
const cta::catalogue::MediaType & mediaType): m_endOfWrapPositions(endOfWrapPositions), m_mediaType(mediaType) {
}
InterpolationFilePositionEstimator::~InterpolationFilePositionEstimator() {
}
FilePosition InterpolationFilePositionEstimator::getFilePosition(const cta::RetrieveJob& job) const {
return FilePosition();
}
}}}}
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include "FilePositionEstimator.hpp"
#include "castor/tape/tapeserver/drive/DriveInterface.hpp"
#include "catalogue/MediaType.hpp"
#include <vector>
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class InterpolationFilePositionEstimator : public FilePositionEstimator{
public:
InterpolationFilePositionEstimator(const std::vector<drive::endOfWrapPosition> & endOfWrapPositions, const cta::catalogue::MediaType & mediaType);
FilePosition getFilePosition(const cta::RetrieveJob& job) const override;
virtual ~InterpolationFilePositionEstimator();
private:
std::vector<drive::endOfWrapPosition> m_endOfWrapPositions;
cta::catalogue::MediaType m_mediaType;
};
}}}}
\ No newline at end of file
......@@ -19,19 +19,19 @@
#pragma once
#include "RAOAlgorithm.hpp"
#include "NoParamRAOAlgorithmFactory.hpp"
#include "NonConfigurableRAOAlgorithmFactory.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {