2020package org .elasticsearch .cloud .azure .storage ;
2121
2222import com .microsoft .azure .storage .RetryPolicy ;
23- import org .elasticsearch .cloud .azure .storage .AzureStorageService .Storage ;
24- import org .elasticsearch .common .collect .Tuple ;
2523import org .elasticsearch .common .settings .SecureSetting ;
2624import org .elasticsearch .common .settings .SecureString ;
2725import org .elasticsearch .common .settings .Setting ;
2826import org .elasticsearch .common .settings .Setting .AffixSetting ;
2927import org .elasticsearch .common .settings .Setting .Property ;
3028import org .elasticsearch .common .settings .Settings ;
31- import org .elasticsearch .common .settings .SettingsException ;
3229import org .elasticsearch .common .unit .TimeValue ;
3330
34- import java .util .ArrayList ;
3531import java .util .Collections ;
3632import java .util .HashMap ;
37- import java .util .List ;
3833import java .util .Map ;
3934import java .util .Set ;
4035
41- import static org .elasticsearch .cloud .azure .storage .AzureStorageService .Storage .STORAGE_ACCOUNTS ;
42-
4336public final class AzureStorageSettings {
4437 // prefix for azure client settings
4538 private static final String PREFIX = "azure.client." ;
@@ -64,56 +57,20 @@ public final class AzureStorageSettings {
6457 key -> SecureSetting .secureString (key , null ));
6558
6659 public static final AffixSetting <TimeValue > TIMEOUT_SETTING = Setting .affixKeySetting (PREFIX , "timeout" ,
67- (key ) -> Setting .timeSetting (key , Storage .TIMEOUT_SETTING , Property .NodeScope ));
68-
69-
70- @ Deprecated
71- public static final Setting <TimeValue > DEPRECATED_TIMEOUT_SETTING = Setting .affixKeySetting (Storage .PREFIX , "timeout" ,
72- (key ) -> Setting .timeSetting (key , Storage .TIMEOUT_SETTING , Property .NodeScope , Property .Deprecated ));
73- @ Deprecated
74- public static final Setting <String > DEPRECATED_ACCOUNT_SETTING = Setting .affixKeySetting (Storage .PREFIX , "account" ,
75- (key ) -> Setting .simpleString (key , Property .NodeScope , Property .Deprecated ));
76- @ Deprecated
77- public static final Setting <String > DEPRECATED_KEY_SETTING = Setting .affixKeySetting (Storage .PREFIX , "key" ,
78- (key ) -> Setting .simpleString (key , Property .NodeScope , Property .Deprecated ));
79- @ Deprecated
80- public static final Setting <Boolean > DEPRECATED_DEFAULT_SETTING = Setting .affixKeySetting (Storage .PREFIX , "default" ,
81- (key ) -> Setting .boolSetting (key , false , Property .NodeScope , Property .Deprecated ));
82-
60+ (key ) -> Setting .timeSetting (key , TimeValue .timeValueMinutes (-1 ), Property .NodeScope ));
8361
84- @ Deprecated
85- private final String name ;
8662 private final String account ;
8763 private final String key ;
8864 private final TimeValue timeout ;
89- @ Deprecated
90- private final boolean activeByDefault ;
9165 private final int maxRetries ;
9266
9367 public AzureStorageSettings (String account , String key , TimeValue timeout , int maxRetries ) {
94- this .name = null ;
95- this .account = account ;
96- this .key = key ;
97- this .timeout = timeout ;
98- this .activeByDefault = false ;
99- this .maxRetries = maxRetries ;
100- }
101-
102- @ Deprecated
103- public AzureStorageSettings (String name , String account , String key , TimeValue timeout , boolean activeByDefault , int maxRetries ) {
104- this .name = name ;
10568 this .account = account ;
10669 this .key = key ;
10770 this .timeout = timeout ;
108- this .activeByDefault = activeByDefault ;
10971 this .maxRetries = maxRetries ;
11072 }
11173
112- @ Deprecated
113- public String getName () {
114- return name ;
115- }
116-
11774 public String getKey () {
11875 return key ;
11976 }
@@ -126,39 +83,21 @@ public TimeValue getTimeout() {
12683 return timeout ;
12784 }
12885
129- @ Deprecated
130- public Boolean isActiveByDefault () {
131- return activeByDefault ;
132- }
133-
13486 public int getMaxRetries () {
13587 return maxRetries ;
13688 }
13789
13890 @ Override
13991 public String toString () {
14092 final StringBuilder sb = new StringBuilder ("AzureStorageSettings{" );
141- sb .append ("name='" ).append (name ).append ('\'' );
14293 sb .append (", account='" ).append (account ).append ('\'' );
14394 sb .append (", key='" ).append (key ).append ('\'' );
144- sb .append (", activeByDefault='" ).append (activeByDefault ).append ('\'' );
14595 sb .append (", timeout=" ).append (timeout );
14696 sb .append (", maxRetries=" ).append (maxRetries );
14797 sb .append ('}' );
14898 return sb .toString ();
14999 }
150100
151- /**
152- * Parses settings and read all legacy settings available under cloud.azure.storage.*
153- * @param settings settings to parse
154- * @return A tuple with v1 = primary storage and v2 = secondary storage
155- */
156- @ Deprecated
157- public static Tuple <AzureStorageSettings , Map <String , AzureStorageSettings >> loadLegacy (Settings settings ) {
158- List <AzureStorageSettings > storageSettings = createStorageSettingsDeprecated (settings );
159- return Tuple .tuple (getPrimary (storageSettings ), getSecondaries (storageSettings ));
160- }
161-
162101 /**
163102 * Parses settings and read all settings available under azure.client.*
164103 * @param settings settings to parse
@@ -192,25 +131,6 @@ static AzureStorageSettings getClientSettings(Settings settings, String clientNa
192131 }
193132 }
194133
195- @ Deprecated
196- private static List <AzureStorageSettings > createStorageSettingsDeprecated (Settings settings ) {
197- // ignore global timeout which has the same prefix but does not belong to any group
198- Settings groups = STORAGE_ACCOUNTS .get (settings .filter ((k ) -> k .equals (Storage .TIMEOUT_SETTING .getKey ()) == false ));
199- List <AzureStorageSettings > storageSettings = new ArrayList <>();
200- for (String groupName : groups .getAsGroups ().keySet ()) {
201- storageSettings .add (
202- new AzureStorageSettings (
203- groupName ,
204- getValue (settings , groupName , DEPRECATED_ACCOUNT_SETTING ),
205- getValue (settings , groupName , DEPRECATED_KEY_SETTING ),
206- getValue (settings , groupName , DEPRECATED_TIMEOUT_SETTING ),
207- getValue (settings , groupName , DEPRECATED_DEFAULT_SETTING ),
208- getValue (settings , groupName , MAX_RETRIES_SETTING ))
209- );
210- }
211- return storageSettings ;
212- }
213-
214134 private static <T > T getConfigValue (Settings settings , String clientName ,
215135 Setting .AffixSetting <T > clientSetting ) {
216136 Setting <T > concreteSetting = clientSetting .getConcreteSettingForNamespace (clientName );
@@ -222,45 +142,4 @@ public static <T> T getValue(Settings settings, String groupName, Setting<T> set
222142 String fullKey = k .toConcreteKey (groupName ).toString ();
223143 return setting .getConcreteSetting (fullKey ).get (settings );
224144 }
225-
226- @ Deprecated
227- private static AzureStorageSettings getPrimary (List <AzureStorageSettings > settings ) {
228- if (settings .isEmpty ()) {
229- return null ;
230- } else if (settings .size () == 1 ) {
231- // the only storage settings belong (implicitly) to the default primary storage
232- AzureStorageSettings storage = settings .get (0 );
233- return new AzureStorageSettings (storage .getName (), storage .getAccount (), storage .getKey (), storage .getTimeout (), true ,
234- storage .getMaxRetries ());
235- } else {
236- AzureStorageSettings primary = null ;
237- for (AzureStorageSettings setting : settings ) {
238- if (setting .isActiveByDefault ()) {
239- if (primary == null ) {
240- primary = setting ;
241- } else {
242- throw new SettingsException ("Multiple default Azure data stores configured: [" + primary .getName () + "] and [" + setting .getName () + "]" );
243- }
244- }
245- }
246- if (primary == null ) {
247- throw new SettingsException ("No default Azure data store configured" );
248- }
249- return primary ;
250- }
251- }
252-
253- @ Deprecated
254- private static Map <String , AzureStorageSettings > getSecondaries (List <AzureStorageSettings > settings ) {
255- Map <String , AzureStorageSettings > secondaries = new HashMap <>();
256- // when only one setting is defined, we don't have secondaries
257- if (settings .size () > 1 ) {
258- for (AzureStorageSettings setting : settings ) {
259- if (setting .isActiveByDefault () == false ) {
260- secondaries .put (setting .getName (), setting );
261- }
262- }
263- }
264- return secondaries ;
265- }
266145}
0 commit comments