1 // Copyright (C) 2009-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "JM_EditSalomeResource.hxx"
21 #include "BL_Traces.hxx"
25 JM::EditSalomeResource::EditSalomeResource(QWidget *parent, BL::SALOMEServices * salome_services,
26 const std::string & resource_name) : QDialog(parent)
28 DEBTRACE("Creating JM::EditSalomeResource");
30 BL_ASSERT(salome_services);
32 _salome_services = salome_services;
33 _resource_name = resource_name;
35 //setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
40 QGroupBox * main_groupBox = new QGroupBox("Main values");
41 QLabel * name_label = new QLabel("Name:");
42 _name_line = new QLineEdit(this);
43 QLabel * hostname_label = new QLabel("Hostname:");
44 _hostname_line = new QLineEdit(this);
45 QLabel * username_label = new QLabel("Username:");
46 _username_line = new QLineEdit(this);
47 QLabel * applipath_label = new QLabel("Applipath:");
48 _applipath_line = new QLineEdit(this);
50 QLabel * protocol_label = new QLabel("Protocol:");
51 _protocol_line = new QComboBox(this);
52 _protocol_line->addItem("ssh");
53 _protocol_line->addItem("rsh");
54 _protocol_line->addItem("sh");
55 _protocol_line->setCurrentIndex(0);
57 QLabel * componentList_label = new QLabel("Component List:");
58 _add_button = new QPushButton("Add");
59 _remove_button = new QPushButton("Remove");
60 _remove_button->setEnabled(false);
61 QWidget * component_widget = new QWidget(this);
62 _componentList = new QListWidget(this);
63 _componentList->setSelectionMode(QAbstractItemView::MultiSelection);
64 QGridLayout * input_box = new QGridLayout(this);
65 input_box->addWidget(_add_button, 0, 0);
66 input_box->addWidget(_remove_button, 0, 1);
67 input_box->addWidget(_componentList, 1, 0, 1, -1);
68 component_widget->setLayout(input_box);
69 connect(_add_button, SIGNAL(clicked()), this, SLOT(add_component()));
70 connect(_remove_button, SIGNAL(clicked()), this, SLOT(remove_components()));
71 connect(_componentList, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
73 QLabel * working_directory_label = new QLabel("Working Directory:");
74 _working_directory = new QLineEdit(this);
75 _can_launch_batch_jobs = new QCheckBox("This resource can be used to launch batch jobs", this);
76 _can_launch_batch_jobs->setCheckState(Qt::Checked);
77 _can_run_containers = new QCheckBox("This resource can be used to run interactive containers", this);
79 QGridLayout * m_layout = new QGridLayout;
80 m_layout->addWidget(name_label, 0, 0);
81 m_layout->addWidget(_name_line, 0, 1);
82 m_layout->addWidget(hostname_label, 1, 0);
83 m_layout->addWidget(_hostname_line, 1, 1);
84 m_layout->addWidget(protocol_label, 2, 0);
85 m_layout->addWidget(_protocol_line, 2, 1);
86 m_layout->addWidget(username_label, 3, 0);
87 m_layout->addWidget(_username_line, 3, 1);
88 m_layout->addWidget(applipath_label, 4, 0);
89 m_layout->addWidget(_applipath_line, 4, 1);
90 m_layout->addWidget(componentList_label, 5, 0);
91 m_layout->addWidget(component_widget, 5, 1);
92 m_layout->addWidget(working_directory_label, 6, 0);
93 m_layout->addWidget(_working_directory, 6, 1);
94 m_layout->addWidget(_can_launch_batch_jobs, 7, 1);
95 m_layout->addWidget(_can_run_containers, 8, 1);
96 main_groupBox->setLayout(m_layout);
99 QGroupBox * config_groupBox = new QGroupBox("Configuration values");
100 QLabel * os_label = new QLabel("OS:");
101 _os_line = new QLineEdit(this);
103 QLabel * mem_mb_label = new QLabel("Memory (mb):");
104 _mem_mb_line = new QSpinBox(this);
105 _mem_mb_line->setMinimum(0);
106 _mem_mb_line->setMaximum(1000000);
107 _mem_mb_line->setValue(0);
108 QLabel * cpu_clock_label = new QLabel("CPU Clock:");
109 _cpu_clock_line = new QSpinBox(this);
110 _cpu_clock_line->setMinimum(0);
111 _cpu_clock_line->setMaximum(1000000);
112 _cpu_clock_line->setValue(0);
113 QLabel * nb_node_label = new QLabel("Nb node:");
114 _nb_node_line = new QSpinBox(this);
115 _nb_node_line->setMinimum(1);
116 _nb_node_line->setMaximum(1000000);
117 _nb_node_line->setValue(1);
118 QLabel * nb_proc_per_node_label = new QLabel("Nb proc/node:");
119 _nb_proc_per_node_line = new QSpinBox(this);
120 _nb_proc_per_node_line->setMinimum(1);
121 _nb_proc_per_node_line->setMaximum(1000000);
122 _nb_proc_per_node_line->setValue(1);
124 QLabel * iprotocol_label = new QLabel("Internal protocol:");
125 _iprotocol_line = new QComboBox(this);
126 _iprotocol_line->addItem("ssh");
127 _iprotocol_line->addItem("rsh");
128 _iprotocol_line->addItem("srun");
129 _iprotocol_line->addItem("pbsdsh");
130 _iprotocol_line->addItem("blaunch");
131 _iprotocol_line->setCurrentIndex(0);
133 QLabel * batch_label = new QLabel("Batch Manager:");
134 _batch_line = new QComboBox(this);
135 _batch_line->addItem("None", "none");
136 _batch_line->addItem("CCC", "ccc");
137 _batch_line->addItem("LSF", "lsf");
138 _batch_line->addItem("SGE", "sge");
139 _batch_line->addItem("SLURM", "slurm");
140 _batch_line->addItem("VISHNU", "vishnu");
141 _batch_line->addItem("CooRM (limited support)", "coorm");
142 _batch_line->addItem("LoadLeveler (limited support)", "ll");
143 _batch_line->addItem("OAR (limited support)", "oar");
144 _batch_line->addItem("PBS (limited support)", "pbs");
145 _batch_line->setCurrentIndex(0);
147 QLabel * mpiImpl_label = new QLabel("MPI impl:");
148 _mpiImpl_line = new QComboBox(this);
149 _mpiImpl_line->addItem("lam");
150 _mpiImpl_line->addItem("mpich1");
151 _mpiImpl_line->addItem("mpich2");
152 _mpiImpl_line->addItem("openmpi");
153 _mpiImpl_line->addItem("slurmmpi");
154 _mpiImpl_line->addItem("prun");
155 _mpiImpl_line->setCurrentIndex(-1);
157 QGridLayout * c_layout = new QGridLayout;
158 c_layout->addWidget(os_label, 0, 0);
159 c_layout->addWidget(_os_line, 0, 1);
160 c_layout->addWidget(mem_mb_label, 1, 0);
161 c_layout->addWidget(_mem_mb_line, 1, 1);
162 c_layout->addWidget(cpu_clock_label, 2, 0);
163 c_layout->addWidget(_cpu_clock_line, 2, 1);
164 c_layout->addWidget(nb_node_label, 3, 0);
165 c_layout->addWidget(_nb_node_line, 3, 1);
166 c_layout->addWidget(nb_proc_per_node_label, 4, 0);
167 c_layout->addWidget(_nb_proc_per_node_line, 4, 1);
168 c_layout->addWidget(batch_label, 5, 0);
169 c_layout->addWidget(_batch_line, 5, 1);
170 c_layout->addWidget(mpiImpl_label, 6, 0);
171 c_layout->addWidget(_mpiImpl_line, 6, 1);
172 c_layout->addWidget(iprotocol_label, 7, 0);
173 c_layout->addWidget(_iprotocol_line, 7, 1);
174 config_groupBox->setLayout(c_layout);
177 QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
178 | QDialogButtonBox::Cancel);
180 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
181 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
184 QVBoxLayout * mainLayout = new QVBoxLayout(this);
185 mainLayout->addWidget(main_groupBox);
186 mainLayout->addWidget(config_groupBox);
187 mainLayout->addWidget(buttonBox);
188 setLayout(mainLayout);
190 setWindowTitle("Edit/Add a resource");
191 if (_resource_name != "")
195 JM::EditSalomeResource::~EditSalomeResource()
197 DEBTRACE("Destroying JM::EditSalomeResource");
201 JM::EditSalomeResource::get_infos()
203 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_name);
205 _name_line->setText(QString(resource_descr.name.c_str()));
206 _hostname_line->setText(QString(resource_descr.hostname.c_str()));
207 _username_line->setText(QString(resource_descr.username.c_str()));
208 _applipath_line->setText(QString(resource_descr.applipath.c_str()));
209 _os_line->setText(QString(resource_descr.OS.c_str()));
210 _working_directory->setText(QString(resource_descr.working_directory.c_str()));
212 if (resource_descr.can_launch_batch_jobs)
213 _can_launch_batch_jobs->setCheckState(Qt::Checked);
215 _can_launch_batch_jobs->setCheckState(Qt::Unchecked);
217 if (resource_descr.can_run_containers)
218 _can_run_containers->setCheckState(Qt::Checked);
220 _can_run_containers->setCheckState(Qt::Unchecked);
222 std::string protocol = resource_descr.protocol.c_str();
223 if (protocol == "ssh")
224 _protocol_line->setCurrentIndex(0);
225 else if(protocol == "rsh")
226 _protocol_line->setCurrentIndex(1);
227 else if(protocol == "sh")
228 _protocol_line->setCurrentIndex(2);
230 _protocol_line->setCurrentIndex(-1);
232 std::string iprotocol = resource_descr.iprotocol.c_str();
233 if (iprotocol == "ssh")
234 _iprotocol_line->setCurrentIndex(0);
235 else if (iprotocol == "rsh")
236 _iprotocol_line->setCurrentIndex(1);
237 else if (iprotocol == "srun")
238 _iprotocol_line->setCurrentIndex(2);
239 else if (iprotocol == "pbsdsh")
240 _iprotocol_line->setCurrentIndex(3);
241 else if (iprotocol == "blaunch")
242 _iprotocol_line->setCurrentIndex(4);
244 _iprotocol_line->setCurrentIndex(-1);
246 for (int i=0 ; i<_batch_line->count() ; i++)
248 if (_batch_line->itemData(i).toString().toStdString() == resource_descr.batch)
250 _batch_line->setCurrentIndex(i);
254 std::string mpiImpl = resource_descr.mpiImpl.c_str();
255 if (mpiImpl == "lam")
256 _mpiImpl_line->setCurrentIndex(0);
257 else if (mpiImpl == "mpich1")
258 _mpiImpl_line->setCurrentIndex(1);
259 else if (mpiImpl == "mpich2")
260 _mpiImpl_line->setCurrentIndex(2);
261 else if (mpiImpl == "openmpi")
262 _mpiImpl_line->setCurrentIndex(3);
263 else if (mpiImpl == "slurmmpi")
264 _mpiImpl_line->setCurrentIndex(4);
265 else if (mpiImpl == "prun")
266 _mpiImpl_line->setCurrentIndex(5);
268 _mpiImpl_line->setCurrentIndex(-1);
270 int value = resource_descr.mem_mb;
272 _mem_mb_line->setValue(value);
273 value = resource_descr.cpu_clock;
275 _cpu_clock_line->setValue(value);
276 value = resource_descr.nb_node;
278 _nb_node_line->setValue(value);
279 value = resource_descr.nb_proc_per_node;
281 _nb_proc_per_node_line->setValue(value);
283 std::list<std::string>::iterator it = resource_descr.componentList.begin();
284 for(; it != resource_descr.componentList.end(); it++)
285 _componentList->addItem(QString((*it).c_str()));
287 // Better if string's length is bigger than the widget
288 _name_line->setCursorPosition(0);
289 _hostname_line->setCursorPosition(0);
290 _username_line->setCursorPosition(0);
291 _applipath_line->setCursorPosition(0);
292 _os_line->setCursorPosition(0);
293 _working_directory->setCursorPosition(0);
298 JM::EditSalomeResource::itemSelectionChanged()
300 if (_componentList->selectedItems().size() > 0)
301 _remove_button->setEnabled(true);
303 _remove_button->setEnabled(false);
307 JM::EditSalomeResource::add_component()
310 QString text = QInputDialog::getText(this, "Add a component",
311 "Component name:", QLineEdit::Normal,
313 if (ok && !text.isEmpty())
314 _componentList->addItem(text);
318 JM::EditSalomeResource::remove_components()
320 QList<QListWidgetItem *> list = _componentList->selectedItems();
321 for (int i = 0; i < list.size(); ++i)
323 int row = _componentList->row( list.at(i) );
324 delete _componentList->takeItem(row);
329 JM::EditSalomeResource::accept()
331 BL::ResourceDescr resource;
334 resource.name = _name_line->text().trimmed().toStdString();
335 resource.hostname = _hostname_line->text().trimmed().toStdString();
336 resource.username = _username_line->text().trimmed().toStdString();
337 resource.applipath = _applipath_line->text().trimmed().toStdString();
338 resource.OS = _os_line->text().trimmed().toStdString();
339 resource.working_directory = _working_directory->text().trimmed().toStdString();
340 resource.can_launch_batch_jobs = (_can_launch_batch_jobs->checkState() == Qt::Checked);
341 resource.can_run_containers = (_can_run_containers->checkState() == Qt::Checked);
344 int count = _componentList->count();
345 for (int i = 0; i < count; i++)
346 resource.componentList.push_back(_componentList->item(i)->text().trimmed().toStdString());
349 resource.protocol = _protocol_line->currentText().toStdString();
350 resource.iprotocol = _iprotocol_line->currentText().toStdString();
351 resource.batch = _batch_line->itemData(_batch_line->currentIndex()).toString().toStdString();
352 resource.mpiImpl = _mpiImpl_line->currentText().toStdString();
355 resource.mem_mb = _mem_mb_line->value();
356 resource.cpu_clock = _cpu_clock_line->value();
357 resource.nb_node = _nb_node_line->value();
358 resource.nb_proc_per_node = _nb_proc_per_node_line->value();
360 if (resource.name != "" &&
361 resource.hostname != "" &&
362 resource.protocol != "")
366 _salome_services->addResource(resource);
369 catch (const BL::Exception & ex)
371 QMessageBox::critical(this, "Error", QString("Cannot add resource: ") + ex.what());
376 QMessageBox::warning(NULL, "Values missing", "name, hostname and protocol are mandatory! Cancel or add values!");