Exemple #1
0
/**
 * Finalize.
 */
static int
ngcllLocalMachineInformationManagerFinalize(
    ngclContext_t *context,
    ngcliLocalMachineInformationManager_t *lmInfoMng,
    int *error)
{
    int result;
    static const char fName[] = "ngcllLocalMachineInformationManagerFinalize";

    /* Check the arguments */
    assert(context != NULL);
    assert(lmInfoMng != NULL);

    /* Destroy the Read/Write Lock for own instance */
    result = ngiRWlockFinalize(&lmInfoMng->nglmim_rwlOwn,
	context->ngc_log, error);
    if (result == 0) {
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't destroy Read/Write Lock for own instance.\n"); 
	return 0;
    }

    /* Release the information */
    result = ngclLocalMachineInformationRelease(context,
	&lmInfoMng->nglmim_info, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't release the Local Machine Information.\n"); 
	return 0;
    }

    /* Success */
    return 1;
}
Exemple #2
0
static int
ngcllLocalMachineInformationRelease(
    ngclContext_t *context,
    ngclLocalMachineInformation_t *lmInfo,
    int *error)
{
    int result;
    ngLog_t *log;
    int ret = 1;
    static const char fName[] = "ngcllLocalMachineInformationRelease";

    /* Check the arguments */
    assert(context != NULL);

    if (lmInfo == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT);
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Invalid argument.\n"); 
        return 0;
    }

    log = context->ngc_log;

    /* Deallocate the members */
    if (lmInfo->nglmi_hostName != NULL)
        ngiFree(lmInfo->nglmi_hostName, log, error);
    if (lmInfo->nglmi_tmpDir != NULL)
	ngiFree(lmInfo->nglmi_tmpDir, log, error);
    if (lmInfo->nglmi_invokeServerLog != NULL)
	ngiFree(lmInfo->nglmi_invokeServerLog, log, error);
    if (lmInfo->nglmi_commProxyLog != NULL)
	ngiFree(lmInfo->nglmi_commProxyLog, log, error);
    if (lmInfo->nglmi_infoServiceLog != NULL)
	ngiFree(lmInfo->nglmi_infoServiceLog, log, error);
    if (lmInfo->nglmi_signals != NULL)
	ngiFree(lmInfo->nglmi_signals, log, error);

    /* Release Log Information */
    result = ngiLogInformationFinalize(&lmInfo->nglmi_logInfo, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't release Log Information.\n"); 
        error = NULL;
        ret = 0;
    }

    result = ngiLogLevelInformationFinalize(&lmInfo->nglmi_logLevels, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't release Log Levels Information.\n"); 
        error = NULL;
        ret = 0;
    }

    /* Initialize the members */
    ngcllLocalMachineInformationInitializeMember(lmInfo);

    /* Success */
    return ret;
}
Exemple #3
0
/**
 * Information delete.
 */
int
ngcliLocalMachineInformationCacheUnregister(
    ngclContext_t *context,
    int *error)
{
    int result;
    static const char fName[] = "ngcliLocalMachineInformationCacheUnregister";

    /* Is context valid? */
    result = ngcliContextIsValid(context, error);
    if (result == 0) {
	ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName,  
	    "Ninf-G Context is not valid.\n"); 
	return 0;
    }

    /* Lock the list */
    result = ngcliLocalMachineInformationListWriteLock(context,
	context->ngc_log, error);
    if (result == 0) {
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't lock LocalMachineInformation list.\n"); 
	return 0;
    }

    /* Is information registered? */
    if (context->ngc_lmInfo == NULL) {
	/* Not registered */
	NGI_SET_ERROR(error, NG_ERROR_NOT_EXIST);
        ngcliLocalMachineInformationListWriteUnlock(context,
	    context->ngc_log, NULL);
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't unregister DefaultRemoteMachineInformation list.\n"); 
	return 0;
    }

    /* Delete */
    result = ngcllLocalMachineInformationDestruct(
	context, context->ngc_lmInfo, error);
    if (result == 0) {
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't destruct LocalMachineInformation.\n"); 
	return 0;
    }

    /* Unlock the list */
    result = ngcliLocalMachineInformationListWriteUnlock(context,
	context->ngc_log, error);
    if (result == 0) {
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't unlock LocalMachineInformation list.\n"); 
	return 0;
    }

    return 1;
}
Exemple #4
0
/**
 * Construct.
 */
static ngcliLocalMachineInformationManager_t *
ngcllLocalMachineInformationConstruct(
    ngclContext_t *context,
    ngclLocalMachineInformation_t *lmInfo,
    int *error)
{
    int result;
    ngcliLocalMachineInformationManager_t *lmInfoMng;
    static const char fName[] = "ngcllLocalMachineInformationConstruct";

    /* Check the arguments */
    assert(context != NULL);
    assert(lmInfo != NULL);

    /* Allocate */
    lmInfoMng = NGI_ALLOCATE(ngcliLocalMachineInformationManager_t,
        context->ngc_log, error);
    if (lmInfoMng == NULL) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't allocate the storage for Local Machine Information.\n"); 
	return NULL;
    }

    /* Initialize */
    result = ngcllLocalMachineInformationManagerInitialize(
        context, lmInfoMng, lmInfo, error);
    if (result == 0) {
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't initialize the Local Machine Information.\n"); 
	goto error;
    }

    /* Register */
    result = ngcliContextRegisterLocalMachineInformation(
    	context, lmInfoMng, error);
    if (result == 0) {
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't register the Local Machine Information for Ninf-G Context.\n"); 
	goto error;
    }

    /* Success */
    return lmInfoMng;

    /* Error occurred */
error:
    result = ngcllLocalMachineInformationDestruct(context, lmInfoMng, error);
    if (result == 0) {
    	ngclLogFatalContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't free the storage for Local Machine Information Manager.\n"); 
	return NULL;
    }

    return NULL;
}
Exemple #5
0
/**
 * JobStartTimeout: Time change event arrived.
 */
static int
ngcllJobStartTimeoutEventTimeSet(
    void *arg,
    ngiIOhandle_t *handle,
    ngiIOhandleState_t state,
    ngLog_t *argLog,
    int *argError)
{
    static const char fName[] = "ngcllJobStartTimeoutEventTimeSet";
    int *error, errorEntity;
    ngclContext_t *context;
    time_t timeoutTime;
    ngLog_t *log;
    int result;

    /* Check the arguments */
    assert(arg != NULL);

    context = (ngclContext_t *)arg;
    log = context->ngc_log;
    error = &errorEntity;
    NGI_SET_ERROR(error, NG_ERROR_NO_ERROR);

    if (state == NGI_IOHANDLE_STATE_CANCELED) {
        ngclLogDebugContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "job start timeout event time change callback canceled.\n"); 

        return 1;
    }
    assert(state == NGI_IOHANDLE_STATE_NORMAL);

    /* Get earliest timeout time */
    result = ngcllJobStartTimeoutGetEarliestTimeoutTime(
        context, &timeoutTime, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Getting earliest timeout time failed.\n"); 
        return 0;
    }

    /* Set new timeout time */
    result = ngiIOhandleTimeEventTimeSet(
        context->ngc_jobStartTimeoutHandle, timeoutTime, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Set the event time failed.\n"); 
        return 0;
    }

    /* Success */
    return 1;
}
Exemple #6
0
/**
 * Get the information.
 *
 * Note:
 * Lock the list before using this function, and unlock the list after use.
 */
