You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2014/06/03 14:35:55 UTC

svn commit: r1599511 - in /incubator/celix/trunk: cmake/ deployment_admin/ deployment_admin/private/include/ deployment_admin/private/src/ framework/public/include/

Author: pnoltes
Date: Tue Jun  3 12:35:55 2014
New Revision: 1599511

URL: http://svn.apache.org/r1599511
Log:
CELIX-118: 
- Added properties in the cmake deploy macro, so that additional properties in the config.properties can be specified. This is, for example, useful for the deployment admin.
- Fixed bug in deployment_admin when a tmp directory for unpacking deployment packages on a different device that the target directory is used. Unpacking now happens in directly in the bundle directory.
- Added the first support for the auditlog. Celix target will now automatically popup in Apache ACE.


Modified:
    incubator/celix/trunk/cmake/Packaging.cmake
    incubator/celix/trunk/cmake/config.properties.in
    incubator/celix/trunk/deployment_admin/CMakeLists.txt
    incubator/celix/trunk/deployment_admin/deploy.cmake
    incubator/celix/trunk/deployment_admin/private/include/deployment_admin.h
    incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c
    incubator/celix/trunk/framework/public/include/celix_errno.h

Modified: incubator/celix/trunk/cmake/Packaging.cmake
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/cmake/Packaging.cmake?rev=1599511&r1=1599510&r2=1599511&view=diff
==============================================================================
--- incubator/celix/trunk/cmake/Packaging.cmake (original)
+++ incubator/celix/trunk/cmake/Packaging.cmake Tue Jun  3 12:35:55 2014
@@ -324,7 +324,7 @@ ENDMACRO(package)
 
 ADD_CUSTOM_TARGET(deploy)
 MACRO(deploy)
-    PARSE_ARGUMENTS(DEPLOY "BUNDLES;DRIVERS;ENDPOINTS" "" ${ARGN})
+    PARSE_ARGUMENTS(DEPLOY "BUNDLES;DRIVERS;ENDPOINTS;PROPERTIES" "" ${ARGN})
     LIST(GET DEPLOY_DEFAULT_ARGS 0 DEPLOY_NAME)
     
 	SET(DEPLOY_COMPONENT deploy_${DEPLOY_NAME})
@@ -332,6 +332,7 @@ MACRO(deploy)
 		
 	SET(BUNDLES "")
 	SET(DEPS)
+	SET(PROPERTIES "")
 	
 	FOREACH(BUNDLE ${DEPLOY_BUNDLES})
 		SET(DEP_NAME ${DEPLOY_NAME}_${BUNDLE}) 
@@ -345,6 +346,7 @@ MACRO(deploy)
 	    SET(BUNDLES "${BUNDLES} bundles/${BUNDLE}.zip")
 	    SET(DEPS ${DEPS};${CMAKE_CURRENT_BINARY_DIR}/deploy/${DEPLOY_NAME}/bundles/${BUNDLE}.zip)
 	ENDFOREACH(BUNDLE)
+
 	FOREACH(BUNDLE ${DEPLOY_DRIVERS})
         SET(DEP_NAME ${DEPLOY_NAME}_${BUNDLE}) 
         get_property(bundle_file TARGET ${BUNDLE} PROPERTY BUNDLE)
@@ -356,8 +358,9 @@ MACRO(deploy)
         )
         #SET(BUNDLES "${BUNDLES} drivers/${BUNDLE}.zip")
         SET(DEPS ${DEPS};${CMAKE_CURRENT_BINARY_DIR}/deploy/${DEPLOY_NAME}/drivers/${BUNDLE}.zip)
-    ENDFOREACH(BUNDLE)
-    FOREACH(BUNDLE ${DEPLOY_ENDPOINTS})
+    	ENDFOREACH(BUNDLE)
+
+	FOREACH(BUNDLE ${DEPLOY_ENDPOINTS})
         SET(DEP_NAME ${DEPLOY_NAME}_${BUNDLE}) 
         get_property(bundle_file TARGET ${BUNDLE} PROPERTY BUNDLE)
         add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/deploy/${DEPLOY_NAME}/endpoints/${BUNDLE}.zip
