diff options
author | Marco Platania <platania@research.att.com> | 2018-11-30 16:37:21 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-11-30 16:37:21 +0000 |
commit | 3d9c60866a1ca4f083b4acce5276eef498d7250b (patch) | |
tree | c6e03886c17fb2e2bc9f55f3fac2225b064399a4 | |
parent | e96f8427c7a6209ed7b8e9165d718aeeaef6c888 (diff) | |
parent | 06c467f6db1b1bd3505c8dbdf36ff0aae4beab7e (diff) |
Merge "resubmit - 2 collector support-include readme .."
9 files changed, 505 insertions, 897 deletions
diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.c index 488e073a..fbe3de41 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.c +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.c @@ -70,7 +70,6 @@ char *functional_role = NULL; * @param topic The optional topic part of the URL (may be NULL). * @param ring buf size Ring buffer size * @param secure Whether to use HTTPS (0=HTTP, 1=HTTPS) - * @param activmode Whether to use ActivStandby(0) collectors or ActiveStandby(1) * @param cert_file_path Path to client certificate file * @param key_file_path Path to client key file * @param ca_info Path to CA cert file @@ -100,7 +99,6 @@ EVEL_ERR_CODES evel_initialize(const char * const fqdn, const char * const topic, int ring_buf_size, int secure, - int activmode, const char * const cert_file_path, const char * const key_file_path, const char * const ca_info, @@ -308,7 +306,6 @@ EVEL_ERR_CODES evel_initialize(const char * const fqdn, bakup_source_ip, ring_buf_size, secure, - activmode, cert_file_path, key_file_path, ca_info, diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h index c8587269..d62911de 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h @@ -1435,7 +1435,6 @@ typedef struct copyright { * @param topic The optional topic part of the URL (may be NULL). * @param ring_buf_size Ring buffer size (>=100) ~ Avg Messages in 1hr * @param secure Whether to use HTTPS (0=HTTP, 1=HTTPS). - * @param activmode Whether to use ActiveActive or ActiveStandby collector mode * @param cert_file_path Path to client certificate file * @param key_file_path Path to client key file * @param ca_info Path to CA info @@ -1465,7 +1464,6 @@ EVEL_ERR_CODES evel_initialize(const char * const fqdn, const char * const topic, int ring_buf_size, int secure, - int activmode, const char * const cert_file_path, const char * const key_file_path, const char * const ca_info, diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c index 4fb195c1..347f0284 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c @@ -1,6 +1,6 @@ /*************************************************************************//** * - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * * Unless otherwise specified, all software contained herein is * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,7 +41,12 @@ * How long we're prepared to wait for the API service to respond in * seconds. *****************************************************************************/ -static const int EVEL_API_TIMEOUT = 10; +static const int EVEL_API_TIMEOUT = 5; + +/**************************************************************************//** + * Wait time if both the collectors are not responding + *****************************************************************************/ +static const int EVEL_COLLECTOR_RECONNECTION_WAIT_TIME = 120; /*****************************************************************************/ /* Prototypes of locally scoped functions. */ @@ -58,28 +63,23 @@ static bool evel_tokens_match_command_list(const MEMORY_CHUNK * const chunk, static bool evel_token_equals_string(const MEMORY_CHUNK * const chunk, const jsmntok_t * const json_token, const char * check_string); -static void * event_multi_handler(void * arg __attribute__ ((unused))); +static EVEL_ERR_CODES evel_setup_curl(); /**************************************************************************//** * Buffers for error strings from libcurl. *****************************************************************************/ static char curl_err_string[CURL_ERROR_SIZE] = "<NULL>"; -static char curl_err_string2[CURL_ERROR_SIZE] = "<NULL>"; /**************************************************************************//** * Handle for the API into libcurl. *****************************************************************************/ static CURL * curl_handle = NULL; -static CURL * curl_handle2 = NULL; -static CURLM * multi_handle = NULL; int curr_global_handles = 0; -int activmode = -1; /**************************************************************************//** * Special headers that we send. *****************************************************************************/ static struct curl_slist * hdr_chunk = NULL; -static struct curl_slist * hdr_chunk2 = NULL; /**************************************************************************//** * Message queue for sending events to the API. @@ -115,7 +115,28 @@ static char * evel_bevent_api_url; static char * evel_bthrot_api_url; static char * evel_bbatch_api_url; - +/**************************************************************************//** + * Storage for other CURL related parameters + *****************************************************************************/ +int evel_secure = -1; +int evel_verbosity = -1; + +long evel_verify_peer = 0; +long evel_verify_host = 0; + +static char * evel_source_ip = NULL; +static char * evel_source_ip_bakup = NULL; +static char * evel_cert_file_path = NULL; +static char * evel_key_file_path = NULL; +static char * evel_ca_info = NULL; +static char * evel_ca_file_path = NULL; +static char * evel_username = NULL; +static char * evel_password = NULL; +static char * evel_username2 = NULL; +static char * evel_password2 = NULL; + +static int http_response_code = 0; +static int evel_collector_id = 0; /**************************************************************************//** * Initialize the event handler. * @@ -147,7 +168,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, const char * const source_ip_bakup, int ring_buf_size, int secure, - int activitymode, const char * const cert_file_path, const char * const key_file_path, const char * const ca_info, @@ -161,9 +181,7 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, int verbosity) { int rc = EVEL_SUCCESS; - CURLcode curl_rc = CURLE_OK; char batch_api_url[EVEL_MAX_URL_LEN + 1] = {0}; - char local_address[64]; EVEL_ENTER(); @@ -180,7 +198,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, assert(password2 != NULL); } - /***************************************************************************/ /* Store the API URLs. */ /***************************************************************************/ @@ -191,13 +208,14 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, assert(evel_batch_api_url != NULL); evel_throt_api_url = strdup(throt_api_url); assert(evel_throt_api_url != NULL); + curr_global_handles = 1; if( bakup_api_url != NULL ) { evel_bevent_api_url = strdup(bakup_api_url); assert(evel_bevent_api_url != NULL); - sprintf(batch_api_url,"%s/eventBatch",event_api_url); + sprintf(batch_api_url,"%s/eventBatch",bakup_api_url); evel_bbatch_api_url = strdup(batch_api_url); assert(evel_bbatch_api_url != NULL); evel_bthrot_api_url = strdup(throt_api_url); @@ -205,6 +223,84 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, curr_global_handles = 2; } + /***************************************************************************/ + /* Store other parameters + /***************************************************************************/ + evel_secure = secure; + evel_verbosity = verbosity; + + evel_verify_peer = verify_peer; + evel_verify_host = verify_host; + + evel_source_ip = NULL; + if (source_ip != NULL) + { + evel_source_ip = strdup(source_ip); + assert(evel_source_ip != NULL); + } + + evel_source_ip_bakup = NULL; + if (source_ip_bakup != NULL) + { + evel_source_ip_bakup = strdup(source_ip_bakup); + assert(evel_source_ip_bakup != NULL); + } + + evel_cert_file_path = NULL; + if (cert_file_path != NULL) + { + evel_cert_file_path = strdup(cert_file_path); + assert(evel_cert_file_path != NULL); + } + + evel_key_file_path = NULL; + if (key_file_path != NULL) + { + evel_key_file_path = strdup(key_file_path); + assert(evel_key_file_path != NULL); + } + + evel_ca_info = NULL; + if (ca_info != NULL) + { + evel_ca_info = strdup(ca_info); + assert(evel_ca_info != NULL); + } + + evel_ca_file_path = NULL; + if (ca_file_path != NULL) + { + evel_ca_file_path = strdup(ca_file_path); + assert(evel_ca_file_path != NULL); + } + + evel_username = NULL; + if (username != NULL) + { + evel_username = strdup(username); + assert(evel_username != NULL); + } + + evel_password = NULL; + if (password != NULL) + { + evel_password = strdup(password); + assert(evel_password != NULL); + } + + evel_username2 = NULL; + if (username2 != NULL) + { + evel_username2 = strdup(username2); + assert(evel_username2 != NULL); + } + + evel_password2 = NULL; + if (password2 != NULL) + { + evel_password2 = strdup(password2); + assert(evel_password2 != NULL); + } curl_version_info_data *d = curl_version_info(CURLVERSION_NOW); /* compare with the 24 bit hex number in 8 bit fields */ @@ -215,6 +311,98 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, else { EVEL_INFO("Old Curl version."); } + + /***************************************************************************/ + /* Initialize a message ring-buffer to be used between the foreground and */ + /* the thread which sends the messages. This can't fail. */ + /***************************************************************************/ + if( ring_buf_size < EVEL_EVENT_BUFFER_DEPTH ) + { + log_error_state("Warning: Failed to initialize Ring buffer size to %d. ", + ring_buf_size); + goto exit_label; + } + ring_buffer_initialize(&event_buffer, EVEL_EVENT_BUFFER_DEPTH); + +exit_label: + + EVEL_EXIT(); + + return rc; + +} +/**************************************************************************//** + * Setup the curl connection to collector + * + * Primarily responsible for getting CURL ready to send message. Also it would + * be used to swithch over to other collector + *****************************************************************************/ +static EVEL_ERR_CODES evel_setup_curl() +{ + int rc = EVEL_SUCCESS; + CURLcode curl_rc = CURLE_OK; + char local_address[64]; + char * api_url = NULL; + char * username = NULL; + char * password = NULL; + char * source_ip = NULL; + + EVEL_ENTER(); + + if (evel_collector_id > 4) + { + rc = EVEL_CURL_LIBRARY_FAIL; + log_error_state("Wrong evel_collector- value > 4"); + goto exit_label; + } + + /***************************************************************************/ + /* Initialize the local variable with proper global variables that are */ + /* required to setup the connection */ + /***************************************************************************/ + if (evel_collector_id == 1) + { + api_url = evel_event_api_url; + source_ip = evel_source_ip; + username = evel_username; + password = evel_password; + } + else if (evel_collector_id == 2) + { + api_url = evel_bevent_api_url; + source_ip = evel_source_ip_bakup; + username = evel_username2; + password = evel_password2; + } + else if (evel_collector_id == 3) + { + api_url = evel_batch_api_url; + source_ip = evel_source_ip; + username = evel_username; + password = evel_password; + } + else if (evel_collector_id == 4) + { + api_url = evel_bbatch_api_url; + source_ip = evel_source_ip_bakup; + username = evel_username2; + password = evel_password2; + } + + /***************************************************************************/ + /* Clean-up the cURL library. */ + /***************************************************************************/ + if (curl_handle != NULL) + { + curl_easy_cleanup(curl_handle); + curl_handle = NULL; + } + if (hdr_chunk != NULL) + { + curl_slist_free_all(hdr_chunk); + hdr_chunk = NULL; + } + /***************************************************************************/ /* Start the CURL library. Note that this initialization is not threadsafe */ /* which imposes a constraint that the EVEL library is initialized before */ @@ -239,16 +427,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_handle2 = curl_easy_init(); - if (curl_handle2 == NULL) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to get backup libCURL handle"); - goto exit_label; - } - } /***************************************************************************/ /* Prime the library to give friendly error codes. */ /***************************************************************************/ @@ -263,25 +441,10 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_ERRORBUFFER, - curl_err_string2); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL2 to provide friendly errors. " - "Error code=%d", curl_rc); - goto exit_label; - } - } - - /***************************************************************************/ /* If running in verbose mode generate more output. */ /***************************************************************************/ - if (verbosity > 0) + if (evel_verbosity > 0) { curl_rc = curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); if (curl_rc != CURLE_OK) @@ -291,26 +454,12 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d", curl_rc); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, CURLOPT_VERBOSE, 1L); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL to be verbose. " - "Error code=%d", curl_rc); - goto exit_label; - } - } - } - - /***************************************************************************/ /* Set the URL for the API. */ /***************************************************************************/ - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, event_api_url); + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, api_url); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -318,22 +467,7 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - EVEL_INFO("Initializing CURL to send events to: %s", event_api_url); - - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_URL, - bakup_api_url); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - + EVEL_INFO("Initializing CURL to send events to: %s", api_url); /***************************************************************************/ /* send all data to this function. */ @@ -348,21 +482,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_WRITEFUNCTION, - evel_write_callback); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - - /***************************************************************************/ /* configure local ip address if provided */ @@ -385,46 +504,17 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, } } } - if( source_ip_bakup != NULL ) - { - snprintf(local_address,sizeof(local_address),source_ip_bakup); - if( local_address[0] != '\0' ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_INTERFACE, - local_address); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize bakup libCURL with the local address. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - } /***************************************************************************/ /* configure SSL options for HTTPS transfers */ /***************************************************************************/ - if( secure ) + if( evel_secure ) { - if( cert_file_path != NULL ) + if( evel_cert_file_path != NULL ) { curl_rc = curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, - cert_file_path); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the client cert. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_SSLCERT, - cert_file_path); + evel_cert_file_path); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -432,14 +522,13 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - } } - if( key_file_path != NULL ) + if( evel_key_file_path != NULL ) { curl_rc = curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, - key_file_path); + evel_key_file_path); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -447,38 +536,13 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_SSLKEY, - key_file_path); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the client key. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - } } - if( ca_info != NULL ) + if( evel_ca_info != NULL ) { curl_rc = curl_easy_setopt(curl_handle, CURLOPT_CAINFO, - ca_info); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the CA cert file. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_CAINFO, - ca_info); + evel_ca_info); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -486,14 +550,13 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - } } - if( ca_file_path != NULL ) + if( evel_ca_file_path != NULL ) { curl_rc = curl_easy_setopt(curl_handle, CURLOPT_CAPATH, - ca_file_path); + evel_ca_file_path); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -501,24 +564,11 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_CAPATH, - ca_file_path); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the CA cert path. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - } } curl_rc = curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, - verify_peer); + evel_verify_peer); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -528,7 +578,7 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, } curl_rc = curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, - verify_host); + evel_verify_host); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -537,29 +587,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_SSL_VERIFYPEER, - verify_peer); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with SSL Server verification. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_SSL_VERIFYHOST, - verify_host); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with Client host verification. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - } } @@ -578,20 +605,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, - CURLOPT_USERAGENT, - "libcurl-agent/1.0"); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - /***************************************************************************/ /* Specify that we are going to POST data. */ @@ -604,18 +617,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2,CURLOPT_POST, 1L); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - /***************************************************************************/ /* we want to use our own read function. */ @@ -628,18 +629,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "function. Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2,CURLOPT_READFUNCTION, read_callback); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - /***************************************************************************/ /* All of our events are JSON encoded. We also suppress the */ @@ -662,21 +651,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - hdr_chunk2 = curl_slist_append(hdr_chunk2, "Content-type: application/json"); - hdr_chunk2 = curl_slist_append(hdr_chunk2, "Expect:"); - curl_rc = curl_easy_setopt(curl_handle2,CURLOPT_HTTPHEADER, hdr_chunk2); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - - /***************************************************************************/ /* Set the timeout for the operation. */ @@ -691,18 +665,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, "Error code=%d (%s)", curl_rc, curl_err_string); goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2,CURLOPT_TIMEOUT, EVEL_API_TIMEOUT); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - } - /***************************************************************************/ /* Set that we want Basic authentication with username:password Base-64 */ @@ -733,57 +695,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, goto exit_label; } - if( bakup_api_url != NULL ) - { - curl_rc = curl_easy_setopt(curl_handle2, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL for Basic Authentication. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - curl_rc = curl_easy_setopt(curl_handle2, CURLOPT_USERNAME, username2); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with username. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - curl_rc = curl_easy_setopt(curl_handle2, CURLOPT_PASSWORD, password2); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with password. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - - multi_handle = curl_multi_init();; - if (multi_handle == NULL) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to get libCURL Multi handle"); - goto exit_label; - } - activmode = activitymode; - - } - - - /***************************************************************************/ - /* Initialize a message ring-buffer to be used between the foreground and */ - /* the thread which sends the messages. This can't fail. */ - /***************************************************************************/ - if( ring_buf_size < EVEL_EVENT_BUFFER_DEPTH ) - { - log_error_state("Warning: Failed to initialize Ring buffer size to %d. ", - ring_buf_size); - goto exit_label; - } - ring_buffer_initialize(&event_buffer, EVEL_EVENT_BUFFER_DEPTH); - /***************************************************************************/ /* Initialize the priority post buffer to empty. */ /***************************************************************************/ @@ -816,11 +727,7 @@ EVEL_ERR_CODES event_handler_run() /* Start the event handler thread. */ /***************************************************************************/ evt_handler_state = EVT_HANDLER_INACTIVE; - if( curr_global_handles <= 1 ) - pthread_rc = pthread_create(&evt_handler_thread, NULL, event_handler, NULL); - else - pthread_rc = pthread_create(&evt_handler_thread, NULL, event_multi_handler, NULL); - + pthread_rc = pthread_create(&evt_handler_thread, NULL, event_handler, NULL); if (pthread_rc != 0) { rc = EVEL_PTHREAD_LIBRARY_FAIL; @@ -893,31 +800,16 @@ EVEL_ERR_CODES event_handler_terminate() /***************************************************************************/ /* Clean-up the cURL library. */ /***************************************************************************/ - if (multi_handle != NULL) - { - curl_multi_cleanup(multi_handle); - } if (curl_handle != NULL) { curl_easy_cleanup(curl_handle); curl_handle = NULL; } - if (curl_handle2 != NULL) - { - curl_easy_cleanup(curl_handle2); - curl_handle2 = NULL; - } if (hdr_chunk != NULL) { curl_slist_free_all(hdr_chunk); hdr_chunk = NULL; } - if (hdr_chunk2 != NULL) - { - curl_slist_free_all(hdr_chunk2); - hdr_chunk2 = NULL; - } - /***************************************************************************/ /* Free off the stored API URL strings. */ @@ -1009,7 +901,6 @@ static EVEL_ERR_CODES evel_post_api(char * msg, size_t size) CURLcode curl_rc = CURLE_OK; MEMORY_CHUNK rx_chunk; MEMORY_CHUNK tx_chunk; - int http_response_code = 0; EVEL_ENTER(); @@ -1072,6 +963,8 @@ static EVEL_ERR_CODES evel_post_api(char * msg, size_t size) /***************************************************************************/ /* Now run off and do what you've been told! */ /***************************************************************************/ + http_response_code = 0; + curl_rc = curl_easy_perform(curl_handle); if (curl_rc != CURLE_OK) { @@ -1201,312 +1094,6 @@ size_t evel_write_callback(void *contents, return realsize; } - -/**************************************************************************//** - * Post an event to the Vendor Event Listener API. - * - * @returns Status code - * @retval EVEL_SUCCESS On success - * @retval "One of ::EVEL_ERR_CODES" On failure. - *****************************************************************************/ -static EVEL_ERR_CODES evel_postmulti_message(char *msg, size_t size, int *still, - CURL *handle, CURL *bhandle, int numhandles ) -{ - int rc = EVEL_SUCCESS; - CURLcode curl_rc = CURLE_OK; - MEMORY_CHUNK rx_chunk[2]; - MEMORY_CHUNK tx_chunk[2]; - int http_response_code = 0, i; - - EVEL_ENTER(); - - EVEL_INFO("Sending :%s: %d\n",msg, numhandles); - - /***************************************************************************/ - /* Create the memory chunk to be used for the response to the post. The */ - /* will be realloced. */ - /***************************************************************************/ -for (i=0;i<numhandles;i++) -{ - rx_chunk[i].memory = malloc(1); - assert(rx_chunk[i].memory != NULL); - rx_chunk[i].size = 0; - - /***************************************************************************/ - /* Create the memory chunk to be sent as the body of the post. */ - /***************************************************************************/ - tx_chunk[i].memory = msg; - tx_chunk[i].size = size; - EVEL_DEBUG("Sending chunk of size %d", tx_chunk[i].size); -} - - /***************************************************************************/ - /* Point to the data to be received. */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(handle, CURLOPT_WRITEDATA, &rx_chunk[0]); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL rx to upload. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - - /***************************************************************************/ - /* Pointer to pass to our read function */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(handle, CURLOPT_READDATA, &tx_chunk[0]); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to set upload data for libCURL tx to upload. " - "Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - /***************************************************************************/ - /* Size of the data to transmit. */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(handle, - CURLOPT_POSTFIELDSIZE, - tx_chunk[0].size); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to set length of upload data for libCURL to " - "upload. Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - -if(numhandles == 2) -{ - - /***************************************************************************/ - /* Point to the data to be received. */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(bhandle, CURLOPT_WRITEDATA, &rx_chunk[1]); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL2 rx to upload. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - - /***************************************************************************/ - /* Pointer to pass to our read function */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(bhandle, CURLOPT_READDATA, &tx_chunk[1]); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to set upload data for libCURL2 tx to upload. " - "Error code=%d (%s)", curl_rc, curl_err_string2); - goto exit_label; - } - /***************************************************************************/ - /* Size of the data to transmit. */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(bhandle, - CURLOPT_POSTFIELDSIZE, - tx_chunk[1].size); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to set length of upload data for libCURL2 to " - "upload. Error code=%d (%s)", curl_rc, curl_err_string); - goto exit_label; - } - -} - - /***************************************************************************/ - /* Now run off and do what you've been told! */ - /***************************************************************************/ - curl_rc = curl_multi_perform(multi_handle, still); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to transfer an multi event to Vendor Event Listener! " - "Error code=%d (%s)", curl_rc, curl_multi_strerror(curl_rc -)); - EVEL_ERROR("Dropped event: %s", msg); - goto exit_label; - } - - /***************************************************************************/ - /* See what response we got - any 2XX response is good. */ - /***************************************************************************/ - -exit_label: - for (i=0;i<numhandles;i++) - free(rx_chunk[i].memory); - EVEL_EXIT(); - - return(rc); -} - - -/**************************************************************************//** - * Event Multi Post Handler. - * - * Watch for messages coming on the internal queue and send them to the - * listener. - * - * param[in] jsonmsg json message to be sent. - * param[in] size size of json message - * param[in] currhandle Primary handle - * param[in] url1 pimary url - * param[in] bakkhandle Backup handle - * param[in] url2 secondary url - *****************************************************************************/ -static int evel_post_multiapi(char *jsonmsg, size_t size,CURL *currhandle, char *url1, - CURL *bakkhandle, char *url2) -{ - int rc = EVEL_SUCCESS; - CURLcode curl_rc = 0; - int nhandles = 1; - int still_running,i; - CURLMsg *msg; /* for picking up messages with the transfer status */ - int msgs_left; /* how many messages are left */ - - /***************************************************************************/ - /* Set the URL for the API. */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(currhandle, CURLOPT_URL, url1); - if (curl_rc != CURLE_OK ) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the multi API URL. " - "%s Error code=%d (%s)", url1, curl_rc, curl_err_string); - } - - if( url2 != NULL && activmode == 1 ) - { - curl_rc = curl_easy_setopt(bakkhandle, CURLOPT_URL, url2); - if (curl_rc != CURLE_OK) - { - rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Failed to initialize libCURL with the API URL. " - "%s Error code=%d (%s)", url2, curl_rc, curl_err_string2); - } - nhandles = 2; - } - - /* we start some action by calling perform right away */ - curl_multi_add_handle(multi_handle, currhandle); - if(nhandles==2){ - curl_multi_add_handle(multi_handle, bakkhandle); - } - - /* we start some action by calling perform right away */ - curl_multi_perform(multi_handle, &still_running); - - do { - struct timeval timeout; - int rc; /* select() return code */ - CURLMcode mc; /* curl_multi_fdset() return code */ - - fd_set fdread; - fd_set fdwrite; - fd_set fdexcep; - int maxfd = -1; - - long curl_timeo = -1; - - FD_ZERO(&fdread); - FD_ZERO(&fdwrite); - FD_ZERO(&fdexcep); - - /* set a suitable timeout to play around with */ - timeout.tv_sec = 1; - timeout.tv_usec = 0; - - curl_multi_timeout(multi_handle, &curl_timeo); - if(curl_timeo >= 0) { - timeout.tv_sec = curl_timeo / 1000; - if(timeout.tv_sec > 1) - timeout.tv_sec = 1; - else - timeout.tv_usec = (curl_timeo % 1000) * 1000; - } - - /* get file descriptors from the transfers */ - mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - - if(mc != CURLM_OK) { - EVEL_ERROR("curl_multi_fdset() failed, code %d.\n", mc); - break; - } - - /* On success the value of maxfd is guaranteed to be >= -1. We call - select(maxfd + 1, ...); specially in case of (maxfd == -1) there are - no fds ready yet so we call select(0, ...) --or Sleep() on Windows-- - to sleep 100ms, which is the minimum suggested value in the - curl_multi_fdset() doc. */ - - if(maxfd == -1) { -#ifdef _WIN32 - Sleep(100); - rc = 0; -#else - /* Portable sleep for platforms other than Windows. */ - struct timeval wait = { 0, 300000 }; /* 250ms */ - rc = select(0, NULL, NULL, NULL, &wait); -#endif - } - else { - /* Note that on some platforms 'timeout' may be modified by select(). - If you need access to the original value save a copy beforehand. */ - rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); - } - - switch(rc) { - case -1: - /* select error */ - break; - case 0: /* timeout */ - default: /* action */ - //curl_multi_perform(multi_handle, &still_running); - evel_postmulti_message(jsonmsg, size, &still_running, currhandle, bakkhandle, nhandles); - } - } while(still_running); - - /* See how the transfers went */ - while((msg = curl_multi_info_read(multi_handle, &msgs_left))) { - if(msg->msg == CURLMSG_DONE) { - int idx, found = 0; - EVEL_DEBUG("Transfer status - %s\n", curl_multi_strerror(msg->data.result)); - - /* Find out which handle this message is about */ - for(idx = 0; idx<nhandles; idx++) { - if (msg->easy_handle == currhandle) break; - else if(msg->easy_handle == bakkhandle) break; - } - - switch(idx) { - case 0: - curl_rc = msg->data.result; - break; - case 1: - curl_rc = msg->data.result; - break; - } - } - } - - /* we start some action by calling perform right away */ - curl_multi_remove_handle(multi_handle, currhandle); - if(nhandles==2){ - curl_multi_remove_handle(multi_handle, bakkhandle); - } - - EVEL_DEBUG("Transfer completed with status %s\n", curl_multi_strerror(curl_rc)); - if( curl_rc == 0 || curl_rc == 55 ) - return EVEL_SUCCESS; - else - return EVEL_CURL_LIBRARY_FAIL; - -} /**************************************************************************//** * Event Handler. * @@ -1515,7 +1102,7 @@ static int evel_post_multiapi(char *jsonmsg, size_t size,CURL *currhandle, char * * param[in] arg Argument - unused. *****************************************************************************/ -static void * event_multi_handler(void * arg __attribute__ ((unused))) +static void * event_handler(void * arg __attribute__ ((unused))) { int old_type = 0; EVENT_HEADER * msg = NULL; @@ -1524,12 +1111,10 @@ static void * event_multi_handler(void * arg __attribute__ ((unused))) char json_body[EVEL_MAX_JSON_BODY]; int rc = EVEL_SUCCESS; CURLcode curl_rc; - CURL *currhandler = NULL; - CURL *bakhandler = NULL; - char *send_url = NULL; - char *send_url2 = NULL; + int collector_down_count = 0; + int switch_coll = 0; - EVEL_INFO("Event multi handler thread started"); + EVEL_INFO("Event handler thread started"); /***************************************************************************/ /* Set this thread to be cancellable immediately. */ @@ -1551,12 +1136,12 @@ static void * event_multi_handler(void * arg __attribute__ ((unused))) "Handler will exit immediately!"); } - currhandler = curl_handle; while (evt_handler_state == EVT_HANDLER_ACTIVE) { /*************************************************************************/ /* Wait for a message to be received. */ /*************************************************************************/ + EVEL_DEBUG("Event handler getting any messages"); msg = ring_buffer_read(&event_buffer); /*************************************************************************/ @@ -1573,231 +1158,62 @@ static void * event_multi_handler(void * arg __attribute__ ((unused))) json_size = evel_json_encode_batch_event(json_body, EVEL_MAX_JSON_BODY, msg); /***************************************************************************/ - /* Set the URL for the API. */ + /* Set the connection to collector */ /***************************************************************************/ - if( currhandler == curl_handle){ - send_url = evel_batch_api_url; - send_url2 = evel_bbatch_api_url; - bakhandler = curl_handle2; - } else if(currhandler == curl_handle2) { - send_url = evel_bbatch_api_url; - send_url2 = evel_batch_api_url; - bakhandler = curl_handle; - } - - /***********************************************************************/ - /* Send the JSON across the API. */ - /***********************************************************************/ - EVEL_DEBUG("Sending Batch JSON of size %d is: %s", json_size, json_body); - rc = evel_post_multiapi(json_body, json_size, currhandler, send_url, bakhandler, send_url2); - if (rc != EVEL_SUCCESS) + while (true) { - EVEL_ERROR("Failed to transfer the data to %s. Error code=%d", send_url, rc); - EVEL_INFO("Switched Collector ..."); - if( currhandler == curl_handle){ - currhandler = curl_handle2; - bakhandler = curl_handle; - } else if(currhandler == curl_handle2) { - currhandler = curl_handle; - bakhandler = curl_handle2; - } - rc = evel_post_multiapi(json_body, json_size, currhandler, send_url2, bakhandler,send_url); - if (rc != EVEL_SUCCESS) - EVEL_ERROR("Failed to transfer the data to failover %s. Error code=%d", send_url2, rc); + evel_collector_id =3; + rc = evel_setup_curl(); + + if ( rc != EVEL_SUCCESS) + { + EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc); + if (curr_global_handles == 2) + { + EVEL_DEBUG("Switching to other collector"); + + evel_collector_id = 4; + + rc = evel_setup_curl(); + if ( rc != EVEL_SUCCESS) + { + EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc); + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count); + } + else + { + break; + collector_down_count = 0; + } + } + else + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + } + } + else + { + break; + collector_down_count = 0; + } } - } - else if (msg->event_domain != EVEL_DOMAIN_INTERNAL ) - { - EVEL_DEBUG("External event received"); - - /***********************************************************************/ - /* Encode the event in JSON. */ - /***********************************************************************/ - json_size = evel_json_encode_event(json_body, EVEL_MAX_JSON_BODY, msg); /***************************************************************************/ /* Set the URL for the API. */ /***************************************************************************/ - if( currhandler == curl_handle){ - send_url = evel_event_api_url; - send_url2 = evel_bevent_api_url; - bakhandler = curl_handle2; - } else if(currhandler == curl_handle2) { - send_url = evel_bevent_api_url; - send_url2 = evel_event_api_url; - bakhandler = curl_handle; - } - - /***********************************************************************/ - /* Send the JSON across the API. */ - /***********************************************************************/ - EVEL_DEBUG("Sending Batch JSON of size %d is: %s", json_size, json_body); - rc = evel_post_multiapi(json_body, json_size, currhandler, send_url, bakhandler, send_url2); - if (rc != EVEL_SUCCESS) - { - EVEL_ERROR("Failed to transfer the data to %s. Error code=%d", send_url, rc); - EVEL_INFO("Switched Collector ..."); - if( currhandler == curl_handle){ - currhandler = curl_handle2; - bakhandler = curl_handle; - } else if(currhandler == curl_handle2) { - currhandler = curl_handle; - bakhandler = curl_handle2; - } - rc = evel_post_multiapi(json_body, json_size, currhandler, send_url2, bakhandler,send_url); - if (rc != EVEL_SUCCESS) - EVEL_ERROR("Failed to transfer the data to failover %s. Error code=%d", send_url2, rc); - } - - } - else - { - EVEL_DEBUG("Internal event received"); - internal_msg = (EVENT_INTERNAL *) msg; - assert(internal_msg->command == EVT_CMD_TERMINATE); - evt_handler_state = EVT_HANDLER_TERMINATING; - } - - /*************************************************************************/ - /* We are responsible for freeing the memory. */ - /*************************************************************************/ - evel_free_event(msg); - msg = NULL; - - /*************************************************************************/ - /* There may be a single priority post to be sent. */ - /*************************************************************************/ - if (priority_post.memory != NULL) - { - EVEL_DEBUG("Priority Post"); - - /***********************************************************************/ - /* Set the URL for the throttling API. */ - /***********************************************************************/ - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_throt_api_url); - if (curl_rc != CURLE_OK) + if (evel_collector_id == 3) { - /*********************************************************************/ - /* This is only likely to happen with CURLE_OUT_OF_MEMORY, in which */ - /* case we carry on regardless. */ - /*********************************************************************/ - EVEL_ERROR("Failed to set throttling URL. Error code=%d", rc); + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url); } else { - rc = evel_post_api(priority_post.memory, priority_post.size); - if (rc != EVEL_SUCCESS) - { - EVEL_ERROR("Failed to transfer priority post. Error code=%d", rc); - } + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bbatch_api_url); } - /***********************************************************************/ - /* Reinstate the URL for the event API. */ - /***********************************************************************/ - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url); - if (curl_rc != CURLE_OK) - { - /*********************************************************************/ - /* This is only likely to happen with CURLE_OUT_OF_MEMORY, in which */ - /* case we carry on regardless. */ - /*********************************************************************/ - EVEL_ERROR("Failed to reinstate events URL. Error code=%d", rc); - } - - /***********************************************************************/ - /* We are responsible for freeing the memory. */ - /***********************************************************************/ - free(priority_post.memory); - priority_post.memory = NULL; - } - } - - /***************************************************************************/ - /* The event handler is now exiting. The ring-buffer could contain events */ - /* which have not been processed, so deplete those. Because we've been */ - /* asked to exit we can be confident that the foreground will have stopped */ - /* sending events in so we know that this process will conclude! */ - /***************************************************************************/ - evt_handler_state = EVT_HANDLER_TERMINATING; - while (!ring_buffer_is_empty(&event_buffer)) - { - EVEL_DEBUG("Reading event from buffer"); - msg = ring_buffer_read(&event_buffer); - evel_free_event(msg); - } - evt_handler_state = EVT_HANDLER_TERMINATED; - EVEL_INFO("Event handler thread stopped"); - - return (NULL); -} - - -/**************************************************************************//** - * Event Handler. - * - * Watch for messages coming on the internal queue and send them to the - * listener. - * - * param[in] arg Argument - unused. - *****************************************************************************/ -static void * event_handler(void * arg __attribute__ ((unused))) -{ - int old_type = 0; - EVENT_HEADER * msg = NULL; - EVENT_INTERNAL * internal_msg = NULL; - int json_size = 0; - char json_body[EVEL_MAX_JSON_BODY]; - int rc = EVEL_SUCCESS; - CURLcode curl_rc; - - EVEL_INFO("Event handler thread started"); - - /***************************************************************************/ - /* Set this thread to be cancellable immediately. */ - /***************************************************************************/ - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_type); - - /***************************************************************************/ - /* Set the handler as active, defending against weird situations like */ - /* immediately shutting down after initializing the library so the */ - /* handler never gets started up properly. */ - /***************************************************************************/ - if (evt_handler_state == EVT_HANDLER_INACTIVE) - { - evt_handler_state = EVT_HANDLER_ACTIVE; - } - else - { - EVEL_ERROR("Event Handler State was not INACTIVE at start-up - " - "Handler will exit immediately!"); - } - - while (evt_handler_state == EVT_HANDLER_ACTIVE) - { - /*************************************************************************/ - /* Wait for a message to be received. */ - /*************************************************************************/ - EVEL_DEBUG("Event handler getting any messages"); - msg = ring_buffer_read(&event_buffer); - - /*************************************************************************/ - /* Internal events get special treatment while regular events get posted */ - /* to the far side. */ - /*************************************************************************/ - if (msg->event_domain == EVEL_DOMAIN_BATCH ) - { - EVEL_DEBUG("Batch event received"); - - /***********************************************************************/ - /* Encode the event in JSON. */ - /***********************************************************************/ - json_size = evel_json_encode_batch_event(json_body, EVEL_MAX_JSON_BODY, msg); - - /***************************************************************************/ - /* Set the URL for the API. */ - /***************************************************************************/ - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url); if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -1810,9 +1226,64 @@ static void * event_handler(void * arg __attribute__ ((unused))) /***********************************************************************/ EVEL_DEBUG("Sending Batch JSON of size %d is: %s", json_size, json_body); rc = evel_post_api(json_body, json_size); - if (rc != EVEL_SUCCESS) + + switch_coll = 0; + if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2)) { - EVEL_ERROR("Failed to transfer the data %s. Error code=%d", evel_batch_api_url, rc); + switch_coll = 1; + if (http_response_code == 400) // 400 - Bad JSON related return code + switch_coll = 0; + } + + if ((rc != EVEL_SUCCESS) || (switch_coll == 1)) + { + EVEL_ERROR("Failed to transfer the data. Error code=%d", rc); + EVEL_DEBUG("Switching to other collector if any"); + + while (true) + { + if ((evel_collector_id == 3) && (curr_global_handles == 2)) + { + evel_collector_id =4; + } + else if (evel_collector_id == 4) + { + evel_collector_id =3; + } + + rc = evel_setup_curl(); + + if ( rc != EVEL_SUCCESS) + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + continue; + } + + if (evel_collector_id == 3) + { + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url); + } + else if (evel_collector_id == 4) + { + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bbatch_api_url); + } + + rc = evel_post_api(json_body, json_size); + if ( rc != EVEL_SUCCESS) + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + continue; + } + else + { + EVEL_DEBUG("Successfully sent msg after retry=%d", collector_down_count); + break; + } + } } } else if (msg->event_domain != EVEL_DOMAIN_INTERNAL ) @@ -1825,9 +1296,57 @@ static void * event_handler(void * arg __attribute__ ((unused))) json_size = evel_json_encode_event(json_body, EVEL_MAX_JSON_BODY, msg); /***************************************************************************/ + /* Set the connection to collector */ + /***************************************************************************/ + while (true) + { + evel_collector_id = 1; + rc = evel_setup_curl(); + + if ( rc != EVEL_SUCCESS) + { + EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc); + if (curr_global_handles == 2) + { + EVEL_DEBUG("Switching to other collector"); + + evel_collector_id = 2; + + rc = evel_setup_curl(); + if ( rc != EVEL_SUCCESS) + { + EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc); + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count); + } + else + { + break; + collector_down_count = 0; + } + } + else + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + } + } + else + { + break; + collector_down_count = 0; + } + } + /***************************************************************************/ /* Set the URL for the API. */ /***************************************************************************/ - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url); + if (evel_collector_id == 1) + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url); + else + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url); + if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -1840,9 +1359,64 @@ static void * event_handler(void * arg __attribute__ ((unused))) /***********************************************************************/ EVEL_DEBUG("Sending JSON of size %d is: %s", json_size, json_body); rc = evel_post_api(json_body, json_size); - if (rc != EVEL_SUCCESS) + + switch_coll = 0; + if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2)) + { + switch_coll = 1; + if (http_response_code == 400) // 400 - Bad JSON related return code + switch_coll = 0; + } + + if ((rc != EVEL_SUCCESS) || (switch_coll == 1)) { - EVEL_ERROR("Failed to transfer the data %s. Error code=%d",evel_event_api_url, rc); + EVEL_ERROR("Failed to transfer the data. Error code=%d", rc); + EVEL_DEBUG("Switching to other collector if any"); + + while (true) + { + if ((evel_collector_id == 1) && (curr_global_handles == 2)) + { + evel_collector_id =2; + } + else if (evel_collector_id == 2) + { + evel_collector_id =1; + } + + rc = evel_setup_curl(); + + if ( rc != EVEL_SUCCESS) + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + continue; + } + + if (evel_collector_id == 1) + { + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url); + } + else if (evel_collector_id == 2) + { + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url); + } + + rc = evel_post_api(json_body, json_size); + if ( rc != EVEL_SUCCESS) + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + continue; + } + else + { + EVEL_DEBUG("Successfully sent msg after retry=%d", collector_down_count); + break; + } + } } } else @@ -1974,11 +1548,11 @@ void evel_handle_event_response(const MEMORY_CHUNK * const chunk, } else { - //EVEL_DEBUG("Decode JSON response tokens"); - //if (!evel_handle_response_tokens(chunk, json_tokens, num_tokens, post)) - //{ - // EVEL_ERROR("Failed to handle JSON response."); - //} + EVEL_DEBUG("Decode JSON response tokens"); + if (!evel_handle_response_tokens(chunk, json_tokens, num_tokens, post)) + { + EVEL_ERROR("Failed to handle JSON response."); + } } EVEL_EXIT(); @@ -1998,7 +1572,7 @@ bool evel_handle_response_tokens(const MEMORY_CHUNK * const chunk, const int num_tokens, MEMORY_CHUNK * const post) { - bool json_ok = false; + bool json_ok = true; EVEL_ENTER(); diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_internal.h b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_internal.h index 621f8a53..14d224d4 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_internal.h +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_internal.h @@ -201,7 +201,6 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, const char * const bakup_source_ip, int ring_buf_size, int secure, - int activitymode, const char * const cert_file_path, const char * const key_file_path, const char * const ca_info, diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/readme.md b/vnfs/VES5.0/evel/evel-library/code/evel_library/readme.md index 3cf57083..2033cfc9 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/readme.md +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/readme.md @@ -76,17 +76,30 @@ The following fragment illustrates the above usage: ```C - if (evel_initialize(api_fqdn, - api_port, - api_path, - api_topic, - api_secure, - "Alice", - "This isn't very secure!", - EVEL_SOURCE_VIRTUAL_MACHINE, - "EVEL demo client", - verbose_mode)) - { +EVEL_ERR_CODES evel_initialize(const char * const fqdn, + int port, + const char * const bakup_fqdn, + int bakup_port, + const char * const path, + const char * const topic, + int ring_buf_size, + int secure, + const char * const cert_file_path, + const char * const key_file_path, + const char * const ca_info, + const char * const ca_file_path, + long verify_peer, + long verify_host, + const char * const username, + const char * const password, + const char * const bakup_username, + const char * const bakup_password, + const char * const source_ip, + const char * const bakup_source_ip, + EVEL_SOURCE_TYPES source_type, + const char * const role, + int verbosity + ) { fprintf(stderr, "Failed to initialize the EVEL library!!!"); exit(-1); } diff --git a/vnfs/VESreporting_vFW5.0/go-client.sh b/vnfs/VESreporting_vFW5.0/go-client.sh index 116f8905..3b4b49d3 100755 --- a/vnfs/VESreporting_vFW5.0/go-client.sh +++ b/vnfs/VESreporting_vFW5.0/go-client.sh @@ -4,3 +4,4 @@ export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) ./vpp_measurement_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT eth1 +#./vpp_measurement_reporter 127.0.0.1 30000 127.0.0.1 31000 eth1 diff --git a/vnfs/VESreporting_vFW5.0/vpp_measurement_reporter.c b/vnfs/VESreporting_vFW5.0/vpp_measurement_reporter.c index 6f6a7c04..7cf0414d 100644 --- a/vnfs/VESreporting_vFW5.0/vpp_measurement_reporter.c +++ b/vnfs/VESreporting_vFW5.0/vpp_measurement_reporter.c @@ -171,17 +171,30 @@ int main(int argc, char** argv) char* fqdn = argv[1]; int port = atoi(argv[2]); char* vnic = argv[3]; + char* fqdn2 = NULL; + int port2 = 0; + MEASUREMENT_VNIC_PERFORMANCE * vnic_performance = NULL; //struct timeval tv_start; + if(argc == 6) + { + fqdn2 = argv[3]; + port2 = atoi(argv[4]); + vnic = argv[5]; + } + printf("\nVector Packet Processing (VPP) measurement collection\n"); fflush(stdout); - if (argc != 4) + if (!((argc == 6) || (argc == 4))) { - fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <interface>\n", argv[0]); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> <interface> \n", argv[0]); + fprintf(stderr, "OR\n"); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <interface> \n", argv[0]); exit(-1); } + srand(time(NULL)); /**************************************************************************/ @@ -189,23 +202,22 @@ int main(int argc, char** argv) /**************************************************************************/ if(evel_initialize(fqdn, /* FQDN */ port, /* Port */ - "", /* Backup FQDN */ - 5555, /* Backup Port */ + fqdn2, /* Backup FQDN */ + port2, /* Backup port */ NULL, /* optional path */ NULL, /* optional topic */ 100, /* Ring Buffer size */ 0, /* HTTPS? */ - 0, /* Active mode */ NULL, /* cert file */ NULL, /* key file */ NULL, /* ca info */ NULL, /* ca file */ 0, /* verify peer */ 0, /* verify host */ - "", /* Username */ - "", /* Password */ - "", /* Backup Username */ - "", /* Backup Password */ + "sample1", /* Username */ + "sample1", /* Password */ + "sample1", /* Username2 */ + "sample1", /* Password2 */ NULL, /* Source ip */ NULL, /* Backup Source IP */ EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ diff --git a/vnfs/VESreporting_vLB5.0/go-client.sh b/vnfs/VESreporting_vLB5.0/go-client.sh index 116f8905..623c86ec 100755 --- a/vnfs/VESreporting_vLB5.0/go-client.sh +++ b/vnfs/VESreporting_vLB5.0/go-client.sh @@ -4,3 +4,5 @@ export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) ./vpp_measurement_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT eth1 + + diff --git a/vnfs/VESreporting_vLB5.0/vpp_measurement_reporter.c b/vnfs/VESreporting_vLB5.0/vpp_measurement_reporter.c index 7e83d1e8..78050498 100644 --- a/vnfs/VESreporting_vLB5.0/vpp_measurement_reporter.c +++ b/vnfs/VESreporting_vLB5.0/vpp_measurement_reporter.c @@ -120,16 +120,29 @@ int main(int argc, char** argv) char* fqdn = argv[1]; int port = atoi(argv[2]); char* vnic = argv[3]; + char* fqdn2 = NULL; + int port2 = 0; + + if(argc == 6) + { + fqdn2 = argv[3]; + port2 = atoi(argv[4]); + vnic = argv[5]; + } + MEASUREMENT_VNIC_PERFORMANCE * vnic_performance = NULL; printf("\nVector Packet Processing (VPP) measurement collection\n"); fflush(stdout); - if (argc != 4) + if (!((argc == 6) || (argc == 4))) { - fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <interface>\n", argv[0]); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> <interface> \n", argv[0]); + fprintf(stderr, "OR\n"); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <interface> \n", argv[0]); exit(-1); } + srand(time(NULL)); /**************************************************************************/ @@ -137,23 +150,22 @@ int main(int argc, char** argv) /**************************************************************************/ if(evel_initialize(fqdn, /* FQDN */ port, /* Port */ - "", /* Backup FQDN */ - 5566, /* Backup Port */ + fqdn2, /* Backup FQDN */ + port2, /* Backup port */ NULL, /* optional path */ NULL, /* optional topic */ 100, /* Ring Buffer size */ 0, /* HTTPS? */ - 0, /* Active mode */ NULL, /* cert file */ NULL, /* key file */ NULL, /* ca info */ NULL, /* ca file */ 0, /* verify peer */ 0, /* verify host */ - "", /* Username */ - "", /* Password */ - "", /* Backup Username */ - "", /* Backup Password */ + "sample1", /* Username */ + "sample1", /* Password */ + "sample1", /* Username2 */ + "sample1", /* Password2 */ NULL, /* Source ip */ NULL, /* Backup Source IP */ EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ |