Exemplo n.º 1
0
static void
ngislSSHjobPBSsubmitReadCallback(
    void *arg,
    ngisLineBuffer_t *lBuf,
    char *line,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    int result;
    char *jobID = NULL;
    int nActive;
    ngisLog_t *log;
    static const char fName[] = "ngislSSHjobPBSsubmitReadCallback";

    NGIS_ASSERT(job != NULL);
    NGIS_ASSERT(lBuf != NULL);

    log = job->ngsj_log;

    switch (cResult) {
    case NGIS_CALLBACK_RESULT_CANCEL:
        ngisDebugPrint(log, fName, "Callback is canceled.\n");
        return;
    case NGIS_CALLBACK_RESULT_EOF:
        ngisErrorPrint(log, fName, "Unexcept EOF.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_FAILED:
        ngisErrorPrint(log, fName, "Can't read the reply.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_SUCCESS:
        break;
    default:
        NGIS_ASSERT_NOTREACHED();
    }

    /* Failed? */
    if (strcmp(line, NGIS_SSH_JOB_COMMAND_FAILED) == 0) {
        ngisErrorPrint(log, fName, "Can't submit the job.\n");
        goto next;
    }

    ngisDebugPrint(log, fName, "Job ID = %s.\n", line);

    jobID = strdup(line);
    if (jobID == NULL) {
        ngisErrorPrint(log, fName, "Can't copy the job ID.\n");
        goto next;
    }

next:
    if (jobID != NULL) {
        job->ngsj_executables[job->ngsj_iExecutables].nge_identifier = jobID;
        jobID = NULL;
        result = ngisSSHjobExecutableSetStatus(
            job, &job->ngsj_executables[job->ngsj_iExecutables],
            NGIS_EXECUTABLE_STATUS_PENDING);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't set status.\n");
            goto next;
        }
    } else {
        result = ngisSSHjobExecutableSetStatus(
            job, &job->ngsj_executables[job->ngsj_iExecutables],
            NGIS_EXECUTABLE_STATUS_FAILED);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't set status.\n");
        }
    }

    job->ngsj_iExecutables++;
    if (job->ngsj_iExecutables < job->ngsj_nExecutables) {
        result = ngislSSHjobPBSsubmit(job);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't submit next job.\n");
            goto error;
        }
    } else {
        nActive = ngisSSHjobGetNexecutable(job, NGIS_EXECUTABLE_STATUS_PENDING);
        if (nActive == 0) {
            ngisErrorPrint(log, fName, "Can't execute all executables.\n");
            goto error;
        }

        /* Polling Start */
        result = ngisSSHjobPollingStart(job);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't start status polling.\n");
            goto error;
        }
    }    

    return;
error:
    NGIS_NULL_CHECK_AND_FREE(jobID);

    result = ngisSSHjobProcessAfterExit(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName,
            "The job isn't able to be done.\n");
    }
    return;
}
Exemplo n.º 2
0
/**
 * SSH job: Callback for polling
 */
void
ngisSSHjobPollingCallback(
    void *arg,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    int result;
    ngisLog_t *log;
    static const char fName[] = "ngisSSHjobPollingCallback";

    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;
    job->ngsj_timerCallback = NULL;

    ngisDebugPrint(log, fName, "Called.\n");

    switch (cResult) {
    case NGIS_CALLBACK_RESULT_SUCCESS:
        break;
    case NGIS_CALLBACK_RESULT_CANCEL:
        ngisDebugPrint(log, fName, "Canceled.\n");
        return;
    case NGIS_CALLBACK_RESULT_FAILED:
        ngisErrorPrint(log, fName, "Failed.\n");
        goto error;
    default:
        NGIS_ASSERT_NOTREACHED();
    }

    /* Next */
    result = ngisSSHjobPollingStart(job);
    if (result == 0) {
        ngisErrorPrint(log, fName, "Can't continue status polling.\n");
        goto error;
    }

    if (job->ngsj_statusChecking != 0) {
        ngisWarningPrint(log, fName, 
            "Previous status checking still has not finished. "
            "Skip checking of this time.\n");
        /* DONOTHING */
        return;
    } else {
        /* Check Start */
        ngisSSHjobFunctionReset(job);
        job->ngsj_statusChecking = 1;
        job->ngsj_iExecutables = 0;
        switch (job->ngsj_jobManagerType) {
        case NGIS_SSH_JOB_MANAGER_NORMAL:
            result = ngislSSHjobQueryStatus(job);
            break;
        case NGIS_SSH_JOB_MANAGER_SGE:
            result = ngisSSHjobSGEqueryStatus(job);
            break;
        case NGIS_SSH_JOB_MANAGER_PBS:
            result = ngisSSHjobPBSqueryStatus(job);
            break;
        default:
            NGIS_ASSERT_NOTREACHED();
        }
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't query status.\n");
            goto error;
        }
    }
    
    return;
error:
    result = ngisSSHjobProcessAfterExit(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName, "The job isn't able to be done.\n");
    }
    return;
}