Wednesday, July 6, 2016

Supporting WSO2 Data Services in AppCloud


Data services allows you to expose your relational databases, CSV files, Microsoft Excel sheets, Google spread sheets as SOAP and REST services. This helps you to expose your data through API Management solution such as API Cloud where your partners can consume your data in cloud. To read more about data services, refer to online documentation.

To start deploying dataservices in AppCloud, you need to have a car file which contains data service artifacts(dbs). In this post, I will explain how to
1. generate CRUD operations for a database table and get a data service.
2. import generated data service into to Developer studio and update with datasource configurations.
3. create a car file including above data service.
4. deploy it into AppCloud.

Lets get a database created in AppCloud so you can use it for the sample.
        Login to App Cloud using https://apps.cloud.wso2.com/appmgt/site/pages/index.jag
Create Database

provide database name, user and password
Find jdbc url etc
Connect to database and execute below queries
mysql -hmysql.storage.cloud.wso2.com -uemusr_vEqJD7xK -p
show databases;
use employeedb_manjulaorg;
create table employee(id VARCHAR(10) NOT NULL PRIMARY KEY, name VARCHAR(100), address VARCHAR(100));
insert into employee values('01','john','Boston');
insert into employee values('02','Micheal','Dallas');
insert into employee values('03','richard','Chicago');
SELECT * FROM employee;


1. Generate CRUD operations for a database table and get a data service.
Local setup details
Download wso2dss-3.5.0.zip file from wso2 web site and unzip.
Copy mysql-connector-java-5.* jar to wso2dss-3.5.0/repository/components/lib/
Start the server(wso2dss-3.5.0/bin/wso2server.sh start)
Login using admin/admin user.

Create a data source
In configure tab, create a new data source as below. You can get the database connection url, username from AppCloud UI as above.

Generate data service

In main tab, click on Add/Data Service/Generate button. Select data source you created in above step and provide the database name you created in AppCloud.
Next select table you need to expose with CRUD operations.
Provide a name to data service with namespace etc.
Data service will be deployed successfully.
Check the services deployed in services dashboard.
Try out your generated service with tryit tool.
Above are very simple steps to get CRUD operations exposed as a data service on a given table. You might need to change the queries, come up with better operation names, result elements etc. You can get this done easily by editing the data service through wizard or xml editor.
You can access the deployable file created in above steps in below location.
wso2dss-3.5.0/repository/deployment/server/dataservices/EmployeeService.dbs

2. Import generated data service into to Developer studio and update with data source configurations.
Open developer studio and create a data service project.
Next create a data service by importing the locally generated EmployeeService.dbs file.


Delete default(config) datasource and add a new one(right click on EmployeeService(data) -> Add Data Source -> RDBMS -> MySQL).
Make sure to keep the data source id as 'default'.


3. Create a car file including above data service.
Create composite application project.


Right click on composite project and export car file.



4. Deploy it into AppCloud.
Login to AppCloud start creating a application.
 Upload the created car file.
Application is created. Check the logs to see any errors in your data service.


If you get the service deployed correctly, check the car deployment logs as below.


To invoke the data service, click on the launch link. You will have to change the browser url to append /service/EmployeeService?wsdl as below.
https://manjulaorg-employeeservice-1-0-0.wso2apps.com/services/EmployeeService?wsdl 
Open the WSDL using soap ui tool and invoke the operations.
To summarize,
Most part of this post is about coming up with your data service and exporting it as a car file using developer studio.
If you have your own data service that is working locally, you can bring it to cloud easily as explained in this post using App Cloud.
To deploy multiple services in a single container, you can package multiple data services into car file and upload.



I will explain steps for securing this data service with username token ws security policy in next post.


Tuesday, June 28, 2016

Continuous integration and deployment with WSO2 App Cloud

If you have started deploying applications into WSO2 App Cloud, you will look for automating the deployment and configure it with your internal infrastructures such as GitHub, Jenkins etc.



Read tutorial to learn more about it.

WSO2 App Cloud for hosting your services and web applications

WSO2 App Cloud helps you to bring your web applications and services into Cloud easily.

Do you need to get a public URL to your service or your web app?
WSO2 App Cloud generate one for you with your organization name, application/service name and version.
eg. https://manjulaorg-esample-1-0-0.wso2apps.com/
If you have your own domain, you can use it too, learn how to.


4.png 
Do you have valuable data to be shared with your partners, co-workers in a secure manner? 
  • Create a micro service and expose your data or
  • Create a data service and expose your data.
  • Secure your micro service or data service using user name tokens.
  • Expose your service as an API in API Cloud.

Your partners need to consume your API and build a cool web app?
  • Subscribe to interested APIs in API Cloud.
  • Get consumer key, secret (OAuth tokens).
  • Write a jsp web application or php or jaggery and deploy in App Cloud.

Ok, there is a sample you can try out for above use cases... Buzzword sample.
  • As an API developer, you write a simple micro service to collect new buzzwords. You open a non secured endpoint to your friends to send/vote buzzwords.
  • But you hide the results, to get the ranks about your buzz words, consumers has to subscribe to your buzzword API.
  • As an Application developer, your friend consumes your buzzword API and come up with a web application and show the buzzwords as a tag cloud.  
http://manjulaorg-buzzwords-1-0-0.wso2apps.com/

Try out more tutorials on App Cloud.