Commit 779a4105 authored by Ramon Nou's avatar Ramon Nou
Browse files

Merge branch 'amiranda/99-refactor-rpc-implementation-of-admire-register_pfs_storage' into 'main'

Resolve "Refactor RPC implementation of `admire::register_pfs_storage`"

This MR moves the implementation of the RPC construction for
`ADM_register_pfs_storage` to `admire::detail` in `impl.[ch]pp`
similarly to other RPCs already refactored. This includes changing
the C ADM_types to native C++ types.

Closes #99

See merge request !68
parents 721d0eb0 98de9313
Loading
Loading
Loading
Loading
Loading
+44 −17
Original line number Diff line number Diff line
@@ -25,11 +25,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <admire.h>
#include <assert.h>
#include "common.h"

#define NINPUTS  10
#define NOUTPUTS 5

int
main(int argc, char* argv[]) {
@@ -41,28 +36,60 @@ main(int argc, char* argv[]) {
    }

    int exit_status = EXIT_SUCCESS;
    ADM_server_t server = ADM_server_create("tcp", argv[1]);
    ADM_return_t ret = ADM_SUCCESS;
    ADM_server_t server = NULL;

    // pfs information
    const char* pfs_name = "gpfs_scratch";
    const char* pfs_mount = "/gpfs/scratch";
    ADM_pfs_context_t pfs_ctx = NULL;
    ADM_pfs_storage_t pfs_storage = NULL;

    ADM_pfs_storage_t pfs_storage;
    // Let's prepare all the information required by the API calls.
    // ADM_register_pfs_storage() requires a set of nodes for the PFS
    // storage to use and an appropriate execution context defining how it
    // should behave:

    ADM_pfs_context_t ctx = ADM_pfs_context_create("/gpfs");
    assert(ctx);
    // 1. define the PFS execution context
    pfs_ctx = ADM_pfs_context_create(pfs_mount);

    ADM_return_t ret = ADM_register_pfs_storage(server, ctx, &pfs_storage);
    if(pfs_ctx == NULL) {
        fprintf(stderr, "Fatal error preparing PFS context\n");
        goto cleanup;
    }

    // All the information required by the ADM_register_pfs_storage() API is
    // now ready. Let's actually contact the server:

    // 1. Find the server endpoint
    if((server = ADM_server_create("tcp", argv[1])) == NULL) {
        fprintf(stderr, "Fatal error creating server\n");
        goto cleanup;
    }

    if(ret != ADM_SUCCESS) {
        fprintf(stderr,
                "ADM_register_pfs_storage() remote procedure not completed "
                "successfully: %s\n",
    // 2. Register the adhoc storage
    if(ADM_register_pfs_storage(server, pfs_name, ADM_PFS_STORAGE_GPFS, pfs_ctx,
                                &pfs_storage) != ADM_SUCCESS) {
        fprintf(stderr, "ADM_register_pfs_storage() failed: %s\n",
                ADM_strerror(ret));
        exit_status = EXIT_FAILURE;
        goto cleanup;
    }

    fprintf(stdout, "ADM_register_pfs_storage() remote procedure completed "
                    "successfully\n");
    // The PFS storage is now registered into the system :)
    exit_status = EXIT_SUCCESS;

    // Once the PFS storage is no longer required we need to notify the server
    if((ret = ADM_remove_pfs_storage(server, pfs_storage)) != ADM_SUCCESS) {
        fprintf(stderr, "ADM_remove_pfs_storage() failed: %s\n",
                ADM_strerror(ret));
        pfs_storage = NULL;
        exit_status = EXIT_FAILURE;
        // intentionally fall through...
    }

cleanup:
    ADM_server_destroy(server);
    ADM_pfs_context_destroy(pfs_ctx);

    exit(exit_status);
}
+40 −21
Original line number Diff line number Diff line
@@ -37,41 +37,60 @@ main(int argc, char* argv[]) {
    }

    int exit_status = EXIT_SUCCESS;
    ADM_server_t server = ADM_server_create("tcp", argv[1]);
    ADM_return_t ret = ADM_SUCCESS;
    ADM_server_t server = NULL;

    ADM_pfs_context_t ctx = ADM_pfs_context_create("/gpfs");
    assert(ctx);
    // pfs information
    const char* pfs_name = "gpfs_scratch";
    const char* pfs_mount = "/gpfs/scratch";
    ADM_pfs_context_t pfs_ctx = NULL;
    ADM_pfs_storage_t pfs_storage = NULL;

    ADM_pfs_storage_t pfs_storage;
    ADM_return_t ret = ADM_register_pfs_storage(server, ctx, &pfs_storage);
    // Let's prepare all the information required by the API calls.
    // ADM_remove_pfs_storage() obviously requires a PFS storage to have
    // been registered onto the system, so let's prepare first the data required
    // to call ADM_register_pfs_storage():

    if(ret != ADM_SUCCESS) {
        fprintf(stderr,
                "ADM_register_pfs_storage() remote procedure not completed "
                "successfully: %s\n",
                ADM_strerror(ret));
        exit_status = EXIT_FAILURE;
    // 1. define the PFS execution context
    pfs_ctx = ADM_pfs_context_create(pfs_mount);

    if(pfs_ctx == NULL) {
        fprintf(stderr, "Fatal error preparing PFS context\n");
        goto cleanup;
    }

    // All the information required by the ADM_register_pfs_storage() API is
    // now ready. Let's actually contact the server:

    // 1. Find the server endpoint
    if((server = ADM_server_create("tcp", argv[1])) == NULL) {
        fprintf(stderr, "Fatal error creating server\n");
        goto cleanup;
    }

    fprintf(stdout, "ADM_register_pfs_storage() remote procedure completed "
                    "successfully\n");
    // 2. Register the adhoc storage
    if(ADM_register_pfs_storage(server, pfs_name, ADM_PFS_STORAGE_GPFS, pfs_ctx,
                                &pfs_storage) != ADM_SUCCESS) {
        fprintf(stderr, "ADM_register_pfs_storage() failed: %s\n",
                ADM_strerror(ret));
        goto cleanup;
    }

    ret = ADM_remove_pfs_storage(server, pfs_storage);
    // Now that we have an existing PFS storage registered into the system
    // we can try to remove it...

    if(ret != ADM_SUCCESS) {
        fprintf(stderr,
                "ADM_remove_pfs_storage() remote procedure not completed "
                "successfully: %s\n",
    if((ret = ADM_remove_pfs_storage(server, pfs_storage)) != ADM_SUCCESS) {
        fprintf(stderr, "ADM_remove_pfs_storage() failed: %s\n",
                ADM_strerror(ret));
        exit_status = EXIT_FAILURE;
        goto cleanup;
    }

    fprintf(stdout, "ADM_remove_pfs_storage() remote procedure completed "
                    "successfully\n");
    // Everything is fine now...
    exit_status = EXIT_SUCCESS;

cleanup:
    ADM_server_destroy(server);
    ADM_pfs_context_destroy(pfs_ctx);

    exit(exit_status);
}
+59 −20
Original line number Diff line number Diff line
@@ -37,41 +37,80 @@ main(int argc, char* argv[]) {
    }

    int exit_status = EXIT_SUCCESS;
    ADM_server_t server = ADM_server_create("tcp", argv[1]);
    ADM_return_t ret = ADM_SUCCESS;
    ADM_server_t server = NULL;

    ADM_pfs_context_t ctx = ADM_pfs_context_create("/gpfs");
    assert(ctx);
    // pfs information
    const char* pfs_name = "gpfs_scratch";
    const char* pfs_mount = "/gpfs/scratch";
    const char* new_pfs_mount = "/gpfs/scratch2";
    ADM_pfs_context_t pfs_ctx = NULL;
    ADM_pfs_context_t new_pfs_ctx = NULL;
    ADM_pfs_storage_t pfs_storage = NULL;

    ADM_pfs_storage_t pfs_storage;
    ADM_return_t ret = ADM_register_pfs_storage(server, ctx, &pfs_storage);
    // Let's prepare all the information required by the API calls.
    // ADM_register_pfs_storage() requires a set of nodes for the PFS
    // storage to use and an appropriate execution context defining how it
    // should behave:

    if(ret != ADM_SUCCESS) {
        fprintf(stderr,
                "ADM_register_pfs_storage() remote procedure not completed "
                "successfully: %s\n",
    // 1. define the PFS execution context
    pfs_ctx = ADM_pfs_context_create(pfs_mount);

    if(pfs_ctx == NULL) {
        fprintf(stderr, "Fatal error preparing PFS context\n");
        goto cleanup;
    }

    // All the information required by the ADM_register_pfs_storage() API is
    // now ready. Let's actually contact the server:

    // 1. Find the server endpoint
    if((server = ADM_server_create("tcp", argv[1])) == NULL) {
        fprintf(stderr, "Fatal error creating server\n");
        goto cleanup;
    }

    // 2. Register the adhoc storage
    if(ADM_register_pfs_storage(server, pfs_name, ADM_PFS_STORAGE_GPFS, pfs_ctx,
                                &pfs_storage) != ADM_SUCCESS) {
        fprintf(stderr, "ADM_register_pfs_storage() failed: %s\n",
                ADM_strerror(ret));
        exit_status = EXIT_FAILURE;
        goto cleanup;
    }

    fprintf(stdout, "ADM_register_pfs_storage() remote procedure completed "
                    "successfully\n");
    // Now that we have an existing PFS storage registered into the
    // system, let's prepare a new execution context for the PFS
    // storage system
    new_pfs_ctx = ADM_pfs_context_create(new_pfs_mount);

    ret = ADM_update_pfs_storage(server, ctx, pfs_storage);
    if(new_pfs_ctx == NULL) {
        fprintf(stderr, "Fatal error preparing new PFS context\n");
        goto cleanup;
    }

    if(ret != ADM_SUCCESS) {
        fprintf(stderr,
                "ADM_update_pfs_storage() remote procedure not completed "
                "successfully: %s\n",
    // We can now request the update to the server
    if((ret = ADM_update_pfs_storage(server, new_pfs_ctx, pfs_storage)) !=
       ADM_SUCCESS) {
        fprintf(stderr, "ADM_update_pfs_storage() failed: %s\n",
                ADM_strerror(ret));
        exit_status = EXIT_FAILURE;
        goto cleanup;
    }

    fprintf(stdout, "ADM_update_pfs_storage() remote procedure completed "
                    "successfully\n");
    // At this point, the PFS storage has been updated...
    exit_status = EXIT_SUCCESS;

    // Once the PFS storage is no longer required we need to notify the server
    if((ret = ADM_remove_pfs_storage(server, pfs_storage)) != ADM_SUCCESS) {
        fprintf(stderr, "ADM_remove_pfs_storage() failed: %s\n",
                ADM_strerror(ret));
        pfs_storage = NULL;
        exit_status = EXIT_FAILURE;
        // intentionally fall through...
    }

cleanup:
    ADM_server_destroy(server);
    ADM_pfs_context_destroy(pfs_ctx);

    exit(exit_status);
}
+5 −11
Original line number Diff line number Diff line
@@ -38,25 +38,19 @@ main(int argc, char* argv[]) {

    admire::server server{"tcp", argv[1]};

    ADM_pfs_context_t ctx{};
    ADM_pfs_storage_t pfs_storage{};
    ADM_return_t ret = ADM_SUCCESS;
    std::string pfs_name = "gpfs_scratch";
    std::string pfs_mount = "/gpfs/scratch";

    try {
        ret = admire::register_pfs_storage(server, ctx, &pfs_storage);
        admire::register_pfs_storage(server, pfs_name,
                                     admire::pfs_storage::type::gpfs,
                                     admire::pfs_storage::ctx{pfs_mount});
    } catch(const std::exception& e) {
        fmt::print(stderr, "FATAL: ADM_register_pfs_storage() failed: {}\n",
                   e.what());
        exit(EXIT_FAILURE);
    }

    if(ret != ADM_SUCCESS) {
        fmt::print(stdout,
                   "ADM_register_pfs_storage() remote procedure not completed "
                   "successfully\n");
        exit(EXIT_FAILURE);
    }

    fmt::print(stdout, "ADM_register_pfs_storage() remote procedure completed "
                       "successfully\n");
}
+4 −4
Original line number Diff line number Diff line
@@ -510,11 +510,11 @@ ADM_adhoc_context_destroy(ADM_adhoc_context_t ctx);
 * @param[in] pfs_ctx Some specific context information for the storage
 * tier or NULL if none is required. For instance, an adhoc storage system may
 * find it useful to provide an ADM_adhoc_context_t describing the instance.
 * @return A valid ADM_ADHOC_STORAGE if successful, or NULL in case of failure.
 * @return A valid ADM_PFS_STORAGE if successful, or NULL in case of failure.
 */
ADM_adhoc_storage_t
ADM_pfs_storage_create(const char* name, ADM_adhoc_storage_type_t type,
                       uint64_t id, ADM_adhoc_context_t adhoc_ctx);
ADM_pfs_storage_t
ADM_pfs_storage_create(const char* name, ADM_pfs_storage_type_t type,
                       uint64_t id, ADM_pfs_context_t pfs_ctx);

/**
 * Destroy an ADM_ADHOC_STORAGE created by ADM_adhoc_storage_destroy().
Loading