Example #1
0
// At this point we may or may not have a valid working directory in that the
// selected directory may exist and we haven't confirmed if the user wants to
// overwrite it. 
void ProcessMonitor::submitJob2()
{
   if (!m_pendingProcess) {
      qDebug() << "ProcessMonitor::submitJob2() called with no pending process";
      return;
   }

   ServerTask::Base* task = qobject_cast<ServerTask::Base*>(sender());
   if (!task) {
      delete m_pendingProcess;
      m_pendingProcess = 0;
      return;
   }

   QString errorMessage(task->errorMessage());
   task->deleteLater();

   Server* server = ServerRegistry::instance().get(m_pendingProcess->serverName());

   if (errorMessage.contains("Working directory exists")) {
      if (QMsgBox::question(0, "IQmol", "Directory exists, overwrite?") == QMessageBox::Ok) {
         m_pendingProcess->jobInfo()->promptOnOverwrite(false);
      }else if (!server->getWorkingDirectoryFromUser(m_pendingProcess)) {
         delete m_pendingProcess;
         m_pendingProcess = 0;
         return;
      }
 
      task = server->setup(m_pendingProcess);
      connect(task, SIGNAL(finished()), this, SLOT(submitJob2()));
      task->start();
      return;
   }

   if (!errorMessage.isEmpty()) {
      QString msg("Problem setting up Job:\n");
      msg += errorMessage;
      QMsgBox::warning(this, "IQmol", msg);
      delete m_pendingProcess;
      m_pendingProcess = 0;
      return;
   }

   // We now have a valid working directory
   postStatusMessage("Configuring options...");
   if (server->configureJob(m_pendingProcess)) {
      postStatusMessage("Submitting job...");
      task = server->submit(m_pendingProcess);
      connect(task, SIGNAL(finished()), this, SLOT(jobSubmitted()));
      task->start();
   }else {
      delete m_pendingProcess;
      m_pendingProcess = 0;
      return;
   }
}
Example #2
0
void ProcessMonitor::killProcess()
{     
   Process* process(getSelectedProcess());
   if (!process) return;
  
   Process::Status status(process->status());

   QString msg;
   if (status == Process::Queued) {
      msg = "Are you sure you want to remove the job ";
      msg += process->name() + " from the queue?";
   }else {
      msg = "Are you sure you want to terminate the job ";
      msg += process->name() + "?";
   }     

   if (QMsgBox::question(this, "IQmol", msg) == QMessageBox::Cancel) return;
    
   Server* server = ServerRegistry::instance().get(process->serverName());
   ServerTask::Base* task = server->kill(process);
   if (task) {
      connect(task, SIGNAL(finished()), this, SLOT(processKilled()));
      task->start();
   }
}
Example #3
0
void ProcessMonitor::queryProcess(Process* process)
{
   QString msg;

   switch (process->status()) {
      case Process::NotRunning:
         msg = "Process not yet started";
         break;

      case Process::Queued:
      case Process::Running:
      case Process::Suspended: {
         Server* server = ServerRegistry::instance().get(process->serverName());
         if (server) {
            ServerTask::Base* task = server->query(process);
            if (task) {
               connect(task, SIGNAL(finished()), this, SLOT(queryFinished()));
               task->start();
            }
            return;
         }else {
            msg = "Server not found";
         }
      } break;
   
      case Process::Copying:
         msg = "Copying files from server";
         break;

      case Process::Killed:
         msg = "Process killed. R.I.P.";
         break;

      case Process::Error:
         msg = "Job failed:\n" + process->comment();
         break;

      case Process::Finished:
         if (process->jobInfo()->localFilesExist()) {
            msg = "Job finished.  Results are in\n";
            msg += process->jobInfo()->get(JobInfo::LocalWorkingDirectory);
         }else {
            msg = "Job finished.  Results not yet copied from server";
         }
         break;

      case Process::Unknown:
         msg = "Status unknown, possibly due to a timeout on the server";
         break;
   }

   QMsgBox::information(this, "IQmol", msg);
}
Example #4
0
void ProcessMonitor::submitJob(IQmol::JobInfo* jobInfo)
{  
   if (m_pendingProcess) {
      QString msg("Job submission pending, cannot submit additional jobs");
      QMsgBox::warning(this, "IQmol", msg);
      return;
   }

   // Because we need to thread the network stuff, we break the job submission
   // process up into several bits (ServerTasks) and connect these via signals
   // and slots. First we need to make sure the server is connected and tested. 
   // Note that because the connection process is potentially interactive, we
   // don't bother threading it.
   QString serverName(jobInfo->get(JobInfo::ServerName));
   Server* server = ServerRegistry::instance().get(serverName);

   if (!server) {
      QMsgBox::warning(this, "IQmol", "Invalid server");
      return;
   }

   if (!server->isConnected()) {
      postStatusMessage("Connecting to server...");
      try {
         QLOG_DEBUG() << "Attempting to connect to server " << server->name();
         if (!server->connectServer()) throw Server::Exception("Connection failed");
         QLOG_DEBUG() << "Connection established: " << server->isConnected();
         postStatusMessage("Testing configuration...");
      } catch (std::exception& err) {
         QString msg("Failed to connect to server ");
         msg += serverName + ":\n";
         msg += err.what();
         QMsgBox::warning(this, "IQmol", msg);
         return;
      }
   }

   // This is a bit untidy, but we need to tell the next slot in the submission
   // thread chain what job we are dealing with.
   m_pendingProcess = new Process(jobInfo);
   ServerTask::Base* task = server->testConfiguration();
   if (task) {
      connect(task, SIGNAL(finished()), this, SLOT(submitJob1()));
      task->start();
   }
}
Example #5
0
void ProcessMonitor::copyResults(Process* process)
{        
   if (process->jobInfo()->localFilesExist()) {
      QString msg("Results are in the directory:\n");
      msg += process->jobInfo()->get(JobInfo::LocalWorkingDirectory);
      QMsgBox::information(this, "IQmol", msg);
   }else if (process->status() == Process::Copying) {
      QString msg("Results are already being transfered.\nBe patient...");
      QMsgBox::information(this, "IQmol", msg);
   }else {
      if (process->getLocalSaveDirectory()) {
         Server* server = ServerRegistry::instance().get(process->serverName());
         ServerTask::Base* task = server->copyResults(process);
         if (task) {
            connect(task, SIGNAL(finished()), this, SLOT(resultsCopied()));
            task->start();
         }
      }
   }
} 
Example #6
0
void BasicServer::runQueue()
{  
   if (!isConnected()) {
      QLOG_DEBUG() << "BasicServer::runQueue server not connected";
      return;
   }
   int running(m_server->watchedWithStatus(Process::Running));

   qDebug() << "runQueue() jobLimit:" << m_jobLimit;
   qDebug() << "runQueue() queued:  " << m_queue.size();
   qDebug() << "runQueue() running: " << running;

   while (!m_queue.isEmpty() && running < m_jobLimit) {
      Process* process(m_queue.dequeue());
      ServerTask::Base* task = submitToHost(process);
      if (task) {
         connect(task, SIGNAL(finished()), this, SLOT(submitFinished()));
         task->start();
         ++running;
      }
   }
}
Example #7
0
// At this point the server is connected and tested, but we still need to check
// if the test was successful.  If it is, then we can go ahead with the setup
// which starts with obtaining the working directory.
void ProcessMonitor::submitJob1()
{
   if (!m_pendingProcess) {
      qDebug() << "ProcessMonitor::submitJob1() called with no pending process";
      return;
   }

   ServerTask::Base* task = qobject_cast<ServerTask::Base*>(sender());
   if (!task) {
      delete m_pendingProcess;
      m_pendingProcess = 0;
      return;
   }

   QString errorMessage(task->errorMessage());
   task->deleteLater();

   if (!errorMessage.isEmpty()) {
      QString msg("Problem submitting job:\n");
      msg += errorMessage;
      QMsgBox::warning(this, "IQmol", msg);
      delete m_pendingProcess;
      m_pendingProcess = 0;
      return;
   }

   postStatusMessage("Determining working directory...");
   Server* server = ServerRegistry::instance().get(m_pendingProcess->serverName());
   if (server->getWorkingDirectoryFromUser(m_pendingProcess)) {
      task = server->setup(m_pendingProcess);
      connect(task, SIGNAL(finished()), this, SLOT(submitJob2()));
      task->start();
   }else {
      delete m_pendingProcess;
      m_pendingProcess = 0;
   }
}