Add Simple Replicate Software Type

Agenda

  • Prerequisite
  • Add Replicate Instance to request 2 default html5as instances
  • Add new software type to the software release
  • Verification

In this tutorial we take the first step in transforming html5as in a CDN.

Two elements are introduced. Having different type of instances in the same software release. Requesting other instances of a different type from a root instance. The elements are the first step to deploy complex interconnected services.

Here is the commit introducing this functionality to html5as Software release: commit diff.

Prerequisite

Software Types

  • Root Software Instance
  • Default
  • Resilient
  • Database
  • Balancer
  • Cache
  • Mailer
  • etc...

Software Types are used to specialise instances inside a Software Release. This is used to define how an instance is going to be used in a more complex software. For instance, in an ERP5, we have one Software release for the whole ERP system, but we have an instance for the database, an instance for the web services, an instance for cache, an instance for organizing all instances together and so on. The file instance.cfg.in act as a switch that to pick which kind of instance we are going to deploy. By default the type is "default" or "RootSoftwareType". Having more software types allow to make more complex software release and offer more flexibility when deploying. If a service can be split in different instance it can be deployed on multiples servers.

Other Examples:

A CDN, is by definition deployed across multiple servers. Two type of services are needed for a CDN: The frontends providing the content and a service to orchestrate these frontends. So a software release for a CDN will have two software types: "frontend" running the actual service and "replicate" to replicate this service across the world.

For a lamp stack we may want to have the database in a different instance as the apache php. So this instance will have three software types: "mariadb" which host the database of the lamp stack, "apache" which host the php processing and access to the service and the "default" type which is in charge of requesting and coordinating the two previous types.

Add Replicate Instance template

Create a new file software/html5as-base/instance_replicate.cfg.in with the following content

{% set parameter_dict = dict(default_parameter_dict, **slapparameter_dict) %}

# Standard buildout section
[buildout]
parts =
    publish-connection-information

eggs-directory = {{ buildout['eggs-directory'] }}
develop-eggs-directory = {{ buildout['develop-eggs-directory'] }}
offline = true

################################
# Sections to Request instances
################################

# Macro section sharing request parameters
[instance-request-base]
<= slap-connection
recipe = slapos.cookbook:request
# It is the same software as the current one
software-url = ${slap-connection:software-release-url}
# We want the default behaviour
software-type = default
# What parameter are neede to be retrieved
return = server_url server-cdn-url monitor-setup-url
# Provided parameters
config-title = {{ parameter_dict['title'] }}
config-download_url = {{ parameter_dict['download_url'] }}

# Request a normal html5as instance
[instance-1]
<= instance-request-base
# Name of the instance
name = instance-html5as-1
# Port and title can be configured by instance
config-port = {{ parameter_dict['port1'] }}
config-title = {{ parameter_dict['title1'] }}
config-monitor-httpd-port = {{ parameter_dict['monitor-httpd-port1'] }}

# Request a second html5as instance
[instance-2]
<= instance-request-base
# Name of the instance
name = instance-html5as-2
config-port = {{ parameter_dict['port2'] }}
config-title = {{ parameter_dict['title2'] }}
config-monitor-httpd-port = {{ parameter_dict['monitor-httpd-port2'] }}

# Publish information to connect to the two instances
[publish-connection-information]
recipe = slapos.cookbook:publish
instance-1-server_url = ${instance-1:connection-server_url}
instance-1-server-cdn-url = ${instance-1:connection-server-cdn-url}
instance-1-server-monitor-setup-url = ${instance-1:connection-monitor-setup-url}
instance-2-server_url = ${instance-2:connection-server_url}
instance-2-server-cdn-url = ${instance-1:connection-server-cdn-url}
instance-2-server-monitor-setup-url = ${instance-1:connection-monitor-setup-url}

Add section for replicate template

Refer How To Move to md5sum automatic update to add the new section [template_instance_replicate] at the end of buildout.hash.cfg:

[template_instance_replicate]
_update_hash_filename_ = instance_replicate.cfg.in
md5sum = 

Add section for replicate template

Add the new section [template_instance_replicate] in software.cfg

[template_instance_replicate]
<= download-base

Process replicate template

Add key template_instance_replicate template_instance_replicate:target in template-cfg:context in software.cfg

[template-cfg]
...
  key template_instance_replicate template_instance_replicate:target
...

Render replicate instance template

Add the new section [instance-replicate] in instance.cfg.in

[instance-replicate]
recipe = slapos.recipe.template:jinja2
url = {{ template_instance_replicate }}
output = ${buildout:directory}/${:filename}
filename = instance-replicate-html5as.cfg
context =
  section buildout buildout
  section parameter_list profile-common
  key slapparameter_dict slap-configuration:configuration
  jsonkey default_parameter_dict :default-parameters
# User can specify parameter for any of the two instances
default-parameters =
  {
    "title": "",
    "title1": "",
    "title2": "",
    "download_url": "",
    "port1": 8081,
    "port2": 8082,
    "monitor-httpd-port1": 8197,
    "monitor-httpd-port2": 8198
  }

Add replicate software type

In the [switch-softwaretype] section of instance.cfg.in, add the replicate key. This section recipe acts as a switch using the software type value. It will process the instance file whose key match the software type.

[switch-softwaretype]
...
replicate = instance-replicate:output

Update md5sums

Refer How To Move to md5sum automatic update to update md5sum:

$ cd ~/srv/project/slapos/software/html5as-base
$ ../../update-hash

Validation

  1. Request a replicate html5as
  2. Verify connection parameters
 

Request a replicate html5as

To request a replicate type of sofware, you should define the type in the request script:

slapos request $software_name'_1' $software_release_uri --type="replicate"

Make sure to edit it in your request file (request-html5as-base.sh) instead of the example one. Make also sure that there is only one slapos request in your script (the one above).

Run the request script by

$ cd ~/srv/project/slapos/software/html5as-base
$ bash ../../../request-html5as-base.sh 

Re-compile the software by

$ slapos node software --all

Once it completes, you may re-instantiate it by

$ slapos node instance --all

The instanciation should raise, run it until there are no error displayed. The compiling and instantiation should be completed.

Verify connection parameters

Make sure that the compiling and instantiation is completed. You can now inspect the connection parameters by re-running the request script:

$ cd ~/srv/project/slapos/software/html5as-base
$ . ../../../request-html5as-base.sh 

It is obviously that the software type is switched to "replicate" because the output of connection parameters are corresponding to what you have defined in instance_replicate.cfg.in.

Thank You

  • Rapid.Space
  • 147 Rue du Ballon
  • 59110 La Madeleine
  • France
  • +33629024425
  • contact (@) rapid.space

For more information, please contact Jean-Paul, CEO of Rapid.Space (+33 629 02 44 25).