Example #1
0
void
cleanup_calculations(pe_working_set_t *data_set)
{
	pe_dataset = NULL;
	if(data_set == NULL) {
		return;
	}

	if(data_set->config_hash != NULL) {
		g_hash_table_destroy(data_set->config_hash);
	}
	
	crm_free(data_set->dc_uuid);
	
	crm_debug_3("deleting resources");
	pe_free_resources(data_set->resources); 
	
	crm_debug_3("deleting actions");
	pe_free_actions(data_set->actions);

	crm_debug_3("deleting nodes");
	pe_free_nodes(data_set->nodes);
	
	free_xml(data_set->graph);
	free_ha_date(data_set->now);
	free_xml(data_set->input);
	free_xml(data_set->failed);
	data_set->stonith_action = NULL;

	CRM_CHECK(data_set->ordering_constraints == NULL, ;);
Example #2
0
ha_time_t *
parse_time(char **time_str, ha_time_t * a_time, gboolean with_offset)
{
    ha_time_t *new_time = a_time;

    tzset();
    if (a_time == NULL) {
        new_time = new_ha_date(FALSE);
    }

    CRM_CHECK(new_time != NULL, return NULL);
    CRM_CHECK(new_time->has != NULL, free_ha_date(new_time);
              return NULL);

    /* reset the time fields */
    new_time->hours = 0;
    new_time->minutes = 0;
    new_time->seconds = 0;

    crm_trace("Get hours...");
    new_time->has->hours = FALSE;
    if (parse_int(time_str, 2, 24, &new_time->hours)) {
        new_time->has->hours = TRUE;
    }

    crm_trace("Get minutes...");
    new_time->has->minutes = FALSE;
    if (parse_int(time_str, 2, 60, &new_time->minutes)) {
        new_time->has->minutes = TRUE;
    }

    crm_trace("Get seconds...");
    new_time->has->seconds = FALSE;
    if (parse_int(time_str, 2, 60, &new_time->seconds)) {
        new_time->has->seconds = TRUE;
    }

    if (with_offset) {
        crm_trace("Get offset...");
        while (isspace((int)(*time_str)[0])) {
            (*time_str)++;
        }

        new_time->offset = parse_time_offset(time_str);
        normalize_time(new_time);
    }
    return new_time;
}
Example #3
0
void
cleanup_calculations(pe_working_set_t * data_set)
{
    pe_dataset = NULL;
    if (data_set == NULL) {
        return;
    }

    clear_bit_inplace(data_set->flags, pe_flag_have_status);
    if (data_set->config_hash != NULL) {
        g_hash_table_destroy(data_set->config_hash);
    }

    if (data_set->tickets) {
        g_hash_table_destroy(data_set->tickets);
    }

    if (data_set->template_rsc_sets) {
        g_hash_table_destroy(data_set->template_rsc_sets);
    }

    crm_free(data_set->dc_uuid);

    crm_trace("deleting resources");
    pe_free_resources(data_set->resources);

    crm_trace("deleting actions");
    pe_free_actions(data_set->actions);

    if (data_set->domains) {
        g_hash_table_destroy(data_set->domains);
    }

    crm_trace("deleting nodes");
    pe_free_nodes(data_set->nodes);

    free_xml(data_set->graph);
    free_ha_date(data_set->now);
    free_xml(data_set->input);
    free_xml(data_set->failed);

    set_working_set_defaults(data_set);

    CRM_CHECK(data_set->ordering_constraints == NULL,;);
Example #4
0
unsigned long long
crm_get_interval(const char * input)
{
    ha_time_t *interval = NULL;
    char *input_copy = crm_strdup(input);
    char *input_copy_mutable = input_copy;
    unsigned long long msec = 0;
    
    if(input == NULL) {
	return 0;

    } else if(input[0] != 'P') {
	crm_free(input_copy);
	return crm_get_msec(input);
    }
    
    interval = parse_time_duration(&input_copy_mutable);
    msec = date_in_seconds(interval);
    free_ha_date(interval);
    crm_free(input_copy);
    return msec * 1000;
}
Example #5
0
gboolean
test_date_expression(xmlNode * time_expr, ha_time_t * now)
{
    ha_time_t *start = NULL;
    ha_time_t *end = NULL;
    const char *value = NULL;
    char *value_copy = NULL;
    char *value_copy_start = NULL;
    const char *op = crm_element_value(time_expr, "operation");

    xmlNode *duration_spec = NULL;
    xmlNode *date_spec = NULL;

    gboolean passed = FALSE;

    crm_trace("Testing expression: %s", ID(time_expr));

    duration_spec = first_named_child(time_expr, "duration");
    date_spec = first_named_child(time_expr, "date_spec");

    value = crm_element_value(time_expr, "start");
    if (value != NULL) {
        value_copy = crm_strdup(value);
        value_copy_start = value_copy;
        start = parse_date(&value_copy);
        crm_free(value_copy_start);
    }
    value = crm_element_value(time_expr, "end");
    if (value != NULL) {
        value_copy = crm_strdup(value);
        value_copy_start = value_copy;
        end = parse_date(&value_copy);
        crm_free(value_copy_start);
    }

    if (start != NULL && end == NULL && duration_spec != NULL) {
        end = parse_xml_duration(start, duration_spec);
    }
    if (op == NULL) {
        op = "in_range";
    }

    if (safe_str_eq(op, "date_spec") || safe_str_eq(op, "in_range")) {
        if (start != NULL && compare_date(start, now) > 0) {
            passed = FALSE;
        } else if (end != NULL && compare_date(end, now) < 0) {
            passed = FALSE;
        } else if (safe_str_eq(op, "in_range")) {
            passed = TRUE;
        } else {
            passed = cron_range_satisfied(now, date_spec);
        }

    } else if (safe_str_eq(op, "gt") && compare_date(start, now) < 0) {
        passed = TRUE;

    } else if (safe_str_eq(op, "lt") && compare_date(end, now) > 0) {
        passed = TRUE;

    } else if (safe_str_eq(op, "eq") && compare_date(start, now) == 0) {
        passed = TRUE;

    } else if (safe_str_eq(op, "neq") && compare_date(start, now) != 0) {
        passed = TRUE;
    }

    free_ha_date(start);
    free_ha_date(end);
    return passed;
}