Пример #1
0
//! Reads the list of enabled sensors from Eucalyptus configuration
//! files and ensures that only those are enabled on the system.
int update_sensors_list()
{

    int ret = EUCA_OK;
    char **names = NULL;

    char *tmpstr = configFileValue(SENSOR_LIST_CONF_PARAM_NAME);
    if (tmpstr == NULL) {
        LOGDEBUG("%s parameter is missing from config file\n", SENSOR_LIST_CONF_PARAM_NAME);
    } else {
        names = from_var_to_char_list(tmpstr);
        EUCA_FREE(tmpstr);
    }

    char **sensors = { NULL }; // if no config value or an empty list
    if (names != NULL) {
        sensors = names;
    }

    ret = conf_stats((const char **)sensors);

    if (names) {
        for (int i=0; names[i]; i++) {
            EUCA_FREE(names[i]);
        }
        EUCA_FREE(names);
    }

    return ret;
}
Пример #2
0
//! Do a full init and execution run. Tests end-to-end
static int test_stats_run(const char *config_file_path) {
    print_header(__func__);
    char *(*check_call)() = testing_service_check_call;
    char *(*state_call)() = testing_service_state_call;
    const char *test_home = getenv(EUCALYPTUS_ENV_VAR_NAME);

    //Init the config file stuff
    LOGDEBUG("Setting up config files and values for init test\n");
    char configFiles[1][EUCA_MAX_PATH];
    bzero(configFiles[0], EUCA_MAX_PATH);
    euca_strncpy(configFiles[0], config_file_path, EUCA_MAX_PATH);
    configInitValues(configEntryKeysRestart, configEntryKeysNoRestart);
    readConfigFile(configFiles, 1);
    LOGDEBUG("Getting sensor list to validate config works\n");
    char *test_value = configFileValue(SENSOR_LIST_CONF_PARAM_NAME);
    if(!test_value) {
        LOGERROR("Config setup didn't work. Null value found\n");
        return EUCA_ERROR;
    } else {
        LOGINFO("Config file has enabled stats: %s\n", test_value);
    }
    LOGDEBUG("Done with config file checks\n");

    flush_sensor_registry(); //just to be sure from other tests
    initialize_message_sensor("testservice", 60, 60, test_get_msg_stats, test_set_msg_stats);
    initialize_service_state_sensor("testservice", 60, 60, state_call, check_call);

    if(init_stats(test_home, "testservice", test_lock, test_unlock) != EUCA_OK) {
        LOGERROR("Error initialing stats\n");
        flush_sensor_registry();
        return EUCA_ERROR;
    }

    LOGINFO("Setting some message stats and doing an internal run\n");
    //populate some stats for the message stats
    update_message_stats(test_msg_stats, "fakemessage", 500, 0);
    update_message_stats(test_msg_stats, "fakemessageDescribe", 250, 0);
    update_message_stats(test_msg_stats, "fakemessageRun", 200, 0);

    int ret = internal_sensor_pass(TRUE);
    flush_sensor_registry();
    return ret;
}
Пример #3
0
QString sandboxPath( SandboxPath pathType )
{
    switch( pathType )
    {
    case SP_EXE:
        {
            QString tmp = QCoreApplication::applicationFilePath();
            return tmp;
        }
    case SP_APP:
        {
            return QCoreApplication::applicationDirPath()+QString("/");
        }
    case SP_MEDIA:
        {
            QVariant mediaRelPath = configFileValue("config","mediaPath","media");
            QString mediaDir = sandboxPath(SP_APP) + mediaRelPath.toString() + "/";
            /* 最後に本当にそのディレクトリがあるかをチェック */
            QDir dir(mediaDir);
            if( !dir.exists( mediaDir ) )
            {
                //nlPrintf( "media directory is not found\n" );
                return "";
            }
            return mediaDir;
        }
    case SP_MESH:
        return sandboxPath(SP_MEDIA)+QString("mesh/");
    case SP_SHADER:
        return sandboxPath(SP_MEDIA)+QString("shader/");
    case SP_RENDERTARGET:
        return sandboxPath(SP_MEDIA)+QString("rendertarget/");
    case SP_PATH:
        return sandboxPath(SP_MEDIA)+QString("path/");
    case SP_MUSIC:
        return sandboxPath(SP_MEDIA)+QString("music/");
    case SP_SCENE:
        return sandboxPath(SP_MEDIA)+QString("scene/");
    case SP_TMP:
        return sandboxPath(SP_APP)+QString("/tmp/");
    }
    return "";
}
Пример #4
0
//! A single sensor pass. Runs each sensor and emits the result using
//! the configured emitter.
//! 
int internal_sensor_pass(int return_on_fail) {
    LOGTRACE("Executing internal sensor pass\n");
    json_object *result;
    int i = 0;
    int is_enabled = FALSE;
    int ret = EUCA_OK;
    //Get the sensor list from the config
    char **names = NULL;
    char *tmpstr = configFileValue(SENSOR_LIST_CONF_PARAM_NAME);
    if (tmpstr == NULL) {
        LOGDEBUG("%s parameter is missing from config file\n", SENSOR_LIST_CONF_PARAM_NAME);
    } else {
        names = from_var_to_char_list(tmpstr);
        EUCA_FREE(tmpstr);
    }

    char **sensors = { NULL }; // if no config value or an empty list
    if (names != NULL) {
        sensors = names;
    }

    //Enter the execution loop
    if(get_lock_fn != NULL) {
        get_lock_fn();
    } else {
        LOGERROR("Cannot run internal sensor pass because no lock provided to protect data.\n");

        //Free up the sensor listing
        if (names) {
            for (int i=0; names[i]; i++) {
                EUCA_FREE(names[i]);
            }
            EUCA_FREE(names);
        }

        return EUCA_ERROR;
    }

    LOGTRACE("Running %d sensors\n", sensor_registry.sensor_count);
    for(i = 0; i < sensor_registry.sensor_count; i++) {
        LOGTRACE("Checking sensor %s is enabled\n", sensor_registry.sensors[i]->sensor_name);
        is_enabled = get_new_config_status(sensor_registry.sensors[i]->config_name, (const char**)sensors);
        if(is_enabled && sensor_registry.sensors[i]->sensor_function != NULL) {
            result = sensor_registry.sensors[i]->sensor_function(); 
            if(result == NULL) {
                LOGERROR("Error encountered getting internal sensor output from sensor %s\n", sensor_registry.sensors[i]->sensor_name);
                ret = EUCA_ERROR;
            } else {
                LOGTRACE("Offering event for emitter: %s\n", json_object_to_json_string(result));
                if(emitter_offer_event(result) != EUCA_OK) {
                    LOGERROR("Error emitting event from internal sensor %s\n", sensor_registry.sensors[i]->sensor_name);
                    ret = EUCA_ERROR;
                } else {
                    LOGTRACE("Event offered to emitter successfully\n");
                }
            }
        } else {
            LOGTRACE("Sensor %s not enabled, skipping execution\n", sensor_registry.sensors[i]->sensor_name);
        }
        
        //Update the state of the sensor as needed.
        if(sensor_registry.sensors[i]->state_toggle_callback != NULL) {
            //Must be idempotent
            LOGTRACE("Calling toggle callback on sensor %s with enabled=%d\n", sensor_registry.sensors[i]->sensor_name, is_enabled);
            sensor_registry.sensors[i]->state_toggle_callback(is_enabled);
        }

        if(return_on_fail && ret != EUCA_OK) {
            goto cleanup;
        }
    }
    
 cleanup:
    if(release_lock_fn != NULL) {
        release_lock_fn();
        LOGTRACE("Released lock for stats during sensor pass\n");
    } else {
        LOGERROR("No lock release function found, this could result in deadlock or leaks. Continuing to exit sensor pass function\n");       
    }

    //Free up the sensor listing
    if (names) {
        for (int i=0; names[i]; i++) {
            EUCA_FREE(names[i]);
        }
        EUCA_FREE(names);
    }
    return ret;
}