This documentation is for WSO2 App Factory 1.0.0. View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

The sample is described in the following topics:


This sample demonstrates how to create and promote an application through its lifecycle stages and how to reuse the same datasource to connect to different databases at each stage.

A developer builds an application around customer data stored in an organization's database to which s/he does not have access to. S /he creates a database in development environment (developer cluster) with dummy customer data and points the application to the development database through a datasource. After development work is completed, the application is promoted to Testing and then over to Staging and production. At each of these stages, QA or a DevOps person maps the endpoint URL of the development database and points the same datasource to QA or the production database.


Set up App Factory using the instructions given in section Getting Started.

Executing the Sample

  1. Log in to the App Factory portal, click the Add New Application button and provide the details of the new application. In this sample, we use,
    Application name : Cust_PortalApp1
    Application type : Web Application
    epository type : Git
  2. Click Create Application once done. Wait a few seconds for the application creation process to complete. It takes some time because multiple tasks such as creating a new code repository for your application run in the background.

    After the application is created, it has the following readily available in the App Factory portal.

    • Source control
    • Build system
    • Deployment environment
  3. Next, go to the Team tab in the portal and invite 3 members to your team as a Developer, a QA and a DevOps.
  4. Log in to App Factory portal as the developer and check out the application's code repository to your local environment using the following command.

    git clone
    You can find the repository URL from the Repos and Builds tab on the left panel of the App Factory portal.

  5. Next step is for the developer to code the Web application. In this sample we use a pre-built code. You can find it  in <AF_HOME>/samples directory and commit it to the Cust_PortalApp1 application created above using the following Git commands:

    //To add all the changes in a directory
    git add * 
    //To commit the changes
    git commit -am "Committing changes"
    //To push the commits
    git push 


  6. Click the Resource tab from the left panel and then click the Create Database button to create two new databases as Portal and TestPortal. Be sure to select the Advanced Options and create custom database user (user1 in this sample) and a permission template (template1 in this sample) as follows:

  7. Click the Resource tab again, then Datasources tab and and then click the Create Datasource button to create a new datasource by the name customer_ds. Refer Datasources for more details.  
  8. Log into MySQL using the command: mysql -u user1_eGIAAXhi -h -p where  user1_eGIAAXhi is the database user.
  9. Run the following MySQL database scripts. They fill the databases created in step 5 with test data. You can find the same scripts in <AF_HOME>/samples/CustomerPortal/dbscripts folder.

    Prod database script:

    USE TestPortal;
    CREATE TABLE IF NOT EXISTS Customer (Name VARCHAR (20), Category VARCHAR (20), Region VARCHAR (20));
    INSERT INTO Customer(Name, Category, Region) VALUES ('Bar Bank','Banking', 'Asia');
    INSERT INTO Customer(Name, Category, Region) VALUES ('Doo International','Travel', 'Europe');
    INSERT INTO Customer(Name, Category, Region) VALUES ('Foo','Retail', 'USA');

    Development/Test/Staging database script:

    USE Portal;
    CREATE TABLE IF NOT EXISTS Customer (Name VARCHAR (20), Category VARCHAR (20), Region VARCHAR (20));
    INSERT INTO Customer(Name, Category, Region) VALUES ('Bank of Ceylon','Banking', 'Asia');
    INSERT INTO Customer(Name, Category, Region) VALUES ('Sun Travels','Travel', 'Europe');
    INSERT INTO Customer(Name, Category, Region) VALUES ('My Home','Retail', 'USA');
    INSERT INTO Customer(Name, Category, Region) VALUES ('Herbal Spa','Health', 'USA');
    INSERT INTO Customer(Name, Category, Region) VALUES ('Kids Unlimited','Retail', 'USA');
    INSERT INTO Customer(Name, Category, Region) VALUES ('Cologne Mart','Retail', 'Midle East');


  10.  Create a branch of the application Cust_PortalApp1 added in step 1 and deploy it to App Server in Development environment. You can do this using Repos and Builds tab in App Factory portal. For more information, see Building and Deploying the Application   

  11. You can click the Test button associated with the branch in the Repos and Builds page to run the application. Also, you can do more changes to the code, check in to the repository again and build and deploy as explained above.
  12. After the development process is done, the developer promotes the application to Testing. You can do this by selecting Lifecycle Management tab in the App Factory portal and clicking Promote.
  13. Now the application is in Testing stage. Log in to the app Factory portal as a QA role, go to Resources tab and select Datasources.
  14. Click the datasource name created earlier (customer_ds in this case). You can point the same datasource to the QA database created in step 6 (TestPortal in this case).
    Simply select the Stage as Testing and give the URL of the QA database as follows:

  15. Similarly, after promoting the application to Staging, log in as a DevOps person and edit the datasource to point to the production database.  
  16. DevOps can run tests and then promote the application to production.

You have created an application and taken it through its lifecycle stages by reusing the same datasource to point to different databases at different levels.

Also see Reusing an Endpoint in all Lifecycle Stages on how to create and reuse an endpoint resource though the application's lifecycle stages.

  • No labels