void get_named_object_partially() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; dpl_range_t range; banner("9 - get named object partially"); //first 1000 bytes range.start = 0; range.end = 999; atask = (dpl_async_task_t *) dpl_get_async_prepare(ctx, //the context NULL, //no bucket file3_path, //the key NULL, //no option DPL_FTYPE_REG, //object type NULL, //no condition &range); //range if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_get_named_object_partially; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void delete_object() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; fprintf(stderr, "delete object+MD\n"); atask = (dpl_async_task_t *) dpl_delete_async_prepare(ctx, //the context NULL, //no bucket new_path, //the key NULL, //no option DPL_FTYPE_UNDEF, //no matter the file type NULL); //no condition if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_delete_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void get_object() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; fprintf(stderr, "getting object+MD\n"); atask = (dpl_async_task_t *) dpl_get_async_prepare(ctx, //the context NULL, //no bucket new_path, //the key NULL, //no opion DPL_FTYPE_REG, //object type NULL, //no condition NULL); //no range if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_get_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void rename_object(char *resource_path) { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; snprintf(new_path, sizeof (new_path), "%su.1", folder); atask = (dpl_async_task_t *) dpl_copy_async_prepare(ctx, NULL, //no src bucket resource_path, //the src resource NULL, //no dst bucket new_path, //dst resource NULL, //no option DPL_FTYPE_REG, //regular file DPL_COPY_DIRECTIVE_MOVE, //rename NULL, //no metadata NULL, //no sysmd NULL); //no server side condition if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_rename_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void get_nameless_object() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; banner("7 - get nameless object data+metadata"); atask = (dpl_async_task_t *) dpl_get_id_async_prepare(ctx, //the context NULL, //no bucket id1, //the key NULL, //no opion DPL_FTYPE_REG, //object type NULL, //no condition NULL); //no range if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_get_nameless_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void get_metadata() { dpl_async_task_t *atask = NULL; fprintf(stderr, "getting MD only\n"); atask = (dpl_async_task_t *) dpl_head_async_prepare(ctx, //the context NULL, //no bucket, new_path, //the key NULL, //no option DPL_FTYPE_UNDEF, //no matter the file type NULL); //no condition, if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_get_metadata; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void list_bucket() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; int i; fprintf(stderr, "listing of folder\n"); atask = (dpl_async_task_t *) dpl_list_bucket_async_prepare(ctx, NULL, folder, "/"); if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_list_bucket; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void get_object_meta() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; banner("10 - get object meta"); atask = (dpl_async_task_t *) dpl_head_async_prepare(ctx, //the context NULL, //no bucket file3_path, //the key NULL, //no opion DPL_FTYPE_REG, //object type NULL); //no condition if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_get_object_meta; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void make_folder() { dpl_status_t ret, ret2; dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; banner("creating folder"); buf = dpl_buf_new(); if (NULL == buf) exit(1); atask = (dpl_async_task_t *) dpl_put_async_prepare(ctx, //the context NULL, //no bucket folder, //the folder NULL, //no option DPL_FTYPE_DIR, //directory NULL, //no condition NULL, //no range NULL, //no metadata NULL, //no sysmd buf); //object body if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_make_folder; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void copy_nameless_object_with_new_md() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; dpl_dict_t *metadata = NULL; banner("11 - copy nameless object with new metadata"); metadata = dpl_dict_new(13); if (NULL == metadata) { ret = DPL_ENOMEM; exit(1); } ret = dpl_dict_add(metadata, "bar", "qux", 0); if (DPL_SUCCESS != ret) { fprintf(stderr, "error updating metadatum: %s (%d)\n", dpl_status_str(ret), ret); exit(1); } /* * note: With Dewpoint, it would be possible to copy nameless object into another nameless object. * Does it make sense ? for now we copy it into a named object */ atask = (dpl_async_task_t *) dpl_copy_id_async_prepare(ctx, NULL, //no src bucket id1, //the src resource NULL, //no dst bucket file1_path, //dst resource NULL, //no option DPL_FTYPE_REG, //regular file DPL_COPY_DIRECTIVE_COPY, //rename metadata, //metadata NULL, //no sysmd NULL); //no server side condition if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_copy_nameless_object_with_new_md; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void append_to_nonexisting_named_object_precond() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; dpl_condition_t condition; buf = dpl_buf_new(); if (NULL == buf) exit(1); buf->size = DATA_LEN; buf->ptr = malloc(buf->size); if (NULL == buf->ptr) { fprintf(stderr, "alloc data failed\n"); exit(1); } memset(buf->ptr, 'z', buf->size); banner("4 - append data to nonexisting named object with precondition"); condition.conds[0].type = DPL_CONDITION_IF_MATCH; condition.conds[0].etag[0] = '*'; condition.conds[0].etag[1] = 0; condition.n_conds = 1; atask = (dpl_async_task_t *) dpl_post_async_prepare(ctx, NULL, //no bucket file3_path, //the id NULL, //option DPL_FTYPE_REG, //regular object &condition, //expect failure if exists NULL, //range NULL, //the metadata NULL, //no sysmd buf, //object body NULL); //query params if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_append_to_nonexisting_named_object_precond; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void update_metadata_named_object() { dpl_async_task_t *atask = NULL; dpl_status_t ret; dpl_option_t option; dpl_dict_t *metadata = NULL; banner("6 - append metadata to existing named object"); metadata = dpl_dict_new(13); if (NULL == metadata) { ret = DPL_ENOMEM; exit(1); } ret = dpl_dict_add(metadata, "foo", "bar", 0); if (DPL_SUCCESS != ret) { fprintf(stderr, "error updating metadatum: %s (%d)\n", dpl_status_str(ret), ret); exit(1); } option.mask = DPL_OPTION_APPEND_METADATA; atask = (dpl_async_task_t *) dpl_put_async_prepare(ctx, NULL, //no bucket file3_path, //the id &option, //option DPL_FTYPE_REG, //regular object NULL, //condition NULL, //range metadata, //the metadata NULL, //no sysmd NULL); //object body dpl_dict_free(metadata); if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_update_metadata_named_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void add_existing_named_object() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; dpl_condition_t condition; buf = dpl_buf_new(); if (NULL == buf) exit(1); buf->size = DATA_LEN; buf->ptr = malloc(buf->size); if (NULL == buf->ptr) { fprintf(stderr, "alloc data failed\n"); exit(1); } memset(buf->ptr, 'y', buf->size); banner("3 - add existing named object with precondition"); condition.mask = DPL_CONDITION_IF_NONE_MATCH; condition.etag[0] = '*'; condition.etag[1] = 0; atask = (dpl_async_task_t *) dpl_put_async_prepare(ctx, NULL, //no bucket file2_path, //the id NULL, //no option DPL_FTYPE_REG, //regular object &condition, //expect failure if exists NULL, //no range NULL, //the metadata NULL, //no sysmd buf); //object body if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_add_existing_named_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void copy_named_object_with_new_md() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; dpl_dict_t *metadata = NULL; banner("12 - copy named object with new metadata"); metadata = dpl_dict_new(13); if (NULL == metadata) { ret = DPL_ENOMEM; exit(1); } ret = dpl_dict_add(metadata, "qux", "baz", 0); if (DPL_SUCCESS != ret) { fprintf(stderr, "error updating metadatum: %s (%d)\n", dpl_status_str(ret), ret); exit(1); } atask = (dpl_async_task_t *) dpl_copy_async_prepare(ctx, NULL, //no src bucket file1_path, //the src resource NULL, //no dst bucket file4_path, //dst resource NULL, //no option DPL_FTYPE_REG, //regular file DPL_COPY_DIRECTIVE_COPY, //rename metadata, //metadata NULL, //no sysmd NULL); //no server side condition if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_copy_named_object_with_new_md; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void add_nameless_object() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; buf = dpl_buf_new(); if (NULL == buf) exit(1); buf->size = DATA_LEN; buf->ptr = malloc(buf->size); if (NULL == buf->ptr) { fprintf(stderr, "alloc data failed\n"); exit(1); } memset(buf->ptr, 'x', buf->size); banner("1 - add nameless object"); atask = (dpl_async_task_t *) dpl_post_id_async_prepare(ctx, //the context NULL, //no bucket NULL, //no id NULL, //no option DPL_FTYPE_REG, //regular object NULL, //condition NULL, //range NULL, //the metadata NULL, //no sysmd buf, //object body NULL); //no query params if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_add_nameless_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void append_to_nonexisting_named_object() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; buf = dpl_buf_new(); if (NULL == buf) exit(1); buf->size = DATA_LEN; buf->ptr = malloc(buf->size); if (NULL == buf->ptr) { fprintf(stderr, "alloc data failed\n"); exit(1); } memset(buf->ptr, 'z', buf->size); banner("5 - append data to nonexisting named object"); atask = (dpl_async_task_t *) dpl_post_async_prepare(ctx, NULL, //no bucket file3_path, //the id NULL, //option DPL_FTYPE_REG, //regular object NULL, //no condition NULL, //range NULL, //the metadata NULL, //no sysmd buf, //object body NULL); //query params if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_append_to_nonexisting_named_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void update_metadata() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; fprintf(stderr, "setting MD only\n"); ret = dpl_dict_add(metadata, "foo", "bar2", 0); if (DPL_SUCCESS != ret) { fprintf(stderr, "error updating metadatum: %s (%d)\n", dpl_status_str(ret), ret); exit(1); } atask = (dpl_async_task_t *) dpl_copy_async_prepare(ctx, //the context NULL, //no src bucket new_path, //the key NULL, //no dst bucket new_path, //the same key NULL, //no option DPL_FTYPE_REG, //object type DPL_COPY_DIRECTIVE_METADATA_REPLACE, //tell server to replace metadata metadata, //the updated metadata NULL, //no sysmd NULL); //no condition if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_update_metadata; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void create_object() { dpl_async_task_t *atask = NULL; dpl_buf_t *buf = NULL; dpl_status_t ret; buf = dpl_buf_new(); if (NULL == buf) exit(1); buf->size = DATA_LEN; buf->ptr = malloc(DATA_LEN); if (NULL == buf->ptr) { fprintf(stderr, "alloc data failed\n"); exit(1); } memset(buf->ptr, 'z', buf->size); metadata = dpl_dict_new(13); if (NULL == metadata) { fprintf(stderr, "dpl_dict_new failed\n"); exit(1); } ret = dpl_dict_add(metadata, "foo", "bar", 0); if (DPL_SUCCESS != ret) { fprintf(stderr, "dpl_dict_add failed\n"); exit(1); } ret = dpl_dict_add(metadata, "foo2", "qux", 0); if (DPL_SUCCESS != ret) { fprintf(stderr, "dpl_dict_add failed\n"); exit(1); } fprintf(stderr, "atomic creation of an object+MD\n"); atask = (dpl_async_task_t *) dpl_post_async_prepare(ctx, //the context NULL, //no bucket folder, //the folder NULL, //no option DPL_FTYPE_REG, //regular object NULL, //condition NULL, //range metadata, //the metadata NULL, //no sysmd buf, //object body NULL); //no query params if (NULL == atask) { fprintf(stderr, "error preparing task\n"); exit(1); } atask->cb_func = cb_create_object; atask->cb_arg = atask; dpl_task_pool_put(pool, (dpl_task_t *) atask); }
void cb_list_bucket(void *handle) { dpl_async_task_t *atask = (dpl_async_task_t *) handle; int i; if (DPL_SUCCESS != atask->ret) { fprintf(stderr, "error listing folder: %s (%d)\n", dpl_status_str(atask->ret), atask->ret); exit(1); } pthread_mutex_init(&list_lock, NULL); pthread_cond_init(&list_cond, NULL); for (i = 0;i < atask->u.list_bucket.objects->n_items;i++) { dpl_object_t *obj = (dpl_object_t *) dpl_vec_get(atask->u.list_bucket.objects, i); dpl_sysmd_t obj_sysmd; dpl_dict_t *obj_md = NULL; dpl_async_task_t *sub_atask = NULL; fprintf(stderr, "getting md\n"); sub_atask = (dpl_async_task_t *) dpl_head_async_prepare(ctx, NULL, //no bucket obj->path, NULL, //option DPL_FTYPE_UNDEF, //no matter the file type NULL); //condition if (NULL == sub_atask) { fprintf(stderr, "error preparing task\n"); exit(1); } sub_atask->cb_func = cb_head_object; sub_atask->cb_arg = sub_atask; dpl_task_pool_put(pool, (dpl_task_t *) sub_atask); } for (i = 0;i < atask->u.list_bucket.common_prefixes->n_items;i++) { dpl_common_prefix_t *dir = (dpl_common_prefix_t *) dpl_vec_get(atask->u.list_bucket.common_prefixes, i); fprintf(stderr, "dir %s\n", dir->prefix); } again: pthread_cond_wait(&list_cond, &list_lock); //printf("n_ok=%d\n", n_ok); if (n_ok != atask->u.list_bucket.objects->n_items) goto again; dpl_async_task_free(atask); delete_object(); }