You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2012/02/17 08:37:06 UTC

svn commit: r1245337 - in /incubator/celix/trunk: ./ deployment_admin/ deployment_admin/private/include/ deployment_admin/private/src/ deployment_admin/public/ deployment_admin/public/include/ framework/public/include/

Author: abroekhuis
Date: Fri Feb 17 07:37:05 2012
New Revision: 1245337

URL: http://svn.apache.org/viewvc?rev=1245337&view=rev
Log:
Resource Processor support

Added support for resource processors to the deployment admin

Added:
    incubator/celix/trunk/deployment_admin/public/
    incubator/celix/trunk/deployment_admin/public/include/
    incubator/celix/trunk/deployment_admin/public/include/resource_processor.h
Modified:
    incubator/celix/trunk/CMakeLists.txt
    incubator/celix/trunk/deployment_admin/CMakeLists.txt
    incubator/celix/trunk/deployment_admin/private/include/deployment_package.h
    incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c
    incubator/celix/trunk/deployment_admin/private/src/deployment_package.c
    incubator/celix/trunk/framework/public/include/constants.h

Modified: incubator/celix/trunk/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/CMakeLists.txt?rev=1245337&r1=1245336&r2=1245337&view=diff
==============================================================================
--- incubator/celix/trunk/CMakeLists.txt (original)
+++ incubator/celix/trunk/CMakeLists.txt Fri Feb 17 07:37:05 2012
@@ -60,6 +60,7 @@ add_subdirectory(examples)
 add_subdirectory(remote_services)
 
 add_subdirectory(deployment_admin)
+add_subdirectory(o2parameters_resource_processor)
 
 include(target.cmake)
 #enable_testing()

