Commit daa94edb authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

don't use qsettings for server parameters, instead use arguments to methods.

parent f3a24075
......@@ -18,9 +18,16 @@ ApplicationWindow {
ListModel {
id: servers
ListElement { text: "http://localhost" }
ListElement { text: "http://nef-devel.inria.fr" }
ListElement { text: "http://fsophia.sophia.grid5000.fr" }
ListElement { text: "localhost" }
ListElement { text: "nef-devel.inria.fr" }
ListElement { text: "fsophia.sophia.grid5000.fr" }
}
ListModel {
id: types
ListElement { text: "local" }
ListElement { text: "torque" }
ListElement { text: "oar" }
}
RowLayout {
......@@ -33,29 +40,72 @@ ApplicationWindow {
Layout.minimumWidth: 400
Layout.fillWidth: false
RowLayout {
id: statusrow
id: serverrow
Label {
id: serverLabel
text: "resources:"
}
ComboBox {
id: combo
editable: true
model: servers
currentIndex: 0
Layout.fillWidth: true
onAccepted: {
controller.deploy( servers.get(combo.currentIndex).text );
Status.show()
/* onAccepted: { */
/* console.log("accepted " + currentText +" " + Status.guess_type(currentText) + " "+ combotypes.find(Status.guess_type(currentText))) */
/* combotypes.currentIndex = combotypes.find(Status.guess_type(currentText)) */
/* /\* controller.deploy( Status.url(false),combotypes.currentText, tunnel.checked, serverPath.text); *\/ */
/* /\* Status.show() *\/ */
/* } */
onCurrentIndexChanged: {
if (combotypes) {
console.log("index changed " + currentText +" " + combotypes.find(Status.guess_type(currentText)))
combotypes.currentIndex = combotypes.find(Status.guess_type(currentText))
}
}
}
Label {
id: typeLabel
text: "type:"
}
ComboBox {
id: combotypes
editable: true
model: types
Layout.minimumWidth: 80
currentIndex: 0
}
}
RowLayout {
id: pathrow
Label {
id: pathLabel
text: "path:"
}
TextEdit {
id: serverPath
Layout.fillWidth: true
/* width: 72 */
/* autoScroll: true */
text: "/home/nniclaus/git/dtk-github/build/bin/dtkDistributedServer"
}
}
RowLayout {
id: actionrow
CheckBox {
id: tunnel
text: "SSH Tunnel"
checked: true
checked: false
}
Button {
id: connectBotton
text: "Connect"
tooltip: "Deploy resource manager daemon on remote host"
onClicked: {
controller.deploy( servers.get(combo.currentIndex).text );
controller.deploy( Status.url(false),combotypes.currentText, tunnel.checked, serverPath.text);
Status.show()
}
}
......@@ -67,6 +117,14 @@ ApplicationWindow {
Status.show()
}
}
Button {
id: quitBotton
text: "Stop"
tooltip:"Deconnect and stop server"
onClicked: {
controller.stop( Status.url(false) );
}
}
}
RowLayout {
id: submitrow
......
......@@ -3,14 +3,26 @@ function url(check_tunnel)
if (check_tunnel && tunnel.checked) {
return "http://localhost:" +controller.defaultPort()
} else {
return combo.currentText + ":" +controller.defaultPort()
return "http://" + combo.currentText + ":" +controller.defaultPort()
}
}
function policy()
{
return comboPolicies.currentText
}
function guess_type(server)
{
if (/nef/.test(server)) {
return "torque"
} else if (/grid5000/.test(server)) {
return "oar"
} else {
return "local"
}
}
function setWalltime(hours, min, sec)
{
return hours + ":" + min +":" + sec ;
......@@ -54,6 +66,7 @@ function submit(nodes, cores, walltime)
function show()
{
console.debug("show")
var xhr = new XMLHttpRequest();
xhr.open("GET", url(true) +"/status",true);
xhr.onreadystatechange = function()
......
......@@ -140,12 +140,23 @@ void dtkDistributedController::killjob(const QUrl& server, QString jobid)
void dtkDistributedController::stop(const QUrl& server)
{
dtkDebug() << "Want to stop server on " << server;
dtkDistributedMessage *msg = new dtkDistributedMessage(dtkDistributedMessage::STOP,"",dtkDistributedMessage::SERVER_RANK);
msg->send(d->sockets[server.toString()]);
dtkDebug() << "Want to stop server on " << server.toString();
if (!d->sockets.contains(server.toString())) {
dtkDebug() << "Needs to reconnect to server" << server.toString();
this->connect(server);
}
if (!isConnected(server)) {
dtkWarn() << "Can't stop server " << server.toString() << "not connected";
d->servers.remove(server.toString());
return;
}
dtkDebug() << "Send stop message to server" << server.toString();
dtkDistributedMessage msg(dtkDistributedMessage::STOP,"",dtkDistributedMessage::SERVER_RANK);
msg.send(d->sockets[server.toString()]);
this->disconnect(server);
d->servers.remove(server.toString());
delete msg;
}
void dtkDistributedController::refresh(const QUrl& server)
......@@ -165,8 +176,9 @@ void dtkDistributedController::refresh(const QUrl& server)
}
// deploy a server instance on remote host (to be executed before connect)
bool dtkDistributedController::deploy(const QUrl& server)
bool dtkDistributedController::deploy(const QUrl& server, QString type, bool ssh_tunnel, QString path)
{
dtkDebug() << "deploy" << server << type << ssh_tunnel << path;
if(!d->servers.keys().contains(server.toString())) {
int port = (server.port() == -1) ? dtkDistributedController::defaultPort(): server.port();
......@@ -181,25 +193,8 @@ bool dtkDistributedController::deploy(const QUrl& server)
args << server.host();
serverProc->setProcessChannelMode(QProcess::MergedChannels);
QSettings settings("inria", "dtk");
settings.beginGroup("distributed");
QString defaultPath;
QString key;
#if defined(Q_WS_MAC)
key = server.host().replace(".", "_");
#else
key = server.host();
#endif
if (!settings.contains(key+"_server_path")) {
defaultPath = "./dtkDistributedServer";
dtkDebug() << "Filling in empty path in settings with default path:" << defaultPath;
}
QString path = settings.value(key+"_server_path", defaultPath).toString();
QString forward = key+"_server_forward";
if (settings.contains(forward) && settings.value(forward).toString() == "true") {
if (ssh_tunnel) {
dtkTrace() << "ssh port forwarding is set for server " << server.host();
int port = (server.port() == -1) ? dtkDistributedController::defaultPort(): server.port();
args << "-L" << QString::number(port)+":localhost:"+QString::number(port);
......@@ -208,13 +203,12 @@ bool dtkDistributedController::deploy(const QUrl& server)
args << path;
args << "-p";
args << QString::number(port);
args << "-type "+settings.value(key+"_server_type", "torque").toString();
args << "-type "+ type;
settings.endGroup();
serverProc->start("ssh", args);
// need to wait a bit when ssh port forwarding is used
if (settings.contains(forward) && settings.value(forward).toString() == "true")
if (ssh_tunnel)
sleep(1);
dtkDebug() << "ssh" << args;
......@@ -239,8 +233,15 @@ bool dtkDistributedController::deploy(const QUrl& server)
return true;
} else {
dtkDebug() << "dtkDistributedServer already started on " << server.host();
return true;
if (isConnected(server)) {
dtkDebug() << "dtkDistributedServer already started on " << server.host();
return true;
} else {
//server exists but is not connected, remove from list and retry
dtkWarn() << "dtkDistributedServer " << server.host() << "exist but is not connected";
d->servers.remove(server.toString());
this->deploy(server,type,ssh_tunnel,path);
}
}
}
......@@ -282,32 +283,23 @@ QTcpSocket *dtkDistributedController::socket(const QString& jobid)
return NULL;
}
bool dtkDistributedController::connect(const QUrl& server)
bool dtkDistributedController::connect(const QUrl& server, bool ssh_tunnel)
{
if(!d->sockets.keys().contains(server.toString())) {
QTcpSocket *socket = new QTcpSocket(this);
QString key;
#if defined(Q_WS_MAC)
key = server.host().replace(".", "_");
#else
key = server.host();
#endif
QSettings settings("inria", "dtk");
settings.beginGroup("distributed");
QString forward = key+"_server_forward";
key = server.host();
int port = (server.port() == -1) ? dtkDistributedController::defaultPort(): server.port();
if (settings.contains(forward) && settings.value(forward).toString() == "true")
if (ssh_tunnel)
socket->connectToHost("localhost", port);
else
socket->connectToHost(server.host(), port);
settings.endGroup();
if(socket->waitForConnected()) {
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
......@@ -317,10 +309,6 @@ bool dtkDistributedController::connect(const QUrl& server)
emit connected(server);
dtkDistributedMessage* msg = new dtkDistributedMessage(dtkDistributedMessage::STATUS);
msg->send(socket);
delete msg;
return true;
} else {
......@@ -416,7 +404,10 @@ void dtkDistributedController::cleanup()
void dtkDistributedController::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus )
{
Q_UNUSED(exitCode);
dtkInfo() << "remote server deployment failure" << exitStatus ;
if (exitStatus != QProcess::NormalExit)
dtkInfo() << "remote server deployment failure" << exitStatus ;
else
dtkInfo() << "remote server stopped";
}
void dtkDistributedController::error(QAbstractSocket::SocketError error)
......
......@@ -56,14 +56,14 @@ signals:
void jobQueued(QString jobid);
public slots:
bool connect(const QUrl& server);
bool connect(const QUrl& server, bool ssh_tunnel = false);
void disconnect(const QUrl& server);
void stop(const QUrl& server);
void refresh(const QUrl& server);
void killjob(const QUrl& server, QString jobid);
void send(dtkDistributedMessage *msg);
void send(QVariant v, QString jobid, qint16 destrank);
bool deploy(const QUrl& server);
bool deploy(const QUrl& server, QString type = "local", bool ssh_tunnel = false, QString path = "./dtkDistributedServer");
bool submit(const QUrl& server, QByteArray& resources);
public:
......
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