/
HdfsRepository.cs
192 lines (166 loc) · 7.43 KB
/
HdfsRepository.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* 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.Collections.Generic;
using System.Runtime.Serialization;
using OpenSearch.Net.Utf8Json;
namespace OpenSearch.Client
{
/// <summary>
/// A snapshot repository that stores snapshot data within a Hadoop HDFS filesystem
/// <para />
/// Requires the repository-hdfs plugin to be installed on the cluster
/// </summary>
public interface IHdfsRepository : IRepository<IHdfsRepositorySettings> { }
/// <inheritdoc />
public class HdfsRepository : IHdfsRepository
{
public HdfsRepository(HdfsRepositorySettings settings) => Settings = settings;
public IHdfsRepositorySettings Settings { get; set; }
object IRepositoryWithSettings.DelegateSettings => Settings;
public string Type { get; } = "hdfs";
}
/// <summary>
/// Snapshot repository settings for <see cref="IHdfsRepository"/>
/// </summary>
public interface IHdfsRepositorySettings : IRepositorySettings
{
/// <summary>
/// Big files can be broken down into chunks during snapshotting if needed.
/// The chunk size can be specified in bytes or by using size value notation,
/// i.e. 1g, 10m, 5k. Disabled by default
/// </summary>
[DataMember(Name ="chunk_size")]
string ChunkSize { get; set; }
/// <summary>
/// When set to true metadata files are stored in compressed format. This setting doesn't
/// affect index files that are already compressed by default. Defaults to <c>false</c>.
/// </summary>
[DataMember(Name ="compress")]
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
bool? Compress { get; set; }
/// <summary>
/// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5
/// </summary>
[DataMember(Name ="concurrent_streams")]
[JsonFormatter(typeof(NullableStringIntFormatter))]
int? ConcurrentStreams { get; set; }
/// <summary>
/// Hadoop configuration XML to be loaded (use commas for multi values)
/// </summary>
[DataMember(Name ="conf_location")]
string ConfigurationLocation { get; set; }
/// <summary>
/// 'inlined' key=value added to the Hadoop configuration
/// </summary>
[IgnoreDataMember]
Dictionary<string, object> InlineHadoopConfiguration { get; set; }
/// <summary>
/// Whether to load the default Hadoop configuration (default) or not
/// </summary>
[DataMember(Name ="load_defaults")]
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
bool? LoadDefaults { get; set; }
/// <summary>
/// The path with the file-system where data is stored/loaded. Required
/// </summary>
[DataMember(Name ="path")]
string Path { get; set; }
/// <summary>
/// The Hadoop file-system URI. Optional
/// </summary>
[DataMember(Name ="uri")]
string Uri { get; set; }
}
/// <inheritdoc />
public class HdfsRepositorySettings : IHdfsRepositorySettings
{
internal HdfsRepositorySettings() { }
public HdfsRepositorySettings(string path) => Path = path;
/// <inheritdoc />
public string ChunkSize { get; set; }
/// <inheritdoc />
public bool? Compress { get; set; }
/// <inheritdoc />
public int? ConcurrentStreams { get; set; }
/// <inheritdoc />
public string ConfigurationLocation { get; set; }
/// <inheritdoc />
public Dictionary<string, object> InlineHadoopConfiguration { get; set; }
/// <inheritdoc />
public bool? LoadDefaults { get; set; }
/// <inheritdoc />
public string Path { get; set; }
/// <inheritdoc />
public string Uri { get; set; }
}
/// <inheritdoc cref="IHdfsRepositorySettings"/>
public class HdfsRepositorySettingsDescriptor
: DescriptorBase<HdfsRepositorySettingsDescriptor, IHdfsRepositorySettings>, IHdfsRepositorySettings
{
string IHdfsRepositorySettings.ChunkSize { get; set; }
bool? IHdfsRepositorySettings.Compress { get; set; }
int? IHdfsRepositorySettings.ConcurrentStreams { get; set; }
string IHdfsRepositorySettings.ConfigurationLocation { get; set; }
Dictionary<string, object> IHdfsRepositorySettings.InlineHadoopConfiguration { get; set; }
bool? IHdfsRepositorySettings.LoadDefaults { get; set; }
string IHdfsRepositorySettings.Path { get; set; }
string IHdfsRepositorySettings.Uri { get; set; }
/// <inheritdoc cref="IHdfsRepositorySettings.Uri"/>
public HdfsRepositorySettingsDescriptor Uri(string uri) => Assign(uri, (a, v) => a.Uri = v);
/// <inheritdoc cref="IHdfsRepositorySettings.Path"/>
public HdfsRepositorySettingsDescriptor Path(string path) => Assign(path, (a, v) => a.Path = v);
/// <inheritdoc cref="IHdfsRepositorySettings.LoadDefaults"/>
public HdfsRepositorySettingsDescriptor LoadDefaults(bool? loadDefaults = true) => Assign(loadDefaults, (a, v) => a.LoadDefaults = v);
/// <inheritdoc cref="IHdfsRepositorySettings.ConfigurationLocation"/>
public HdfsRepositorySettingsDescriptor ConfigurationLocation(string configurationLocation) =>
Assign(configurationLocation, (a, v) => a.ConfigurationLocation = v);
/// <inheritdoc cref="IHdfsRepositorySettings.InlineHadoopConfiguration"/>
public HdfsRepositorySettingsDescriptor InlinedHadoopConfiguration(
Func<FluentDictionary<string, object>, FluentDictionary<string, object>> inlineConfig
) => Assign(inlineConfig, (a, v) => a.InlineHadoopConfiguration = v(new FluentDictionary<string, object>()));
/// <inheritdoc cref="IHdfsRepositorySettings.Compress"/>
public HdfsRepositorySettingsDescriptor Compress(bool? compress = true) => Assign(compress, (a, v) => a.Compress = v);
/// <inheritdoc cref="IHdfsRepositorySettings.ConcurrentStreams"/>
public HdfsRepositorySettingsDescriptor ConcurrentStreams(int? concurrentStreams) => Assign(concurrentStreams, (a, v) => a.ConcurrentStreams = v);
/// <inheritdoc cref="IHdfsRepositorySettings.ChunkSize"/>
public HdfsRepositorySettingsDescriptor ChunkSize(string chunkSize) => Assign(chunkSize, (a, v) => a.ChunkSize = v);
}
/// <inheritdoc cref="IHdfsRepository"/>
public class HdfsRepositoryDescriptor
: DescriptorBase<HdfsRepositoryDescriptor, IHdfsRepository>, IHdfsRepository
{
IHdfsRepositorySettings IRepository<IHdfsRepositorySettings>.Settings { get; set; }
object IRepositoryWithSettings.DelegateSettings => Self.Settings;
string ISnapshotRepository.Type => "hdfs";
/// <inheritdoc cref="IHdfsRepositorySettings"/>
public HdfsRepositoryDescriptor Settings(string path, Func<HdfsRepositorySettingsDescriptor, IHdfsRepositorySettings> settingsSelector = null
) =>
Assign(settingsSelector.InvokeOrDefault(new HdfsRepositorySettingsDescriptor().Path(path)), (a, v) => a.Settings = v);
}
}