Modified: incubator/celix/trunk/deployment_admin/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/CMakeLists.txt?rev=1245337&r1=1245336&r2=1245337&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/CMakeLists.txt (original)
+++ incubator/celix/trunk/deployment_admin/CMakeLists.txt Fri Feb 17 07:37:05 2012
@@ -20,6 +20,7 @@ add_definitions(-DUSE_FILE32API)
 include_directories("/opt/local/include")
 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")
 
 link_directories("/opt/local/lib")
 bundle(deployment_admin SOURCES

Modified: incubator/celix/trunk/deployment_admin/private/include/deployment_package.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/private/include/deployment_package.h?rev=1245337&r1=1245336&r2=1245337&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/private/include/deployment_package.h (original)
+++ incubator/celix/trunk/deployment_admin/private/include/deployment_package.h Fri Feb 17 07:37:05 2012
@@ -19,18 +19,30 @@ struct bundle_info {
 	char *path;
 	VERSION version;
 	char *symbolicName;
+	bool customizer;
 
 	PROPERTIES attributes;
 };
 
 typedef struct bundle_info *bundle_info_t;
 
+struct resource_info {
+	char *path;
+	PROPERTIES attributes;
+
+	char *resourceProcessor;
+};
+
+typedef struct resource_info *resource_info_t;
+
 struct deployment_package {
 	apr_pool_t *pool;
 	BUNDLE_CONTEXT context;
 	MANIFEST manifest;
 	ARRAY_LIST bundleInfos;
+	ARRAY_LIST resourceInfos;
 	HASH_MAP nameToBundleInfo;
+	HASH_MAP pathToEntry;
 };
 
 typedef struct deployment_package *deployment_package_t;
@@ -39,6 +51,8 @@ celix_status_t deploymentPackage_create(
 celix_status_t deploymentPackage_getName(deployment_package_t package, char **name);
 celix_status_t deploymentPackage_getBundleInfos(deployment_package_t package, ARRAY_LIST *infos);
 celix_status_t deploymentPackage_getBundleInfoByName(deployment_package_t package, char *name, bundle_info_t *info);
+celix_status_t deploymentPackage_getResourceInfos(deployment_package_t package, ARRAY_LIST *infos);
+celix_status_t deploymentPackage_getResourceInfoByPath(deployment_package_t package, char *path, resource_info_t *info);
 celix_status_t deploymentPackage_getBundle(deployment_package_t package, char *name, BUNDLE *bundle);
 celix_status_t deploymentPackage_getVersion(deployment_package_t package, VERSION *version);
 

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=1245337&r1=1245336&r2=1245337&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c (original)
+++ incubator/celix/trunk/deployment_admin/private/src/deployment_admin.c Fri Feb 17 07:37:05 2012
@@ -21,6 +21,8 @@
 #include "bundle.h"
 #include "utils.h"
 
+#include "resource_processor.h"
+
 #define VERSIONS "http://localhost:8080/deployment/test/versions"
 
 static void *APR_THREAD_FUNC deploymentAdmin_poll(apr_thread_t *thd, void *deploymentAdmin);
@@ -31,6 +33,9 @@ celix_status_t deploymentAdmin_readVersi
 
 celix_status_t deploymentAdmin_stopDeploymentPackageBundles(deployment_admin_t admin, deployment_package_t target);
 celix_status_t deploymentAdmin_updateDeploymentPackageBundles(deployment_admin_t admin, deployment_package_t source);
+celix_status_t deploymentAdmin_startDeploymentPackageCustomizerBundles(deployment_admin_t admin, deployment_package_t source, deployment_package_t target);
+celix_status_t deploymentAdmin_processDeploymentPackageResources(deployment_admin_t admin, deployment_package_t source);
+celix_status_t deploymentAdmin_dropDeploymentPackageResources(deployment_admin_t admin, deployment_package_t source, deployment_package_t target);
 celix_status_t deploymentAdmin_dropDeploymentPackageBundles(deployment_admin_t admin, deployment_package_t source, deployment_package_t target);
 celix_status_t deploymentAdmin_startDeploymentPackageBundles(deployment_admin_t admin, deployment_package_t source);
 
@@ -116,8 +121,15 @@ static void *APR_THREAD_FUNC deploymentA
 				}
 
 				deployment_package_t target = hashMap_get(admin->packages, name);
+				if (target == NULL) {
+//					target = empty package
+				}
+
 				deploymentAdmin_stopDeploymentPackageBundles(admin, target);
 				deploymentAdmin_updateDeploymentPackageBundles(admin, source);
+				deploymentAdmin_startDeploymentPackageCustomizerBundles(admin, source, target);
+				deploymentAdmin_processDeploymentPackageResources(admin, source);
+				deploymentAdmin_dropDeploymentPackageResources(admin, source, target);
 				deploymentAdmin_dropDeploymentPackageBundles(admin, source, target);
 				deploymentAdmin_startDeploymentPackageBundles(admin, source);
 
@@ -319,21 +331,172 @@ celix_status_t deploymentAdmin_updateDep
 	return status;
 }
 