@@ -368,7 +371,11 @@ MACRO(deploy)
         )
         #SET(BUNDLES "${BUNDLES} drivers/${BUNDLE}.zip")
         SET(DEPS ${DEPS};${CMAKE_CURRENT_BINARY_DIR}/deploy/${DEPLOY_NAME}/endpoints/${BUNDLE}.zip)
-    ENDFOREACH(BUNDLE)
+    	ENDFOREACH(BUNDLE)
+	
+	FOREACH(PROPERTY ${DEPLOY_PROPERTIES})
+		SET(PROPERTIES "${PROPERTIES}\n${PROPERTY}")
+	ENDFOREACH(PROPERTY)
 	
 	IF(NOT(CELIX_FOUND)) #celix project
 		set(DEPS ${DEPS};celix)

Modified: incubator/celix/trunk/cmake/config.properties.in
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/cmake/config.properties.in?rev=1599511&r1=1599510&r2=1599511&view=diff
==============================================================================
--- incubator/celix/trunk/cmake/config.properties.in (original)
+++ incubator/celix/trunk/cmake/config.properties.in Tue Jun  3 12:35:55 2014
@@ -1 +1,2 @@
-cosgi.auto.start.1=@BUNDLES@
\ No newline at end of file
+cosgi.auto.start.1=@BUNDLES@
+@PROPERTIES@

Modified: incubator/celix/trunk/deployment_admin/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/CMakeLists.txt?rev=1599511&r1=1599510&r2=1599511&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/CMakeLists.txt (original)
+++ incubator/celix/trunk/deployment_admin/CMakeLists.txt Tue Jun  3 12:35:55 2014
@@ -26,6 +26,8 @@ if (DEPLOYMENT_ADMIN)
 	SET_HEADERS("Bundle-Name: Apache Celix Deployment Admin") 
     
     include_directories("${CURL_INCLUDE_DIR}")
+    include_directories("${APR_INCLUDE_DIR}")
+    include_directories("${APRUTIL_INCLUDE_DIR}")
     include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
     include_directories("${PROJECT_SOURCE_DIR}/deployment_admin/private/include")
     include_directories("${PROJECT_SOURCE_DIR}/deployment_admin/public/include")
@@ -57,5 +59,5 @@ if (DEPLOYMENT_ADMIN)
     		public/include/resource_processor.h
 	)
     
-    target_link_libraries(deployment_admin celix_framework ${CURL_LIBRARIES})
+    target_link_libraries(deployment_admin celix_framework ${CURL_LIBRARIES} ${APR_LIBRARY} ${APRUTIL_LIBRARY})
 endif (DEPLOYMENT_ADMIN)

Modified: incubator/celix/trunk/deployment_admin/deploy.cmake
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/deploy.cmake?rev=1599511&r1=1599510&r2=1599511&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/deploy.cmake (original)
+++ incubator/celix/trunk/deployment_admin/deploy.cmake Tue Jun  3 12:35:55 2014
@@ -16,5 +16,9 @@
 # under the License.
 is_enabled(DEPLOYMENT_ADMIN)
 if (DEPLOYMENT_ADMIN)
-	deploy("deployment-admin" BUNDLES deployment_admin shell shell_tui log_service log_writer)
-endif (DEPLOYMENT_ADMIN)
\ No newline at end of file
+	deploy("deployment-admin" BUNDLES deployment_admin shell shell_tui log_service log_writer PROPERTIES 
+		"deployment_admin_url=http://localhost:8080"
+		"deployment_admin_identification=celix"
+		"org.osgi.framework.storage.clean=onFirstInit"
+	)
+endif (DEPLOYMENT_ADMIN)

Modified: incubator/celix/trunk/deployment_admin/private/include/deployment_admin.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/private/include/deployment_admin.h?rev=1599511&r1=1599510&r2=1599511&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/private/include/deployment_admin.h (original)
+++ incubator/celix/trunk/deployment_admin/private/include/deployment_admin.h Tue Jun  3 12:35:55 2014
@@ -43,8 +43,15 @@ struct deployment_admin {
 	hash_map_pt packages;
 	char *targetIdentification;
 	char *pollUrl;
+	char *auditlogUrl;
+	apr_time_t auditlogId;
+	unsigned int aditlogSeqNr;
 };
 
