Ejemplo n.º 1
0
/**
 * SSH job: Execute SSH
 */
static pid_t
ngislSSHjobExecuteSSH(
    ngisSSHjob_t *job)
{
    pid_t pid = -1;
    ngisLog_t *log;
    static const char fName[] = "ngislSSHjobExecuteSSH";
    
    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;

    pid = ngislSSHjobSSHpopen(job, NULL, &job->ngsj_stdio);
    if (pid < 0) {
        ngisErrorPrint(log, fName, "Can't execute SSH.\n");
        return -1;
    }
    
    ngisDebugPrint(log, fName, "Child Process's STDIN  is %d.\n",
        job->ngsj_stdio.ngsio_in);
    ngisDebugPrint(log, fName, "Child Process's STDOUT is %d.\n",
        job->ngsj_stdio.ngsio_out);
    ngisDebugPrint(log, fName, "Child Process's STDERR is %d.\n",
        job->ngsj_stdio.ngsio_error);

    return pid;
}
Ejemplo n.º 2
0
static int
ngislSSHjobPBSqueryStatus(
    ngisSSHjob_t *job)
{
    ngisCallback_t callback;
    int index;
    ngisExecutable_t *exe;
    ngisLog_t *log;
    int result;
    static const char fName[] = "ngislSSHjobPBSqueryStatus";

    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;

    while (job->ngsj_iExecutables < job->ngsj_nExecutables) {
        index = job->ngsj_iExecutables;
        exe   = &job->ngsj_executables[index];
        ngisDebugPrint(log, fName,
            "Executable[%d] is %d\n", index, exe->nge_status);

        if (exe->nge_status <= NGIS_EXECUTABLE_STATUS_ACTIVE) {
            /* Check Status */
            job->ngsj_nextReadCallback = ngislSSHjobPBSqueryStatusReadCallback;
            callback = ngisCallbackWriteFormat(
                job->ngsj_stdio.ngsio_in,
                ngisSSHjobWriteStringCallback, job,
                "%s -f %s | %s 'job_state';%s dummy\n",
                job->ngsj_attributes->ngsja_sshStatusCommand,
                exe->nge_identifier, NGIS_GREP_COMMAND, NGIS_ECHO_COMMAND);
            if (!ngisCallbackIsValid(callback)) {
                ngisErrorPrint(log, fName,
                    "Can't register function for sending"
                    " query status command string.\n");
                return 0;
            }
            break;
        }
        job->ngsj_iExecutables++;
    }

    if (!(job->ngsj_iExecutables < job->ngsj_nExecutables)) {
        ngisDebugPrint(log, fName, "Status checking has finished.\n");
        job->ngsj_iExecutables = 0;
        result = ngisSSHjobFinishQuery(job);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't finish to query the job status.\n");
            return 0;
        }
    }
    return 1;
}
Ejemplo n.º 3
0
/**
 * SSH job: Query status
 */
static int
ngislSSHjobQueryStatus(
    ngisSSHjob_t *job)
{
    int index;
    ngisExecutable_t *exe;
    ngisCallback_t callback;
    ngisLog_t *log = NULL;
    int result;
    static const char fName[] = "ngislSSHjobQueryStatus";

    NGIS_ASSERT(job != NULL);
    NGIS_ASSERT(job->ngsj_attributes != NULL);

    log = job->ngsj_log;

    ngisDebugPrint(log, fName, "Index is %d/%d\n",
        job->ngsj_iExecutables, job->ngsj_nExecutables);

    while (job->ngsj_iExecutables < job->ngsj_nExecutables) {
        index =  job->ngsj_iExecutables;
        exe   = &job->ngsj_executables[index];
        ngisDebugPrint(log, fName, "Executable[%d] is %s\n",
            index, ngislExecutableStatusString[exe->nge_status]);
        if (exe->nge_status == NGIS_EXECUTABLE_STATUS_ACTIVE) {
            /* Check Status */
            job->ngsj_nextReadCallback = ngislSSHjobQueryStatusReadCallback;
            callback = ngisCallbackWriteFormat(
                job->ngsj_stdio.ngsio_in, ngisSSHjobWriteStringCallback, job,
                "%s %s 2> %s && %s %s || %s %s\n",
                NGIS_QUERY_COMMAND, exe->nge_identifier, NGIS_DEV_NULL,
                NGIS_ECHO_COMMAND, NGIS_SSH_JOB_NONE,
                NGIS_ECHO_COMMAND, NGIS_SSH_JOB_EXIT);
            if (!ngisCallbackIsValid(callback)) {
                ngisErrorPrint(log, fName,
                    "Can't write command invoking a executable.\n");
            }
            break;
        }
        job->ngsj_iExecutables++;
    }

    if (!(job->ngsj_iExecutables < job->ngsj_nExecutables)) {
        ngisDebugPrint(log, fName, "Status checking has finished.\n");
        result = ngisSSHjobFinishQuery(job);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't finish to query the job status.\n");
            return 0;
        }
    }
    return 1;
}
Ejemplo n.º 4
0
/**
 * SSH Job: Callback function called when a line is read from standard error
 */
