Skip to content

Commit

Permalink
Handle background thread when updating/removing Aviso or Remote attri…
Browse files Browse the repository at this point in the history
…bute
  • Loading branch information
marcosbento committed May 15, 2024
1 parent ec4780e commit fcd01c1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
4 changes: 2 additions & 2 deletions libs/base/src/ecflow/base/cts/user/AlterCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ STC_Cmd_ptr AlterCmd::doHandleRequest(AbstractServer* as) const {
node->addDay(DayAttr::create(name_));
break;
case AlterCmd::ADD_AVISO: {
auto aviso = AvisoParser::parse_aviso_line(value_, name_);
auto aviso = AvisoParser::parse_aviso_line(value_, name_, node.get());
node->addAviso(aviso);
break;
}
case AlterCmd::ADD_MIRROR: {
auto mirror = MirrorParser::parse_mirror_line(value_, name_);
auto mirror = MirrorParser::parse_mirror_line(value_, name_, node.get());
node->addMirror(mirror);
break;
}
Expand Down
9 changes: 8 additions & 1 deletion libs/node/src/ecflow/node/MirrorAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ MirrorAttr::MirrorAttr(Node* parent,
if (!is_valid_name(name_)) {
throw ecf::InvalidArgument(ecf::Message("Invalid MirrorAttr name :", name_));
}
};
}

MirrorAttr::~MirrorAttr() {
if (controller_ != nullptr) {
controller_->stop();
controller_.reset();
}
}

void MirrorAttr::poke() {
ALOG(D, "**** Check Mirror attribute (name: " << name_ << ")");
Expand Down
3 changes: 3 additions & 0 deletions libs/node/src/ecflow/node/MirrorAttr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MirrorAttr {
remote_port_t remote_port,
polling_t polling);
MirrorAttr(const MirrorAttr& rhs) = default;
~MirrorAttr();

MirrorAttr& operator=(const MirrorAttr& rhs) = default;

Expand All @@ -71,6 +72,8 @@ class MirrorAttr {
[[nodiscard]] inline const std::string& remote_port() const { return remote_port_; }
[[nodiscard]] inline polling_t polling() const { return polling_; }

void set_parent(Node* parent) { parent_ = parent; }

unsigned int state_change_no() const { return state_change_no_; }

bool why(std::string& theReasonWhy) const;
Expand Down
14 changes: 11 additions & 3 deletions libs/node/src/ecflow/node/NodeChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ void Node::changeAviso(const std::string& name, const std::string& value, uint64
throw std::runtime_error("Node::changeAviso: Could not find aviso " + name);
}

*found = AvisoParser::parse_aviso_line(value, name);
found->set_revision(revision);
auto attr = AvisoParser::parse_aviso_line(value, name);
attr.set_revision(revision);

// The following delete/add enforces the reconfiguration of the attribute backend thread
this->deleteAviso(name); // delete the aviso if it exists (to avoid duplicates
this->addAviso(attr);

state_change_no_ = Ecf::incr_state_change_no();
}
Expand All @@ -197,7 +201,11 @@ void Node::changeMirror(const std::string& name, const std::string& value) {
throw std::runtime_error("Node::changeMirror: Could not find mirror " + name);
}

*found = MirrorParser::parse_mirror_line(value, name);
auto attr = MirrorParser::parse_mirror_line(value, name, this);

// The following delete/add enforces the reconfiguration of the attribute backend thread
this->deleteMirror(name); // delete the mirror if it exists (to avoid duplicates
this->addMirror(attr);

state_change_no_ = Ecf::incr_state_change_no();
}
Expand Down
6 changes: 5 additions & 1 deletion libs/node/src/ecflow/node/parser/AvisoParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ ecf::AvisoAttr AvisoParser::parse_aviso_line(const std::string& line) {
}

ecf::AvisoAttr AvisoParser::parse_aviso_line(const std::string& line, const std::string& name) {
return parse_aviso_line(line, name, nullptr);
}

ecf::AvisoAttr AvisoParser::parse_aviso_line(const std::string& line, const std::string& name, Node* parent) {
auto updated_line = line + " --name " + name;
return parse_aviso_line(updated_line, nullptr);
return parse_aviso_line(updated_line, parent);
}

ecf::AvisoAttr AvisoParser::parse_aviso_line(const std::string& line, Node* parent) {
Expand Down
1 change: 1 addition & 0 deletions libs/node/src/ecflow/node/parser/AvisoParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AvisoParser : public Parser {

static ecf::AvisoAttr parse_aviso_line(const std::string& line);
static ecf::AvisoAttr parse_aviso_line(const std::string& line, const std::string& name);
static ecf::AvisoAttr parse_aviso_line(const std::string& line, const std::string& name, Node* parent);
static ecf::AvisoAttr parse_aviso_line(const std::string& line, Node* parent);

explicit AvisoParser(DefsStructureParser* p) : Parser(p) {}
Expand Down
8 changes: 6 additions & 2 deletions libs/node/src/ecflow/node/parser/MirrorParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ ecf::MirrorAttr MirrorParser::parse_mirror_line(const std::string& line) {
}

ecf::MirrorAttr MirrorParser::parse_mirror_line(const std::string& line, const std::string& name) {
return parse_mirror_line(line, name, nullptr);
}

ecf::MirrorAttr MirrorParser::parse_mirror_line(const std::string& line, const std::string& name, Node* parent) {
auto updated_line = line + " --name " + name;
return parse_mirror_line(updated_line, nullptr);
return parse_mirror_line(updated_line, parent);
}

ecf::MirrorAttr MirrorParser::parse_mirror_line(const std::string& line, Node* parent) {
Expand Down Expand Up @@ -78,7 +82,7 @@ ecf::MirrorAttr MirrorParser::parse_mirror_line(const std::string& line, Node* p

bool MirrorParser::doParse(const std::string& line, std::vector<std::string>& lineTokens) {
if (nodeStack().empty()) {
throw std::runtime_error("AvisoParser::doParse: Could not add aviso as node stack is empty at line: " + line);
throw std::runtime_error("MirrorParser::doParse: Could not add 'mirror' as node stack is empty at line: " + line);
}

Node* parent = nodeStack_top();
Expand Down
1 change: 1 addition & 0 deletions libs/node/src/ecflow/node/parser/MirrorParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MirrorParser : public Parser {

static ecf::MirrorAttr parse_mirror_line(const std::string& line);
static ecf::MirrorAttr parse_mirror_line(const std::string& line, const std::string& name);
static ecf::MirrorAttr parse_mirror_line(const std::string& line, const std::string& name, Node* parent);
static ecf::MirrorAttr parse_mirror_line(const std::string& line, Node* parent);

explicit MirrorParser(DefsStructureParser* p) : Parser(p) {}
Expand Down

0 comments on commit fcd01c1

Please sign in to comment.