From 36e27e2c90a5041b86f213bc84e4813d3f066341 Mon Sep 17 00:00:00 2001 From: ribes Date: Mon, 18 Jan 2010 16:33:29 +0000 Subject: [PATCH] Add a view of a resource --- src/engine/BL_SALOMEServices.cxx | 29 +++++ src/engine/BL_SALOMEServices.hxx | 20 +++ src/genericgui/JM_ResourceCatalog.cxx | 16 ++- src/genericgui/JM_ResourceCatalog.hxx | 3 + src/genericgui/JM_SalomeResource.cxx | 176 ++++++++++++++++++++++++++ src/genericgui/JM_SalomeResource.hxx | 66 ++++++++++ src/genericgui/Makefile.am | 6 +- 7 files changed, 313 insertions(+), 3 deletions(-) create mode 100644 src/genericgui/JM_SalomeResource.cxx create mode 100644 src/genericgui/JM_SalomeResource.hxx diff --git a/src/engine/BL_SALOMEServices.cxx b/src/engine/BL_SALOMEServices.cxx index 20c3a54..d024ff3 100644 --- a/src/engine/BL_SALOMEServices.cxx +++ b/src/engine/BL_SALOMEServices.cxx @@ -78,11 +78,40 @@ BL::SALOMEServices::getResourceList() const char* aResource = (*resourceList)[i]; resource_list.push_back(aResource); } + delete resourceList; } return resource_list; } +BL::ResourceDescr +BL::SALOMEServices::getResourceDescr(const std::string& name) +{ + Engines::ResourceDefinition_var resource_definition = _resources_manager-> GetResourceDefinition(name.c_str()); + BL::ResourceDescr resource_descr; + + resource_descr.name = resource_definition->name.in(); + resource_descr.hostname = resource_definition->hostname.in(); + resource_descr.protocol = resource_definition->protocol.in(); + resource_descr.username = resource_definition->username.in(); + resource_descr.applipath = resource_definition->applipath.in(); + for (int i = 0; i < resource_definition->componentList.length(); i++) + { + resource_descr.componentList.push_back(resource_definition->componentList[i].in()); + } + + resource_descr.OS = resource_definition->OS.in(); + resource_descr.mem_mb = resource_definition->mem_mb; + resource_descr.cpu_clock = resource_definition->cpu_clock; + resource_descr.nb_node = resource_definition->nb_node; + resource_descr.nb_proc_per_node = resource_definition->nb_proc_per_node; + resource_descr.batch = resource_definition->batch.in(); + resource_descr.mpiImpl = resource_definition->mpiImpl.in(); + resource_descr.iprotocol = resource_definition->iprotocol.in(); + + return resource_descr; +} + std::string BL::SALOMEServices::create_job(BL::Job * job) { diff --git a/src/engine/BL_SALOMEServices.hxx b/src/engine/BL_SALOMEServices.hxx index c81f022..037aaa9 100644 --- a/src/engine/BL_SALOMEServices.hxx +++ b/src/engine/BL_SALOMEServices.hxx @@ -33,6 +33,25 @@ namespace BL{ + struct ResourceDescr + { + std::string name; + std::string hostname; + std::string protocol; + std::string username; + std::string applipath; + std::list componentList; + + std::string OS; + unsigned int mem_mb; + unsigned int cpu_clock; + unsigned int nb_node; + unsigned int nb_proc_per_node; + std::string batch; + std::string mpiImpl; + std::string iprotocol; + }; + class SALOMEServices { public: @@ -42,6 +61,7 @@ namespace BL{ bool initNS(); std::list getResourceList(); + BL::ResourceDescr getResourceDescr(const std::string& name); std::string create_job(BL::Job * job); std::string start_job(BL::Job * job); diff --git a/src/genericgui/JM_ResourceCatalog.cxx b/src/genericgui/JM_ResourceCatalog.cxx index 1ca831a..464813a 100644 --- a/src/genericgui/JM_ResourceCatalog.cxx +++ b/src/genericgui/JM_ResourceCatalog.cxx @@ -19,6 +19,7 @@ #include "JM_ResourceCatalog.hxx" #include "BL_Traces.hxx" +#include "JM_SalomeResource.hxx" JM::ResourceCatalog::ResourceCatalog(QWidget *parent, BL::SALOMEServices * salome_services) : QWidget(parent) { @@ -32,7 +33,8 @@ JM::ResourceCatalog::ResourceCatalog(QWidget *parent, BL::SALOMEServices * salom _refresh_button->show(); connect(_refresh_button, SIGNAL(clicked()), this, SLOT(refresh_resource_list())); _resource_files_list = new QListWidget(this); - _resource_files_list->setSelectionMode(QAbstractItemView::NoSelection); + _resource_files_list->setSelectionMode(QAbstractItemView::SingleSelection); + connect(_resource_files_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(item_choosed(QListWidgetItem*))); std::list resource_list = _salome_services->getResourceList(); std::list::iterator it; for (it = resource_list.begin(); it != resource_list.end(); it++) @@ -64,3 +66,15 @@ JM::ResourceCatalog::refresh_resource_list() _resource_files_list->addItem(QString(resource.c_str())); } } + +void +JM::ResourceCatalog::item_choosed(QListWidgetItem * item) +{ + DEBTRACE("JM::ResourceCatalog::item_choosed"); + JM::SalomeResource * resource_widget = new JM::SalomeResource(this, + _salome_services, + item->text().toStdString(), + false); + resource_widget->exec(); + delete resource_widget; +} diff --git a/src/genericgui/JM_ResourceCatalog.hxx b/src/genericgui/JM_ResourceCatalog.hxx index 59e3699..731430c 100644 --- a/src/genericgui/JM_ResourceCatalog.hxx +++ b/src/genericgui/JM_ResourceCatalog.hxx @@ -37,8 +37,11 @@ namespace JM ResourceCatalog(QWidget *parent, BL::SALOMEServices * salome_services); virtual ~ResourceCatalog(); + void get_infos(); + public slots: void refresh_resource_list(); + void item_choosed(QListWidgetItem * item); protected: QWidget* _parent; diff --git a/src/genericgui/JM_SalomeResource.cxx b/src/genericgui/JM_SalomeResource.cxx new file mode 100644 index 0000000..83e4849 --- /dev/null +++ b/src/genericgui/JM_SalomeResource.cxx @@ -0,0 +1,176 @@ +// Copyright (C) 2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "JM_SalomeResource.hxx" +#include "BL_Traces.hxx" + +JM::SalomeResource::SalomeResource(QWidget *parent, BL::SALOMEServices * salome_services, + const std::string & resource_name, bool edit) : QDialog(parent) +{ + DEBTRACE("Creating JM::SalomeResource"); + BL_ASSERT(parent); + BL_ASSERT(salome_services); + _parent = parent; + _salome_services = salome_services; + _resource_name = resource_name; + _edit = edit; + + // Widget code + QGroupBox * main_groupBox = new QGroupBox("Main values"); + QLabel * name_label = new QLabel("Name:"); + _name_line = new QLineEdit(this); + QLabel * hostname_label = new QLabel("Hostname:"); + _hostname_line = new QLineEdit(this); + QLabel * protocol_label = new QLabel("Protocol:"); + _protocol_line = new QLineEdit(this); + QLabel * username_label = new QLabel("Username:"); + _username_line = new QLineEdit(this); + QLabel * applipath_label = new QLabel("Applipath:"); + _applipath_line = new QLineEdit(this); + QLabel * componentList_label = new QLabel("Component List:"); + _componentList = new QListWidget(this); + _componentList->setViewMode(QListView::ListMode); + QGridLayout * m_layout = new QGridLayout; + m_layout->addWidget(name_label, 0, 0); + m_layout->addWidget(_name_line, 0, 1); + m_layout->addWidget(hostname_label, 1, 0); + m_layout->addWidget(_hostname_line, 1, 1); + m_layout->addWidget(protocol_label, 2, 0); + m_layout->addWidget(_protocol_line, 2, 1); + m_layout->addWidget(username_label, 3, 0); + m_layout->addWidget(_username_line, 3, 1); + m_layout->addWidget(applipath_label, 4, 0); + m_layout->addWidget(_applipath_line, 4, 1); + m_layout->addWidget(componentList_label, 5, 0); + m_layout->addWidget(_componentList, 5, 1); + main_groupBox->setLayout(m_layout); + + + QGroupBox * config_groupBox = new QGroupBox("Configuration values"); + QLabel * os_label = new QLabel("OS:"); + _os_line = new QLineEdit(this); + QLabel * mem_mb_label = new QLabel("Memory (mb):"); + _mem_mb_line = new QLineEdit(this); + QLabel * cpu_clock_label = new QLabel("CPU Clock:"); + _cpu_clock_line = new QLineEdit(this); + QLabel * nb_node_label = new QLabel("Nb node:"); + _nb_node_line = new QLineEdit(this); + QLabel * nb_proc_per_node_label = new QLabel("Nb proc/node:"); + _nb_proc_per_node_line = new QLineEdit(this); + QLabel * batch_label = new QLabel("Batch:"); + _batch_line = new QLineEdit(this); + QLabel * mpiImpl_label = new QLabel("MPI impl:"); + _mpiImpl_line = new QLineEdit(this); + QLabel * iprotocol_label = new QLabel("Internal proctocol:"); + _iprotocol_line = new QLineEdit(this); + QGridLayout * c_layout = new QGridLayout; + c_layout->addWidget(os_label, 0, 0); + c_layout->addWidget(_os_line, 0, 1); + c_layout->addWidget(mem_mb_label, 1, 0); + c_layout->addWidget(_mem_mb_line, 1, 1); + c_layout->addWidget(cpu_clock_label, 2, 0); + c_layout->addWidget(_cpu_clock_line, 2, 1); + c_layout->addWidget(nb_node_label, 3, 0); + c_layout->addWidget(_nb_node_line, 3, 1); + c_layout->addWidget(nb_proc_per_node_label, 4, 0); + c_layout->addWidget(_nb_proc_per_node_line, 4, 1); + c_layout->addWidget(batch_label, 5, 0); + c_layout->addWidget(_batch_line, 5, 1); + c_layout->addWidget(mpiImpl_label, 6, 0); + c_layout->addWidget(_mpiImpl_line, 6, 1); + c_layout->addWidget(iprotocol_label, 7, 0); + c_layout->addWidget(_iprotocol_line, 7, 1); + config_groupBox->setLayout(c_layout); + + // Main Layout + QVBoxLayout * mainLayout = new QVBoxLayout(this); + mainLayout->addWidget(main_groupBox); + mainLayout->addWidget(config_groupBox); + setLayout(mainLayout); + + if (_edit) + { + setWindowTitle("Add a new resource"); + } + else + { + setWindowTitle("Resource"); + get_infos(); + // Line cannot be changed + _name_line->setCursorPosition(0); + _hostname_line->setCursorPosition(0); + _protocol_line->setCursorPosition(0); + _username_line->setCursorPosition(0); + _applipath_line->setCursorPosition(0); + _os_line->setCursorPosition(0); + _mem_mb_line->setCursorPosition(0); + _cpu_clock_line->setCursorPosition(0); + _nb_node_line->setCursorPosition(0); + _nb_proc_per_node_line->setCursorPosition(0); + _batch_line->setCursorPosition(0); + _mpiImpl_line->setCursorPosition(0); + _iprotocol_line->setCursorPosition(0); + + _name_line->setReadOnly(true); + _hostname_line->setReadOnly(true); + _protocol_line->setReadOnly(true); + _username_line->setReadOnly(true); + _applipath_line->setReadOnly(true); + _os_line->setReadOnly(true); + _mem_mb_line->setReadOnly(true); + _cpu_clock_line->setReadOnly(true); + _nb_node_line->setReadOnly(true); + _nb_proc_per_node_line->setReadOnly(true); + _batch_line->setReadOnly(true); + _mpiImpl_line->setReadOnly(true); + _iprotocol_line->setReadOnly(true); + } +} + +JM::SalomeResource::~SalomeResource() +{ + DEBTRACE("Destroying JM::SalomeResource"); +} + +void +JM::SalomeResource::get_infos() +{ + BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_name); + + _name_line->setText(QString(resource_descr.name.c_str())); + _hostname_line->setText(QString(resource_descr.hostname.c_str())); + _protocol_line->setText(QString(resource_descr.protocol.c_str())); + _username_line->setText(QString(resource_descr.username.c_str())); + _applipath_line->setText(QString(resource_descr.applipath.c_str())); + _os_line->setText(QString(resource_descr.OS.c_str())); + _batch_line->setText(QString(resource_descr.batch.c_str())); + _mpiImpl_line->setText(QString(resource_descr.mpiImpl.c_str())); + _iprotocol_line->setText(QString(resource_descr.iprotocol.c_str())); + + QString value; + _mem_mb_line->setText(value.setNum(resource_descr.mem_mb)); + _cpu_clock_line->setText(value.setNum(resource_descr.cpu_clock)); + _nb_node_line->setText(value.setNum(resource_descr.nb_node)); + _nb_proc_per_node_line->setText(value.setNum(resource_descr.nb_proc_per_node)); + + std::list::iterator it = resource_descr.componentList.begin(); + for(; it != resource_descr.componentList.end(); it++) + _componentList->addItem(QString((*it).c_str())); +} + diff --git a/src/genericgui/JM_SalomeResource.hxx b/src/genericgui/JM_SalomeResource.hxx new file mode 100644 index 0000000..4daf7a0 --- /dev/null +++ b/src/genericgui/JM_SalomeResource.hxx @@ -0,0 +1,66 @@ +// Copyright (C) 2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _JM_SALOMERESOURCE_HXX_ +#define _JM_SALOMERESOURCE_HXX_ + +#include +#include "BL_SALOMEServices.hxx" + +#include + +namespace JM +{ + class SalomeResource: public QDialog + { + Q_OBJECT + + public: + SalomeResource(QWidget *parent, BL::SALOMEServices * salome_services, + const std::string & resource_name, bool edit); + virtual ~SalomeResource(); + + void get_infos(); + + protected: + QWidget* _parent; + BL::SALOMEServices * _salome_services; + std::string _resource_name; + bool _edit; + + // widget + QLineEdit * _name_line; + QLineEdit * _hostname_line; + QLineEdit * _protocol_line; + QLineEdit * _username_line; + QLineEdit * _applipath_line; + QListWidget * _componentList; + QLineEdit * _os_line; + QLineEdit * _mem_mb_line; + QLineEdit * _cpu_clock_line; + QLineEdit * _nb_node_line; + QLineEdit * _nb_proc_per_node_line; + QLineEdit * _batch_line; + QLineEdit * _mpiImpl_line; + QLineEdit * _iprotocol_line; + }; +} + +#endif + diff --git a/src/genericgui/Makefile.am b/src/genericgui/Makefile.am index 383fd24..d6c2879 100644 --- a/src/genericgui/Makefile.am +++ b/src/genericgui/Makefile.am @@ -29,13 +29,15 @@ libBL_GenericGui_la_SOURCES = BL_GenericGui.hxx BL_GenericGui.cxx \ BL_QModelManager.hxx BL_QModelManager.cxx \ BL_CreateJobWizard.hxx BL_CreateJobWizard.cxx \ BL_Summary.hxx BL_Summary.cxx \ - JM_ResourceCatalog.hxx JM_ResourceCatalog.cxx + JM_ResourceCatalog.hxx JM_ResourceCatalog.cxx \ + JM_SalomeResource.hxx JM_SalomeResource.cxx nodist_libBL_GenericGui_la_SOURCES = BL_GenericGui_moc.cxx BL_JobsTable_moc.cxx \ BL_JobTab_moc.cxx \ BL_Buttons_moc.cxx BL_JobsManager_QT_moc.cxx \ BL_QModelManager_moc.cxx BL_CreateJobWizard_moc.cxx \ - BL_Summary_moc.cxx JM_ResourceCatalog_moc.cxx + BL_Summary_moc.cxx JM_ResourceCatalog_moc.cxx \ + JM_SalomeResource_moc.cxx libBL_GenericGui_la_CXXFLAGS = $(qt4_cppflags) \ -I$(top_srcdir)/src/bases \ -- 2.39.2