void
ngisSSHjobErrorCallback(
    void *arg,
    ngisLineBuffer_t *lineBuffer,
    char *line,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    int result;
    ngisLog_t *log = NULL;
    static const char fName[] = "ngisSSHjobErrorCallback";

    NGIS_ASSERT(job != NULL);
    NGIS_ASSERT(lineBuffer != NULL);
    NGIS_ASSERT(lineBuffer == job->ngsj_lBufStderr);

    log = job->ngsj_log;

    switch (cResult) {
    case NGIS_CALLBACK_RESULT_EOF:
        ngisDebugPrint(log, fName, "Called with EOF.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_CANCEL:
        ngisDebugPrint(log, fName, "Called because callback was canceled.\n");
        return;
    case NGIS_CALLBACK_RESULT_FAILED:
        ngisErrorPrint(log, fName,
            "Called because error occurred on reading from STDERR.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_SUCCESS:
        break;
    default:
        NGIS_ASSERT_NOTREACHED();
    }
    NGIS_ASSERT(line != NULL);
    ngisErrorPrint(log, fName, "\"%s\".\n", line);

    /* Next Line */
    result = ngisLineBufferReadLine(lineBuffer, ngisSSHjobErrorCallback, job);
    if (result == 0) {
        ngisErrorPrint(log, fName,
            "Can't register callback for reading STDERR.\n");
        goto error;
    }
    
    return;
error:
    ngisLineBufferDestroy(job->ngsj_lBufStderr);
    job->ngsj_lBufStderr = NULL;

    return;
}
Ejemplo n.º 5
0
static int
ngislSSHjobPBSsubmit(
    ngisSSHjob_t *job)
{
    ngisCallback_t callback;
    ngisLog_t *log;
    static const char fName[] = "ngislSSHjobPBSsubmit";

    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;

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

    job->ngsj_nextReadCallback = ngislSSHjobPBSsubmitReadCallback;
    callback = ngisCallbackWriteFormat(
        job->ngsj_stdio.ngsio_in, ngisSSHjobWriteStringCallback, job,
        "%s %s || %s %s\n",
        job->ngsj_attributes->ngsja_sshSubmitCommand,
        job->ngsj_remoteScriptName,
        NGIS_ECHO_COMMAND, NGIS_SSH_JOB_COMMAND_FAILED);
    if (!ngisCallbackIsValid(callback)) {
        ngisErrorPrint(log, fName,
            "Can't register for sending submit command string.\n");
        return 0;
    }
    job->ngsj_stdinCallback = callback;


    return 1;
}
Ejemplo n.º 6
0
/**
 * SSH job: done
 */
int
ngisSSHjobDone(
    ngisSSHjob_t *job)
{
    int i;
    int result;
    ngisLog_t *log;
    ngisExecutable_t *exe = NULL;
    static const char fName[] = "ngisSSHjobDone";

    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;
    ngisDebugPrint(log, fName, "called.\n");

    for (i = 0;i < job->ngsj_nExecutables;++i) {
        exe = &job->ngsj_executables[i];
        switch (exe->nge_status) {
        case NGIS_EXECUTABLE_STATUS_FAILED:
        case NGIS_EXECUTABLE_STATUS_FAILED_STAGEOUT:
            break;
        default:
            result = ngisSSHjobExecutableSetStatus(
                job, exe, NGIS_EXECUTABLE_STATUS_DONE);
            if (result == 0) {
                ngisErrorPrint(log, fName, "Can't set status.\n");            
            }
            break;
        }
    }

    if (((ngisJob_t *)job)->ngj_destroyRequested != 0) {
        result = ngisJobDestroy((ngisJob_t *)job);
        if (result == 0) {
            ngisErrorPrint(NULL, fName, "Can't destroy the job.\n");            
            /* through */
        }
        job = NULL;
    } else {
        /* Disable */
        result = ngislSSHjobDisable(job);
        if (result == 0) {
            ngisErrorPrint(NULL, fName, "Can't disable the job.\n");            
            /* through */
        }
    }
    return 1;
}
Ejemplo n.º 7
0
static void
ngislSSHjobPBSqueryStatusReadCallback(
    void *arg,
    ngisLineBuffer_t *lBuf,
    char *line,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    int result;
    int i;
    ngisTokenAnalyzer_t tokenAnalyzer;
    int tokenAnalyzerInitialized = 0;
    char *status = NULL;
    ngisLog_t *log;
    static const char fName[] = "ngislSSHjobPBSqueryStatusReadCallback";

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

    log = job->ngsj_log;

    switch (cResult) {
    case NGIS_CALLBACK_RESULT_EOF:
        ngisErrorPrint(log, fName, "Unexcept EOF.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_CANCEL:
        ngisDebugPrint(log, fName,
            "Callback is canceled.\n");
        return;
    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, "dummy") == 0) {
        /* Done */
        job->ngsj_executables[0].nge_exitCode = 0;/* Success */
        result = ngisSSHjobExecutableSetStatus(
            job, &job->ngsj_executables[0],
            NGIS_EXECUTABLE_STATUS_EXIT);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't set status.\n");            
            goto error;
        }

        result = ngisSSHjobProcessAfterExit(job);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't process after exit.\n");
            goto error;
        }
        return;
    }

    ngisTokenAnalyzerInitialize(&tokenAnalyzer, line);
    tokenAnalyzerInitialized = 0;

    /* job_state = [STATUS] */
    for (i = 0;i < 2;++i) {
        result = ngisTokenAnalyzerNext(&tokenAnalyzer);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't get status.\n.");
            goto error;
        }
    }
    
    /* Get Status */
    status = ngisTokenAnalyzerGetString(&tokenAnalyzer);
    if (status == NULL) {
        ngisErrorPrint(log, fName,
            "Can't get status.\n");
        goto error;
    }

    ngisDebugPrint(log, fName, "Status string is \"%s\".\n", status);

    /* Check Status */
    switch (*status) {
    case 'Q':
    case 'W':
    case 'T':
        break;
    case 'B':
    case 'E':
    case 'R':
    case 'X':
        /* t(ransfering), r(unning) */
        job->ngsj_executables[0].nge_status
            = NGIS_EXECUTABLE_STATUS_ACTIVE;
        break;
    case 'H':
        /* Do nothing */
        break;
    case 'S':
        break;
    case 'U':
    default:
        /* DONOTHING */;
    }

    free(status);
    status = NULL;

    ngisTokenAnalyzerFinalize(&tokenAnalyzer);
    tokenAnalyzerInitialized = 0;

    result = ngisLineBufferReadLine(job->ngsj_lBufStdout, 
        ngisSSHjobQueryStatusReadDummyCallback, job);
    if (result == 0) {
        ngisErrorPrint(log, fName, 
            "Can't register the function for reading the line.\n");
        goto error;
    }

    return;