-celix_status_t deploymentAdmin_dropDeploymentPackageBundles(deployment_admin_t admin, deployment_package_t source, deployment_package_t target) {
+celix_status_t deploymentAdmin_startDeploymentPackageCustomizerBundles(deployment_admin_t admin, deployment_package_t source, deployment_package_t target) {
 	celix_status_t status = CELIX_SUCCESS;
 
+	apr_pool_t *tmpPool = NULL;
+	ARRAY_LIST bundles = NULL;
+	ARRAY_LIST sourceInfos = NULL;
+
+	apr_pool_create(&tmpPool, admin->pool);
+	arrayList_create(tmpPool, &bundles);
+
+	deploymentPackage_getBundleInfos(source, &sourceInfos);
+	int i;
+	for (i = 0; i < arrayList_size(sourceInfos); i++) {
+		bundle_info_t sourceInfo = arrayList_get(sourceInfos, i);
+		if (sourceInfo->customizer) {
+			BUNDLE bundle = NULL;
+			deploymentPackage_getBundle(source, sourceInfo->symbolicName, &bundle);
+			if (bundle != NULL) {
+				arrayList_add(bundles, bundle);
+			}
+		}
+	}
+
 	if (target != NULL) {
 		ARRAY_LIST targetInfos = NULL;
 		deploymentPackage_getBundleInfos(target, &targetInfos);
-		int i;
 		for (i = 0; i < arrayList_size(targetInfos); i++) {
 			bundle_info_t targetInfo = arrayList_get(targetInfos, i);
-			bundle_info_t info = NULL;
-			deploymentPackage_getBundleInfoByName(source, targetInfo->symbolicName, &info);
-			if (info == NULL) {
+			if (targetInfo->customizer) {
 				BUNDLE bundle = NULL;
 				deploymentPackage_getBundle(target, targetInfo->symbolicName, &bundle);
-				bundle_uninstall(bundle);
+				if (bundle != NULL) {
+					arrayList_add(bundles, bundle);
+				}
+			}
+		}
+	}
+
+	for (i = 0; i < arrayList_size(bundles); i++) {
+		BUNDLE bundle = arrayList_get(bundles, i);
+		bundle_start(bundle, 0);
+	}
+
+	apr_pool_destroy(tmpPool);
+
+	return status;
+}
+
+celix_status_t deploymentAdmin_processDeploymentPackageResources(deployment_admin_t admin, deployment_package_t source) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	ARRAY_LIST infos = NULL;
+	deploymentPackage_getResourceInfos(source, &infos);
+	int i;
+	for (i = 0; i < arrayList_size(infos); i++) {
+		resource_info_t info = arrayList_get(infos, i);
+		apr_pool_t *tmpPool = NULL;
+		ARRAY_LIST services = NULL;
+		char *filter = NULL;
+
+		printf("Process resource: %s with %s\n", info->path, info->resourceProcessor);
+
+		apr_pool_create(&tmpPool, admin->pool);
+		filter = apr_pstrcat(tmpPool, "(", SERVICE_PID, "=", info->resourceProcessor, ")", NULL);
+
+		status = bundleContext_getServiceReferences(admin->context, RESOURCE_PROCESSOR_SERVICE, filter, &services);
+		if (status == CELIX_SUCCESS) {
+			printf("REFS\n");
+			if (services != NULL && arrayList_size(services) > 0) {
+				printf("REFS22\n");
+				SERVICE_REFERENCE ref = arrayList_get(services, 0);
+				// In Felix a check is done to assure the processor belongs to the deployment package
+				// Is this according to spec?
+				void *processorP = NULL;
+				status = bundleContext_getService(admin->context, ref, &processorP);
+				if (status == CELIX_SUCCESS) {
+					BUNDLE bundle = NULL;
+					char *entry = NULL;
+					char *name = NULL;
+					char *packageName = NULL;
+					resource_processor_service_t processor = processorP;
+
+					bundleContext_getBundle(admin->context, &bundle);
+					bundle_getEntry(bundle, "/", admin->pool, &entry);
+					deploymentPackage_getName(source, &name);
+
+					char *resourcePath = apr_pstrcat(admin->pool, entry, "repo/", name, "/", info->path, NULL);
+					deploymentPackage_getName(source, &packageName);
+
+					processor->begin(processor->processor, packageName);
+					processor->process(processor->processor, info->path, resourcePath);
+				}
+			}
+		}
+
+
+	}
+
+	return status;
+}
+
+celix_status_t deploymentAdmin_dropDeploymentPackageResources(deployment_admin_t admin, deployment_package_t source, deployment_package_t target) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (target != NULL) {
+		ARRAY_LIST infos = NULL;
+		deploymentPackage_getResourceInfos(target, &infos);
+		int i;
+		for (i = 0; i < arrayList_size(infos); i++) {
+			resource_info_t info = arrayList_get(infos, i);
+			resource_info_t sourceInfo = NULL;
+			deploymentPackage_getResourceInfoByPath(source, info->path, &sourceInfo);
+			if (sourceInfo == NULL) {
+				apr_pool_t *tmpPool = NULL;
+				ARRAY_LIST services = NULL;
+				char *filter = NULL;
+
+				printf("Drop resource: %s with %s\n", info->path, info->resourceProcessor);
+
+				apr_pool_create(&tmpPool, admin->pool);
+				filter = apr_pstrcat(tmpPool, "(", SERVICE_PID, "=", info->resourceProcessor, ")", NULL);
+
+				status = bundleContext_getServiceReferences(admin->context, RESOURCE_PROCESSOR_SERVICE, filter, &services);
+				if (status == CELIX_SUCCESS) {
+					if (services != NULL && arrayList_size(services) > 0) {
+						SERVICE_REFERENCE ref = arrayList_get(services, 0);
+						// In Felix a check is done to assure the processor belongs to the deployment package
+						// Is this according to spec?
+						void *processorP = NULL;
+						status = bundleContext_getService(admin->context, ref, &processorP);
+						if (status == CELIX_SUCCESS) {
+							BUNDLE bundle = NULL;
+							char *packageName = NULL;
+							resource_processor_service_t processor = processorP;
+
+							deploymentPackage_getName(source, &packageName);
+							processor->begin(processor->processor, packageName);
+							processor->dropped(processor->processor, info->path);
+						}
+					}
+				}
+
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t deploymentAdmin_dropDeploymentPackageBundles(deployment_admin_t admin, deployment_package_t source, deployment_package_t target) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (target != NULL) {
+		ARRAY_LIST targetInfos = NULL;
+		deploymentPackage_getBundleInfos(target, &targetInfos);
+		int i;
+		for (i = 0; i < arrayList_size(targetInfos); i++) {
+			bundle_info_t targetInfo = arrayList_get(targetInfos, i);
+			if (!targetInfo->customizer) {
+				bundle_info_t info = NULL;
+				deploymentPackage_getBundleInfoByName(source, targetInfo->symbolicName, &info);
+				if (info == NULL) {
+					BUNDLE bundle = NULL;
+					deploymentPackage_getBundle(target, targetInfo->symbolicName, &bundle);
+					bundle_uninstall(bundle);
+				}
 			}
 		}
 	}
@@ -350,11 +513,13 @@ celix_status_t deploymentAdmin_startDepl
 	for (i = 0; i < arrayList_size(infos); i++) {
 		BUNDLE bundle = NULL;
 		bundle_info_t info = arrayList_get(infos, i);
-		deploymentPackage_getBundle(source, info->symbolicName, &bundle);
-		if (bundle != NULL) {
-			bundle_start(bundle, 0);
-		} else {
-			printf("DEPLOYMENT_ADMIN: Could not start bundle %s\n", info->symbolicName);
+		if (!info->customizer) {
+			deploymentPackage_getBundle(source, info->symbolicName, &bundle);
+			if (bundle != NULL) {
+				bundle_start(bundle, 0);
+			} else {
+				printf("DEPLOYMENT_ADMIN: Could not start bundle %s\n", info->symbolicName);
+			}
 		}
 	}
 

Modified: incubator/celix/trunk/deployment_admin/private/src/deployment_package.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/private/src/deployment_package.c?rev=1245337&r1=1245336&r2=1245337&view=diff
==============================================================================
--- incubator/celix/trunk/deployment_admin/private/src/deployment_package.c (original)
+++ incubator/celix/trunk/deployment_admin/private/src/deployment_package.c Fri Feb 17 07:37:05 2012
@@ -15,7 +15,12 @@
 #include "module.h"
 #include "bundle.h"
 
-celix_status_t deploymentPackage_setBundleInfos(deployment_package_t package);
+static const char * const RESOURCE_PROCESSOR = "Resource-Processor";
+static const char * const DEPLOYMENTPACKAGE_CUSTOMIZER = "DeploymentPackage-Customizer";
+
+celix_status_t deploymentPackage_processEntries(deployment_package_t package);
+static celix_status_t deploymentPackage_isBundleResource(PROPERTIES attributes, bool *isBundleResource);
+static celix_status_t deploymentPackage_parseBooleanHeader(char *value, bool *boolValue);
 
 celix_status_t deploymentPackage_create(apr_pool_t *pool, BUNDLE_CONTEXT context, MANIFEST manifest, deployment_package_t *package) {
 	celix_status_t status = CELIX_SUCCESS;
@@ -28,15 +33,24 @@ celix_status_t deploymentPackage_create(
 		(*package)->context = context;
 		(*package)->manifest = manifest;
 		(*package)->bundleInfos = NULL;
+		(*package)->resourceInfos = NULL;
 		(*package)->nameToBundleInfo = hashMap_create(string_hash, NULL, string_equals, NULL);
+		(*package)->pathToEntry = hashMap_create(string_hash, NULL, string_equals, NULL);
 		status = arrayList_create(pool, &(*package)->bundleInfos);
 		if (status == CELIX_SUCCESS) {
-			status = deploymentPackage_setBundleInfos(*package);
+			status = arrayList_create(pool, &(*package)->resourceInfos);
 			if (status == CELIX_SUCCESS) {
-				int i;
-				for (i = 0; i < arrayList_size((*package)->bundleInfos); i++) {
-					bundle_info_t info = arrayList_get((*package)->bundleInfos, i);
-					hashMap_put((*package)->nameToBundleInfo, info->symbolicName, info);
+				status = deploymentPackage_processEntries(*package);
+				if (status == CELIX_SUCCESS) {
+					int i;
+					for (i = 0; i < arrayList_size((*package)->bundleInfos); i++) {
+						bundle_info_t info = arrayList_get((*package)->bundleInfos, i);
+						hashMap_put((*package)->nameToBundleInfo, info->symbolicName, info);
+					}
+					for (i = 0; i < arrayList_size((*package)->resourceInfos); i++) {
+						resource_info_t info = arrayList_get((*package)->resourceInfos, i);
+						hashMap_put((*package)->pathToEntry, info->path, info);
+					}
 				}
 			}
 		}
@@ -81,12 +95,22 @@ celix_status_t deploymentPackage_getBund
 	return CELIX_SUCCESS;
 }
 
+celix_status_t deploymentPackage_getResourceInfos(deployment_package_t package, ARRAY_LIST *infos) {
+	*infos = arrayList_clone(package->pool, package->resourceInfos);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deploymentPackage_getResourceInfoByPath(deployment_package_t package, char *path, resource_info_t *info) {
+	*info = hashMap_get(package->pathToEntry, path);
+	return CELIX_SUCCESS;
+}
+
 celix_status_t deploymentPackage_getVersion(deployment_package_t package, VERSION *version) {
 	char *versionStr = manifest_getValue(package->manifest, "DeploymentPackage-Version");
 	return version_createVersionFromString(package->pool, versionStr, version);
 }
 
-celix_status_t deploymentPackage_setBundleInfos(deployment_package_t package) {
+celix_status_t deploymentPackage_processEntries(deployment_package_t package) {
 	celix_status_t status = CELIX_SUCCESS;
 
 	HASH_MAP entries = NULL;
@@ -97,18 +121,48 @@ celix_status_t deploymentPackage_setBund
 		char *name = hashMapEntry_getKey(entry);
 		PROPERTIES values = hashMapEntry_getValue(entry);
 
-		bundle_info_t info = apr_palloc(package->pool, sizeof(*info));
-		info->path = name;
-		info->attributes = values;
-		info->symbolicName = properties_get(values, (char *) BUNDLE_SYMBOLICNAME);
-		char *version = properties_get(values, (char *) BUNDLE_VERSION);
-		info->version = NULL;
-		status = version_createVersionFromString(package->pool, version, &info->version);
+		bool isBundleResource;
+		deploymentPackage_isBundleResource(values, &isBundleResource);
+		if (isBundleResource) {
+			bundle_info_t info = apr_palloc(package->pool, sizeof(*info));
+			info->path = name;
+			info->attributes = values;
+			info->symbolicName = properties_get(values, (char *) BUNDLE_SYMBOLICNAME);
+			char *version = properties_get(values, (char *) BUNDLE_VERSION);
+			info->version = NULL;
+			status = version_createVersionFromString(package->pool, version, &info->version);
+			char *customizer = properties_get(values, (char *) DEPLOYMENTPACKAGE_CUSTOMIZER);
+			deploymentPackage_parseBooleanHeader(customizer, &info->customizer);
+
+			arrayList_add(package->bundleInfos, info);
+		} else {
+			resource_info_t info = apr_palloc(package->pool, sizeof(*info));
+			info->path = name;
+			info->attributes = values;
+			info->resourceProcessor = properties_get(values, (char *) RESOURCE_PROCESSOR);
 
-		arrayList_add(package->bundleInfos, info);
+			arrayList_add(package->resourceInfos, info);
+		}
 	}
 
 	return status;
 }
 
+static celix_status_t deploymentPackage_isBundleResource(PROPERTIES attributes, bool *isBundleResource) {
+	*isBundleResource = properties_get(attributes, (char *) BUNDLE_SYMBOLICNAME) != NULL;
+	return CELIX_SUCCESS;
+}
+
+static celix_status_t deploymentPackage_parseBooleanHeader(char *value, bool *boolValue) {
+	*boolValue = false;
+	if (value != NULL) {
+		if (strcmp(value, "true") == 0) {
+			*boolValue = true;
+		} else {
+			*boolValue = false;
+		}
+	}
+	return CELIX_SUCCESS;
+}
+
 

Added: incubator/celix/trunk/deployment_admin/public/include/resource_processor.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/deployment_admin/public/include/resource_processor.h?rev=1245337&view=auto
==============================================================================
--- incubator/celix/trunk/deployment_admin/public/include/resource_processor.h (added)
+++ incubator/celix/trunk/deployment_admin/public/include/resource_processor.h Fri Feb 17 07:37:05 2012
@@ -0,0 +1,35 @@
+/*
+ * resource_processor.h
+ *
+ *  Created on: Feb 13, 2012
+ *      Author: alexander
+ */
+
+#ifndef RESOURCE_PROCESSOR_H_
+#define RESOURCE_PROCESSOR_H_
+
+#include "celix_errno.h"
+
+#define RESOURCE_PROCESSOR_SERVICE "resource_processor"
+
+typedef struct resource_processor *resource_processor_t;
+
+typedef struct resource_processor_service *resource_processor_service_t;
+
+struct resource_processor_service {
+	resource_processor_t processor;
+	celix_status_t (*begin)(resource_processor_t processor, char *packageName);
+
+	celix_status_t (*process)(resource_processor_t processor, char *name, char *path);
+
+	celix_status_t (*dropped)(resource_processor_t processor, char *name);
+	celix_status_t (*dropAllResources)(resource_processor_t processor);
+
+	//celix_status_t (*prepare)(resource_processor_t processor);
+	//celix_status_t (*commit)(resource_processor_t processor);
+	//celix_status_t (*rollback)(resource_processor_t processor);
+
+	//celix_status_t (*cancel)(resource_processor_t processor);
+};
+
+#endif /* RESOURCE_PROCESSOR_H_ */

Modified: incubator/celix/trunk/framework/public/include/constants.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/constants.h?rev=1245337&r1=1245336&r2=1245337&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/constants.h (original)
+++ incubator/celix/trunk/framework/public/include/constants.h Fri Feb 17 07:37:05 2012
@@ -28,6 +28,7 @@
 
 static const char * const OBJECTCLASS = "objectClass";
 static const char * const SERVICE_ID = "service.id";
+static const char * const SERVICE_PID = "service.pid";
 static const char * const SERVICE_RANKING = "service.ranking";
 
 static const char * const BUNDLE_ACTIVATOR_CREATE = "bundleActivator_create";