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 7e10ae6..fe88555 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 @@ -154,6 +154,7 @@ public final class RestClientBindings { copy(conf, prefix + DOT_TRUST_ID, props, SWIFT_TRUST_ID_PROPERTY, false); copy(conf, prefix + DOT_DOMAIN_NAME, props, SWIFT_DOMAIN_NAME_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 cc8b3f1..7e42d88 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"; @@ -232,6 +233,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 44e44da..b2d593c 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 @@ -175,6 +175,7 @@ public final class SwiftRestClient { */ private final String container; private final String serviceDescription; + private final String containerTenant; /** * Access token (Secret) @@ -496,6 +497,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); @@ -1295,6 +1299,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(), @@ -1310,6 +1323,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()) { @@ -1369,6 +1389,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, @@ -1384,6 +1413,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; @@ -1962,6 +1996,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