From 784a8a9d2c769962478b65f8614d9b07e9188963 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 6 Sep 2018 18:56:47 +0200 Subject: [PATCH] QualifiedResourceNameTypeConverter: added extra field for job_id --- core/src/filed/dir_cmd.cc | 2 +- .../qualified_resource_name_type_converter.cc | 30 +++++++++++++++++-- .../qualified_resource_name_type_converter.h | 3 +- core/src/lib/res.cc | 3 +- ...ified_resource_name_type_converter_test.cc | 11 +++++-- 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/core/src/filed/dir_cmd.cc b/core/src/filed/dir_cmd.cc index 27512b867e9..a6c61fae4de 100644 --- a/core/src/filed/dir_cmd.cc +++ b/core/src/filed/dir_cmd.cc @@ -1590,7 +1590,7 @@ static bool StorageCmd(JobControlRecord *jcr) jcr->store_bsock = sd; if (!my_config->GetQualifiedResourceNameTypeConverter()->ResourceToString( - jcr->client_name, my_config->r_own_, qualified_resource_name)) { + jcr->client_name, my_config->r_own_, jcr->JobId, qualified_resource_name)) { goto bail_out; } diff --git a/core/src/lib/qualified_resource_name_type_converter.cc b/core/src/lib/qualified_resource_name_type_converter.cc index 8a1444e3598..ef7a0ff96ea 100644 --- a/core/src/lib/qualified_resource_name_type_converter.cc +++ b/core/src/lib/qualified_resource_name_type_converter.cc @@ -77,6 +77,19 @@ bool QualifiedResourceNameTypeConverter::ResourceToString(const std::string &nam return true; } +bool QualifiedResourceNameTypeConverter::ResourceToString(const std::string &name_of_resource, + const int &r_type, + const int &job_id, + std::string &out) const +{ + std::string r_name = ResourceTypeToString(r_type); + if (r_name.empty()) { + return false; + } + out = r_name + std::string(":") + name_of_resource + std::string(":") + std::to_string(job_id); + return true; +} + template void split(const std::string &str, Container &cont, char delim, int max_substring) { @@ -91,11 +104,12 @@ void split(const std::string &str, Container &cont, char delim, int max_substrin bool QualifiedResourceNameTypeConverter::StringToResource(std::string &name_of_resource, int &r_type, + int &job_id, const std::string &in) const { std::vector string_list; - split(in, string_list, ':', 2); - if (string_list.size() < 2) { + split(in, string_list, ':', 3); + if (string_list.size() < 2) { /* minimum of parameters are name and r_type */ return false; } std::string r_type_str = string_list.at(0); @@ -105,5 +119,17 @@ bool QualifiedResourceNameTypeConverter::StringToResource(std::string &name_of_r } r_type = r_type_eval; name_of_resource = string_list.at(1); + + if (string_list.size() == 3) { + int job_id_temp; + std::string job_id_str = string_list.at(2); + try { + job_id_temp = std::stoi(job_id_str); + } + catch (const std::exception &e) { + return false; + } + job_id = job_id_temp; + } return true; } diff --git a/core/src/lib/qualified_resource_name_type_converter.h b/core/src/lib/qualified_resource_name_type_converter.h index 83e6bf6a791..60b3e077a0e 100644 --- a/core/src/lib/qualified_resource_name_type_converter.h +++ b/core/src/lib/qualified_resource_name_type_converter.h @@ -28,7 +28,8 @@ class QualifiedResourceNameTypeConverter { public: QualifiedResourceNameTypeConverter(std::map map); bool ResourceToString(const std::string &name_of_resource, const int &r_type, std::string &out) const; - bool StringToResource(std::string &name_of_resource, int &r_type, const std::string &in) const; + bool ResourceToString(const std::string &name_of_resource, const int &r_type, const int &JobId, std::string &out) const; + bool StringToResource(std::string &name_of_resource, int &r_type, int &job_id, const std::string &in) const; private: std::map type_name_relation_map_; diff --git a/core/src/lib/res.cc b/core/src/lib/res.cc index f6840b38583..eefedaa103f 100644 --- a/core/src/lib/res.cc +++ b/core/src/lib/res.cc @@ -148,8 +148,9 @@ bool ConfigurationParser::GetTlsPskByFullyQualifiedResourceName(ConfigurationPar free(fq_name_buffer); int r_type; + int job_id; std::string name; - bool ok = config->GetQualifiedResourceNameTypeConverter()->StringToResource(name, r_type, fq_name_in); + bool ok = config->GetQualifiedResourceNameTypeConverter()->StringToResource(name, r_type, job_id, fq_name_in); if (!ok || r_type < 0) { return false; } TlsResource *tls = reinterpret_cast(config->GetResWithName(r_type, name.c_str())); if (tls) { diff --git a/core/src/lib/unittests/qualified_resource_name_type_converter_test.cc b/core/src/lib/unittests/qualified_resource_name_type_converter_test.cc index bb09fc2fa5c..389e40d9b5e 100644 --- a/core/src/lib/unittests/qualified_resource_name_type_converter_test.cc +++ b/core/src/lib/unittests/qualified_resource_name_type_converter_test.cc @@ -67,11 +67,18 @@ TEST(QualifiedResourceNameTypeConverter, ResourceTypeToString) std::string name; int r_type; - ok = c.StringToResource(name, r_type, "kOne:Developer"); + int job_id = -1; + ok = c.StringToResource(name, r_type, job_id, "kOne:Developer:123"); EXPECT_EQ(ok, true); EXPECT_EQ(r_type, kOne); + EXPECT_EQ(job_id, 123); EXPECT_STREQ(name.c_str(), "Developer"); - ok = c.StringToResource(name, r_type, "kOneDeveloper"); + ok = c.StringToResource(name, r_type, job_id, "kOneDeveloper"); EXPECT_EQ(ok, false); + + job_id = -1; + ok = c.StringToResource(name, r_type, job_id, "kOne:Developer"); + EXPECT_EQ(ok, true); + EXPECT_EQ(job_id, -1); }