ngcliLocalMachineInformationManager_t *
ngcliLocalMachineInformationCacheGet(
    ngclContext_t *context,
    int *error)
{
    int result;
    static const char fName[] = "ngcliLocalMachineInformationCacheGet";

    /* Is context valid? */
    result = ngcliContextIsValid(context, error);
    if (result == 0) {
	ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName,  
	    "Ninf-G Context is not valid.\n"); 
	return NULL;
    }

    if (context->ngc_lmInfo == NULL) {
        /* Not found */
        NGI_SET_ERROR(error, NG_ERROR_NOT_EXIST);
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't get LocalMachineInformation list.\n"); 
        return NULL;
    }
    return context->ngc_lmInfo;
}
Exemple #7
0
/**
 * Free the information storage. (not Manager)
 */
int
ngcliLocalMachineInformationFree(
    ngclContext_t *context,
    ngclLocalMachineInformation_t *lmInfo,
    int *error)
{
    int result;
    ngLog_t *log;
    static const char fName[] = "ngcliLocalMachineInformationFree";

    /* Is context valid? */
    result = ngcliContextIsValid(context, error);
    if (result == 0) {
        ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName,  
            "Ninf-G Context is not valid.\n"); 
        return 0;
    }

    log = context->ngc_log;

    /* Check the arguments */
    if (lmInfo == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT);
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Invalid argument.\n"); 
        return 0;
    }

    ngiFree(lmInfo, log, error);

    return 1;
}
Exemple #8
0
/**
 * Allocate the information storage. (not Manager)
 */
ngclLocalMachineInformation_t *
ngcliLocalMachineInformationAllocate(
    ngclContext_t *context,
    int *error)
{
    int result;
    ngLog_t *log;
    ngclLocalMachineInformation_t *lmInfo;
    static const char fName[] = "ngcliLocalMachineInformationAllocate";

    /* Is context valid? */
    result = ngcliContextIsValid(context, error);
    if (result == 0) {
        ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName,  
            "Ninf-G Context is not valid.\n"); 
        return 0;
    }

    log = context->ngc_log;

    /* Allocate new storage */
    lmInfo = ngiCalloc(
        1, sizeof (ngclLocalMachineInformation_t), log, error);
    if (lmInfo == NULL) {
    	NGI_SET_ERROR(error, NG_ERROR_MEMORY);
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't allocate the storage "
            "for LocalMachineInformationManager.\n"); 
	return NULL;
    }

    return lmInfo;
}
Exemple #9
0
/**
 * JobStartTimeout: Initialize
 */
int
ngcliJobStartTimeoutInitialize(
    ngclContext_t *context,
    int *error)
{
    static const char fName[] = "ngcliJobStartTimeoutInitialize";
    ngiIOhandle_t *handle;
    ngLog_t *log;
    int result;

    /* Check the arguments */
    assert(context != NULL);

    log = context->ngc_log;

    context->ngc_jobStartTimeoutHandle = NULL;

    /* log */
    ngclLogDebugContext(context, NG_LOGCAT_NINFG_PURE, fName,  
        "Initialize the Job Start Timeout check module.\n"); 

    /* Construct the I/O handle. */
    handle = ngiIOhandleConstruct(context->ngc_event, log, error);
    if (handle == NULL) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Construct the I/O handle failed.\n"); 
        return 0;
    }

    context->ngc_jobStartTimeoutHandle = handle;

    /* Register the Time Event callback. */
    result = ngiIOhandleTimeEventCallbackRegister(
        handle,
        ngcllJobStartTimeoutEvent, context,
         ngcllJobStartTimeoutEventTimeSet, context,
        log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Register the Time Event to handle failed.\n"); 
        return 0;
    }

    /* Success */
    return 1;
}
Exemple #10
0
/**
 * Initialize the members.
 */
