diff --git a/CMakeLists.txt b/CMakeLists.txt index b3d0275..4a754a4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,45 +82,24 @@ include_directories("/usr/include/irods") # Generate the shared Library (= binary) from the source code # Note: unlike an Executable, a library does not contain a main method. It just contains the classes add_library(msi_getenv SHARED msi_getenv/msi_getenv.cpp) -#add_library(msi_http_send_file SHARED msi_http_send_file/msi_http_send_file.cpp) add_library(msi_json_arrayops SHARED msi_json_arrayops/libmsi_json_arrayops.cpp) add_library(msi_json_objops SHARED msi_json_objops/libmsi_json_objops.cpp) #add_library(msi_time_ts2str SHARED msi_time_ts2str/libmsi_time_ts2str.cpp) -#add_library(msi_unmount SHARED msi_unmount/unmount.cpp) -#add_library(msiput_dataobj_or_coll SHARED msiput_dataobj_or_coll/libmsiput_dataobj_or_coll.cpp) -#add_library(msi_amqp_basic_publish SHARED msi_amqp_basic_publish/msi_amqp_basic_publish.cpp) -add_library(msi_set_avu SHARED msi_set_avu/msi_set_avu.cpp) -add_library(msi_add_avu SHARED msi_add_avu/msi_add_avu.cpp) -add_library(msi_rmw_avu SHARED msi_rmw_avu/msi_rmw_avu.cpp) # Link the generated library to dependency libraries target_link_libraries(msi_getenv LINK_PUBLIC ${Boost_LIBRARIES}) -#target_link_libraries(msi_http_send_file LINK_PUBLIC ${Boost_LIBRARIES} ${CURL_LIBRARIES}) target_link_libraries(msi_json_arrayops LINK_PUBLIC ${JANSSON_LIBRARIES} ${Boost_LIBRARIES}) target_link_libraries(msi_json_objops LINK_PUBLIC ${JANSSON_LIBRARIES} ${Boost_LIBRARIES}) #target_link_libraries(msi_time_ts2str LINK_PUBLIC ${Boost_LIBRARIES}) -#target_link_libraries(msi_unmount LINK_PUBLIC ${Boost_LIBRARIES}) -#target_link_libraries(msiput_dataobj_or_coll LINK_PUBLIC ${Boost_LIBRARIES}) -#target_link_libraries(msi_amqp_basic_publish LINK_PUBLIC ${Boost_LIBRARIES} ${RABBITMQ_LIBRARIES}) -target_link_libraries(msi_set_avu LINK_PUBLIC ${Boost_LIBRARIES}) -target_link_libraries(msi_add_avu LINK_PUBLIC ${Boost_LIBRARIES}) -target_link_libraries(msi_rmw_avu LINK_PUBLIC ${Boost_LIBRARIES}) # Set the location for library installation install(CODE "MESSAGE(\"Installing microservices to iRODS plugins folder...\")") install(TARGETS msi_getenv -# msi_http_send_file msi_json_arrayops msi_json_objops # msi_time_ts2str - # msi_unmount -# msiput_dataobj_or_coll -# msi_amqp_basic_publish - msi_set_avu - msi_add_avu - msi_rmw_avu DESTINATION /usr/lib/irods/plugins/microservices) diff --git a/msi_add_avu/msi_add_avu.cpp b/msi_add_avu/msi_add_avu.cpp deleted file mode 100644 index 1104850..0000000 --- a/msi_add_avu/msi_add_avu.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "irods_error.hpp" -#include "irods_ms_plugin.hpp" -#include "rsModAVUMetadata.hpp" - -int msiAddAVU( - msParam_t* _item_type, - msParam_t* _item_name, - msParam_t* _attr_name, - msParam_t* _attr_val, - msParam_t* _attr_unit, - ruleExecInfo_t* _rei ) { - - char *it_str = parseMspForStr( _item_type ); - if( !it_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *in_str = parseMspForStr( _item_name ); - if( !in_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *an_str = parseMspForStr( _attr_name ); - if( !an_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *av_str = parseMspForStr( _attr_val ); - if( !av_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *au_str = parseMspForStr( _attr_unit ); - if( !au_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char op[] = "add"; - - modAVUMetadataInp_t avuOp; - memset(&avuOp, 0, sizeof(avuOp)); - avuOp.arg0 = op; - avuOp.arg1 = it_str; - avuOp.arg2 = in_str; - avuOp.arg3 = an_str; - avuOp.arg4 = av_str; - avuOp.arg5 = au_str; - - _rei->status = rsModAVUMetadata(_rei->rsComm, &avuOp); - - return _rei->status; - -} - -extern "C" -irods::ms_table_entry* plugin_factory() { - irods::ms_table_entry* msvc = new irods::ms_table_entry(5); - - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiAddAVU", - std::function(msiAddAVU)); - return msvc; -} \ No newline at end of file diff --git a/msi_add_avu/msi_add_avu_test.r b/msi_add_avu/msi_add_avu_test.r deleted file mode 100644 index efd85c6..0000000 --- a/msi_add_avu/msi_add_avu_test.r +++ /dev/null @@ -1,13 +0,0 @@ -# Call with -# -# irule -F msi_add_avu_test.r -# - -test() { - # type, path, attribute, value, unit - msi_add_avu("-d", "/nlmumc/home/rods/docker-compose.yml", "foo", "bar", "xyz"); -} - - -INPUT null -OUTPUT ruleExecOut \ No newline at end of file diff --git a/msi_amqp_basic_publish/Makefile b/msi_amqp_basic_publish/Makefile deleted file mode 100644 index 7b78b74..0000000 --- a/msi_amqp_basic_publish/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# TODO: Make this msi compatible with CMake building in 4.2.x - -GCC=g++ -INC=-I/usr/include/irods/ -I/usr/include/irods/boost/ - -all: msi_amqp_basic_publish - -msi_amqp_basic_publish: - ${GCC} ${INC} -DRODS_SERVER -fPIC "-Wl,-E" -shared -g -Wno-deprecated -rdynamic -o lib$@.so $@.cpp -lrabbitmq /usr/lib/libirods_client.a - -clean: - @rm -f ./*.so diff --git a/msi_amqp_basic_publish/msi_amqp_basic_publish.cpp b/msi_amqp_basic_publish/msi_amqp_basic_publish.cpp deleted file mode 100644 index 72e01cc..0000000 --- a/msi_amqp_basic_publish/msi_amqp_basic_publish.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// =-=-=-=-=-=-=- -#include "irods_error.hpp" -#include "irods_ms_plugin.hpp" - -// =-=-=-=-=-=-=- -// STL Includes -#include -#include - -// =-=-=-=-=-=-=- -// librabbitmq includes -#include -#include -#include - -extern "C" { - - // =-=-=-=-=-=-=- - // 1. Write a standard issue microservice - int irods_amqp_basic_publish( - msParam_t* hostnameParam, - msParam_t* portParam, - msParam_t* usernameParam, - msParam_t* passwordParam, - msParam_t* exchangeParam, - msParam_t* routingKeyParam, - msParam_t* messageParam, - ruleExecInfo_t* rei - ) { - amqp_socket_t *socket = NULL; - amqp_connection_state_t conn; - amqp_rpc_reply_t reply; - amqp_bytes_t message_bytes, exchange_bytes, routing_key_bytes; - amqp_basic_properties_t props; - int status; - - // Sanity checks - if ( !rei || !rei->rsComm ) { - rodsLog( LOG_ERROR, "amqp_basic_publish: Input rei or rsComm is NULL." ); - return ( SYS_INTERNAL_NULL_INPUT_ERR ); - } - - // hostname - const char *hostname = parseMspForStr( hostnameParam ); - if( !hostname ) { - rodsLog(LOG_ERROR, "amqp_basic_publish - invalid hostname"); - return SYS_INVALID_INPUT_PARAM; - } - - // port - if (portParam == NULL || portParam->type == NULL || strcmp(portParam->type, INT_MS_T) != 0) { - rodsLog(LOG_ERROR, "amqp_basic_publish - invalid port"); - return (USER_PARAM_TYPE_ERR); - } - int port = parseMspForPosInt(portParam); - - // username - const char *username = parseMspForStr( usernameParam ); - if( !username ) { - rodsLog(LOG_ERROR, "amqp_basic_publish - invalid username"); - return SYS_INVALID_INPUT_PARAM; - } - - // password - const char *password = parseMspForStr( passwordParam ); - if( !password ) { - rodsLog(LOG_ERROR, "amqp_basic_publish - invalid password"); - return SYS_INVALID_INPUT_PARAM; - } - - // exchange - const char *exchange = parseMspForStr( exchangeParam ); - if( !exchange ) { - rodsLog(LOG_ERROR, "amqp_basic_publish - invalid exchange"); - return SYS_INVALID_INPUT_PARAM; - } - exchange_bytes = amqp_cstring_bytes(exchange); - - // routing_key - const char *routingKey = parseMspForStr( routingKeyParam ); - if( !routingKey ) { - rodsLog(LOG_ERROR, "amqp_basic_publish - invalid routing key"); - return SYS_INVALID_INPUT_PARAM; - } - routing_key_bytes = amqp_cstring_bytes(routingKey); - - // message - const char *message = parseMspForStr( messageParam ); - if( !message ) { - rodsLog(LOG_ERROR, "amqp_basic_publish - invalid message"); - return SYS_INVALID_INPUT_PARAM; - } - message_bytes = amqp_cstring_bytes(message); - - // Start rabbitmq sequence - conn = amqp_new_connection(); - socket = amqp_tcp_socket_new(conn); - status = amqp_socket_open(socket, hostname, port); - - if ( status < 0 ) { - rodsLog( LOG_ERROR, "amqp_basic_publish: amqp_socket_open returned %d (%s)", status, amqp_error_string2(status)); - return SYS_INTERNAL_NULL_INPUT_ERR; - } - - reply = amqp_login(conn, "/", 1, 131072, 0, AMQP_SASL_METHOD_PLAIN, username, password); - - if ( reply.reply_type != AMQP_RESPONSE_NORMAL) { - rodsLog( LOG_ERROR, "amqp_basic_publish: amqp_login response was not normal"); - return SYS_INTERNAL_NULL_INPUT_ERR; - } - - amqp_channel_open(conn, 1); - reply = amqp_get_rpc_reply(conn); - - if ( reply.reply_type != AMQP_RESPONSE_NORMAL) { - rodsLog( LOG_ERROR, "amqp_basic_publish: amqp_get_rpc_reply response was not normal"); - return SYS_INTERNAL_NULL_INPUT_ERR; - } - - // persistent delivery mode - props._flags = AMQP_BASIC_DELIVERY_MODE_FLAG; - props.delivery_mode = 2; - - status = amqp_basic_publish(conn, 1, exchange_bytes, routing_key_bytes, 0, 0, &props, message_bytes); - - if ( status > 0 ) { - rodsLog( LOG_ERROR, "amqp_basic_publish: amqp_basic_publish returned %d (%s)", status, amqp_error_string2(status)); - return SYS_INTERNAL_NULL_INPUT_ERR; - } - - rodsLog( LOG_NOTICE, "amqp_basic_publish: Published message to rabbitmq (on %s) at exchange %s using routing_key %s.", hostname, exchange, routingKey); - - reply = amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS); - - if ( reply.reply_type != AMQP_RESPONSE_NORMAL) { - rodsLog( LOG_ERROR, "amqp_basic_publish: amqp_channel_close response was not normal"); - return SYS_INTERNAL_NULL_INPUT_ERR; - } - - reply = amqp_connection_close(conn, AMQP_REPLY_SUCCESS); - - if ( reply.reply_type != AMQP_RESPONSE_NORMAL) { - rodsLog( LOG_ERROR, "amqp_basic_publish: amqp_connection_close response was not normal"); - return SYS_INTERNAL_NULL_INPUT_ERR; - } - - amqp_destroy_connection(conn); - - // Done - return rei->status; - - } - - - // =-=-=-=-=-=-=- - // 2. Create the plugin factory function which will return a microservice - // table entry - irods::ms_table_entry* plugin_factory() { - // =-=-=-=-=-=-=- - // 3. allocate a microservice plugin which takes the number of function - // params as a parameter to the constructor - // hostname, port, user, password, exchange, routing_key, message - irods::ms_table_entry* msvc = new irods::ms_table_entry( 7 ); - - // =-=-=-=-=-=-=- - // 4. add the microservice function as an operation to the plugin - // the first param is the name / key of the operation, the second - // is the name of the function which will be the microservice - msvc->add_operation( - "irods_amqp_basic_publish", - std::function(irods_amqp_basic_publish)); - // =-=-=-=-=-=-=- - // 5. return the newly created microservice plugin - return msvc; - } - -} // extern "C" diff --git a/msi_amqp_basic_publish/msi_amqp_basic_publish_test.r b/msi_amqp_basic_publish/msi_amqp_basic_publish_test.r deleted file mode 100644 index 162e984..0000000 --- a/msi_amqp_basic_publish/msi_amqp_basic_publish_test.r +++ /dev/null @@ -1,16 +0,0 @@ -# Basic existence checker of resources -# -# Call with -# -# irule -F msi_amqp_basic_publish_test.r -# - -test() { - *message = '{"project": "P000000001", "collection": "C000000012"}' - # hostname, port, user, password, exchange, routing_key, message - msi_amqp_basic_publish("rabbitmq.dh.local", 5672, "user", "password", "datahub.events_tx", "projectCollection.metadata.validated", *message ); -} - - -INPUT null -OUTPUT ruleExecOut \ No newline at end of file diff --git a/msi_http_send_file/msi_http_send_file.cpp b/msi_http_send_file/msi_http_send_file.cpp deleted file mode 100644 index 3d0d2f2..0000000 --- a/msi_http_send_file/msi_http_send_file.cpp +++ /dev/null @@ -1,214 +0,0 @@ -// =-=-=-=-=-=-=- -#include "irods_error.hpp" -#include "rsDataObjClose.hpp" -#include "rsDataObjOpen.hpp" -#include "rsDataObjRead.hpp" -#include "irods_ms_plugin.hpp" - -// =-=-=-=-=-=-=- -// STL Includes -#include -#include - -// =-=-=-=-=-=-=- -// cURL Includes -#include -#include - -typedef struct readData_t { - char path[MAX_NAME_LEN]; - int desc; - rsComm_t *rsComm; -} readData_t; - -class irodsCurl { - private: - // iRODS server handle - rsComm_t *rsComm; - - // cURL handle - CURL *curl; - - - public: - irodsCurl( rsComm_t *comm ) { - rsComm = comm; - - curl = curl_easy_init(); - if ( !curl ) { - rodsLog( LOG_ERROR, "irods_http_send_file: %s", curl_easy_strerror( CURLE_FAILED_INIT ) ); - } - } - - ~irodsCurl() { - if ( curl ) { - curl_easy_cleanup( curl ); - } - } - - int post( char *url, char* objectPath ) { - CURLcode res = CURLE_OK; - char errbuf[CURL_ERROR_SIZE]; - readData_t readData; - openedDataObjInp_t openedSource; - - /* Create readData object */ - memset(&readData, 0, sizeof(readData_t)); - memset(&openedSource, 0, sizeof(openedDataObjInp_t)); - snprintf(readData.path, MAX_NAME_LEN, "%s", objectPath); - readData.desc = 0; - readData.rsComm = rsComm; - - // Set up easy handler - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); - curl_easy_setopt(curl, CURLOPT_READDATA, &readData); - curl_easy_setopt(curl, CURLOPT_READFUNCTION, &irodsCurl::my_read_obj); - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-iRODS"); - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); - // Possibly this timeout is too conservative - curl_easy_setopt(curl, CURLOPT_TIMEOUT, 120L); - - // CURL call - res = curl_easy_perform(curl); - - if ( res != 0 ) { - rodsLog( LOG_ERROR, "irods_http_send_file: curl error (%i): %s", res, errbuf ); - return SYS_INTERNAL_NULL_INPUT_ERR; - } else { - long http_code = 0; - curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code); - - if (http_code != 200) { - rodsLog( LOG_ERROR, "irods_http_send_file: HTTP returned error code %d", http_code ); - return SYS_INTERNAL_NULL_INPUT_ERR; - } - } - - if (readData.desc) { - openedSource.l1descInx = readData.desc; - int status = rsDataObjClose(rsComm, &openedSource); - if (status < 0) { - rodsLog(LOG_ERROR, "irods_http_send_file: rsDataObjClose failed for %s, status = %d",readData.path, status); - } - } - - return 0; - } - - static size_t my_read_obj(void *buffer, size_t size, size_t nmemb, void* userp) { - struct readData_t *readData = (struct readData_t *) userp; - - dataObjInp_t file; - openedDataObjInp_t openedFile; - bytesBuf_t bytesBuf; - int bytesRead; - - // Make sure we have something to read from - if (!readData) { - rodsLog(LOG_ERROR, "irods_http_send_file: readData is NULL"); - return CURL_READFUNC_ABORT; - } - - // Zero fill input structs - memset(&file, 0, sizeof (dataObjInp_t)); - memset(&openedFile, 0, sizeof (openedDataObjInp_t)); - memset(&bytesBuf, 0, sizeof (bytesBuf_t)); - - // If this is the first call we need to create our data object before reading from it - if (!readData->desc) { - strncpy(file.objPath, readData->path, MAX_NAME_LEN); - - // readData->desc = 5; - readData->desc = rsDataObjOpen(readData->rsComm, &file); - - // TODO: <= 2 instead of < 0? Look up rsDataObjOpen return codes - if (readData->desc < 0) { - rodsLog(LOG_ERROR, "irods_http_send_file: Cannot read iRODS object %s Status = %d",readData->path, readData->desc); - return CURL_READFUNC_ABORT; - } - } - - // Setup buffer for rsDataObjRead - bytesBuf.len = (int)(size * nmemb); - bytesBuf.buf = buffer; - - // Setup input struct for rsDataObjRead - openedFile.l1descInx = readData->desc; - openedFile.len = bytesBuf.len; - - // Read iRODS object - bytesRead = rsDataObjRead(readData->rsComm, &openedFile, &bytesBuf); - - if (bytesRead < 0) { - rodsLog(LOG_ERROR, "irods_http_send_file: Problem reading iRODS object. Status = %d", bytesRead); - return CURL_READFUNC_ABORT; - } - - return (size_t) bytesRead; - } - -}; // class irodsCurl - - -extern "C" { - -// =-=-=-=-=-=-=- -// 1. Write a standard issue microservice - int irods_http_send_file( msParam_t* url, msParam_t* src_obj, ruleExecInfo_t* rei ) { - dataObjInp_t dataObjInp, *myDataObjInp; - - // Sanity checks - if ( !rei || !rei->rsComm ) { - rodsLog( LOG_ERROR, "irods_http_send_file Input rei or rsComm is NULL." ); - return ( SYS_INTERNAL_NULL_INPUT_ERR ); - } - - // Get path of destination object - rei->status = parseMspForDataObjInp( src_obj, &dataObjInp, &myDataObjInp, 0 ); - if ( rei->status < 0 ) { - rodsLog( LOG_ERROR, "irods_http_send_file: Input object error. status = %d", rei->status ); - return ( rei->status ); - } - - // Create irodsCurl instance - irodsCurl myCurl( rei->rsComm ); - - // Call irodsCurl::post - rei->status = myCurl.post( parseMspForStr( url ), myDataObjInp->objPath ); - - // Done - return rei->status; - - } - - -// =-=-=-=-=-=-=- -// 2. Create the plugin factory function which will return a microservice -// table entry - irods::ms_table_entry* plugin_factory() { - // =-=-=-=-=-=-=- - // 3. allocate a microservice plugin which takes the number of function - // params as a parameter to the constructor - irods::ms_table_entry* msvc = new irods::ms_table_entry(2); - - // =-=-=-=-=-=-=- - // 4. add the microservice function as an operation to the plugin - // the first param is the name / key of the operation, the second - // is the name of the function which will be the microservice - msvc->add_operation< - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("irods_http_send_file", - std::function(irods_http_send_file)); - // =-=-=-=-=-=-=- - // 5. return the newly created microservice plugin - return msvc; - } - -} // extern "C" diff --git a/msi_http_send_file/msi_http_send_file_test.r b/msi_http_send_file/msi_http_send_file_test.r deleted file mode 100644 index 88dd499..0000000 --- a/msi_http_send_file/msi_http_send_file_test.r +++ /dev/null @@ -1,19 +0,0 @@ -# Simple rule to test microservice -# -# Call with -# -# irule -F msi_http_send_file_test.r "*url='mirthconnect:6670/?project=P000000001&collection=C000000001'" "*filePath='/nlmumc/projects/P000000001/C000000001/metadata.xml'" - -irule_dummy() { - writeLine("stdout", "Testing msi_http_send_file ..."); - IRULE_msi_http_send_file_test(*url, *filePath); -} - -IRULE_msi_http_send_file_test(*url, *filePath) { - - msi_http_send_file("*url", "*filePath"); - -} - -INPUT *url="", *filePath="" -OUTPUT ruleExecOut \ No newline at end of file diff --git a/msi_rmw_avu/msi_rmw_avu.cpp b/msi_rmw_avu/msi_rmw_avu.cpp deleted file mode 100644 index b00b016..0000000 --- a/msi_rmw_avu/msi_rmw_avu.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "irods_error.hpp" -#include "irods_ms_plugin.hpp" -#include "rsModAVUMetadata.hpp" - -int msiRmwAVU( - msParam_t* _item_type, - msParam_t* _item_name, - msParam_t* _attr_name, - msParam_t* _attr_val, - msParam_t* _attr_unit, - ruleExecInfo_t* _rei ) { - - char *it_str = parseMspForStr( _item_type ); - if( !it_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *in_str = parseMspForStr( _item_name ); - if( !in_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *an_str = parseMspForStr( _attr_name ); - if( !an_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *av_str = parseMspForStr( _attr_val ); - if( !av_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *au_str = parseMspForStr( _attr_unit ); - if( !au_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char op[] = "rmw"; - - modAVUMetadataInp_t avuOp; - memset(&avuOp, 0, sizeof(avuOp)); - avuOp.arg0 = op; - avuOp.arg1 = it_str; - avuOp.arg2 = in_str; - avuOp.arg3 = an_str; - avuOp.arg4 = av_str; - avuOp.arg5 = au_str; - - _rei->status = rsModAVUMetadata(_rei->rsComm, &avuOp); - - return _rei->status; - -} - -extern "C" -irods::ms_table_entry* plugin_factory() { - irods::ms_table_entry* msvc = new irods::ms_table_entry(5); - - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiRmwAVU", - std::function(msiRmwAVU)); - return msvc; -} \ No newline at end of file diff --git a/msi_rmw_avu/msi_rmw_avu_test.r b/msi_rmw_avu/msi_rmw_avu_test.r deleted file mode 100644 index 2190fe0..0000000 --- a/msi_rmw_avu/msi_rmw_avu_test.r +++ /dev/null @@ -1,13 +0,0 @@ -# Call with -# -# irule -F msi_add_avu_test.r -# - -test() { - # type, path, attribute, value, unit - msi_rmw_avu("-d", "/nlmumc/home/rods/docker-compose.yml", "%", "%", "xyz"); -} - - -INPUT null -OUTPUT ruleExecOut \ No newline at end of file diff --git a/msi_set_avu/msi_set_avu.cpp b/msi_set_avu/msi_set_avu.cpp deleted file mode 100644 index 33c4ab8..0000000 --- a/msi_set_avu/msi_set_avu.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "irods_error.hpp" -#include "irods_ms_plugin.hpp" -#include "rsModAVUMetadata.hpp" - -int msiSetAVU( - msParam_t* _item_type, - msParam_t* _item_name, - msParam_t* _attr_name, - msParam_t* _attr_val, - msParam_t* _attr_unit, - ruleExecInfo_t* _rei ) { - - char *it_str = parseMspForStr( _item_type ); - if( !it_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *in_str = parseMspForStr( _item_name ); - if( !in_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *an_str = parseMspForStr( _attr_name ); - if( !an_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *av_str = parseMspForStr( _attr_val ); - if( !av_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char *au_str = parseMspForStr( _attr_unit ); - if( !au_str ) { - return SYS_INVALID_INPUT_PARAM; - } - - char op[] = "set"; - - modAVUMetadataInp_t avuOp; - memset(&avuOp, 0, sizeof(avuOp)); - avuOp.arg0 = op; - avuOp.arg1 = it_str; - avuOp.arg2 = in_str; - avuOp.arg3 = an_str; - avuOp.arg4 = av_str; - avuOp.arg5 = au_str; - - _rei->status = rsModAVUMetadata(_rei->rsComm, &avuOp); - - return _rei->status; - -} - -extern "C" -irods::ms_table_entry* plugin_factory() { - irods::ms_table_entry* msvc = new irods::ms_table_entry(5); - - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiSetAVU", - std::function(msiSetAVU)); - return msvc; -} \ No newline at end of file diff --git a/msi_set_avu/msi_set_avu_test.r b/msi_set_avu/msi_set_avu_test.r deleted file mode 100644 index df7186e..0000000 --- a/msi_set_avu/msi_set_avu_test.r +++ /dev/null @@ -1,13 +0,0 @@ -# Call with -# -# irule -F msi_set_avu_test.r -# - -test() { - # type, path, attribute, value, unit - msi_set_avu("-d", "/nlmumc/home/rods/docker-compose.yml", "foo", "bar", "xyz"); -} - - -INPUT null -OUTPUT ruleExecOut \ No newline at end of file diff --git a/msi_unmount/unmount.cpp b/msi_unmount/unmount.cpp deleted file mode 100644 index 0bcc459..0000000 --- a/msi_unmount/unmount.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// =-=-=-=-=-=-=- -#include "irods_error.hpp" -#include "irods_ms_plugin.hpp" - -#include "rsPhyPathReg.hpp" - -// =-=-=-=-=-=-=- -// STL Includes -#include -#include - - -extern "C" { - -double get_plugin_interface_version() { - return 1.0; -} -// =-=-=-=-=-=-=- -// 1. Write a standard issue microservice - int irods_unmount( msParam_t* in, ruleExecInfo_t* rei ) { - dataObjInp_t *destObjInp; - - // Sanity checks - if ( !rei || !rei->rsComm ) { - rodsLog( LOG_ERROR, "irods_unmount: Input rei or rsComm is NULL." ); - return ( SYS_INTERNAL_NULL_INPUT_ERR ); - } - - destObjInp = ( dataObjInp_t* ) malloc( sizeof( dataObjInp_t ) ); - memset( destObjInp, 0, sizeof( dataObjInp_t ) ); - strncpy( destObjInp->objPath, parseMspForStr( in ), MAX_NAME_LEN ); - - int status = unmountFileDir( rei->rsComm, destObjInp ); - - free( destObjInp ); - - rodsLog( LOG_ERROR, "rods_unmount status: %i", status); - - // Done - return 0; - - } - - - -// =-=-=-=-=-=-=- -// 2. Create the plugin factory function which will return a microservice -// table entry - irods::ms_table_entry* plugin_factory() { - // =-=-=-=-=-=-=- - // 3. allocate a microservice plugin which takes the number of function - // params as a parameter to the constructor - irods::ms_table_entry* msvc = new irods::ms_table_entry(1); - - // =-=-=-=-=-=-=- - // 4. add the microservice function as an operation to the plugin - // the first param is the name / key of the operation, the second - // is the name of the function which will be the microservice - msvc->add_operation< - msParam_t*, - ruleExecInfo_t*>("irods_unmount", - std::function(irods_unmount)); - - // =-=-=-=-=-=-=- - // 5. return the newly created microservice plugin - return msvc; - } - - - -} // extern "C" diff --git a/msi_unmount/unmount_test.r b/msi_unmount/unmount_test.r deleted file mode 100644 index 3ed9721..0000000 --- a/msi_unmount/unmount_test.r +++ /dev/null @@ -1,24 +0,0 @@ -# Simple rule to test microservice -# -# Call with -# -# irule -F unmount_test.r "*coll='/nlmumc/ingest/zones/tricky-token'" -# -# Expected outcomes -# Before: `ils -L /nlmumc/ingest/zones` -# C- /nlmumc/ingest/zones/tricky-token mountPoint -# -# After: `ils -L /nlmumc/ingest/zones` -# C- /nlmumc/ingest/zones/tricky-token - -irule_dummy() { - writeLine("stdout", "Testing unmount ..."); - IRULE_msi_unmount_test(*coll); -} - -IRULE_msi_unmount_test(*coll) { - msi_unmount(*coll); -} - -INPUT *coll="" -OUTPUT null diff --git a/msiput_dataobj_or_coll/README.md b/msiput_dataobj_or_coll/README.md deleted file mode 100755 index 31b93d9..0000000 --- a/msiput_dataobj_or_coll/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# msiput_dataobj_or_coll - -Recursively puts files and folders into an iRODS collection. Allows usage of parallel transfer mechanism in the iRODS protocol for files > 32 MB. - -Adapted from [irods-contrib](https://github.com/irods/contrib/tree/master/microservices/landing_zone_microservices/msiput_dataobj_or_coll) diff --git a/msiput_dataobj_or_coll/libmsiput_dataobj_or_coll.cpp b/msiput_dataobj_or_coll/libmsiput_dataobj_or_coll.cpp deleted file mode 100644 index 32990fe..0000000 --- a/msiput_dataobj_or_coll/libmsiput_dataobj_or_coll.cpp +++ /dev/null @@ -1,339 +0,0 @@ -#include "irods_ms_plugin.hpp" -#include "objInfo.h" -#include "collCreate.h" -#include "dataObjPut.h" -#include "collection.hpp" - -#include "boost/filesystem/operations.hpp" -#include "boost/filesystem/path.hpp" -#include "boost/lexical_cast.hpp" -#include - -namespace fs = boost::filesystem; - - - -void strip_trailing_slash( - std::string& _path ) { - if( *_path.rbegin() == '/' ) - _path = _path.substr( 0, _path.size()-1 ); -} - - - -std::string get_logical_path( - const std::string& _full_path, - const std::string& _root_path, - const std::string& _tgt_coll ) { - - std::string logical_path; - std::string tmp; - std::size_t found; - std::string result; - std::string dropzone; - - fs::path fp = fs::canonical( fs::path( _full_path ) ); - fs::path rp = fs::canonical( fs::path( _root_path ) ); - - // ensure target collection ends in an irods - // separator - std::string tg = _tgt_coll; - if( *tg.rbegin() != '/' ) - tg += "/"; - - logical_path = tg + fp.filename().string(); - - if( !_root_path.empty() ) { - std::string::size_type pos = _full_path.find( _root_path ); - if( std::string::npos != pos ) { - // need the +1 to skip first slash in root path - tmp = _full_path.substr( pos+_root_path.size()+1 )+'/'; - found = tmp.find('/')+1; - dropzone = tmp.substr(0, found-1); - - logical_path = tg + _full_path.substr( pos+_root_path.size()+1 ); - boost::replace_all(logical_path,dropzone,""); - boost::replace_all(logical_path,"//","/"); - } - - } - - strip_trailing_slash( logical_path ); - - return logical_path; - -} // get_logical_path - - - -irods::error put_a_file( - rcComm_t* _comm, - const std::string& _file_path, - const std::string& _logical_path, - const std::string& _resc, - const std::string& _opts ) { - - rodsLog( - LOG_DEBUG, - "put_a_file :: put [%s] to [%s]", - _file_path.c_str(), - _logical_path.c_str() ); - - dataObjInp_t inp; - memset( &inp, 0, sizeof( inp ) ); - strncpy( - inp.objPath, - _logical_path.c_str(), - MAX_NAME_LEN ); - - int status = rcDataObjPut( - _comm, - &inp, - (char*)_file_path.c_str() ); - if( status < 0 ) { - std::string msg( "rcDataObjPut failed for [" ); - msg += _file_path; - msg += "]"; - return ERROR( status, msg ); - } - - return SUCCESS(); - -} // put_a_file - - - - -irods::error put_all_the_files( - rcComm_t* _comm, - const fs::path& _path, - const std::string& _root, - const std::string& _resc, - const std::string& _opts, - const std::string& _tgt_coll, - std::string& _out_path ) { - irods::error final_error = SUCCESS(); - - try { - if ( fs::is_directory( _path ) ) { - // create a matching collection - std::string logical_path = get_logical_path( - _path.string(), - _root, - _tgt_coll ); - rodsLog( - LOG_DEBUG, - "put_all_the_files :: create coll [%s]", - logical_path.c_str() ); - - collInp_t coll_inp; - memset( &coll_inp, 0, sizeof( coll_inp ) ); - strncpy( coll_inp.collName, logical_path.c_str(), MAX_NAME_LEN ); - int status = rcCollCreate( _comm, &coll_inp ); - if( status < 0 && status != CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) { - rodsLog( - LOG_ERROR, - "put_all_the_files :: rsCollCreate failed for [%s] with [%d]", - logical_path.c_str(), - status ); - - } else { - fs::directory_iterator end_iter; - fs::directory_iterator dir_itr( _path ); - - for( ; dir_itr != end_iter; ++dir_itr ) { - - // recurse on this new directory - irods::error ret = put_all_the_files( - _comm, - dir_itr->path(), - _root, - _resc, - _opts, - _tgt_coll, - _out_path ); - if ( !ret.ok() ) { - return PASS( ret ); - } - } - } - - } - else if ( fs::is_regular_file( _path ) ) { - std::string logical_path = get_logical_path( - _path.string(), - _root, - _tgt_coll ); - irods::error ret = put_a_file( - _comm, - _path.string(), - logical_path, - _resc, - _opts ); - if( !ret.ok() ) { - return PASS( ret ); - - } - - } - else { - std::stringstream msg; - msg << "unhandled entry ["; - msg << _path.filename(); - msg << "]"; - rodsLog( LOG_NOTICE, msg.str().c_str() ); - } - - } - catch ( const std::exception & ex ) { - std::stringstream msg; - msg << "caught exception ["; - msg << ex.what(); - msg << "] for directory entry ["; - msg << _path.filename(); - msg << "]"; - return ERROR( -1, msg.str() ); - - } - - _out_path = get_logical_path( - _path.string(), - _root, - _tgt_coll ); - return final_error; - -} // put_all_the_files - -// =-=-=-=-=-=-=- -// 1. Write a standard issue microservice -long long msiput_dataobj_or_coll( - msParam_t* _path, - msParam_t* _resc, - msParam_t* _opts, - msParam_t* _tgt_coll, - msParam_t* _out_path, - ruleExecInfo_t* rei) { - - char *path = parseMspForStr(_path); - if (!path) { - rodsLog(LOG_ERROR, "%s null _path", __FUNCTION__); - return SYS_INVALID_INPUT_PARAM; - } - - char *resc = parseMspForStr(_resc); - if (!resc) { - rodsLog(LOG_ERROR, "%s null _resc", __FUNCTION__); - return SYS_INVALID_INPUT_PARAM; - } - - char *opts = parseMspForStr(_opts); - if (!opts) { - rodsLog(LOG_ERROR, "%s null _opts", __FUNCTION__); - return SYS_INVALID_INPUT_PARAM; - } - - char *tgt_coll = parseMspForStr(_tgt_coll); - if (!tgt_coll) { - rodsLog(LOG_ERROR, "%s null _tgt_coll", __FUNCTION__); - return SYS_INVALID_INPUT_PARAM; - } - - std::string file_name; - fs::path inp_path(path); - if (fs::is_directory(inp_path)) { - file_name = fs::canonical(inp_path).parent_path().string(); - - } - - std::string tmp_coll(tgt_coll); - strip_trailing_slash(tmp_coll); - int status = rsMkCollR( - rei->rsComm, - "/", - tmp_coll.c_str()); - if (status < 0) { - rodsLog( - LOG_ERROR, - "msiput_dataobj_or_coll - failed to make collection [%s]", - _tgt_coll); - return status; - - } - - rcComm_t *comm = rcConnect( - rei->rsComm->myEnv.rodsHost, - rei->rsComm->myEnv.rodsPort, - rei->rsComm->myEnv.rodsUserName, - rei->rsComm->myEnv.rodsZone, - NO_RECONN, 0); - if (!comm) { - rodsLog( - LOG_ERROR, - "msiput_dataobj_or_coll - rcConnect failed"); - return 0; - } - - status = clientLogin( - comm, - 0, - rei->rsComm->myEnv.rodsAuthScheme); - if (status != 0) { - rcDisconnect(comm); - rodsLog( - LOG_ERROR, - "msiput_dataobj_or_coll - client login failed %d", - status); - return 0; - } - - std::string out_path; - irods::error ret = put_all_the_files( - comm, - inp_path, - file_name, - resc, - opts, - tgt_coll, - out_path); - - rcDisconnect(comm); - - if (!ret.ok()) { - addRErrorMsg( - &rei->rsComm->rError, - (int) ret.code(), - ret.result().c_str()); - } - - fillMsParam(_out_path, NULL, STR_MS_T, (void *) out_path.c_str(), NULL); - - return ret.code(); - -} - -extern "C" -// =-=-=-=-=-=-=- -// 2. Create the plugin factory function which will return a microservice -// table entry -irods::ms_table_entry* plugin_factory() { - // =-=-=-=-=-=-=- - // 3. allocate a microservice plugin which takes the number of function - // params as a parameter to the constructor - irods::ms_table_entry* msvc = new irods::ms_table_entry(5); - // =-=-=-=-=-=-=- - // 4. add the microservice function as an operation to the plugin - // the first param is the name / key of the operation, the second - // is the name of the function which will be the microservice - msvc->add_operation( - "msiput_dataobj_or_coll", - std::function(msiput_dataobj_or_coll)); - // =-=-=-=-=-=-=- - // 5. return the newly created microservice plugin - return msvc; -} diff --git a/msiput_dataobj_or_coll/msiput_dataobj_or_coll_test.r b/msiput_dataobj_or_coll/msiput_dataobj_or_coll_test.r deleted file mode 100644 index 72c7ad8..0000000 --- a/msiput_dataobj_or_coll/msiput_dataobj_or_coll_test.r +++ /dev/null @@ -1,19 +0,0 @@ -# Simple rule to test microservice -# -# Call with -# -# irule -F msiput_dataobj_or_coll_test.r "*srcColl='/mnt/ingest/zones/clumsy-crabs'" "*resc='replRescUM01'" "*dstColl='/nlmumc/projects/P000000001/C000000003'" -# -# IMPORTANT NOTE: This rule has to be called on the resource server that holds the physical path defined in *srcColl - -irule_dummy() { - writeLine("stdout", "Testing msiput_dataobj_or_coll ..."); - IRULE_msiput_dataobj_or_coll_test(*srcColl, *resc, *dstColl); -} - -IRULE_msiput_dataobj_or_coll_test(*srcColl, *resc, *dstColl) { - msiput_dataobj_or_coll("*srcColl", *resc, "numThreads=10++++forceFlag=", *dstColl, *real_path) -} - -INPUT *srcColl='', *resc='', *dstColl='' -OUTPUT ruleExecOut \ No newline at end of file