The sample is described in the following topics:
|Table of Contents|
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
- 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 :
Application type :
Web ApplicationR epository type :
- 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
- Next, go to the Team tab in the portal and invite 3 members to your team as a Developer, a QA and a DevOps.
- 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.
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_PortalApp1application 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
Click the Resource tab from the left panel and then click the Create Database button to create two new databases as
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:
- 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.
- Log into MySQL using the command:
mysql -u user1_eGIAAXhi -h rss.dev.appfactorypreview.wso2.com -pwhere
user1_eGIAAXhiis the database user.
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');
Create a branch of the application
Cust_PortalApp1added 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.
- 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.
- 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.
- 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.
- Click the datasource name created earlier (
customer_dsin this case). You can point the same datasource to the QA database created in step 6 (
TestPortalin this case).
Simply select the Stage as Testing and give the URL of the QA database as follows:
- Similarly, after promoting the application to Staging, log in as a DevOps person and edit the datasource to point to the production database.
- 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.