7#include "ui_clusterWidget.h"
12#include <QRadioButton>
38 ui->executeBtn->setDisabled(
true);
72 yError()<<
"ClusterWidget:Unable parse cluster-config.xml in context iCubCluster";
78 ui->lineEditUser->setText(cluster.
user.c_str());
79 ui->lineEditNs->setText(cluster.
nameSpace.c_str());
88 l.push_back(cluster.
nsNode.c_str());
90 for (
auto& node:cluster.
nodes)
92 addRow(node.name, node.displayValue, node.user, node.address, node.onOff, node.log, i);
94 if (cluster.
nsNode == node.name) {
97 l.push_back(node.name.c_str());
101 ui->executeComboBox->addItems(
l);
102 ui->executeComboBox->setEditable(
true);
104 ui->nsNodeComboBox->addItems(
l);
105 ui->nsNodeComboBox->setEditable(
true);
113 ui->nodestreeWidget->header()->resizeSection(0, 50);
115 onNodeSelectionChanged();
119void ClusterWidget::onCheckAll()
121 for (
int i = 0; i<ui->nodestreeWidget->topLevelItemCount(); i++)
123 QTreeWidgetItem *
it = ui->nodestreeWidget->topLevelItem(i);
124 int itr =
it->text(6).toInt();
126 if (checkNode(node.
name))
128 cluster.
nodes[itr].onOff=
true;
129 it->setIcon(0,
QIcon(
":/computer-available22.svg"));
133 cluster.
nodes[itr].onOff=
false;
134 it->setIcon(0,
QIcon(
":/computer-unavailable22.svg"));
140void ClusterWidget::onCheckServer()
142 checkNs = checkNameserver();
150 ui->checkRos->setDisabled(checkNs);
151 ui->runServerBtn->setDisabled(checkNs);
152 ui->nsNodeComboBox->setDisabled(checkNs);
153 ui->stopServerBtn->setDisabled(!checkNs);
156void ClusterWidget::onRunServer()
158 updateServerEntries();
162 if (ui->checkRos->isChecked())
172 std::string err =
"ClusterWidget: failed to run the server on " + cluster.
nsNode;
183void ClusterWidget::onStopServer()
185 updateServerEntries();
187 auto count = std::count_if(cluster.
nodes.begin(), cluster.
nodes.end(),
192 auto reply = QMessageBox::warning(
this,
"Shutting down yarpserver",
193 "You have some yarprun on execution."
194 " After shutting down yarpserver you might not be able to recover them."
196 QMessageBox::Yes|QMessageBox::No);
197 if (reply== QMessageBox::No) {
210 std::string err =
"ClusterWidget: failed to stop the server on " + cluster.
nsNode;
227 std::string
info =
"ClusterWidget: yarpserver successfully stopped on "+ cluster.
nsNode;
232void ClusterWidget::onKillServer()
234 updateServerEntries();
243 std::string err =
"ClusterWidget: failed to kill the server on " + cluster.
nsNode;
249 std::string
info =
"ClusterWidget: yarpserver successfully killed on "+ cluster.
nsNode;
256void ClusterWidget::onRunSelected()
261 int itr =
it->text(6).toInt();
263 std::string portName = node.
name;
265 if (portName.find(
'/') == std::string::npos)
267 portName.insert(0, 1,
'/');
283 cmdRunYarprun.append(
" yarprun --server ").append(portName).append(
" --log 2>&1 2>/tmp/yarprunserver.log");
287 cmdRunYarprun.append(
" yarprun --server ").append(portName).append(
" 2>&1 2>/tmp/yarprunserver.log");
297 std::string err =
"ClusterWidget: failed to run yarprun on " + node.
name;
303 std::string
info =
"ClusterWidget: yarprun successfully executed on "+ node.
name;
313void ClusterWidget::onStopSelected()
318 int itr =
it->text(6).toInt();
324 std::string portName = node.
name;
325 if (portName.find(
'/') == std::string::npos)
327 portName.insert(0, 1,
'/');
332 cmdStopYarprun.append(
" yarprun --exit --on ").append(portName).append(
" &");
337 std::string err =
"ClusterWidget: failed to stop yarprun on " + node.
name;
343 std::string
info =
"ClusterWidget: yarprun successfully stopped on "+ node.
name;
352void ClusterWidget::onKillSelected()
357 int itr =
it->text(6).toInt();
371 std::string err =
"ClusterWidget: failed to kill yarprun on " + node.
name;
377 std::string
info =
"ClusterWidget: yarprun successfully killed on "+ node.
name;
385void ClusterWidget::onExecute()
387 if (ui->lineEditExecute->text().trimmed().size() == 0)
392 auto nodeName = ui->executeComboBox->currentText();
394 if (nodeName.trimmed().size() == 0)
400 [&nodeName](
const ClusterNode&
n){ return n.name == nodeName.toStdString(); });
409 auto command = ui->lineEditExecute->text().toStdString();
418 std::string err =
"ClusterWidget: failed to run "+ command +
" on " + node.
name;
424 std::string
info =
"ClusterWidget: command "+ command +
" successfully executed on " + node.
name;
428 ui->lineEditExecute->clear();
431void ClusterWidget::onNodeSelectionChanged()
433 if(ui->nodestreeWidget->selectedItems().isEmpty())
435 ui->runSelBtn->setDisabled(
true);
436 ui->stopSelBtn->setDisabled(
true);
437 ui->killSelBtn->setDisabled(
true);
441 ui->runSelBtn->setDisabled(!checkNs);
442 ui->stopSelBtn->setDisabled(!checkNs);
443 ui->killSelBtn->setDisabled(!checkNs);
448void ClusterWidget::onExecuteTextChanged()
450 if (ui->lineEditExecute->text().trimmed().size() > 0) {
451 ui->executeBtn->setDisabled(
false);
453 ui->executeBtn->setDisabled(
true);
459void ClusterWidget::addRow(
const std::string& name,
const std::string& display,
460 const std::string& user,
const std::string& address,
461 bool onOff,
bool log,
int id)
466 ui->nodestreeWidget->addTopLevelItem(
it);
467 ui->nodestreeWidget->setItemWidget((QTreeWidgetItem *)
it, 5,
new QCheckBox(
this));
475 it->setIcon(0,
QIcon(
":/computer-available22.svg"));
479 it->setIcon(0,
QIcon(
":/computer-unavailable22.svg"));
484std::string ClusterWidget::getSSHCmd(
const std::string &user,
const std::string &host,
const std::string &ssh_options)
488 if (!ssh_options.empty())
490 cmd = cmd +
" " + ssh_options;
494 cmd = cmd +
" " + host;
498 cmd = cmd +
" " + user +
"@" +host;
504bool ClusterWidget::checkNameserver()
506 std::string name = ui->lineEditNs->text().toStdString();
513 if (name.find(
'/') == std::string::npos)
521 yError()<<
"ClusterWidget: yarpserver is not running";
533 yError()<<
"ClusterWidget: Cannot contact the NameClient";
554bool ClusterWidget::checkNode(
const std::string &name)
556 std::string portname = name;
557 if (portname.find(
'/') == std::string::npos)
559 portname =
"/" + portname;
564 yError()<<
"ClusterWidget: yarpserver is not running";
571 yError()<<
"ClusterWidget: port"<<portname<<
"is not responding";
583 yError()<<
"ClusterWidget: Cannot contact the NameClient";
605void ClusterWidget::updateServerEntries()
608 cluster.
user = ui->lineEditUser->text().simplified().trimmed().toStdString();
609 cluster.
nsNode = ui->nsNodeComboBox->currentText().simplified().trimmed().toStdString();
612void ClusterWidget::reportErrors()
631 clusLoader =
nullptr;
int SIGNAL(int pid, int signum)
Singleton class ErrorLogger.
const char * getLastError()
void addError(const char *szError)
static ErrorLogger * Instance()
Singleton class ErrorLogger.
bool parseXmlFile(Cluster &_cluster)
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A mini-server for performing network communication in the background.
static bool checkNetwork()
Check if the YARP Network is up and running.
virtual bool asBool() const
Get boolean value.
static NameClient & getNameClient()
Get an instance of the name client.
static bool getPortDetails(const std::string &portName, PortDetails &info)
void delay(double seconds)
Wait for a certain number of seconds.
An interface to the operating system, including Port based communication.
std::vector< ClusterNode > nodes