Merge branch 'develop' into monitor_refactoring
This commit is contained in:
@ -37,7 +37,7 @@ This feature is not enabled by default: MaxScale must be configured in [feedback
|
|||||||
|
|
||||||
[feedback]
|
[feedback]
|
||||||
feedback_enable=1
|
feedback_enable=1
|
||||||
feedback_url=https://mariadb.org/feedback_plugin/post
|
feedback_url=https://enterprise.mariadb.com/feedback/post
|
||||||
feedback_user_info=x-y-z-w
|
feedback_user_info=x-y-z-w
|
||||||
|
|
||||||
The activation code that will be provided by MariaDB corp upon request by the customer and it shlud be put in feedback_user_info.
|
The activation code that will be provided by MariaDB corp upon request by the customer and it shlud be put in feedback_user_info.
|
||||||
|
|||||||
@ -1338,6 +1338,10 @@ int i;
|
|||||||
{
|
{
|
||||||
feedback.feedback_connect_timeout = atoi(value);
|
feedback.feedback_connect_timeout = atoi(value);
|
||||||
}
|
}
|
||||||
|
if (strcmp(name, "feedback_frequency") == 0)
|
||||||
|
{
|
||||||
|
feedback.feedback_frequency = atoi(value);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1389,6 +1393,7 @@ feedback_defaults()
|
|||||||
feedback.feedback_timeout = _NOTIFICATION_OPERATION_TIMEOUT;
|
feedback.feedback_timeout = _NOTIFICATION_OPERATION_TIMEOUT;
|
||||||
feedback.feedback_connect_timeout = _NOTIFICATION_CONNECT_TIMEOUT;
|
feedback.feedback_connect_timeout = _NOTIFICATION_CONNECT_TIMEOUT;
|
||||||
feedback.feedback_url = NULL;
|
feedback.feedback_url = NULL;
|
||||||
|
feedback.feedback_frequency = 1800;
|
||||||
feedback.release_info = gateway.release_string;
|
feedback.release_info = gateway.release_string;
|
||||||
feedback.sysname = gateway.sysname;
|
feedback.sysname = gateway.sysname;
|
||||||
feedback.mac_sha1 = gateway.mac_sha1;
|
feedback.mac_sha1 = gateway.mac_sha1;
|
||||||
@ -2138,7 +2143,7 @@ config_get_release_string(char* release)
|
|||||||
*end = 0;
|
*end = 0;
|
||||||
|
|
||||||
to = strcpy(distribution, "lsb: ");
|
to = strcpy(distribution, "lsb: ");
|
||||||
memmove(to, found, end - found + 1);
|
memmove(to, found, end - found + 1 < INT_MAX ? end - found + 1 : INT_MAX);
|
||||||
|
|
||||||
strncpy(release, to, _RELEASE_STR_LENGTH);
|
strncpy(release, to, _RELEASE_STR_LENGTH);
|
||||||
|
|
||||||
@ -2175,7 +2180,7 @@ config_get_release_string(char* release)
|
|||||||
+5 and -8 below cut the file name part out of the
|
+5 and -8 below cut the file name part out of the
|
||||||
full pathname that corresponds to the mask as above.
|
full pathname that corresponds to the mask as above.
|
||||||
*/
|
*/
|
||||||
new_to = strcpy(distribution, found.gl_pathv[0] + 5);
|
new_to = strncpy(distribution, found.gl_pathv[0] + 5,_RELEASE_STR_LENGTH - 1);
|
||||||
new_to += 8;
|
new_to += 8;
|
||||||
*new_to++ = ':';
|
*new_to++ = ':';
|
||||||
*new_to++ = ' ';
|
*new_to++ = ' ';
|
||||||
@ -2221,14 +2226,14 @@ config_enable_feedback_task(void) {
|
|||||||
|
|
||||||
if (enable_set && url_set && user_info_set) {
|
if (enable_set && url_set && user_info_set) {
|
||||||
/* Add the task to the tasl list */
|
/* Add the task to the tasl list */
|
||||||
if (hktask_add("send_feedback", module_feedback_send, cfg, 1800)) {
|
if (hktask_add("send_feedback", module_feedback_send, cfg, cfg->feedback_frequency)) {
|
||||||
|
|
||||||
LOGIF(LM, (skygw_log_write_flush(
|
LOGIF(LM, (skygw_log_write_flush(
|
||||||
LOGFILE_MESSAGE,
|
LOGFILE_MESSAGE,
|
||||||
"Notification service feedback task started: URL=%s, User-Info=%s, Frequency %u seconds",
|
"Notification service feedback task started: URL=%s, User-Info=%s, Frequency %u seconds",
|
||||||
cfg->feedback_url,
|
cfg->feedback_url,
|
||||||
cfg->feedback_user_info,
|
cfg->feedback_user_info,
|
||||||
1800)));
|
cfg->feedback_frequency)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (enable_set) {
|
if (enable_set) {
|
||||||
|
|||||||
@ -798,7 +798,7 @@ getUsers(SERVICE *service, USERS *users)
|
|||||||
if (db_grants) {
|
if (db_grants) {
|
||||||
/* we have dbgrants, store them */
|
/* we have dbgrants, store them */
|
||||||
if(row[5]){
|
if(row[5]){
|
||||||
strcpy(dbnm,row[5]);
|
strncpy(dbnm,row[5],MYSQL_DATABASE_MAXLEN);
|
||||||
if(service->strip_db_esc) {
|
if(service->strip_db_esc) {
|
||||||
strip_escape_chars(dbnm);
|
strip_escape_chars(dbnm);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,7 @@ static void register_module(const char *module,
|
|||||||
MODULE_INFO *info);
|
MODULE_INFO *info);
|
||||||
static void unregister_module(const char *module);
|
static void unregister_module(const char *module);
|
||||||
int module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *cfg);
|
int module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *cfg);
|
||||||
|
int do_http_post(GWBUF *buffer, void *cfg);
|
||||||
|
|
||||||
struct MemoryStruct {
|
struct MemoryStruct {
|
||||||
char *data;
|
char *data;
|
||||||
@ -568,13 +569,13 @@ module_feedback_send(void* data) {
|
|||||||
GWBUF *buffer = NULL;
|
GWBUF *buffer = NULL;
|
||||||
void *data_ptr=NULL;
|
void *data_ptr=NULL;
|
||||||
long http_code = 0;
|
long http_code = 0;
|
||||||
struct MemoryStruct chunk;
|
|
||||||
int last_action = _NOTIFICATION_SEND_PENDING;
|
int last_action = _NOTIFICATION_SEND_PENDING;
|
||||||
time_t now;
|
time_t now;
|
||||||
struct tm *now_tm;
|
struct tm *now_tm;
|
||||||
int hour;
|
int hour;
|
||||||
int n_mod=0;
|
int n_mod=0;
|
||||||
char hex_setup_info[2 * SHA_DIGEST_LENGTH + 1]="";
|
char hex_setup_info[2 * SHA_DIGEST_LENGTH + 1]="";
|
||||||
|
int http_send = 0;
|
||||||
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
now_tm = localtime(&now);
|
now_tm = localtime(&now);
|
||||||
@ -634,11 +635,6 @@ module_feedback_send(void* data) {
|
|||||||
"module_feedback_send(): task now runs: hour is [%d], last_action [%d]",
|
"module_feedback_send(): task now runs: hour is [%d], last_action [%d]",
|
||||||
hour, feedback_config->feedback_last_action)));
|
hour, feedback_config->feedback_last_action)));
|
||||||
|
|
||||||
|
|
||||||
/* allocate first memory chunck for httpd servr reply */
|
|
||||||
chunk.data = malloc(1); /* will be grown as needed by the realloc above */
|
|
||||||
chunk.size = 0; /* no data at this point */
|
|
||||||
|
|
||||||
if (!module_create_feedback_report(&buffer, modules_list, feedback_config)) {
|
if (!module_create_feedback_report(&buffer, modules_list, feedback_config)) {
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
LOGFILE_ERROR,
|
LOGFILE_ERROR,
|
||||||
@ -649,118 +645,27 @@ module_feedback_send(void* data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* try sending data via http/https post */
|
||||||
|
http_send = do_http_post(buffer, feedback_config);
|
||||||
|
|
||||||
/* Initializing curl library for data send via HTTP */
|
if (http_send == 0) {
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
feedback_config->feedback_last_action = _NOTIFICATION_SEND_OK;
|
||||||
|
|
||||||
curl = curl_easy_init();
|
|
||||||
|
|
||||||
if (curl) {
|
|
||||||
char error_message[CURL_ERROR_SIZE]="";
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_message);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, feedback_config->feedback_connect_timeout);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, feedback_config->feedback_timeout);
|
|
||||||
|
|
||||||
/* curl API call for data send via HTTP POST using a "file" type input */
|
|
||||||
curl_formadd(&formpost,
|
|
||||||
&lastptr,
|
|
||||||
CURLFORM_COPYNAME, "data",
|
|
||||||
CURLFORM_BUFFER, "report.txt",
|
|
||||||
CURLFORM_BUFFERPTR, (char *)GWBUF_DATA(buffer),
|
|
||||||
CURLFORM_BUFFERLENGTH, strlen((char *)GWBUF_DATA(buffer)),
|
|
||||||
CURLFORM_CONTENTTYPE, "text/plain",
|
|
||||||
CURLFORM_END);
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
|
|
||||||
|
|
||||||
/* some servers don't like requests that are made without a user-agent field, so we provide one */
|
|
||||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "MaxScale-agent/http-1.0");
|
|
||||||
/* Force HTTP/1.0 */
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, feedback_config->feedback_url);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
|
||||||
|
|
||||||
#ifdef SKIP_PEER_VERIFICATION
|
|
||||||
/*
|
|
||||||
* This makes the connection A LOT LESS SECURE.
|
|
||||||
*/
|
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SKIP_HOSTNAME_VERIFICATION
|
|
||||||
/*
|
|
||||||
* this will make the connection less secure.
|
|
||||||
*/
|
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* send all data to this function */
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
|
||||||
|
|
||||||
/* we pass our 'chunk' struct to the callback function */
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
|
|
||||||
|
|
||||||
/* Perform the request, res will get the return code */
|
|
||||||
res = curl_easy_perform(curl);
|
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if(res != CURLE_OK) {
|
|
||||||
last_action = _NOTIFICATION_SEND_ERROR;
|
|
||||||
|
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
|
||||||
LOGFILE_ERROR,
|
|
||||||
"Error: module_feedback_send(), curl call for [%s] failed due: %s, %s",
|
|
||||||
feedback_config->feedback_url,
|
|
||||||
curl_easy_strerror(res),
|
|
||||||
error_message)));
|
|
||||||
} else {
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (http_code == 302) {
|
|
||||||
char *from = strstr(chunk.data, "<h1>ok</h1>");
|
|
||||||
if (from) {
|
|
||||||
last_action = _NOTIFICATION_SEND_OK;
|
|
||||||
} else {
|
|
||||||
last_action = _NOTIFICATION_SEND_ERROR;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
last_action = _NOTIFICATION_SEND_ERROR;
|
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
|
||||||
LOGFILE_ERROR,
|
|
||||||
"Error in module_feedback_send(), Bad HTTP Code from remote server: %lu",
|
|
||||||
http_code)));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
feedback_config->feedback_last_action = _NOTIFICATION_SEND_ERROR;
|
||||||
LOGFILE_ERROR,
|
|
||||||
"Error in module_feedback_send(), curl object not initialized")));
|
|
||||||
last_action = _NOTIFICATION_SEND_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update last action in the config struct */
|
LOGIF(LT, (skygw_log_write_flush(
|
||||||
feedback_config->feedback_last_action = last_action;
|
LOGFILE_TRACE,
|
||||||
|
"Error in module_create_feedback_report(): do_http_post ret_code is %d", http_send)));
|
||||||
|
}
|
||||||
|
|
||||||
LOGIF(LT, (skygw_log_write_flush(
|
LOGIF(LT, (skygw_log_write_flush(
|
||||||
LOGFILE_TRACE,
|
LOGFILE_TRACE,
|
||||||
"module_feedback_send(): task run result: hour is [%d], last_action [%d], HTTP code [%d]",
|
"module_feedback_send(): task completed: hour is [%d], last_action [%d]",
|
||||||
hour, feedback_config->feedback_last_action, http_code)));
|
hour,
|
||||||
|
feedback_config->feedback_last_action)));
|
||||||
|
|
||||||
if (chunk.data)
|
gwbuf_free(buffer);
|
||||||
free(chunk.data);
|
|
||||||
|
|
||||||
if (buffer)
|
|
||||||
gwbuf_free(buffer);
|
|
||||||
|
|
||||||
if (curl) {
|
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
curl_formfree(formpost);
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_global_cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -785,6 +690,8 @@ module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *c
|
|||||||
time_t now;
|
time_t now;
|
||||||
struct tm *now_tm;
|
struct tm *now_tm;
|
||||||
int report_max_bytes=0;
|
int report_max_bytes=0;
|
||||||
|
if(buffer == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
|
|
||||||
@ -809,7 +716,7 @@ module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *c
|
|||||||
report_max_bytes = ((n_mod * 4) + 7) * (_NOTIFICATION_REPORT_ROW_LEN + 1);
|
report_max_bytes = ((n_mod * 4) + 7) * (_NOTIFICATION_REPORT_ROW_LEN + 1);
|
||||||
*buffer = gwbuf_alloc(report_max_bytes);
|
*buffer = gwbuf_alloc(report_max_bytes);
|
||||||
|
|
||||||
if (buffer == NULL) {
|
if (*buffer == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -865,3 +772,125 @@ module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *c
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send data to notification service via http/https
|
||||||
|
*
|
||||||
|
* @param buffer The GWBUF with data to send
|
||||||
|
* @param cfg The configuration details of notification service
|
||||||
|
* @return 0 on success, != 0 on failure
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
do_http_post(GWBUF *buffer, void *cfg) {
|
||||||
|
CURL *curl = NULL;
|
||||||
|
CURLcode res;
|
||||||
|
struct curl_httppost *formpost=NULL;
|
||||||
|
struct curl_httppost *lastptr=NULL;
|
||||||
|
long http_code = 0;
|
||||||
|
struct MemoryStruct chunk;
|
||||||
|
int ret_code = 1;
|
||||||
|
|
||||||
|
FEEDBACK_CONF *feedback_config = (FEEDBACK_CONF *) cfg;
|
||||||
|
|
||||||
|
/* allocate first memory chunck for httpd servr reply */
|
||||||
|
chunk.data = malloc(1); /* will be grown as needed by the realloc above */
|
||||||
|
chunk.size = 0; /* no data at this point */
|
||||||
|
|
||||||
|
/* Initializing curl library for data send via HTTP */
|
||||||
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
|
||||||
|
curl = curl_easy_init();
|
||||||
|
|
||||||
|
if (curl) {
|
||||||
|
char error_message[CURL_ERROR_SIZE]="";
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_message);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, feedback_config->feedback_connect_timeout);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, feedback_config->feedback_timeout);
|
||||||
|
|
||||||
|
/* curl API call for data send via HTTP POST using a "file" type input */
|
||||||
|
curl_formadd(&formpost,
|
||||||
|
&lastptr,
|
||||||
|
CURLFORM_COPYNAME, "data",
|
||||||
|
CURLFORM_BUFFER, "report.txt",
|
||||||
|
CURLFORM_BUFFERPTR, (char *)GWBUF_DATA(buffer),
|
||||||
|
CURLFORM_BUFFERLENGTH, strlen((char *)GWBUF_DATA(buffer)),
|
||||||
|
CURLFORM_CONTENTTYPE, "text/plain",
|
||||||
|
CURLFORM_END);
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
|
||||||
|
|
||||||
|
/* some servers don't like requests that are made without a user-agent field, so we provide one */
|
||||||
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "MaxScale-agent/http-1.0");
|
||||||
|
/* Force HTTP/1.0 */
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, feedback_config->feedback_url);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||||
|
|
||||||
|
/* send all data to this function */
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
||||||
|
|
||||||
|
/* we pass our 'chunk' struct to the callback function */
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
|
||||||
|
|
||||||
|
/* Perform the request, res will get the return code */
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
|
||||||
|
/* Check for errors */
|
||||||
|
if(res != CURLE_OK) {
|
||||||
|
ret_code = 2;
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error: do_http_post(), curl call for [%s] failed due: %s, %s",
|
||||||
|
feedback_config->feedback_url,
|
||||||
|
curl_easy_strerror(res),
|
||||||
|
error_message)));
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (http_code == 302) {
|
||||||
|
char *from = strstr(chunk.data, "<h1>ok</h1>");
|
||||||
|
if (from) {
|
||||||
|
ret_code = 0;
|
||||||
|
} else {
|
||||||
|
ret_code = 3;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error: do_http_post(), Bad HTTP Code from remote server: %lu",
|
||||||
|
http_code)));
|
||||||
|
ret_code = 4;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error: do_http_post(), curl object not initialized")));
|
||||||
|
ret_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGIF(LT, (skygw_log_write_flush(
|
||||||
|
LOGFILE_TRACE,
|
||||||
|
"do_http_post() ret_code [%d], HTTP code [%d]",
|
||||||
|
ret_code, http_code)));
|
||||||
|
cleanup:
|
||||||
|
|
||||||
|
if (chunk.data)
|
||||||
|
free(chunk.data);
|
||||||
|
|
||||||
|
if (curl) {
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
curl_formfree(formpost);
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_global_cleanup();
|
||||||
|
|
||||||
|
return ret_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,14 +21,16 @@
|
|||||||
* @verbatim
|
* @verbatim
|
||||||
* Revision History
|
* Revision History
|
||||||
*
|
*
|
||||||
* Date Who Description
|
* Date Who Description
|
||||||
* 09-03-2015 Markus Mäkelä Initial implementation
|
* 09-03-2015 Markus Mäkelä Initial implementation
|
||||||
|
* 10-03-2015 Massimiliano Pinto Added http_check
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FAILTEST(s) printf("TEST FAILED: " s "\n");return 1;
|
#define FAILTEST(s) printf("TEST FAILED: " s "\n");return 1;
|
||||||
|
#include <my_config.h>
|
||||||
|
#include <mysql.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <notification.h>
|
#include <notification.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -39,13 +41,36 @@
|
|||||||
#include <buffer.h>
|
#include <buffer.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
|
||||||
|
static char* server_options[] = {
|
||||||
|
"MariaDB Corporation MaxScale",
|
||||||
|
"--no-defaults",
|
||||||
|
"--datadir=",
|
||||||
|
"--language=",
|
||||||
|
"--skip-innodb",
|
||||||
|
"--default-storage-engine=myisam",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
|
||||||
|
|
||||||
|
static char* server_groups[] = {
|
||||||
|
"embedded",
|
||||||
|
"server",
|
||||||
|
"server",
|
||||||
|
"embedded",
|
||||||
|
"server",
|
||||||
|
"server",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
FEEDBACK_CONF* fc;
|
FEEDBACK_CONF* fc;
|
||||||
char* home;
|
|
||||||
char* cnf;
|
|
||||||
GWBUF* buf;
|
GWBUF* buf;
|
||||||
regex_t re;
|
regex_t re;
|
||||||
|
char* home;
|
||||||
|
char* cnf;
|
||||||
|
|
||||||
hkinit();
|
hkinit();
|
||||||
home = getenv("MAXSCALE_HOME");
|
home = getenv("MAXSCALE_HOME");
|
||||||
@ -62,23 +87,30 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
printf("Config: %s\n",cnf);
|
printf("Config: %s\n",cnf);
|
||||||
|
|
||||||
|
|
||||||
|
mysql_library_init(num_elements, server_options, server_groups);
|
||||||
|
|
||||||
config_load(cnf);
|
config_load(cnf);
|
||||||
|
|
||||||
if((fc = config_get_feedback_data()) == NULL ||
|
if ((fc = config_get_feedback_data()) == NULL)
|
||||||
fc->feedback_user_info == NULL)
|
|
||||||
{
|
{
|
||||||
FAILTEST("Configuration was NULL.");
|
FAILTEST("Configuration for Feedback was NULL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
regcomp(&re,fc->feedback_user_info,0);
|
regcomp(&re,fc->feedback_user_info,0);
|
||||||
|
|
||||||
module_create_feedback_report(&buf,NULL,fc);
|
module_create_feedback_report(&buf,NULL,fc);
|
||||||
printf("%s",(char*)buf->start);
|
|
||||||
|
|
||||||
if(regexec(&re,(char*)buf->start,0,NULL,0))
|
if(regexec(&re,(char*)buf->start,0,NULL,0))
|
||||||
{
|
{
|
||||||
FAILTEST("Regex match of 'user_info' failed.");
|
FAILTEST("Regex match of 'user_info' failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (do_http_post(buf, fc) != 0)
|
||||||
|
{
|
||||||
|
FAILTEST("Http send failed\n");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -31,11 +31,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <maxscale_test.h>
|
#include <maxscale_test.h>
|
||||||
|
#include <test_utils.h>
|
||||||
#include <service.h>
|
#include <service.h>
|
||||||
#include <poll.h>
|
|
||||||
#include <dcb.h>
|
|
||||||
|
|
||||||
#include "housekeeper.h"
|
|
||||||
|
|
||||||
static bool success = false;
|
static bool success = false;
|
||||||
|
|
||||||
@ -58,17 +56,18 @@ DCB *dcb;
|
|||||||
int result;
|
int result;
|
||||||
int argc = 3;
|
int argc = 3;
|
||||||
|
|
||||||
char* argv[] =
|
init_test_env();
|
||||||
{
|
/* char* argv[] = */
|
||||||
"log_manager",
|
/* { */
|
||||||
"-j",
|
/* "log_manager", */
|
||||||
TEST_LOG_DIR,
|
/* "-j", */
|
||||||
NULL
|
/* TEST_LOG_DIR, */
|
||||||
};
|
/* NULL */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
skygw_logmanager_init(argc,argv);
|
/* skygw_logmanager_init(argc,argv); */
|
||||||
poll_init();
|
/* poll_init(); */
|
||||||
hkinit();
|
/* hkinit(); */
|
||||||
|
|
||||||
/* Service tests */
|
/* Service tests */
|
||||||
ss_dfprintf(stderr,
|
ss_dfprintf(stderr,
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
* Copyright MariaDB Corporation Ab 2013-2014
|
* Copyright MariaDB Corporation Ab 2013-2014
|
||||||
*/
|
*/
|
||||||
#include <skygw_utils.h>
|
#include <skygw_utils.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
/**
|
/**
|
||||||
* @file config.h The configuration handling elements
|
* @file config.h The configuration handling elements
|
||||||
|
|||||||
@ -52,6 +52,7 @@ typedef struct {
|
|||||||
int feedback_timeout; /**< An attempt to write/read the data times out and fails after this many seconds */
|
int feedback_timeout; /**< An attempt to write/read the data times out and fails after this many seconds */
|
||||||
int feedback_connect_timeout; /**< An attempt to send the data times out and fails after this many seconds */
|
int feedback_connect_timeout; /**< An attempt to send the data times out and fails after this many seconds */
|
||||||
int feedback_last_action; /**< Holds the feedback last send action status */
|
int feedback_last_action; /**< Holds the feedback last send action status */
|
||||||
|
int feedback_frequency; /*< Frequency of the housekeeper task */
|
||||||
char *release_info; /**< Operating system Release name */
|
char *release_info; /**< Operating system Release name */
|
||||||
char *sysname; /**< Operating system name */
|
char *sysname; /**< Operating system name */
|
||||||
uint8_t *mac_sha1; /**< First available MAC address*/
|
uint8_t *mac_sha1; /**< First available MAC address*/
|
||||||
|
|||||||
26
server/include/test_utils.h
Normal file
26
server/include/test_utils.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef TEST_UTILS_H
|
||||||
|
#define TEST_UTILS_H
|
||||||
|
#include <poll.h>
|
||||||
|
#include <dcb.h>
|
||||||
|
#include <housekeeper.h>
|
||||||
|
#include <maxscale_test.h>
|
||||||
|
#include <log_manager.h>
|
||||||
|
|
||||||
|
void init_test_env()
|
||||||
|
{
|
||||||
|
int argc = 3;
|
||||||
|
|
||||||
|
char* argv[] =
|
||||||
|
{
|
||||||
|
"log_manager",
|
||||||
|
"-j",
|
||||||
|
TEST_LOG_DIR,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
skygw_logmanager_init(argc,argv);
|
||||||
|
poll_init();
|
||||||
|
hkinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -126,7 +126,7 @@ MAXINFO_TREE *col, *table;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a column list, may be a * or a valid list of string name
|
* Parse a column list, may be a * or a valid list of string name
|
||||||
* seperated by a comma
|
* separated by a comma
|
||||||
*
|
*
|
||||||
* @param sql Pointer to pointer to column list updated to point to the table name
|
* @param sql Pointer to pointer to column list updated to point to the table name
|
||||||
* @return A tree of column names
|
* @return A tree of column names
|
||||||
@ -148,9 +148,11 @@ MAXINFO_TREE * rval = NULL;
|
|||||||
case LT_COMMA:
|
case LT_COMMA:
|
||||||
rval = make_tree_node(MAXOP_COLUMNS, text, NULL,
|
rval = make_tree_node(MAXOP_COLUMNS, text, NULL,
|
||||||
parse_column_list(ptr));
|
parse_column_list(ptr));
|
||||||
|
break;
|
||||||
case LT_FROM:
|
case LT_FROM:
|
||||||
rval = make_tree_node(MAXOP_COLUMNS, text, NULL,
|
rval = make_tree_node(MAXOP_COLUMNS, text, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1632,7 +1632,7 @@ gen_show_dbs_response(ROUTER_INSTANCE* router, ROUTER_CLIENT_SES* client)
|
|||||||
rval = gwbuf_append(rval, last_packet);
|
rval = gwbuf_append(rval, last_packet);
|
||||||
|
|
||||||
rval = gwbuf_make_contiguous(rval);
|
rval = gwbuf_make_contiguous(rval);
|
||||||
|
hashtable_iterator_free(iter);
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2224,19 +2224,20 @@ static void clientReply (
|
|||||||
goto lock_failed;
|
goto lock_failed;
|
||||||
}
|
}
|
||||||
bref = get_bref_from_dcb(router_cli_ses, backend_dcb);
|
bref = get_bref_from_dcb(router_cli_ses, backend_dcb);
|
||||||
skygw_log_write(LOGFILE_DEBUG,"schemarouter: Received reply from %s for session %p",
|
|
||||||
bref->bref_backend->backend_server->unique_name,
|
|
||||||
router_cli_ses->rses_client_dcb->session);
|
|
||||||
#if !defined(FOR_BUG548_FIX_ONLY)
|
|
||||||
/** This makes the issue becoming visible in poll.c */
|
|
||||||
if (bref == NULL)
|
if (bref == NULL)
|
||||||
{
|
{
|
||||||
/** Unlock router session */
|
/** Unlock router session */
|
||||||
rses_end_locked_router_action(router_cli_ses);
|
rses_end_locked_router_action(router_cli_ses);
|
||||||
goto lock_failed;
|
goto lock_failed;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
skygw_log_write(LOGFILE_DEBUG,"schemarouter: Received reply from %s for session %p",
|
||||||
|
bref->bref_backend->backend_server->unique_name,
|
||||||
|
router_cli_ses->rses_client_dcb->session);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(router_cli_ses->init & INIT_MAPPING)
|
if(router_cli_ses->init & INIT_MAPPING)
|
||||||
{
|
{
|
||||||
bool mapped = true, logged = false;
|
bool mapped = true, logged = false;
|
||||||
@ -3905,7 +3906,7 @@ static bool handle_error_new_connection(
|
|||||||
|
|
||||||
skygw_log_write(LOGFILE_TRACE,"schemarouter: Re-mapping databases");
|
skygw_log_write(LOGFILE_TRACE,"schemarouter: Re-mapping databases");
|
||||||
gen_databaselist(rses->router,rses);
|
gen_databaselist(rses->router,rses);
|
||||||
|
hashtable_iterator_free(iter);
|
||||||
return_succp:
|
return_succp:
|
||||||
return succp;
|
return succp;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -274,7 +274,8 @@ char* get_lenenc_str(void* data, int* len)
|
|||||||
|
|
||||||
if(data == NULL || len == NULL)
|
if(data == NULL || len == NULL)
|
||||||
{
|
{
|
||||||
*len = -1;
|
if(len)
|
||||||
|
*len = -1;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1099,7 +1100,8 @@ return_rses:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
errorblock:
|
errorblock:
|
||||||
if(client_rses->subservice)
|
|
||||||
|
if(client_rses && client_rses->subservice)
|
||||||
{
|
{
|
||||||
for(j = 0; j < i; j++)
|
for(j = 0; j < i; j++)
|
||||||
{
|
{
|
||||||
@ -1661,14 +1663,7 @@ routeQuery(ROUTER* instance,
|
|||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
/** Something else went wrong, terminate connection */
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
goto retblock;
|
goto retblock;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2794,6 +2789,9 @@ get_shard_subsvc(SUBSERVICE** subsvc,ROUTER_CLIENT_SES* session,char* target)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if(subsvc == NULL || session == NULL || target == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
for(i = 0;i<session->n_subservice;i++)
|
for(i = 0;i<session->n_subservice;i++)
|
||||||
{
|
{
|
||||||
if(strcmp(session->subservice[i]->service->name,target) == 0)
|
if(strcmp(session->subservice[i]->service->name,target) == 0)
|
||||||
@ -2859,7 +2857,7 @@ router_handle_state_switch(
|
|||||||
CHK_DCB(dcb);
|
CHK_DCB(dcb);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
#if 0
|
||||||
if(SERVER_IS_RUNNING(srv) && SERVER_IS_IN_CLUSTER(srv))
|
if(SERVER_IS_RUNNING(srv) && SERVER_IS_IN_CLUSTER(srv))
|
||||||
{
|
{
|
||||||
goto return_rc;
|
goto return_rc;
|
||||||
@ -2882,6 +2880,7 @@ router_handle_state_switch(
|
|||||||
|
|
||||||
return_rc:
|
return_rc:
|
||||||
return rc;
|
return rc;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -78,7 +78,7 @@ int main(int argc, char** argv)
|
|||||||
goto report;
|
goto report;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(query,"STOP SLAVE",databases[i]);
|
sprintf(query,"STOP SLAVE");
|
||||||
if(mysql_real_query(server,query,strlen(query)))
|
if(mysql_real_query(server,query,strlen(query)))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to stop slave in %d: %s.\n",
|
fprintf(stderr, "Failed to stop slave in %d: %s.\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user