Class FileSettingsService
- All Implemented Interfaces:
Closeable,AutoCloseable,ClusterStateListener,LifecycleComponent,Releasable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classStateless service that maps aFileSettingsService.FileSettingsHealthInfoto aHealthIndicatorResult.static final recordstatic classHouses the currentFileSettingsService.FileSettingsHealthInfoand provides a means to publish it to the health node. -
Field Summary
FieldsFields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle -
Constructor Summary
ConstructorsConstructorDescriptionFileSettingsService(ClusterService clusterService, ReservedClusterStateService stateService, Environment environment, FileSettingsService.FileSettingsHealthTracker healthIndicatorTracker) Constructs theFileSettingsService -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcompleteProcessing(Exception e, PlainActionFuture<Void> completion) protected XContentParsercreateParser(InputStream stream) protected voiddoStart()Start this component.protected voiddoStop()Stop this component.protected booleanfilesExists(Path path) protected booleanfilesIsDirectory(Path path) protected booleanfilesIsSymbolicLink(Path path) protected InputStreamfilesNewInputStream(Path path) protected <A extends BasicFileAttributes>
AfilesReadAttributes(Path path, Class<A> clazz) protected PathfilesSetLastModifiedTime(Path path, FileTime time) voidhandleSnapshotRestore(ClusterState clusterState, Metadata.Builder mdBuilder, ProjectId projectId) Used by snapshot restore serviceRestoreServiceto prepare the reserved state of the snapshot for the current cluster.protected org.apache.logging.log4j.Loggerlogger()protected voidonProcessFileChangesException(Path file, Exception e) Called for checked exceptions only.protected voidprocessFile(Path file, boolean startup) protected final voidprocessFileChanges(Path file) Read settings and pass them toReservedClusterStateServicefor applicationprotected final voidRead settings and pass them toReservedClusterStateServicefor application.protected voidprotected booleanshouldRefreshFileState(ClusterState clusterState) If the file settings metadata version is set to zero, then we have restored from a snapshot and must reprocess the file.Methods inherited from class org.elasticsearch.common.file.MasterNodeFileWatchingService
clusterChangedMethods inherited from class org.elasticsearch.common.file.AbstractFileWatchingService
doClose, startWatcher, stopWatcher, watchedFileDir, watcherThread, watchingMethods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.cluster.ClusterStateListener
clusterChanged
-
Field Details
-
SETTINGS_FILE_NAME
- See Also:
-
NAMESPACE
- See Also:
-
OPERATOR_DIRECTORY
- See Also:
-
-
Constructor Details
-
FileSettingsService
public FileSettingsService(ClusterService clusterService, ReservedClusterStateService stateService, Environment environment, FileSettingsService.FileSettingsHealthTracker healthIndicatorTracker) Constructs theFileSettingsService- Parameters:
clusterService- so we can register ourselves as a cluster state change listenerstateService- an instance of the immutable cluster state controller, so we can perform the cluster state changesenvironment- we need the environment to pull the location of the config and operator directorieshealthIndicatorTracker- tracks the success or failure of file-based settings operations
-
-
Method Details
-
logger
protected org.apache.logging.log4j.Logger logger() -
watchedFile
-
handleSnapshotRestore
public void handleSnapshotRestore(ClusterState clusterState, Metadata.Builder mdBuilder, ProjectId projectId) Used by snapshot restore serviceRestoreServiceto 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 restoremdBuilder- the current metadata builder for the new cluster stateprojectId- the project associated with the restore
-
doStart
protected void doStart()Description copied from class:AbstractLifecycleComponentStart this component. Typically that means doing things like launching background processes and registering listeners on other components. Other components have been initialized by this point, but may not yet be started.If this method throws an exception then the startup process will fail, but this component will not be stopped before it is closed.
This method is called while synchronized on
AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, although it may not be called at all if the startup process encountered some kind of fatal error, such as the failure of some other component to initialize or start.- Overrides:
doStartin classMasterNodeFileWatchingService
-
doStop
protected void doStop()Description copied from class:AbstractLifecycleComponentStop this component. Typically that means doing the reverse of whateverAbstractLifecycleComponent.doStart()does.This method is called while synchronized on
AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, after callingAbstractLifecycleComponent.doStart(), although it will not be called at all if this component did not successfully start.- Overrides:
doStopin classMasterNodeFileWatchingService
-
shouldRefreshFileState
If the file settings metadata version is set to zero, then we have restored from a snapshot and must reprocess the file.- Overrides:
shouldRefreshFileStatein classMasterNodeFileWatchingService- Parameters:
clusterState- State of the cluster- Returns:
- true if file settings metadata version is exactly 0, false otherwise.
-
processFileChanges
protected final void processFileChanges(Path file) throws ExecutionException, InterruptedException, IOException Read settings and pass them toReservedClusterStateServicefor application- Specified by:
processFileChangesin classAbstractFileWatchingService- Parameters:
file- the full path of the file that has changed inside the watched directory- Throws:
IOException- if there is an error reading the file itselfExecutionException- if there is an issue while applying the changes from the fileInterruptedException- if the file processing is interrupted by another thread.
-
processFileOnServiceStart
protected final void processFileOnServiceStart(Path file) throws IOException, ExecutionException, InterruptedException Read settings and pass them toReservedClusterStateServicefor application. Settings will be reprocessed even if the cluster-state version equals that found in the settings file.- Overrides:
processFileOnServiceStartin classAbstractFileWatchingService- Throws:
IOExceptionExecutionExceptionInterruptedException
-
processFile
protected void processFile(Path file, boolean startup) throws IOException, ExecutionException, InterruptedException -
createParser
- Throws:
IOException
-
completeProcessing
-
onProcessFileChangesException
Description copied from class:AbstractFileWatchingServiceCalled for checked exceptions only.- Overrides:
onProcessFileChangesExceptionin classAbstractFileWatchingService
-
processInitialFilesMissing
- Specified by:
processInitialFilesMissingin classAbstractFileWatchingService- Throws:
ExecutionExceptionInterruptedException
-
filesExists
- Specified by:
filesExistsin classAbstractFileWatchingService
-
filesIsDirectory
- Specified by:
filesIsDirectoryin classAbstractFileWatchingService
-
filesIsSymbolicLink
- Specified by:
filesIsSymbolicLinkin classAbstractFileWatchingService
-
filesReadAttributes
protected <A extends BasicFileAttributes> A filesReadAttributes(Path path, Class<A> clazz) throws IOException - Specified by:
filesReadAttributesin classAbstractFileWatchingService- Throws:
IOException
-
filesList
- Specified by:
filesListin classAbstractFileWatchingService- Throws:
IOException
-
filesSetLastModifiedTime
- Specified by:
filesSetLastModifiedTimein classAbstractFileWatchingService- Throws:
IOException
-
filesNewInputStream
- Specified by:
filesNewInputStreamin classAbstractFileWatchingService- Throws:
IOException
-