Commit 56c4c332 authored by Eric Cano's avatar Eric Cano
Browse files

Implemented drive status support in drive register structure and code.

Added drive status reporting in scheduler
Added drive status reporting in OStoreDB
Added support for drive status listing in the front end
Removed virtual functions from the Scheduler, which is never overloaded.
Added DesiredDriveState structure to drive state.
Removed usage of duplicate MountType, DriveStatus and DriveState structures.
Created DriveInfo structure to allow recreation of drive register entry in all
reporting situation (potentially with partial/assumed info).
parent 425af9d0
......@@ -36,6 +36,7 @@ set (COMMON_LIB_SRC_FILES
dataStructures/ArchiveRoute.cpp
dataStructures/CancelRetrieveRequest.cpp
dataStructures/DeleteArchiveRequest.cpp
dataStructures/DesiredDriveState.cpp
dataStructures/DiskFileInfo.cpp
dataStructures/DriveState.cpp
dataStructures/DriveStatus.cpp
......
......@@ -24,7 +24,7 @@
namespace cta { namespace common {
enum DriveStatus {
enum DriveStatusToDecommission {
Down,
Up,
Starting, // This status allows drive register to represent drives committed
......@@ -37,8 +37,13 @@ namespace cta { namespace common {
DrainingToDisk,
CleaningUp
};
struct DesiredDriveStateToDecommission {
bool up; ///< Should the drive be up?
bool forceDown; ///< Should going down preempt an existig mount?
};
struct DriveState {
struct DriveStateToDecommission {
std::string name;
std::string logicalLibrary;
uint64_t sessionId;
......@@ -55,10 +60,13 @@ namespace cta { namespace common {
time_t cleanupStartTime;
time_t lastUpdateTime;
time_t startStartTime;
cta::MountType::Enum mountType;
DriveStatus status;
cta::MountTypeToDecommission::Enum mountType;
dataStructures::DriveStatus status;
std::string currentVid;
std::string currentTapePool;
dataStructures::DesiredDriveState desiredDriveState;
};
}} //namespace cta::common
\ No newline at end of file
}} //namespace cta::common
#error This should have been decomissioned
\ No newline at end of file
/*
* 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 "DesiredDriveState.hpp"
std::ostream &cta::common::dataStructures::operator<<(std::ostream& os, const DesiredDriveState& obj) {
std::string upStr(obj.up?"true":"false"),
forceStr(obj.forceDown?"true":"false");
return os << "(up=" << upStr << " forceDown=" << forceStr << ")";
}
/*
* 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/>.
*/
#pragma once
#include <ostream>
namespace cta {
namespace common {
namespace dataStructures {
/**
* Structure describing the instructions to the drive from operators.
* The values are reset to all false when the drive goes down (including
* at startup).
*/
struct DesiredDriveState {
bool up; ///< Should the drive be up?
bool forceDown; ///< Should going down preempt an existig mount?
bool operator==(const DesiredDriveState &rhs) const {
return up == rhs.up && forceDown == rhs.forceDown;
}
};
std::ostream &operator<<(std::ostream& os, const DesiredDriveState& obj);
}}} // namespace cta::common::dataStructures
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include <string>
namespace cta {
namespace common {
namespace dataStructures {
enum DriveDesiredState {
Down,
Up
};
std::string toString(DriveDesiredState desiredState);
} // namespace dataStructures
} // namespace common
} // namespace cta
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include <string>
namespace cta {
namespace common {
namespace dataStructures {
/**
* This struct holds minimal drive info. It is used to (re-)create the
* drive's entry in the register is needed.
*/
struct DriveInfo {
std::string driveName;
std::string host;
std::string logicalLibrary;
};
}}} //namespace cta::common::dataStructures
\ No newline at end of file
......@@ -33,13 +33,24 @@ DriveState::DriveState():
filesTransferedInSession(0),
latestBandwidth(0),
sessionStartTime(0),
currentStateStartTime(0) {}
mountStartTime(0),
transferStartTime(0),
unloadStartTime(0),
unmountStartTime(0),
drainingStartTime(0),
downOrUpStartTime(0),
cleanupStartTime(0),
lastUpdateTime(0),
startStartTime(0),
mountType(dataStructures::MountType::NoMount),
driveStatus(dataStructures::DriveStatus::Down),
desiredDriveState({false, false}) {}
//------------------------------------------------------------------------------
// operator==
//------------------------------------------------------------------------------
bool DriveState::operator==(const DriveState &rhs) const {
return name==rhs.name
return driveName==rhs.driveName
&& host==rhs.host
&& logicalLibrary==rhs.logicalLibrary
&& sessionId==rhs.sessionId
......@@ -47,9 +58,18 @@ bool DriveState::operator==(const DriveState &rhs) const {
&& filesTransferedInSession==rhs.filesTransferedInSession
&& latestBandwidth==rhs.latestBandwidth
&& sessionStartTime==rhs.sessionStartTime
&& currentStateStartTime==rhs.currentStateStartTime
&& mountStartTime==rhs.mountStartTime
&& transferStartTime==rhs.transferStartTime
&& unloadStartTime==rhs.unloadStartTime
&& unmountStartTime==rhs.unmountStartTime
&& drainingStartTime==rhs.drainingStartTime
&& downOrUpStartTime==rhs.downOrUpStartTime
&& cleanupStartTime==rhs.cleanupStartTime
&& lastUpdateTime==rhs.lastUpdateTime
&& startStartTime==rhs.startStartTime
&& mountType==rhs.mountType
&& status==rhs.status
&& driveStatus==rhs.driveStatus
&& desiredDriveState==rhs.desiredDriveState
&& currentVid==rhs.currentVid
&& currentTapePool==rhs.currentTapePool;
}
......@@ -65,7 +85,8 @@ bool DriveState::operator!=(const DriveState &rhs) const {
// operator<<
//------------------------------------------------------------------------------
std::ostream &operator<<(std::ostream &os, const DriveState &obj) {
os << "(name=" << obj.name
return
os << "(name=" << obj.driveName
<< " host=" << obj.host
<< " logicalLibrary=" << obj.logicalLibrary
<< " sessionId=" << obj.sessionId
......@@ -73,12 +94,20 @@ std::ostream &operator<<(std::ostream &os, const DriveState &obj) {
<< " filesTransferedInSession=" << obj.filesTransferedInSession
<< " latestBandwidth=" << obj.latestBandwidth
<< " sessionStartTime=" << obj.sessionStartTime
<< " currentStateStartTime=" << obj.currentStateStartTime
<< " mountStartTime=" << obj.mountStartTime
<< " transferStartTime=" << obj.transferStartTime
<< " unloadStartTime=" << obj.unloadStartTime
<< " unmountStartTime=" << obj.unmountStartTime
<< " drainingStartTime=" << obj.drainingStartTime
<< " downOrUpStartTime=" << obj.downOrUpStartTime
<< " cleanupStartTime=" << obj.cleanupStartTime
<< " lastUpdateTime=" << obj.lastUpdateTime
<< " startStartTime=" << obj.startStartTime
<< " mountType=" << obj.mountType
<< " status=" << obj.status
<< " status=" << obj.driveStatus
<< " desiredState=" << obj.desiredDriveState
<< " currentVid=" << obj.currentVid
<< " currentTapePool=" << obj.currentTapePool << ")";
return os;
}
} // namespace dataStructures
......
......@@ -18,13 +18,12 @@
#pragma once
#include <list>
#include <map>
#include <stdint.h>
#include <string>
#include "common/dataStructures/DriveStatus.hpp"
#include "common/dataStructures/MountType.hpp"
#include "DriveStatus.hpp"
#include "MountType.hpp"
#include "DesiredDriveState.hpp"
namespace cta {
namespace common {
......@@ -42,17 +41,26 @@ struct DriveState {
bool operator!=(const DriveState &rhs) const;
std::string name;
std::string driveName;
std::string host;
std::string logicalLibrary;
uint64_t sessionId;
uint64_t bytesTransferedInSession;
uint64_t filesTransferedInSession;
uint64_t latestBandwidth;
double latestBandwidth; /** < Byte per seconds */
time_t sessionStartTime;
time_t currentStateStartTime;
time_t mountStartTime;
time_t transferStartTime;
time_t unloadStartTime;
time_t unmountStartTime;
time_t drainingStartTime;
time_t downOrUpStartTime;
time_t cleanupStartTime;
time_t lastUpdateTime;
time_t startStartTime;
MountType mountType;
DriveStatus status;
DriveStatus driveStatus;
DesiredDriveState desiredDriveState;
std::string currentVid;
std::string currentTapePool;
......
......@@ -18,6 +18,8 @@
#include "common/dataStructures/DriveStatus.hpp"
#include <sstream>
std::string cta::common::dataStructures::toString(cta::common::dataStructures::DriveStatus type) {
switch(type) {
case cta::common::dataStructures::DriveStatus::Down:
......@@ -38,7 +40,15 @@ std::string cta::common::dataStructures::toString(cta::common::dataStructures::D
return "DrainingToDisk";
case cta::common::dataStructures::DriveStatus::CleaningUp:
return "CleaningUp";
case cta::common::dataStructures::DriveStatus::Unknown:
return "Unknown";
default:
return "UNKNOWN";
{
std::stringstream ret;
ret << "WRONG STATE CODE (" << (uint32_t) type << ")";
return ret.str();
}
}
}
......@@ -32,7 +32,8 @@ enum DriveStatus {
Unloading,
Unmounting,
DrainingToDisk,
CleaningUp
CleaningUp,
Unknown
};
std::string toString(DriveStatus type);
......
......@@ -20,13 +20,20 @@
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";
case cta::common::dataStructures::MountType::Archive:
return "Archive";
case cta::common::dataStructures::MountType::Retrieve:
return "Retrieve";
case cta::common::dataStructures::MountType::Label:
return "Label";
case cta::common::dataStructures::MountType::NoMount:
return "NoMount";
default:
return "UNKNOWN";
}
}
std::ostream & cta::common::dataStructures::operator<<(std::ostream &os,
const cta::common::dataStructures::MountType &obj) {
return os << toString(obj);
}
......@@ -23,13 +23,16 @@
namespace cta {
namespace common {
namespace dataStructures {
enum MountType {
archive,
retrieve,
none
enum class MountType: uint32_t {
Archive = 1,
Retrieve = 2,
Label = 3,
NoMount = 0
};
std::string toString(MountType type);
std::ostream &operator <<(std::ostream& os, const MountType &obj);
} // namespace dataStructures
} // namespace common
} // namespace cta
This diff is collapsed.
......@@ -21,7 +21,7 @@
#include "ObjectOps.hpp"
#include <list>
#include <limits>
#include "common/DriveState.hpp"
#include "common/dataStructures/DriveState.hpp"
namespace cta { namespace objectstore {
......@@ -41,62 +41,36 @@ public:
bool isEmpty();
// Drives management =========================================================
void addDrive (const std::string & driveName, const std::string & logicalLibrary,
const EntryLogSerDeser & creationLog);
void removeDrive (const std::string & name);
private:
cta::MountType::Enum deserializeMountType(serializers::MountType);
serializers::MountType serializeMountType(cta::MountType::Enum);
common::DriveStatus deserializeDriveStatus(serializers::DriveStatus);
serializers::DriveStatus serializeDriveStatus(common::DriveStatus);
public:
CTA_GENERATE_EXCEPTION_CLASS(MissingStatistics);
CTA_GENERATE_EXCEPTION_CLASS(MissingTapeInfo);
CTA_GENERATE_EXCEPTION_CLASS(MissingSessionInfo);
CTA_GENERATE_EXCEPTION_CLASS(NoSuchDrive);
CTA_GENERATE_EXCEPTION_CLASS(WrongStateTransition);
CTA_GENERATE_EXCEPTION_CLASS(NotImplemented);
/**
* Report the status of the drive to the DB.
* Returns all the drive states stored in the drive registry.
* @return a list of all the drive states
*/
std::list<cta::common::dataStructures::DriveState> getAllDrivesState();
/**
* Query the complete drive state for one drive.
* @param driveName
* @return complete drive state, or throws an exception if the drive is not
* known.
*/
cta::common::dataStructures::DriveState getDriveState(const std::string &driveName);
/**
* Set the state of a drive. Either creates or overwrites the entry.
* @param driveState Full drive state (drive name is part of the structure).
*/
void setDriveState(const cta::common::dataStructures::DriveState driveState);
/**
* Remove the drive from the register.
* @param name
*/
void removeDrive (const std::string & driveName);
/**
* JSON dump of the drive
* @return
*/
void reportDriveStatus (const std::string & drive, const std::string & logicalLibary,
common::DriveStatus status, time_t reportTime,
cta::MountType::Enum mountType = cta::MountType::NONE,
uint64_t mountSessionId = std::numeric_limits<uint64_t>::max(),
uint64_t byteTransfered = std::numeric_limits<uint64_t>::max(),
uint64_t filesTransfered = std::numeric_limits<uint64_t>::max(),
double latestBandwidth = std::numeric_limits<double>::max(),
const std::string & vid = "",
const std::string & tapepool = "");
private:
/* Collection of smaller scale parts of reportDriveStatus */
struct ReportDriveStatusInputs {
const std::string & drive;
const std::string & logicalLibary;
common::DriveStatus status;
cta::MountType::Enum mountType;
time_t reportTime;
uint64_t mountSessionId;
uint64_t byteTransfered;
uint64_t filesTransfered;
double latestBandwidth;
std::string vid;
std::string tapepool;
ReportDriveStatusInputs(const std::string & d, const std::string & ll):
drive(d), logicalLibary(ll) {}
};
void checkReportDriveStatusInputs(ReportDriveStatusInputs & inputs);
void setDriveDown(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveUp(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveStarting(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveMounting(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveTransfering(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveUnloading(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveUnmounting(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveDrainingToDisk(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
void setDriveCleaningUp(ReportDriveStatusInputs & inputs, serializers::DriveState * drive);
public:
std::list<common::DriveState> dumpDrives();
std::string dump();
};
......
......@@ -46,6 +46,7 @@ public:
CTA_GENERATE_EXCEPTION_CLASS(NotInitialized);
CTA_GENERATE_EXCEPTION_CLASS(AddressAlreadySet);
CTA_GENERATE_EXCEPTION_CLASS(InvalidAddress);
CTA_GENERATE_EXCEPTION_CLASS(FailedToSerialize);
protected:
void checkHeaderWritable() {
if (!m_headerInterpreted)
......@@ -266,7 +267,12 @@ public:
if (!m_existingObject)
throw NewObject("In ObjectOps::commit: trying to update a new object");
// Serialise the payload into the header
m_header.set_payload(m_payload.SerializeAsString());
try {
m_header.set_payload(m_payload.SerializeAsString());
} catch (std::exception & stdex) {
cta::exception::Exception ex(std::string("In ObjectOps::commit(): failed to serialize: ")+stdex.what());
throw ex;
}
// Write the object
m_objectStore.atomicOverwrite(getAddressIfSet(), m_header.SerializeAsString());
}
......
......@@ -33,26 +33,6 @@ enum ObjectType {
GenericObject_t = 1000;
}
// The types of mounts
enum MountType {
NoMount = 0;
Archive = 1;
Retrieve = 2;
}
// The drive statuses
enum DriveStatus {
Down = 0;
Up = 1;
Starting = 2;
Mounting = 3;
Transfering = 4;
Unloading = 5;
Unmounting = 6;
DrainingToDisk = 7;
CleaningUp = 8;
};
// The base object header. This will allow introspection and automatic
// "garbage collection", i.e. returning an unprocessed object belonging
// to a dead agent to the right queue or container.
......@@ -120,7 +100,9 @@ message RetrieveQueuePointer {
// the admin handled configuration information
message RootEntry {
repeated ArchiveQueuePointer archivequeuepointers = 1050;
repeated RetrieveQueuePointer retrievequeuepointers = 1060; //new queues by tape vid that will replace the old retrieve queues (these are pointers because queues change often and are volatile and we shouldn't lock th root entry for each change)
repeated RetrieveQueuePointer retrievequeuepointers = 1060; //new queues by tape
// vid that will replace the old retrieve queues (these are pointers because queues
// change often and are volatile and we shouldn't lock th root entry for each change)
optional DriveRegisterPointer driveregisterpointer = 1070;
optional AgentRegisterPointer agentregisterpointer = 1080;
optional string agentregisterintent = 1090;
......@@ -292,25 +274,29 @@ message RetrieveToFileRequest {
message DriveState {
required string drivename = 5000;
required string logicallibrary = 5001;
optional uint64 sessionid = 5002;
optional uint64 bytestransferedinsession = 5003;
optional uint64 filestransferedinsession = 5004;
optional double latestbandwidth = 5005;
optional uint64 sessionstarttime = 5006;
optional uint64 mountstarttime = 5007;
optional uint64 transferstarttime = 5008;
optional uint64 unloadstarttime = 5009;
optional uint64 unmountstarttime = 5010;
optional uint64 drainingstarttime = 5011;
optional uint64 downorupstarttime = 5012;
optional uint64 cleanupstarttime = 5013;
optional uint64 lastupdatetime = 5014;
required MountType mounttype = 5015;
required DriveStatus drivestatus = 5016;
optional string currentvid = 5017;
optional string currenttapepool = 5018;
required EntryLog creationlog = 5019;
required string host = 5001;
required string logicallibrary = 5002;
optional uint64 sessionid = 5003;
optional uint64 bytestransferedinsession = 5004;
optional uint64 filestransferedinsession = 5005;
optional double latestbandwidth = 5006;
optional uint64 sessionstarttime = 5007;
optional uint64 mountstarttime = 5008;
optional uint64 transferstarttime = 5009;
optional uint64 unloadstarttime = 5010;
optional uint64 unmountstarttime = 5011;
optional uint64 drainingstarttime = 5012;
optional uint64 downorupstarttime = 5013;
optional uint64 cleanupstarttime = 5014;
optional uint64 lastupdatetime = 5015;
optional uint64 startstarttime = 5016;