Public Member Functions | Protected Attributes | Private Attributes

job_Manager Class Reference
[Partition Manager]

#include <jobs.h>

Inheritance diagram for job_Manager:
Inheritance graph
[legend]
Collaboration diagram for job_Manager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 job_Manager ()
virtual ~job_Manager ()
i_ResourceManager_ptr GetRM ()
UInt32_t GetJobCount ()
void AbortJob (UInt64_t a_JobId)
 Removing Job from List of active.
void AbortAllJobs ()
void ForceEndJob (UInt64_t a_jobId)
i_JobList_tGetAllJobs ()
i_JobParamsSeq_tGetAllJobParams ()
i_Job_iFindJob (UInt64_t a_jobId)
 Finding Job in active Job List.
void AddJobToList (i_Job_i *a_job)
 inserting Job from List of active
void RemoveFromList (UInt64_t a_jobID, i_CompletionStatus_e a_status)
void SetMaxRunningJobs (UInt32_t a_maxJobs)
i_Status_t GetJobStatus (UInt64_t a_jobId)

Protected Attributes

UInt64_t m_createBufSize
cmn_Mutex m_diskBuf_x

Private Attributes

 log_CLASSID_m
cmn_Mutex m_jobMap_x
job_JobList_v_t m_jobList
list< job_finishedStatusm_finishedJobList
UInt32_t m_maxRunningJobs
UInt32_t m_maxRecallJobs
UInt32_t m_runningJobs
i_ResourceManager_var m_rm

Detailed Description

Definition at line 92 of file jobs.h.


Constructor & Destructor Documentation

job_Manager::job_Manager (  ) 
job_Manager::~job_Manager (  )  [virtual]

Definition at line 59 of file job_manager.cpp.

References AbortAllJobs(), dbg_LOW, ivd_Sleep, log_DBG_m, log_FUNC_m, m_jobList, and m_jobMap_x.

                         {
    log_FUNC_m(~job_Manager);

    AbortAllJobs();
    UInt32_t jobMapSize(1);
    do {
        {
            cmn_MutexLock l(m_jobMap_x);
            jobMapSize = m_jobList.size();
        }// Unlock here

        if (jobMapSize > 0) {
            log_DBG_m(dbg_LOW,"JobManager Shutdown: Jobs are still active waiting ...");
            ivd_Sleep(1);
        }
    } while ( jobMapSize > 0 ) ;

}

Here is the call graph for this function:


Member Function Documentation

void job_Manager::AbortAllJobs (  ) 

Definition at line 223 of file job_manager.cpp.

References dbg_NORM, jt_RECOVERY, log_DBG_m, log_FUNC_m, m_jobList, and m_jobMap_x.

Referenced by i_PartitionManager_i::AbortAllJobs(), and ~job_Manager().

                              {
    log_FUNC_m(AbortAllJobs);

    cmn_MutexLock l(m_jobMap_x);

    if (m_jobList.begin() == m_jobList.end()){
        //nothing to do
        return;
    }

    job_Iterator_t iter;
    for (iter = m_jobList.begin(); iter != m_jobList.end(); iter++) {
        try {
            i_Job_var       job = (*iter)->GetJob();
            i_JobParams_var jobParams = job->GetJobParams();
            if (jobParams->jobType != jt_RECOVERY) {
                // Cancel all migration and recall jobs

                log_DBG_m(dbg_NORM, "Cancelling Job:" << jobParams->jobID);
                (*iter)->AbortJob();
            };
        }
        catch (...) {
            // Ignore all exceptions and try to do as much cleanup as possible
        }
    };

}

Here is the caller graph for this function:

void job_Manager::AbortJob ( UInt64_t  a_JobId  ) 

Removing Job from List of active.

Definition at line 119 of file job_manager.cpp.

References dbg_NORM, ie_JOB_NOT_FOUND, ipc_EXEC_m, ivd_Error, log_DBG_m, log_FUNC_m, m_jobList, and m_jobMap_x.

Referenced by i_PartitionManager_i::AbortJob().

                                           {
    log_FUNC_m(AbortJob);

    cmn_MutexLock l(m_jobMap_x);

    // find job by its ID
    job_Iterator_t iter = find_if(  m_jobList.begin(),
                                    m_jobList.end(),
                                    JobIDEqual(a_jobID));

    if (iter == m_jobList.end()) {
        throw ivd_Error(ie_JOB_NOT_FOUND, "Can not abort nonexistent job");
    }

    ipc_EXEC_m (
        if ((*iter)->Started()){
            (*iter)->AbortJob();
            log_DBG_m(dbg_NORM,
                "Job " << a_jobID <<
                " aborting. " );
        } else {
            (*iter)->AbortJob();
            (*iter)->Start();
            log_DBG_m(dbg_NORM,
                "Job " << a_jobID <<
                " job was not started yet. Removing pending job. " );
        }
    );
}

