Verified Commit 1a66c869 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

API: Add user level library for `scord`

parent 13aa7293
Loading
Loading
Loading
Loading
Loading
+104 −0
Original line number Diff line number Diff line
/******************************************************************************
 * Copyright 2021-2023, Barcelona Supercomputing Center (BSC), Spain
 *
 * This software was partially supported by the EuroHPC-funded project ADMIRE
 *   (Project ID: 956748, https://www.admire-eurohpc.eu).
 *
 * This file is part of scord.
 *
 * scord is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * scord is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with scord.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *****************************************************************************/

#include <scord/scord-user.h>
#include <stdio.h>
#include "common.h"

int
main(int argc, char** argv) {

    enum { N = 5 };

    test_info_t test_info = {
            .name = TESTNAME,
            .requires_server = true,
            .requires_controller = true,
    };

    cli_args_t cli_args;
    if(process_args(argc, argv, test_info, &cli_args)) {
        exit(EXIT_FAILURE);
    }

    const char* paths[N] = {"input00.dat", "inpu01.dat", "input02.dat",
                            "input03.dat", "input04.dat"};

    ADM_dataset_t sources[N];
    ADM_dataset_t targets[N];

    for(size_t i = 0; i < N; ++i) {
        sources[i] = ADM_dataset_create(/*"lustre", */ paths[i]);
        targets[i] = ADM_dataset_create(/*"gekkofs",*/ paths[i]);

        if(!sources[i] || !targets[i]) {
            abort();
        }
    }

    ADM_return_t ret = ADM_SUCCESS;
    ADM_transfer_t tx;

    // the library will automatically route the request to the `scord`
    // server configured in the cluster
    if((ret = ADM_transfer_datasets(sources, N, targets, N, &tx)) !=
       ADM_SUCCESS) {
        fprintf(stderr, "ADM_transfer_datasets() failed: %s\n",
                ADM_strerror(ret));
        abort();
    }

    ADM_transfer_status_t status;
    do {
        struct timespec timeout = {.tv_sec = 1, .tv_nsec = 0};
        // Wait for the transfer to complete
        ret = ADM_transfer_wait(tx, &status, &timeout);

        if(ret != ADM_SUCCESS && ret != ADM_ETIMEOUT) {
            fprintf(stderr, "ADM_transfer_wait() failed: %s\n",
                    ADM_strerror(ret));
            abort();
        }

        if(ADM_TRANSFER_SUCCEEDED(status)) {
            fprintf(stdout, "Transfer completed successfully\n");
        } else if(ADM_TRANSFER_FAILED(status)) {
            fprintf(stderr, "Transfer failed: %s\n",
                    ADM_strerror(ADM_TRANSFER_ERROR(status)));
        } else if(ADM_TRANSFER_PENDING(status)) {
            fprintf(stdout, "Transfer pending\n");
            continue;
        } else if(ADM_TRANSFER_IN_PROGRESS(status)) {
            fprintf(stdout, "Transfer in progress\n");
            continue;
        } else {
            fprintf(stderr, "Transfer status unknown\n");
            abort();
        }
    } while(!ADM_TRANSFER_SUCCEEDED(status));

    free(status);

    return 0;
}
+17 −1
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ list(APPEND c_examples_with_controller
  # transfers
  ADM_transfer_datasets ADM_get_transfer_priority ADM_set_transfer_priority
  ADM_cancel_transfer ADM_get_pending_transfers
  # transfers (user)
  ADM_transfer_datasets_user
  # qos
  ADM_set_qos_constraints ADM_get_qos_constraints
  # data operations
@@ -55,7 +57,15 @@ target_link_libraries(c_examples_common libscord_c_types)
foreach(example IN LISTS c_examples_with_controller c_examples_without_controller)
  add_executable(${example}_c)
  target_sources(${example}_c PRIVATE ${example}.c)
  target_link_libraries(${example}_c PUBLIC libscord c_examples_common)

  if (example MATCHES "^.*_user$")
    target_link_libraries(${example}_c PUBLIC libscord-user)
  else ()
    target_link_libraries(${example}_c PUBLIC libscord)
  endif ()

  target_link_libraries(${example}_c PUBLIC c_examples_common)

  set_target_properties(${example}_c PROPERTIES OUTPUT_NAME ${example})
endforeach()

@@ -92,6 +102,12 @@ if(SCORD_BUILD_TESTS)
      )
  endforeach()

  # Disable until we have more than stubs for the user library
  set_tests_properties(run_ADM_transfer_datasets_user_c_test
    PROPERTIES DISABLED TRUE)
  set_tests_properties(validate_ADM_transfer_datasets_user_c_test
    PROPERTIES DISABLED TRUE)

  foreach(example IN LISTS c_examples_without_controller)

    # prepare environment for the RPC test itself and its validation test
