Commit ebe48d83 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

cta-taped sets the reason why a drive has been put down

parent a29df67b
......@@ -56,7 +56,8 @@ typename std::result_of<T()>::type retryOnLostConnection(log::Logger &log, const
{"tryNb", tryNb},
{"msg", le.getMessage().str()}
};
log(cta::log::WARNING, "Lost database connection", params);
int logLevel = (tryNb == maxTriesToConnect) ? cta::log::CRIT : cta::log::WARNING;
log(logLevel, "Lost database connection", params);
}
}
......
......@@ -110,6 +110,7 @@ set (COMMON_LIB_SRC_FILES
log/LogLevel.cpp
log/Message.cpp
log/Param.cpp
log/PriorityMaps.cpp
log/StringLogger.cpp
log/SyslogLogger.cpp
log/StdoutLogger.cpp
......
......@@ -17,6 +17,7 @@
*/
#include "DesiredDriveState.hpp"
#include "common/log/PriorityMaps.hpp"
namespace cta {
namespace common {
......@@ -41,6 +42,18 @@ DesiredDriveState& DesiredDriveState::operator=(const DesiredDriveState& ds) {
return *this;
}
std::string DesiredDriveState::c_tpsrvPrefixComment = "[cta-taped]";
void DesiredDriveState::setReasonFromLogMsg(const int logLevel, const std::string & msg){
reason = DesiredDriveState::generateReasonFromLogMsg(logLevel,msg);
}
std::string DesiredDriveState::generateReasonFromLogMsg(const int logLevel, const std::string & msg){
std::string localReason = c_tpsrvPrefixComment;
localReason += " " + cta::log::PriorityMaps::getPriorityText(logLevel) + " "+msg;
return localReason;
}
}}}
......
......@@ -40,7 +40,10 @@ struct DesiredDriveState {
bool operator==(const DesiredDriveState &rhs) const {
return up == rhs.up && forceDown == rhs.forceDown;
}
DesiredDriveState(): up(false), forceDown(false) {}
DesiredDriveState(){}
static std::string c_tpsrvPrefixComment;
void setReasonFromLogMsg(const int logLevel, const std::string & msg);
static std::string generateReasonFromLogMsg(const int logLevel, const std::string & msg);
};
std::ostream &operator<<(std::ostream& os, const DesiredDriveState& obj);
......
......@@ -20,8 +20,8 @@
#include "common/log/LogLevel.hpp"
#include "common/utils/utils.hpp"
#include "common/exception/Exception.hpp"
#include "PriorityMaps.hpp"
#include <sys/time.h>
#include <sys/syslog.h>
#include <sys/syscall.h>
namespace cta {
......@@ -117,25 +117,7 @@ std::string Logger::cleanString(const std::string &s,
//------------------------------------------------------------------------------
std::map<int, std::string>
Logger::generatePriorityToTextMap() {
std::map<int, std::string> m;
try {
m[LOG_EMERG] = "EMERG";
m[ALERT] = "ALERT";
m[LOG_CRIT] = "CRIT";
m[ERR] = "ERROR";
m[WARNING] = "WARN";
m[LOG_NOTICE] = "NOTICE";
m[INFO] = "INFO";
m[DEBUG] = "DEBUG";
} catch(std::exception &se) {
exception::Exception ex;
ex.getMessage() << "Failed to generate priority to text mapping: " <<
se.what();
throw ex;
}
return m;
return PriorityMaps::c_priorityToTextMap;
}
//------------------------------------------------------------------------------
......@@ -143,26 +125,7 @@ std::map<int, std::string>
//------------------------------------------------------------------------------
std::map<std::string, int>
Logger::generateConfigTextToPriorityMap() {
std::map<std::string, int> m;
try {
m["LOG_EMERG"] = LOG_EMERG;
m["ALERT"] = ALERT;
m["LOG_CRIT"] = LOG_CRIT;
m["ERR"] = ERR;
m["WARNING"] = WARNING;
m["LOG_NOTICE"] = LOG_NOTICE;
m["INFO"] = INFO;
m["DEBUG"] = DEBUG;
} catch(std::exception &se) {
exception::Exception ex;
ex.getMessage() <<
"Failed to generate configuration text to priority mapping: " <<
se.what();
throw ex;
}
return m;
return PriorityMaps::c_configTextToPriorityMap;
}
//------------------------------------------------------------------------------
......
/*
* 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 <sys/syslog.h>
#include "PriorityMaps.hpp"
#include "Constants.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace log {
const std::map<int,std::string> PriorityMaps::c_priorityToTextMap = {
{LOG_EMERG,"EMERG"},
{ALERT,"ALERT"},
{LOG_CRIT,"CRIT"},
{ERR,"ERROR"},
{WARNING,"WARN"},
{LOG_NOTICE,"NOTICE"},
{INFO,"INFO"},
{DEBUG,"DEBUG"},
};
const std::map<std::string,int> PriorityMaps::c_configTextToPriorityMap = {
{"LOG_EMERG",LOG_EMERG},
{"ALERT",ALERT},
{"LOG_CRIT",LOG_CRIT},
{"ERR",ERR},
{"WARNING",WARNING},
{"LOG_NOTICE",LOG_NOTICE},
{"INFO",INFO},
{"DEBUG",DEBUG},
};
std::string PriorityMaps::getPriorityText(const int priority){
std::string ret = "";
try {
ret = c_priorityToTextMap.at(priority);
} catch(const std::exception & ex){
//if no corresponding priority, we return an empty string
}
return ret;
}
}}
/*
* 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 <map>
namespace cta {
namespace log {
class PriorityMaps {
public:
static const std::map<int,std::string> c_priorityToTextMap;
static const std::map<std::string, int> c_configTextToPriorityMap;
static std::string getPriorityText(const int priority);
};
}}
#!/bin/bash
set -e
DEVTOOLSET_ENABLE_SCRIPT=/opt/rh/devtoolset-8/enable
EOS_BUILD_DIR=~/eos_build
EOS_SRC_DIR=~/eos
echo "DEVTOOLSET_ENABLE_SCRIPT=${DEVTOOLSET_ENABLE_SCRIPT}"
if ! test -f ${DEVTOOLSET_ENABLE_SCRIPT}; then
echo "The devtoolset enable script ${DEVTOOLSET_ENABLE_SCRIPT} does not exists or is not a regular file"
exit 1
fi
echo "EOS_SRC_DIR=${EOS_SRC_DIR}"
if ! test -d ${EOS_SRC_DIR}; then
echo "The ${EOS_SRC_DIR} directory does not exists or is not a directory"
exit 1
fi
echo "Sourcing ${DEVTOOLSET_ENABLE_SCRIPT}"
. ${DEVTOOLSET_ENABLE_SCRIPT}
echo "Deleting ${EOS_BUILD_DIR}"
rm -rf ${EOS_BUILD_DIR}
echo "Creating ${EOS_BUILD_DIR}"
mkdir -p ${EOS_BUILD_DIR}
cd ${EOS_BUILD_DIR}
cmake3 -DPACKAGEONLY=1 ${EOS_SRC_DIR}
make srpm
sudo yum-builddep -y ${EOS_BUILD_DIR}/SRPMS/eos-*.cern.src.rpm
......@@ -313,8 +313,8 @@ cta::ArchiveMount::~ArchiveMount() throw() {
//------------------------------------------------------------------------------
// setDriveStatus()
//------------------------------------------------------------------------------
void cta::ArchiveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status) {
m_dbMount->setDriveStatus(status, time(NULL));
void cta::ArchiveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason) {
m_dbMount->setDriveStatus(status, time(NULL), reason);
}
//------------------------------------------------------------------------------
......
......@@ -109,7 +109,7 @@ namespace cta {
/**
* Report a drive status change
*/
void setDriveStatus(cta::common::dataStructures::DriveStatus status) override;
void setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason = cta::nullopt) override;
/**
* Report a tape session statistics
......
......@@ -55,7 +55,7 @@ std::string LabelMount::getVid() const {
// TODO
}
void LabelMount::setDriveStatus(cta::common::dataStructures::DriveStatus status) {
void LabelMount::setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason) {
throw 0;
// TODO
}
......
......@@ -90,7 +90,7 @@ namespace cta {
/**
* Report a drive status change
*/
void setDriveStatus(cta::common::dataStructures::DriveStatus status) override;
void setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason = cta::nullopt) override;
/**
* Report a tape session statistics
......
......@@ -3064,6 +3064,7 @@ void OStoreDB::setDriveDown(common::dataStructures::DriveState & driveState,
driveState.currentVid="";
driveState.currentTapePool="";
driveState.currentActivityAndWeight = nullopt;
driveState.desiredDriveState.reason = inputs.reason;
}
//------------------------------------------------------------------------------
......@@ -3076,6 +3077,7 @@ void OStoreDB::setDriveUpOrMaybeDown(common::dataStructures::DriveState & driveS
DriveStatus targetStatus=DriveStatus::Up;
if (!driveState.desiredDriveState.up) {
driveState.driveStatus = common::dataStructures::DriveStatus::Down;
driveState.desiredDriveState.reason = inputs.reason;
}
// If we were already up (or down), then we only update the last update time.
if (driveState.driveStatus == targetStatus) {
......@@ -3959,7 +3961,7 @@ void OStoreDB::RetrieveMount::complete(time_t completionTime) {
//------------------------------------------------------------------------------
// OStoreDB::RetrieveMount::setDriveStatus()
//------------------------------------------------------------------------------
void OStoreDB::RetrieveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime) {
void OStoreDB::RetrieveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime, const cta::optional<std::string> & reason) {
// We just report the drive status as instructed by the tape thread.
// Reset the drive state.
common::dataStructures::DriveInfo driveInfo;
......@@ -3973,6 +3975,7 @@ void OStoreDB::RetrieveMount::setDriveStatus(cta::common::dataStructures::DriveS
inputs.status = status;
inputs.vid = mountInfo.vid;
inputs.tapepool = mountInfo.tapePool;
inputs.reason = reason;
// TODO: statistics!
inputs.byteTransferred = 0;
inputs.filesTransferred = 0;
......@@ -4160,7 +4163,7 @@ void OStoreDB::RetrieveMount::flushAsyncSuccessReports(std::list<cta::SchedulerD
//------------------------------------------------------------------------------
// OStoreDB::ArchiveMount::setDriveStatus()
//------------------------------------------------------------------------------
void OStoreDB::ArchiveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime) {
void OStoreDB::ArchiveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime, const cta::optional<std::string> & reason) {
// We just report the drive status as instructed by the tape thread.
// Reset the drive state.
common::dataStructures::DriveInfo driveInfo;
......@@ -4174,6 +4177,7 @@ void OStoreDB::ArchiveMount::setDriveStatus(cta::common::dataStructures::DriveSt
inputs.status = status;
inputs.vid = mountInfo.vid;
inputs.tapepool = mountInfo.tapePool;
inputs.reason = reason;
// TODO: statistics!
inputs.byteTransferred = 0;
inputs.filesTransferred = 0;
......
......@@ -167,7 +167,7 @@ public:
std::list<std::unique_ptr<SchedulerDatabase::ArchiveJob>> getNextJobBatch(uint64_t filesRequested,
uint64_t bytesRequested, log::LogContext &logContext) override;
void complete(time_t completionTime) override;
void setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime) override;
void setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime, const cta::optional<std::string> & reason = cta::nullopt) override;
void setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) override;
public:
void setJobBatchTransferred(
......@@ -234,7 +234,7 @@ public:
/// Public but non overriding function used by retrieve jobs (on failure to transfer):
void releaseDiskSpace(const DiskSpaceReservationRequest& diskSpaceReservation, log::LogContext & lc);
void complete(time_t completionTime) override;
void setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime) override;
void setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime, const cta::optional<std::string> & reason = cta::nullopt) override;
void setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) override;
public:
void flushAsyncSuccessReports(std::list<cta::SchedulerDatabase::RetrieveJob*>& jobsBatch, log::LogContext& lc) override;
......@@ -582,6 +582,7 @@ private:
std::string vid;
std::string tapepool;
optional<common::dataStructures::DriveState::ActivityAndWeight> activityAndWeigh;
optional<std::string> reason;
};
/** Collection of smaller scale parts of reportDriveStats */
struct ReportDriveStatsInputs {
......
......@@ -293,8 +293,8 @@ void cta::RetrieveMount::abort() {
//------------------------------------------------------------------------------
// setDriveStatus()
//------------------------------------------------------------------------------
void cta::RetrieveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status) {
m_dbMount->setDriveStatus(status, time(NULL));
void cta::RetrieveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason) {
m_dbMount->setDriveStatus(status, time(NULL), reason);
}
//------------------------------------------------------------------------------
......
......@@ -127,7 +127,7 @@ namespace cta {
/**
* Report a drive status change
*/
virtual void setDriveStatus(cta::common::dataStructures::DriveStatus status);
virtual void setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason = cta::nullopt);
/**
* Report a tape session statistics
......
......@@ -167,7 +167,7 @@ public:
virtual std::list<std::unique_ptr<ArchiveJob>> getNextJobBatch(uint64_t filesRequested,
uint64_t bytesRequested, log::LogContext& logContext) = 0;
virtual void complete(time_t completionTime) = 0;
virtual void setDriveStatus(common::dataStructures::DriveStatus status, time_t completionTime) = 0;
virtual void setDriveStatus(common::dataStructures::DriveStatus status, time_t completionTime, const cta::optional<std::string> & reason = cta::nullopt) = 0;
virtual void setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) = 0;
virtual void setJobBatchTransferred(
std::list<std::unique_ptr<cta::SchedulerDatabase::ArchiveJob>> & jobsBatch, log::LogContext & lc) = 0;
......@@ -383,7 +383,7 @@ public:
virtual std::list<std::unique_ptr<cta::SchedulerDatabase::RetrieveJob>> getNextJobBatch(uint64_t filesRequested,
uint64_t bytesRequested, cta::disk::DiskSystemFreeSpaceList & diskSystemFreeSpace, log::LogContext& logContext) = 0;
virtual void complete(time_t completionTime) = 0;
virtual void setDriveStatus(common::dataStructures::DriveStatus status, time_t completionTime) = 0;
virtual void setDriveStatus(common::dataStructures::DriveStatus status, time_t completionTime, const cta::optional<std::string> & reason = cta::nullopt) = 0;
virtual void setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) = 0;
virtual void flushAsyncSuccessReports(std::list<cta::SchedulerDatabase::RetrieveJob *> & jobsBatch, log::LogContext & lc) = 0;
virtual ~RetrieveMount() {}
......
......@@ -90,7 +90,7 @@ namespace cta {
/**
* Report a drive status change
*/
virtual void setDriveStatus(cta::common::dataStructures::DriveStatus status) = 0;
virtual void setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason = cta::nullopt) = 0;
/**
* Report a tape session statistics
......
......@@ -56,7 +56,7 @@ class TapeMountDummy: public TapeMount {
throw exception::Exception("In DummyTapeMount::getVendor() : not implemented");
}
void setDriveStatus(cta::common::dataStructures::DriveStatus status) override {}
void setDriveStatus(cta::common::dataStructures::DriveStatus status, const cta::optional<std::string> & reason) override {}
void setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) override {};
void setTapeMounted(log::LogContext &logContext) const override {};
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment