The purpose of this document is to provide a solution for the scenario of a multi-tenant application that uses GXflow and GAM, where the application is also to be deployed in the same Web Application, using the same database with the system’s and the GAM’s tables for all Tenants in the application.
Since GXflow does not support a multi-tenant schema where all tenants share the same database, the architecture recommended for such a scenario is the following:
- There is a database with the tables corresponding to the system and the GAM.
- A GXflow database is necessary for each tenant.
- The application’s binaries are deployed in the same Web Application, meaning that, the binaries of the application, and of the GAM and GXflow will be executed on the same Web Application.
- For this scenario, it is recommended to set up the GXflow licenses on a protection server, in order to centralize their administration.
- It is not possible to use the SQL statement cache in this scenario.
Below is a description of the steps to follow in setting up the development environment.
- Activate GAM and create a database with tables in the application and the GAM.
- Modify the connection.gam to allow the possibility of creating multiple repositories.
- Go to the option: Tools\GeneXus Access Manager\Update connection file, enter with user gamadmin, and select both repositories. (For further details on how to set up the GAM in this scenario, read Multiple Repositories Scenario: The same application installation is shared by many companies).
- This will enable the possibility of access with user gamadmin to create new repositories for each Tenant.
- Create GXflow datastore and indicate a database name different from that of the Default datastore.
- Create some process diagrams to enable GXflow in the KB.
- In the Environment properties, set up the "Deploy business processes on build" property with value No.
- Export the processes created with the BPDeployer tool.
- Execute the BPDeployer tool and import the exported processes. This tool will create the database the first time, as well as the GXflow tables, in addition to impacting the exported processes.
- A procedure must be created to associate the Before Connect event, where information on the session is read to define the company, and based on it, you obtain the logic on which is the name of the GXflow database that corresponds to that company.
- This is an example of how this procedure could be done, assuming that the session variable 'CompanyId' was previously set up in the system’s login screen and that the name of the GXflow database is parameterized for each company.
&CompanyId = val(&Session.Get('CompanyId'))
Where CompanyId = &CompanyId
&Database = CompanyDatabaseName
If not &Database.IsEmpty()
&dbconn = GetDatastore('GXflow')
&dbconn.ConnectionData = 'DATABASE=' + &Database.Trim()
- Disabling the automatic synchronization that the IDE does between the GAM and GXflow is recommended. To that end, a config.gx file must be created in the KB’s root directory, with content DisableGamRolesSync= True
- Edit the file client.exe.config with the information of the GXflow datastore so that it will point to the new database.
- Execute, by commands line, the apwfinitializegam.exe program, passing, as a parameter, the name of the repository created in step 1. This will be initiating the roles of GXflow, the permits, and the subscriptions to events within the GAM.
When you want to include changes at the process level, the following is required:
1. Create an export of the changes with the option Tools > Workflow > Create business deploy file and select the processes to be exported. This will also take the information of the Roles defined in the IDE.
2. Use the Business Process Deployer tool to import the file generated in the previous step, connecting to the GXflow base.
3. To synchronize the new roles with the GAM you must:
1. Edit the client.exe.config file with the information of the GXflow datastore so that it will point at the GXflow database.
2. Execute, commands line, the apwfmigraterolestogam.exe program, passing, as a parameter, the name of the GAM’s repository against which you want to synchronize.
The following steps indicate what must be done on the GAM side and on the GXflow in order to add a new Tenant to the system:
- Create a new repository in the GAM.
- Export, with the BPDeployer tool, the corresponding processes for the new Tenant.
- Use the BPDeployer tool and select the file generated in step 2.
- This tool will create the database if it does not exist, as well as the GXflow tables for the first time. It will also impact the processes and roles within the GXflow tables.
- Edit the client.exe.config file with the information of the GXflow datastore so that it will point at the new GXflow database.
- Execute, by commands line, the apwfinitializegam.exe program, passing, as a parameter, the name of the repository created in step 1.
- Execute, by commands line, the apwfmigraterolestogam.exe program, passing, as a parameter, the name of the repository created in step 1, to synchronize the roles defined in GXflow towards the GAM repository.
- Go to the GXflow License Manager Web and set up the licenses.
- Following the previous steps, you may start creating users that will be part of the processes and assign to them the "GXflow Public" role, in addition to the typical roles of the processes.