int
ngcliLocalMachineInformationInitialize(
    ngclContext_t *context,
    ngclLocalMachineInformation_t *lmInfo,
    int *error)
{
    int result;
    ngLog_t *log;
    static const char fName[] = "ngcliLocalMachineInformationInitialize";

    /* Is context valid? */
    result = ngcliContextIsValid(context, error);
    if (result == 0) {
        ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName,  
            "Ninf-G Context is not valid.\n"); 
        return 0;
    }
    log = context->ngc_log;

    /* Check the arguments */
    if (lmInfo == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT);
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Invalid argument.\n"); 
        return 0;
    }

    ngcllLocalMachineInformationInitializeMember(lmInfo);

    result = ngiLogInformationInitialize(&lmInfo->nglmi_logInfo, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't initialize the log information.\n"); 
        return 0;
    }
    result = ngiLogLevelInformationInitialize(&lmInfo->nglmi_logLevels, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't initialize the log levels.\n"); 
        return 0;
    }

    /* Success */
    return 1;
}
Exemple #11
0
/**
 * JobStartTimeout: Finalize
 */
int
ngcliJobStartTimeoutFinalize(
    ngclContext_t *context,
    int *error)
{
    static const char fName[] = "ngcliJobStartTimeoutFinalize";
    ngiIOhandle_t *handle;
    ngLog_t *log;
    int result;

    /* Check the arguments */
    assert(context != NULL);

    log = context->ngc_log;
    handle = context->ngc_jobStartTimeoutHandle;

    /* log */
    ngclLogDebugContext(context, NG_LOGCAT_NINFG_PURE, fName,  
        "Finalize the Job Start Timeout check module.\n"); 

    /* Unregister the Time Event Callback. */
    result = ngiIOhandleTimeEventCallbackUnregister(
        handle, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Unregister the Time Event to handle failed.\n"); 
        return 0;
    }

    /* Destruct the I/O handle. */
    result = ngiIOhandleDestruct(handle, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Destruct the I/O handle failed.\n"); 
        return 0;
    }

    context->ngc_jobStartTimeoutHandle = NULL;

    /* Success */
    return 1;
}
Exemple #12
0
/**
 * Destruct.
 */
static int
ngcllLocalMachineInformationDestruct(
    ngclContext_t *context,
    ngcliLocalMachineInformationManager_t *lmInfoMng,
    int *error)
{
    int result;
    static const char fName[] = "ngcllLocalMachineInformationDestruct";

    /* Check the arguments */
    assert(context != NULL);
    assert(lmInfoMng != NULL);

    /* Unregister */
    result = ngcliContextUnregisterLocalMachineInformation(context, lmInfoMng, error);
    if (result == 0) {
	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
	    "Can't unregister the Local Machine Information.\n"); 
	return 0;
    }

    /* Finalize */
    result = ngcllLocalMachineInformationManagerFinalize(context, lmInfoMng, error);
    if (result == 0) {
	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
	    "Can't finalize the Local Machine Information.\n"); 
	return 0;
    }

    /* Deallocate */
    result = NGI_DEALLOCATE(ngcliLocalMachineInformationManager_t,
            lmInfoMng, context->ngc_log, error);
    if (result == 0) {
	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
	    "Can't deallocate the Local Machine Information.\n"); 
	return 0;
    }

    /* Success */
    return 1;
}
Exemple #13
0
/**
 * JobStartTimeout: Job Started.
 */
int
ngcliJobStartTimeoutJobStarted(
    ngclContext_t *context,
    ngclExecutable_t *executable,
    int *error)
{
    static const char fName[] = "ngcliJobStartTimeoutJobStarted";
    ngcliJobManager_t *jobMng;
    ngLog_t *log;
    int result;

    /* Check the arguments */
    assert(context != NULL);
    assert(executable != NULL);

    jobMng = executable->nge_jobMng;
    log = context->ngc_log;

    if (jobMng->ngjm_attr.ngja_startTimeout <= 0) {
        /* Job Start Timeout was not used */
        return 1;
    }

    result = ngcliExecutableLock(executable, log, error);
    if (result == 0) {
        ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't lock the Executable.\n"); 
        return 0;
    }

    /* No need to check anymore */
    executable->nge_jobStartTimeoutTime = 0;

    result = ngcliExecutableUnlock(executable, log, error);
    if (result == 0) {
        ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't unlock the Executable.\n"); 
        return 0;
    }

    /* Notify Time handle that the event time was changed. */
    result = ngiIOhandleTimeEventTimeChangeRequest(
        context->ngc_jobStartTimeoutHandle, log,  error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Change Time request for handle failed.\n"); 
        return 0;
    }

    /* Success */
    return 1;
}
Exemple #14
0
/**
 * Information append.
 */
