celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt reference, void *service) { celix_status_t status = CELIX_SUCCESS; bundle_context_pt context = NULL; bundle_pt bundle = NULL; dm_event_pt event = NULL; dm_service_dependency_pt dependency = _ptr; if (!dependency || !reference || !service) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { status = component_getBundleContext(dependency->component, &context); if (!context) { status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { status = bundleContext_getBundle(context, &bundle); if (!bundle) { status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { status = event_create(DM_EVENT_REMOVED, bundle, context, reference, service, &event); } if (status == CELIX_SUCCESS) { component_handleEvent(dependency->component, dependency, event); } return status; }
celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { celix_status_t status = CELIX_SUCCESS; struct publisherActivator * act = malloc(sizeof(*act)); const char* fwUUID = NULL; bundleContext_getProperty(context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID); if(fwUUID == NULL){ printf("MP_PUBLISHER: Cannot retrieve fwUUID.\n"); status = CELIX_INVALID_BUNDLE_CONTEXT; } if (status == CELIX_SUCCESS){ bundle_pt bundle = NULL; long bundleId = 0; bundleContext_getBundle(context,&bundle); bundle_getBundleId(bundle,&bundleId); arrayList_create(&(act->trackerList)); act->client = publisher_create(act->trackerList,fwUUID,bundleId); *userData = act; } else { free(act); } return status; }
celix_status_t deploymentAdmin_updateDeploymentPackageBundles(deployment_admin_pt admin, deployment_package_pt source) { celix_status_t status = CELIX_SUCCESS; array_list_pt infos = NULL; deploymentPackage_getBundleInfos(source, &infos); int i; for (i = 0; i < arrayList_size(infos); i++) { bundle_pt bundle = NULL; bundle_info_pt info = arrayList_get(infos, i); bundleContext_getBundle(admin->context, &bundle); char *entry = NULL; bundle_getEntry(bundle, "/", &entry); char *name = NULL; deploymentPackage_getName(source, &name); char *bundlePath = apr_pstrcat(admin->pool, entry, "repo/", name, "/", info->path, NULL); char *bsn = apr_pstrcat(admin->pool, "osgi-dp:", info->symbolicName, NULL); bundle_pt updateBundle = NULL; deploymentPackage_getBundle(source, info->symbolicName, &updateBundle); if (updateBundle != NULL) { //printf("Update bundle from: %s\n", bundlePath); bundle_update(updateBundle, bundlePath); } else { //printf("Install bundle from: %s\n", bundlePath); bundleContext_installBundle2(admin->context, bsn, bundlePath, &updateBundle); } } return status; }
celix_status_t deploymentAdmin_processDeploymentPackageResources(deployment_admin_pt admin, deployment_package_pt source) { celix_status_t status = CELIX_SUCCESS; array_list_pt infos = NULL; deploymentPackage_getResourceInfos(source, &infos); int i; for (i = 0; i < arrayList_size(infos); i++) { resource_info_pt info = arrayList_get(infos, i); apr_pool_t *tmpPool = NULL; array_list_pt services = NULL; char *filter = NULL; apr_pool_create(&tmpPool, admin->pool); filter = apr_pstrcat(tmpPool, "(", OSGI_FRAMEWORK_SERVICE_PID, "=", info->resourceProcessor, ")", NULL); status = bundleContext_getServiceReferences(admin->context, DEPLOYMENTADMIN_RESOURCE_PROCESSOR_SERVICE, filter, &services); if (status == CELIX_SUCCESS) { if (services != NULL && arrayList_size(services) > 0) { service_reference_pt 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_pt bundle = NULL; char *entry = NULL; char *name = NULL; char *packageName = NULL; resource_processor_service_pt processor = processorP; bundleContext_getBundle(admin->context, &bundle); bundle_getEntry(bundle, "/", &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); } } } if(services!=NULL){ arrayList_destroy(services); } } return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { struct publisherActivator * act = (struct publisherActivator *) userData; int i; array_list_pt topic_list = pubsub_getTopicsFromString(PUB_TOPIC); if(topic_list !=NULL){ char filter[128]; for(i=0; i<arrayList_size(topic_list);i++){ char* topic = arrayList_get(topic_list,i); if(strlen(topic)<MAX_TOPIC_LEN){ bundle_pt bundle = NULL; long bundleId = 0; bundleContext_getBundle(context,&bundle); bundle_getBundleId(bundle,&bundleId); service_tracker_pt tracker = NULL; memset(filter,0,128); snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC,topic); service_tracker_customizer_pt customizer = NULL; serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer); serviceTracker_createWithFilter(context, filter, customizer, &tracker); arrayList_add(act->trackerList,tracker); } else{ printf("Topic %s too long. Skipping publication.\n",topic); } free(topic); } arrayList_destroy(topic_list); } publisher_start(act->client); for(i=0;i<arrayList_size(act->trackerList);i++){ service_tracker_pt tracker = arrayList_get(act->trackerList,i); serviceTracker_open(tracker); } return CELIX_SUCCESS; }
static void * APR_THREAD_FUNC 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; deploymentAdmin_readVersions(admin, &versions); char *last = arrayList_get(versions, arrayList_size(versions) - 1); if (last != NULL) { if (admin->current == NULL || strcmp(last, admin->current) > 0) { char *request = NULL; if (admin->current == NULL) { request = apr_pstrcat(admin->pool, admin->pollUrl, "/", last, NULL); } else { // We do not yet support fix packages //request = apr_pstrcat(admin->pool, VERSIONS, "/", last, "?current=", admin->current, NULL); request = apr_pstrcat(admin->pool, admin->pollUrl, "/", last, NULL); } char inputFile[256]; inputFile[0] = '\0'; char *test = inputFile; celix_status_t status = deploymentAdmin_download(request, &test); if (status == CELIX_SUCCESS) { bundle_pt bundle = NULL; bundleContext_getBundle(admin->context, &bundle); char *entry = NULL; bundle_getEntry(bundle, "/", &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. unzip_extractDeploymentPackage(test, tmpDir); char *manifest = apr_pstrcat(admin->pool, tmpDir, "/META-INF/MANIFEST.MF", NULL); manifest_pt mf = NULL; manifest_createFromFile(manifest, &mf); deployment_package_pt source = NULL; deploymentPackage_create(admin->pool, admin->context, mf, &source); char *name = NULL; deploymentPackage_getName(source, &name); 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); deploymentAdmin_deleteTree(repoCache, admin->pool); apr_status_t stat = apr_file_rename(tmpDir, repoCache, admin->pool); if (stat != APR_SUCCESS) { printf("No success\n"); } deployment_package_pt 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); deploymentAdmin_deleteTree(repoCache, admin->pool); deploymentAdmin_deleteTree(tmpDir, admin->pool); remove(test); admin->current = strdup(last); hashMap_put(admin->packages, name, source); } } } sleep(5); } apr_thread_exit(thd, APR_SUCCESS); return NULL; }