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; }
/** * Loop through all bundles and look for the bundle with the keys inside. * If no key bundle found, return NULL * * Caller is responsible for freeing the object */ char* pubsub_getKeysBundleDir(bundle_context_pt ctx) { array_list_pt bundles = NULL; bundleContext_getBundles(ctx, &bundles); int nrOfBundles = arrayList_size(bundles); long bundle_id = -1; char* result = NULL; for (int i = 0; i < nrOfBundles; i++){ bundle_pt b = arrayList_get(bundles, i); /* Skip bundle 0 (framework bundle) since it has no path nor revisions */ bundle_getBundleId(b, &bundle_id); if(bundle_id==0){ continue; } char* dir = NULL; bundle_getEntry(b, ".", &dir); char cert_dir[MAX_KEYBUNDLE_LENGTH]; snprintf(cert_dir, MAX_KEYBUNDLE_LENGTH, "%s/META-INF/keys", dir); struct stat s; int err = stat(cert_dir, &s); if (err != -1){ if (S_ISDIR(s.st_mode)){ result = dir; break; } } free(dir); } arrayList_destroy(bundles); return result; }
static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) { celix_status_t status = CELIX_SUCCESS; char *descriptorFile = NULL; char name[128]; snprintf(name, 128, "%s.descriptor", import->classObject); status = bundle_getEntry(bundle, name, &descriptorFile); if (descriptorFile == NULL) { printf("Cannot find entry '%s'\n", name); status = CELIX_ILLEGAL_ARGUMENT; } else { printf("Found descriptor at '%s'\n", descriptorFile); } struct service_proxy *proxy = NULL; if (status == CELIX_SUCCESS) { proxy = calloc(1, sizeof(*proxy)); if (proxy == NULL) { status = CELIX_ENOMEM; } } if (status == CELIX_SUCCESS) { FILE *df = fopen(descriptorFile, "r"); if (df != NULL) { int rc = dynInterface_parse(df, &proxy->intf); fclose(df); if (rc != 0) { status = CELIX_BUNDLE_EXCEPTION; } } } if (status == CELIX_SUCCESS) { size_t count = dynInterface_nrOfMethods(proxy->intf); proxy->service = calloc(1 + count, sizeof(void *)); if (proxy->service == NULL) { status = CELIX_ENOMEM; } } if (status == CELIX_SUCCESS) { void **serv = proxy->service; serv[0] = import; struct methods_head *list = NULL; dynInterface_methods(proxy->intf, &list); struct method_entry *entry = NULL; void (*fn)(void) = NULL; int index = 0; TAILQ_FOREACH(entry, list, entries) { int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn); serv[index + 1] = fn; index += 1; if (rc != 0) { status = CELIX_BUNDLE_EXCEPTION; break; } }
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; }