int
ngcliLocalMachineInformationCacheRegister(
    ngclContext_t *context,
    ngclLocalMachineInformation_t *lmInfo,
    int *error)
{
    int result;
    ngcliLocalMachineInformationManager_t *lmInfoMng;
    static const char fName[] = "ngcliLocalMachineInformationCacheRegister";

    /* Is context valid? */
    result = ngcliContextIsValid(context, error);
    if (result == 0) {
        ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName,  
            "Ninf-G Context is not valid.\n"); 
        return 0;
    }

    /* Check the arguments */
    if (lmInfo == NULL) {
	NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT);
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Invalid argument.\n"); 
	return 0;
    }

    /* Note : No Replace for Local Machine Information. */

    /* Construct */
    lmInfoMng = ngcllLocalMachineInformationConstruct(context, lmInfo, error);
    if (lmInfoMng == NULL) {
	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
	    "Can't construct Local Machine Information.\n"); 
        return 0;
    }

    /* Success */
    return 1;
}
Exemple #15
0
/**
 * JobStartTimeout: Time event arrived.
 */
static int
ngcllJobStartTimeoutEvent(
    void *arg,
    ngiIOhandle_t *handle,
    ngiIOhandleState_t state,
    ngLog_t *argLog,
    int *argError)
{
    static const char fName[] = "ngcllJobStartTimeoutEvent";
    int *error, errorEntity;
    ngclContext_t *context;
    int result;

    /* Check the arguments */
    assert(arg != NULL);

    context = (ngclContext_t *)arg;
    error = &errorEntity;
    NGI_SET_ERROR(error, NG_ERROR_NO_ERROR);

    if (state == NGI_IOHANDLE_STATE_CANCELED) {
        ngclLogDebugContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "job start timeout event callback canceled.\n"); 

        return 1;
    }
    assert(state == NGI_IOHANDLE_STATE_NORMAL);

    ngclLogInfoContext(context, NG_LOGCAT_NINFG_PURE, fName,  
        "Checking job start timeout."
        " May be, one executable handle was timeout.\n"); 

    /* Check the job start timeout */
    result = ngcllJobStartTimeoutCheck(context, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "checking job start timeout failed.\n"); 
        return 0;
    }

    /* Success */
    return 1;
}
Exemple #16
0
/**
 * Initialize.
 */
static int
ngcllLocalMachineInformationManagerInitialize(
     ngclContext_t *context,
     ngcliLocalMachineInformationManager_t *lmInfoMng,
     ngclLocalMachineInformation_t *lmInfo,
     int *error)
{
    int result;
    static const char fName[] = "ngcllLocalMachineInformationManagerInitialize";

    /* Check the arguments */
    assert(context != NULL);
    assert(lmInfoMng != NULL);
    assert(lmInfo != NULL);

    /* Copy to new information */
    result = ngcliLocalMachineInformationCopy(context, lmInfo,
	    &lmInfoMng->nglmim_info, error);
    if (result == 0) {
        ngclLogFatalContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't copy the Local Machine Information.\n"); 
        return 0;
    }

    /* Initialize the Read/Write Lock for own instance */
    result = ngiRWlockInitialize(&lmInfoMng->nglmim_rwlOwn,
	context->ngc_log, error);
    if (result == 0) {
    	ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
    	    "Can't initialize Read/Write Lock for own instance.\n"); 
	return 0;
    }

    /* Success */
    return 1;
}
Exemple #17
0
/**
 * JobStartTimeout: Check timeout and proceed timeout.
 */
