From: Konstantin Leontev Date: Tue, 25 Jul 2023 15:31:35 +0000 (+0100) Subject: [bos #35138][EDF] (2023-T1) Specialization of resources in KERNEL. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0bcf5ecb518fda0a6c13dbd0cb584e9d5ab052b4;p=modules%2Fjobmanager.git [bos #35138][EDF] (2023-T1) Specialization of resources in KERNEL. --- diff --git a/src/engine/BL_SALOMEServices.cxx b/src/engine/BL_SALOMEServices.cxx index 4cff3e8..a2540b9 100644 --- a/src/engine/BL_SALOMEServices.cxx +++ b/src/engine/BL_SALOMEServices.cxx @@ -18,8 +18,37 @@ // #include "BL_SALOMEServices.hxx" + +#include "utilities.h" + #include + +namespace +{ + template + void resourceDefinition_CORBAtoCPP(const T& resDefIn, U& resDefOut) + { + resDefOut.name = resDefIn->name.in(); + resDefOut.hostname = resDefIn->hostname.in(); + resDefOut.protocol = resDefIn->protocol.in(); + resDefOut.username = resDefIn->username.in(); + resDefOut.applipath = resDefIn->applipath.in(); + resDefOut.batch = resDefIn->batch.in(); + } + + template + void resourceDefinition_CPPtoCORBA(const T& resDefIn, U& resDefOut) + { + resDefOut->name = CORBA::string_dup(resDefIn.name.c_str()); + resDefOut->hostname = CORBA::string_dup(resDefIn.hostname.c_str()); + resDefOut->protocol = CORBA::string_dup(resDefIn.protocol.c_str()); + resDefOut->username = CORBA::string_dup(resDefIn.username.c_str()); + resDefOut->applipath = CORBA::string_dup(resDefIn.applipath.c_str()); + resDefOut->batch = CORBA::string_dup(resDefIn.batch.c_str()); + } +} + static std::ostream & operator<<(std::ostream & os, const CORBA::Exception & e) { @@ -68,7 +97,7 @@ BL::SALOMEServices::initNS() if (CORBA::is_nil(_salome_launcher)) { - DEBMSG("SALOME Launcher is not reachable!") + MESSAGE("SALOME Launcher is not reachable!") return_value = false; } _salome_launcher->addObserver(_this()); @@ -78,7 +107,7 @@ BL::SALOMEServices::initNS() _resources_manager = Engines::ResourcesManager::_narrow(obj); if (CORBA::is_nil(_resources_manager)) { - DEBMSG("SALOME Resource Manager is not reachable !"); + MESSAGE("SALOME Resource Manager is not reachable !"); return_value = false; } @@ -86,70 +115,104 @@ BL::SALOMEServices::initNS() return return_value; } -std::list -BL::SALOMEServices::getResourceList(bool batch_only) +BL::ResourceList BL::SALOMEServices::getResourceList(bool isJobResource) const { - std::list resource_list; + if (!_state) + { + return {}; + } - if (_state) + Engines::ResourceList* resourceList = nullptr; + try { - Engines::ResourceParameters params; - _lcc->preSet(params); - params.can_launch_batch_jobs = batch_only; - Engines::ResourceList * resourceList = NULL; - try - { - resourceList = _resources_manager->GetFittingResources(params); - } - catch (const SALOME::SALOME_Exception & ex) + // In previous implementation we used GetFittingResources() to get + // all resources of job or container types separately. + // Now we don't need to search, because they're already separated. + if (isJobResource) { - DEBMSG("SALOME Exception in addResource ! " << ex.details.text.in()); + resourceList = _resources_manager->ListAllResourcesInCatalogJob(); } - catch (const CORBA::SystemException& ex) + else { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); - } - if (resourceList) + resourceList = _resources_manager->ListAllResourcesInCatalogContainer(); + } + } + catch (const SALOME::SALOME_Exception& ex) + { + MESSAGE(ex.details.text.in()); + } + catch (const CORBA::SystemException& ex) + { + MESSAGE(ex); + } + + ResourceList resource_list; + if (resourceList) + { + for (int i = 0; i < resourceList->length(); i++) { - for (int i = 0; i < resourceList->length(); i++) - { - const char* aResource = (*resourceList)[i]; - resource_list.push_back(aResource); - } - delete resourceList; + const char* aResource = (*resourceList)[i]; + resource_list.push_back(aResource); } + + delete resourceList; } + return resource_list; } -BL::ResourceDescr -BL::SALOMEServices::getResourceDescr(const std::string& name) +BL::ResourceDescrJob BL::SALOMEServices::getResourceDescrJob(const std::string& name) const { - Engines::ResourceDefinition * resource_definition = NULL; - BL::ResourceDescr resource_descr; + Engines::ResourceDefinitionJob* resource_definition = nullptr; + try + { + resource_definition = _resources_manager->GetResourceDefinitionJob(name.c_str()); + } + catch (const SALOME::SALOME_Exception& ex) + { + MESSAGE(ex.details.text.in()); + } + catch (const CORBA::SystemException& ex) + { + MESSAGE(ex); + } + + BL::ResourceDescrJob resource_descr; + if(resource_definition) + { + resourceDefinition_CORBAtoCPP(resource_definition, resource_descr); + + resource_descr.mpiImpl = resource_definition->mpiImpl.in(); + resource_descr.iprotocol = resource_definition->iprotocol.in(); + resource_descr.working_directory = resource_definition->working_directory.in(); + delete resource_definition; + } + + return resource_descr; +} + +BL::ResourceDescrContainer BL::SALOMEServices::getResourceDescrContainer(const std::string& name) const +{ + Engines::ResourceDefinitionContainer* resource_definition = nullptr; try { - resource_definition = _resources_manager-> GetResourceDefinition(name.c_str()); + resource_definition = _resources_manager->GetResourceDefinitionContainer(name.c_str()); } - catch (const SALOME::SALOME_Exception & ex) + catch (const SALOME::SALOME_Exception& ex) { - DEBMSG("SALOME Exception in addResource ! " << ex.details.text.in()); + MESSAGE(ex.details.text.in()); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE(ex); } + BL::ResourceDescrContainer resource_descr; if(resource_definition) { - 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(); + resourceDefinition_CORBAtoCPP(resource_definition, resource_descr); + for (int i = 0; i < resource_definition->componentList.length(); i++) { resource_descr.componentList.push_back(resource_definition->componentList[i].in()); @@ -161,92 +224,111 @@ BL::SALOMEServices::getResourceDescr(const std::string& name) 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(); - resource_descr.can_launch_batch_jobs = resource_definition->can_launch_batch_jobs; - resource_descr.can_run_containers = resource_definition->can_run_containers; - resource_descr.working_directory = resource_definition->working_directory.in(); delete resource_definition; } + return resource_descr; } -void -BL::SALOMEServices::addResource(BL::ResourceDescr & new_resource) +void BL::SALOMEServices::addResourceJob(BL::ResourceDescrJob& resource) { - Engines::ResourceDefinition_var resource_definition = new Engines::ResourceDefinition; + Engines::ResourceDefinitionJob_var resource_definition = new Engines::ResourceDefinitionJob; - resource_definition->name = CORBA::string_dup(new_resource.name.c_str()); - resource_definition->hostname = CORBA::string_dup(new_resource.hostname.c_str()); - if (new_resource.batch == "none") - resource_definition->type = CORBA::string_dup("single_machine"); - else - resource_definition->type = CORBA::string_dup("cluster"); - resource_definition->protocol = CORBA::string_dup(new_resource.protocol.c_str()); - resource_definition->username = CORBA::string_dup(new_resource.username.c_str()); - resource_definition->applipath = CORBA::string_dup(new_resource.applipath.c_str()); + resourceDefinition_CPPtoCORBA(resource, resource_definition); + + resource_definition->mpiImpl = CORBA::string_dup(resource.mpiImpl.c_str()); + resource_definition->iprotocol = CORBA::string_dup(resource.iprotocol.c_str()); + resource_definition->working_directory = CORBA::string_dup(resource.working_directory.c_str()); + + try + { + _resources_manager->AddResourceJob(resource_definition, true, ""); + } + catch(const SALOME::SALOME_Exception & ex) + { + MESSAGE(ex.details.text.in()); + throw(BL::Exception(ex.details.text.in())); + } + catch(const CORBA::SystemException& ex) + { + MESSAGE(ex); + throw(BL::Exception("SALOME System Exception")); + } +} + +void BL::SALOMEServices::addResourceContainer(BL::ResourceDescrContainer& resource) +{ + Engines::ResourceDefinitionContainer_var resource_definition = new Engines::ResourceDefinitionContainer; + + resourceDefinition_CPPtoCORBA(resource, resource_definition); int i = 0; - std::list::iterator it = new_resource.componentList.begin(); - resource_definition->componentList.length(new_resource.componentList.size()); - for(; it != new_resource.componentList.end(); it++) + resource_definition->componentList.length(resource.componentList.size()); + for(const auto& res: resource.componentList) { - resource_definition->componentList[i] = CORBA::string_dup((*it).c_str()); + resource_definition->componentList[i] = CORBA::string_dup(res.c_str()); i++; } - resource_definition->OS = CORBA::string_dup(new_resource.OS.c_str()); - resource_definition->mem_mb = new_resource.mem_mb; - resource_definition->cpu_clock = new_resource.cpu_clock; - resource_definition->nb_node = new_resource.nb_node; - resource_definition->nb_proc_per_node = new_resource.nb_proc_per_node; - resource_definition->batch = CORBA::string_dup(new_resource.batch.c_str()); - resource_definition->mpiImpl = CORBA::string_dup(new_resource.mpiImpl.c_str()); - resource_definition->iprotocol = CORBA::string_dup(new_resource.iprotocol.c_str()); - resource_definition->can_launch_batch_jobs = new_resource.can_launch_batch_jobs; - resource_definition->can_run_containers = new_resource.can_run_containers; - resource_definition->working_directory = CORBA::string_dup(new_resource.working_directory.c_str()); + resource_definition->OS = CORBA::string_dup(resource.OS.c_str()); + resource_definition->mem_mb = resource.mem_mb; + resource_definition->cpu_clock = resource.cpu_clock; + resource_definition->nb_node = resource.nb_node; + resource_definition->nb_proc_per_node = resource.nb_proc_per_node; try { - _resources_manager->AddResource(resource_definition, true, ""); + _resources_manager->AddResourceContainer(resource_definition, true, ""); } - catch (const SALOME::SALOME_Exception & ex) + catch(const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in addResource ! " << ex.details.text.in()); + MESSAGE(ex.details.text.in()); throw(BL::Exception(ex.details.text.in())); } - catch (const CORBA::SystemException& ex) + catch(const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE(ex); throw(BL::Exception("SALOME System Exception")); } } -void -BL::SALOMEServices::removeResource(const std::string & name) +void BL::SALOMEServices::removeResourceJob(const std::string& name) +{ + try + { + _resources_manager->RemoveResourceJob(name.c_str(), true, ""); + } + catch (const SALOME::SALOME_Exception & ex) + { + MESSAGE(ex.details.text.in()); + } + catch (const CORBA::SystemException& ex) + { + MESSAGE(ex); + } +} + +void BL::SALOMEServices::removeResourceContainer(const std::string& name) { try { - _resources_manager->RemoveResource(name.c_str(), true, ""); + _resources_manager->RemoveResourceContainer(name.c_str(), true, ""); } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in removeResource ! " << ex.details.text.in()); + MESSAGE(ex.details.text.in()); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE(ex); } } std::string BL::SALOMEServices::create_job(BL::Job * job) { - DEBMSG("Begin of create_job"); + MESSAGE("Begin of create_job"); std::string ret = ""; Engines::JobParameters_var job_parameters = new Engines::JobParameters; @@ -370,13 +452,13 @@ BL::SALOMEServices::create_job(BL::Job * job) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in createJob !"); + MESSAGE("SALOME Exception in createJob !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive SALOME System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "SALOME System Exception - see logs"; } return ret; @@ -393,13 +475,13 @@ BL::SALOMEServices::start_job(BL::Job * job) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in launchJob !"); + MESSAGE("SALOME Exception in launchJob !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive SALOME System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "SALOME System Exception - see logs"; } return ret; @@ -418,13 +500,13 @@ BL::SALOMEServices::refresh_job(BL::Job * job) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in getJobState !"); + MESSAGE("SALOME Exception in getJobState !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive SALOME System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "SALOME System Exception - see logs"; } return ret; @@ -441,13 +523,13 @@ BL::SALOMEServices::delete_job(BL::Job * job) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in removeJob !"); + MESSAGE("SALOME Exception in removeJob !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive SALOME System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "SALOME System Exception - see logs"; } return ret; @@ -463,13 +545,13 @@ BL::SALOMEServices::stop_job(BL::Job * job) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in stopJob !"); + MESSAGE("SALOME Exception in stopJob !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive SALOME System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "SALOME System Exception - see logs"; } return ret; @@ -490,13 +572,13 @@ BL::SALOMEServices::get_results_job(BL::Job * job) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in refresh_job !"); + MESSAGE("SALOME Exception in refresh_job !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive SALOME System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "SALOME System Exception - see logs"; } return ret; @@ -515,13 +597,13 @@ BL::SALOMEServices::get_assigned_hostnames(BL::Job * job) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in get_assigned_hostnames !"); + MESSAGE("SALOME Exception in get_assigned_hostnames !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive SALOME System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive SALOME System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "SALOME System Exception - see logs"; } return ret; @@ -538,13 +620,13 @@ BL::SALOMEServices::save_jobs(const std::string & file_name) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in saveJobs !"); + MESSAGE("SALOME Exception in saveJobs !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive CORBA System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive CORBA System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "CORBA System Exception - see SALOME logs"; } return ret; @@ -561,13 +643,13 @@ BL::SALOMEServices::load_jobs(const std::string & file_name) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in loadJobs !"); + MESSAGE("SALOME Exception in loadJobs !"); ret = ex.details.text.in(); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive CORBA System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive CORBA System Exception: " << ex); + MESSAGE("Check SALOME servers..."); ret = "CORBA System Exception - see SALOME logs"; } return ret; @@ -576,7 +658,7 @@ BL::SALOMEServices::load_jobs(const std::string & file_name) void BL::SALOMEServices::notify(const char* event_name, const char * event_data) { - DEBMSG("Launcher event received " << event_name << " " << event_data); + MESSAGE("Launcher event received " << event_name << " " << event_data); std::string event(event_name); std::string data(event_data); @@ -603,14 +685,14 @@ BL::SALOMEServices::notify(const char* event_name, const char * event_data) } else { - DEBMSG("Unkown launcher event received"); + MESSAGE("Unkown launcher event received"); } } BL::Job * BL::SALOMEServices::get_new_job(int job_number) { - DEBMSG("Start of BL::SALOMEServices::get_new_job"); + MESSAGE("Start of BL::SALOMEServices::get_new_job"); BL::Job * job_return = NULL; Engines::JobParameters * job_parameters = NULL; try @@ -619,12 +701,12 @@ BL::SALOMEServices::get_new_job(int job_number) } catch (const SALOME::SALOME_Exception & ex) { - DEBMSG("SALOME Exception in saveJobs !"); + MESSAGE("SALOME Exception in saveJobs !"); } catch (const CORBA::SystemException& ex) { - DEBMSG("Receive CORBA System Exception: " << ex); - DEBMSG("Check SALOME servers..."); + MESSAGE("Receive CORBA System Exception: " << ex); + MESSAGE("Check SALOME servers..."); } if (job_parameters) @@ -705,7 +787,7 @@ BL::SALOMEServices::get_new_job(int job_number) else { // Error in getting state - DEBMSG("Error in getting state of the new job!"); + MESSAGE("Error in getting state of the new job!"); delete job_return; job_return = NULL; } diff --git a/src/engine/BL_SALOMEServices.hxx b/src/engine/BL_SALOMEServices.hxx index 0987058..611317d 100644 --- a/src/engine/BL_SALOMEServices.hxx +++ b/src/engine/BL_SALOMEServices.hxx @@ -41,6 +41,8 @@ namespace BL{ class JobsManager; + using ResourceList = std::list; + struct BL_Engine_EXPORT ResourceDescr { std::string name; @@ -48,20 +50,24 @@ namespace BL{ std::string protocol; std::string username; std::string applipath; - std::list componentList; + std::string batch; + }; + + struct BL_Engine_EXPORT ResourceDescrJob : ResourceDescr + { + std::string mpiImpl; + std::string iprotocol; + std::string working_directory; + }; + struct BL_Engine_EXPORT ResourceDescrContainer : ResourceDescr + { + ResourceList 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; - - bool can_launch_batch_jobs; - bool can_run_containers; - std::string working_directory; }; class BL_Engine_EXPORT SALOMEServices : @@ -76,10 +82,16 @@ namespace BL{ void set_manager(BL::JobsManager * manager) {_manager = manager;} - std::list getResourceList(bool batch_only); - BL::ResourceDescr getResourceDescr(const std::string& name); - void addResource(BL::ResourceDescr & new_resource); - void removeResource(const std::string & name); + ResourceList getResourceList(bool isJobResource) const; + + BL::ResourceDescrJob getResourceDescrJob(const std::string& name) const; + BL::ResourceDescrContainer getResourceDescrContainer(const std::string& name) const; + + void addResourceJob(BL::ResourceDescrJob& resource); + void addResourceContainer(BL::ResourceDescrContainer& resource); + + void removeResourceJob(const std::string& name); + void removeResourceContainer(const std::string& name); std::string save_jobs(const std::string & file_name); std::string load_jobs(const std::string & file_name); diff --git a/src/genericgui/BL_CreateJobWizard.cxx b/src/genericgui/BL_CreateJobWizard.cxx index 8a9e063..adace53 100644 --- a/src/genericgui/BL_CreateJobWizard.cxx +++ b/src/genericgui/BL_CreateJobWizard.cxx @@ -175,7 +175,7 @@ BL::CreateJobWizard::clone(const std::string & name) // For COORM BL::Job::BatchParam batch_params = job->getBatchParameters(); - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str()); + BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(job->getResource().c_str()); std::string batch = resource_descr.batch.c_str(); if (batch == "coorm") { @@ -407,7 +407,7 @@ BL::CreateJobWizard::end(int result) batch_partition = f_batch_partition.trimmed().toUtf8().constData(); // LoadLeveler JobType - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed); + BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(resource_choosed); std::string batch = resource_descr.batch.c_str(); if (batch == "ll") { @@ -850,7 +850,7 @@ BatchParametersPage::initializePage() { resource_choosed = f_resource_choosed; // If choosed resource has a SLURM batch manager, activate option "memory per cpu" - ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed); + const ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(resource_choosed); if (resource_descr.batch == "slurm") { ui->combo_memory_req_type->setEnabled(true); @@ -1011,7 +1011,7 @@ BL::COORM_BatchParametersPage::initializePage() resource_choosed = f_resource_choosed; // If choosed resource has a working_directory set // Generates a default remote working directory - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData()); + BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(resource_choosed.toUtf8().constData()); QString res_work_dir = resource_descr.working_directory.c_str(); if (res_work_dir != "") { @@ -1076,7 +1076,7 @@ FilesPage::initializePage() resource_choosed = f_resource_choosed; // If choosed resource has a working_directory set // Generates a default remote working directory - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData()); + BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(resource_choosed.toUtf8().constData()); QString res_work_dir = resource_descr.working_directory.c_str(); if (res_work_dir != "") { @@ -1331,7 +1331,7 @@ BL::ResourcePage::validatePage() return false; } - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData()); + BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(resource_choosed.toUtf8().constData()); std::string batch = resource_descr.batch.c_str(); if (batch == "ll") { @@ -1353,7 +1353,7 @@ BL::ResourcePage::itemSelected(QListWidgetItem * item) _resource_choosed->setReadOnly(true); //Specific parameters for LoadLeveler - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData()); + BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(item->text().toUtf8().constData()); std::string batch = resource_descr.batch.c_str(); if (batch == "ll") { @@ -1374,7 +1374,7 @@ BL::ResourcePage::itemSelected(QListWidgetItem * item) int BL::ResourcePage::nextId() const { - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData()); + BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(_resource_choosed->text().toUtf8().constData()); std::string batch = resource_descr.batch.c_str(); if (batch == "coorm") { diff --git a/src/genericgui/BL_JobsManager_QT.cxx b/src/genericgui/BL_JobsManager_QT.cxx index 384ea3b..c5b2a6e 100644 --- a/src/genericgui/BL_JobsManager_QT.cxx +++ b/src/genericgui/BL_JobsManager_QT.cxx @@ -148,14 +148,14 @@ BL::JobsManager_QT::save_jobs_button() dialog.setNameFilters(filters); dialog.selectNameFilter("(*.xml)"); dialog.setDefaultSuffix("xml"); - dialog.setConfirmOverwrite(true); + dialog.setOption(QFileDialog::DontConfirmOverwrite, false); dialog.setAcceptMode(QFileDialog::AcceptSave); QString jobs_file(""); QStringList fileNames; fileNames.clear(); if (bool ret = dialog.exec()) { - DEBTRACE(ret << " " << dialog.confirmOverwrite()); + DEBTRACE(ret << " " << !dialog.testOption(QFileDialog::DontConfirmOverwrite)); fileNames = dialog.selectedFiles(); if (!fileNames.isEmpty()) jobs_file= fileNames.first(); diff --git a/src/genericgui/CMakeLists.txt b/src/genericgui/CMakeLists.txt index 272e440..15464ff 100644 --- a/src/genericgui/CMakeLists.txt +++ b/src/genericgui/CMakeLists.txt @@ -58,8 +58,9 @@ SET(BL_GenericGui_HEADERS BL_CreateJobWizard.hxx BL_Summary.hxx JM_ResourceCatalog.hxx - JM_SalomeResource.hxx JM_EditSalomeResource.hxx + JM_EditSalomeResourceJob.hxx + JM_EditSalomeResourceContainer.hxx ) # --- sources --- @@ -77,9 +78,10 @@ SET(_other_SOURCES BL_QModelManager.cxx BL_CreateJobWizard.cxx BL_Summary.cxx - JM_ResourceCatalog.cxx - JM_SalomeResource.cxx + JM_ResourceCatalog.cxx JM_EditSalomeResource.cxx + JM_EditSalomeResourceJob.cxx + JM_EditSalomeResourceContainer.cxx ) # --- resources --- diff --git a/src/genericgui/JM_EditSalomeResource.cxx b/src/genericgui/JM_EditSalomeResource.cxx index a254d27..f2b603f 100644 --- a/src/genericgui/JM_EditSalomeResource.cxx +++ b/src/genericgui/JM_EditSalomeResource.cxx @@ -14,54 +14,78 @@ // 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 +// See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "JM_EditSalomeResource.hxx" #include "BL_Traces.hxx" +#include "utilities.h" -#include #include #include #include #include -#include #include #include -#include #include -#include -#include #include -using namespace std; -JM::EditSalomeResource::EditSalomeResource(QWidget *parent, BL::SALOMEServices * salome_services, - const std::string & resource_name) : QDialog(parent) +JM::EditSalomeResource::EditSalomeResource( + QWidget* parent, + BL::SALOMEServices* salome_services, + const std::string& resource_name /* = ""*/ + ) : + QDialog(parent), + _parent(parent), + _salome_services(salome_services), + _resource_name(resource_name) { - DEBTRACE("Creating JM::EditSalomeResource"); + MESSAGE("Creating JM::EditSalomeResource"); BL_ASSERT(parent); BL_ASSERT(salome_services); - _parent = parent; - _salome_services = salome_services; - _resource_name = resource_name; +} + +JM::EditSalomeResource::~EditSalomeResource() +{ + MESSAGE("Destroying JM::EditSalomeResource"); +} + +void JM::EditSalomeResource::init(const QString& resourceType) +{ + MESSAGE("Init dialog for :" << resourceType.toUtf8().constData()); - //setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + QGroupBox* main_groupBox = initMainValues(); + QGroupBox* config_groupBox = initConfigValues(); + QDialogButtonBox* buttonBox = initDialogButtonBox(); - // Widget code + QVBoxLayout* mainLayout = new QVBoxLayout(this); + mainLayout->addWidget(main_groupBox); + mainLayout->addWidget(config_groupBox); + mainLayout->addWidget(buttonBox); + setLayout(mainLayout); - // Part 1 - QGroupBox * main_groupBox = new QGroupBox("Main values"); - QLabel * name_label = new QLabel("Name:"); + setWindowTitle("Edit/Add a " + resourceType); + if (!_resource_name.empty()) + { + get_infos(); + } +} + +void JM::EditSalomeResource::accept() +{ + QDialog::accept(); +} + +QGroupBox* JM::EditSalomeResource::initMainValues() +{ + QLabel* name_label = new QLabel("Name:"); _name_line = new QLineEdit(this); - QLabel * hostname_label = new QLabel("Hostname:"); + + QLabel* hostname_label = new QLabel("Hostname:"); _hostname_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 * protocol_label = new QLabel("Protocol:"); + QLabel* protocol_label = new QLabel("Protocol:"); _protocol_line = new QComboBox(this); _protocol_line->addItem("ssh"); _protocol_line->addItem("rsh"); @@ -69,83 +93,13 @@ JM::EditSalomeResource::EditSalomeResource(QWidget *parent, BL::SALOMEServices * _protocol_line->addItem("rsync"); _protocol_line->setCurrentIndex(0); - QLabel * componentList_label = new QLabel("Component List:"); - _add_button = new QPushButton("Add"); - _remove_button = new QPushButton("Remove"); - _remove_button->setEnabled(false); - QWidget * component_widget = new QWidget(this); - _componentList = new QListWidget(this); - _componentList->setSelectionMode(QAbstractItemView::MultiSelection); - QGridLayout * input_box = new QGridLayout(this); - input_box->addWidget(_add_button, 0, 0); - input_box->addWidget(_remove_button, 0, 1); - input_box->addWidget(_componentList, 1, 0, 1, -1); - component_widget->setLayout(input_box); - connect(_add_button, SIGNAL(clicked()), this, SLOT(add_component())); - connect(_remove_button, SIGNAL(clicked()), this, SLOT(remove_components())); - connect(_componentList, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged())); - - QLabel * working_directory_label = new QLabel("Working Directory:"); - _working_directory = new QLineEdit(this); - _can_launch_batch_jobs = new QCheckBox("This resource can be used to launch batch jobs", this); - _can_launch_batch_jobs->setCheckState(Qt::Checked); - _can_run_containers = new QCheckBox("This resource can be used to run interactive containers", this); - - 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(component_widget, 5, 1); - m_layout->addWidget(working_directory_label, 6, 0); - m_layout->addWidget(_working_directory, 6, 1); - m_layout->addWidget(_can_launch_batch_jobs, 7, 1); - m_layout->addWidget(_can_run_containers, 8, 1); - main_groupBox->setLayout(m_layout); + QLabel* username_label = new QLabel("Username:"); + _username_line = new QLineEdit(this); + + QLabel* applipath_label = new QLabel("Applipath:"); + _applipath_line = new QLineEdit(this); - // Part 2 - 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 QSpinBox(this); - _mem_mb_line->setMinimum(0); - _mem_mb_line->setMaximum(1000000); - _mem_mb_line->setValue(0); - QLabel * cpu_clock_label = new QLabel("CPU Clock:"); - _cpu_clock_line = new QSpinBox(this); - _cpu_clock_line->setMinimum(0); - _cpu_clock_line->setMaximum(1000000); - _cpu_clock_line->setValue(0); - QLabel * nb_node_label = new QLabel("Nb node:"); - _nb_node_line = new QSpinBox(this); - _nb_node_line->setMinimum(1); - _nb_node_line->setMaximum(1000000); - _nb_node_line->setValue(1); - QLabel * nb_proc_per_node_label = new QLabel("Nb proc/node:"); - _nb_proc_per_node_line = new QSpinBox(this); - _nb_proc_per_node_line->setMinimum(1); - _nb_proc_per_node_line->setMaximum(1000000); - _nb_proc_per_node_line->setValue(1); - - QLabel * iprotocol_label = new QLabel("Internal protocol:"); - _iprotocol_line = new QComboBox(this); - _iprotocol_line->addItem("ssh"); - _iprotocol_line->addItem("rsh"); - _iprotocol_line->addItem("srun"); - _iprotocol_line->addItem("pbsdsh"); - _iprotocol_line->addItem("blaunch"); - _iprotocol_line->setCurrentIndex(0); - - QLabel * batch_label = new QLabel("Batch Manager:"); + QLabel* batch_label = new QLabel("Batch Manager:"); _batch_line = new QComboBox(this); _batch_line->addItem("None", "none"); _batch_line->addItem("CCC", "ccc"); @@ -159,82 +113,62 @@ JM::EditSalomeResource::EditSalomeResource(QWidget *parent, BL::SALOMEServices * _batch_line->addItem("VISHNU (limited support)", "vishnu"); _batch_line->setCurrentIndex(0); - QLabel * mpiImpl_label = new QLabel("MPI impl:"); - _mpiImpl_line = new QComboBox(this); - _mpiImpl_line->addItem("lam"); - _mpiImpl_line->addItem("mpich1"); - _mpiImpl_line->addItem("mpich2"); - _mpiImpl_line->addItem("openmpi"); - _mpiImpl_line->addItem("slurmmpi"); - _mpiImpl_line->addItem("prun"); - _mpiImpl_line->setCurrentIndex(-1); - - 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); - - // Part 3 - QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok - | QDialogButtonBox::Cancel); + 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(batch_label, 5, 0); + m_layout->addWidget(_batch_line, 5, 1); + + QGroupBox* main_groupBox = new QGroupBox("Main values"); + main_groupBox->setLayout(m_layout); + + return main_groupBox; +} + +QGroupBox* JM::EditSalomeResource::initConfigValues() +{ + MESSAGE("Init resource config values..."); + + return new QGroupBox("Configuration values"); +} + +QDialogButtonBox* JM::EditSalomeResource::initDialogButtonBox() +{ + QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - // Main Layout - QVBoxLayout * mainLayout = new QVBoxLayout(this); - mainLayout->addWidget(main_groupBox); - mainLayout->addWidget(config_groupBox); - mainLayout->addWidget(buttonBox); - setLayout(mainLayout); - - setWindowTitle("Edit/Add a resource"); - if (_resource_name != "") - get_infos(); + return buttonBox; } -JM::EditSalomeResource::~EditSalomeResource() +void JM::EditSalomeResource::get_infos() { - DEBTRACE("Destroying JM::EditSalomeResource"); + // Should be implemented in derived class } -void -JM::EditSalomeResource::get_infos() +bool JM::EditSalomeResource::copyValuesFromResource(const BL::ResourceDescr& resourceIn) { - 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())); - _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())); - _working_directory->setText(QString(resource_descr.working_directory.c_str())); + if (resourceIn.name.empty() || resourceIn.hostname.empty() || resourceIn.protocol.empty()) + { + QMessageBox::warning(NULL, "Values missing", "name, hostname and protocol are mandatory!"); - if (resource_descr.can_launch_batch_jobs) - _can_launch_batch_jobs->setCheckState(Qt::Checked); - else - _can_launch_batch_jobs->setCheckState(Qt::Unchecked); + // TODO: should we do something whith this error? + //return false; + } - if (resource_descr.can_run_containers) - _can_run_containers->setCheckState(Qt::Checked); - else - _can_run_containers->setCheckState(Qt::Unchecked); + _name_line->setText(QString(resourceIn.name.c_str())); + _hostname_line->setText(QString(resourceIn.hostname.c_str())); - std::string protocol = resource_descr.protocol.c_str(); + const std::string& protocol = resourceIn.protocol.c_str(); if (protocol == "ssh") _protocol_line->setCurrentIndex(0); else if(protocol == "rsh") @@ -246,150 +180,42 @@ JM::EditSalomeResource::get_infos() else _protocol_line->setCurrentIndex(-1); - std::string iprotocol = resource_descr.iprotocol.c_str(); - if (iprotocol == "ssh") - _iprotocol_line->setCurrentIndex(0); - else if (iprotocol == "rsh") - _iprotocol_line->setCurrentIndex(1); - else if (iprotocol == "srun") - _iprotocol_line->setCurrentIndex(2); - else if (iprotocol == "pbsdsh") - _iprotocol_line->setCurrentIndex(3); - else if (iprotocol == "blaunch") - _iprotocol_line->setCurrentIndex(4); - else - _iprotocol_line->setCurrentIndex(-1); + _username_line->setText(QString(resourceIn.username.c_str())); + _applipath_line->setText(QString(resourceIn.applipath.c_str())); - for (int i=0 ; i<_batch_line->count() ; i++) + for (int i = 0 ; i < _batch_line->count(); i++) { - if (_batch_line->itemData(i).toString().toStdString() == resource_descr.batch) + if (_batch_line->itemData(i).toString().toStdString() == resourceIn.batch) { _batch_line->setCurrentIndex(i); } } - std::string mpiImpl = resource_descr.mpiImpl.c_str(); - if (mpiImpl == "lam") - _mpiImpl_line->setCurrentIndex(0); - else if (mpiImpl == "mpich1") - _mpiImpl_line->setCurrentIndex(1); - else if (mpiImpl == "mpich2") - _mpiImpl_line->setCurrentIndex(2); - else if (mpiImpl == "openmpi") - _mpiImpl_line->setCurrentIndex(3); - else if (mpiImpl == "slurmmpi") - _mpiImpl_line->setCurrentIndex(4); - else if (mpiImpl == "prun") - _mpiImpl_line->setCurrentIndex(5); - else - _mpiImpl_line->setCurrentIndex(-1); - - int value = resource_descr.mem_mb; - if (value > 0) - _mem_mb_line->setValue(value); - value = resource_descr.cpu_clock; - if (value > 0) - _cpu_clock_line->setValue(value); - value = resource_descr.nb_node; - if (value > 1) - _nb_node_line->setValue(value); - value = resource_descr.nb_proc_per_node; - if (value > 1) - _nb_proc_per_node_line->setValue(value); - - std::list::iterator it = resource_descr.componentList.begin(); - for(; it != resource_descr.componentList.end(); it++) - _componentList->addItem(QString((*it).c_str())); - // Better if string's length is bigger than the widget _name_line->setCursorPosition(0); _hostname_line->setCursorPosition(0); _username_line->setCursorPosition(0); _applipath_line->setCursorPosition(0); - _os_line->setCursorPosition(0); - _working_directory->setCursorPosition(0); -} - -void -JM::EditSalomeResource::itemSelectionChanged() -{ - if (_componentList->selectedItems().size() > 0) - _remove_button->setEnabled(true); - else - _remove_button->setEnabled(false); + return true; } -void -JM::EditSalomeResource::add_component() +bool JM::EditSalomeResource::copyValuesToResource(BL::ResourceDescr& resourceOut) const { - bool ok; - QString text = QInputDialog::getText(this, "Add a component", - "Component name:", QLineEdit::Normal, - "", &ok); - if (ok && !text.isEmpty()) - _componentList->addItem(text); -} - -void -JM::EditSalomeResource::remove_components() -{ - QList list = _componentList->selectedItems(); - for (int i = 0; i < list.size(); ++i) - { - int row = _componentList->row( list.at(i) ); - delete _componentList->takeItem(row); - } -} + resourceOut.name = _name_line->text().trimmed().toUtf8().constData(); + resourceOut.hostname = _hostname_line->text().trimmed().toStdString(); + resourceOut.protocol = _protocol_line->currentText().toStdString(); -void -JM::EditSalomeResource::accept() -{ - BL::ResourceDescr resource; - - // Text - resource.name = _name_line->text().trimmed().toUtf8().constData(); - resource.hostname = _hostname_line->text().trimmed().toStdString(); - resource.username = _username_line->text().trimmed().toStdString(); - resource.applipath = _applipath_line->text().trimmed().toUtf8().constData(); - resource.OS = _os_line->text().trimmed().toStdString(); - resource.working_directory = _working_directory->text().trimmed().toUtf8().constData(); - resource.can_launch_batch_jobs = (_can_launch_batch_jobs->checkState() == Qt::Checked); - resource.can_run_containers = (_can_run_containers->checkState() == Qt::Checked); - - // Components - int count = _componentList->count(); - for (int i = 0; i < count; i++) - resource.componentList.push_back(_componentList->item(i)->text().trimmed().toStdString()); - - // ComboBox - resource.protocol = _protocol_line->currentText().toStdString(); - resource.iprotocol = _iprotocol_line->currentText().toStdString(); - resource.batch = _batch_line->itemData(_batch_line->currentIndex()).toString().toStdString(); - resource.mpiImpl = _mpiImpl_line->currentText().toStdString(); - - // QSpinBox - resource.mem_mb = _mem_mb_line->value(); - resource.cpu_clock = _cpu_clock_line->value(); - resource.nb_node = _nb_node_line->value(); - resource.nb_proc_per_node = _nb_proc_per_node_line->value(); - - if (resource.name != "" && - resource.hostname != "" && - resource.protocol != "") - { - try - { - _salome_services->addResource(resource); - QDialog::accept(); - } - catch (const BL::Exception & ex) - { - QMessageBox::critical(this, "Error", QString("Cannot add resource: ") + ex.what()); - } - } - else + if (resourceOut.name.empty() || resourceOut.hostname.empty() || resourceOut.protocol.empty()) { QMessageBox::warning(NULL, "Values missing", "name, hostname and protocol are mandatory! Cancel or add values!"); + + return false; } + + resourceOut.username = _username_line->text().trimmed().toStdString(); + resourceOut.applipath = _applipath_line->text().trimmed().toUtf8().constData(); + resourceOut.batch = _batch_line->itemData(_batch_line->currentIndex()).toString().toStdString(); + + return true; } diff --git a/src/genericgui/JM_EditSalomeResource.hxx b/src/genericgui/JM_EditSalomeResource.hxx index 3bac412..82c0740 100644 --- a/src/genericgui/JM_EditSalomeResource.hxx +++ b/src/genericgui/JM_EditSalomeResource.hxx @@ -23,64 +23,55 @@ #include "BL_SALOMEServices.hxx" #include -#include -class QCheckBox; class QComboBox; class QLineEdit; -class QListWidget; -class QPushButton; -class QSpinBox; +class QGroupBox; +class QDialogButtonBox; namespace JM { + // Base class for all type of resources: job and containers class EditSalomeResource: public QDialog { Q_OBJECT public: - EditSalomeResource(QWidget *parent, - BL::SALOMEServices * salome_services, - const std::string & resource_name = ""); + EditSalomeResource( + QWidget* parent, + BL::SALOMEServices* salome_services, + const std::string& resource_name = "" + ); + virtual ~EditSalomeResource(); - void get_infos(); + void init(const QString& resourceType); public slots: virtual void accept(); - void add_component(); - void remove_components(); - void itemSelectionChanged(); protected: - QWidget* _parent; - BL::SALOMEServices * _salome_services; - std::string _resource_name; - - // widget - QLineEdit * _name_line; - QLineEdit * _hostname_line; - QLineEdit * _username_line; - QLineEdit * _applipath_line; - QListWidget * _componentList; - QLineEdit * _os_line; + QGroupBox* initMainValues(); + virtual QGroupBox* initConfigValues(); + QDialogButtonBox* initDialogButtonBox(); - QComboBox * _protocol_line; - QComboBox * _iprotocol_line; - QComboBox * _batch_line; - QComboBox * _mpiImpl_line; + virtual void get_infos(); - QSpinBox * _mem_mb_line; - QSpinBox * _cpu_clock_line; - QSpinBox * _nb_node_line; - QSpinBox * _nb_proc_per_node_line; + virtual bool copyValuesFromResource(const BL::ResourceDescr& resourceIn); + virtual bool copyValuesToResource(BL::ResourceDescr& resourceOut) const; - QLineEdit * _working_directory; - QCheckBox * _can_launch_batch_jobs; - QCheckBox * _can_run_containers; + protected: + QWidget* _parent = nullptr; + BL::SALOMEServices* _salome_services = nullptr; + std::string _resource_name; - QPushButton * _add_button; - QPushButton * _remove_button; + // widget + QLineEdit* _name_line; + QLineEdit* _hostname_line; + QComboBox* _protocol_line; + QLineEdit* _username_line; + QLineEdit* _applipath_line; + QComboBox* _batch_line; }; } diff --git a/src/genericgui/JM_EditSalomeResourceContainer.cxx b/src/genericgui/JM_EditSalomeResourceContainer.cxx new file mode 100644 index 0000000..8eb6f19 --- /dev/null +++ b/src/genericgui/JM_EditSalomeResourceContainer.cxx @@ -0,0 +1,221 @@ +// Copyright (C) 2009-2023 CEA, EDF +// +// 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, or (at your option) any later version. +// +// 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 https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "JM_EditSalomeResourceContainer.hxx" +#include "utilities.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +JM::EditSalomeResourceContainer::EditSalomeResourceContainer( + QWidget* parent, + BL::SALOMEServices* salome_services, + const std::string& resource_name /* = ""*/ + ) : + EditSalomeResource(parent, salome_services, resource_name) +{ + MESSAGE("Creating JM::EditSalomeResourceContainer"); +} + +QGroupBox* JM::EditSalomeResourceContainer::initConfigValues() +{ + MESSAGE("Init container resource config values..."); + + QLabel* componentList_label = new QLabel("Component List:"); + _add_button = new QPushButton("Add"); + _remove_button = new QPushButton("Remove"); + _remove_button->setEnabled(false); + + QWidget* component_widget = new QWidget(this); + _componentList = new QListWidget(this); + _componentList->setSelectionMode(QAbstractItemView::MultiSelection); + + QGridLayout* input_box = new QGridLayout(this); + input_box->addWidget(_add_button, 0, 0); + input_box->addWidget(_remove_button, 0, 1); + input_box->addWidget(_componentList, 1, 0, 1, -1); + component_widget->setLayout(input_box); + + connect(_add_button, SIGNAL(clicked()), this, SLOT(add_component())); + connect(_remove_button, SIGNAL(clicked()), this, SLOT(remove_components())); + connect(_componentList, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged())); + + QLabel* os_label = new QLabel("OS:"); + _os_line = new QLineEdit(this); + + QLabel* mem_mb_label = new QLabel("Memory (mb):"); + _mem_mb_line = new QSpinBox(this); + _mem_mb_line->setMinimum(0); + _mem_mb_line->setMaximum(1000000); + _mem_mb_line->setValue(0); + + QLabel* cpu_clock_label = new QLabel("CPU Clock:"); + _cpu_clock_line = new QSpinBox(this); + _cpu_clock_line->setMinimum(0); + _cpu_clock_line->setMaximum(1000000); + _cpu_clock_line->setValue(0); + + QLabel* nb_node_label = new QLabel("Nb node:"); + _nb_node_line = new QSpinBox(this); + _nb_node_line->setMinimum(1); + _nb_node_line->setMaximum(1000000); + _nb_node_line->setValue(1); + + QLabel* nb_proc_per_node_label = new QLabel("Nb proc/node:"); + _nb_proc_per_node_line = new QSpinBox(this); + _nb_proc_per_node_line->setMinimum(1); + _nb_proc_per_node_line->setMaximum(1000000); + _nb_proc_per_node_line->setValue(1); + + QGridLayout* c_layout = new QGridLayout; + c_layout->addWidget(componentList_label, 0, 0); + c_layout->addWidget(component_widget, 0, 1); + c_layout->addWidget(os_label, 1, 0); + c_layout->addWidget(_os_line, 1, 1); + c_layout->addWidget(mem_mb_label, 2, 0); + c_layout->addWidget(_mem_mb_line, 2, 1); + c_layout->addWidget(cpu_clock_label, 3, 0); + c_layout->addWidget(_cpu_clock_line, 3, 1); + c_layout->addWidget(nb_node_label, 4, 0); + c_layout->addWidget(_nb_node_line, 4, 1); + c_layout->addWidget(nb_proc_per_node_label, 5, 0); + c_layout->addWidget(_nb_proc_per_node_line, 5, 1); + + QGroupBox* config_groupBox = JM::EditSalomeResource::initConfigValues(); + config_groupBox->setLayout(c_layout); + + return config_groupBox; +} + +JM::EditSalomeResourceContainer::~EditSalomeResourceContainer() +{ + DEBTRACE("Destroying JM::EditSalomeResourceContainer"); +} + +void JM::EditSalomeResourceContainer::get_infos() +{ + const BL::ResourceDescrContainer resource_descr = _salome_services->getResourceDescrContainer(_resource_name); + if (!JM::EditSalomeResource::copyValuesFromResource(resource_descr)) + { + return; + } + + for(const auto& res : resource_descr.componentList) + { + _componentList->addItem(QString(res.c_str())); + } + + _os_line->setText(QString(resource_descr.OS.c_str())); + + if (resource_descr.mem_mb > 0) + { + _mem_mb_line->setValue(resource_descr.mem_mb); + } + + if (resource_descr.cpu_clock > 0) + { + _cpu_clock_line->setValue(resource_descr.cpu_clock); + } + + if (resource_descr.nb_node > 1) + { + _nb_node_line->setValue(resource_descr.nb_node); + } + + if (resource_descr.nb_proc_per_node > 1) + { + _nb_proc_per_node_line->setValue(resource_descr.nb_proc_per_node); + } + + // Better if string's length is bigger than the widget + _os_line->setCursorPosition(0); +} + +void JM::EditSalomeResourceContainer::itemSelectionChanged() +{ + const bool isSelected = _componentList->selectedItems().size() > 0; + _remove_button->setEnabled(isSelected); +} + +void JM::EditSalomeResourceContainer::add_component() +{ + bool ok; + QString text = QInputDialog::getText( + this, + "Add a component", + "Component name:", + QLineEdit::Normal, + "", + &ok + ); + + if (ok && !text.isEmpty()) + { + _componentList->addItem(text); + } +} + +void JM::EditSalomeResourceContainer::remove_components() +{ + QList list = _componentList->selectedItems(); + for (int i = 0; i < list.size(); ++i) + { + int row = _componentList->row(list.at(i)); + delete _componentList->takeItem(row); + } +} + +void JM::EditSalomeResourceContainer::accept() +{ + BL::ResourceDescrContainer resource; + if (!JM::EditSalomeResource::copyValuesToResource(resource)) + { + return; + } + + // Components + int count = _componentList->count(); + for (int i = 0; i < count; i++) + { + resource.componentList.push_back(_componentList->item(i)->text().trimmed().toStdString()); + } + + resource.OS = _os_line->text().trimmed().toStdString(); + resource.mem_mb = _mem_mb_line->value(); + resource.cpu_clock = _cpu_clock_line->value(); + resource.nb_node = _nb_node_line->value(); + resource.nb_proc_per_node = _nb_proc_per_node_line->value(); + + try + { + _salome_services->addResourceContainer(resource); + JM::EditSalomeResource::accept(); + } + catch (const BL::Exception & ex) + { + QMessageBox::critical(this, "Error", QString("Cannot add resource: ") + ex.what()); + } +} diff --git a/src/genericgui/JM_EditSalomeResourceContainer.hxx b/src/genericgui/JM_EditSalomeResourceContainer.hxx new file mode 100644 index 0000000..929655f --- /dev/null +++ b/src/genericgui/JM_EditSalomeResourceContainer.hxx @@ -0,0 +1,72 @@ +// Copyright (C) 2009-2023 CEA, EDF +// +// 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, or (at your option) any later version. +// +// 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_EDITSALOMERESOURCECONTAINER_HXX_ +#define _JM_EDITSALOMERESOURCECONTAINER_HXX_ + +#include "JM_EditSalomeResource.hxx" + +class QLineEdit; +class QListWidget; +class QPushButton; +class QSpinBox; +class QGroupBox; + +namespace JM +{ + class EditSalomeResourceContainer: public EditSalomeResource + { + Q_OBJECT + + public: + EditSalomeResourceContainer( + QWidget* parent, + BL::SALOMEServices* salome_services, + const std::string& resource_name = "" + ); + + virtual ~EditSalomeResourceContainer(); + + public slots: + virtual void accept(); + void add_component(); + void remove_components(); + void itemSelectionChanged(); + + protected: + virtual QGroupBox* initConfigValues() override; + virtual void get_infos() override; + + protected: + // Resource values + QListWidget* _componentList; + QLineEdit* _os_line; + QSpinBox* _mem_mb_line; + QSpinBox* _cpu_clock_line; + QSpinBox* _nb_node_line; + QSpinBox* _nb_proc_per_node_line; + + // Helper elements + QPushButton* _add_button; + QPushButton* _remove_button; + }; +} + +#endif + diff --git a/src/genericgui/JM_EditSalomeResourceJob.cxx b/src/genericgui/JM_EditSalomeResourceJob.cxx new file mode 100644 index 0000000..3194fac --- /dev/null +++ b/src/genericgui/JM_EditSalomeResourceJob.cxx @@ -0,0 +1,151 @@ +// Copyright (C) 2009-2023 CEA, EDF +// +// 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, or (at your option) any later version. +// +// 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 https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "JM_EditSalomeResourceJob.hxx" +#include "utilities.h" + +#include +#include +#include +#include +#include +#include + + +JM::EditSalomeResourceJob::EditSalomeResourceJob( + QWidget* parent, + BL::SALOMEServices* salome_services, + const std::string& resource_name /* = ""*/ + ) : + EditSalomeResource(parent, salome_services, resource_name) +{ + MESSAGE("Creating JM::EditSalomeResourceJob"); +} + +JM::EditSalomeResourceJob::~EditSalomeResourceJob() +{ + MESSAGE("Destroying JM::EditSalomeResourceJob"); +} + +QGroupBox* JM::EditSalomeResourceJob::initConfigValues() +{ + MESSAGE("Init job resource config values..."); + + QLabel* mpiImpl_label = new QLabel("MPI impl:"); + _mpiImpl_line = new QComboBox(this); + _mpiImpl_line->addItem("lam"); + _mpiImpl_line->addItem("mpich1"); + _mpiImpl_line->addItem("mpich2"); + _mpiImpl_line->addItem("openmpi"); + _mpiImpl_line->addItem("slurmmpi"); + _mpiImpl_line->addItem("prun"); + _mpiImpl_line->setCurrentIndex(-1); + + QLabel* iprotocol_label = new QLabel("Internal protocol:"); + _iprotocol_line = new QComboBox(this); + _iprotocol_line->addItem("ssh"); + _iprotocol_line->addItem("rsh"); + _iprotocol_line->addItem("srun"); + _iprotocol_line->addItem("pbsdsh"); + _iprotocol_line->addItem("blaunch"); + _iprotocol_line->setCurrentIndex(0); + + QLabel* working_directory_label = new QLabel("Working Directory:"); + _working_directory = new QLineEdit(this); + + QGridLayout* c_layout = new QGridLayout; + c_layout->addWidget(mpiImpl_label, 0, 0); + c_layout->addWidget(_mpiImpl_line, 0, 1); + c_layout->addWidget(iprotocol_label, 1, 0); + c_layout->addWidget(_iprotocol_line, 1, 1); + c_layout->addWidget(working_directory_label, 2, 0); + c_layout->addWidget(_working_directory, 2, 1); + + QGroupBox* config_groupBox = JM::EditSalomeResource::initConfigValues(); + config_groupBox->setLayout(c_layout); + + return config_groupBox; +} + +void JM::EditSalomeResourceJob::get_infos() +{ + const BL::ResourceDescrJob resource_descr = _salome_services->getResourceDescrJob(_resource_name); + if (!JM::EditSalomeResource::copyValuesFromResource(resource_descr)) + { + return; + } + + const std::string mpiImpl = resource_descr.mpiImpl; + if (mpiImpl == "lam") + _mpiImpl_line->setCurrentIndex(0); + else if (mpiImpl == "mpich1") + _mpiImpl_line->setCurrentIndex(1); + else if (mpiImpl == "mpich2") + _mpiImpl_line->setCurrentIndex(2); + else if (mpiImpl == "openmpi") + _mpiImpl_line->setCurrentIndex(3); + else if (mpiImpl == "slurmmpi") + _mpiImpl_line->setCurrentIndex(4); + else if (mpiImpl == "prun") + _mpiImpl_line->setCurrentIndex(5); + else + _mpiImpl_line->setCurrentIndex(-1); + + const std::string iprotocol = resource_descr.iprotocol; + if (iprotocol == "ssh") + _iprotocol_line->setCurrentIndex(0); + else if (iprotocol == "rsh") + _iprotocol_line->setCurrentIndex(1); + else if (iprotocol == "srun") + _iprotocol_line->setCurrentIndex(2); + else if (iprotocol == "pbsdsh") + _iprotocol_line->setCurrentIndex(3); + else if (iprotocol == "blaunch") + _iprotocol_line->setCurrentIndex(4); + else + _iprotocol_line->setCurrentIndex(-1); + + _working_directory->setText(QString(resource_descr.working_directory.c_str())); + + // Better if string's length is bigger than the widget + _working_directory->setCursorPosition(0); +} + +void JM::EditSalomeResourceJob::accept() +{ + BL::ResourceDescrJob resource; + if (!JM::EditSalomeResource::copyValuesToResource(resource)) + { + return; + } + + resource.mpiImpl = _mpiImpl_line->currentText().toStdString(); + resource.iprotocol = _iprotocol_line->currentText().toStdString(); + resource.working_directory = _working_directory->text().trimmed().toUtf8().constData(); + + try + { + _salome_services->addResourceJob(resource); + JM::EditSalomeResource::accept(); + } + catch (const BL::Exception & ex) + { + QMessageBox::critical(this, "Error", QString("Cannot add resource: ") + ex.what()); + } +} diff --git a/src/genericgui/JM_EditSalomeResourceJob.hxx b/src/genericgui/JM_EditSalomeResourceJob.hxx new file mode 100644 index 0000000..6fa1b86 --- /dev/null +++ b/src/genericgui/JM_EditSalomeResourceJob.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2009-2023 CEA, EDF +// +// 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, or (at your option) any later version. +// +// 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 https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _JM_EDITSALOMERESOURCEJOB_HXX_ +#define _JM_EDITSALOMERESOURCEJOB_HXX_ + +#include "JM_EditSalomeResource.hxx" + +class QComboBox; +class QLineEdit; +class QGroupBox; + +namespace JM +{ + class EditSalomeResourceJob: public EditSalomeResource + { + Q_OBJECT + + public: + EditSalomeResourceJob( + QWidget* parent, + BL::SALOMEServices* salome_services, + const std::string& resource_name = "" + ); + + virtual ~EditSalomeResourceJob(); + + public slots: + virtual void accept(); + + protected: + virtual QGroupBox* initConfigValues() override; + virtual void get_infos() override; + + protected: + QComboBox* _mpiImpl_line; + QComboBox* _iprotocol_line; + QLineEdit* _working_directory; + }; +} + +#endif + diff --git a/src/genericgui/JM_ResourceCatalog.cxx b/src/genericgui/JM_ResourceCatalog.cxx index df11a37..d577c41 100644 --- a/src/genericgui/JM_ResourceCatalog.cxx +++ b/src/genericgui/JM_ResourceCatalog.cxx @@ -19,35 +19,45 @@ #include "JM_ResourceCatalog.hxx" #include "BL_Traces.hxx" -#include "JM_SalomeResource.hxx" -#include "JM_EditSalomeResource.hxx" +#include "JM_EditSalomeResourceJob.hxx" +#include "JM_EditSalomeResourceContainer.hxx" +#include "utilities.h" #include #include #include #include -JM::ResourceCatalog::ResourceCatalog(QWidget *parent, BL::SALOMEServices * salome_services, bool batch_only) -: QWidget(parent), +JM::ResourceCatalog::ResourceCatalog(QWidget* parent, BL::SALOMEServices* salome_services, bool batch_only) : + QWidget(parent), + _parent(parent), + _salome_services(salome_services), _batch_only(batch_only) { - DEBTRACE("Creating JM::ResourceCatalog"); + MESSAGE("Creating JM::ResourceCatalog"); + BL_ASSERT(parent); BL_ASSERT(salome_services); - _parent = parent; - _salome_services = salome_services; + init_layout(); +} + +JM::ResourceCatalog::~ResourceCatalog() +{ + MESSAGE("Destroying JM::ResourceCatalog"); +} + +QListWidget* JM::ResourceCatalog::getQListWidget() +{ + return _resource_files_list; +} + +void JM::ResourceCatalog::init_layout() +{ _refresh_button = new QPushButton("Refresh Resource List"); _refresh_button->show(); - _resource_files_list = new QListWidget(this); - _resource_files_list->setSelectionMode(QAbstractItemView::SingleSelection); - std::list resource_list = _salome_services->getResourceList(_batch_only); - std::list::iterator it; - for (it = resource_list.begin(); it != resource_list.end(); it++) - { - std::string resource = *it; - _resource_files_list->addItem(QString(resource.c_str())); - } + + create_resource_list(); _show_button = new QPushButton("Show"); _show_button->setEnabled(false); @@ -71,108 +81,111 @@ JM::ResourceCatalog::ResourceCatalog(QWidget *parent, BL::SALOMEServices * salom mainLayout->addWidget(layout_widget); setLayout(mainLayout); + connect_slots(); +} + +void JM::ResourceCatalog::create_resource_list() +{ + _resource_files_list = new QListWidget(this); + _resource_files_list->setSelectionMode(QAbstractItemView::SingleSelection); + + refresh_resource_list(); +} + +void JM::ResourceCatalog::connect_slots() +{ // Buttons connect(_refresh_button, SIGNAL(clicked()), this, SLOT(refresh_resource_list())); connect(_show_button, SIGNAL(clicked()), this, SLOT(show_button())); connect(_edit_button, SIGNAL(clicked()), this, SLOT(edit_button())); connect(_add_button, SIGNAL(clicked()), this, SLOT(add_button())); connect(_remove_button, SIGNAL(clicked()), this, SLOT(remove_button())); - // Double click on an item + + // Resource list connect(_resource_files_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(item_choosed(QListWidgetItem*))); - // Selection management connect(_resource_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(buttons_management())); } -JM::ResourceCatalog::~ResourceCatalog() +void JM::ResourceCatalog::refresh_resource_list() { - DEBTRACE("Destroying JM::ResourceCatalog"); -} + _resource_files_list->clear(); -QListWidget * -JM::ResourceCatalog::getQListWidget() -{ - return _resource_files_list; -} + const BL::ResourceList resource_list = _salome_services->getResourceList(_batch_only); -void -JM::ResourceCatalog::refresh_resource_list() -{ - _resource_files_list->clear(); - std::list resource_list = _salome_services->getResourceList(_batch_only); - std::list::iterator it; - for (it = resource_list.begin(); it != resource_list.end(); it++) + for (const auto& resource : resource_list) { - std::string resource = *it; _resource_files_list->addItem(QString(resource.c_str())); } } -void -JM::ResourceCatalog::item_choosed(QListWidgetItem * item) +void JM::ResourceCatalog::item_choosed(QListWidgetItem* item) { - DEBTRACE("JM::ResourceCatalog::item_choosed"); - JM::SalomeResource * resource_widget = new JM::SalomeResource(this, - _salome_services, - item->text().toUtf8().constData()); - resource_widget->exec(); - delete resource_widget; + MESSAGE("JM::ResourceCatalog::item_choosed"); + + openAddEditDialog(item->text().toUtf8().constData(), false); } -void -JM::ResourceCatalog::buttons_management() +void JM::ResourceCatalog::buttons_management() { - QList item_list = _resource_files_list->selectedItems(); - - // Test if an item is selected - if (item_list.size() == 0) - { - _show_button->setEnabled(false); - _edit_button->setEnabled(false); - _remove_button->setEnabled(false); - } - else - { - _show_button->setEnabled(true); - _edit_button->setEnabled(true); - _remove_button->setEnabled(true); - } + const QList item_list = _resource_files_list->selectedItems(); + + const bool hasSelected = item_list.size() > 0; + + _show_button->setEnabled(hasSelected); + _edit_button->setEnabled(hasSelected); + _remove_button->setEnabled(hasSelected); } -void -JM::ResourceCatalog::show_button() +void JM::ResourceCatalog::show_button() { - QList item_list = _resource_files_list->selectedItems(); + const QList item_list = _resource_files_list->selectedItems(); item_choosed(item_list.at(0)); } -void -JM::ResourceCatalog::add_button() +void JM::ResourceCatalog::add_button() { - JM::EditSalomeResource * resource_widget = new JM::EditSalomeResource(this, - _salome_services); - resource_widget->exec(); - delete resource_widget; + openAddEditDialog(); refresh_resource_list(); } -void -JM::ResourceCatalog::remove_button() +void JM::ResourceCatalog::remove_button() { - QList item_list = _resource_files_list->selectedItems(); + QList item_list = _resource_files_list->selectedItems(); QString item_name = item_list.at(0)->text(); - _salome_services->removeResource(item_name.toUtf8().constData()); + const std::string res_name = item_name.toUtf8().constData(); + + if (_batch_only) + { + _salome_services->removeResourceJob(res_name); + } + else + { + _salome_services->removeResourceContainer(res_name); + } + refresh_resource_list(); } -void -JM::ResourceCatalog::edit_button() +void JM::ResourceCatalog::edit_button() { - QList item_list = _resource_files_list->selectedItems(); + QList item_list = _resource_files_list->selectedItems(); QString item_name = item_list.at(0)->text(); - JM::EditSalomeResource * resource_widget = new JM::EditSalomeResource(this, - _salome_services, - item_name.toUtf8().constData()); + const std::string res_name = item_name.toUtf8().constData(); + + openAddEditDialog(res_name); + + refresh_resource_list(); +} + +void JM::ResourceCatalog::openAddEditDialog(const std::string& res_name/* = ""*/, bool isEditable/* = true*/) +{ + JM::EditSalomeResource* resource_widget = _batch_only ? + static_cast(new JM::EditSalomeResourceJob(this, _salome_services, res_name)) : + static_cast(new JM::EditSalomeResourceContainer(this, _salome_services, res_name)); + + resource_widget->init(_batch_only ? "job resource" : "container resource"); + resource_widget->setEnabled(isEditable); resource_widget->exec(); + delete resource_widget; - refresh_resource_list(); } diff --git a/src/genericgui/JM_ResourceCatalog.hxx b/src/genericgui/JM_ResourceCatalog.hxx index 8e3a210..6d6a8ef 100644 --- a/src/genericgui/JM_ResourceCatalog.hxx +++ b/src/genericgui/JM_ResourceCatalog.hxx @@ -23,8 +23,6 @@ #include "BL_SALOMEServices.hxx" #include -#include -#include class QListWidget; class QListWidgetItem; @@ -37,16 +35,16 @@ namespace JM Q_OBJECT public: - ResourceCatalog(QWidget *parent, BL::SALOMEServices * salome_services, bool batch_only); + ResourceCatalog(QWidget* parent, BL::SALOMEServices* salome_services, bool batch_only); virtual ~ResourceCatalog(); void get_infos(); - QListWidget * getQListWidget(); + QListWidget* getQListWidget(); public slots: void refresh_resource_list(); - void item_choosed(QListWidgetItem * item); + void item_choosed(QListWidgetItem* item); void buttons_management(); void show_button(); void edit_button(); @@ -54,15 +52,21 @@ namespace JM void remove_button(); protected: - QWidget* _parent; - BL::SALOMEServices * _salome_services; + void init_layout(); + void create_resource_list(); + void connect_slots(); + void openAddEditDialog(const std::string& res_name = "", bool isEditable = true); - QPushButton * _refresh_button; - QPushButton * _show_button; - QPushButton * _edit_button; - QPushButton * _add_button; - QPushButton * _remove_button; - QListWidget * _resource_files_list; + protected: + QWidget* _parent = nullptr; + BL::SALOMEServices* _salome_services = nullptr; + + QPushButton* _refresh_button = nullptr; + QPushButton* _show_button = nullptr; + QPushButton* _edit_button = nullptr; + QPushButton* _add_button = nullptr; + QPushButton* _remove_button = nullptr; + QListWidget* _resource_files_list = nullptr; bool _batch_only; }; } diff --git a/src/genericgui/JM_SalomeResource.cxx b/src/genericgui/JM_SalomeResource.cxx deleted file mode 100644 index 6fa107e..0000000 --- a/src/genericgui/JM_SalomeResource.cxx +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (C) 2009-2023 CEA, EDF -// -// 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, or (at your option) any later version. -// -// 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" - -#include -#include -#include -#include -#include -#include -#include - -JM::SalomeResource::SalomeResource(QWidget *parent, BL::SALOMEServices * salome_services, - const std::string & resource_name) -: QDialog(parent, Qt::Window) -{ - DEBTRACE("Creating JM::SalomeResource"); - BL_ASSERT(parent); - BL_ASSERT(salome_services); - _parent = parent; - _salome_services = salome_services; - _resource_name = resource_name; - - // 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); - QLabel * working_directory_label = new QLabel("Working Directory:"); - _working_directory = new QLineEdit(this); - _can_launch_batch_jobs = new QCheckBox("This resource can be used to launch batch jobs", this); - _can_run_containers = new QCheckBox("This resource can be used to run interactive containers", this); - 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); - m_layout->addWidget(working_directory_label, 6, 0); - m_layout->addWidget(_working_directory, 6, 1); - m_layout->addWidget(_can_launch_batch_jobs, 7, 1); - m_layout->addWidget(_can_run_containers, 8, 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); - - 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); - _working_directory->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); - _working_directory->setReadOnly(true); - _can_launch_batch_jobs->setEnabled(false); - _can_run_containers->setEnabled(false); -} - -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())); - _working_directory->setText(QString(resource_descr.working_directory.c_str())); - - if (resource_descr.can_launch_batch_jobs) - _can_launch_batch_jobs->setCheckState(Qt::Checked); - else - _can_launch_batch_jobs->setCheckState(Qt::Unchecked); - - if (resource_descr.can_run_containers) - _can_run_containers->setCheckState(Qt::Checked); - else - _can_run_containers->setCheckState(Qt::Unchecked); - - 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 deleted file mode 100644 index cb1780b..0000000 --- a/src/genericgui/JM_SalomeResource.hxx +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2009-2023 CEA, EDF -// -// 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, or (at your option) any later version. -// -// 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 "BL_SALOMEServices.hxx" - -#include -#include - -class QCheckBox; -class QLineEdit; -class QListWidget; - -namespace JM -{ - class SalomeResource: public QDialog - { - Q_OBJECT - - public: - SalomeResource(QWidget *parent, BL::SALOMEServices * salome_services, - const std::string & resource_name); - virtual ~SalomeResource(); - - void get_infos(); - - protected: - QWidget* _parent; - BL::SALOMEServices * _salome_services; - std::string _resource_name; - - // widget - QLineEdit * _name_line; - QLineEdit * _hostname_line; - QLineEdit * _protocol_line; - QLineEdit * _username_line; - QLineEdit * _applipath_line; - QListWidget * _componentList; - QCheckBox * _can_launch_batch_jobs; - QCheckBox * _can_run_containers; - QLineEdit * _working_directory; - 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 -