/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
using System;
using System.Runtime.Serialization;
using OpenSearch.Net.Utf8Json;
namespace OpenSearch.Client.Specification.SnapshotApi
{
///
/// A snapshot repository that uses a shared file system to store snapshot data.
/// The path specified in the location parameter should point to the same location in the shared
/// filesystem and be accessible on all data and cluster_manager nodes.
///
public interface IFileSystemRepository : IRepository { }
///
public class FileSystemRepository : IFileSystemRepository
{
public FileSystemRepository(FileSystemRepositorySettings settings) => Settings = settings;
public IFileSystemRepositorySettings Settings { get; set; }
object IRepositoryWithSettings.DelegateSettings => Settings;
public string Type { get; } = "fs";
}
///
/// Repository settings for
///
public interface IFileSystemRepositorySettings : IRepositorySettings
{
///
/// Big files can be broken down into chunks during the snapshot process, if needed.
/// The chunk size can be specified in bytes or by using size value notation, i.e. 1g, 10m, 5k.
/// Defaults to null (unlimited chunk size).
///
[DataMember(Name ="chunk_size")]
string ChunkSize { get; set; }
///
/// Turns on compression of the snapshot files. Defaults to true.
///
[DataMember(Name ="compress")]
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
bool? Compress { get; set; }
///
/// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5
///
[DataMember(Name ="concurrent_streams")]
[JsonFormatter(typeof(NullableStringIntFormatter))]
int? ConcurrentStreams { get; set; }
///
/// Location of the snapshots. Mandatory.
///
[DataMember(Name ="location")]
string Location { get; set; }
///
/// Throttles per node restore rate. Defaults to 20mb per second.
///
[DataMember(Name ="max_restore_bytes_per_second")]
string RestoreBytesPerSecondMaximum { get; set; }
///
/// Throttles per node snapshot rate. Defaults to 20mb per second.
///
[DataMember(Name ="max_snapshot_bytes_per_second")]
string SnapshotBytesPerSecondMaximum { get; set; }
}
///
public class FileSystemRepositorySettings : IFileSystemRepositorySettings
{
internal FileSystemRepositorySettings() { }
public FileSystemRepositorySettings(string location) => Location = location;
public string ChunkSize { get; set; }
public bool? Compress { get; set; }
public int? ConcurrentStreams { get; set; }
public string Location { get; set; }
public string RestoreBytesPerSecondMaximum { get; set; }
public string SnapshotBytesPerSecondMaximum { get; set; }
}
///
public class FileSystemRepositorySettingsDescriptor
: DescriptorBase, IFileSystemRepositorySettings
{
string IFileSystemRepositorySettings.ChunkSize { get; set; }
bool? IFileSystemRepositorySettings.Compress { get; set; }
int? IFileSystemRepositorySettings.ConcurrentStreams { get; set; }
string IFileSystemRepositorySettings.Location { get; set; }
string IFileSystemRepositorySettings.RestoreBytesPerSecondMaximum { get; set; }
string IFileSystemRepositorySettings.SnapshotBytesPerSecondMaximum { get; set; }
///
public FileSystemRepositorySettingsDescriptor Location(string location) => Assign(location, (a, v) => a.Location = v);
///
public FileSystemRepositorySettingsDescriptor Compress(bool? compress = true) => Assign(compress, (a, v) => a.Compress = v);
///
public FileSystemRepositorySettingsDescriptor ConcurrentStreams(int? concurrentStreams) =>
Assign(concurrentStreams, (a, v) => a.ConcurrentStreams = v);
///
public FileSystemRepositorySettingsDescriptor ChunkSize(string chunkSize) => Assign(chunkSize, (a, v) => a.ChunkSize = v);
///
public FileSystemRepositorySettingsDescriptor RestoreBytesPerSecondMaximum(string maximumBytesPerSecond) =>
Assign(maximumBytesPerSecond, (a, v) => a.RestoreBytesPerSecondMaximum = v);
///
public FileSystemRepositorySettingsDescriptor SnapshotBytesPerSecondMaximum(string maximumBytesPerSecond) =>
Assign(maximumBytesPerSecond, (a, v) => a.SnapshotBytesPerSecondMaximum = v);
}
///
public class FileSystemRepositoryDescriptor
: DescriptorBase, IFileSystemRepository
{
IFileSystemRepositorySettings IRepository.Settings { get; set; }
object IRepositoryWithSettings.DelegateSettings => Self.Settings;
string ISnapshotRepository.Type { get; } = "fs";
///
public FileSystemRepositoryDescriptor Settings(string location,
Func settingsSelector = null
) =>
Assign(settingsSelector.InvokeOrDefault(new FileSystemRepositorySettingsDescriptor().Location(location)), (a, v) => a.Settings = v);
}
}