error:
    NGIS_NULL_CHECK_AND_FREE(status);

    if (tokenAnalyzerInitialized != 0) {
        ngisTokenAnalyzerFinalize(&tokenAnalyzer);
        tokenAnalyzerInitialized = 0;
    }
    result = ngisSSHjobProcessAfterExit(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName, "The job isn't able to be done.\n");
    }
    return;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
/**
 * SSH job: Callback function for "Query exit status"
 */
static void
ngislSSHjobExecutableDoneReadCallback(
    void *arg,
    ngisLineBuffer_t *lBuf,
    char *line,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    int exitStatus;
    int result;
    int nExit;
    ngisLog_t *log;
    ngisTokenAnalyzer_t tokenAnalyzer;
    int tokenAnalyzerInitialized = 0;
    ngisExecutable_t *exe = NULL;
    static const char fName[] = "ngislSSHjobExecutableDoneReadCallback";

    NGIS_ASSERT(job != NULL);
    NGIS_ASSERT(lBuf != NULL);
    
    log = job->ngsj_log;

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

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

    NGIS_ASSERT(line != NULL);

    ngisTokenAnalyzerInitialize(&tokenAnalyzer, line);
    tokenAnalyzerInitialized = 1;

    /* Get Exit Status */
    result = ngisTokenAnalyzerGetInt(&tokenAnalyzer, &exitStatus);
    if (result == 0) {
        ngisErrorPrint(log, fName, "Can't get exit status.\n");
        goto error;
    }

    /* Check End */
    result = ngisTokenAnalyzerNext(&tokenAnalyzer);
    if (result != 0) {
        ngisErrorPrint(log, fName, "Unnecessary token.\n.");
        goto error;
    }
    tokenAnalyzerInitialized = 0;
    ngisTokenAnalyzerFinalize(&tokenAnalyzer);

    ngisDebugPrint(log, fName, "Exit status is \"%d\".\n", exitStatus);

    /* Set status */
    exe = &job->ngsj_executables[job->ngsj_iExecutables];
    exe->nge_exitCode = exitStatus;
    result = ngisSSHjobExecutableSetStatus(
        job, exe, NGIS_EXECUTABLE_STATUS_EXIT);
    if (result == 0) {
        ngisErrorPrint(log, fName, "Can't set status.\n");
        goto error;
    }

    nExit = ngisSSHjobGetNexecutable(job, NGIS_EXECUTABLE_STATUS_EXIT);
    if (nExit >= job->ngsj_nExecutables) {
        ngisDebugPrint(log, fName, "All Executable exit.\n");
        result = ngisSSHjobProcessAfterExit(job);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't process after exit.\n");
            goto error;
        }
    } else {
        ngisDebugPrint(log, fName, "Check status of the next executable.\n");
        job->ngsj_iExecutables++;
        result = ngislSSHjobQueryStatus(job);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't query status.\n");
            goto error;
        }
    }
    return;