+typedef enum {
+	DEPLOYMENT_ADMIN_AUDIT_EVENT__FRAMEWORK_STARTED = 1005
+} DEPLOYMENT_ADMIN_AUDIT_EVENT;
+
 celix_status_t deploymentAdmin_create(apr_pool_t *pool, bundle_context_pt context, deployment_admin_pt *admin);
 
 #endif /* DEPLOYMENT_ADMIN_H_ */

Modified: incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c?rev=1599511&r1=1599510&r2=1599511&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c (original)
+++ incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c Tue Jun  3 12:35:55 2014
@@ -23,14 +23,22 @@
  *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
  *  \copyright	Apache License, Version 2.0
  */
+
+#include <stddef.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
+
 #include <curl/curl.h>
 #include <curl/easy.h>
+
+#include <apr_thread_proc.h>
 #include <apr_strings.h>
+#include <apr_time.h>
+#include <apr_uuid.h>
 
+#include "celixbool.h"
 #include "deployment_admin.h"
 #include "celix_errno.h"
 #include "bundle_context.h"
@@ -52,7 +60,7 @@
 
 #define VERSIONS "/versions"
 
-static void *APR_THREAD_FUNC deploymentAdmin_poll(apr_thread_t *thd, void *deploymentAdmin);
+static void* deploymentAdmin_poll(apr_thread_t *thd, void *deploymentAdmin);
 celix_status_t deploymentAdmin_download(char * url, char **inputFile);
 size_t deploymentAdmin_writeData(void *ptr, size_t size, size_t nmemb, FILE *stream);
 static celix_status_t deploymentAdmin_deleteTree(char * directory, apr_pool_t *mp);
@@ -65,6 +73,7 @@ celix_status_t deploymentAdmin_processDe
 celix_status_t deploymentAdmin_dropDeploymentPackageResources(deployment_admin_pt admin, deployment_package_pt source, deployment_package_pt target);
 celix_status_t deploymentAdmin_dropDeploymentPackageBundles(deployment_admin_pt admin, deployment_package_pt source, deployment_package_pt target);
 celix_status_t deploymentAdmin_startDeploymentPackageBundles(deployment_admin_pt admin, deployment_package_pt source);
