Class AutoScalerFactoryServer


  • public class AutoScalerFactoryServer
    extends java.lang.Object
    Main class with factory method for creating a REST API server that exposes an AutoScalerFactory.
    See Also:
    AutoScalerFactory, AutoScalerFactoryRestApi
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.eclipse.jetty.server.Server createServer​(com.elastisys.autoscaler.core.autoscaler.factory.AutoScalerFactory factory, AutoScalerFactoryServerOptions options)
      Creates a HTTPS server that serves REST API requests for a given AutoScalerFactory.
      static void launchServer​(AutoScalerFactoryServerOptions options, java.util.Map<java.lang.String,​java.lang.String> addonSubsystems)
      Launches an AutoScalerFactoryServer with the options and add-on subsystems.
      static java.util.Map<java.lang.String,​java.lang.String> loadAddons​(java.lang.String addonConfigPath)
      Loads any add-on subsystems from the given file path.
      static void main​(java.lang.String[] args)
      Parses command-line arguments and start an HTTPS server that serves REST API requests for an AutoScalerFactory.
      static AutoScalerFactoryServerOptions parseCommandLine​(java.lang.String[] args)
      Parses the command-line arguments and returns the AutoScalerFactoryServerOptions that were specified.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AutoScalerFactoryServer

        public AutoScalerFactoryServer()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Parses command-line arguments and start an HTTPS server that serves REST API requests for an AutoScalerFactory.

        A failure to parse the command-line arguments will cause the program to print a usage message and exit with an error code.

        The function blocks until the started server is stopped.

        Parameters:
        args - The command-line arguments.
        Throws:
        java.lang.Exception
      • launchServer

        public static void launchServer​(AutoScalerFactoryServerOptions options,
                                        java.util.Map<java.lang.String,​java.lang.String> addonSubsystems)
                                 throws java.lang.IllegalArgumentException,
                                        java.lang.InterruptedException
        Launches an AutoScalerFactoryServer with the options and add-on subsystems.

        The function blocks until the started server is stopped.

        Parameters:
        options - A set of options that control the behavior of the server.
        addonSubsystems - The collection of add-on subsystems that will be added to all AutoScaler instances the AutoScalerFactory creates. These add-on subsystems are not strictly necessary for the AutoScaler to operate, but may extend it with additional functionality. Accounting and high-availability are two examples of what such add-on subsystems could achieve. Keys are names, such as accountingSubsystem, and values are class names, such as com.elastisys.AccountingSubsystemImpl.
        Throws:
        java.lang.IllegalArgumentException
        java.lang.InterruptedException
      • parseCommandLine

        public static AutoScalerFactoryServerOptions parseCommandLine​(java.lang.String[] args)
        Parses the command-line arguments and returns the AutoScalerFactoryServerOptions that were specified. Will exit the process in case parsing failed or if --help or --version was specified.
        Parameters:
        args - Command-line arguments.
        Returns:
      • createServer

        public static org.eclipse.jetty.server.Server createServer​(com.elastisys.autoscaler.core.autoscaler.factory.AutoScalerFactory factory,
                                                                   AutoScalerFactoryServerOptions options)
        Creates a HTTPS server that serves REST API requests for a given AutoScalerFactory.

        The created server is returned with the AutoScalerFactory REST API deployed, but in an unstarted state, so the client is responsible for starting the server.

        The behavior of the HTTPS server is controlled via a set of AutoScalerFactoryServerOptions.

        Parameters:
        factory - The AutoScalerFactory to be published by the Server. Note: assumed to be passed in a configured state.
        options - A set of options that control the behavior of the HTTPS server.
        Returns:
        The created Server.
        Throws:
        java.lang.Exception - Thrown on a failure to initialize the AutoScalerFactory or create the server.
      • loadAddons

        public static java.util.Map<java.lang.String,​java.lang.String> loadAddons​(java.lang.String addonConfigPath)
        Loads any add-on subsystems from the given file path. On failure to parse the JSON file, an exception is raised.
        Parameters:
        addonConfigFile - A file system path.
        Returns:
        The collection of add-on subsystems to configure the autoscaler server with.