CELIX-278: deployment_admin: added capability to add tags, minor refactoring
Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/a8942991 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/a8942991 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/a8942991 Branch: refs/heads/feature/CELIX-269_depman Commit: a89429917439c93fdd8fb0ae2598b8842e472c9a Parents: 6c93851 Author: Bjoern Petri <bpe...@apache.org> Authored: Mon Oct 26 18:22:19 2015 +0100 Committer: Bjoern Petri <bpe...@apache.org> Committed: Mon Oct 26 18:22:19 2015 +0100 ---------------------------------------------------------------------- .../private/include/deployment_admin.h | 4 +- deployment_admin/private/src/deployment_admin.c | 110 ++++++++++++------- .../private/src/deployment_admin_activator.c | 2 +- .../private/src/deployment_package.c | 2 +- deployment_admin/private/src/log.c | 2 +- 5 files changed, 79 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/a8942991/deployment_admin/private/include/deployment_admin.h ---------------------------------------------------------------------- diff --git a/deployment_admin/private/include/deployment_admin.h b/deployment_admin/private/include/deployment_admin.h index f6244b2..a7e3a39 100644 --- a/deployment_admin/private/include/deployment_admin.h +++ b/deployment_admin/private/include/deployment_admin.h @@ -46,7 +46,9 @@ struct deployment_admin { }; typedef enum { - DEPLOYMENT_ADMIN_AUDIT_EVENT__FRAMEWORK_STARTED = 1005 + DEPLOYMENT_ADMIN_AUDIT_EVENT__FRAMEWORK_STARTED = 1005, + DEPLOYMENT_ADMIN_AUDIT_EVENT__TARGETPROPERTIES_SET = 4001 + } DEPLOYMENT_ADMIN_AUDIT_EVENT; celix_status_t deploymentAdmin_create(bundle_context_pt context, deployment_admin_pt *admin); http://git-wip-us.apache.org/repos/asf/celix/blob/a8942991/deployment_admin/private/src/deployment_admin.c ---------------------------------------------------------------------- diff --git a/deployment_admin/private/src/deployment_admin.c b/deployment_admin/private/src/deployment_admin.c index 7e936e4..eaf2468 100644 --- a/deployment_admin/private/src/deployment_admin.c +++ b/deployment_admin/private/src/deployment_admin.c @@ -59,6 +59,7 @@ #define IDENTIFICATION_ID "deployment_admin_identification" #define DISCOVERY_URL "deployment_admin_url" #define DEPLOYMENT_CACHE_DIR "deployment_cache_dir" +#define DEPLOYMENT_TAGS "deployment_tags" // "http://localhost:8080/deployment/" #define VERSIONS "/versions" @@ -172,48 +173,86 @@ celix_status_t deploymentAdmin_destroy(deployment_admin_pt admin) { return status; } -static celix_status_t deploymentAdmin_updateAuditPool(deployment_admin_pt admin, DEPLOYMENT_ADMIN_AUDIT_EVENT auditEvent) { - celix_status_t status = CELIX_SUCCESS; +static celix_status_t deploymentAdmin_performRequest(deployment_admin_pt admin, char* entry) { + celix_status_t status = CELIX_SUCCESS; - CURL *curl; - CURLcode res; - curl = curl_easy_init(); + CURL *curl; + CURLcode res; + curl = curl_easy_init(); - if (!curl) { - status = CELIX_BUNDLE_EXCEPTION; + if (!curl) { + status = CELIX_BUNDLE_EXCEPTION; - fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error initializing curl."); - } + fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error initializing curl."); + } - char url[strlen(admin->auditlogUrl)+6]; - sprintf(url, "%s/send", admin->auditlogUrl); - char entry[512]; - int entrySize = snprintf(entry, 512, "%s,%llu,%u,0,%i\n", admin->targetIdentification, admin->auditlogId, admin->aditlogSeqNr++, auditEvent); - if (entrySize >= 512) { - status = CELIX_BUNDLE_EXCEPTION; - fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error, entry buffer is too small"); - } + char url[strlen(admin->auditlogUrl)+6]; + sprintf(url, "%s/send", admin->auditlogUrl); - if (status == CELIX_SUCCESS) { - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, entry); - res = curl_easy_perform(curl); + if (status == CELIX_SUCCESS) { + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, entry); + res = curl_easy_perform(curl); - if (res != CURLE_OK ) { - status = CELIX_BUNDLE_EXCEPTION; - fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error sending auditlog, got curl error code %d", res); - } - } + if (res != CURLE_OK ) { + status = CELIX_BUNDLE_EXCEPTION; + fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error sending auditlog, got curl error code %d", res); + } + } - return status; + return status; } +static celix_status_t deploymentAdmin_auditEventTargetPropertiesSet(deployment_admin_pt admin) { + celix_status_t status = CELIX_SUCCESS; + + char *tags = NULL; + + bundleContext_getProperty(admin->context, DEPLOYMENT_TAGS, &tags); + + if (tags != NULL) { + char entry[512]; + int entrySize = 0; + + entrySize = snprintf(entry, 512, "%s,%llu,%u,0,%i,%s\n", admin->targetIdentification, admin->auditlogId, admin->aditlogSeqNr++, DEPLOYMENT_ADMIN_AUDIT_EVENT__TARGETPROPERTIES_SET, tags); + + if (entrySize >= 512) { + status = CELIX_BUNDLE_EXCEPTION; + } + else { + status = deploymentAdmin_performRequest(admin, entry); + } + } + + return status; +} + +static celix_status_t deploymentAdmin_auditEventFrameworkStarted(deployment_admin_pt admin) { + celix_status_t status = CELIX_SUCCESS; + + char entry[512]; + int entrySize = 0; + + entrySize = snprintf(entry, 512, "%s,%llu,%u,0,%i\n", admin->targetIdentification, admin->auditlogId, admin->aditlogSeqNr++, DEPLOYMENT_ADMIN_AUDIT_EVENT__FRAMEWORK_STARTED); + + if (entrySize >= 512) { + status = CELIX_BUNDLE_EXCEPTION; + } + else { + status = deploymentAdmin_performRequest(admin, entry); + } + + return status; +} + + static void *deploymentAdmin_poll(void *deploymentAdmin) { deployment_admin_pt admin = deploymentAdmin; /*first poll send framework started audit event, note this will register the target in Apache ACE*/ - deploymentAdmin_updateAuditPool(admin, DEPLOYMENT_ADMIN_AUDIT_EVENT__FRAMEWORK_STARTED); + deploymentAdmin_auditEventFrameworkStarted(admin); + deploymentAdmin_auditEventTargetPropertiesSet(admin); while (admin->running) { //poll ace @@ -228,15 +267,12 @@ static void *deploymentAdmin_poll(void *deploymentAdmin) { if (admin->current == NULL || strcmp(last, admin->current) != 0) { int length = strlen(admin->pollUrl) + strlen(last) + 2; char request[length]; - if (admin->current == NULL) { - snprintf(request, length, "%s/%s", admin->pollUrl, last); - } else { - // TODO - // We do not yet support fix packages - // Check string lenght! - // snprintf(request, length, "%s/%s?current=%s", admin->pollUrl, last, admin->current); - snprintf(request, length, "%s/%s", admin->pollUrl, last); - } + + // TODO + // We do not yet support fix packages + // Check string lenght! + // snprintf(request, length, "%s/%s?current=%s", admin->pollUrl, last, admin->current); + snprintf(request, length, "%s/%s", admin->pollUrl, last); char *inputFilename = NULL; celix_status_t status = deploymentAdmin_download(admin ,request, &inputFilename); http://git-wip-us.apache.org/repos/asf/celix/blob/a8942991/deployment_admin/private/src/deployment_admin_activator.c ---------------------------------------------------------------------- diff --git a/deployment_admin/private/src/deployment_admin_activator.c b/deployment_admin/private/src/deployment_admin_activator.c index 9a3ce5f..93fd6b5 100644 --- a/deployment_admin/private/src/deployment_admin_activator.c +++ b/deployment_admin/private/src/deployment_admin_activator.c @@ -64,7 +64,7 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) } celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status; bundle_activator_pt activator = (bundle_activator_pt) userData; http://git-wip-us.apache.org/repos/asf/celix/blob/a8942991/deployment_admin/private/src/deployment_package.c ---------------------------------------------------------------------- diff --git a/deployment_admin/private/src/deployment_package.c b/deployment_admin/private/src/deployment_package.c index 042d9ae..3fb962f 100644 --- a/deployment_admin/private/src/deployment_package.c +++ b/deployment_admin/private/src/deployment_package.c @@ -46,7 +46,7 @@ celix_status_t deploymentPackage_create(bundle_context_pt context, manifest_pt m celix_status_t status = CELIX_SUCCESS; *package = calloc(1, sizeof(**package)); - if (!package) { + if (!(*package)) { status = CELIX_ENOMEM; } else { (*package)->context = context; http://git-wip-us.apache.org/repos/asf/celix/blob/a8942991/deployment_admin/private/src/log.c ---------------------------------------------------------------------- diff --git a/deployment_admin/private/src/log.c b/deployment_admin/private/src/log.c index a5227ca..98e757d 100644 --- a/deployment_admin/private/src/log.c +++ b/deployment_admin/private/src/log.c @@ -55,7 +55,7 @@ celix_status_t log_destroy(log_pt *log) { } celix_status_t log_log(log_pt log, unsigned int type, properties_pt properties) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status; log_event_pt event = NULL;