+static celix_status_t deploymentAdmin_updateAuditPool(deployment_admin_pt admin, DEPLOYMENT_ADMIN_AUDIT_EVENT auditEvent);
 
 celix_status_t deploymentAdmin_create(apr_pool_t *pool, bundle_context_pt context, deployment_admin_pt *admin) {
 	celix_status_t status = CELIX_SUCCESS;
@@ -82,7 +91,12 @@ celix_status_t deploymentAdmin_create(ap
 		(*admin)->packages = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
 		(*admin)->targetIdentification = NULL;
 		(*admin)->pollUrl = NULL;
+		(*admin)->auditlogUrl = NULL;
+
         bundleContext_getProperty(context, IDENTIFICATION_ID, &(*admin)->targetIdentification);
+        (*admin)->auditlogId = apr_time_now();
+        (*admin)->aditlogSeqNr = 0;
+
 		if ((*admin)->targetIdentification == NULL ) {
 			printf("Target name must be set using \"deployment_admin_identification\"\n");
 			status = CELIX_ILLEGAL_ARGUMENT;
@@ -93,7 +107,8 @@ celix_status_t deploymentAdmin_create(ap
 				printf("URL must be set using \"deployment_admin_url\"\n");
 				status = CELIX_ILLEGAL_ARGUMENT;
 			} else {
-				(*admin)->pollUrl = apr_pstrcat(subpool, url, (*admin)->targetIdentification, VERSIONS, NULL);
+				(*admin)->pollUrl = apr_pstrcat(subpool, url, "/deployment/", (*admin)->targetIdentification, VERSIONS, NULL);
+				(*admin)->auditlogUrl = apr_pstrcat(subpool, url, "/auditlog", NULL);
 
 //				log_store_pt store = NULL;
 //				log_pt log = NULL;
@@ -113,9 +128,48 @@ celix_status_t deploymentAdmin_create(ap
 	return status;
 }
 
-static void *APR_THREAD_FUNC deploymentAdmin_poll(apr_thread_t *thd, void *deploymentAdmin) {
+static celix_status_t deploymentAdmin_updateAuditPool(deployment_admin_pt admin, DEPLOYMENT_ADMIN_AUDIT_EVENT auditEvent) {
+	celix_status_t status = CELIX_SUCCESS;
+
+
+	CURL *curl;
+	CURLcode res;
+	curl = curl_easy_init();
+
+	if (!curl) {
+		status = CELIX_BUNDLE_EXCEPTION;
+		printf("Error initializing curl\n");
+	}
+
+	char url[strlen(admin->auditlogUrl)+6];
+	sprintf(url, "%s/send", admin->auditlogUrl);
+	char entry[512];
+	int entrySize = snprintf(entry, 512, "%s,%i,%i,0,%i\n", admin->targetIdentification, admin->auditlogId, admin->aditlogSeqNr++, auditEvent);
+	if (entrySize >= 512) {
+		status = CELIX_BUNDLE_EXCEPTION;
+		printf("Error, entry buffer is too small\n");
+	}
+
+	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;
+				printf("Error sending auditlog, got curl error code %i\n", res);
+			}
+	}
+
+	return status;
+}
+
+static void * deploymentAdmin_poll(apr_thread_t *thd, 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);
+
 	while (admin->running) {
 		//poll ace
 		array_list_pt versions = NULL;
@@ -134,16 +188,23 @@ static void *APR_THREAD_FUNC deploymentA
 					request = apr_pstrcat(admin->pool, admin->pollUrl, "/", last, NULL);
 				}
 
-				char inputFile[MAXNAMLEN];
+				char inputFile[256];
 				inputFile[0] = '\0';
 				char *test = inputFile;
 				celix_status_t status = deploymentAdmin_download(request, &test);
 				if (status == CELIX_SUCCESS) {
-					// Handle file
-					char tmpDir[MAXNAMLEN];
-					tmpDir[0] = '\0';
-					tmpnam(tmpDir);
+					bundle_pt bundle = NULL;
+					bundleContext_getBundle(admin->context, &bundle);
+					char *entry = NULL;
+					bundle_getEntry(bundle, "/", admin->pool, &entry);
 
+					// Handle file
+					char tmpDir[256];
+					char uuidStr[128];
+                    apr_uuid_t tmpUuid;
+                    apr_uuid_get(&tmpUuid);
+                    apr_uuid_format(uuidStr, &tmpUuid);
+                    sprintf(tmpDir, "%s%s", entry, uuidStr);
 					apr_dir_make(tmpDir, APR_UREAD|APR_UWRITE|APR_UEXECUTE, admin->pool);
 
 					// TODO: update to use bundle cache DataFile instead of module entries.
@@ -156,10 +217,6 @@ static void *APR_THREAD_FUNC deploymentA
 					char *name = NULL;
 					deploymentPackage_getName(source, &name);
 
-					bundle_pt bundle = NULL;
-					bundleContext_getBundle(admin->context, &bundle);
-					char *entry = NULL;
-					bundle_getEntry(bundle, "/", admin->pool, &entry);
 					char *repoDir = apr_pstrcat(admin->pool, entry, "repo", NULL);
 					apr_dir_make(repoDir, APR_UREAD|APR_UWRITE|APR_UEXECUTE, admin->pool);
 					char *repoCache = apr_pstrcat(admin->pool, entry, "repo/", name, NULL);

Modified: incubator/celix/trunk/framework/public/include/celix_errno.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/celix_errno.h?rev=1599511&r1=1599510&r2=1599511&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/celix_errno.h (original)
+++ incubator/celix/trunk/framework/public/include/celix_errno.h Tue Jun  3 12:35:55 2014
@@ -31,7 +31,9 @@
 #ifndef CELIX_ERRNO_H_
 #define CELIX_ERRNO_H_
 
+#include <stddef.h>
 #include <errno.h>
+
 #include <apr_errno.h>
 
 #include "framework_exports.h"