Class ServiceConfiguration

java.lang.Object
org.gcube.smartgears.ServiceConfiguration

public final class ServiceConfiguration extends Object
The configuration of a service, read from "service.yaml" in its WEB-INF/classes, the file the provisioning writes for each environment.

The file is a YAML mapping of sections, each a mapping of keys to scalar values. Every value is read as its string form, so a quoted and an unquoted scalar give the same value; a key without a value is left out. A missing file, or one that is not a mapping of sections, is an error: a service does not start silently with default values.

The class is in the war of the service, so get() reads the file of that service and keeps it for the life of the application.

Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • FILENAME

      public static final String FILENAME
      The name of the configuration file of the service, on its class path.
      See Also:
  • Method Details

    • get

      public static ServiceConfiguration get()
      Returns the configuration of the service, read from "service.yaml" the first time.
      Returns:
      the configuration of the service
      Throws:
      IllegalStateException - if the file is missing, cannot be read or is not a mapping of sections
    • section

      public Map<String,String> section(String name)
      Returns a section of the configuration.
      Parameters:
      name - the name of the section
      Returns:
      its keys and values, or null when the file has no such section
    • requiredSection

      public Map<String,String> requiredSection(String name)
      Returns a section the service cannot work without.
      Parameters:
      name - the name of the section
      Returns:
      its keys and values
      Throws:
      IllegalStateException - if the file has no such section