Git Product home page Git Product logo

clara-demo's Introduction

CLARA multi-language application demo

Build Status

Example of a CLARA application wrapping a multi-language legacy library into services.

OpenCV is used to simulate a legacy application that detects faces and pupils on a given set of images. For simplicity the images are stored in a ZIP file. In a real-world scenario the dataset would be saved into a more complex file format, like HDF5.

Application architecture

The application is presented as a multi-project.

legacy subproject

The legacy subproject simulates the legacy application.

The Java implementation presents I/O classes and a simple image detection program:

  • The ImageReader class opens a ZIP file and read images from it.
  • The ImageWriter class opens a ZIP file and writes images to it.
  • The Image class stores the content and name of a file image.
  • The FaceDetector class finds faces in a image.

The C++ implementation adds a new detection algorithm:

  • The Image class stores the content and name of a file image.
  • The PupilDetector class finds pupils in a image.

The legacy subproject creates the demo-legacy-0.1.jar and libdemo_legacy.so artifacts.

data subproject

When the services are developed to be shared with other developers and investigation groups, it is a good idea to present the data types used by the services into its own package.

Orchestrators can then add a dependency on the data type package to send requests to the services, without downloading all the services implementation dependencies.

The data subproject creates the demo-data-0.1.jar and libdemo_data.so artifacts.

services subproject

The final CLARA services are just a tiny layer over the legacy code. The most important thing to consider is thread-safety of the legacy classes. CLARA services will run in a multi-thread environment and developers must ensure thread-safety.

The Java implementation provides the ImageReaderService and the ImageWriterService to open the ZIP dataset files and read or save the images. The services extend the standard CLARA I/O services AbstractEventReaderService and AbstractEventWriterService.

The Java FaceDetectorService and the C++ PupilDetectorService pass any received image to its wrapped detection class.

The services subproject creates the demo-services-0.1.jar and libpupils_detector.so, artifacts.

Dependencies

Install CLARA Java and CLARA C++ into $CLARA_HOME.

Install OpenCV following these instructions.

Build and deploy

Build and deploy the Java services into $CLARA_HOME:

$ ./gradlew
$ ./gradlew deploy

Build and deploy the C++ services into $CLARA_HOME:

$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install

Note: The build may fail if OpenCV cannot be found in a standard location.

  • For Gradle, set the custom OpenCV install prefix in the opencvDir property:

    $ ./gradlew -PopencvDir=/app/opencv3/ [ deploy ]
    
  • For CMake, set the custom OpenCV install prefix in the OpenCV_ROOT variable:

    $ cmake -DOpenCV_ROOT=/app/opencv3 ..
    

Running the application

Using the CLARA Shell

Use the clara-shell to run the services locally with a set of ZIP files (each containing many images). The shell provides a high-level interface to configure and start the different CLARA components required to run an application.

  1. Start the CLARA shell:

    $ $CLARA_HOME/bin/clara-shell
    
  2. Define the application within a services.yaml file. There is one file ready in the root of the repository.

    clara> set servicesFile services.yaml
    
  3. Define the data set with the input files to be processed. Put a list with their names into a text file. There is a files.list file ready in the root of the repository.

    clara> set fileList files.list
    
  4. Define the locations for the input data set and the output result (relative to where the shell was started):

    clara> set inputDir resources
    clara> set outputDir /tmp/out
    

    Optionally you can change the number of parallel threads used by the services to process requests

    clara> set threads <NUM_THREADS>
    
  5. Start the data processing. This will start the main Java DPE, a C++ DPE if the C++ service is listed in services.yaml, and it will run the standard orchestrator to process the dataset.

    clara> run local
    
  6. Inspect the output files in the output directory.

You can put the above shell commands into a script and run the script instead. There is a demo.clara script ready in the root of the repository:

$ $CLARA_HOME/bin/clara-shell demo.clara

Starting the CLARA DPEs and orchestrator manually

All CLARA components started by the CLARA shell can be run manually.

Use the standard clara-orchestrator to run the services with a set of ZIP files (each containing many images):

  1. Start the main Java DPE:

    $ $CLARA_HOME/bin/j_dpe
    
  2. Start the C++ DPE (if the application uses C++ services):

    $ $CLARA_HOME/bin/c_dpe --fe-host localhost
    
  3. Define the application with a services.yaml file. There is one file ready in the root of the repository.

  4. Define the data set with the input files to be processed. Put a list with the names into text file. There is a files.list file ready in the root of the repository.

  5. Run the orchestrator with the application configuration file, the input and output directories, and the list of input files:

    $ $CLARA_HOME/bin/clara-orchestrator -F -i ./resources -o /tmp/out services.yaml files.list
    

    To change the number of parallel threads used by the services to process requests, pass the -t <NUM_THREADS> option.

  6. Inspect the output files in the output directory.

Example

clara-demo's People

Contributors

smancill avatar

Watchers

 avatar James Cloos avatar Stephen Wood avatar pat avatar Wesley Moore avatar Vardan Gyurjyan avatar  avatar  avatar

