Commit 9f8b765d authored by Steven Murray's avatar Steven Murray
Browse files

Filled out castor::messages::ForkLabel

parent 32a050b0
......@@ -31,7 +31,7 @@ namespace castor {
namespace legacymsg {
/**
* The body of an RMC_SCSI_MOUNT message.
* The body of a TPLABEL message.
*/
struct TapeLabelRqstMsgBody {
uint16_t force; // set to 1 if force==true, 0 otherwise
......
This diff is collapsed.
......@@ -101,10 +101,87 @@ class ForkLabel : public ::google::protobuf::Message {
inline void set_unitname(const char* value, size_t size);
inline ::std::string* mutable_unitname();
// required string vid = 2;
// required string dgn = 2;
inline bool has_dgn() const;
inline void clear_dgn();
static const int kDgnFieldNumber = 2;
inline const ::std::string& dgn() const;
inline void set_dgn(const ::std::string& value);
inline void set_dgn(const char* value);
inline void set_dgn(const char* value, size_t size);
inline ::std::string* mutable_dgn();
// required string devfilename = 3;
inline bool has_devfilename() const;
inline void clear_devfilename();
static const int kDevfilenameFieldNumber = 3;
inline const ::std::string& devfilename() const;
inline void set_devfilename(const ::std::string& value);
inline void set_devfilename(const char* value);
inline void set_devfilename(const char* value, size_t size);
inline ::std::string* mutable_devfilename();
// repeated string density = 4;
inline int density_size() const;
inline void clear_density();
static const int kDensityFieldNumber = 4;
inline const ::std::string& density(int index) const;
inline ::std::string* mutable_density(int index);
inline void set_density(int index, const ::std::string& value);
inline void set_density(int index, const char* value);
inline void set_density(int index, const char* value, size_t size);
inline ::std::string* add_density();
inline void add_density(const ::std::string& value);
inline void add_density(const char* value);
inline void add_density(const char* value, size_t size);
inline const ::google::protobuf::RepeatedPtrField< ::std::string>& density() const;
inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_density();
// required string libraryslot = 5;
inline bool has_libraryslot() const;
inline void clear_libraryslot();
static const int kLibraryslotFieldNumber = 5;
inline const ::std::string& libraryslot() const;
inline void set_libraryslot(const ::std::string& value);
inline void set_libraryslot(const char* value);
inline void set_libraryslot(const char* value, size_t size);
inline ::std::string* mutable_libraryslot();
// required string devtype = 6;
inline bool has_devtype() const;
inline void clear_devtype();
static const int kDevtypeFieldNumber = 6;
inline const ::std::string& devtype() const;
inline void set_devtype(const ::std::string& value);
inline void set_devtype(const char* value);
inline void set_devtype(const char* value, size_t size);
inline ::std::string* mutable_devtype();
// required bool force = 7;
inline bool has_force() const;
inline void clear_force();
static const int kForceFieldNumber = 7;
inline bool force() const;
inline void set_force(bool value);
// required uint32 uid = 8;
inline bool has_uid() const;
inline void clear_uid();
static const int kUidFieldNumber = 8;
inline ::google::protobuf::uint32 uid() const;
inline void set_uid(::google::protobuf::uint32 value);
// required uint32 gid = 9;
inline bool has_gid() const;
inline void clear_gid();
static const int kGidFieldNumber = 9;
inline ::google::protobuf::uint32 gid() const;
inline void set_gid(::google::protobuf::uint32 value);
// required string vid = 10;
inline bool has_vid() const;
inline void clear_vid();
static const int kVidFieldNumber = 2;
static const int kVidFieldNumber = 10;
inline const ::std::string& vid() const;
inline void set_vid(const ::std::string& value);
inline void set_vid(const char* value);
......@@ -118,13 +195,25 @@ class ForkLabel : public ::google::protobuf::Message {
::std::string* unitname_;
static const ::std::string _default_unitname_;
::std::string* dgn_;
static const ::std::string _default_dgn_;
::std::string* devfilename_;
static const ::std::string _default_devfilename_;
::google::protobuf::RepeatedPtrField< ::std::string> density_;
::std::string* libraryslot_;
static const ::std::string _default_libraryslot_;
::std::string* devtype_;
static const ::std::string _default_devtype_;
bool force_;
::google::protobuf::uint32 uid_;
::google::protobuf::uint32 gid_;
::std::string* vid_;
static const ::std::string _default_vid_;
friend void protobuf_AddDesc_ForkLabel_2eproto();
friend void protobuf_AssignDesc_ForkLabel_2eproto();
friend void protobuf_ShutdownFile_ForkLabel_2eproto();
::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
::google::protobuf::uint32 _has_bits_[(10 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
inline bool _has_bit(int index) const {
......@@ -189,42 +278,302 @@ inline ::std::string* ForkLabel::mutable_unitname() {
return unitname_;
}
// required string vid = 2;
inline bool ForkLabel::has_vid() const {
// required string dgn = 2;
inline bool ForkLabel::has_dgn() const {
return _has_bit(1);
}
inline void ForkLabel::clear_dgn() {
if (dgn_ != &_default_dgn_) {
dgn_->clear();
}
_clear_bit(1);
}
inline const ::std::string& ForkLabel::dgn() const {
return *dgn_;
}
inline void ForkLabel::set_dgn(const ::std::string& value) {
_set_bit(1);
if (dgn_ == &_default_dgn_) {
dgn_ = new ::std::string;
}
dgn_->assign(value);
}
inline void ForkLabel::set_dgn(const char* value) {
_set_bit(1);
if (dgn_ == &_default_dgn_) {
dgn_ = new ::std::string;
}
dgn_->assign(value);
}
inline void ForkLabel::set_dgn(const char* value, size_t size) {
_set_bit(1);
if (dgn_ == &_default_dgn_) {
dgn_ = new ::std::string;
}
dgn_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ForkLabel::mutable_dgn() {
_set_bit(1);
if (dgn_ == &_default_dgn_) {
dgn_ = new ::std::string;
}
return dgn_;
}
// required string devfilename = 3;
inline bool ForkLabel::has_devfilename() const {
return _has_bit(2);
}
inline void ForkLabel::clear_devfilename() {
if (devfilename_ != &_default_devfilename_) {
devfilename_->clear();
}
_clear_bit(2);
}
inline const ::std::string& ForkLabel::devfilename() const {
return *devfilename_;
}
inline void ForkLabel::set_devfilename(const ::std::string& value) {
_set_bit(2);
if (devfilename_ == &_default_devfilename_) {
devfilename_ = new ::std::string;
}
devfilename_->assign(value);
}
inline void ForkLabel::set_devfilename(const char* value) {
_set_bit(2);
if (devfilename_ == &_default_devfilename_) {
devfilename_ = new ::std::string;
}
devfilename_->assign(value);
}
inline void ForkLabel::set_devfilename(const char* value, size_t size) {
_set_bit(2);
if (devfilename_ == &_default_devfilename_) {
devfilename_ = new ::std::string;
}
devfilename_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ForkLabel::mutable_devfilename() {
_set_bit(2);
if (devfilename_ == &_default_devfilename_) {
devfilename_ = new ::std::string;
}
return devfilename_;
}
// repeated string density = 4;
inline int ForkLabel::density_size() const {
return density_.size();
}
inline void ForkLabel::clear_density() {
density_.Clear();
}
inline const ::std::string& ForkLabel::density(int index) const {
return density_.Get(index);
}
inline ::std::string* ForkLabel::mutable_density(int index) {
return density_.Mutable(index);
}
inline void ForkLabel::set_density(int index, const ::std::string& value) {
density_.Mutable(index)->assign(value);
}
inline void ForkLabel::set_density(int index, const char* value) {
density_.Mutable(index)->assign(value);
}
inline void ForkLabel::set_density(int index, const char* value, size_t size) {
density_.Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ForkLabel::add_density() {
return density_.Add();
}
inline void ForkLabel::add_density(const ::std::string& value) {
density_.Add()->assign(value);
}
inline void ForkLabel::add_density(const char* value) {
density_.Add()->assign(value);
}
inline void ForkLabel::add_density(const char* value, size_t size) {
density_.Add()->assign(reinterpret_cast<const char*>(value), size);
}
inline const ::google::protobuf::RepeatedPtrField< ::std::string>&
ForkLabel::density() const {
return density_;
}
inline ::google::protobuf::RepeatedPtrField< ::std::string>*
ForkLabel::mutable_density() {
return &density_;
}
// required string libraryslot = 5;
inline bool ForkLabel::has_libraryslot() const {
return _has_bit(4);
}
inline void ForkLabel::clear_libraryslot() {
if (libraryslot_ != &_default_libraryslot_) {
libraryslot_->clear();
}
_clear_bit(4);
}
inline const ::std::string& ForkLabel::libraryslot() const {
return *libraryslot_;
}
inline void ForkLabel::set_libraryslot(const ::std::string& value) {
_set_bit(4);
if (libraryslot_ == &_default_libraryslot_) {
libraryslot_ = new ::std::string;
}
libraryslot_->assign(value);
}
inline void ForkLabel::set_libraryslot(const char* value) {
_set_bit(4);
if (libraryslot_ == &_default_libraryslot_) {
libraryslot_ = new ::std::string;
}
libraryslot_->assign(value);
}
inline void ForkLabel::set_libraryslot(const char* value, size_t size) {
_set_bit(4);
if (libraryslot_ == &_default_libraryslot_) {
libraryslot_ = new ::std::string;
}
libraryslot_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ForkLabel::mutable_libraryslot() {
_set_bit(4);
if (libraryslot_ == &_default_libraryslot_) {
libraryslot_ = new ::std::string;
}
return libraryslot_;
}
// required string devtype = 6;
inline bool ForkLabel::has_devtype() const {
return _has_bit(5);
}
inline void ForkLabel::clear_devtype() {
if (devtype_ != &_default_devtype_) {
devtype_->clear();
}
_clear_bit(5);
}
inline const ::std::string& ForkLabel::devtype() const {
return *devtype_;
}
inline void ForkLabel::set_devtype(const ::std::string& value) {
_set_bit(5);
if (devtype_ == &_default_devtype_) {
devtype_ = new ::std::string;
}
devtype_->assign(value);
}
inline void ForkLabel::set_devtype(const char* value) {
_set_bit(5);
if (devtype_ == &_default_devtype_) {
devtype_ = new ::std::string;
}
devtype_->assign(value);
}
inline void ForkLabel::set_devtype(const char* value, size_t size) {
_set_bit(5);
if (devtype_ == &_default_devtype_) {
devtype_ = new ::std::string;
}
devtype_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ForkLabel::mutable_devtype() {
_set_bit(5);
if (devtype_ == &_default_devtype_) {
devtype_ = new ::std::string;
}
return devtype_;
}
// required bool force = 7;
inline bool ForkLabel::has_force() const {
return _has_bit(6);
}
inline void ForkLabel::clear_force() {
force_ = false;
_clear_bit(6);
}
inline bool ForkLabel::force() const {
return force_;
}
inline void ForkLabel::set_force(bool value) {
_set_bit(6);
force_ = value;
}
// required uint32 uid = 8;
inline bool ForkLabel::has_uid() const {
return _has_bit(7);
}
inline void ForkLabel::clear_uid() {
uid_ = 0u;
_clear_bit(7);
}
inline ::google::protobuf::uint32 ForkLabel::uid() const {
return uid_;
}
inline void ForkLabel::set_uid(::google::protobuf::uint32 value) {
_set_bit(7);
uid_ = value;
}
// required uint32 gid = 9;
inline bool ForkLabel::has_gid() const {
return _has_bit(8);
}
inline void ForkLabel::clear_gid() {
gid_ = 0u;
_clear_bit(8);
}
inline ::google::protobuf::uint32 ForkLabel::gid() const {
return gid_;
}
inline void ForkLabel::set_gid(::google::protobuf::uint32 value) {
_set_bit(8);
gid_ = value;
}
// required string vid = 10;
inline bool ForkLabel::has_vid() const {
return _has_bit(9);
}
inline void ForkLabel::clear_vid() {
if (vid_ != &_default_vid_) {
vid_->clear();
}
_clear_bit(1);
_clear_bit(9);
}
inline const ::std::string& ForkLabel::vid() const {
return *vid_;
}
inline void ForkLabel::set_vid(const ::std::string& value) {
_set_bit(1);
_set_bit(9);
if (vid_ == &_default_vid_) {
vid_ = new ::std::string;
}
vid_->assign(value);
}
inline void ForkLabel::set_vid(const char* value) {
_set_bit(1);
_set_bit(9);
if (vid_ == &_default_vid_) {
vid_ = new ::std::string;
}
vid_->assign(value);
}
inline void ForkLabel::set_vid(const char* value, size_t size) {
_set_bit(1);
_set_bit(9);
if (vid_ == &_default_vid_) {
vid_ = new ::std::string;
}
vid_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ForkLabel::mutable_vid() {
_set_bit(1);
_set_bit(9);
if (vid_ == &_default_vid_) {
vid_ = new ::std::string;
}
......
......@@ -21,6 +21,17 @@
package castor.messages;
message ForkLabel {
// Description of the tape drive
required string unitname = 1;
required string vid = 2;
required string dgn = 2;
required string devfilename = 3;
repeated string density = 4;
required string libraryslot = 5;
required string devtype = 6;
// Description of the label job
required bool force = 7;
required uint32 uid = 8;
required uint32 gid = 9;
required string vid = 10;
}
......@@ -22,6 +22,7 @@
*****************************************************************************/
#include "castor/exception/Exception.hpp"
#include "castor/legacymsg/NsProxy_TapeAlwaysEmpty.hpp"
#include "castor/legacymsg/RmcProxyTcpIp.hpp"
#include "castor/messages/ForkCleaner.pb.h"
#include "castor/messages/ForkDataTransfer.pb.h"
......@@ -32,6 +33,7 @@
#include "castor/messages/StopProcessForker.pb.h"
#include "castor/messages/TapeserverProxyZmq.hpp"
#include "castor/tape/tapeserver/daemon/Constants.hpp"
#include "castor/tape/tapeserver/daemon/LabelSession.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForker.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForkerMsgType.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForkerUtils.hpp"
......@@ -441,8 +443,20 @@ castor::tape::tapeserver::daemon::ProcessForker::MsgHandlerResult
} else {
closeCmdReceiverSocket();
// TO BE DONE
exit(0);
try {
exit(runLabelSession(rqst));
} catch(castor::exception::Exception &ne) {
log::Param params[] = {log::Param("message", ne.getMessage().str())};
m_log(LOG_ERR, "Failed to run label session", params);
} catch(std::exception &ne) {
log::Param params[] = {log::Param("message", ne.what())};
m_log(LOG_ERR, "Failed to run label session", params);
} catch(...) {
log::Param params[] = {log::Param("message",
"Caught an unknown exception")};
m_log(LOG_ERR, "Failed to run label session", params);
}
exit(1);
}
}
......@@ -547,25 +561,6 @@ int castor::tape::tapeserver::daemon::ProcessForker::runDataTransferSession(
return dataTransferSession->execute();
}
//------------------------------------------------------------------------------
// getDriveConfig
//------------------------------------------------------------------------------
castor::tape::utils::DriveConfig
castor::tape::tapeserver::daemon::ProcessForker::getDriveConfig(
const messages::ForkDataTransfer &msg) {
utils::DriveConfig config;
config.unitName = msg.unitname();
config.dgn = msg.dgn();
config.devFilename = msg.devfilename();
for(int i=0; i < msg.density_size(); i++) {
config.densities.push_back(msg.density(i));
}
config.librarySlot = msg.libraryslot();
config.devType = msg.devtype();
return config;
}
//------------------------------------------------------------------------------
// getDataTransferConfig
//------------------------------------------------------------------------------
......@@ -784,3 +779,69 @@ void castor::tape::tapeserver::daemon::ProcessForker::
throw ex;
}
}
//------------------------------------------------------------------------------
// runLabelSession
//------------------------------------------------------------------------------
int castor::tape::tapeserver::daemon::ProcessForker::runLabelSession(
const messages::ForkLabel &rqst) {
try {
const utils::DriveConfig &driveConfig = getDriveConfig(rqst);
const legacymsg::TapeLabelRqstMsgBody labelJob = getLabelJob(rqst);
std::list<log::Param> params;
params.push_back(log::Param("unitName", driveConfig.unitName));
params.push_back(log::Param("vid", labelJob.vid));
m_log(LOG_INFO, "Label-session child-process started", params);
// TO BE DONE
exit(0);
const int netTimeout = 10; // Timeout in seconds
legacymsg::RmcProxyTcpIp rmc(m_log, netTimeout);
legacymsg::NsProxy_TapeAlwaysEmpty ns;
castor::tape::System::realWrapper sWrapper;
// TO BE DONE
const int labelCmdConnection = -1;
LabelSession labelsession(
labelCmdConnection,
rmc,
ns,
labelJob,
m_log,
sWrapper,
driveConfig,
rqst.force());
labelsession.execute();
return 0;
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to run label session: " << ne.getMessage().str();
throw ex;
} catch(std::exception &se) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to run label session: " << se.what();
throw ex;
} catch(...) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to run label session"
": Caught an unknown exception";
throw ex;
}
}
//------------------------------------------------------------------------------
// getLabelJob
//------------------------------------------------------------------------------
castor::legacymsg::TapeLabelRqstMsgBody
castor::tape::tapeserver::daemon::ProcessForker::getLabelJob(
const messages::ForkLabel &msg) {
castor::legacymsg::TapeLabelRqstMsgBody job;
job.force = msg.force() ? 1 : 0;
job.uid = msg.uid();
job.gid = msg.gid();
castor::utils::copyString(job.vid,msg.vid());
castor::utils::copyString(job.drive, msg.unitname());
castor::utils::copyString(job.dgn, msg.dgn());
return job;
}