error:
    if (tokenAnalyzerInitialized != 0) {
        tokenAnalyzerInitialized = 0;
        ngisTokenAnalyzerFinalize(&tokenAnalyzer);
    }

    result = ngisSSHjobProcessAfterExit(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName,
            "The job isn't able to be done.\n");
    }
    return;
}
Ejemplo n.º 10
0
int
main(int argc, char *argv[])
{
    int result;
    char *logFileName = NGIS_DEV_NULL;
    int invokeServerInitialized = 0;
    int exitCode = 0;/* Success */
    int opt;
    struct sigaction sa;    
    int debug = 0;
    int i;
    static const int ignoreSignals[] = {
        SIGPIPE, 
        SIGINT,
        SIGTSTP, 
    };
    static const char fName[] = "main";

    /* Options analyze */
    while ((opt = getopt(argc, argv, "l:d")) >= 0) {
        switch (opt) {
        case 'l':
            /* LOG */
            logFileName = optarg;
            break;
        case 'd':
            debug = 1;
            break;
        case '?':
        default:
            /* Ignore arguments */
            ;
        }
    }
    
    result = ngisLogInitializeModule(logFileName, NGIS_LOG_LEVEL_DEBUG);
    if (result == 0) {
        return 1;
    }

    ngisDebugPrint(NULL, fName, "#========================================#\n");
    ngisDebugPrint(NULL, fName, "#      Invoke Server SSH Started         #\n");
    ngisDebugPrint(NULL, fName, "#========================================#\n");
    
    /* Signal */
    sa.sa_flags   = 0;
    sa.sa_handler = SIG_IGN;
    result = sigemptyset(&sa.sa_mask);
    if (result < 0) {
        ngisErrorPrint(NULL, fName, "sigemptyset: %s\n", strerror(errno));
        exitCode = 1;
        goto finalize;
    }

    for (i = 0;i < NGIS_NELEMENTS(ignoreSignals);++i) {
        result = sigaction(ignoreSignals[i], &sa, NULL);
        if (result < 0) {
            ngisErrorPrint(NULL, fName, "sigaction: %s\n", strerror(errno));
            exitCode = 1;
            goto finalize;
        }    
    }
    
    /* Invoke Server */
    result = ngInvokeServerInitialize(&ngislSSHjobTypeInformation);
    if (result == 0) {
        ngisErrorPrint(NULL, fName, "Can't Initialize Invoke Server.\n");
        exitCode = 1;
        goto finalize;
    }
    invokeServerInitialized = 1;
    
    result = ngInvokeServerRun();
    if (result == 0) {
        ngisErrorPrint(NULL, fName, "Invoke Server can't run.\n");
        exitCode = 1;
        goto finalize;
    }
    
finalize:
    if (invokeServerInitialized != 0) {
        result = ngInvokeServerFinalize();
        if (result == 0) {
            ngisErrorPrint(NULL, fName, "Can't finalize Invoke Server.\n");
            exitCode = 1;
        }
    }

    ngisDebugPrint(NULL, fName, "#========================================#\n");
    ngisDebugPrint(NULL, fName, "#      Invoke Server SSH Exit            #\n");
    ngisDebugPrint(NULL, fName, "#========================================#\n");
    
    ngisLogFinalizeModule();
    /* Ignore result */    
    
    return 0;
}
Ejemplo n.º 11
0
static void
ngislSSHjobQueryStatusReadCallback(
    void *arg,
    ngisLineBuffer_t *lBuf,
    char *line,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    ngisCallback_t callback;
    int result;
    char *command;
    ngisLog_t *log;
    static const char fName[] = "ngislSSHjobQueryStatusReadCallback";

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

    log = job->ngsj_log;

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

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

    if (strcmp(line, NGIS_SSH_JOB_NONE) == 0) {
        /* Check next executable */
        job->ngsj_iExecutables++;
        result = ngislSSHjobQueryStatus(job);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't query the status.\n");
            goto error;
        }
    } else if (strcmp(line, NGIS_SSH_JOB_EXIT) == 0) {
        /* Wait the child process and get exit status */
        job->ngsj_nextReadCallback = ngislSSHjobExecutableDoneReadCallback;
        callback = ngisCallbackWriteFormat(
            job->ngsj_stdio.ngsio_in, ngisSSHjobWriteStringCallback, job,
            "wait %s;%s $?\n",
            job->ngsj_executables[job->ngsj_iExecutables].nge_identifier,
            NGIS_ECHO_COMMAND);
        if (!ngisCallbackIsValid(callback)) {
            ngisErrorPrint(log, fName, 
                "Can't write command getting exit code.\n");
            goto error;
        }
        command = NULL;
    } else {
        NGIS_ASSERT_NOTREACHED();
    }

    return;

