DCausse has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/294354

Change subject: Allow region to be specified.
......................................................................

Allow region to be specified.

Necessary if your deployment has multiple regions as the region it selects is 
completely arbitrary.

closes #6

Change-Id: Ib9bdecc51e2a185308dcc21c6b341894f46df673
---
M README.md
M 
src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftAccountFactory.java
M 
src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftRepository.java
M src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftService.java
4 files changed, 15 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/search/repository-swift 
refs/changes/54/294354/1

diff --git a/README.md b/README.md
index dfea7e9..3344f23 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,7 @@
 | swift_password                      | Swift password
 | swift_tenantname                    | Swift tenant name, only used with 
keystone auth
 | swift_username                      | Swift username
+| swift_preferred region              | Region to use.  If you do not specify 
a region, Swift will pick the endpoint of the first region.  If you have 
multiple regions, the order is not guarenteed.
 | chunk_size                          | Maximum size for individual objects in 
the snapshot. Defaults to `5gb` as that's the Swift default
 | compress                            | Turns on compression of the snapshot 
files. Defaults to `false` as it tends to break with Swift
 | max_restore_bytes_per_sec           | Throttles per node restore rate. 
Defaults to `20mb` per second.
diff --git 
a/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftAccountFactory.java
 
b/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftAccountFactory.java
index eec617b..7f01386 100644
--- 
a/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftAccountFactory.java
+++ 
b/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftAccountFactory.java
@@ -4,16 +4,16 @@
 
 public class SwiftAccountFactory {
 
-    public static Account createAccount(SwiftService swiftService, String url, 
String username, String password, String tenantName, String authMethod) {
+    public static Account createAccount(SwiftService swiftService, String url, 
String username, String password, String tenantName, String authMethod, String 
preferredRegion) {
         if ("KEYSTONE".equals(authMethod.toUpperCase())) {
-            return swiftService.swiftKeyStone(url, username, password, 
tenantName);
+            return swiftService.swiftKeyStone(url, username, password, 
tenantName, preferredRegion);
         }
 
         if ("TEMPAUTH".equals(authMethod.toUpperCase())) {
-            return swiftService.swiftTempAuth(url, username, password);
+            return swiftService.swiftTempAuth(url, username, password, 
preferredRegion);
         }
 
-        return swiftService.swiftBasic(url, username, password);
+        return swiftService.swiftBasic(url, username, password, 
preferredRegion);
 
     }
 
diff --git 
a/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftRepository.java
 
b/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftRepository.java
index 2e4c169..cb4d88f 100644
--- 
a/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftRepository.java
+++ 
b/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftRepository.java
@@ -62,7 +62,8 @@
         String password = repositorySettings.settings().get("swift_password", 
"");
         String tenantName = 
repositorySettings.settings().get("swift_tenantname", "");
         String authMethod = 
repositorySettings.settings().get("swift_authmethod", "");
-        Account account = SwiftAccountFactory.createAccount(swiftService, url, 
username, password, tenantName, authMethod);
+        String preferredRegion = 
repositorySettings.settings().get("swift_preferred_region", null);
+        Account account = SwiftAccountFactory.createAccount(swiftService, url, 
username, password, tenantName, authMethod, preferredRegion);
 
         blobStore = new SwiftBlobStore(settings, account, container);
         this.chunkSize = 
repositorySettings.settings().getAsBytesSize("chunk_size",
diff --git 
a/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftService.java
 
b/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftService.java
index 898477a..fe92578 100644
--- 
a/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftService.java
+++ 
b/src/main/java/org/wikimedia/elasticsearch/swift/repositories/SwiftService.java
@@ -39,13 +39,13 @@
      *            The password
      * @return swift Account
      */
-    public synchronized Account swiftBasic(String url, String username, String 
password) {
+    public synchronized Account swiftBasic(String url, String username, String 
password, String preferredRegion) {
         if (swiftUser != null) {
             return swiftUser;
         }
 
         try {
-            AccountConfig conf = getStandardConfig(url, username, password, 
AuthenticationMethod.BASIC);
+            AccountConfig conf = getStandardConfig(url, username, password, 
AuthenticationMethod.BASIC, preferredRegion);
             swiftUser = createAccount(conf);
         } catch (CommandException ce) {
             throw new ElasticsearchException("Unable to authenticate to Swift 
Basic " + url + "/" + username + "/" + password, ce);
@@ -62,13 +62,13 @@
         });
     }
 
-    public synchronized Account swiftKeyStone(String url, String username, 
String password, String tenantName) {
+    public synchronized Account swiftKeyStone(String url, String username, 
String password, String tenantName, String preferredRegion) {
         if (swiftUser != null) {
             return swiftUser;
         }
 
         try {
-            AccountConfig conf = getStandardConfig(url, username, password, 
AuthenticationMethod.KEYSTONE);
+            AccountConfig conf = getStandardConfig(url, username, password, 
AuthenticationMethod.KEYSTONE, preferredRegion);
             conf.setTenantName(tenantName);
             swiftUser = createAccount(conf);
         } catch (CommandException ce) {
@@ -78,13 +78,13 @@
         return swiftUser;
     }
 
-    public synchronized Account swiftTempAuth(String url, String username, 
String password) {
+    public synchronized Account swiftTempAuth(String url, String username, 
String password, String preferredRegion) {
         if (swiftUser != null) {
             return swiftUser;
         }
 
         try {
-            AccountConfig conf = getStandardConfig(url, username, password, 
AuthenticationMethod.TEMPAUTH);
+            AccountConfig conf = getStandardConfig(url, username, password, 
AuthenticationMethod.TEMPAUTH, preferredRegion);
             swiftUser = createAccount(conf);
         } catch (CommandException ce) {
             throw new ElasticsearchException("Unable to authenticate to Swift 
Temp", ce);
@@ -92,7 +92,7 @@
         return swiftUser;
     }
 
-    private AccountConfig getStandardConfig(String url, String username, 
String password, AuthenticationMethod method) {
+    private AccountConfig getStandardConfig(String url, String username, 
String password, AuthenticationMethod method, String preferredRegion) {
         AccountConfig conf = new AccountConfig();
         conf.setAuthUrl(url);
         conf.setUsername(username);
@@ -100,6 +100,7 @@
         conf.setAuthenticationMethod(method);
         conf.setAllowContainerCaching(false);
         conf.setAllowCaching(false);
+        conf.setPreferredRegion(preferredRegion);
         return conf;
     }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/294354
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib9bdecc51e2a185308dcc21c6b341894f46df673
Gerrit-PatchSet: 1
Gerrit-Project: search/repository-swift
Gerrit-Branch: master
Gerrit-Owner: DCausse <dcau...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to