client.c 3.38 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#include <margo.h>
#include <remi/remi-client.h>

int main(int argc, char** argv)
{
    if(argc < 5) {
        fprintf(stderr, "Usage: %s <server-address> <local-root> <dest-root> file1 [ file2 ...\n", argv[0]);
        return -1;
    }

    int ret                        = 0;
    hg_return_t hret               = HG_SUCCESS;
    char** filenames               = argv+4;
    unsigned num_files             = argc-4;
    char* server_addr_str          = argv[1];
    char* local_root               = argv[2];
    char* remote_root              = argv[3];
    margo_instance_id mid          = MARGO_INSTANCE_NULL;
    remi_client_t remi_clt         = REMI_CLIENT_NULL;
    remi_provider_handle_t remi_ph = REMI_PROVIDER_HANDLE_NULL;
    hg_addr_t svr_addr             = HG_ADDR_NULL;
    remi_fileset_t fileset         = REMI_FILESET_NULL;

    // initialize margo
    unsigned i;
    char cli_addr_prefix[64] = {0};
    for(i=0; (i<63 && server_addr_str[i] != '\0' && server_addr_str[i] != ':'); i++)
        cli_addr_prefix[i] = server_addr_str[i];

    mid = margo_init(cli_addr_prefix, MARGO_CLIENT_MODE, 0, 0);
    if(mid == MARGO_INSTANCE_NULL) {
        fprintf(stderr, "ERROR: margo_initialize()\n");
        ret = -1;
        goto error;
    }

    // initialize REMI client
    ret = remi_client_init(mid, &remi_clt);
    if(ret != REMI_SUCCESS) {
        fprintf(stderr, "ERROR: remi_client_init() returned %d\n", ret);
        ret = -1;
        goto error;
    }

    // lookup server address
    hret = margo_addr_lookup(mid, server_addr_str, &svr_addr);
    if(hret != HG_SUCCESS) {
        fprintf(stderr, "ERROR: margo_addr_lookup() returned %d\n", hret);
        ret = -1;
        goto error;
    }

    // create REMI provider handle
    ret = remi_provider_handle_create(remi_clt, svr_addr, 1, &remi_ph);
    if(ret != REMI_SUCCESS) {
        fprintf(stderr, "ERROR: remi_provider_handle_create() returned %d\n", ret);
        ret = -1;
        goto error;
    }

    // create a fileset
    ret = remi_fileset_create("my_migration_class", local_root, &fileset);
    if(ret != REMI_SUCCESS) {
        fprintf(stderr, "ERROR: remi_fileset_create() returned %d\n", ret);
        ret = -1;
        goto error;
    }

    // fill the fileset with file paths
    for(i=0; i < num_files; i++) {
        ret = remi_fileset_register_file(fileset, filenames[i]);
        if(ret != REMI_SUCCESS) {
            fprintf(stderr, "ERROR: remi_fileset_register_file() returned %d\n", ret);
            ret = -1;
            goto error;
        }
    }

    // fill the fileset with some metadata
    ret = remi_fileset_register_metadata(fileset, "ABC", "DEF");
    if(ret != REMI_SUCCESS) {
        fprintf(stderr, "ERROR: remi_fileset_register_metadata() returned %d\n", ret);
        ret = -1;
        goto error;
    }
    remi_fileset_register_metadata(fileset, "AERED", "qerqwer");

    // migrate the fileset
    ret =  remi_fileset_migrate(remi_ph, fileset, remote_root, REMI_KEEP_SOURCE);
    if(ret != REMI_SUCCESS) {
        fprintf(stderr, "ERROR: remi_fileset_migrate() returned %d\n", ret);
        ret = -1;
        goto error;
    }

96 97 98
    // shut down the server
    remi_shutdown_service(remi_clt, svr_addr);

Matthieu Dorier's avatar
Matthieu Dorier committed
99 100 101 102 103 104 105 106 107 108 109
finish:
    // cleanup
    remi_fileset_free(fileset);
    remi_provider_handle_release(remi_ph);
    margo_addr_free(mid, svr_addr);
    remi_client_finalize(remi_clt);
    margo_finalize(mid);
    return ret;
error:
    goto finish;
}