Beispiel #1
0
void  KKJobManager::ProcessRestart ()
{
  log.Level (10) << "ProcessRestart" << endl;

  Block ();

  StatusFileLoad ();

  if  (this->Status () != jsDone)
  {
    ofstream* statusFile = StatusFileOpen (ios::app);

    status = KKJob::jsOpen;
    *statusFile << "ReStart" << endl;
    *statusFile << "Status"  << "\t" << StatusStr () << endl;

    KKJobList::iterator  idx;
    for  (idx = jobs->begin ();  idx != jobs->end ();   idx++)
    {
      KKJobPtr  j = *idx;
      if  (j->Status () == jsStarted)
      {
        j->Status (jsOpen);
        *statusFile << "JobStatusChange" << "\t" << j->JobId () << "\t" << j->StatusStr () << endl;
      }
    }

    statusFile->flush ();
    statusFile->close ();
    delete  statusFile;
  }
 
  EndBlock ();
}  /* ProcessRestart */
Beispiel #2
0
void   KKJobManager::ProcessNextExpansion (ostream&  o)
{
  KKJobListPtr jobsJustCompleted = new KKJobList (this);
  jobsJustCompleted->Owner (false);
  {
    // Add jobs completed since last expansion to this list.
    KKJobList::iterator  idx;
    for  (idx = jobs->begin ();  idx != jobs->end ();  idx++)
    {
      KKJobPtr  j = *idx;
      if  (j->JobId () >= expansionFirstJobId)
        jobsJustCompleted->PushOnBack (j);
    }
  }

  // Derived class will now peform expansion.  
  KKJobListPtr  expandedJobs = JobsExpandNextSetOfJobs (jobsJustCompleted);
  {
    if  (expandedJobs)
    {
      expandedJobs->Owner (false);
      KKJobList::iterator  idx;
      for  (idx = expandedJobs->begin ();  idx != expandedJobs->end ();  idx++)
      {
        KKJobPtr  j = *idx;
        if  (j->JobId () < expansionFirstJobId)
          expansionFirstJobId = j->JobId ();

        jobs->PushOnBack (j);
        o << "KKJob" << "\t" << j->JobType () << "\t" << j->ToStatusStr () << endl;
      }
    }
    delete  expandedJobs;
    expandedJobs = NULL;
  }

  delete  jobsJustCompleted;
  jobsJustCompleted = NULL;

  o << "NextJobId"            << "\t" << nextJobId            << endl
    << "ExpansionCount"       << "\t" << expansionCount       << endl
    << "ExpansionFirstJobId"  << "\t" << expansionFirstJobId  << endl;

}  /* ProcessNextExpansion */
Beispiel #3
0
void   KKJobList::PushOnBack (KKJobPtr  j)
{
  jobIdLookUpTableIdx = jobIdLookUpTable.find (j->JobId ());
  if  (jobIdLookUpTableIdx != jobIdLookUpTable.end ())
  {
    log.Level (-1) << endl
                   << endl
                   << "KKJobList::PushOnBack      ***ERROR***" << endl 
                   << endl 
                   << "KKJobList::PushOnBack        Duplicate JobId[" << j->JobId () << "]" << endl
                   << endl;
    osWaitForEnter ();
    exit (-1);
  }

  KKQueue<KKJob>::PushOnBack (j);
  jobIdLookUpTable.insert (JobIdLookUpTablePair (j->JobId (), j));

  return;
}  /* PushOnBack */
Beispiel #4
0
KKJobListPtr  KKJobManager::GetNextSetOfJobs (KKJobListPtr  completedJobs)
{
  log.Level (20) << "KKJobManager::GetNextSetOfJobs." << endl;

  Block  ();

  StatusFileRefresh ();
 
  if  (completedJobs)
  {
    // We will first write out results of jobs that have been completed,
    ofstream* statusFile = StatusFileOpen (ios::app);

    KKJobList::iterator  idx;
    for  (idx = completedJobs->begin ();  idx != completedJobs->end ();  idx++)
    {
      KKJobPtr  j = *idx;

      *statusFile << "KKJob" << "\t" << j->JobType () << "\t" << j->ToStatusStr () << endl;
      if  (supportCompletedJobData)
      {
        *statusFile << "<KKJob JobType=" << j->JobType () << ", " << "JobId=" << j->JobId () << ">" << endl;
        j->CompletedJobDataWrite (*statusFile);
        *statusFile << "</job>" << endl;
      }

      KKJobPtr  existingJob = jobs->LookUpByJobId (j->JobId ());
      if  (existingJob)
      {
        existingJob->ReFresh (*j);
      }
      else
      {
        log.Level (-1) << endl << endl << endl
                       << "GetNextSetOfJobs     *** ERROR ***"  << endl
                       << endl
                       << "           Could not locate KKJob[" << j->JobId () << "]" << endl
                       << endl;
        return  NULL;
      }
    }

    statusFile->close ();
    delete  statusFile;  statusFile = NULL;
  }


  KKJobListPtr  jobsToExecute = new KKJobList (this);
  jobsToExecute->Owner (false);

  if  (!quitRunning)
  {
    ofstream* statusFile = StatusFileOpen (ios::app);

    KKJobPtr  nextJob = jobs->LocateOpenJob ();

    if  (!nextJob)
    {
      if  (jobs->AreAllJobsDone ())
      {
        // There are no jobs to do;  we will have to expand some existing jobs then
        ProcessNextExpansion (*statusFile);
        nextJob = jobs->LocateOpenJob ();
      }
      else
      {
        // There are still some jobs that are running.   We are going to go to
        // for now and try again later.
        //  
        // By leaving  "nextJob = NULL" we will drop strait through the rest of
        // this method and return to the caller with 'jobsToExecute' empty
        // signaling that it will need to sleep for a while before calling 
        // us again.
      }
    }

    while  (nextJob  &&  (jobsToExecute->QueueSize () < numJobsAtATime))
    {
      jobsToExecute->PushOnBack (nextJob);
      nextJob->Status (jsStarted);
      *statusFile << "JobStatusChange" << "\t" << nextJob->JobId () << "\t" << nextJob->StatusStr () << endl;
      nextJob = jobs->LocateOpenJob ();
    }

    statusFile->close ();
  }

  if  (jobsToExecute->QueueSize () < 1)
  {
    delete  jobsToExecute;
    jobsToExecute = NULL;
  }

  EndBlock ();

  log.Level (20) << "KKJobManager::GetNextSetOfJobs   Exiting." << endl;

  return  jobsToExecute;
}  /* GetNextSetOfJobs */
Beispiel #5
0
void  KKJobManager::StatusFileProcessLine (const KKStr&  ln,
                                           istream&      statusFile
                                          )
{
  if  (ln.SubStrPart (0, 1) == "//")
  {
    // A coment line;  we can ignore it.
    return;
  }

  KKStr  statusStr (ln);
  KKStr  fieldName = statusStr.ExtractToken2 ("\t");
  if  (fieldName.Empty ())
  {
    // A empty line we will ignore it.
    return;
  }

  statusStr.TrimLeft ("\n\r\t ");
  statusStr.TrimRight ("\n\r\t ");

  if  (fieldName.CompareIgnoreCase ("JOB") == 0)
  {
    // We have a KKJob entr line;  the next field determines JobType fllowed by parameters for that JobType constructor.
    KKStr  jobTypeName = fieldName = statusStr.ExtractToken2 ("\t");

    KKJobPtr  j = KKJob::CallAppropriateConstructor (this, jobTypeName, statusStr);
    KKJobPtr  existingJob = jobs->LookUpByJobId (j->JobId ());
    if  (existingJob)
    {
      existingJob->ReFresh (*j);
      delete  j;  j = NULL;
    }
    else
    {
      jobs->PushOnBack (j);
    }
  }

  else if  (fieldName.EqualIgnoreCase ("CPUTIMEUSED"))
  {
    double  cpuTimeUsed = statusStr.ExtractTokenDouble ("\t");
    cpuTimeTotalUsed += cpuTimeUsed;
  }

  else if  (fieldName.EqualIgnoreCase ("CURRENTDATETIME"))
  {
    KKB::DateTime  dateTime = KKB::DateTime (statusStr);
    if  (!dateTimeFirstOneFound)
    {
      dateTimeFirstOneFound = true;
      dateTimeStarted = dateTime;
    }
    dateTimeEnded = dateTime;
  }

  else if  (fieldName.EqualIgnoreCase ("ExpansionCount"))
    expansionCount = statusStr.ToInt ();

  else if  (fieldName.EqualIgnoreCase ("ExpansionFirstJobId"))
    expansionFirstJobId = statusStr.ToInt ();

  else if  (fieldName.EqualIgnoreCase ("JobStatusChange"))
    StatusFileProcessLineJobStatusChange (statusStr);

  else if  (fieldName.EqualIgnoreCase ("NextJobId"))
    nextJobId = statusStr.ExtractTokenInt ("\t");

  else if  (fieldName.EqualIgnoreCase ("QuitRunning"))
    quitRunning = true;

  else if  (fieldName.EqualIgnoreCase ("Restart"))
    restart = false;

  else if  (fieldName.EqualIgnoreCase ("Status"))
    status = KKJob::JobStatusFromStr (statusStr);

  else
  {
    log.Level (-1) << "KKJobManager::StatusFileProcessLine  Invalid Field Name[" << fieldName << "]." << endl;
  }
}  /* StatusFileProcessLine */