Forkers

smancill

clara-demo's Issues

gradlew fails

 ./gradlew                                                               
                                                                                                                                                 
> Task :legacy:compileJava FAILED                                                                                                                
/mnt/old_home/whit/projects/clara/clara-demo/legacy/src/main/java/org/jlab/clara/demo/core/FaceDetector.java:3: error: cannot access Core        
import org.opencv.core.Core;                                                                                                                      
                      ^                                                                                                                          
  bad class file: /usr/share/OpenCV/java/opencv-320.jar(org/opencv/core/Core.class)                                                               
    class file has wrong version 54.0, should be 52.0                                           
    Please remove or make sure it appears in the correct subdirectory of the classpath.                                                          
                                                                                                                                                 
FAILURE: Build failed with an exception.                                                                                                         
                                                                                                                                                 
* What went wrong:
Execution failed for task ':legacy:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insight
s.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
1 actionable task: 1 executed

waiting for local node.

Following the instructions, the processing hangs...

clara> run local
Distribution  :    clara-cre-4.3.5
CLAS12 plugin :    coatjava-5.7.4

==========================================
               CLARA FE/DPE               
==========================================
 Name             = 172.17.0.1%7300_java
 Session          = whit_clara
 Start time       = 2019-02-11 20:34:45
 Version          = 4.3
 Lang             = Java
 Pool size        = 2

 Proxy Host       = 172.17.0.1
 Proxy Port       = 7300
==========================================
==========================================
            CLARA Orchestrator            
==========================================
 Front-end          = 172.17.0.1%7300_java
 Start time         = 2019-02-11 20:34:49
 Threads            = 2

 Input directory    = /mnt/old_home/whit/projects/clara/clara-demo/resources
 Output directory   = /tmp/out
 Output file prefix = out_
 Number of files  = 1
==========================================
2019-02-11 20:34:49.283: Waiting for local node...
2019-02-11 20:35:49.441: Could not run data processing!
2019-02-11 20:35:49.441: could not find a data processing node
2019-02-11 20:35:49.442: Exiting...

This is the same message I got when using with clas12 reconstruction.

C++ issues

Since the opencv demo is not building, can you provide a trivial example for c++? I have tried myself but I am not sure I have things totally in order.

I have the "could not start container" error but nothing else to really understand what the problem is.

Distribution  :    clara-cre-4.3.8
CLAS12 plugin :    coatjava-5.9.0

==========================================
               CLARA FE/DPE
==========================================
 Name             = 172.17.0.1%7140_java
 Session          = whit_clara
 Start time       = 2019-06-28 13:09:45
 Version          = 4.3
 Lang             = Java
 Pool size        = 2

 Proxy Host       = 172.17.0.1
 Proxy Port       = 7140
==========================================
=========================================
                 CLARA DPE
=========================================
 Name             = 172.17.0.1%7150_cpp
 Date             = 2019-06-28 13:09:46
 Version          = 4.3
 Lang             = C++

 Proxy Host       = 172.17.0.1
 Proxy Port       = 7150

 FrontEnd Host    = 172.17.0.1
 FrontEnd Port    = 7140
 FrontEnd Lang    = Java
=========================================
==========================================
            CLARA Orchestrator
==========================================
 Front-end          = 172.17.0.1%7140_java
 Start time         = 2019-06-28 13:09:48
 Threads            = 4

 Input directory    = /mnt/old_home/whit/projects/clara/clara_home/data/input
 Output directory   = /mnt/old_home/whit/projects/clara/clara_home/data/output
 Output file prefix = out_
 Number of files  = 1
==========================================
2019-06-28 13:09:49.179: Waiting for local node...
2019-06-28 13:09:49.332: Start processing on 172.17.0.1...
2019-06-28 13:09:49.333: Searching services in 172.17.0.1...
2019-06-28 13:09:49.349: Deploying services in 172.17.0.1...
2019-06-28 13:09:49: started container = 172.17.0.1%7140_java:whit
2019-06-28 13:09:50: basic_string::_M_create
2019-06-28 13:09:50: started service = 172.17.0.1%7140_java:whit:DataManager  pool_size = 1
2019-06-28 13:09:50: started service = 172.17.0.1%7140_java:whit:HipoToHipoReader  pool_size = 1
2019-06-28 13:09:50: started service = 172.17.0.1%7140_java:whit:HipoToHipoWriter  pool_size = 1
2019-06-28 13:09:51.972: Could not use 172.17.0.1 for processing:
could not start container = 172.17.0.1%7150_cpp:whit
^C2019-06-28 13:09:59: removed service = 172.17.0.1%7140_java:whit:HipoToHipoWriter
2019-06-28 13:09:59: removed service = 172.17.0.1%7140_java:whit:HipoToHipoReader
2019-06-28 13:09:59: removed service = 172.17.0.1%7140_java:whit:DataManager
2019-06-28 13:09:59: removed container = 172.17.0.1%7140_java:whit
2019-06-28 13:09:59: shutdown DPE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.