Commit a995481e authored by Matthieu Dorier's avatar Matthieu Dorier

added examples

parent 4512cdc9
add_executable(remi-test-client client.c)
target_link_libraries(remi-test-client remi)
add_executable(remi-test-server server.c)
target_link_libraries(remi-test-server remi)
#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;
}
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;
}
#include <stdio.h>
#include <margo.h>
#include <remi/remi-server.h>
void my_fileset_printer(const char* filename, void* uarg) {
(void)uarg;
fprintf(stdout," - %s\n", filename);
}
void my_metadata_printer(const char* key, const char* value, void* uarg) {
(void)uarg;
fprintf(stdout," - %s\t==>\t%s\n", key, value);
}
void my_migration_callback(remi_fileset_t fileset, void* uargs) {
fprintf(stdout, "Migration terminated.\n");
fprintf(stdout, "The following files were transfered:\n");
remi_fileset_foreach_file(fileset, my_fileset_printer, NULL);
fprintf(stdout, "Associated metadata:\n");
remi_fileset_foreach_metadata(fileset, my_metadata_printer, NULL);
}
int main(int argc, char** argv)
{
if(argc != 2) {
fprintf(stderr, "Usage: %s <listen-address>\n", argv[0]);
return -1;
}
hg_return_t hret = HG_SUCCESS;
int ret = 0;
char* listen_addr_str = argv[1];
uint16_t provider_id = 1;
margo_instance_id mid = MARGO_INSTANCE_NULL;
remi_provider_t remi_prov = REMI_PROVIDER_NULL;
hg_addr_t my_addr = HG_ADDR_NULL;
// initialize margo
mid = margo_init(listen_addr_str, MARGO_SERVER_MODE, 0, -1);
if(mid == MARGO_INSTANCE_NULL) {
return -1;
}
margo_enable_remote_shutdown(mid);
// get the address we are listening on
char my_addr_str[256] = {0};
size_t my_addr_size = 256;
hret = margo_addr_self(mid, &my_addr);
if(hret != HG_SUCCESS) {
fprintf(stderr, "ERROR: margo_addr_self() returned %d\n", hret);
ret = -1;
goto error;
}
hret = margo_addr_to_string(mid, my_addr_str, &my_addr_size, my_addr);
if(hret != HG_SUCCESS) {
fprintf(stderr, "ERROR: margo_addr_to_string() returned %d\n", hret);
ret = -1;
margo_addr_free(mid, my_addr);
goto error;
}
margo_addr_free(mid, my_addr);
fprintf(stdout,"Server running at address %s\n", my_addr_str);
// create the REMI provider
ret = remi_provider_register(mid, 1, REMI_ABT_POOL_DEFAULT, &remi_prov);
if(ret != REMI_SUCCESS) {
fprintf(stderr, "ERROR: remi_provider_register() returned %d\n", ret);
ret = -1;
goto error;
}
// create migration class
ret = remi_provider_register_migration_class(remi_prov,
"my_migration_class", my_migration_callback, NULL);
if(ret != REMI_SUCCESS) {
fprintf(stderr, "ERROR: remi_provider_register_migration_class() returned %d\n", ret);
ret = -1;
goto error;
}
// make margo wait for finalize
margo_wait_for_finalize(mid);
finish:
return ret;
error:
margo_finalize(mid);
goto finish;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment