Remove deprecated azure settings
This commit is contained in:
parent
98fdb39d3d
commit
6250f4dbaa
|
@ -21,6 +21,7 @@ package org.elasticsearch.cloud.azure.storage;
|
|||
|
||||
import com.microsoft.azure.storage.LocationMode;
|
||||
import com.microsoft.azure.storage.StorageException;
|
||||
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -36,10 +37,6 @@ public interface AzureStorageService {
|
|||
|
||||
final class Storage {
|
||||
public static final String PREFIX = "cloud.azure.storage.";
|
||||
@Deprecated
|
||||
public static final String ACCOUNT_DEPRECATED = "cloud.azure.storage.account";
|
||||
@Deprecated
|
||||
public static final String KEY_DEPRECATED = "cloud.azure.storage.key";
|
||||
|
||||
public static final String TIMEOUT = "cloud.azure.storage.timeout";
|
||||
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
|
||||
package org.elasticsearch.cloud.azure.storage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
|
@ -31,6 +28,9 @@ import org.elasticsearch.common.unit.ByteSizeValue;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.repositories.RepositorySettings;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AzureStorageSettings {
|
||||
private static ESLogger logger = ESLoggerFactory.getLogger(AzureStorageSettings.class.getName());
|
||||
|
||||
|
@ -78,57 +78,46 @@ public class AzureStorageSettings {
|
|||
* @param settings settings to parse
|
||||
* @return A tuple with v1 = primary storage and v2 = secondary storage
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Supports deprecated settings
|
||||
public static Tuple<AzureStorageSettings, Map<String, AzureStorageSettings>> parse(Settings settings) {
|
||||
AzureStorageSettings primaryStorage = null;
|
||||
Map<String, AzureStorageSettings> secondaryStorage = new HashMap<>();
|
||||
|
||||
// We check for deprecated settings
|
||||
String account = settings.get(Storage.ACCOUNT_DEPRECATED);
|
||||
String key = settings.get(Storage.KEY_DEPRECATED);
|
||||
|
||||
TimeValue globalTimeout = settings.getAsTime(Storage.TIMEOUT, TimeValue.timeValueMinutes(5));
|
||||
|
||||
if (account != null) {
|
||||
logger.warn("[{}] and [{}] have been deprecated. Use now [{}xxx.account] and [{}xxx.key] where xxx is any name",
|
||||
Storage.ACCOUNT_DEPRECATED, Storage.KEY_DEPRECATED, Storage.PREFIX, Storage.PREFIX);
|
||||
primaryStorage = new AzureStorageSettings(null, account, key, globalTimeout);
|
||||
} else {
|
||||
Settings storageSettings = settings.getByPrefix(Storage.PREFIX);
|
||||
if (storageSettings != null) {
|
||||
Map<String, Object> asMap = storageSettings.getAsStructuredMap();
|
||||
for (Map.Entry<String, Object> storage : asMap.entrySet()) {
|
||||
if (storage.getValue() instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> map = (Map) storage.getValue();
|
||||
TimeValue timeout = TimeValue.parseTimeValue(map.get("timeout"), globalTimeout, Storage.PREFIX + storage.getKey() + ".timeout");
|
||||
AzureStorageSettings current = new AzureStorageSettings(storage.getKey(), map.get("account"), map.get("key"), timeout);
|
||||
boolean activeByDefault = Boolean.parseBoolean(map.getOrDefault("default", "false"));
|
||||
if (activeByDefault) {
|
||||
if (primaryStorage == null) {
|
||||
primaryStorage = current;
|
||||
} else {
|
||||
logger.warn("default storage settings has already been defined. You can not define it to [{}]", storage.getKey());
|
||||
secondaryStorage.put(storage.getKey(), current);
|
||||
}
|
||||
Settings storageSettings = settings.getByPrefix(Storage.PREFIX);
|
||||
if (storageSettings != null) {
|
||||
Map<String, Object> asMap = storageSettings.getAsStructuredMap();
|
||||
for (Map.Entry<String, Object> storage : asMap.entrySet()) {
|
||||
if (storage.getValue() instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> map = (Map) storage.getValue();
|
||||
TimeValue timeout = TimeValue.parseTimeValue(map.get("timeout"), globalTimeout, Storage.PREFIX + storage.getKey() + ".timeout");
|
||||
AzureStorageSettings current = new AzureStorageSettings(storage.getKey(), map.get("account"), map.get("key"), timeout);
|
||||
boolean activeByDefault = Boolean.parseBoolean(map.getOrDefault("default", "false"));
|
||||
if (activeByDefault) {
|
||||
if (primaryStorage == null) {
|
||||
primaryStorage = current;
|
||||
} else {
|
||||
logger.warn("default storage settings has already been defined. You can not define it to [{}]", storage.getKey());
|
||||
secondaryStorage.put(storage.getKey(), current);
|
||||
}
|
||||
} else {
|
||||
secondaryStorage.put(storage.getKey(), current);
|
||||
}
|
||||
}
|
||||
// If we did not set any default storage, we should complain and define it
|
||||
if (primaryStorage == null && secondaryStorage.isEmpty() == false) {
|
||||
Map.Entry<String, AzureStorageSettings> fallback = secondaryStorage.entrySet().iterator().next();
|
||||
// We only warn if the number of secondary storage if > to 1
|
||||
// If the user defined only one storage account, that's fine. We know it's the default one.
|
||||
if (secondaryStorage.size() > 1) {
|
||||
logger.warn("no default storage settings has been defined. " +
|
||||
"Add \"default\": true to the settings you want to activate by default. " +
|
||||
"Forcing default to [{}].", fallback.getKey());
|
||||
}
|
||||
primaryStorage = fallback.getValue();
|
||||
secondaryStorage.remove(fallback.getKey());
|
||||
}
|
||||
// If we did not set any default storage, we should complain and define it
|
||||
if (primaryStorage == null && secondaryStorage.isEmpty() == false) {
|
||||
Map.Entry<String, AzureStorageSettings> fallback = secondaryStorage.entrySet().iterator().next();
|
||||
// We only warn if the number of secondary storage if > to 1
|
||||
// If the user defined only one storage account, that's fine. We know it's the default one.
|
||||
if (secondaryStorage.size() > 1) {
|
||||
logger.warn("no default storage settings has been defined. " +
|
||||
"Add \"default\": true to the settings you want to activate by default. " +
|
||||
"Forcing default to [{}].", fallback.getKey());
|
||||
}
|
||||
primaryStorage = fallback.getValue();
|
||||
secondaryStorage.remove(fallback.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
package org.elasticsearch.cloud.azure;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Collection;
|
||||
import com.microsoft.azure.storage.LocationMode;
|
||||
import com.microsoft.azure.storage.StorageException;
|
||||
|
||||
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
|
||||
import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage;
|
||||
|
@ -34,8 +34,8 @@ import org.elasticsearch.test.store.MockFSDirectoryService;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import com.microsoft.azure.storage.LocationMode;
|
||||
import com.microsoft.azure.storage.StorageException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class AbstractAzureRepositoryServiceTestCase extends AbstractAzureTestCase {
|
||||
|
||||
|
@ -77,15 +77,9 @@ public abstract class AbstractAzureRepositoryServiceTestCase extends AbstractAzu
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // Supports deprecated settings for testing backwards compatibility
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
Settings.Builder builder = Settings.settingsBuilder()
|
||||
.put(Storage.CONTAINER, "snapshots");
|
||||
|
||||
// We use sometime deprecated settings in tests
|
||||
builder.put(Storage.ACCOUNT_DEPRECATED, "mock_azure_account")
|
||||
.put(Storage.KEY_DEPRECATED, "mock_azure_key");
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,14 +19,13 @@
|
|||
|
||||
package org.elasticsearch.repositories.azure;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage;
|
||||
import org.elasticsearch.cloud.azure.storage.AzureStorageSettings;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
@ -66,20 +65,6 @@ public class AzureSettingsParserTest extends LuceneTestCase {
|
|||
assertThat(tuple.v2().keySet(), hasSize(0));
|
||||
}
|
||||
|
||||
public void testDeprecatedSettings() {
|
||||
@SuppressWarnings("deprecation")
|
||||
Settings settings = Settings.builder()
|
||||
.put(Storage.ACCOUNT_DEPRECATED, "myaccount1")
|
||||
.put(Storage.KEY_DEPRECATED, "mykey1")
|
||||
.build();
|
||||
|
||||
Tuple<AzureStorageSettings, Map<String, AzureStorageSettings>> tuple = AzureStorageSettings.parse(settings);
|
||||
assertThat(tuple.v1(), notNullValue());
|
||||
assertThat(tuple.v1().getAccount(), is("myaccount1"));
|
||||
assertThat(tuple.v1().getKey(), is("mykey1"));
|
||||
assertThat(tuple.v2().keySet(), hasSize(0));
|
||||
}
|
||||
|
||||
public void testParseTwoSettingsNoDefault() {
|
||||
Settings settings = Settings.builder()
|
||||
.put("cloud.azure.storage.azure1.account", "myaccount1")
|
||||
|
|
Loading…
Reference in New Issue