Browse Source

Merge "hadoop-swiftfs: Allow configuring container.tenant"

Jenkins 2 years ago
parent
commit
8cd6d7b0ca

+ 1
- 0
hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/RestClientBindings.java View File

@@ -155,6 +155,7 @@ public final class RestClientBindings {
155 155
     copy(conf, prefix + DOT_DOMAIN_NAME, props, SWIFT_DOMAIN_NAME_PROPERTY, false);
156 156
     copy(conf, prefix + DOT_DOMAIN_ID, props, SWIFT_DOMAIN_ID_PROPERTY, false);
157 157
     copy(conf, prefix + DOT_TENANT, props, SWIFT_TENANT_PROPERTY, false);
158
+    copy(conf, prefix + DOT_CONTAINER_TENANT, props, SWIFT_CONTAINER_TENANT_PROPERTY, false);
158 159
     copy(conf, prefix + DOT_REGION, props, SWIFT_REGION_PROPERTY, false);
159 160
     copy(conf, prefix + DOT_HTTP_PORT, props, SWIFT_HTTP_PORT_PROPERTY, false);
160 161
     copy(conf, prefix +

+ 2
- 0
hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftProtocolConstants.java View File

@@ -207,6 +207,7 @@ public class SwiftProtocolConstants {
207 207
   public static final String DOT_AUTH_URL = ".auth.url";
208 208
   public static final String DOT_AUTH_ENDPOINT_PREFIX = ".auth.endpoint.prefix";
209 209
   public static final String DOT_TENANT = ".tenant";
210
+  public static final String DOT_CONTAINER_TENANT = ".container.tenant";
210 211
   public static final String DOT_USERNAME = ".username";
211 212
   public static final String DOT_PASSWORD = ".password";
212 213
   public static final String DOT_TRUST_ID = ".trust.id";
@@ -233,6 +234,7 @@ public class SwiftProtocolConstants {
233 234
   public static final String SWIFT_AUTH_ENDPOINT_PREFIX =
234 235
       FS_SWIFT + DOT_AUTH_ENDPOINT_PREFIX;
235 236
   public static final String SWIFT_TENANT_PROPERTY = FS_SWIFT + DOT_TENANT;
237
+  public static final String SWIFT_CONTAINER_TENANT_PROPERTY = FS_SWIFT + DOT_CONTAINER_TENANT;
236 238
   public static final String SWIFT_USERNAME_PROPERTY = FS_SWIFT + DOT_USERNAME;
237 239
   public static final String SWIFT_PASSWORD_PROPERTY = FS_SWIFT + DOT_PASSWORD;
238 240
   public static final String SWIFT_TRUST_ID_PROPERTY = FS_SWIFT + DOT_TRUST_ID;

+ 42
- 0
hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftRestClient.java View File

@@ -180,6 +180,7 @@ public final class SwiftRestClient {
180 180
    */
181 181
   private final String container;
182 182
   private final String serviceDescription;
183
+  private final String containerTenant;
183 184
 
184 185
   /**
185 186
    * Access token (Secret)
@@ -502,6 +503,9 @@ public final class SwiftRestClient {
502 503
     region = props.getProperty(SWIFT_REGION_PROPERTY);
503 504
     //tenant is optional
504 505
     tenant = props.getProperty(SWIFT_TENANT_PROPERTY);
506
+    //containerTenant is optional
507
+    containerTenant = props.getProperty(SWIFT_CONTAINER_TENANT_PROPERTY);
508
+
505 509
     //service is used for diagnostics
506 510
     serviceProvider = props.getProperty(SWIFT_SERVICE_PROPERTY);
507 511
     container = props.getProperty(SWIFT_CONTAINER_PROPERTY);
@@ -1303,6 +1307,15 @@ public final class SwiftRestClient {
1303 1307
 
1304 1308
       accessToken = access.getToken();
1305 1309
       String path = getAuthEndpointPrefix() + accessToken.getTenant().getId();
1310
+
1311
+      // Overwrite the user tenant with the shared container tenant id (container.tenant)
1312
+      if (containerTenant != null) {
1313
+        path = getAuthEndpointPrefix() + containerTenant;
1314
+        if (LOG.isDebugEnabled()) {
1315
+          LOG.debug("overwritten path: " + path);
1316
+        }
1317
+      }
1318
+
1306 1319
       String host = endpointURI.getHost();
1307 1320
       try {
1308 1321
         objectLocation = new URI(endpointURI.getScheme(),
@@ -1318,6 +1331,13 @@ public final class SwiftRestClient {
1318 1331
                                  + " + " + path,
1319 1332
                                  e);
1320 1333
       }
1334
+
1335
+      // Overwrite the user tenant with the shared container tenant id (container.tenant)
1336
+      if (containerTenant != null) {
1337
+        endpointURI = objectLocation;
1338
+      }
1339
+
1340
+
1321 1341
       setAuthDetails(endpointURI, objectLocation, accessToken);
1322 1342
 
1323 1343
       if (LOG.isDebugEnabled()) {
@@ -1377,6 +1397,15 @@ public final class SwiftRestClient {
1377 1397
 
1378 1398
       URI objectLocation = null;
1379 1399
       String path = getAuthEndpointPrefix() + token.getTenant().getId();
1400
+
1401
+      // Overwrite the user tenant with the shared container tenant id (container.tenant)
1402
+      if (containerTenant != null) {
1403
+        path = getAuthEndpointPrefix() + containerTenant;
1404
+        if (LOG.isDebugEnabled()) {
1405
+          LOG.debug("overwritten path: " + path);
1406
+        }
1407
+      }
1408
+
1380 1409
       try {
1381 1410
         objectLocation = new URI(endpointURI.getScheme(),
1382 1411
                                  null,
@@ -1392,6 +1421,11 @@ public final class SwiftRestClient {
1392 1421
                                  e);
1393 1422
       }
1394 1423
 
1424
+      // Overwrite the user tenant with the shared container tenant id (container.tenant)
1425
+      if (containerTenant != null) {
1426
+        endpointURI = objectLocation;
1427
+      }
1428
+
1395 1429
       setAuthDetails(endpointURI, objectLocation, token);
1396 1430
       createDefaultContainer();
1397 1431
       return token;
@@ -1970,6 +2004,14 @@ public final class SwiftRestClient {
1970 2004
     return tenant;
1971 2005
   }
1972 2006
 
2007
+  /**
2008
+   * Get the tenant to which this client is bound
2009
+   * @return the tenant
2010
+   */
2011
+  public String getContainerTenant() {
2012
+    return containerTenant;
2013
+  }
2014
+
1973 2015
   /**
1974 2016
    * Get the username this client identifies itself as
1975 2017
    * @return the username

Loading…
Cancel
Save