static int
ngcllJobStartTimeoutCheck(
    ngclContext_t *context,
    int *error)
{
    static const char fName[] = "ngcllJobStartTimeoutCheck";
    ngclExecutable_t *executable;
    ngLog_t *log;
    int executableListLocked;
    int result;
    int wasTimeout;
    time_t now;

    /* Check the arguments */
    assert(context != NULL);

    wasTimeout = 0;
    now = time(NULL);
    executableListLocked = 0;
    log = context->ngc_log;

    ngclLogInfoContext(context, NG_LOGCAT_NINFG_PURE, fName,  
        "Checking job start timeout.\n"); 

    result = ngclExecutableListReadLock(context, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't lock the list of Executable.\n"); 
        goto error;
    }
    executableListLocked = 1;

    executable = NULL; /* retrieve head item */
    while (((executable = ngclExecutableGetNext(
             context, executable, error)) != NULL)) {

        result = ngcliExecutableLock(executable, log, error);
        if (result == 0) {
            ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't unlock the Executable.\n"); 
            goto error;
        }

        wasTimeout = 0;
        if ((executable->nge_status < NG_EXECUTABLE_STATUS_IDLE) &&
            (executable->nge_jobMng->ngjm_attr.ngja_startTimeout > 0) &&
            (executable->nge_jobStartTimeoutTime > 0)) {
            if (now >= executable->nge_jobStartTimeoutTime) {
                ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                    "job start timeout (%d seconds) occurred"
                    " for executable on \"%s\".\n",
                    executable->nge_jobMng->ngjm_attr.ngja_startTimeout,
                    executable->nge_hostName); 

                wasTimeout = 1;
            }
        }

        result = ngcliExecutableUnlock(executable, log, error);
        if (result == 0) {
            ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't unlock the Executable.\n"); 
            goto error;
        }

        /* Job start timeout occurred */
        if (wasTimeout != 0) {
            result = ngcliExecutableUnusable(executable, NG_ERROR_TIMEOUT, error);
            if (result == 0) {
                ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                    "Can't set the Executable unusable.\n"); 
                goto error;
            }
        }
    }

    executableListLocked = 0;
    result = ngclExecutableListReadUnlock(context, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't unlock the list of Executable.\n"); 
        goto error;
    }


    ngclLogDebugContext(context, NG_LOGCAT_NINFG_PURE, fName,  
        "Checking job start timeout done.\n"); 

    /* Success */
    return 1;

    /*Error*/
error:
    if (executableListLocked != 0) {
        result = ngclExecutableListReadUnlock(context, NULL);
        if (result == 0) {
            ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't unlock the list of Executable.\n"); 
        }
    }
    return 0;
}
Exemple #18
0
/**
 * JobStartTimeout: Get an earliest timeout time
 */
static int
ngcllJobStartTimeoutGetEarliestTimeoutTime(
    ngclContext_t *context,
    time_t *timeoutTime,
    int *error)
{
    static const char fName[] = "ngcllJobStartTimeoutGetEarliestTimeoutTime";
    ngclExecutable_t *executable;
    int executableListLocked;
    ngLog_t *log;
    int result;

    /* Check the arguments */
    assert(context != NULL);
    assert(timeoutTime != NULL);

    log = context->ngc_log;
    executableListLocked = 0;;
    *timeoutTime = 0;

    result = ngclExecutableListReadLock(context, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't lock the list of Executable.\n"); 
        goto error;
    }
    executableListLocked = 1;

    executable = NULL; /* retrieve head item */
    while ((executable = ngclExecutableGetNext(
        context, executable, NULL)) != NULL) {

        assert(executable != NULL);

        result = ngcliExecutableLock(executable, log, error);
        if (result == 0) {
            ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't lock the Executable.\n"); 
            goto error;
        }

        if ((executable->nge_status < NG_EXECUTABLE_STATUS_IDLE) &&
            (executable->nge_jobMng->ngjm_attr.ngja_startTimeout > 0) &&
            (executable->nge_jobStartTimeoutTime > 0)) {
            if (*timeoutTime <= 0) {
                *timeoutTime = executable->nge_jobStartTimeoutTime;
            } else if (executable->nge_jobStartTimeoutTime < *timeoutTime) {
                *timeoutTime = executable->nge_jobStartTimeoutTime;
            }
        }

        result = ngcliExecutableUnlock(executable, log, error);
        if (result == 0) {
            ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't unlock the Executable.\n"); 
            goto error;
        }
    }

    executableListLocked = 0;
    result = ngclExecutableListReadUnlock(context, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't unlock the list of Executable.\n"); 
        goto error;
    }

    /* Success */
    return 1;

    /* Error occurred */
error:
    if (executableListLocked != 0) {
        result = ngclExecutableListReadUnlock(context, NULL);
        if (result == 0) {
            ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't unlock the list of Executable.\n"); 
        }
    }
    return 0;
}
Exemple #19
0
/**
 * JobStartTimeout: Job Start
 */
