MoleQueue JSON-RPC Implementation

From wiki.openchemistry.org
Revision as of 09:48, 5 April 2013 by Dlonie (talk | contribs) (→‎This page is out-of-date)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page is out-of-date

The mechanism for handling JSON-RPC transmissions has been simplified. This page may be rewritten at some point.

Language, backends

The MoleQueue JSON-RPC implemention is written in C++, using the JsonCpp parsers. It exposes a Qt 4 interface that provides interprocess communication through a local socket with a visible Qt signal/slot interface.

Components

The implementation consists of the following classes:

MoleQueue::JsonRpc

Internal class used to generate and handle JSON-RPC requests, responses, and notifications as described in the MoleQueue JSON-RPC Specification.

Methods:

  • static QByteArray generateJobRequest(const JobRequest &req, unsigned long requestId): Process a JobRequest into a MoleQueue JSON-RPC QByteArray, ready to send to a QLocalSocket.
  • static QByteArray generateJobCancellation(const JobRequest &req, unsigned long requestId)Process a request to cancel a JobRequest into a MoleQueue JSON-RPC QByteArray.
  • static QByteArray generateQueueList(const QueueManager *, unsigned long requestId): Generate a MoleQueue JSON-RPC QByteArray of the available queues/programs.
  • QVector<unsigned long> interpretIncoming(const QByteArray &): Interpret an incoming MoleQueue JSON-RPC packet, identify the type (should be a request), and emit an appropriate signal. Return value is a unique identifier for this packet that can be used later to match the signal to this packet (should be the JSON-RPC packet id). A QVector is used to handle batch requests.
  • static QByteArray generateJobStateChangeNotification(unsigned long moleQueueId, JobState oldState, JobState newState)
  • static bool validateRequest(const QString &)
  • static bool validateResponse(const QString &)
  • static bool validateNotification(const QString &)

Signals:

  • void queueListRequestReceived(unsigned long packetHandle)
  • void queueListReceived(unsigned long packetHandle, const QList<QPair<QString, QStringList> > &)
  • void jobSubmissionRequestReceived(unsigned long packetHandle, const QHash<QString, QVariant> &options)
  • void successfulSubmissionReceived(unsigned long packetHandle, unsigned long moleQueueId, unsigned long jobId, const QDir &workingDir)
  • void failedSubmissionReceived(unsigned long packetHandle, unsigned long moleQueueId, unsigned long jobId, const QDir &workingDir)
  • void jobCancellationRequestReceived(unsigned long packetHandle, unsigned long moleQueueId)
  • void jobCancellationConfirmationReceived(unsigned long packetHandle, unsigned long moleQueueId)
  • void jobStateChangeReceived(unsigned long packetHandle, unsigned long moleQueueId, JobState oldState, JobState newState)

MoleQueue::MoleQueueClient

Client interface providing methods for requesting and monitoring calculations. This class generates and manages JobRequest objects, which are state objects that define a single job's configuration.

Methods:

  • JobRequest & newJobRequest(): Creates and registers a new JobRequest object with this client.
  • bool submitJobRequest(JobRequest &): Submit a JobRequest to the MoleQueue server.
  • bool cancelJobRequest(JobRequest &): Cancel a JobRequest that has been submitted to the MoleQueue server.

MoleQueue::JobRequest

Class describing a single job from the client's side.

Methods:

  • MoleQueueClient & client(): Return the parent MoleQueueClient.
  • unsigned long id() const: Unique identifier for this job request.
  • unsigned long jobId() const: If set, a queue specific job identifier.
  • Various setters/getters for file path, job options, etc.

Slots:

  • bool submit(): Equivalent to this->client.submitJobRequest(this).
  • bool cancel(): Equivalent to this->client.cancelJobRequest(this).
  • bool destroy(): Removes a JobRequest from the client. Otherwise the instance will persist for the lifetime of the MoleQueueClient.

Signals:

  • void stateChanged(JobState oldState, JobState newState): Emitted when the server indicates a change in the job's status.
  • void submitted(): Emitted when the job is successfully submitted to the MoleQueueServer.
  • void error(ErrorCode ec, const QString &err) Emitted if an error is encountered.
  • void finished(): Emitted when the job execution terminates.

ErrorCode values:

  • SUBMISSION_ERROR: Error submitting request to MoleQueueServer.

MoleQueue::MoleQueueServer

Server for handling requests from and sending notifications to MoleQueueClient instances. It holds a pointer to a QueueManager and directly sends requests to the appropriate Queue objects.

Methods:

  • setQueueManager(QueueManager *): Sets the QueueManager.
  • QueueManager * queueManager(): Get the current QueueManager instance.