Salome HOME
Update from V7_dev branch
[modules/jobmanager.git] / src / genericgui / JM_SalomeResource.cxx
1 // Copyright (C) 2009-2015  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "JM_SalomeResource.hxx"
21 #include "BL_Traces.hxx"
22
23 #include <QCheckBox>
24 #include <QGridLayout>
25 #include <QGroupBox>
26 #include <QLabel>
27 #include <QLineEdit>
28 #include <QListWidget>
29 #include <QVBoxLayout>
30
31 JM::SalomeResource::SalomeResource(QWidget *parent, BL::SALOMEServices * salome_services, 
32                                    const std::string & resource_name) : QDialog(parent)
33 {
34   DEBTRACE("Creating JM::SalomeResource");
35   BL_ASSERT(parent);
36   BL_ASSERT(salome_services);
37   _parent = parent;
38   _salome_services = salome_services;
39   _resource_name = resource_name;
40
41   // Widget code
42   QGroupBox * main_groupBox = new QGroupBox("Main values");
43   QLabel * name_label = new QLabel("Name:");
44   _name_line = new QLineEdit(this);
45   QLabel * hostname_label = new QLabel("Hostname:");
46   _hostname_line = new QLineEdit(this);
47   QLabel * protocol_label = new QLabel("Protocol:");
48   _protocol_line = new QLineEdit(this);
49   QLabel * username_label = new QLabel("Username:");
50   _username_line = new QLineEdit(this);
51   QLabel * applipath_label = new QLabel("Applipath:");
52   _applipath_line = new QLineEdit(this);
53   QLabel * componentList_label = new QLabel("Component List:");
54   _componentList = new QListWidget(this);
55   _componentList->setViewMode(QListView::ListMode);
56   QLabel * working_directory_label = new QLabel("Working Directory:");
57   _working_directory = new QLineEdit(this);
58   _can_launch_batch_jobs = new QCheckBox("This resource can be used to launch batch jobs", this);
59   _can_run_containers = new QCheckBox("This resource can be used to run interactive containers", this);
60   QGridLayout * m_layout = new QGridLayout;
61   m_layout->addWidget(name_label, 0, 0);
62   m_layout->addWidget(_name_line, 0, 1);
63   m_layout->addWidget(hostname_label, 1, 0);
64   m_layout->addWidget(_hostname_line, 1, 1);
65   m_layout->addWidget(protocol_label, 2, 0);
66   m_layout->addWidget(_protocol_line, 2, 1);
67   m_layout->addWidget(username_label, 3, 0);
68   m_layout->addWidget(_username_line, 3, 1);
69   m_layout->addWidget(applipath_label, 4, 0);
70   m_layout->addWidget(_applipath_line, 4, 1);
71   m_layout->addWidget(componentList_label, 5, 0);
72   m_layout->addWidget(_componentList, 5, 1);
73   m_layout->addWidget(working_directory_label, 6, 0);
74   m_layout->addWidget(_working_directory, 6, 1);
75   m_layout->addWidget(_can_launch_batch_jobs, 7, 1);
76   m_layout->addWidget(_can_run_containers, 8, 1);
77   main_groupBox->setLayout(m_layout);
78
79   QGroupBox * config_groupBox = new QGroupBox("Configuration values");
80   QLabel * os_label = new QLabel("OS:");
81   _os_line = new QLineEdit(this);
82   QLabel * mem_mb_label = new QLabel("Memory (mb):");
83   _mem_mb_line = new QLineEdit(this);
84   QLabel * cpu_clock_label = new QLabel("CPU Clock:");
85   _cpu_clock_line = new QLineEdit(this);
86   QLabel * nb_node_label = new QLabel("Nb node:");
87   _nb_node_line = new QLineEdit(this);
88   QLabel * nb_proc_per_node_label = new QLabel("Nb proc/node:");
89   _nb_proc_per_node_line = new QLineEdit(this);
90   QLabel * batch_label = new QLabel("Batch:");
91   _batch_line = new QLineEdit(this);
92   QLabel * mpiImpl_label = new QLabel("MPI impl:");
93   _mpiImpl_line = new QLineEdit(this);
94   QLabel * iprotocol_label = new QLabel("Internal proctocol:");
95   _iprotocol_line = new QLineEdit(this);
96   QGridLayout * c_layout = new QGridLayout;
97   c_layout->addWidget(os_label, 0, 0);
98   c_layout->addWidget(_os_line, 0, 1);
99   c_layout->addWidget(mem_mb_label, 1, 0);
100   c_layout->addWidget(_mem_mb_line, 1, 1);
101   c_layout->addWidget(cpu_clock_label, 2, 0);
102   c_layout->addWidget(_cpu_clock_line, 2, 1);
103   c_layout->addWidget(nb_node_label, 3, 0);
104   c_layout->addWidget(_nb_node_line, 3, 1);
105   c_layout->addWidget(nb_proc_per_node_label, 4, 0);
106   c_layout->addWidget(_nb_proc_per_node_line, 4, 1);
107   c_layout->addWidget(batch_label, 5, 0);
108   c_layout->addWidget(_batch_line, 5, 1);
109   c_layout->addWidget(mpiImpl_label, 6, 0);
110   c_layout->addWidget(_mpiImpl_line, 6, 1);
111   c_layout->addWidget(iprotocol_label, 7, 0);
112   c_layout->addWidget(_iprotocol_line, 7, 1);
113   config_groupBox->setLayout(c_layout);
114
115   // Main Layout
116   QVBoxLayout * mainLayout = new QVBoxLayout(this);
117   mainLayout->addWidget(main_groupBox);
118   mainLayout->addWidget(config_groupBox);
119   setLayout(mainLayout);
120
121   setWindowTitle("Resource");
122   get_infos();
123
124   // Line cannot be changed
125   _name_line->setCursorPosition(0);
126   _hostname_line->setCursorPosition(0);
127   _protocol_line->setCursorPosition(0);
128   _username_line->setCursorPosition(0);
129   _applipath_line->setCursorPosition(0);
130   _os_line->setCursorPosition(0);
131   _mem_mb_line->setCursorPosition(0);
132   _cpu_clock_line->setCursorPosition(0);
133   _nb_node_line->setCursorPosition(0);
134   _nb_proc_per_node_line->setCursorPosition(0);
135   _batch_line->setCursorPosition(0);
136   _mpiImpl_line->setCursorPosition(0);
137   _iprotocol_line->setCursorPosition(0);
138   _working_directory->setCursorPosition(0);
139
140   _name_line->setReadOnly(true);
141   _hostname_line->setReadOnly(true);
142   _protocol_line->setReadOnly(true);
143   _username_line->setReadOnly(true);
144   _applipath_line->setReadOnly(true);
145   _os_line->setReadOnly(true);
146   _mem_mb_line->setReadOnly(true);
147   _cpu_clock_line->setReadOnly(true);
148   _nb_node_line->setReadOnly(true);
149   _nb_proc_per_node_line->setReadOnly(true);
150   _batch_line->setReadOnly(true);
151   _mpiImpl_line->setReadOnly(true);
152   _iprotocol_line->setReadOnly(true);
153   _working_directory->setReadOnly(true);
154   _can_launch_batch_jobs->setEnabled(false);
155   _can_run_containers->setEnabled(false);
156 }
157
158 JM::SalomeResource::~SalomeResource()
159 {
160   DEBTRACE("Destroying JM::SalomeResource");
161 }
162
163 void
164 JM::SalomeResource::get_infos()
165 {
166   BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_name);
167
168   _name_line->setText(QString(resource_descr.name.c_str()));
169   _hostname_line->setText(QString(resource_descr.hostname.c_str()));
170   _protocol_line->setText(QString(resource_descr.protocol.c_str()));
171   _username_line->setText(QString(resource_descr.username.c_str()));
172   _applipath_line->setText(QString(resource_descr.applipath.c_str()));
173   _os_line->setText(QString(resource_descr.OS.c_str()));
174   _batch_line->setText(QString(resource_descr.batch.c_str()));
175   _mpiImpl_line->setText(QString(resource_descr.mpiImpl.c_str()));
176   _iprotocol_line->setText(QString(resource_descr.iprotocol.c_str()));
177   _working_directory->setText(QString(resource_descr.working_directory.c_str()));
178
179   if (resource_descr.can_launch_batch_jobs)
180     _can_launch_batch_jobs->setCheckState(Qt::Checked);
181   else
182     _can_launch_batch_jobs->setCheckState(Qt::Unchecked);
183
184   if (resource_descr.can_run_containers)
185     _can_run_containers->setCheckState(Qt::Checked);
186   else
187     _can_run_containers->setCheckState(Qt::Unchecked);
188
189   QString value;
190   _mem_mb_line->setText(value.setNum(resource_descr.mem_mb));
191   _cpu_clock_line->setText(value.setNum(resource_descr.cpu_clock));
192   _nb_node_line->setText(value.setNum(resource_descr.nb_node));
193   _nb_proc_per_node_line->setText(value.setNum(resource_descr.nb_proc_per_node));
194
195    std::list<std::string>::iterator it = resource_descr.componentList.begin();
196    for(; it != resource_descr.componentList.end(); it++)
197      _componentList->addItem(QString((*it).c_str()));
198 }