int
ngcliJobStartTimeoutJobStart(
    ngclContext_t *context,
    ngcliJobManager_t *jobMng,
    int *error)
{
    static const char fName[] = "ngcliJobStartTimeoutJobStart";
    ngclExecutable_t *executable;
    int timeout, result;
    time_t timeoutTime;
    int executableListLocked;
    ngLog_t *log;

    /* Check the arguments */
    assert(context != NULL);
    assert(jobMng != NULL);

    log = context->ngc_log;
    executableListLocked = 0;

    /* Get the timeout time */
    timeout = jobMng->ngjm_attr.ngja_startTimeout;

    if (timeout <= 0) {
        /* Job start timeout was not used */
        return 1;
    }

    /* Set timeout time for each executable handles */
    timeoutTime = time(NULL) + timeout;

    result = ngclExecutableListReadLock(context, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't lock the list of Executable.\n"); 
        goto error;
    }
    executableListLocked = 1;

    executable = NULL; /* retrieve head item */
    while ((executable = ngcliJobGetNextExecutable(
        jobMng, executable, error)) != NULL) {

        assert(executable != NULL);

        result = ngcliExecutableLock(executable, log, error);
        if (result == 0) {
            ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't lock the Executable.\n"); 
            goto error;
        }

        executable->nge_jobStartTimeoutTime = timeoutTime;

        result = ngcliExecutableUnlock(executable, log, error);
        if (result == 0) {
            ngclLogErrorExecutable(executable, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't unlock the Executable.\n"); 
            goto error;
        }
    }

    executableListLocked = 0;
    result = ngclExecutableListReadUnlock(context, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't unlock the list of Executable.\n"); 
        goto error;
    }

    /* Notify Time handle that the event time was changed. */
    result = ngiIOhandleTimeEventTimeChangeRequest(
        context->ngc_jobStartTimeoutHandle, log,  error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Change Time request for handle failed.\n"); 
        goto error;
    }

    /* Success */
    return 1;

    /* Error */
error:
    if (executableListLocked != 0) {
        result = ngclExecutableListReadUnlock(context, NULL);
        if (result == 0) {
            ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't unlock the list of Executable.\n"); 
        }
    }
    return 0;
}
Exemple #20
0
static int
ngcllLocalMachineInformationGetCopy(
    ngclContext_t *context,
    ngclLocalMachineInformation_t *lmInfo,
    int *error)
{
    int result;
    ngcliLocalMachineInformationManager_t *lmInfoMng;
    static const char fName[] = "ngcllLocalMachineInformationGetCopy";

    /* Check the arguments */
    if (lmInfo == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT);
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Invalid argument.\n"); 
        return 0;
    }

    /* Lock the Local Machine Information */
    result = ngcliLocalMachineInformationListReadLock(
        context, context->ngc_log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't lock the list of Local Machine Information.\n"); 
        return 0;
    }

    /* Get the Local Machine Information */
    lmInfoMng = ngcliLocalMachineInformationCacheGet(context, error);
    if (lmInfoMng == NULL) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't get the Local Machine Information.\n"); 
        goto error;
    }

    /* Copy the Local Machine Information */
    result = ngcliLocalMachineInformationCopy(context,
                    &lmInfoMng->nglmim_info, lmInfo, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,
            "Can't copy the Local Machine Information.\n"); 
        goto error;
    }

    /* Unlock the Local Machine Information */
    result = ngcliLocalMachineInformationListReadUnlock(
        context, context->ngc_log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't unlock the list of Local Machine Information.\n"); 
        return 0;
    }

    /* Success */
    return 1;

    /* Error occurred */
