Multitenancy

So, I have set up multitenancy as per https://docs.axelor.com/adk/5.0/dev-guide/application/multi-tenancy.html but I have two questions, as I am not quite following the logic.

  1. Once set up, how do I access a particular tenant? That is, how do I log in as that tenant?
  2. I don’t follow db.db1.hosts = host1,host1:8080 What should go be replace host1 (if anything)?

Thanks in advance.

Hi,

If you have multitenancy, a combo is displayed at the login page.
For parameters, an exemple :

db.default.driver = org.postgresql.Driver
db.default.ddl = update
db.default.url = jdbc:postgresql://127.0.0.1:5432/db-default0
db.default.user = user1
db.default.password = password2

db.secondary.driver = org.postgresql.Driver
db.secondary.ddl = update
db.secondary.url = jdbc:postgresql://127.0.0.1:5432/db-default1
db.secondary.user = user2
db.secondary.password = password2

Hi, thanks for the feedback.

In your example, how would you get to the login for user2?

Hi,

This is the database login and not the user login.
Eg. in postgresql, you have to create 2 roles (user1 & user2) and to create 2 databases (db-defailt0 owner to user1, db-default1 owner to user2). This sujst an example, name your database and user as u want.

That’s it.

Thus, when use select the DB in the login page everything you 'll do will be applied to the selected database.

Regards

So, the url will look like example.com/user2/login.jsp ?

No, you are making a confusion. On Axelor you have to kind of accounts (users): login/password you are using to connect to the database (configured in the application.properties) and users that connect to the Axelor Web plateform.

On the application.properties you define your database(s) properties. Axelor requires as least 1 database but your can use severals (for test, pre-prod, etc.). To connect to a database you need a login and a password (define in the database system - eg. roles in postgresql), its the goal of the attribute db.default.user (the database user login) and db.default.password the database user password. When I say "user’ is the a people.

On example.com/login.jsp, if you have configured several properties you will have to select the database (default or secondary) and then to enter your user credential (eg. admin/admin) which are not stored in the application.properties but in a database’s table. Now, using the Administation menu you could create a new user.

Summary:

  1. login/passord defined in the application.properties are used for the database connection
  2. when connected on Axelor, use the Administration/Users menu to create new users (people accounts)

Okay, my confusion is that I am not seeing the ability to select the DB. There must be some error in the db set up.

I will work on it. I just did not understand what I ‘should’ be seeing. The rest I get.

Thanks again.

