Datasource is the name given to the connection set up to a database from a server. You can configure datasources to connect to remote databases from App Factory. Each time you create a database, a respective datasource is automatically created in App Factory.
App Factory uses the same datasource name to connect the application with different databases in different environments. When you promote/demote an application from one lifecycle stage to another, App Factory automatically connects it with respective databases using the same datasource name. This datasource uses a unique name but is registered with different connection details across different stages of the application's life cycle.
Figure 1: Same datasource name is registered in all environments
The four default App Factory user roles have different levels of permissions in creating and configuring datasources as shown below:
Anchor above above
|User Role||Level of Permissions|
|App Owner||Can create and edit datasources in Development, Testing and Staging environments|
|Developer||Can create and edit datasources in Development and Testing environments|
|QA||Can configure a datasource in Testing and Staging environments|
|DevOps||Can configure a datasource in Staging and Production environments|
The section covers the following topics:
Table of Contents
Creating a datasource
Before you start creating a datasource, create a database using either the App Factory portal or externally in the respective RDBMS's workbench. After creating the database, follow the instructions below to create the datasource to connect to the database.
- Log in to the App Factory portal (for the online version, try https://appfactorypreview.wso2.com). See the table above for information on which role can configure datasources in which lifecycle stage.
- Select an application from the list of apps that you own or are invited to participate in.
- Click the Resources tab from the left panel.
- The Resource Overview page.
- Click the Create Datasource button in the Overview page. Alternatively, you can go to the Datasources tab and click Create Datasource.
Provide the necessary details in the form that opens and click Create Datasource. For example,
Some of the fields are described below:
Field Name Description Database URL Url to access the database JDBC URL FORMAT: jdbc:mysql://<host>:<port>/<database_name> Database Driver Only mysql database driver is supported. In future other drivers will be supported. Username/Password The given credentials while creating the database.
If the check boxes are checked, this datasource will be copied to Testing and/or Staging.
Reusing the datasource in different environments
You can configure the same datasource to point to different databases in different stages of the lifecycle. To do this, click on the name of the datasource and edit its Stage and database connection details.
The Stage drop-down list is populated only by the lifecycle stages the current user has access to. For example, if you are added to this application as a QA person, you have permission to configure datasources only in Testing and Staging life-cycle stages. Therefore, the Stage drop-down list will be populated only by those two stages. You can read more about datasource editing permissions above.
After creating the datasource, you can use it in your applications as follows.
Also see sample Reusing a Datasource in all Lifecycle Stages. It explains how to define a datasource for an application and how to use it to point to different databases in different lifecycle stages of the application.