error:
    /* Unlock */
    result = ngcliLocalMachineInformationListReadUnlock(
        context, context->ngc_log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't unlock the list of Local Machine Information.\n"); 
        return 0;
    }

    /* Failed */
    return 0;
}
Exemple #21
0
/**
 * Copy the information.
 */
int
ngcliLocalMachineInformationCopy(
    ngclContext_t *context,
    ngclLocalMachineInformation_t *src,
    ngclLocalMachineInformation_t *dest,
    int *error)
{
    int result;
    ngLog_t *log;
    int *signalTable, *newSignalTable, i, size;
    static const char fName[] = "ngcliLocalMachineInformationCopy";

    /* Is context valid? */
    result = ngcliContextIsValid(context, error);
    if (result == 0) {
        ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName,  
            "Ninf-G Context is not valid.\n"); 
        return 0;
    }
    log = context->ngc_log;

    /* Check the arguments */
    if ((src == NULL) || (dest == NULL)) {
        NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT);
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Invalid argument.\n"); 
        return 0;
    }

    /* Initialize the members */
    ngcllLocalMachineInformationInitializeMember(dest);

    /* Copy the members */
    *dest = *src;

    /* Clear pointers for to error-release work fine */
    ngcllLocalMachineInformationInitializePointer(dest);

    /* Copy the strings */
#define NGL_COPY_STRING(src, dest, member) \
    do { \
        if ((src)->member != NULL) {\
            assert((src)->member != NULL); \
            (dest)->member = ngiStrdup((src)->member, log, error); \
            if ((dest)->member == NULL) { \
                ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, \
                    "Can't allocate the storage " \
                    "for Local Machine Information.\n"); \
                    goto error; \
            } \
        } \
    } while(0)
    
    NGL_COPY_STRING(src, dest, nglmi_hostName); 
    NGL_COPY_STRING(src, dest, nglmi_tmpDir);
    NGL_COPY_STRING(src, dest, nglmi_invokeServerLog);
    NGL_COPY_STRING(src, dest, nglmi_commProxyLog);
    NGL_COPY_STRING(src, dest, nglmi_infoServiceLog);
#undef NGL_COPY_STRING

    /* Copy the Log Information */
    result = ngiLogInformationCopy(
        &src->nglmi_logInfo, &dest->nglmi_logInfo, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't copy the Log Information.\n"); 
        goto error;
    }

    result = ngiLogLevelInformationCopy(
        &src->nglmi_logLevels, &dest->nglmi_logLevels, log, error);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't copy the Log Level.\n"); 
        goto error;
    }

    size = 0;
    signalTable = src->nglmi_signals;
    newSignalTable = NULL;
    if (signalTable != NULL) {
        for (; signalTable[size] != 0; size++);

        newSignalTable = ngiCalloc(sizeof(int), size + 1, log, error);
        if (newSignalTable == NULL) {
            ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
                "Can't allocate the storage of signal table.\n"); 
            goto error;
        }

        for (i = 0; i < (size + 1); i++) {
            newSignalTable[i] = signalTable[i];
        }
    }
    dest->nglmi_signals = newSignalTable;

    return 1;

    /* Error occurred */
error:

    /* Release */
    result = ngclLocalMachineInformationRelease(context, dest, NULL);
    if (result == 0) {
        ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName,  
            "Can't release the Local Machine Information.\n"); 
    }

    /* Failed */
    return 0;
}