Snapshot Create RepositoryAPI

edit

The Snapshot Create RepositoryAPI allows to register a snapshot repository.

Snapshot Create RepositoryRequest

edit

A PutRepositoryRequest:

PutRepositoryRequest request = new PutRepositoryRequest();

Repository Settings

edit

Settings requirements will differ based on the repository backend chosen.

request.settings(settings); 

Sets the repository settings

Providing the Settings

edit

The settings to be applied can be provided in different ways:

String locationKey = FsRepository.LOCATION_SETTING.getKey();
String locationValue = ".";
String compressKey = FsRepository.COMPRESS_SETTING.getKey();
boolean compressValue = true;

Settings settings = Settings.builder()
    .put(locationKey, locationValue)
    .put(compressKey, compressValue)
    .build(); 

Settings provided as Settings

Settings.Builder settingsBuilder = Settings.builder()
    .put(locationKey, locationValue)
    .put(compressKey, compressValue);
request.settings(settingsBuilder); 

Settings provided as Settings.Builder

request.settings("{\"location\": \".\", \"compress\": \"true\"}",
    XContentType.JSON); 

Settings provided as String

Map<String, Object> map = new HashMap<>();
map.put(locationKey, locationValue);
map.put(compressKey, compressValue);
request.settings(map); 

Settings provided as a Map

Required Arguments

edit

The following arguments must be provided:

request.name(repositoryName); 

The name of the repository

request.type(FsRepository.TYPE); 

The type of the repository

Optional Arguments

edit

The following arguments can optionally be provided:

request.timeout(TimeValue.timeValueMinutes(1)); 
request.timeout("1m"); 

Timeout to wait for the all the nodes to acknowledge the settings were applied as a TimeValue

Timeout to wait for the all the nodes to acknowledge the settings were applied as a String

request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); 
request.masterNodeTimeout("1m"); 

Timeout to connect to the master node as a TimeValue

Timeout to connect to the master node as a String

request.verify(true); 

Verify after creation as a Boolean

Synchronous Execution

edit
PutRepositoryResponse response = client.snapshot().createRepository(request, RequestOptions.DEFAULT);

Asynchronous Execution

edit

The asynchronous execution of a repository put settings requires both the PutRepositoryRequest instance and an ActionListener instance to be passed to the asynchronous method:

client.snapshot().createRepositoryAsync(request, RequestOptions.DEFAULT, listener); 

The PutRepositoryRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed.

A typical listener for PutRepositoryResponse looks like:

ActionListener<PutRepositoryResponse> listener =
    new ActionListener<PutRepositoryResponse>() {
        @Override
        public void onResponse(PutRepositoryResponse putRepositoryResponse) {
            
        }

        @Override
        public void onFailure(Exception e) {
            
        }
    };

Called when the execution is successfully completed. The response is provided as an argument

Called in case of a failure. The raised exception is provided as an argument

Snapshot Create RepositoryResponse

edit

The returned PutRepositoryResponse allows to retrieve information about the executed operation as follows:

boolean acknowledged = response.isAcknowledged(); 

Indicates the node has acknowledged the request