aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-03-29 15:56:10 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2019-04-01 11:44:53 +0200
commitf6e6432ed03ff76868efe57396036d3124881069 (patch)
treef69013eeb924ce7350de2ceab9b6ae03b1e4f80e
parentfb1f28adcf1cf90606ac31425e9370edfa9e70c2 (diff)
Git submodule migration to separated libraries
- Replace controller binder functions definition with the binder ones. and remove the last used submodules to use the separated libraries. Bug-AGL: SPEC-2139 Change-Id: I0e354757dec692c13b49f02226fcf891953667f5 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--.gitmodules6
-rw-r--r--conf.d/cmake/config.cmake3
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/harvester-binding.c42
-rw-r--r--src/plugins/CMakeLists.txt6
-rw-r--r--src/plugins/influxdb-reader.c38
-rw-r--r--src/plugins/influxdb-writer.c30
-rw-r--r--src/plugins/influxdb.c12
-rw-r--r--src/plugins/influxdb.h2
9 files changed, 62 insertions, 83 deletions
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 42af9ad..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,6 +0,0 @@
-[submodule "afb-helpers"]
- path = afb-helpers
- url = https://gerrit.automotivelinux.org/gerrit/p/apps/app-afb-helpers-submodule.git
-[submodule "app-controller-submodule"]
- path = app-controller-submodule
- url = https://gerrit.automotivelinux.org/gerrit/apps/app-controller-submodule
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
index 0cead88..7e97cdd 100644
--- a/conf.d/cmake/config.cmake
+++ b/conf.d/cmake/config.cmake
@@ -72,7 +72,8 @@ set (PKG_REQUIRED_LIST
json-c
libsystemd>=222
afb-daemon
- libmicrohttpd>=0.9.55
+ afb-helpers
+ appcontroller
libcurl
)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a016c14..6ad1233 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -35,10 +35,4 @@ PROJECT_TARGET_ADD(harvester)
OUTPUT_NAME ${TARGET_NAME}
)
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- afb-helpers
- ctl-utilities
- ${link_libraries})
-
add_subdirectory("plugins")
diff --git a/src/harvester-binding.c b/src/harvester-binding.c
index 36610b1..afa672e 100644
--- a/src/harvester-binding.c
+++ b/src/harvester-binding.c
@@ -20,11 +20,10 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include <afb/afb-binding.h>
-#include "harvester-binding.h"
-// default api to print log when apihandle not avaliable
-afb_dynapi *AFB_default;
+#include "harvester-binding.h"
// Config Section definition (note: controls section index should match handle
// retrieval in HalConfigExec)
@@ -36,30 +35,30 @@ static CtlSectionT ctrlSections[] = {
{.key = NULL}
};
-static void ctrlapi_ping(AFB_ReqT request) {
+static void ctrlapi_ping(afb_req_t request) {
static int count = 0;
count++;
- AFB_ReqNotice(request, "Controller:ping count=%d", count);
- AFB_ReqSuccess(request, json_object_new_int(count), NULL);
+ AFB_REQ_NOTICE(request, "Controller:ping count=%d", count);
+ afb_req_success(request, json_object_new_int(count), NULL);
return;
}
-static void ctrlapi_auth(AFB_ReqT request)
+static void ctrlapi_auth(afb_req_t request)
{
- AFB_ReqSetLOA(request, 1);
- AFB_ReqSuccess(request, NULL, NULL);
+ afb_req_session_set_LOA(request, 1);
+ afb_req_success(request, NULL, NULL);
}
-static AFB_ApiVerbs CtrlApiVerbs[] = {
+static afb_verb_t CtrlApiVerbs[] = {
/* VERB'S NAME FUNCTION TO CALL SHORT DESCRIPTION */
{.verb = "ping", .callback = ctrlapi_ping, .info = "ping test for API"},
{.verb = "auth", .callback = ctrlapi_auth, .info = "Authenticate session to raise Level Of Assurance of the session"},
{.verb = NULL} /* marker for end of the array */
};
-static int CtrlLoadStaticVerbs(afb_dynapi *apiHandle, AFB_ApiVerbs *verbs) {
+static int CtrlLoadStaticVerbs(afb_dynapi *apiHandle, afb_verb_t *verbs) {
int errcount = 0;
for (int idx = 0; verbs[idx].verb; idx++) {
@@ -71,15 +70,14 @@ static int CtrlLoadStaticVerbs(afb_dynapi *apiHandle, AFB_ApiVerbs *verbs) {
return errcount;
};
-static int CtrlInitOneApi(AFB_ApiT apiHandle) {
+static int CtrlInitOneApi(afb_api_t apiHandle) {
int err = 0;
- AFB_default = apiHandle; // hugely hack to make all V2 AFB_DEBUG to work in fileutils
// retrieve section config from api handle
CtlConfigT *ctrlConfig = (CtlConfigT *)afb_dynapi_get_userdata(apiHandle);
err = CtlConfigExec(apiHandle, ctrlConfig);
if(err) {
- AFB_ApiError(apiHandle, "Error at CtlConfigExec step");
+ AFB_API_ERROR(apiHandle, "Error at CtlConfigExec step");
return err;
}
@@ -89,7 +87,7 @@ static int CtrlInitOneApi(AFB_ApiT apiHandle) {
// next generation dynamic API-V3 mode
#include <signal.h>
-static int CtrlLoadOneApi(void *cbdata, AFB_ApiT apiHandle) {
+static int CtrlLoadOneApi(void *cbdata, afb_api_t apiHandle) {
CtlConfigT *ctrlConfig = (CtlConfigT *)cbdata;
// save closure as api's data context
@@ -98,7 +96,7 @@ static int CtrlLoadOneApi(void *cbdata, AFB_ApiT apiHandle) {
// add static controls verbs
int err = CtrlLoadStaticVerbs(apiHandle, CtrlApiVerbs);
if (err) {
- AFB_ApiError(apiHandle, "CtrlLoadSection fail to register static V2 verbs");
+ AFB_API_ERROR(apiHandle, "CtrlLoadSection fail to register static V2 verbs");
return ERROR;
}
@@ -116,9 +114,7 @@ static int CtrlLoadOneApi(void *cbdata, AFB_ApiT apiHandle) {
}
int afbBindingEntry(afb_dynapi *apiHandle) {
-
- AFB_default = apiHandle;
- AFB_ApiNotice(apiHandle, "Controller in afbBindingVdyn");
+ AFB_API_NOTICE(apiHandle, "Controller in afbBindingVdyn");
const char *dirList = getenv("CONTROL_CONFIG_PATH");
if (!dirList)
@@ -126,27 +122,27 @@ int afbBindingEntry(afb_dynapi *apiHandle) {
const char *configPath = CtlConfigSearch(apiHandle, dirList, "");
if (!configPath) {
- AFB_ApiError(apiHandle, "CtlPreInit: No %s* config found in %s ", GetBinderName(), dirList);
+ AFB_API_ERROR(apiHandle, "CtlPreInit: No %s* config found in %s ", GetBinderName(), dirList);
return ERROR;
}
// load config file and create API
CtlConfigT *ctrlConfig = CtlLoadMetaData(apiHandle, configPath);
if (!ctrlConfig) {
- AFB_ApiError(apiHandle,
+ AFB_API_ERROR(apiHandle,
"CtrlBindingDyn No valid control config file in:\n-- %s",
configPath);
return ERROR;
}
if (!ctrlConfig->api) {
- AFB_ApiError(apiHandle,
+ AFB_API_ERROR(apiHandle,
"CtrlBindingDyn API Missing from metadata in:\n-- %s",
configPath);
return ERROR;
}
- AFB_ApiNotice(apiHandle, "Controller API='%s' info='%s'", ctrlConfig->api,
+ AFB_API_NOTICE(apiHandle, "Controller API='%s' info='%s'", ctrlConfig->api,
ctrlConfig->info);
// create one API per config file (Pre-V3 return code ToBeChanged)
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index e366685..603e5a0 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -34,11 +34,5 @@ PROJECT_TARGET_ADD(influxdb)
OUTPUT_NAME ${TARGET_NAME}
)
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- afb-helpers
- ${link_libraries}
- )
-
target_include_directories(${TARGET_NAME}
PRIVATE "${CMAKE_SOURCE_DIR}/app-controller-submodule/ctl-lib")
diff --git a/src/plugins/influxdb-reader.c b/src/plugins/influxdb-reader.c
index 7b184dd..d7ddac7 100644
--- a/src/plugins/influxdb-reader.c
+++ b/src/plugins/influxdb-reader.c
@@ -29,7 +29,7 @@
struct metrics_list {
struct series_t serie;
json_object *metricsJ;
- AFB_ApiT api;
+ afb_api_t api;
};
static void fill_n_send_values(void *c, json_object *valuesJ)
@@ -45,7 +45,7 @@ static void fill_n_send_values(void *c, json_object *valuesJ)
else {
if(set_value(m_list->serie.serie_columns.tags, valuesJ, i)) {
if(set_value(m_list->serie.serie_columns.fields, valuesJ, j)) {
- AFB_ApiError(m_list->api, "No tags nor fields fits.");
+ AFB_API_ERROR(m_list->api, "No tags nor fields fits.");
}
j++;
}
@@ -86,7 +86,7 @@ static void unpack_metric_from_db(void *ml, json_object *metricJ)
"name", &m_list->serie.name,
"columns", &columnsJ,
"values", &valuesJ)) {
- AFB_ApiError(m_list->api, "Unpacking metric goes wrong");
+ AFB_API_ERROR(m_list->api, "Unpacking metric goes wrong");
return;
}
@@ -94,7 +94,7 @@ static void unpack_metric_from_db(void *ml, json_object *metricJ)
wrap_json_array_for_all(valuesJ, fill_n_send_values, m_list);
}
-static json_object *unpack_series(AFB_ApiT apiHandle, json_object *seriesJ)
+static json_object *unpack_series(afb_api_t apiHandle, json_object *seriesJ)
{
struct metrics_list m_list = {
.serie = {
@@ -114,7 +114,7 @@ static json_object *unpack_series(AFB_ApiT apiHandle, json_object *seriesJ)
return m_list.metricsJ;
}
-static void forward_to_garner(AFB_ApiT apiHandle, const char *result, size_t size)
+static void forward_to_garner(afb_api_t apiHandle, const char *result, size_t size)
{
int id = 0;
json_object *resultsJ = NULL,
@@ -135,13 +135,13 @@ static void forward_to_garner(AFB_ApiT apiHandle, const char *result, size_t siz
if(seriesJ) {
metrics2send = unpack_series(apiHandle, seriesJ);
if(json_object_array_length(metrics2send)) {
- if(AFB_ServiceSync(apiHandle, "garner", "write", metrics2send, &call_resultJ)) {
- AFB_ApiError(apiHandle, "Metrics were sent but not done, an error happens. Details: %s", json_object_to_json_string(call_resultJ));
+ if(afb_api_call_sync_legacy(apiHandle, "garner", "write", metrics2send, &call_resultJ)) {
+ AFB_API_ERROR(apiHandle, "Metrics were sent but not done, an error happens. Details: %s", json_object_to_json_string(call_resultJ));
}
}
}
else {
- AFB_ApiError(apiHandle, "Empty response. Request results was:\n%s", result);
+ AFB_API_ERROR(apiHandle, "Empty response. Request results was:\n%s", result);
}
}
@@ -149,26 +149,26 @@ static void influxdb_read_curl_cb(void *closure, int status, CURL *curl, const c
{
if(!closure)
return;
- AFB_ApiT apiHandle = (AFB_ApiT)closure;
+ afb_api_t apiHandle = (afb_api_t)closure;
long rep_code = curl_wrap_response_code_get(curl);
switch(rep_code) {
case 200:
- AFB_ApiDebug(apiHandle, "Read correctly done");
+ AFB_API_DEBUG(apiHandle, "Read correctly done");
forward_to_garner(apiHandle, result, size);
break;
case 400:
- AFB_ApiError(apiHandle, "Unacceptable request. %s", result);
+ AFB_API_ERROR(apiHandle, "Unacceptable request. %s", result);
break;
case 401:
- AFB_ApiError(apiHandle, "Invalid authentication. %s", result);
+ AFB_API_ERROR(apiHandle, "Invalid authentication. %s", result);
break;
default:
- AFB_ApiError(apiHandle, "Unexptected behavior. %s", result);
+ AFB_API_ERROR(apiHandle, "Unexptected behavior. %s", result);
break;
}
}
-static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
+static CURL *make_curl_query_get(afb_api_t apiHandle, const char *url)
{
CURL *curl;
char *args[5];
@@ -184,7 +184,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
args[4] = NULL;
length_now = asprintf(&now, "%lu", get_ts());
- int rootdir_fd = AFB_RootDirGetFD(apiHandle);
+ int rootdir_fd = afb_api_rootdir_get_fd(apiHandle);
int fd_last_read = openat(rootdir_fd, "last_db_read", O_CREAT | O_RDWR, S_IRWXU);
if (fd_last_read < 0)
return NULL;
@@ -193,7 +193,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
else write the last timestamp */
if(read(fd_last_read, last_ts, sizeof(last_ts)) == 0) {
if(write(fd_last_read, now, length_now) != length_now)
- AFB_ApiError(apiHandle, "Error writing last_db_read file: %s\n", strerror( errno ));
+ AFB_API_ERROR(apiHandle, "Error writing last_db_read file: %s\n", strerror( errno ));
}
else {
strcat(query, " WHERE time >= ");
@@ -201,7 +201,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
close(fd_last_read);
fd_last_read = openat(rootdir_fd, "last_db_read", O_TRUNC | O_RDWR);
if (write(fd_last_read, now, length_now) != length_now)
- AFB_ApiError(apiHandle, "Error writing last_db_read file: %s", strerror( errno ));
+ AFB_API_ERROR(apiHandle, "Error writing last_db_read file: %s", strerror( errno ));
}
args[3] = query;
@@ -245,8 +245,8 @@ CTLP_CAPI(read_from_influxdb, source, argsJ, eventJ)
struct sd_event_source *evtSource = NULL;
/* Set a cyclic cb call each 1s to call the read callback */
- sd_event_now(AFB_GetEventLoop(source->api), CLOCK_MONOTONIC, &usec);
- err = sd_event_add_time(AFB_GetEventLoop(source->api), &evtSource, CLOCK_MONOTONIC, usec+1000000, 250, influxdb_read, (void*)source);
+ sd_event_now(afb_api_get_event_loop(source->api), CLOCK_MONOTONIC, &usec);
+ err = sd_event_add_time(afb_api_get_event_loop(source->api), &evtSource, CLOCK_MONOTONIC, usec+1000000, 250, influxdb_read, (void*)source);
if(!err)
err = sd_event_source_set_enabled(evtSource, SD_EVENT_ON);
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index e02612d..9090a32 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -23,29 +23,29 @@
void influxdb_write_curl_cb(void *closure, int status, CURL *curl, const char *result, size_t size)
{
- AFB_ReqT request = (AFB_ReqT)closure;
+ afb_req_t request = (afb_req_t)closure;
long rep_code = curl_wrap_response_code_get(curl);
switch(rep_code) {
case 204:
- AFB_ReqDebug(request, "Request correctly written");
- AFB_ReqSuccess(request, NULL, "Request has been successfully writen");
+ AFB_REQ_DEBUG(request, "Request correctly written");
+ afb_req_success(request, NULL, "Request has been successfully writen");
break;
case 400:
- AFB_ReqFail(request, "Bad request", result);
+ afb_req_fail(request, "Bad request", result);
break;
case 401:
- AFB_ReqFail(request, "Unauthorized access", result);
+ afb_req_fail(request, "Unauthorized access", result);
break;
case 404:
- AFB_ReqFail(request, "Not found", result);
- AFB_ReqNotice(request, "Attempt to create the DB '"DEFAULT_DB"'");
+ afb_req_fail(request, "Not found", result);
+ AFB_REQ_NOTICE(request, "Attempt to create the DB '"DEFAULT_DB"'");
create_database(request);
break;
case 500:
- AFB_ReqFailF(request, "Timeout", "Overloaded server: %s", result);
+ afb_req_fail_f(request, "Timeout", "Overloaded server: %s", result);
break;
default:
- AFB_ReqFail(request, "Failure", "Unexpected behavior.");
+ afb_req_fail(request, "Failure", "Unexpected behavior.");
break;
}
}
@@ -88,7 +88,7 @@ static size_t format_write_args(char *query, struct series_t *serie)
return strlen(query);
}
-CURL *make_curl_write_post(AFB_ApiT apiHandle, const char *url, json_object *metricsJ)
+CURL *make_curl_write_post(afb_api_t apiHandle, const char *url, json_object *metricsJ)
{
CURL *curl = NULL;
size_t lpd = 0, len_write = 0, i = 0;
@@ -114,7 +114,7 @@ CURL *make_curl_write_post(AFB_ApiT apiHandle, const char *url, json_object *met
memset(serie, 0, sizeof(struct series_t));
if(unpack_metric_from_api(json_object_array_get_idx(metricsArrayJ, i), serie)) {
- AFB_ApiError(apiHandle, "ERROR unpacking metric. %s", json_object_to_json_string(metricsArrayJ));
+ AFB_API_ERROR(apiHandle, "ERROR unpacking metric. %s", json_object_to_json_string(metricsArrayJ));
break;
}
else {
@@ -144,7 +144,7 @@ CURL *make_curl_write_post(AFB_ApiT apiHandle, const char *url, json_object *met
return curl;
}
-CURL *influxdb_write(AFB_ApiT apiHandle, const char* host, const char *port, json_object *metricJ)
+CURL *influxdb_write(afb_api_t apiHandle, const char* host, const char *port, json_object *metricJ)
{
char url[URL_MAXIMUM_LENGTH]; /* Safe limit for most popular web browser */
make_url(url, sizeof(url), host, port, "write");
@@ -153,12 +153,12 @@ CURL *influxdb_write(AFB_ApiT apiHandle, const char* host, const char *port, jso
CTLP_CAPI(write_to_influxdb, source, argsJ, eventJ)
{
- AFB_ReqT request = source->request;
+ afb_req_t request = source->request;
const char *port = NULL;
const char *host = NULL;
CURL *curl_request;
- json_object *req_args = AFB_ReqJson(request),
+ json_object *req_args = afb_req_json(request),
*portJ = NULL,
*metric = NULL;
@@ -166,7 +166,7 @@ CTLP_CAPI(write_to_influxdb, source, argsJ, eventJ)
"host", &host,
"port", &portJ,
"metric", &metric) || ! metric)
- AFB_ReqFail(request, "Failed", "Error processing arguments. Miss metric\
+ afb_req_fail(request, "Failed", "Error processing arguments. Miss metric\
JSON object or malformed");
else
port = json_object_is_type(portJ, json_type_null) ?
diff --git a/src/plugins/influxdb.c b/src/plugins/influxdb.c
index 92f1f89..2cfd551 100644
--- a/src/plugins/influxdb.c
+++ b/src/plugins/influxdb.c
@@ -40,7 +40,7 @@ CTLP_ONLOAD(plugin, ret)
curl_wrap_perform(request, &result, &result_size);
if (curl_wrap_response_code_get(request) != 204) {
- AFB_ApiError(plugin->api, "InfluxDB not reachable, please start it");
+ AFB_API_ERROR(plugin->api, "InfluxDB not reachable, please start it");
err = ERROR;
}
@@ -59,10 +59,10 @@ CTLP_CAPI(influxdb_ping, source, argsJ, eventJ)
curl_wrap_perform(curl_req, &result, &result_size);
if (curl_wrap_response_code_get(curl_req) != 204) {
- AFB_ApiError(source->api, "InfluxDB is offline.");
+ AFB_API_ERROR(source->api, "InfluxDB is offline.");
ret = ERROR;
} else {
- AFB_ApiNotice(source->api, "InfluxDB is up and running.");
+ AFB_API_NOTICE(source->api, "InfluxDB is up and running.");
}
curl_easy_cleanup(curl_req);
@@ -88,7 +88,7 @@ size_t make_url(char* url, size_t l_url, const char* host, const char* port, con
return strlen(url);
}
-int create_database(AFB_ReqT request)
+int create_database(afb_req_t request)
{
int ret = 0;
char* result;
@@ -103,14 +103,14 @@ int create_database(AFB_ReqT request)
curl_wrap_perform(curl_req, &result, &result_size);
if (curl_wrap_response_code_get(request) != 200) {
- AFB_ReqError(request, "Can't create database.");
+ AFB_REQ_ERROR(request, "Can't create database.");
ret = ERROR;
}
curl_easy_cleanup(curl_req);
if (ret == 0)
- AFB_ReqNotice(request, "Database '" DEFAULT_DB "' created");
+ AFB_REQ_NOTICE(request, "Database '" DEFAULT_DB "' created");
return ret;
}
diff --git a/src/plugins/influxdb.h b/src/plugins/influxdb.h
index cd7b222..3c60e27 100644
--- a/src/plugins/influxdb.h
+++ b/src/plugins/influxdb.h
@@ -38,7 +38,7 @@ struct series_t {
uint64_t timestamp;
};
-int create_database(AFB_ReqT request);
+int create_database(afb_req_t request);
int unpack_metric_from_api(json_object* m, struct series_t* serie);