Skip to content

Commit

Permalink
CELIX-278: deployment_admin: added capability to add tags, minor refa…
Browse files Browse the repository at this point in the history
…ctoring
  • Loading branch information
bpetri committed Oct 26, 2015
1 parent 6c93851 commit a894299
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 41 deletions.
4 changes: 3 additions & 1 deletion deployment_admin/private/include/deployment_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
110 changes: 73 additions & 37 deletions deployment_admin/private/src/deployment_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion deployment_admin/private/src/deployment_admin_activator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion deployment_admin/private/src/deployment_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion deployment_admin/private/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a894299

Please sign in to comment.