diff --git a/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/RestClientBindings.java b/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/RestClientBindings.java index a55d7d1..17c7521 100644 --- a/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/RestClientBindings.java +++ b/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/RestClientBindings.java @@ -155,6 +155,7 @@ public final class RestClientBindings { copy(conf, prefix + DOT_DOMAIN_NAME, props, SWIFT_DOMAIN_NAME_PROPERTY, false); copy(conf, prefix + DOT_DOMAIN_ID, props, SWIFT_DOMAIN_ID_PROPERTY, false); copy(conf, prefix + DOT_TENANT, props, SWIFT_TENANT_PROPERTY, false); + copy(conf, prefix + DOT_CONTAINER_TENANT, props, SWIFT_CONTAINER_TENANT_PROPERTY, false); copy(conf, prefix + DOT_REGION, props, SWIFT_REGION_PROPERTY, false); copy(conf, prefix + DOT_HTTP_PORT, props, SWIFT_HTTP_PORT_PROPERTY, false); copy(conf, prefix + diff --git a/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftProtocolConstants.java b/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftProtocolConstants.java index b80c3cd..a1f4d61 100644 --- a/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftProtocolConstants.java +++ b/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftProtocolConstants.java @@ -207,6 +207,7 @@ public class SwiftProtocolConstants { public static final String DOT_AUTH_URL = ".auth.url"; public static final String DOT_AUTH_ENDPOINT_PREFIX = ".auth.endpoint.prefix"; public static final String DOT_TENANT = ".tenant"; + public static final String DOT_CONTAINER_TENANT = ".container.tenant"; public static final String DOT_USERNAME = ".username"; public static final String DOT_PASSWORD = ".password"; public static final String DOT_TRUST_ID = ".trust.id"; @@ -233,6 +234,7 @@ public class SwiftProtocolConstants { public static final String SWIFT_AUTH_ENDPOINT_PREFIX = FS_SWIFT + DOT_AUTH_ENDPOINT_PREFIX; public static final String SWIFT_TENANT_PROPERTY = FS_SWIFT + DOT_TENANT; + public static final String SWIFT_CONTAINER_TENANT_PROPERTY = FS_SWIFT + DOT_CONTAINER_TENANT; public static final String SWIFT_USERNAME_PROPERTY = FS_SWIFT + DOT_USERNAME; public static final String SWIFT_PASSWORD_PROPERTY = FS_SWIFT + DOT_PASSWORD; public static final String SWIFT_TRUST_ID_PROPERTY = FS_SWIFT + DOT_TRUST_ID; diff --git a/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftRestClient.java b/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftRestClient.java index ea32a6e..cc94b7a 100644 --- a/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftRestClient.java +++ b/hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/http/SwiftRestClient.java @@ -180,6 +180,7 @@ public final class SwiftRestClient { */ private final String container; private final String serviceDescription; + private final String containerTenant; /** * Access token (Secret) @@ -502,6 +503,9 @@ public final class SwiftRestClient { region = props.getProperty(SWIFT_REGION_PROPERTY); //tenant is optional tenant = props.getProperty(SWIFT_TENANT_PROPERTY); + //containerTenant is optional + containerTenant = props.getProperty(SWIFT_CONTAINER_TENANT_PROPERTY); + //service is used for diagnostics serviceProvider = props.getProperty(SWIFT_SERVICE_PROPERTY); container = props.getProperty(SWIFT_CONTAINER_PROPERTY); @@ -1303,6 +1307,15 @@ public final class SwiftRestClient { accessToken = access.getToken(); String path = getAuthEndpointPrefix() + accessToken.getTenant().getId(); + + // Overwrite the user tenant with the shared container tenant id (container.tenant) + if (containerTenant != null) { + path = getAuthEndpointPrefix() + containerTenant; + if (LOG.isDebugEnabled()) { + LOG.debug("overwritten path: " + path); + } + } + String host = endpointURI.getHost(); try { objectLocation = new URI(endpointURI.getScheme(), @@ -1318,6 +1331,13 @@ public final class SwiftRestClient { + " + " + path, e); } + + // Overwrite the user tenant with the shared container tenant id (container.tenant) + if (containerTenant != null) { + endpointURI = objectLocation; + } + + setAuthDetails(endpointURI, objectLocation, accessToken); if (LOG.isDebugEnabled()) { @@ -1377,6 +1397,15 @@ public final class SwiftRestClient { URI objectLocation = null; String path = getAuthEndpointPrefix() + token.getTenant().getId(); + + // Overwrite the user tenant with the shared container tenant id (container.tenant) + if (containerTenant != null) { + path = getAuthEndpointPrefix() + containerTenant; + if (LOG.isDebugEnabled()) { + LOG.debug("overwritten path: " + path); + } + } + try { objectLocation = new URI(endpointURI.getScheme(), null, @@ -1392,6 +1421,11 @@ public final class SwiftRestClient { e); } + // Overwrite the user tenant with the shared container tenant id (container.tenant) + if (containerTenant != null) { + endpointURI = objectLocation; + } + setAuthDetails(endpointURI, objectLocation, token); createDefaultContainer(); return token; @@ -1970,6 +2004,14 @@ public final class SwiftRestClient { return tenant; } + /** + * Get the tenant to which this client is bound + * @return the tenant + */ + public String getContainerTenant() { + return containerTenant; + } + /** * Get the username this client identifies itself as * @return the username