+35 −2
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ target_link_libraries(
set_property(TARGET libscord_cxx_types PROPERTY POSITION_INDEPENDENT_CODE ON)

################################################################################
# Create a target for the actual library that will be used by clients
# Create a target for the actual library that will be used by admin clients
################################################################################
add_library(libscord SHARED)

@@ -107,8 +107,41 @@ target_link_libraries(

set_target_properties(libscord PROPERTIES OUTPUT_NAME "scord")

################################################################################
# Create a target for the actual library that will be used by users
################################################################################
add_library(libscord-user SHARED)

target_sources(
  libscord-user
  PUBLIC scord/scord-user.h
  PRIVATE libscord-user.c
)

set(public_headers, "")
list(APPEND public_headers "scord/scord-user.h")

set_target_properties(libscord-user PROPERTIES PUBLIC_HEADER
  "${public_headers}")

target_include_directories(
  libscord-user PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  $<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

target_link_libraries(
  libscord-user
  PRIVATE common::network::rpc_client
  PUBLIC libscord_c_types
)

set_target_properties(libscord-user PROPERTIES OUTPUT_NAME "scord-user")

################################################################################
# Install the libraries
################################################################################
install(
  TARGETS libscord libscord_c_types libscord_cxx_types
  TARGETS libscord libscord-user libscord_c_types libscord_cxx_types
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ const char* const adm_errlist[ADM_ERR_MAX + 1] = {
                "Cannot create adhoc storage directory",
        [ADM_EADHOC_DIR_EXISTS] = "Adhoc storage directory already exists",
        [ADM_ESUBPROCESS_ERROR] = "Subprocess error",
        [ADM_ETIMEOUT] = "Timeout",
        [ADM_EOTHER] = "Undetermined error",

        /* fallback */
+88 −0
Original line number Diff line number Diff line
/******************************************************************************
 * Copyright 2021-2023, Barcelona Supercomputing Center (BSC), Spain
 *
 * This software was partially supported by the EuroHPC-funded project ADMIRE
 *   (Project ID: 956748, https://www.admire-eurohpc.eu).
 *
 * This file is part of scord.
 *
 * scord is free software: you can redistribute it and/or modify
 * it under the terms of the Lesser GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * scord is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the Lesser GNU General Public License
 * along with scord.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 *****************************************************************************/

#include <scord/scord-user.h>
#include "types_private.h"

ADM_return_t
ADM_transfer_datasets(ADM_dataset_t sources[], size_t sources_len,
                      ADM_dataset_t targets[], size_t targets_len,
                      ADM_transfer_t* transfer) {
    (void) sources;
    (void) sources_len;
    (void) targets;
    (void) targets_len;
    (void) transfer;

    return ADM_SUCCESS;
}


ADM_return_t
ADM_transfer_wait(ADM_transfer_t transfer, ADM_transfer_status_t* status,
                  struct timespec* timeout) {
    (void) transfer;
    (void) status;
    (void) timeout;

    if(transfer == NULL || status == NULL) {
        return ADM_EBADARGS;
    }

    *status = malloc(sizeof(struct adm_transfer_status));

    if(*status == NULL) {
        return ADM_ENOMEM;
    }

    (*status)->s_state = ADM_TRANSFER_FINISHED;
    (*status)->s_error = ADM_SUCCESS;

    return ADM_SUCCESS;
}

inline bool
__adm_transfer_succeeded(ADM_transfer_status_t st) {
    return st->s_state == ADM_TRANSFER_FINISHED && st->s_error == ADM_SUCCESS;
}

inline bool
__adm_transfer_failed(ADM_transfer_status_t st) {
    return st->s_state == ADM_TRANSFER_FINISHED && st->s_error != ADM_SUCCESS;
}

inline bool
__adm_transfer_pending(ADM_transfer_status_t st) {
    return st->s_state == ADM_TRANSFER_QUEUED;
}

inline bool
__adm_transfer_in_progress(ADM_transfer_status_t st) {
    return st->s_state == ADM_TRANSFER_RUNNING;
}

inline ADM_return_t
__adm_transfer_error(ADM_transfer_status_t st) {
    return st->s_error;
}
Loading