Here is the caller graph for this function:

void job_Manager::AddJobToList ( i_Job_i a_job  ) 

inserting Job from List of active

Definition at line 82 of file job_manager.cpp.

References i_Job_i::ActivateJob(), i_Job_i::CheckJobValid(), dbg_NORM, i_Job_i::GetJobId(), i_Job_i::GetJobTypeEnum(), i_Job_i::InitJob(), job_COUNT_NO_LIMITS, jt_RECALL, log_DBG_m, log_FUNC_m, m_jobList, m_jobMap_x, m_maxRecallJobs, m_maxRunningJobs, m_runningJobs, and i_Job_i::Start().

Referenced by pm_JobMgr::CheckFSCvsIVDFS(), mif_JobManager::CreateBackupJob(), pm_JobMgr::CreateCheckFSCvsMediaJob(), pm_JobMgr::CreateCheckFSCvsMediumJob(), mif_JobManager::CreateCloseVolumeJob(), pm_JobMgr::CreateCopyContentsJob(), pm_JobMgr::CreateDelExpiredFilesJob(), mif_JobManager::CreateDuplMedJob(), pm_JobMgr::CreateEfficientRecallJobs(), mif_JobManager::CreateFormatAndInitJob(), pm_JobMgr::CreateFSCRecoveryJob(), pm_JobMgr::CreateIVDFSRecoveryJob(), pm_JobMgr::CreateMigrationJob(), pm_JobMgr::CreateRecallJob(), mif_JobManager::CreateRecreateFriAndMicJob(), pm_JobMgr::CreateReorgJob(), and pm_JobMgr::CreateReorgScanJob().

                                             {
    log_FUNC_m(AddJobToList);

    a_job->InitJob();
    a_job->CheckJobValid();

    cmn_MutexLock l(m_jobMap_x);
    m_jobList.push_back(a_job);

    a_job->ActivateJob();

    log_DBG_m(dbg_NORM,
        "Job " << a_job->GetJobId() <<
        " inserted to the map. " <<
        m_jobList.size() << " jobs in the map.");

    if (m_maxRunningJobs == job_COUNT_NO_LIMITS ||
        m_runningJobs < m_maxRunningJobs) {

        a_job->Start();
        ++m_runningJobs;

    } else if ( a_job->GetJobTypeEnum() == jt_RECALL &&
                m_runningJobs < m_maxRecallJobs ){

        a_job->Start();
        ++m_runningJobs;

    }

    log_DBG_m(dbg_NORM, "Running jobs: " << m_runningJobs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

i_Job_i * job_Manager::FindJob ( UInt64_t  a_jobId  ) 

Finding Job in active Job List.

Definition at line 258 of file job_manager.cpp.

References ie_JOB_NOT_FOUND, ivd_Error, log_FUNC_m, m_jobList, and m_jobMap_x.

Referenced by i_ManagementInterface_i::AbortJob(), i_PartitionManager_i::GetJob(), and i_ManagementInterface_i::ListJob().

                                              {
    log_FUNC_m(FindJob);

    cmn_MutexLock l(m_jobMap_x);

    job_Iterator_t jobIter = find_if(m_jobList.begin(),
                             m_jobList.end(),
                             JobIDEqual(a_jobId));

    if (jobIter == m_jobList.end()){
        throw ivd_Error(ie_JOB_NOT_FOUND);
    } else {
        return *jobIter;
    }
}

Here is the caller graph for this function:

void job_Manager::ForceEndJob ( UInt64_t  a_jobId  ) 
i_JobParamsSeq_t * job_Manager::GetAllJobParams (  ) 

Definition at line 303 of file job_manager.cpp.

References log_FUNC_m, m_jobList, and m_jobMap_x.

Referenced by i_PartitionManager_i::GetAllJobsParam().

                                               {

    log_FUNC_m(GetAllJobParams);

    cmn_MutexLock l(m_jobMap_x);

    i_JobParamsSeq_t_var jobParams(new i_JobParamsSeq_t(m_jobList.size()));
    jobParams->length(m_jobList.size());

    {
        job_Iterator_t i;
        UInt32_t       j;
        for (i = m_jobList.begin(), j = 0; i != m_jobList.end(); i++, j++) {
            jobParams[j] = *((*i)->GetJobParams());
        }
    };

    return jobParams._retn();
}

Here is the caller graph for this function:

i_JobList_t * job_Manager::GetAllJobs (  ) 

Definition at line 282 of file job_manager.cpp.

References log_FUNC_m, m_jobList, and m_jobMap_x.

Referenced by i_ManagementInterface_i::GetAllAdminJobs(), and i_PartitionManager_i::GetAllJobs().

                                     {

    log_FUNC_m(GetAllJobs);

    cmn_MutexLock l(m_jobMap_x);

    i_JobList_t_var jobList(new i_JobList_t(m_jobList.size()));
    jobList->length(m_jobList.size());

    {
        job_Iterator_t i;
        int            j;
        for (i = m_jobList.begin(), j = 0; i != m_jobList.end(); i++, j++) {
            jobList[j] = (*i)->GetJob();
        };
    }

    return jobList._retn();
}

Here is the caller graph for this function:

UInt32_t job_Manager::GetJobCount (  ) 

Definition at line 275 of file job_manager.cpp.

References m_jobList, and m_jobMap_x.

Referenced by i_PartitionManager_i::GetJobCount(), and i_ManagementInterface_i::SystemStatus().

                                  {
    cmn_MutexLock l(m_jobMap_x);

    return m_jobList.size();

}

Here is the caller graph for this function:

i_Status_t job_Manager::GetJobStatus ( UInt64_t  a_jobId  ) 

Definition at line 362 of file job_manager.cpp.

References dbg_LOW, log_DBG_m, log_FUNC_m, m_finishedJobList, m_jobList, and m_jobMap_x.

Referenced by i_PartitionManager_i::GetJobStatus().

                                                    {
    log_FUNC_m(GetJobStatus);

    cmn_MutexLock l(m_jobMap_x);

    job_Iterator_t jobIter = find_if(m_jobList.begin(),
                                     m_jobList.end(),
                                     JobIDEqual(a_jobId));

    i_Status_t jobStatus;
    if (jobIter == m_jobList.end()){
        //job is not active any more
        //search in finished jobs
        log_DBG_m(dbg_LOW, "Job finished");

        list<job_finishedStatus>::iterator it;
        log_DBG_m(dbg_LOW, "finished job list size" << m_finishedJobList.size());
        bool found = false;

        for ( it = m_finishedJobList.begin(); it != m_finishedJobList.end(); it++) {
            log_DBG_m(dbg_LOW, "finished job list " << it->m_jobID);
            if (it->m_jobID == a_jobId){
                log_DBG_m(dbg_LOW, "Found job: " << a_jobId << " in finished job list" <<
                    " with status:" << it->m_status );
                jobStatus = it->m_status;
                found = true;
                break;
            }
        }

        if (!found){
            log_DBG_m(dbg_LOW, "job is not active and is not in history");
            jobStatus = API_JOB_NOT_FOUND;
        }
    } else {
        log_DBG_m(dbg_LOW, "Job Active");
        jobStatus = API_JOB_IS_IN_PROGRESS;
    }

    log_DBG_m(dbg_LOW, "Status:" << jobStatus);
    return jobStatus;
}

Here is the caller graph for this function:

i_ResourceManager_ptr job_Manager::GetRM (  ) 

Definition at line 323 of file job_manager.cpp.

References ipc_EXEC_m, log_FUNC_m, m_rm, and ipc_Corba::ResolveRM().

                                         {
    log_FUNC_m(GetRM);

    ipc_EXEC_m (
        if (CORBA::is_nil(m_rm)) {
            CORBA::Object_var obj = ipc_Corba::ResolveRM();
            m_rm = i_ResourceManager::_narrow(obj);
        }
        return i_ResourceManager::_duplicate(m_rm);
    );
}

Here is the call graph for this function:

void job_Manager::RemoveFromList ( UInt64_t  a_jobID,
i_CompletionStatus_e  a_status 
)

Definition at line 149 of file job_manager.cpp.

References dbg_LOW, dbg_NORM, ivd_BaseException::GetFriendly(), cmn_Time::GetTime_t(), ie_JOB_NOT_FOUND, ivd_Error, job_COUNT_NO_LIMITS, log_DBG_m, log_ERR_m, log_FUNC_m, m_finishedJobList, m_jobList, m_jobMap_x, m_maxRecallJobs, m_maxRunningJobs, m_runningJobs, and cmn_Time::Time2YMDhmsm().

Referenced by i_Job_i::Remove().

                                                                               {
    log_FUNC_m(RemoveFromList);

    cmn_MutexLock l(m_jobMap_x);

    // find job by its ID
    job_Iterator_t iter = find_if(  m_jobList.begin(),
                                    m_jobList.end(),
                                    JobIDEqual(a_jobID));
    if (iter == m_jobList.end()) {
        log_ERR_m("Trying to remove unexisting job. ID == " << a_jobID);
        throw ivd_Error(ie_JOB_NOT_FOUND, "Can not remove nonexistent job");
    }

    (void)m_jobList.erase(iter);

    log_DBG_m(dbg_NORM,
        "Job " << a_jobID << " removed from the list. " << m_jobList.size() << " jobs remaining.");

    //add job to list of finished jobs

    job_finishedStatus job(a_jobID, a_status);
    m_finishedJobList.push_back(job);

    cmn_Time nowTime;
    nowTime  = nowTime.GetTime_t() - 2*cfg_DAY;

    log_DBG_m(dbg_NORM, "remove Job nowTime: " << nowTime.Time2YMDhmsm());

    while ( m_finishedJobList.size() > 1 ){
        log_DBG_m(dbg_NORM, "m_finishedJobList.size(): " << m_finishedJobList.size());
        log_DBG_m(dbg_NORM, "m_finishedJobList.front().m_finishedTime: " << m_finishedJobList.front().m_finishedTime.Time2YMDhmsm());

        if (m_finishedJobList.front().m_finishedTime.GetTime_t() < nowTime.GetTime_t()){
            log_DBG_m(dbg_NORM, "m_finishedJobList.popFront: " << m_finishedJobList.front().m_jobID);
            m_finishedJobList.pop_front();

        } else {
            break;
        }
    }

    // Running jobs will be counted again
    m_runningJobs = 0;

    log_DBG_m(dbg_NORM, "Will try to start any waiting jobs..");

    for (iter = m_jobList.begin(); iter != m_jobList.end(); iter++) {
        UInt64_t jobID = (*iter)->GetJobId();

        if ((*iter)->Started()) {
            ++m_runningJobs;
        }
        else if (   m_maxRunningJobs == job_COUNT_NO_LIMITS
                 || m_runningJobs < m_maxRunningJobs
                 || (((*iter)->GetJobTypeEnum() == jt_RECALL) &&
                     m_runningJobs < m_maxRecallJobs)) {
// Start waiting jobs up to the limit.
            log_DBG_m(dbg_NORM, "Starting job: " << jobID);

            try {
                (*iter)->Start();
                ++m_runningJobs;
            }
            catch (const ivd_Exception& ie) {
                log_DBG_m(dbg_LOW,
                    "Can't start job: " << jobID << ": " << ie.GetFriendly());
            }
        }
    } // for

    log_DBG_m(dbg_NORM, "Running jobs: " << m_runningJobs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void job_Manager::SetMaxRunningJobs ( UInt32_t  a_maxJobs  ) 

Definition at line 336 of file job_manager.cpp.

References dbg_LOW, log_DBG_m, log_FUNC_A_m, m_jobMap_x, m_maxRecallJobs, and m_maxRunningJobs.

Referenced by i_PartitionManager_i::ParseConfig().

                                                      {
    log_FUNC_A_m(SetMaxRunningJobs, "maxJobs: " << a_maxJobs);

    cmn_MutexLock l(m_jobMap_x);

    const UInt32_t lowerLimit_c(3);
    const UInt32_t upperLimit_c(60);

    if (a_maxJobs == 0) {
        log_DBG_m(dbg_LOW, "Unlimited number of jobs allowed.");
        m_maxRunningJobs = a_maxJobs;
    }
    else {
        if (a_maxJobs < lowerLimit_c) {
            a_maxJobs = lowerLimit_c;
        }
        else if (a_maxJobs > upperLimit_c) {
            a_maxJobs = upperLimit_c;
        }

        log_DBG_m(dbg_LOW, "Changing job limit to: " << a_maxJobs);
        m_maxRunningJobs = a_maxJobs;
        m_maxRecallJobs = m_maxRunningJobs * job_RECALL_FACTOR;
    }
}

Here is the caller graph for this function:


Member Data Documentation

Reimplemented in mif_JobManager, and pm_JobMgr.

Definition at line 98 of file jobs.h.

Definition at line 112 of file jobs.h.

Definition at line 113 of file jobs.h.

Definition at line 103 of file jobs.h.

Referenced by GetJobStatus(), and RemoveFromList().

Definition at line 106 of file jobs.h.

Referenced by AddJobToList(), RemoveFromList(), and SetMaxRunningJobs().

Definition at line 105 of file jobs.h.

Referenced by AddJobToList(), RemoveFromList(), and SetMaxRunningJobs().

i_ResourceManager_var job_Manager::m_rm [private]

Definition at line 108 of file jobs.h.

Referenced by GetRM().

Definition at line 107 of file jobs.h.

Referenced by AddJobToList(), and RemoveFromList().


The documentation for this class was generated from the following files: