Exemplo n.º 1
0
// Doxygen skip:
/// @cond
void QueueManager::handleSubmittedStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_submittedTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_submittedTracker);

  if (s->getStatus() != Structure::Submitted) {
    return;
  }

  switch (m_opt->queueInterface(s->getCurrentOptStep())->getStatus(s)) {
    case QueueInterface::Running:
    case QueueInterface::Queued:
    case QueueInterface::Success:
    case QueueInterface::Started:
      // Update the structure as "InProcess"
      s->lock().lockForWrite();
      s->setStatus(Structure::InProcess);
      s->lock().unlock();
      emit structureUpdated(s);
      break;
    case QueueInterface::Error:
      s->lock().lockForWrite();
      s->setStatus(Structure::Restart);
      s->lock().unlock();
      emit structureUpdated(s);
      break;
    case QueueInterface::CommunicationError:
    case QueueInterface::Unknown:
    case QueueInterface::Pending:
    default:
      // nothing to do but wait
      break;
  }
}
Exemplo n.º 2
0
void DbStructureModel::reloadData()
{
    beginResetModel();

    // Remove all data except for the root item
    while(rootItem->childCount())
        delete rootItem->child(0);

    // Return here if no DB is opened
    if(!m_db.isOpen())
    {
        endResetModel();
        emit structureUpdated();
        return;
    }

    // Create the nodes for browsables and for tables, indices, views and triggers. The idea here is to basically have two trees in one model:
    // In the root node there are two nodes: 'browsables' and 'all'. The first node contains a list of all browsable objects, i.e. views and tables.
    // The second node contains four sub-nodes (tables, indices, views and triggers), each containing a list of objects of that type.
    // This way we only have to have and only have to update one model and can use it in all sorts of places, just by setting a different root node.
    browsablesRootItem = new QTreeWidgetItem(rootItem);
    browsablesRootItem->setIcon(ColumnName, QIcon(QString(":/icons/view")));
    browsablesRootItem->setText(ColumnName, tr("Browsables"));

    // Make sure to always load the main schema first
    QTreeWidgetItem* itemAll = new QTreeWidgetItem(rootItem);
    itemAll->setIcon(ColumnName, QIcon(QString(":/icons/database")));
    itemAll->setText(ColumnName, tr("All"));
    itemAll->setText(ColumnObjectType, "database");
    buildTree(itemAll, "main");

    // Add the temporary database as a node if it isn't empty. Make sure it's always second if it exists.
    if(!m_db.schemata["temp"].isEmpty())
    {
        QTreeWidgetItem* itemTemp = new QTreeWidgetItem(itemAll);
        itemTemp->setIcon(ColumnName, QIcon(QString(":/icons/database")));
        itemTemp->setText(ColumnName, tr("Temporary"));
        itemTemp->setText(ColumnObjectType, "database");
        buildTree(itemTemp, "temp");
    }

    // Now load all the other schemata last
    for(auto it=m_db.schemata.constBegin();it!=m_db.schemata.constEnd();++it)
    {
        // Don't load the main and temp schema again
        if(it.key() != "main" && it.key() != "temp")
        {
            QTreeWidgetItem* itemSchema = new QTreeWidgetItem(itemAll);
            itemSchema->setIcon(ColumnName, QIcon(QString(":/icons/database")));
            itemSchema->setText(ColumnName, it.key());
            itemSchema->setText(ColumnObjectType, "database");
            buildTree(itemSchema, it.key());
        }
    }

    // Refresh the view
    endResetModel();
    emit structureUpdated();
}
Exemplo n.º 3
0
// Doxygen skip:
/// @cond
void QueueManager::addStructureToSubmissionQueue_(Structure* s, int optStep)
{
  Q_ASSERT(trackerContainsStructure(s, &m_newSubmissionTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_newSubmissionTracker);

  // Update structure
  s->lock().lockForWrite();
  if (s->getStatus() != Structure::Optimized) {
    s->setStatus(Structure::WaitingForOptimization);
    if (optStep != -1) {
      s->setCurrentOptStep(optStep);
    }
  }
  s->lock().unlock();

  // Perform writing
  m_opt->queueInterface(s->getCurrentOptStep())->writeInputFiles(s);

  m_jobStartTracker.lockForWrite();
  m_jobStartTracker.append(s);
  m_jobStartTracker.unlock();

  m_runningTracker.lockForWrite();
  m_runningTracker.append(s);
  m_runningTracker.unlock();

  emit structureUpdated(s);
}
Exemplo n.º 4
0
// Doxygen skip:
/// @cond
void QueueManager::handleInProcessStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_inProcessTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_inProcessTracker);

  // Revalidate assumptions
  if (s->getStatus() != Structure::InProcess) {
    return;
  }

  QueueInterface* qi = m_opt->queueInterface(s->getCurrentOptStep());
  switch (qi->getStatus(s)) {
    case QueueInterface::Running:
    case QueueInterface::Queued:
    case QueueInterface::CommunicationError:
    case QueueInterface::Unknown:
    case QueueInterface::Pending:
    case QueueInterface::Started:
    {
      // Kill the structure if it has exceeded the allowable time.
      // Only perform this for remote queues.
      if (m_opt->cancelJobAfterTime() &&
          s->getOptElapsedHours() > m_opt->hoursForCancelJobAfterTime() &&
          qi->getIDString().toLower() != "local") {
        killStructure(s);
        emit structureUpdated(s);
        return;
      }
      // Nothing to do but wait
      break;
    }
    case QueueInterface::Success:
      updateStructure(s);
      break;
    case QueueInterface::Error:
      s->lock().lockForWrite();
      s->setStatus(Structure::Error);
      s->lock().unlock();
      emit structureUpdated(s);
      break;
  }

  return;
}
Exemplo n.º 5
0
void QueueManager::updateStructure(Structure* s)
{
  s->lock().lockForWrite();
  s->stopOptTimer();
  s->resetFailCount();
  s->setStatus(Structure::Updating);
  s->lock().unlock();
  if (!m_opt->optimizer(s->getCurrentOptStep())->update(s)) {
    s->lock().lockForWrite();
    s->setStatus(Structure::Error);
    s->lock().unlock();
    emit structureUpdated(s);
    return;
  }
  s->lock().lockForWrite();
  s->setStatus(Structure::StepOptimized);
  s->lock().unlock();
  emit structureUpdated(s);
  return;
}
Exemplo n.º 6
0
// Doxygen skip:
/// @cond
void QueueManager::handleErrorStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_errorTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_errorTracker);

  if (s->getStatus() != Structure::Error) {
    return;
  }

  if (!m_opt->usingGUI()) {
    qDebug() << "Structure"
             << QString::number(s->getGeneration()) + "x" +
                  QString::number(s->getIDNumber())
             << "failed";
  }

  stopJob(s);

  // Lock for writing
  QWriteLocker locker(&s->lock());

  s->addFailure();

  // If the number of failures has exceed the limit, take
  // appropriate action
  if (s->getFailCount() >= m_opt->failLimit) {
    switch (OptBase::FailActions(m_opt->failAction)) {
      case OptBase::FA_DoNothing:
      default:
        // resubmit job
        s->setStatus(Structure::Restart);
        emit structureUpdated(s);
        return;
      case OptBase::FA_KillIt:
        locker.unlock();
        killStructure(s);
        emit structureUpdated(s);
        return;
      case OptBase::FA_Randomize:
        s->setStatus(Structure::Empty);
        locker.unlock();
        m_opt->replaceWithRandom(s, tr("excessive failures"));
        s->setStatus(Structure::Restart);
        emit structureUpdated(s);
        return;
      case OptBase::FA_NewOffspring:
        s->setStatus(Structure::Empty);
        locker.unlock();
        m_opt->replaceWithOffspring(s, tr("excessive failures"));
        s->setStatus(Structure::Restart);
        emit structureUpdated(s);
        return;
    }
  }
  // Resubmit job if failure limit hasn't been reached
  else {
    s->setStatus(Structure::Restart);
    emit structureUpdated(s);
    return;
  }
}
Exemplo n.º 7
0
// Doxygen skip:
/// @cond
void QueueManager::handleStepOptimizedStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_stepOptimizedTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_stepOptimizedTracker);

  QWriteLocker locker(&s->lock());

  // Validate assumptions
  if (s->getStatus() != Structure::StepOptimized) {
    return;
  }

  s->stopOptTimer();

  QString err;
  if (!m_opt->checkStepOptimizedStructure(s, &err)) {
    // Structure failed a post optimization step:
    m_opt->warning(QString("Structure %1 failed a post-optimization step: %2")
                     .arg(s->getIDString())
                     .arg(err));
    s->setStatus(Structure::Killed);
    locker.unlock();
    emit structureUpdated(s);
    return;
  }

  // update optstep and relaunch if necessary
  if (s->getCurrentOptStep() + 1 <
      static_cast<unsigned int>(m_opt->getNumOptSteps())) {

    // Print an update to the terminal if we are not using the GUI
    if (!m_opt->usingGUI()) {
      qDebug() << "Structure"
               << QString::number(s->getGeneration()) + "x" +
                    QString::number(s->getIDNumber())
               << "completed step" << s->getCurrentOptStep();
    }

    s->setCurrentOptStep(s->getCurrentOptStep() + 1);

    // Update status
    s->setStatus(Structure::WaitingForOptimization);
    m_runningTracker.lockForWrite();
    m_runningTracker.append(s);
    m_runningTracker.unlock();
    locker.unlock();
    emit structureUpdated(s);
    addStructureToSubmissionQueue(s);
    return;
  }
  // Otherwise, it's done
  else {
    // Print an update to the terminal if we are not using the GUI
    if (!m_opt->usingGUI()) {
      qDebug() << "Structure"
               << QString::number(s->getGeneration()) + "x" +
                    QString::number(s->getIDNumber())
               << "is optimized!";
    }

    s->setStatus(Structure::Optimized);
    locker.unlock();
    handleOptimizedStructure(s);
  }
}