How to control Jelastic Traffic Distributor via API

227 Views Asked by At

Traffic Distributor (https://docs.jelastic.com/traffic-distributor) is a cool feature which add's load balancing to your app and enables Blue/Green deploy. However, seems that there's no API to control traffic distributor so it's impossible to automate new releases rollout.

Is there a way to do this?

1

There are 1 best solutions below

1
On BEST ANSWER

There is a possibility to create and control Traffic Distributor via API.

Let us explain the flow...

At first, you should login to the platform and get your session. This can be done by next API request:

https://app.{platform_domain}/1.0/users/authentication/rest/signin/login={your_email}&password={your_password}

If you are using Jelastic platform v5.1+ you should perform the mentioned request as POST.

As example, you can do this using curl:

curl 'https://app.{platform_domain}/1.0/users/authentication/rest/signin' -d "login={your_email}&password={your_password}"

Next, you can create the Traffic Distributor using this request:

http://appstore.{platform_domain}/InstallApp?envName=[env_name]&session=[your_session]&jps=traffic-distributor&displayName=[disp_env_name]&settings={"extip":true,"balancerCount":1,"routingMethod":"round-robin","range":50,"backend1":"{environment_1}","backend2":"{environment_2}"}

, where

  • [env_name] - the name of the environment.

  • [disp_env_name] - the visible name of the environment in the Dashboard.

  • [your_session] - your session, which can be taken from the response of the previous request.

The necessary settings of the Traffic Distributor can be specified inside the JSON:

  • extip - enables the external IP for the Traffic Distributor ( Highly recommended! ).
  • balancerCount - count of the balancers inside the Traffic Distributor. (by default = 1)
  • routingMethod - defines the necessary method of the traffic's routing.

You can specify next possible values: round-robin, sticky-sessions or failover

  • range - define the percent of the traffic, that will be routed to the first environment.

For example: 0 - All requests will be routed to the {environment_2}, 100 - All requests will be routed to the {environment_1}, 50 - All requests will be balanced between environments equally.

  • {environment_1} - URL to the first environment like env-XXXXXXX.{platform_domain}
  • {environment_2} - URL to the second environment like env-XXXXXXX.{platform_domain}

After executing this method - Traffic Distributor will appear in the Jelastic Dashboard.

Please, execute next API request to take the "uniqueName" value from the response (inside the Addons section):

https://app.{Platform_domain}/1.0/environment/control/rest/getenvinfo?envname=[env_name]&session=[your_session]

, where [env_name] - the name of the created environment with the Traffic Distributor addon.

Now you can control the settings of the created Traffic Distributor by next API:

https://appstore.{Platform_domain}/ExecuteAppAction?session=[your_session]&appUniqueName=[app_unique_name]&action=configure&params={"extip":1,"balancerCount":1,"routingMethod":"sticky-sessions","range":50,"backend1":"{environment_1}","backend2":"{environment_2}"}

, where

[app_unique_name] - the value "uniqueName" from the response of the previous request.

The settings inside the JSON exactly the same as for the InstallApp API request.