# Module autoscale

- Description
- Data Types
- Function Index
- Function Details

Auto-scaling service.

Copyright © 2013-2015 Zuse Institute Berlin

Version: $Id$

Behaviours: `gen_component`.

Authors: Ufuk Celebi (`celebi@zib.de`).

## Description

Auto-scaling service.

{autoscale, true} in scalaris.local.cfg will enable this service.

The main task of the autoscale is to manage a set of installed alarms by calling their alarm handlers periodically. Every alarm handler can request to add or remove VMs (see alarm_handler/2).

Alarms are read from the config as a list of alarm records: {autoscale_alarms, [{alarm, Name (req.), Options (opt.), Interval (opt.), Cooldown (opt.), State (opt.)}]}.

Every provided tuple corresponds to the alarm record type: - Name: the name of the alarm handler (should be unique) - Options: options are alarm handler specific (see alarm_handler/2) - Interval: interval between alarm checks in seconds - Cooldown: interval after a scale request - State: active or inactive

Example: {autoscale_alarms, [{alarm, rand_churn, [{lower_limit, -3}, {upper_limit, 10}], 60, 0, inactive}, {alarm, lat_avg, [], 60, 120, inactive}]}.

In this example, the rand_churn alarm handler is called every 60 seconds and configured with the options lower_limit and upper_limit. The lat_avg alarm handler is called every 60 seconds and falls back to the default options (set in the alarm handler), because no options are provided. If the lat_avg handler requested to add or remove VMs, the handler will be called after 120 seconds in order to allow the changes to take effect (cooldown).

VMs requests are handled by the cloud module. It can be configured with {autoscale_cloud_module, CloudModule}.

Possible modules are: cloud_local, cloud_ssh, and cloud_cps. For both cloud_local and cloud_ssh, scale requests are pushed by autoscale, for cloud_cps, autoscale expects pulling of requests.

cloud_cps is a dummy and not actually implemented as a module. Instead, the manager of the ConPaaS scalaris service needs to pull the current request via the JSON API.

## Data Types

### alarm()

    alarm() =
        #alarm{name = atom(),
               options = key_value_list(),
               interval = pos_integer(),
               cooldown = non_neg_integer(),
               state = active | inactive}

### alarms()

    alarms() = [alarm()]

### api_message()

    api_message() =
        {pull_scale_req, Pid :: pid()} |
        {unlock_scale_req, Pid :: pid()} |
        {toggle_alarm, Name :: atom(), Pid :: pid()} |
        {activate_alarms, Pid :: pid()} |
        {deactivate_alarms, Pid :: pid()}

### key_value_list()

    key_value_list() = [{Key :: atom(), Value :: term()}]

### message()

    message() =
        {get_state_response, MyRange :: intervals:interval()} |
        {check_alarm, Name :: atom()} |
        {push_scale_req} |
        api_message()

### scale_req()

    scale_req() =
        #scale_req{req = integer(),
                   lock = locked | unlocked,
                   mode = push | pull}

### state()

    state() =
        {IsLeader :: boolean(),
         Alarms :: alarms(),
         ScaleReq :: scale_req(),
         Triggers :: triggers()}

### triggers()

    triggers() = [{Name :: atom(), Trigger :: reference() | ok}]

## Function Index

check_config/0 | Checks whether config parameters exist and are valid.
init/1 |
on/2 | Set new leader state at startup and ring changes.
rm_exec/5 |
send_my_range_req/4 | Request my_range from dht_node (called by rm_loop at direct neighborhood changes).
start_gen_component/5 |
start_link/1 |

## Function Details

### start_gen_component/5

    start_gen_component(Module :: module(),
                        Handler :: gen_component:handler(),
                        Args :: term(),
                        Options :: [gen_component:option()],
                        Self :: pid()) ->
                           no_return() | ok

### on/2

    on(Msg :: message(), State :: state()) -> state()

Set new leader state at startup and ring changes.

### send_my_range_req/4

    send_my_range_req(Pid :: pid(),
                      Tag :: autoscale,
                      _OldN :: nodelist:neighborhood(),
                      _NewN :: nodelist:neighborhood()) ->
                         ok

Request my_range from dht_node (called by rm_loop at direct neighborhood changes).

### start_link/1

    start_link(DHTNodeGroup :: pid_groups:groupname()) -> {ok, pid()}

### init/1

    init(X1 :: []) -> state()

### check_config/0

    check_config() -> boolean()

Checks whether config parameters exist and are valid.

### rm_exec/5

    rm_exec(Pid :: pid(),
            Tag :: autoscale,
            OldNeighbors :: nodelist:neighborhood(),
            NewNeighbors :: nodelist:neighborhood(),
            Reason :: rm_loop:reason()) ->
               ok

Generated by EDoc, Feb 29 2016, 16:12:17.