Class FileSettingsService

All Implemented Interfaces:
Closeable, AutoCloseable, ClusterStateListener, LifecycleComponent, Releasable

public class FileSettingsService extends MasterNodeFileWatchingService implements ClusterStateListener
File based settings applier service which watches an 'operator` directory inside the config directory.

The service expects that the operator directory will contain a single JSON file with all the settings that need to be applied to the cluster state. The name of the file is fixed to be settings.json. The operator directory name can be configured by setting the 'path.config.operator_directory' in the node properties.

The FileSettingsService is active always, but enabled only on the current master node. We register the service as a listener to cluster state changes, so that we can enable the file watcher thread when this node becomes a master node.

  • Field Details

  • Constructor Details

    • FileSettingsService

      public FileSettingsService(ClusterService clusterService, ReservedClusterStateService stateService, Environment environment)
      Constructs the FileSettingsService
      Parameters:
      clusterService - so we can register ourselves as a cluster state change listener
      stateService - an instance of the immutable cluster state controller, so we can perform the cluster state changes
      environment - we need the environment to pull the location of the config and operator directories
  • Method Details

    • handleSnapshotRestore

      public void handleSnapshotRestore(ClusterState clusterState, Metadata.Builder mdBuilder)
      Used by snapshot restore service RestoreService to prepare the reserved state of the snapshot for the current cluster.

      If the current cluster where we are restoring the snapshot into has any operator file based settings, we'll reset the reserved state version to 0.

      If there's no file based settings file in this cluster, we'll remove all state reservations for file based settings from the cluster state.

      Parameters:
      clusterState - the cluster state before snapshot restore
      mdBuilder - the current metadata builder for the new cluster state
    • shouldRefreshFileState

      protected boolean shouldRefreshFileState(ClusterState clusterState)
      If the file settings metadata version is set to zero, then we have restored from a snapshot and must reprocess the file.
      Overrides:
      shouldRefreshFileState in class MasterNodeFileWatchingService
      Parameters:
      clusterState - State of the cluster
      Returns:
      true if file settings metadata version is exactly 0, false otherwise.
    • processFileChanges

      protected void processFileChanges() throws ExecutionException, InterruptedException, IOException
      Read settings and pass them to ReservedClusterStateService for application
      Specified by:
      processFileChanges in class AbstractFileWatchingService
      Throws:
      IOException - if there is an error reading the file itself
      ExecutionException - if there is an issue while applying the changes from the file
      InterruptedException - if the file processing is interrupted by another thread.