Tuesday, December 1, 2015

Configure WSO2 DSS with Cassandra

Here are the steps to setup DSS and Cassandra integration

Setup 1: download and install Cassandra
WSO2 DSS 3.5.0 is based on WSO2 Carbon 4.4.2 and Cassandra version 2.0 is recommended
WSO2 DSS 3.2.2 is based on WSO2 Carbon 4.2.0 and Cassandra version 2.0 is recommended

Step 2: download and install WSO2DSS
http://wso2.com/products/data-services-server/
https://docs.wso2.com/display/DSS322/WSO2+Data+Services+Server+Documentation

Step 3: configure following operations in DSS
Create Key space - UserKS
CREATE KEYSPACE UserKS WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1}
Create column family - User (id, name, country)
CREATE TABLE UserKS.User (id text, name text, country text, PRIMARY KEY (id))
addUser
INSERT INTO UserKS.User (id, name, country) values (?,?,?)
getUsers
SELECT * FROM UserKS.User
updateUser
UPDATE UserKS.User SET country = ? WHERE id =?
deleteUser
DELETE FROM UserKS.User WHERE id = ?

You can try the above command using cqlsh tool resides in cassandra/bin

Option1: Going through the WSO2DSS Management Console Wizard and configure
Option2: Use Developer Studio, create a CAR file and deploy it on WSO2DSS.

https://docs.wso2.com/display/DVS371/Creating+Data+Services+Server+Artifacts

Note: DSS generates a .dbs file which contains all the configurations, which you can find out in wso2dss-3.2.2\repository\deployment\server\dataservices location

Step 4: execute Cassandra queries from Soap UI
Get the WSDL from the WSO2DSS Management console, add it to the Soap UI and invoke

Contents of .dbs file
<data name="UserDS" transports="http https local">
    <config id="UserDataSource">
        <property name="cassandraServers">localhost</property>
    </config>
    <query id="createKeySpace" useConfig="UserDataSource">
        <expression>CREATE KEYSPACE UserKS WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1}</expression>
    </query>
    <query id="dropKeySpace" useConfig="UserDataSource">
        <expression>DROP KEYSPACE UserKS</expression>
    </query>
    <query id="createUserTable" useConfig="UserDataSource">
        <expression>CREATE TABLE UserKS.User (id text, name text, country text, PRIMARY KEY (id))</expression>
    </query>
    <query id="addUser" useConfig="UserDataSource">
        <expression>INSERT INTO UserKS.User (id, name, country) values (?,?,?)</expression>
        <param name="id" ordinal="1" sqlType="STRING"/>
        <param name="name" ordinal="2" sqlType="STRING"/>
        <param name="country" ordinal="3" sqlType="STRING"/>
    </query>
    <query id="getUsers" useConfig="UserDataSource">
        <expression>SELECT * FROM UserKS.User</expression>
        <result element="Users" rowName="User">
            <element column="id" name="id" xsdType="string"/>
            <element column="name" name="name" xsdType="string"/>
            <element column="country" name="country" xsdType="string"/>
        </result>
    </query>
    <query id="updateUser" useConfig="UserDataSource">
        <expression>UPDATE UserKS.User SET country = ? WHERE id =?</expression>
        <param name="country" sqlType="STRING"/>
        <param name="id" sqlType="STRING"/>
    </query>
    <query id="deleteUser" useConfig="UserDataSource">
        <expression>DELETE FROM UserKS.User WHERE id = ?</expression>
        <param name="id" sqlType="STRING"/>
    </query>
    <query id="getUserById" useConfig="UserDataSource">
        <expression>SELECT * FROM UserKS.User where id = ?</expression>
        <result element="Users" rowName="User">
            <element column="id" name="id" xsdType="string"/>
            <element column="name" name="name" xsdType="string"/>
            <element column="country" name="country" xsdType="string"/>
        </result>
        <param name="id" sqlType="STRING"/>
    </query>
    <operation name="createKeySpace">
        <call-query href="createKeySpace"/>
    </operation>
    <operation name="dropKeySpace">
        <call-query href="dropKeySpace"/>
    </operation>
    <operation name="createUserTable">
        <call-query href="createUserTable"/>
    </operation>
    <operation name="addUser">
        <call-query href="addUser">
            <with-param name="id" query-param="id"/>
            <with-param name="name" query-param="name"/>
            <with-param name="country" query-param="country"/>
        </call-query>
    </operation>
    <operation name="getUsers">
        <call-query href="getUsers"/>
    </operation>
    <operation name="updateUser">
        <call-query href="updateUser">
            <with-param name="country" query-param="country"/>
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <operation name="deleteUser">
        <call-query href="deleteUser">
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <operation name="getUserById">
        <call-query href="getUserById">
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <resource method="GET" path="user/get">
        <call-query href="getUsers"/>
    </resource>
    <resource method="GET" path="user/get/{id}">
        <call-query href="getUserById">
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
    <resource method="PUT" path="user/add/{id}/{name}/{country}">
        <call-query href="addUser">
            <with-param name="id" query-param="id"/>
            <with-param name="name" query-param="name"/>
            <with-param name="country" query-param="country"/>
        </call-query>
    </resource>
    <resource method="POST" path="user/update/{country}/{id}">
        <call-query href="updateUser">
            <with-param name="country" query-param="country"/>
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
    <resource method="DELETE" path="user/delete/{id}">
        <call-query href="deleteUser">
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
</data>