Developing Microservice Plugins

Jason Coposky, Chief Technologist

The iRODS Plugin Architecture

iRODS provides 6 plugin interfaces

  • Storage Resource
  • Authentication
  • Network
  • Database
  • RPC API
  • Microservice

Anatomy of a Plugin

  • Built as a dynamic shared object
  • provides a plugin_factory method which instantiates the plugin object
  • contains a class derived from a plugin interface base class:
    • ​api
    • auth
    • network
    • resource
    • database
    • ms_table_entry
  • NOTE: microservices do not require a derived class, the factory can return an instance of ms_table_entry

Example Code

git clone https://github.com/irods/contrib

 

cd contrib/microservices/training_example/msiget_image_meta

 

 

Writing a microservice - part 1

  • The microservice must use C linkage
extern "C" {
  • Declare the microservice implementation as usual, following the parameters with the rule engine context
 int msiget_image_meta_impl(msParam_t* _in, msParam_t* _out, ruleExecInfo_t* rei) {
        using std::cout;
        using std::endl;
        using std::string;
        char *filePath = parseMspForStr( _in );
        if( !filePath ) {
            cout << "msiget_image_meta - null filePath parameter" << endl;
            return SYS_INVALID_INPUT_PARAM;
        }

Writing a microservice - part 2

        InitializeMagick((const char*)0);
        Image imgObj;
        imgObj.read(filePath);
        std::stringstream metaData;
        metaData << "ImageDepth=" << imgObj.modulusDepth()
                 << "%Width=" << imgObj.columns()
                 << "%Height=" << imgObj.rows()
                 << "%CompressionType=" << convertCompressTypeToStr(imgObj.compressType())
                 << "%Format=" << imgObj.format() 
                 << "%Colorspace=" << convertColorSpaceTypeToStr(imgObj.colorSpace());
        fillStrInMsParam(_out, metaData.str().c_str());
        return 0;
    } // msi_get_image_meta_impl

The plugin factory

  • factory function requires C linkage and must follow the signature
    irods::ms_table_entry* plugin_factory() {
  • instantiate a table entry and pass it the number of parameters of the microservice - not including the rule engine context
            irods::ms_table_entry* msvc = new irods::ms_table_entry(2);
  • wire the microservice name to the name of the implementation and return the plugin
            msvc->add_operation(
                "msiget_image_meta_impl",
                "msiget_image_meta");
            return msvc;
        }
    } // extern "C"

Building a microservice plugin

  • The irods-dev package is required to build plugins
GCC = g++
INC=-I/usr/include/irods/ -I/usr/include/irods/boost/ -I/usr/include/ImageMagick
all: libmsiget_image_meta
libmsiget_image_meta:
    ${GCC} ${INC} -DRODS_SERVER -fPIC "-Wl,-E" -shared -g \
        -Wno-deprecated -rdynamic -o $@.so $@.cpp -lMagick++
clean:
    @rm -f ./*.so

Questions?

Developing Microservice Plugins

By jason coposky

Developing Microservice Plugins

An overview of how to write and build an iRODS microservice plugin

  • 1,409
Loading comments...

More from jason coposky