error:
    result = ngisSSHjobProcessAfterExit(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName,
            "The job isn't able to be done.\n");
    }
    return;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
/**
 * SSH Job: Cancel
 */
static int
ngislSSHjobCancel(
    ngisJob_t* job)
{
    ngisSSHjob_t *sshJob = (ngisSSHjob_t *)job;
    int result = 0;
    ngisExecutableStatus_t status;
    ngisLog_t *log;
    static const char fName[] = "ngislSSHjobCancel";    

    NGIS_ASSERT(sshJob != NULL);

    log = sshJob->ngsj_log;
    
    ngisDebugPrint(log, fName, "called.\n");
    sshJob->ngsj_cancelCalled = 0;

    status = ngisSSHjobGetStatus(sshJob);
    switch (status) {
    case NGIS_EXECUTABLE_STATUS_UNSUBMITTED:
        result = ngisSSHjobDone(sshJob);
        if (result == 0) {
            ngisErrorPrint(NULL, fName,
                "The job isn't able to be done.\n");
        }
        break;
    case NGIS_EXECUTABLE_STATUS_SUBMITTING:
        ngisDebugPrint(log, fName, "Delayed cancel.\n");
        sshJob->ngsj_cancelCalled = 1;
        break;
    case NGIS_EXECUTABLE_STATUS_PENDING:
    case NGIS_EXECUTABLE_STATUS_ACTIVE:
        if (sshJob->ngsj_statusChecking == 0) {
            switch (sshJob->ngsj_jobManagerType) {
            case NGIS_SSH_JOB_MANAGER_NORMAL:
                result = ngislSSHjobDoCancel(sshJob);
                break;
            case NGIS_SSH_JOB_MANAGER_SGE:
                result = ngisSSHjobSGEdoCancel(sshJob);
                break;
            case NGIS_SSH_JOB_MANAGER_PBS:
                result = ngisSSHjobPBSdoCancel(sshJob);
                break;
            default:
                NGIS_ASSERT_NOTREACHED();
            }
            if (result == 0) {
                ngisErrorPrint(log, fName, "Can't cancel the job.\n");
                return 0;
            }
        } else {
            ngisDebugPrint(log, fName, "Delayed cancel.\n");
            sshJob->ngsj_cancelCalled = 1;
        }
        break;
    case NGIS_EXECUTABLE_STATUS_DONE:
    case NGIS_EXECUTABLE_STATUS_FAILED:
    case NGIS_EXECUTABLE_STATUS_STAGEOUT:
    case NGIS_EXECUTABLE_STATUS_FAILED_STAGEOUT:
    case NGIS_EXECUTABLE_STATUS_EXIT:
        break;
    }

    return 1; 
}