static void allservice_check_start_HT(struct namespace_data_s *ns_data, GHashTable *ht) { gsize offset; struct taskdata_checksrv_s td_scheme; GHashTableIter iter_serv; gpointer k, v; TRACE_POSITION(); g_hash_table_iter_init(&iter_serv, ht); while (g_hash_table_iter_next(&iter_serv, &k, &v)) { struct service_info_s *si = v; memset(&td_scheme, 0x00, sizeof(td_scheme)); offset = g_snprintf(td_scheme.task_name, sizeof(td_scheme.task_name), "%s.", TASK_ID); addr_info_to_string(&(si->addr), td_scheme.task_name+offset, sizeof(td_scheme.task_name)-offset); g_strlcpy(td_scheme.ns_name, ns_data->name, sizeof(td_scheme.ns_name)-1); if (!_agent_check_enabled(si)) { GRID_DEBUG("Task [%s] disabled by " NAME_TAGNAME_AGENT_CHECK, td_scheme.task_name); } else if (!is_task_scheduled(td_scheme.task_name)) { GError *error_local = NULL; task_t *task = NULL; struct taskdata_checksrv_s *task_data; TRACE_POSITION(); agent_get_service_key(si, td_scheme.srv_key, sizeof(td_scheme.srv_key)); g_strlcpy(td_scheme.srv_key, (gchar*)k, sizeof(td_scheme.srv_key)-1); /* prepare the task structure */ task_data = g_memdup(&td_scheme, sizeof(td_scheme)); if (!task_data) { ERROR("Memory allocation failure"); continue; } task = create_task(period_check_services, td_scheme.task_name); task = set_task_callbacks(task, _check_tcp_service_task, g_free, task_data); if (!task) { ERROR("Memory allocation failure"); continue; } /* now start the task! */ if (add_task_to_schedule(task, &error_local)) INFO("Task started: %s", td_scheme.task_name); else { ERROR("Failed to add task to scheduler [%s] : %s", td_scheme.task_name, gerror_get_message(error_local)); g_free(task); } if (error_local) g_clear_error(&error_local); } } TRACE_POSITION(); }
static gboolean task_starter(gpointer udata, GError **error) { gpointer ns_k, ns_v; GHashTableIter ns_iterator; task_t *task; gchar ns_id[sizeof(TASK_ID)+1+LIMIT_LENGTH_NSNAME]; namespace_data_t *ns_data; (void)udata; g_hash_table_iter_init(&ns_iterator, namespaces); while (g_hash_table_iter_next(&ns_iterator,&ns_k,&ns_v)) { ns_data = ns_v; g_snprintf(ns_id,sizeof(ns_id),TASK_ID".%s",ns_data->name); if (!namespace_is_available(ns_data)) { if (!is_task_scheduled(ns_id)) { task = create_task(period_get_ns, ns_id); task = set_task_callbacks(task, task_worker, g_free, g_strdup(ns_data->name)); if (!add_task_to_schedule(task, error)) { ERROR("[task_id="TASK_ID"] Failed to start a sub worker for namespace '%s'", (gchar*)ns_k); g_free(task); } else INFO("[task_id="TASK_ID"] subtask started [%s]", ns_id); } } } task_done(TASK_ID); return 1; }
int start_namespace_get_task(GError **error) { task_t *task = create_task(2, TASK_ID); task->task_handler = task_starter; if (!add_task_to_schedule(task, error)) { GSETERROR(error, "Failed to add vol_list_get task to scheduler"); g_free(task); return 0; } return 1; }
int start_cpu_stat_task(GError ** error) { nb_loops = 0; task_t *task = g_malloc0(sizeof(task_t)); task->id = g_strdup(TASK_ID); task->period = 1; task->task_handler = cpu_stat_task_worker; if (!add_task_to_schedule(task, error)) { GSETERROR(error, "Failed to add cpu_stat task to scheduler"); g_free(task); return 0; } return (1); }
int services_task_check(GError ** error) { task_t *task = NULL; task = set_task_callbacks(create_task(2, TASK_ID), allservices_check_starter, NULL, NULL); if (!task) { GSETERROR(error, "Memory allocation failure"); return 0; } if (!add_task_to_schedule(task, error)) { g_free(task); GSETERROR(error, "Failed to add vol_stat_send task to scheduler"); return 0; } INFO("Task started: "TASK_ID); return 1; }
static void allservice_check_start_HT(struct namespace_data_s *ns_data, GHashTable *ht) { gsize offset; struct taskdata_checksrv_s td_scheme; GHashTableIter iter_serv; gpointer k, v; g_hash_table_iter_init(&iter_serv, ht); while (g_hash_table_iter_next(&iter_serv, &k, &v)) { struct service_info_s *si = v; gboolean srv_check_enabled = TRUE; /* Services can disable TCP checks (enabled by default) */ service_tag_t *tag = service_info_get_tag(si->tags, NAME_TAGNAME_AGENT_CHECK); if (tag) { GError *err = NULL; if (tag->type == STVT_BOOL) { service_tag_get_value_boolean(tag, &srv_check_enabled, &err); } else { gchar buf[64] = {0}; service_tag_get_value_string(tag, buf, sizeof(buf), &err); srv_check_enabled = metautils_cfg_get_bool(buf, TRUE); } g_clear_error(&err); } memset(&td_scheme, 0x00, sizeof(td_scheme)); offset = g_snprintf(td_scheme.task_name, sizeof(td_scheme.task_name), "%s.", TASK_ID); addr_info_to_string(&(si->addr), td_scheme.task_name+offset, sizeof(td_scheme.task_name)-offset); g_strlcpy(td_scheme.ns_name, ns_data->name, sizeof(td_scheme.ns_name)-1); if (!srv_check_enabled) { GRID_DEBUG("Task [%s] disabled by " NAME_TAGNAME_AGENT_CHECK, td_scheme.task_name); } else if (!is_task_scheduled(td_scheme.task_name)) { GError *error_local = NULL; task_t *task = NULL; struct taskdata_checksrv_s *task_data; agent_get_service_key(si, td_scheme.srv_key, sizeof(td_scheme.srv_key)); g_strlcpy(td_scheme.srv_key, (gchar*)k, sizeof(td_scheme.srv_key)-1); /* prepare the task structure */ task_data = g_memdup(&td_scheme, sizeof(td_scheme)); if (!task_data) { ERROR("Memory allocation failure"); continue; } task = create_task(period_check_services, td_scheme.task_name); task = set_task_callbacks(task, _check_tcp_service_task, g_free, task_data); if (!task) { ERROR("Memory allocation failure"); continue; } /* now start the task! */ if (add_task_to_schedule(task, &error_local)) INFO("Task started: %s", td_scheme.task_name); else { ERROR("Failed to add task to scheduler [%s] : %s", td_scheme.task_name, gerror_get_message(error_local)); g_free(task); } if (error_local) g_clear_error(&error_local); } } }