Commit 551868b6 authored by Daniele Kruse's avatar Daniele Kruse
Browse files

More work on the CLI, added new utility functions

parent 94d3f36b
......@@ -11,13 +11,17 @@ set (COMMON_LIB_SRC_FILES
dataStructures/ArchiveRoute.cpp
dataStructures/CancelRetrieveRequest.cpp
dataStructures/Dedication.cpp
dataStructures/DedicationType.cpp
dataStructures/DeleteArchiveRequest.cpp
dataStructures/DRData.cpp
dataStructures/DriveState.cpp
dataStructures/DriveStatus.cpp
dataStructures/EntryLog.cpp
dataStructures/ListStorageClassRequest.cpp
dataStructures/MountType.cpp
dataStructures/ReadTestResult.cpp
dataStructures/RepackInfo.cpp
dataStructures/RepackType.cpp
dataStructures/Requester.cpp
dataStructures/RetrieveJob.cpp
dataStructures/RetrieveMount.cpp
......@@ -28,6 +32,7 @@ set (COMMON_LIB_SRC_FILES
dataStructures/TapeFileLocation.cpp
dataStructures/TapeMount.cpp
dataStructures/TapePool.cpp
dataStructures/TestSourceType.cpp
dataStructures/UpdateFileInfoRequest.cpp
dataStructures/User.cpp
dataStructures/UserGroup.cpp
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 "common/dataStructures/DedicationType.hpp"
std::string cta::common::dataStructures::toString(cta::common::dataStructures::DedicationType type) {
switch(type) {
case cta::common::dataStructures::DedicationType::readonly:
return "readonly";
case cta::common::dataStructures::DedicationType::writeonly:
return "writeonly";
case cta::common::dataStructures::DedicationType::readwrite:
return "readwrite";
default:
return "UNKNOWN";
}
}
\ No newline at end of file
......@@ -18,6 +18,8 @@
#pragma once
#include <string>
namespace cta {
namespace common {
namespace dataStructures {
......@@ -26,6 +28,8 @@ enum DedicationType {
writeonly,
readwrite
};
std::string toString(DedicationType type);
} // namespace dataStructures
} // namespace common
} // namespace cta
......
......@@ -32,6 +32,7 @@ cta::common::dataStructures::DriveState::DriveState() {
m_logicalLibrarySet = false;
m_mountTypeSet = false;
m_nameSet = false;
m_hostSet = false;
m_sessionIdSet = false;
m_sessionStartTimeSet = false;
m_statusSet = false;
......@@ -56,6 +57,7 @@ bool cta::common::dataStructures::DriveState::allFieldsSet() const {
&& m_logicalLibrarySet
&& m_mountTypeSet
&& m_nameSet
&& m_hostSet
&& m_sessionIdSet
&& m_sessionStartTimeSet
&& m_statusSet;
......@@ -223,6 +225,24 @@ std::string cta::common::dataStructures::DriveState::getName() const {
return m_name;
}
//------------------------------------------------------------------------------
// setHost
//------------------------------------------------------------------------------
void cta::common::dataStructures::DriveState::setHost(const std::string &host) {
m_host = host;
m_hostSet = true;
}
//------------------------------------------------------------------------------
// getHost
//------------------------------------------------------------------------------
std::string cta::common::dataStructures::DriveState::getHost() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the DriveState have been set!");
}
return m_host;
}
//------------------------------------------------------------------------------
// setSessionId
//------------------------------------------------------------------------------
......
......@@ -71,6 +71,9 @@ public:
void setName(const std::string &name);
std::string getName() const;
void setHost(const std::string &host);
std::string getHost() const;
void setSessionId(const uint64_t sessionId);
uint64_t getSessionId() const;
......@@ -115,6 +118,9 @@ private:
std::string m_name;
bool m_nameSet;
std::string m_host;
bool m_hostSet;
uint64_t m_sessionId;
bool m_sessionIdSet;
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 "common/dataStructures/DriveStatus.hpp"
std::string cta::common::dataStructures::toString(cta::common::dataStructures::DriveStatus type) {
switch(type) {
case cta::common::dataStructures::DriveStatus::Down:
return "Down";
case cta::common::dataStructures::DriveStatus::Up:
return "Up";
case cta::common::dataStructures::DriveStatus::Starting:
return "Starting";
case cta::common::dataStructures::DriveStatus::Mounting:
return "Mounting";
case cta::common::dataStructures::DriveStatus::Transfering:
return "Transfering";
case cta::common::dataStructures::DriveStatus::Unloading:
return "Unloading";
case cta::common::dataStructures::DriveStatus::Unmounting:
return "Unmounting";
case cta::common::dataStructures::DriveStatus::DrainingToDisk:
return "DrainingToDisk";
case cta::common::dataStructures::DriveStatus::CleaningUp:
return "CleaningUp";
default:
return "UNKNOWN";
}
}
......@@ -18,6 +18,8 @@
#pragma once
#include <string>
namespace cta {
namespace common {
namespace dataStructures {
......@@ -32,6 +34,8 @@ enum DriveStatus {
DrainingToDisk,
CleaningUp
};
std::string toString(DriveStatus type);
} // namespace dataStructures
} // namespace common
} // namespace cta
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 "common/dataStructures/MountType.hpp"
std::string cta::common::dataStructures::toString(cta::common::dataStructures::MountType type) {
switch(type) {
case cta::common::dataStructures::MountType::archive:
return "archive";
case cta::common::dataStructures::MountType::retrieve:
return "retrieve";
case cta::common::dataStructures::MountType::none:
return "none";
default:
return "UNKNOWN";
}
}
......@@ -18,6 +18,8 @@
#pragma once
#include <string>
namespace cta {
namespace common {
namespace dataStructures {
......@@ -26,6 +28,8 @@ enum MountType {
retrieve,
none
};
std::string toString(MountType type);
} // namespace dataStructures
} // namespace common
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 "common/dataStructures/RepackType.hpp"
std::string cta::common::dataStructures::toString(cta::common::dataStructures::RepackType type) {
switch(type) {
case cta::common::dataStructures::RepackType::expandandrepack:
return "expandandrepack";
case cta::common::dataStructures::RepackType::justexpand:
return "justexpand";
case cta::common::dataStructures::RepackType::justrepack:
return "justrepack";
default:
return "UNKNOWN";
}
}
......@@ -18,6 +18,8 @@
#pragma once
#include <string>
namespace cta {
namespace common {
namespace dataStructures {
......@@ -26,6 +28,8 @@ enum RepackType {
justexpand,
justrepack
};
std::string toString(RepackType type);
} // namespace dataStructures
} // namespace common
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 "common/dataStructures/TestSourceType.hpp"
std::string cta::common::dataStructures::toString(cta::common::dataStructures::TestSourceType type) {
switch(type) {
case cta::common::dataStructures::TestSourceType::devzero:
return "devzero";
case cta::common::dataStructures::TestSourceType::devurandom:
return "devurandom";
default:
return "UNKNOWN";
}
}
......@@ -18,6 +18,7 @@
#pragma once
#include <string>
namespace cta {
namespace common {
namespace dataStructures {
......@@ -25,6 +26,8 @@ enum TestSourceType {
devzero,
devurandom
};
std::string toString(TestSourceType type);
} // namespace dataStructures
} // namespace common
} // namespace cta
......
......@@ -347,6 +347,15 @@ bool XrdProFile::hasOption(const std::vector<std::string> &tokens, const std::st
return false;
}
//------------------------------------------------------------------------------
// timeToString
//------------------------------------------------------------------------------
std::string XrdProFile::timeToString(const time_t &time) {
std::string timeString(ctime(&time));
timeString=timeString.substr(0,timeString.size()-1); //remove newline
return timeString;
}
//------------------------------------------------------------------------------
// formatResponse
//------------------------------------------------------------------------------
......@@ -380,20 +389,14 @@ std::string XrdProFile::formatResponse(const std::vector<std::vector<std::string
// addLogInfoToResponseRow
//------------------------------------------------------------------------------
void XrdProFile::addLogInfoToResponseRow(std::vector<std::string> &responseRow, const cta::common::dataStructures::EntryLog &creationLog, const cta::common::dataStructures::EntryLog &lastModificationLog) {
time_t creationTime = creationLog.getTime();
time_t lastModificationTime = lastModificationLog.getTime();
std::string creationTimeString(ctime(&creationTime));
std::string lastModificationTimeString(ctime(&lastModificationTime));
creationTimeString=creationTimeString.substr(0,24); //remove the newline
lastModificationTimeString=lastModificationTimeString.substr(0,24); //remove the newline
responseRow.push_back(std::to_string((unsigned long long)creationLog.getUser().getUid()));
responseRow.push_back(std::to_string((unsigned long long)creationLog.getUser().getGid()));
responseRow.push_back(creationLog.getHost());
responseRow.push_back(creationTimeString);
responseRow.push_back(timeToString(creationLog.getTime()));
responseRow.push_back(std::to_string((unsigned long long)lastModificationLog.getUser().getUid()));
responseRow.push_back(std::to_string((unsigned long long)lastModificationLog.getUser().getGid()));
responseRow.push_back(lastModificationLog.getHost());
responseRow.push_back(lastModificationTimeString);
responseRow.push_back(timeToString(lastModificationLog.getTime()));
}
//------------------------------------------------------------------------------
......@@ -1271,20 +1274,14 @@ void XrdProFile::xCom_dedication(const std::vector<std::string> &tokens, const c
default:
type_s = "readwrite";
break;
}
time_t fromTime = it->getFromTimestamp();
time_t untilTime = it->getUntilTimestamp();
std::string fromTimeString(ctime(&fromTime));
std::string untilTimeString(ctime(&untilTime));
fromTimeString=fromTimeString.substr(0,24); //remove the newline
untilTimeString=untilTimeString.substr(0,24); //remove the newline
}
currentRow.push_back(it->getDriveName());
currentRow.push_back(type_s);
currentRow.push_back(it->getVid());
currentRow.push_back(it->getUserGroup());
currentRow.push_back(it->getTag());
currentRow.push_back(fromTimeString);
currentRow.push_back(untilTimeString);
currentRow.push_back(timeToString(it->getFromTimestamp()));
currentRow.push_back(timeToString(it->getUntilTimestamp()));
addLogInfoToResponseRow(currentRow, it->getCreationLog(), it->getLastModificationLog());
currentRow.push_back(it->getComment());
responseTable.push_back(currentRow);
......@@ -1375,9 +1372,6 @@ void XrdProFile::xCom_repack(const std::vector<std::string> &tokens, const cta::
type_s = "justrepack";
break;
}
time_t creationTime = it->getCreationLog().getTime();
std::string creationTimeString(ctime(&creationTime));
creationTimeString=creationTimeString.substr(0,24); //remove the newline
std::vector<std::string> currentRow;
currentRow.push_back(it->getVid());
currentRow.push_back(std::to_string((unsigned long long)it->getTotalFiles()));
......@@ -1392,7 +1386,7 @@ void XrdProFile::xCom_repack(const std::vector<std::string> &tokens, const cta::
currentRow.push_back(std::to_string((unsigned long long)it->getCreationLog().getUser().getUid()));
currentRow.push_back(std::to_string((unsigned long long)it->getCreationLog().getUser().getGid()));
currentRow.push_back(it->getCreationLog().getHost());
currentRow.push_back(creationTimeString);
currentRow.push_back(timeToString(it->getCreationLog().getTime()));
responseTable.push_back(currentRow);
}
m_data = formatResponse(responseTable);
......@@ -1482,9 +1476,6 @@ void XrdProFile::xCom_verify(const std::vector<std::string> &tokens, const cta::
std::vector<std::string> header = {"vid","files","size","tag","to verify","failed","verified","status","uid","gid","host","time"};
responseTable.push_back(header);
for(auto it = list.cbegin(); it != list.cend(); it++) {
time_t creationTime = it->getCreationLog().getTime();
std::string creationTimeString(ctime(&creationTime));
creationTimeString=creationTimeString.substr(0,24); //remove the newline
std::vector<std::string> currentRow;
currentRow.push_back(it->getVid());
currentRow.push_back(std::to_string((unsigned long long)it->getTotalFiles()));
......@@ -1496,8 +1487,8 @@ void XrdProFile::xCom_verify(const std::vector<std::string> &tokens, const cta::
currentRow.push_back(it->getVerifyStatus());
currentRow.push_back(std::to_string((unsigned long long)it->getCreationLog().getUser().getUid()));
currentRow.push_back(std::to_string((unsigned long long)it->getCreationLog().getUser().getGid()));
currentRow.push_back(it->getCreationLog().getHost());
currentRow.push_back(creationTimeString);
currentRow.push_back(it->getCreationLog().getHost());
currentRow.push_back(timeToString(it->getCreationLog().getTime()));
responseTable.push_back(currentRow);
}
m_data = formatResponse(responseTable);
......@@ -1875,6 +1866,30 @@ void XrdProFile::xCom_listpendingretrieves(const std::vector<std::string> &token
void XrdProFile::xCom_listdrivestates(const std::vector<std::string> &tokens, const cta::common::dataStructures::SecurityIdentity &requester) {
std::stringstream help;
help << tokens[0] << " lds/listdrivestates" << std::endl;
std::list<cta::common::dataStructures::DriveState> result = m_scheduler->getDriveStates(requester);
if(result.size()>0) {
std::vector<std::vector<std::string>> responseTable;
std::vector<std::string> header = {"vid","id","copy no.","fseq","block id","size","user","group","instance","path","diskpool","diskpool throughput"};
responseTable.push_back(header);
for(auto it = result.cbegin(); it != result.cend(); it++) {
std::vector<std::string> currentRow;
currentRow.push_back(it->getLogicalLibrary());
currentRow.push_back(it->getHost());
currentRow.push_back(it->getName());
currentRow.push_back(cta::common::dataStructures::toString(it->getStatus()));
currentRow.push_back(std::to_string((unsigned long long)(time(NULL)-it->getCurrentStateStartTime())));
currentRow.push_back(cta::common::dataStructures::toString(it->getMountType()));
currentRow.push_back(it->getCurrentVid());
currentRow.push_back(it->getCurrentTapePool());
currentRow.push_back(std::to_string((unsigned long long)it->getSessionId()));
currentRow.push_back(std::to_string((unsigned long long)(time(NULL)-it->getSessionStartTime())));
currentRow.push_back(std::to_string((unsigned long long)it->getFilesTransferedInSession()));
currentRow.push_back(std::to_string((unsigned long long)it->getBytesTransferedInSession()));
currentRow.push_back(std::to_string((long double)it->getLatestBandwidth()));
responseTable.push_back(currentRow);
}
m_data = formatResponse(responseTable);
}
}
//------------------------------------------------------------------------------
......
......@@ -153,6 +153,14 @@ protected:
*/
std::string formatResponse(const std::vector<std::vector<std::string>> &responseTable);
/**
* Returns a string representation of the time
*
* @param time The input time
* @return a string representation of the time
*/
std::string timeToString(const time_t &time);
/**
* Adds the creation log and the last modification log to the current response row
*
......
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