1 // Copyright (C) 2009-2013 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.
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"
23 JM::EditSalomeResource::EditSalomeResource(QWidget *parent, BL::SALOMEServices * salome_services,
24 const std::string & resource_name) : QDialog(parent)
26 DEBTRACE("Creating JM::EditSalomeResource");
28 BL_ASSERT(salome_services);
30 _salome_services = salome_services;
31 _resource_name = resource_name;
33 //setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
38 QGroupBox * main_groupBox = new QGroupBox("Main values");
39 QLabel * name_label = new QLabel("Name:");
40 _name_line = new QLineEdit(this);
41 QLabel * hostname_label = new QLabel("Hostname:");
42 _hostname_line = new QLineEdit(this);
43 QLabel * username_label = new QLabel("Username:");
44 _username_line = new QLineEdit(this);
45 QLabel * applipath_label = new QLabel("Applipath:");
46 _applipath_line = new QLineEdit(this);
48 QLabel * protocol_label = new QLabel("Protocol:");
49 _protocol_line = new QComboBox(this);
50 _protocol_line->addItem("ssh");
51 _protocol_line->addItem("rsh");
52 _protocol_line->addItem("srun");
53 _protocol_line->addItem("pbsdsh");
54 _protocol_line->addItem("blaunch");
55 _protocol_line->setCurrentIndex(-1);
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_run_containers = new QCheckBox("This resource can be used to run interactive containers", this);
78 QGridLayout * m_layout = new QGridLayout;
79 m_layout->addWidget(name_label, 0, 0);
80 m_layout->addWidget(_name_line, 0, 1);
81 m_layout->addWidget(hostname_label, 1, 0);
82 m_layout->addWidget(_hostname_line, 1, 1);
83 m_layout->addWidget(protocol_label, 2, 0);
84 m_layout->addWidget(_protocol_line, 2, 1);
85 m_layout->addWidget(username_label, 3, 0);
86 m_layout->addWidget(_username_line, 3, 1);
87 m_layout->addWidget(applipath_label, 4, 0);
88 m_layout->addWidget(_applipath_line, 4, 1);
89 m_layout->addWidget(componentList_label, 5, 0);
90 m_layout->addWidget(component_widget, 5, 1);
91 m_layout->addWidget(working_directory_label, 6, 0);
92 m_layout->addWidget(_working_directory, 6, 1);
93 m_layout->addWidget(_can_launch_batch_jobs, 7, 1);
94 m_layout->addWidget(_can_run_containers, 8, 1);
95 main_groupBox->setLayout(m_layout);
98 QGroupBox * config_groupBox = new QGroupBox("Configuration values");
99 QLabel * os_label = new QLabel("OS:");
100 _os_line = new QLineEdit(this);
102 QLabel * mem_mb_label = new QLabel("Memory (mb):");
103 _mem_mb_line = new QSpinBox(this);
104 _mem_mb_line->setMinimum(0);
105 _mem_mb_line->setMaximum(1000000);
106 _mem_mb_line->setValue(0);
107 QLabel * cpu_clock_label = new QLabel("CPU Clock:");
108 _cpu_clock_line = new QSpinBox(this);
109 _cpu_clock_line->setMinimum(0);
110 _cpu_clock_line->setMaximum(1000000);
111 _cpu_clock_line->setValue(0);
112 QLabel * nb_node_label = new QLabel("Nb node:");
113 _nb_node_line = new QSpinBox(this);
114 _nb_node_line->setMinimum(1);
115 _nb_node_line->setMaximum(1000000);
116 _nb_node_line->setValue(1);
117 QLabel * nb_proc_per_node_label = new QLabel("Nb proc/node:");
118 _nb_proc_per_node_line = new QSpinBox(this);
119 _nb_proc_per_node_line->setMinimum(1);
120 _nb_proc_per_node_line->setMaximum(1000000);
121 _nb_proc_per_node_line->setValue(1);
123 QLabel * iprotocol_label = new QLabel("Internal protocol:");
124 _iprotocol_line = new QComboBox(this);
125 _iprotocol_line->addItem("ssh");
126 _iprotocol_line->addItem("rsh");
127 _iprotocol_line->addItem("srun");
128 _iprotocol_line->addItem("pbsdsh");
129 _iprotocol_line->addItem("blaunch");
130 _iprotocol_line->setCurrentIndex(-1);
132 QLabel * batch_label = new QLabel("Batch:");
133 _batch_line = new QComboBox(this);
134 _batch_line->addItem("pbs");
135 _batch_line->addItem("lsf");
136 _batch_line->addItem("sge");
137 _batch_line->addItem("ssh");
138 _batch_line->addItem("ccc");
139 _batch_line->addItem("slurm");
140 _batch_line->addItem("ll");
141 _batch_line->addItem("vishnu");
142 _batch_line->setCurrentIndex(-1);
144 QLabel * mpiImpl_label = new QLabel("MPI impl:");
145 _mpiImpl_line = new QComboBox(this);
146 _mpiImpl_line->addItem("lam");
147 _mpiImpl_line->addItem("mpich1");
148 _mpiImpl_line->addItem("mpich2");
149 _mpiImpl_line->addItem("openmpi");
150 _mpiImpl_line->addItem("slurmmpi");
151 _mpiImpl_line->addItem("prun");
152 _mpiImpl_line->setCurrentIndex(-1);
154 QGridLayout * c_layout = new QGridLayout;
155 c_layout->addWidget(os_label, 0, 0);
156 c_layout->addWidget(_os_line, 0, 1);
157 c_layout->addWidget(mem_mb_label, 1, 0);
158 c_layout->addWidget(_mem_mb_line, 1, 1);
159 c_layout->addWidget(cpu_clock_label, 2, 0);
160 c_layout->addWidget(_cpu_clock_line, 2, 1);
161 c_layout->addWidget(nb_node_label, 3, 0);
162 c_layout->addWidget(_nb_node_line, 3, 1);
163 c_layout->addWidget(nb_proc_per_node_label, 4, 0);
164 c_layout->addWidget(_nb_proc_per_node_line, 4, 1);
165 c_layout->addWidget(batch_label, 5, 0);
166 c_layout->addWidget(_batch_line, 5, 1);
167 c_layout->addWidget(mpiImpl_label, 6, 0);
168 c_layout->addWidget(_mpiImpl_line, 6, 1);
169 c_layout->addWidget(iprotocol_label, 7, 0);
170 c_layout->addWidget(_iprotocol_line, 7, 1);
171 config_groupBox->setLayout(c_layout);
174 QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
175 | QDialogButtonBox::Cancel);
177 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
178 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
181 QVBoxLayout * mainLayout = new QVBoxLayout(this);
182 mainLayout->addWidget(main_groupBox);
183 mainLayout->addWidget(config_groupBox);
184 mainLayout->addWidget(buttonBox);
185 setLayout(mainLayout);
187 setWindowTitle("Edit/Add a resource");
188 if (_resource_name != "")
192 JM::EditSalomeResource::~EditSalomeResource()
194 DEBTRACE("Destroying JM::EditSalomeResource");
198 JM::EditSalomeResource::get_infos()
200 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_name);
202 _name_line->setText(QString(resource_descr.name.c_str()));
203 _hostname_line->setText(QString(resource_descr.hostname.c_str()));
204 _username_line->setText(QString(resource_descr.username.c_str()));
205 _applipath_line->setText(QString(resource_descr.applipath.c_str()));
206 _os_line->setText(QString(resource_descr.OS.c_str()));
207 _working_directory->setText(QString(resource_descr.working_directory.c_str()));
209 if (resource_descr.can_launch_batch_jobs)
210 _can_launch_batch_jobs->setCheckState(Qt::Checked);
212 _can_launch_batch_jobs->setCheckState(Qt::Unchecked);
214 if (resource_descr.can_run_containers)
215 _can_run_containers->setCheckState(Qt::Checked);
217 _can_run_containers->setCheckState(Qt::Unchecked);
219 std::string protocol = resource_descr.protocol.c_str();
220 if (protocol == "ssh")
221 _protocol_line->setCurrentIndex(0);
222 else if(protocol == "rsh")
223 _protocol_line->setCurrentIndex(1);
224 else if(protocol == "srun")
225 _protocol_line->setCurrentIndex(2);
226 else if(protocol == "pbsdsh")
227 _protocol_line->setCurrentIndex(3);
228 else if(protocol == "blaunch")
229 _protocol_line->setCurrentIndex(4);
231 _protocol_line->setCurrentIndex(-1);
233 std::string iprotocol = resource_descr.iprotocol.c_str();
234 if (iprotocol == "ssh")
235 _iprotocol_line->setCurrentIndex(0);
236 else if (iprotocol == "rsh")
237 _iprotocol_line->setCurrentIndex(1);
238 else if (iprotocol == "srun")
239 _iprotocol_line->setCurrentIndex(2);
240 else if (iprotocol == "pbsdsh")
241 _iprotocol_line->setCurrentIndex(3);
242 else if (iprotocol == "blaunch")
243 _iprotocol_line->setCurrentIndex(4);
245 _iprotocol_line->setCurrentIndex(-1);
247 std::string batch = resource_descr.batch.c_str();
249 _batch_line->setCurrentIndex(0);
250 else if (batch == "lsf")
251 _batch_line->setCurrentIndex(1);
252 else if (batch == "sge")
253 _batch_line->setCurrentIndex(2);
254 else if (batch == "ssh_batch")
255 _batch_line->setCurrentIndex(3);
256 else if (batch == "ccc")
257 _batch_line->setCurrentIndex(4);
258 else if (batch == "slurm")
259 _batch_line->setCurrentIndex(5);
260 else if (batch == "ll")
261 _batch_line->setCurrentIndex(6);
262 else if (batch == "vishnu")
263 _batch_line->setCurrentIndex(7);
265 _batch_line->setCurrentIndex(-1);
267 std::string mpiImpl = resource_descr.mpiImpl.c_str();
268 if (mpiImpl == "lam")
269 _mpiImpl_line->setCurrentIndex(0);
270 else if (mpiImpl == "mpich1")
271 _mpiImpl_line->setCurrentIndex(1);
272 else if (mpiImpl == "mpich2")
273 _mpiImpl_line->setCurrentIndex(2);
274 else if (mpiImpl == "openmpi")
275 _mpiImpl_line->setCurrentIndex(3);
276 else if (mpiImpl == "slurmmpi")
277 _mpiImpl_line->setCurrentIndex(4);
278 else if (mpiImpl == "prun")
279 _mpiImpl_line->setCurrentIndex(5);
281 _mpiImpl_line->setCurrentIndex(-1);
283 int value = resource_descr.mem_mb;
285 _mem_mb_line->setValue(value);
286 value = resource_descr.cpu_clock;
288 _cpu_clock_line->setValue(value);
289 value = resource_descr.nb_node;
291 _nb_node_line->setValue(value);
292 value = resource_descr.nb_proc_per_node;
294 _nb_proc_per_node_line->setValue(value);
296 std::list<std::string>::iterator it = resource_descr.componentList.begin();
297 for(; it != resource_descr.componentList.end(); it++)
298 _componentList->addItem(QString((*it).c_str()));
300 // Better if string's length is bigger than the widget
301 _name_line->setCursorPosition(0);
302 _hostname_line->setCursorPosition(0);
303 _username_line->setCursorPosition(0);
304 _applipath_line->setCursorPosition(0);
305 _os_line->setCursorPosition(0);
306 _working_directory->setCursorPosition(0);
311 JM::EditSalomeResource::itemSelectionChanged()
313 if (_componentList->selectedItems().size() > 0)
314 _remove_button->setEnabled(true);
316 _remove_button->setEnabled(false);
320 JM::EditSalomeResource::add_component()
323 QString text = QInputDialog::getText(this, "Add a component",
324 "Component name:", QLineEdit::Normal,
326 if (ok && !text.isEmpty())
327 _componentList->addItem(text);
331 JM::EditSalomeResource::remove_components()
333 QList<QListWidgetItem *> list = _componentList->selectedItems();
334 for (int i = 0; i < list.size(); ++i)
336 int row = _componentList->row( list.at(i) );
337 delete _componentList->takeItem(row);
342 JM::EditSalomeResource::accept()
344 BL::ResourceDescr resource;
347 resource.name = _name_line->text().toStdString();
348 resource.hostname = _hostname_line->text().toStdString();
349 resource.username = _username_line->text().toStdString();
350 resource.applipath = _applipath_line->text().toStdString();
351 resource.OS = _os_line->text().toStdString();
352 resource.working_directory = _working_directory->text().toStdString();
353 resource.can_launch_batch_jobs = (_can_launch_batch_jobs->checkState() == Qt::Checked);
354 resource.can_run_containers = (_can_run_containers->checkState() == Qt::Checked);
357 int count = _componentList->count();
358 for (int i = 0; i < count; i++)
359 resource.componentList.push_back(_componentList->item(i)->text().toStdString());
362 resource.protocol = _protocol_line->currentText().toStdString();
363 resource.iprotocol = _iprotocol_line->currentText().toStdString();
364 resource.batch = _batch_line->currentText().toStdString();
365 if (resource.batch == "ssh")
366 resource.batch = "ssh_batch";
367 resource.mpiImpl = _mpiImpl_line->currentText().toStdString();
370 resource.mem_mb = _mem_mb_line->value();
371 resource.cpu_clock = _cpu_clock_line->value();
372 resource.nb_node = _nb_node_line->value();
373 resource.nb_proc_per_node = _nb_proc_per_node_line->value();
375 if (resource.name != "" &&
376 resource.hostname != "" &&
377 resource.protocol != "")
379 _salome_services->addResource(resource);
384 QMessageBox::warning(NULL, "Values missing", "name, hostname and protocol are mandatory! Cancel or add values!");