Demo showing Fuse Online and 3Scale. This guide was based on Rodrigo Ramalho demo.
We will create and expose an API that get data from a posgresql database using Fuse Online. After that, we'll expose it through 3Scale.
No code is necessary for this demo
- 3Scale Dashboard Samples: https://rramalho-admin.3scale.net
- Apicurio: https://www.apicur.io/
- Microcks: http://microcks.github.io/
- Syndesis Extensions: https://github.com/syndesisio/syndesis-extensions
You need to create an integrately environment
First, login to Openshift using a token.
And then copy to clipboard your login command
Now, let's create a new database in a project named fuse-demo
:
# Create new project on Openshift
oc new-project fuse-demo
# Create a new postgresql database using a Openshift template
oc new-app --template=postgresql-persistent --param=POSTGRESQL_PASSWORD=redhat --param=POSTGRESQL_USER=redhat --param=POSTGRESQL_DATABASE=sampledb -n fuse-demo
When the pod is ready, run:
# Get postgresql pod name
POD_POSTGRESQL=$(oc get po | grep postgresql | awk '{print $1}')
# Create database
oc exec -it $POD_POSTGRESQL -- bash -c 'psql -U redhat -d sampledb -c "CREATE TABLE users(id serial PRIMARY KEY,name VARCHAR (50),phone VARCHAR (50),age integer);"'
# Populate the database
oc exec -it $POD_POSTGRESQL -- bash -c "psql -U redhat -d sampledb -c \"INSERT INTO users(name, phone, age) VALUES ('Rodrigo Ramalho', '(11) 95474-8099', 30);\""
oc exec -it $POD_POSTGRESQL -- bash -c "psql -U redhat -d sampledb -c \"INSERT INTO users(name, phone, age) VALUES ('Thiago Araki', '(11) 95474-8099', 31);\""
oc exec -it $POD_POSTGRESQL -- bash -c "psql -U redhat -d sampledb -c \"INSERT INTO users(name, phone, age) VALUES ('Gustavo Luszczynski', '(11) 95474-8099', 29);\""
oc exec -it $POD_POSTGRESQL -- bash -c "psql -U redhat -d sampledb -c \"INSERT INTO users(name, phone, age) VALUES ('Rafael Tuelho', '(11) 95474-8099', 55);\""
oc exec -it $POD_POSTGRESQL -- bash -c "psql -U redhat -d sampledb -c \"INSERT INTO users(name, phone, age) VALUES ('Elvis is not dead', '(11) 95474-8099', 36);\""
# Make sure your data is saved
oc exec -it $POD_POSTGRESQL -- bash -c "psql -U redhat -d sampledb -c \"select * from users;\""
If for some reason you need to reinstall the database, just run:
oc delete all -l app=postgresql-persistent -n fuse-demo
oc delete pvc postgresql -n fuse-demo
oc delete secret postgresql -n fuse-demo
Open your tutorial page: https://tutorial-web-app-webapp.apps.latam-3a88.openshiftworkshop.com
Update this url
https://tutorial-web-app-webapp.apps.latam-3a88.openshiftworkshop.com
according to your environment
Open Fuse Online
Click on Connections
Click on Create Connection
Then, select Database
Fill the database configuration with the following values:
url: jdbc:postgresql://postgresql.fuse-demo:5432/sampledb
user: redhat
password: redhat
Now, click on Validate
to make sure everything is working as expected. If it is all good, click on Next
.
The Connection Name is: Users Database
. Then, click on Create
Now you should see connection Users Database
listed in the connections page.
We are good to go for our API creation demo.
Back to our Home
page, click on Create Integration
Then select API Provider
from the connections listed.
Choose Create from scratch
Click on Add a data type
Give it a name like: User
Paste the following json example and choose REST Resource
. Then, click Save
.
{
"id": 0,
"name": "Rodrigo Ramalho",
"phone": "11 95474-8099",
"age": 30
}
Click Save
again.
Now, click on Next
And give a name for our integration: Users API
. Click on Save and continue
Create now a flow for the GET Method that list all users:
Add a step in our flow clicking on +
:
Now choose our Users Database
connection created previously.
Click on Invoke SQL to obtain, store, update or delete data
:
Fill the SQL Statement
with: select * from users
and then click Next
Add a log step in our flow. Click again on the +
:
Then choose Log
In the Custom Text
, write Loading users from database
and click Done
.
Now, let's add a data mapping to our flow. In the last step, click in the yellow icon and then go to Add a data mapping step
.
Expand both panel clicking on the arrows:
Now, drag and drop the source fields matching with the target fields and then click on Done
.
Click now on Save
.
From the combobox Operations
, choose Create a users
:
Repeat the same steps you did when Creating an API for Get All Users (GET)
When adding the Users Database, you need to click on Invoke SQL to obtain, store, update or delete data
and add INSERT INTO USERS(NAME,PHONE,AGE) VALUES(:#NAME,:#PHONE,:#AGE);
in the field SQL statement
.
Also, during the data mapping you won't need to associate the id
field because it will be already generate by the postgres database.
In the end, you should have something like:
Now, click on Save
and then on Publish
Now, we need to wait Openshift build our container. When done, you should see Published version 1
on the top of the page.
If you go to the Home
page, we have 1 integration running.
Our last step is to expose our integration on Openshift using Route
s.
oc create route edge i-users-api --service=i-users-api -n fuse
You can check if your integration is working properly running:
curl https://$(oc get route -n fuse | grep i-users-api | awk '{print $2"/users"}')
Or you can try with httpie:
http https://$(oc get route -n fuse | grep i-users-api | awk '{print $2"/users"}')
First, let's import our API from Openshift. To do that, just click on NEW API
.
Select Import from Openshift
. Then choose fuse
for the Namespace
combobox and i-users-api
for the Name
field. Click on Create Service
.
Now you should see your new api on the 3scale dashboard.
We need to create an application plan for our users api. Click on Dashboard
menu and then on i-users-api
Now, click on Create Application Plan
.
For the Name
field use: Basic Plan
. And for the System name
: basic-plan
. Now click on Create Application Plan
.
We need to publish our application plan. To do that, click on Publish