Skip to content

Commit

Permalink
Change the implementation to a a RPC client
Browse files Browse the repository at this point in the history
  • Loading branch information
brunogamacatao committed Jul 29, 2018
1 parent dae8f28 commit d587293
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name = "pypi"

[packages]
flask = "*"
pika = "*"

[dev-packages]

Expand Down
10 changes: 9 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Saiku Python Client

This is an implementation of a Python client for the Saiku core features. It exposes those features as a REST webservice.

## Architecture

The architecture is based on a messaging queue service, [RabbitMQ](https://www.rabbitmq.com/). Saiku core is implemented in Java, it exposes its functionalities as RPC functions. On the other side, there's a Python RPC client which connects to the message queue, sends messages to the Java RPC server.

## Requirements

1. Install Erlang (http://www.erlang.org/downloads)
2. Install RabbitMQ (https://www.rabbitmq.com)
3. Download the Saiku Report Viewer Server
```
git clone -b development https://github.com/OSBI/saiku-report-viewer-server
```
4. Download the Saiku Python RPC Client
```
git clone https://github.com/OSBI/python_saiku_report_viewer_server
```

## Running
1. Run the RabbitMQ service
2. Run the Saiku service (org.saiku.reportviewer.server.Main)
3. Run the Python client (python -m saiku.main)
4. Open the following URL on a browser: http://127.0.0.1:5002/
37 changes: 36 additions & 1 deletion src/saiku/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,49 @@

from flask import Flask
from flask import request
from flask import make_response
import pika
import uuid

class SaikuRpcClient(object):
def __init__(self):
self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
self.channel = self.connection.channel()
result = self.channel.queue_declare(exclusive=True)
self.callback_queue = result.method.queue
self.channel.basic_consume(self.on_response, no_ack=True, queue=self.callback_queue)

def on_response(self, ch, method, props, body):
if self.corr_id == props.correlation_id:
self.response = body

def call(self):
self.response = None
self.corr_id = str(uuid.uuid4())
self.channel.basic_publish(exchange='',
routing_key='SAIKU',
properties=pika.BasicProperties(
reply_to = self.callback_queue,
correlation_id = self.corr_id,
),
body='')
while self.response is None:
self.connection.process_data_events()
return self.response

# Create the Saiku RPC Client
saiku_rpc = SaikuRpcClient()

# Create the Flask APP
app = Flask(__name__)

# Setup the webservice routes
@app.route("/")
def hello():
return "It's alive"
response = make_response(saiku_rpc.call())
response.headers.set('Content-Disposition', 'inline', filename='saiku_report.pdf')
response.headers.set('Content-Type', 'application/pdf')
return response

# Start the server
if __name__ == '__main__':
Expand Down

0 comments on commit d587293

Please sign in to comment.