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; }
void updateCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)) { bundle_pt bundle = NULL; char delims[] = " "; char * sub = NULL; char outString[256]; sub = strtok(line, delims); sub = strtok(NULL, delims); if (sub == NULL) { err("Incorrect number of arguments.\n"); sprintf(outString, "%s\n", command->usage); out(outString); } else { long id = atol(sub); bundleContext_getBundleById(command->bundleContext, id, &bundle); if (bundle != NULL) { char inputFile[256]; sub = strtok(NULL, delims); inputFile[0] = '\0'; if (sub != NULL) { char *test = inputFile; printf("URL: %s\n", sub); if (updateCommand_download(command, sub, &test) == CELIX_SUCCESS) { printf("Update bundle with stream\n"); bundle_update(bundle, inputFile); } else { char error[256]; sprintf(error, "Unable to download from %s\n", sub); err(error); } } else { bundle_update(bundle, NULL); } } else { err("Bundle id is invalid.\n"); } } }
bundle_status_t bundle_step (bundle_t *bundle, int max_qp_iterations, double subgnorm_opt_tol, double linerr_opt_tol, double z_cutoff, void* data, double (*bundle_callback) (void*, double*, double*), double init_scale, double acceptable_model_exactness) /* * Performs one iteration of the bundle method: * - max_qp_iterations: maximum enumerations of mask to solve QP * - subgnorm_opt_tol: threshold below which a subgradient norm are deemed to be zero, * - linerr_opt_tol: threshold below which a linearization error is deemed to be zero, * - z_cutoff: threshold above which z no longer needs to be maximized any further, * - data: a pointer passed on to bundle_callback, * - double bundle_callback(void *data, double *x, double *subg): must evalute and return z at x, writing the subgradient at x in subg. * - init_scale: initial penalty parameter * - acceptable_model_exactness: if the ratio between actual and predicted improvement is above this value, then the bundle method performs a major step, */ { int new_subg_i = -1; double roh; double previous_best_z = bundle->best_z; double *new_subg = NULL; double subg_delta, linerr_opt_delta, agg_subg_square; int i; //printf("it: %i\tpen: %f\t", bundle->n_iterations, bundle->scale); // guess where the x yielding the optimal z lies bundle->time_qp -= getutime(1); bundle->guessed_z = bundle_guess(bundle, max_qp_iterations); bundle->time_qp += getutime(1); linerr_opt_delta = bundle->agg_b - bundle->best_z; agg_subg_square = ddot(bundle->n, bundle->agg_subg, bundle->agg_subg); //printf("z-est: %f ", bundle->guessed_z); // update the bundle new_subg_i = bundle_update(bundle, agg_subg_square); // evaluate guessed x and subgradient at guessed x new_subg = &bundle->a[new_subg_i * bundle->n]; bundle->time_callback -= getutime(1); bundle->actual_z = bundle_callback(data, bundle->x, new_subg); bundle->time_callback += getutime(1); // update maximums if (bundle->actual_z > bundle->max_z) { bundle->max_z = bundle->actual_z; memcpy(bundle->max_x, bundle->x, bundle->n * sizeof(double)); if (bundle->max_z >= z_cutoff) { //printf("(%f)*\tcutoff\n", bundle->actual_z); return bundle_status_cutoff; } } //printf("(%f)%c\t", bundle->actual_z, (bundle->actual_z == bundle->max_z) ? '*' : ' '); // update A.A^T with new subgradient for (i = 0; i < bundle->m; i++) bundle->aat[i * bundle->max_m + new_subg_i] = bundle->aat[new_subg_i * bundle->max_m + i] = ddot(bundle->n, &bundle->a[i * bundle->n], new_subg); // check for optimality, i.e. if new subgradient is a null vector if (bundle->aat[new_subg_i * bundle->max_m + new_subg_i] < bundle->epsilon) { //printf("optimal\n"); return bundle_status_optimal; } //printf("agg.err: %f\tagg.norm: %f\t", linerr_opt_delta, sqrt(agg_subg_square)); if (linerr_opt_delta <= linerr_opt_tol && agg_subg_square <= subgnorm_opt_tol * subgnorm_opt_tol) { //printf("optimal withing tolerances\n"); return bundle_status_tolerably_optimal; } // check improvement roh = (bundle->actual_z - previous_best_z) / (bundle->guessed_z - previous_best_z + bundle->epsilon); //printf("roh: %.2f\t", roh); if (roh >= acceptable_model_exactness) { // Major Step // update penalization parameter bundle->scale daxpy(bundle->n, -1.0, new_subg, bundle->best_subg); subg_delta = ddot(bundle->n, bundle->best_subg, bundle->best_subg); bundle->scale = (subg_delta == 0.0) ? init_scale : (1.0 / (1.0 / bundle->scale + ddot(bundle->n, bundle->kkt_x, bundle->best_subg) / subg_delta)); // center the penalized QP to new maximum bundle->best_z = bundle->actual_z; memcpy(bundle->best_x, bundle->x, bundle->n * sizeof(double)); memcpy(bundle->best_subg, new_subg, bundle->n * sizeof(double)); // update QP rhs for new center memcpy(bundle->b, bundle->next_b, bundle->max_m * sizeof(double)); bundle->b[new_subg_i] = bundle->actual_z; // the most recent subgradient may not be active bundle->most_recent_i = -1; //printf("major step\n"); return bundle_status_major_step; } else { // Minor Step // update rhs for new subgradient for existing center bundle->b[new_subg_i] = bundle->actual_z - ddot(bundle->n, new_subg, bundle->kkt_x); //printf("\n"); // the most recent subgradient is certainly active bundle->most_recent_i = new_subg_i; return bundle_status_minor_step; } }