You can first test the db connection your defined in the application.properties using a client (eg. pgsql). If both connections work you should see the combo in the login page and then use the default axelor account admin (password admin. You need to restart tomcat after any modification of the application.properties.

Great. You have been very helpful. Much good karma to you.

just be care of : only default database supports DDL operations, schema for other tenants should be created manually

So to make it work you need to clone youe default database to the second one :slight_smile:

If you don’t really need multitenants, forget it…it’s an advise

Got it.

Would you suggest running multiple axelor instances on the same tomcat server?
Or multiple tomcat servers on the same platform?
Or none of the above?

there is no perfect answer:

Case 1: in this case you will have several URL due to tomcat root contexts that need to be different for each webApp (example.com/instance1/login.jsp and example.com/instance2/login.jsp)

Case 2: in this cas you will have several connection port due to tomcat bind (example.com:80 and example.com:81)

So nothing is perfec, it just depends of what is the goal of having several instances:

  1. if its for dev and prod, use 2 different server
  2. if its for several company you can solve point 1 & 2 by using a reverse proxy (eg. Apache) and make a specific reverse, using the requested domain, as a transparent action

Hello sir I have some multi-tency issues too and here is my setting:

#enable multi-tenancy
application.multi_tenancy = true

db.default.visible = false
db.default.driver = org.postgresql.Driver
db.default.ddl = update
db.default.url = jdbc:postgresql://localhost:5432/axelor
db.default.user = axelor
db.default.password = axelor

db.hh24.name = hh24
db.hh24.hosts = host1,127.0.0.1:8081,localhost:8081
db.hh24.driver = org.postgresql.Driver
db.hh24.url = jdbc:postgresql://localhost:5432/hh24
db.hh24.user = hh24
db.hh24.password = hh24

db.wpf.name = wpf
db.wpf.hosts = host1,127.0.0.1:8082,localhost:8082
db.wpf.driver = org.postgresql.Driver
db.wpf.url = jdbc:postgresql://localhost:5432/wpf
db.wpf.user = wpf

db.bm.name = bm
db.bm.hosts = 127.0.0.1:8083,localhost:8083
db.bm.driver = org.postgresql.Driver
db.bm.url = jdbc:postgresql://localhost:5432/bm
db.bm.user = bm
db.bm.password = bm

Could you tell if there is something wrong in my configuration?
Ideally If I am tenant “hh24” I would connect using port 8081(ea. “http://cloud.censon.us:8081/login.jsp”) so that I will be using the database named “hh24”.
If I am tenant “wpf” I would connect using port 8082(ea. “http://cloud.censon.us:8082/login.jsp”) so that I will be using the database named “wpf” and so on and so forth.

what is happening to my server is that it looks like it is “unable to resolve tenant id for some reason” and only the default/fallback database is used and when using ports other than the default ones my credentials “admin/admin” does not work.

Hi,

The “hosts” property in the tenant config is: host name based filter, the tenant is accessible from those hosts only (error in the doc, the numer 5 and 6 has been reversed). Thus don’t increment it like u done.

Now, with multi tenants, just connect to http://yourhost:8080/login.jsp (default access) and u you should see a combobox with the list of your tenants.

db.hh24.name = hh24
db.hh24.hosts = 127.0.0.1:8080,my_ip_address
db.hh24.driver = org.postgresql.Driver
db.hh24.url = jdbc:postgresql://localhost:5432/hh24
db.hh24.user = hh24
db.hh24.password = hh24

db.wpf.name = wpf
db.wpf.hosts = 127.0.0.1:8080,my_ip_address
db.wpf.driver = org.postgresql.Driver
db.wpf.url = jdbc:postgresql://localhost:5432/wpf
db.wpf.user = wpf

db.bm.name = bm
db.bm.hosts = 127.0.0.1:8080,my_ip_address
db.bm.driver = org.postgresql.Driver
db.bm.url = jdbc:postgresql://localhost:5432/bm
db.bm.user = bm
db.bm.password = bm

Good day sir,

I did your reccomendation but I still get this:

using tenant config provider: com.axelor.db.tenants.TenantConfigProviderImpl
2018-12-27 17:06:19.213 DEBUG 12750 — [ost-startStop-4] c.a.db.tenants.TenantConnectionProvider : using tenant: default
2018-12-27 17:06:19.214 DEBUG 12750 — [ost-startStop-4] c.a.db.tenants.TenantConnectionProvider : creating datasource for tenant config: TenantConfigImpl{tenantId=default, jdbcDriver=org.postgresql.Driver, jdbcUrl=jdbc:postgresql://localhost:5432/axelor}

and still I could not see a dropdown box/combo box anywhere to choose DB’s.

Hi,

I don’t think it’s a good idea to use the multi tenancy. Prefer to setup several WebApps instead.
Just to check, did you create other database with the [default] schema ?

Regards

Hello sir,

I created schma for other databases by running/booting each one of them once with axelor so that the tables there will be created. I can use those other databases to for main. Is there a best way to create schema for other tenants other thatn running them once as main/default db?

thanks sir for your replies :smiley:

Hi,

If you have created other databases as the default one it’s not normal that the combo on the login page is not displayed.

Did you set the property application.multi_tenancy to true ?

Regards

Hi,

I just want to apology because I found the problem: the name of the fields.
You need to respect the previx db[number] for each property. Eg:

db.db1.name = hh24
db.db1.hosts = 127.0.0.1:8080,my_ip_address
db.db1.driver = org.postgresql.Driver
db.db1.url = jdbc:postgresql://localhost:5432/hh24
db.db1.user = hh24
db.db1.password = hh24

db.db2.name = wpf
db.db2.hosts = host1,127.0.0.1:8082,localhost:8082
db.db2.driver = org.postgresql.Driver
db.db2.url = jdbc:postgresql://localhost:5432/wpf
db.db2.user = wpf

in this example, each property need to start with db.db[number] and not db.hh24 nor db.wpf.
Just try to replace db.hh24.* by db.db1., db.wpf.* by db.db2. and db.bm.* by db.db3. and it should work

So, your config should be (with correct login/password for each of course):

db.default.driver = org.postgresql.Driver
db.default.ddl = update
db.default.url = jdbc:postgresql://localhost:5432/default
db.default.user = default
db.default.password = default

db.db1.name = hh24
db.db1.hosts = 127.0.0.1:8080,my_ip_address
db.db1.driver = org.postgresql.Driver
db.db1.url = jdbc:postgresql://localhost:5432/hh24
db.db1.user = hh24
db.db1.password = hh24

db.db2.name = wpf
db.db2.hosts = 127.0.0.1:8080,my_ip_address
db.db2.driver = org.postgresql.Driver
db.db2.url = jdbc:postgresql://localhost:5432/wpf
db.db2.user = wpf
db.db2.password = wpf

db.db3.name = bm
db.db3.hosts = 127.0.0.1:8080,my_ip_address
db.db3.driver = org.postgresql.Driver
db.db3.url = jdbc:postgresql://localhost:5432/bm
db.db3.user = bm
db.db3.password = bm

Hi, i see the multi tanancy mode we must create multi database instance but i want make tenancy by data --> company / organization in this way How i can do it?
because it will take small size of database and make very easy to maintenance.
pls Help.
Thanks