This module helps non-PHP programs/scripts integrate with Drupal. Currently it only supports Java-based languages (Java/Groovy/Scala/Jython/JRuby/etc), but native Python support will be added later (see #1710746: Add native Python support). The basic idea is: on your Drupal site, your have a module put commands plus Drupal data into a queue; and then your non-PHP programs (perhaps on a remote server) will retrieve these commands and execute them asynchronously and save results back to Drupal.
The module provides 4 ways to help non-PHP programs interact with Drupal:
- To connect to Drupal via Drush, execute any Drupal functions via Drush, and get results back in JSON.
- To connect to Drupal via Services module endpoints with REST/XML-RPC (to be implemented, see #1712174: Support Services module).
- To connect to Drupal via direct database access with SQL and JDBC.
- To connect to Drupal via direct database access on top of a Object-Relational-Mapping layer with Hibernate-JPA and SQLAlchemy (to be implemented), see #1712246: Add ORM support).
You can write your own Java/Python code to do all of those. But this module provides reusable code so you don't have to do them again.
Some other built-in features to help non-PHP programs interact with Drupal:
- An asynchronous queue system to transfer data in/out of Drupal.
- Views integration to display program execution results, status, and logging information.
- Rules integration to send notifications of command execution status (to be implemented, see #1712248: Rules integration).
- Easy access to drush, php or services from Java/PHP program.
Why?
Drupal is amazing as a CMS. But occasionally you want to do data analysis, visualization, reporting, etc, using Java/Python libraries, such as:
- Machine Learning/Data Mining: Apache Mahout (Java), Weka (Java), Orange (Python).
- Statistics/Scientific Computing: Numpy/Scipy (Python), R (Python), Apache Math (Java).
- Text Analysis/Information Retrieval: Apache Lucene (Java), LingPipe (Java), Apache OpenNLP (Java).
- Network Analysis/Visualization: JUNG (Java), igraph (Python), GUESS (Jython), Prefuse (Java).
Those libraries don't have alternatives in PHP, and you want to write native Java/Python scripts to use those libraries on top of Drupal data. Drupal Hybrid Computing module helps you do exactly that.
Code examples
This shows how to use Jython (or Python) to get a Drupal node via drush:
# requires jython 2.7+, and computing.jar in classpath.
import json
drush = DUtils.Drush("drush @dev")
# execute any Drupal/PHP functions and get results in JSON.
result = drush.computingEval("return node_load(1);")
# parse the JSON results
node = json.loads(result)
print node['title']This shows how to directly access a Drupal database using Java:
DConfig config = new DConfig();
// if you don't set this, the library will automatically tries to find settings.php
config.setProperties("drupal.settings.file", "/drupal/sites/default/settings.php");
// this will read db connection info from settings.php or other places
Properties dbProperties = config.getDbProperties();
// create direct database connection with JDBC and DBCP.
DDatabase db = new DDatabase(dbProperties);
// note here you can use {node} to take care of db_prefix, and type=? to take care of escaping.
long count = (Long) db.queryValue("SELECT COUNT(*) FROM {node} WHERE type=?", "forum");
System.out.println(count);To fully use the queue sub-system to transfer data in/out of Drupal and execute non-PHP commands asynchronously, please read documentation. Access Drupal via Services is to be implemented. See #1712174: Support Services module
Comparison to other modules
Drush: Drush only supports PHP. The Hybrid Computing module is intended to be the drush for non-PHP programs/scripts.
Services: Services exposes Drupal functionality through HTTP. But the Computing module can be viewed as a Services client. Besides, the computing module provides 3 mores ways to access Drupal (drush, SQL, ORM). See #1712174: Support Services module.
Feeds and Views Data Export: You can use both modules to export data, run non-PHP programs to process the exported data, and then import results back into Drupal. There are a few problems though: 1) export/import might be slow, 2) you can only import/export Views data, not any non-structural data, 3) latency problems. Instead, you can simply use the Hybrid Computing module to directly interact with Drupal.
Drupal's BatchAPI or QueueAPI: Both APIs are intended to work within Drupal. The Computing module has a queue sub-system, but it's designed to facilitate non-PHP program integration.
Beanstalkd: It requires the Beanstalkd service. Also, it's only a queue system.
Background process: It allows for things to happen in the background via asynchronous http requests. The external endpoint doesn't have to be PHP, just a web server. It is different from the Hybrid Computing module whose goal is to access Drupal directly from non-PHP code.
Supported modules
- RecommenderAPI (to be ported)
- Amazon Mechanical Turk Integration
- Text Analysis Suite (to be ported)
This module is a successor of the Async Command module. Also, please be noted that this module is under active development and APIs might get changed without notice. Currently we don't have documentations, but it will come eventually.
Downloads
Project Information
- Maintenance status: Actively maintained
- Development status: Under active development
- Reported installs: 7 sites currently report using this module. View usage statistics.
- Downloads: 101
- Last modified: August 8, 2012