Commit 0e9843d9 by Jozsef Makai

MGM,FST: FST to CTA almost done

parent 8a2487d2
......@@ -1641,7 +1641,7 @@ XrdFstOfs::CallSynchronousClosew(const Fmd& fmd, const string& ownerName,
if(getenv("XRDDEBUG")) {
config.set("log", "all");
} else {
config.set("log", "info");
config.set("log", "all");
}
config.set("request_timeout", "120");
// Instantiate service object only once, static is also thread-safe
......
......@@ -1916,6 +1916,19 @@ XrdFstOfsFile::close()
eventType = "closer";
}
if (syncEventOnClose) {
std::string decodedAttributes;
eos::common::SymKey::Base64Decode(eventAttributes.c_str(), decodedAttributes);
std::map<std::string, std::string> attributes;
eos::common::StringConversion::GetKeyValueMap(decodedAttributes.c_str(), attributes, "=", ";;;", nullptr);
rc = gOFS.CallSynchronousClosew(fMd->mProtoFmd, eventOwner, eventOwnerGroup, eventInstance, capOpaque->Get("mgm.path"), attributes);
if (rc == SFS_OK) {
return rc;
}
}
capOpaqueFile += "&mgm.event=";
capOpaqueFile += eventType;
......@@ -2892,6 +2905,18 @@ XrdFstOfsFile::ProcessOpenOpaque(const std::string& in_opaque,
val = env.Get("mgm.workflow");
mEventWorkflow = (val ? val : "");
val = env.Get("mgm.instance");
eventInstance = val ? val : "";
val = env.Get("mgm.owner");
eventOwner = val ? val : "";
val = env.Get("mgm.ownergroup");
eventOwnerGroup = val ? val : "";
val = env.Get("mgm.attributes");
eventAttributes = val ? val : "";
}
if ((val = env.Get("eos.injection"))) {
......
......@@ -399,6 +399,10 @@ protected:
//! Indicates the workflow to be triggered by an event
XrdOucString mEventWorkflow;
bool syncEventOnClose; //! indicator to send a specified event to the mgm on close
std::string eventInstance;
std::string eventOwner;
std::string eventOwnerGroup;
std::string eventAttributes;
enum {
kOfsIoError = 1, //! generic IO error
......
......@@ -1695,40 +1695,9 @@ WFE::Job::DoIt(bool issync)
notification->mutable_cli()->mutable_user()->set_groupname(GetGroupName(mVid.gid));
auto collectAttributes = [&notification, &fullPath] {
eos::common::Mapping::VirtualIdentity rootvid;
eos::common::Mapping::Root(rootvid);
XrdOucErrInfo errInfo;
IContainerMD::XAttrMap fileAttributes, parentDirAttributes;
if (gOFS->_attr_ls(fullPath.c_str(),
errInfo, rootvid, nullptr, fileAttributes, true, true) == 0) {
for (const auto& fileAttrPair : fileAttributes)
{
if (fileAttrPair.first.find("sys.") == 0 ||
fileAttrPair.first.find("user.") == 0) {
continue;
}
google::protobuf::MapPair<std::string, std::string> attr(fileAttrPair.first,
fileAttrPair.second);
notification->mutable_file()->mutable_xattr()->insert(attr);
}
}
errInfo.clear();
if (gOFS->_attr_ls(eos::common::Path{fullPath.c_str()}.GetParentPath(),
errInfo, rootvid, nullptr, parentDirAttributes, true, true) == 0) {
for (const auto& dirAttrPair : parentDirAttributes)
{
if (dirAttrPair.first.find("sys.") == 0 ||
dirAttrPair.first.find("user.") == 0) {
continue;
}
google::protobuf::MapPair<std::string, std::string> attr(dirAttrPair.first,
dirAttrPair.second);
notification->mutable_file()->mutable_xattr()->insert(attr);
}
for (const auto& attribute : CollectAttributes(fullPath)) {
google::protobuf::MapPair<std::string, std::string> attr(attribute.first, attribute.second);
notification->mutable_file()->mutable_xattr()->insert(attr);
}
};
......@@ -2312,4 +2281,37 @@ WFE::PublishActiveJobs()
true);
}
IContainerMD::XAttrMap
WFE::CollectAttributes(const std::string& fullPath) {
eos::common::Mapping::VirtualIdentity rootvid;
eos::common::Mapping::Root(rootvid);
XrdOucErrInfo errInfo;
IContainerMD::XAttrMap fileAttributes, parentDirAttributes, result;
if (gOFS->_attr_ls(fullPath.c_str(),
errInfo, rootvid, nullptr, fileAttributes, true, true) == 0) {
for (const auto& fileAttrPair : fileAttributes)
{
if (fileAttrPair.first.find("sys.") != 0 &&
fileAttrPair.first.find("user.") != 0) {
result.insert(fileAttrPair);
}
}
}
errInfo.clear();
if (gOFS->_attr_ls(eos::common::Path{fullPath.c_str()}.GetParentPath(),
errInfo, rootvid, nullptr, parentDirAttributes, true, true) == 0) {
for (const auto& dirAttrPair : parentDirAttributes)
{
if (dirAttrPair.first.find("sys.") != 0 &&
dirAttrPair.first.find("user.") != 0) {
result.insert(dirAttrPair);
}
}
}
return result;
}
EOSMGMNAMESPACE_END
......@@ -309,6 +309,8 @@ public:
static std::string GetGroupName(gid_t gid);
static IContainerMD::XAttrMap CollectAttributes(const std::string& fullPath);
/// the scheduler class is providing a destructor-less object,
/// so we have to create once a singleton of this and keep/share it
static XrdSysMutex gSchedulerMutex;
......
......@@ -119,12 +119,40 @@ Workflow::getCGICloseW(std::string workflow)
// synchronous closew has priority
if (mAttr && (*mAttr).count(syncKey)) {
std::string owner, ownerGroup, fullPath;
try {
eos::common::RWMutexReadLock rlock(gOFS->eosViewRWMutex);
auto fmd = gOFS->eosFileService->getFileMD(mFid);
fullPath = gOFS->eosView->getUri(fmd.get());
owner = WFE::GetUserName(fmd->getCUid());
ownerGroup = WFE::GetGroupName(fmd->getCGid());
} catch (eos::MDException& e) {
return "";
}
auto attributes = WFE::CollectAttributes(fullPath);
std::ostringstream attrStream;
std::string separator;
for (const auto& attribute : attributes) {
attrStream << separator << attribute.first << "=" << attribute.second;
separator = ";;;";
}
auto attrStr = attrStream.str();
std::string attrEncoded;
eos::common::SymKey::Base64Encode(attrStr.c_str(), attrStr.length(), attrEncoded);
cgi = "&mgm.event=sync::closew&mgm.workflow=";
cgi += workflow;
cgi += "&mgm.instance=";
cgi += gOFS->MgmOfsInstanceName.c_str();
cgi += "&mgm.owner=";
cgi += owner;
cgi += "&mgm.ownergroup=";
cgi += ownerGroup;
cgi += "&mgm.attributes=";
cgi += attrEncoded;
} else if (mAttr && (*mAttr).count(key)) {
cgi = "&mgm.event=closew&mgm.workflow=";
cgi += workflow;
......
......@@ -2325,6 +2325,7 @@ XrdMgmOfsFile::open(const char* inpath,
}
// add workflow cgis
workflow.SetFile(path, fileId);
if (isRW) {
redirectionhost += workflow.getCGICloseW(currentWorkflow.c_str()).c_str();
} else {
......
Markdown is supported
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