com.elastisys.scale.cloudpool.api.restapi

## Class ConfigHandler

- java.lang.Object
- - com.elastisys.scale.cloudpool.api.restapi.ConfigHandler

    @Path(value="/config")
     @Consumes(value="application/json")
     @Produces(value="application/json")
    public class ConfigHandler
    extends Object

A REST response handler that handles requests to get (`GET`) and set ( `POST`) the `CloudPool` configuration.

### Field Summary

Fields
`static String` `DEFAULT_CONFIG_FILE_NAME` Default file name (within the storage directory) in which `CloudPool` configuration is stored.

### Constructor Summary

Constructors
Constructor and Description
`ConfigHandler(CloudPool cloudPool, String storageDir)` Creates a `ConfigHandler` that will store set `CloudPool` configurations under a given storage directory with the `DEFAULT_CONFIG_FILE_NAME`.
`ConfigHandler(CloudPool cloudPool, String storageDir, String configFileName)` Creates a `ConfigHandler` that will store set `CloudPool` configurations under a given storage directory with a given file name.

### Method Summary

All Methods Instance Methods Concrete Methods
`Path` `getCloudPoolConfigPath()` Returns the file system path where the `ConfigHandler` stores received `CloudPool` configurations.
`javax.ws.rs.core.Response` `getConfig()` Retrieves the configuration currently set for the `CloudPool`.
`javax.ws.rs.core.Response` `setAndStoreConfig(com.google.gson.JsonObject configuration)` Sets the configuration for the `CloudPool`.
`void` `storeConfig(com.google.gson.JsonObject configuration)` Stores a configuration in the `storageDir`, to allow it to be restored when the `CloudPool` is restarted.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_CONFIG_FILE_NAME

    public static final String DEFAULT_CONFIG_FILE_NAME

Default file name (within the storage directory) in which `CloudPool` configuration is stored.

See Also:
  Constant Field Values

### Constructor Detail

#### ConfigHandler

    public ConfigHandler(CloudPool cloudPool,
                         String storageDir)

Creates a `ConfigHandler` that will store set `CloudPool` configurations under a given storage directory with the `DEFAULT_CONFIG_FILE_NAME`.

Parameters:
  `cloudPool` - The back-end `CloudPool` that is being managed.
  `storageDir` - The directory path where runtime state for the `CloudPool` is stored. The `ConfigHandler` will use this directory to store every set configuration so that it can be restored on restart. The directory will be created if it does not exist.

#### ConfigHandler

    public ConfigHandler(CloudPool cloudPool,
                         String storageDir,
                         String configFileName)

Creates a `ConfigHandler` that will store set `CloudPool` configurations under a given storage directory with a given file name.

Parameters:
  `cloudPool` - The back-end `CloudPool` that is being managed.
  `storageDir` - The directory path where runtime state for the `CloudPool` is stored. The `ConfigHandler` will use this directory to store every set configuration so that it can be restored on restart. The directory will be created if it does not exist.
  `configFileName` - The file name, within the `storageDir`, in which `CloudPool` configuration is stored.

### Method Detail

#### getConfig

    @GET
    public javax.ws.rs.core.Response getConfig()

Retrieves the configuration currently set for the `CloudPool`.

Returns:
  - On success: HTTP response code 200 with a JSON-formatted configuration.
  - On error: HTTP response 404 (Not Found) if no configuration has been set. On other errors: HTTP response code 500 with an `ErrorType` message.

#### setAndStoreConfig

    @POST
    public javax.ws.rs.core.Response setAndStoreConfig(com.google.gson.JsonObject configuration)

Sets the configuration for the `CloudPool`.

Parameters:
  `configuration` - The (JSON) configuration document to set.
Returns:
  - On success: HTTP response code 200 without content.
  - On error:
    - on illegal input: HTTP response code 400 with an `ErrorType` message
    - otherwise: HTTP response code 500 with an `ErrorType` message

#### storeConfig

    public void storeConfig(com.google.gson.JsonObject configuration)
                     throws IOException

Stores a configuration in the `storageDir`, to allow it to be restored when the `CloudPool` is restarted.

Parameters:
  `configuration` -
Throws:
  `IOException` - If the configuration could not be stored.

#### getCloudPoolConfigPath

    public Path getCloudPoolConfigPath()

Returns the file system path where the `ConfigHandler` stores received `CloudPool` configurations.

Parameters:
  `storageDir` -
Returns: