Ejemplo n.º 1
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.º 2
0
/**
 * SSH job: Start status polling
 */
int
ngisSSHjobPollingStart(
    ngisSSHjob_t *job)
{
    int interval;
    ngisCallback_t callback;
    ngisLog_t *log;
    static const char fName[] = "ngisSSHjobPollingStart";

    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;

    interval = job->ngsj_attributes->ngsja_statusPolling;
    if (interval <= 0) {
        interval = NGIS_SSH_JOB_DEFAULT_POLLING_TIME;
    }
    callback = ngisCallbackSetTimer(interval, ngisSSHjobPollingCallback, job);
    if (!ngisCallbackIsValid(callback)) {
        ngisErrorPrint(log, fName,
            "Can't register callback for status polling.\n");
        return 0;
    }
    job->ngsj_timerCallback = callback;

    return 1;
}
Ejemplo n.º 3
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.º 4
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.º 5
0
int
ngisSSHjobPBSdoCancel(
    ngisSSHjob_t *job)
{
    ngisStringBuffer_t sBuf;
    int sBufInitialized = 0;
    char *command = NULL;
    int i;
    int ret = 1;
    int nExe = 0;
    int result;
    ngisCallback_t callback;
    ngisLog_t *log;
    static const char fName[] = "ngisSSHjobPBSdoCancel";

    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;

    nExe =  ngisSSHjobGetNexecutable(job, NGIS_EXECUTABLE_STATUS_PENDING);
    nExe += ngisSSHjobGetNexecutable(job, NGIS_EXECUTABLE_STATUS_ACTIVE);
    if (nExe == 0) {
        /* There is no executable. */
        goto finalize;
    }

    result = ngisStringBufferInitialize(&sBuf);
    if (result == 0) {
        ngisErrorPrint(log, fName, "Can't initialize the string buffer.\n");
        ret = 0;
        goto finalize;
    }
    sBufInitialized = 1;

    result = ngisStringBufferAppend(&sBuf,
        job->ngsj_attributes->ngsja_sshDeleteCommand);
    if (result == 0) {
        ngisErrorPrint(log, fName,
            "Can't append string to the string buffer.\n");
        ret = 0;
        goto finalize;
    }
    for (i = 0;i < job->ngsj_nExecutables;++i) {
        switch (job->ngsj_executables[i].nge_status) {
        case NGIS_EXECUTABLE_STATUS_PENDING:
        case NGIS_EXECUTABLE_STATUS_ACTIVE:
            result = ngisStringBufferFormat(&sBuf,
                " %s", job->ngsj_executables[i].nge_identifier);
            if (result == 0) {
                ngisErrorPrint(log, fName,
                    "Can't append string to the string buffer.\n");
                ret = 0;
                goto finalize;
            }
            break;
        default:
            break;
        }
    }
    result = ngisStringBufferAppend(&sBuf, "\n");
    if (result == 0) {
        ngisErrorPrint(log, fName,
            "Can't append string to the string buffer.\n");
        ret = 0;
        goto finalize;
    }

    command = ngisStringBufferRelease(&sBuf);
    if (command == NULL) {
        ngisErrorPrint(log, fName,
            "Can't release string from string buffer.\n");
        ret = 0;
        goto finalize;
    }

    callback = ngisCallbackWriteFormat(
        job->ngsj_stdio.ngsio_in, ngisSSHjobCancelWriteCallback, job,
        "%s", command);
    if (!ngisCallbackIsValid(callback)) {
        ngisErrorPrint(log, fName, "Can't send command string.\n");
        ret = 0;
        goto finalize;
    }
    job->ngsj_stdinCallback = callback;
    
finalize:
    NGIS_NULL_CHECK_AND_FREE(command);

    if (sBufInitialized != 0) {
        ngisStringBufferFinalize(&sBuf);
        sBufInitialized = 0;
    }
    return ret;
}
Ejemplo n.º 6
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.º 7
0
static int
ngislSSHjobDoCancel(
    ngisSSHjob_t* job)
{
    ngisStringBuffer_t sBuf;
    int sBufInitialized = 0;
    char *command = NULL;
    int i;
    int ret = 1;
    int nActive = 0;
    int result;
    ngisCallback_t callback;
    ngisLog_t *log;
    ngisExecutable_t *exe;
    static const char fName[] = "ngislSSHjobDoCancel";

    NGIS_ASSERT(job != NULL);

    log = job->ngsj_log;

    nActive = ngisSSHjobGetNexecutable(job, NGIS_EXECUTABLE_STATUS_ACTIVE);
    if (nActive == 0) {
        /* There is no executable. */
        goto finalize;
    }

    result = ngisStringBufferInitialize(&sBuf);
    if (result == 0) {
        ngisErrorPrint(log, fName, "Can't initialize the string buffer.\n");
        ret = 0;
        goto finalize;
    }
    sBufInitialized = 1;

    result = ngisStringBufferAppend(&sBuf, NGIS_KILL_COMMAND);
    if (result == 0) {
        ngisErrorPrint(log, fName,
            "Can't append string to the string buffer.\n");
        ret = 0;
        goto finalize;
    }
    for (i = 0;i < job->ngsj_nExecutables;++i) {
        exe = &job->ngsj_executables[i];
        if (exe->nge_status == NGIS_EXECUTABLE_STATUS_ACTIVE) {
            result = ngisStringBufferFormat(&sBuf, " %s", exe->nge_identifier);
            if (result == 0) {
                ngisErrorPrint(log, fName,
                    "Can't append string to the string buffer.\n");
                ret = 0;
                goto finalize;
            }
        }
    }
    result = ngisStringBufferAppend(&sBuf, "\n");
    if (result == 0) {
        ngisErrorPrint(log, fName,
            "Can't append string to the string buffer.\n");
        ret = 0;
        goto finalize;
    }

    command = ngisStringBufferRelease(&sBuf);
    if (command == NULL) {
        ngisErrorPrint(log, fName,
            "Can't append string to the string buffer.\n");
        ret = 0;
        goto finalize;
    }

    callback = ngisCallbackWriteFormat(job->ngsj_stdio.ngsio_in,
        ngisSSHjobCancelWriteCallback, job, "%s", command);
    if (!ngisCallbackIsValid(callback)) {
        ngisErrorPrint(log, fName,
            "Can't register function for sending command string.\n");
        ret = 0;
        goto finalize;
    }
    job->ngsj_stdinCallback = callback;
    
finalize:
    NGIS_NULL_CHECK_AND_FREE(command);

    if (sBufInitialized != 0) {
        ngisStringBufferFinalize(&sBuf);
        sBufInitialized = 0;
    }
    return ret;
}
Ejemplo n.º 8
0
int
ngisSSHjobProcessAfterExit(
    ngisSSHjob_t *job)
{
    int result;
    ngisLog_t *log = NULL;
    int i;
    ngisExecutable_t *exe = NULL;
    ngisExecutableStatus_t jobStatus;
    static const char fName[] = "ngisSSHjobProcessAfterExit";
    
    NGIS_ASSERT(job != NULL);

    log  = job->ngsj_log;
    jobStatus = ngisSSHjobGetStatus(job);

    ngisSSHjobFunctionReset(job);
    job->ngsj_iExecutables = 0;

    /* Stop polling */
    if (ngisCallbackIsValid(job->ngsj_timerCallback)) {
        ngisCallbackCancel(job->ngsj_timerCallback);
        job->ngsj_timerCallback = NULL;
    }

    if (job->ngsj_afterExit != 0) {
        goto error;
    }
    job->ngsj_afterExit = 1;

    if ((job->ngsj_attributes->ngsja_redirectEnable != 0) &&
        (jobStatus > NGIS_EXECUTABLE_STATUS_SUBMITTING)   &&
        (jobStatus < NGIS_EXECUTABLE_STATUS_STAGEOUT)) {

        for (i = 0;i < job->ngsj_nExecutables;++i) {
            exe = &job->ngsj_executables[i];
            if (exe->nge_status == NGIS_EXECUTABLE_STATUS_FAILED) {
                result = ngisSSHjobExecutableSetStatus(
                    job, exe, NGIS_EXECUTABLE_STATUS_FAILED_STAGEOUT);
            } else {
                result = ngisSSHjobExecutableSetStatus(
                    job, exe, NGIS_EXECUTABLE_STATUS_STAGEOUT);
            }
            if (result == 0) {
                ngisErrorPrint(log, fName, "Can't set status.\n");            
                goto error;
            }
        }

        /* Redirect outerr */
        result = ngisSSHjobFunctionPush(job, ngislSSHjobTransferStdout);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't register the function for transfer STDOUT.\n");
            goto error;
        }
        result = ngisSSHjobFunctionPush(job, ngislSSHjobTransferStderr);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't register the function for transfer STDERR.\n");
            goto error;
        }
    } 

    result = ngisSSHjobFunctionPush(job, ngisSSHjobDone);
    if (result == 0) {
        ngisErrorPrint(log, fName,
            "Can't register the function for transfer job done.\n");
        goto error;
    }

    result = ngisSSHjobFunctionPop(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName,
            "Fails the registered function.\n");
        return 0;
    }
    
    return 1;
error:
    result = ngisSSHjobDone(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName, "Can't done the job.\n");
    }
    return 0;
}