Skip to content

Commit 8c98d67

Browse files
Sanjay Sharmasanjay990
Sanjay Sharma
authored andcommitted
Add configuration variables for authenticating to Azure Blob
1 parent 46593ed commit 8c98d67

9 files changed

+117
-8
lines changed

presto-hive/src/main/java/com/facebook/presto/hive/HdfsConfigurationUpdater.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ public class HdfsConfigurationUpdater
7575
private final File s3StagingDirectory;
7676
private final boolean pinS3ClientToCurrentRegion;
7777
private final String s3UserAgentPrefix;
78+
private final String wasbAccessKey;
79+
private final String wasbStorageAccount;
7880

7981
@Inject
80-
public HdfsConfigurationUpdater(HiveClientConfig hiveClientConfig, HiveS3Config s3Config)
82+
public HdfsConfigurationUpdater(HiveClientConfig hiveClientConfig, HiveS3Config s3Config, HiveWasbConfig wasbConfig)
8183
{
8284
requireNonNull(hiveClientConfig, "hiveClientConfig is null");
8385
checkArgument(hiveClientConfig.getDfsTimeout().toMillis() >= 1, "dfsTimeout must be at least 1 ms");
@@ -115,6 +117,9 @@ public HdfsConfigurationUpdater(HiveClientConfig hiveClientConfig, HiveS3Config
115117
this.s3StagingDirectory = s3Config.getS3StagingDirectory();
116118
this.pinS3ClientToCurrentRegion = s3Config.isPinS3ClientToCurrentRegion();
117119
this.s3UserAgentPrefix = s3Config.getS3UserAgentPrefix();
120+
121+
this.wasbAccessKey = wasbConfig.getWasbAccessKey();
122+
this.wasbStorageAccount = wasbConfig.getWasbStorageAccount();
118123
}
119124

120125
private static Configuration readConfiguration(List<String> resourcePaths)
@@ -208,6 +213,11 @@ public void updateConfiguration(PrestoHadoopConfiguration config)
208213
config.setLong(PrestoS3FileSystem.S3_MULTIPART_MIN_PART_SIZE, s3MultipartMinPartSize.toBytes());
209214
config.setBoolean(PrestoS3FileSystem.S3_PIN_CLIENT_TO_CURRENT_REGION, pinS3ClientToCurrentRegion);
210215
config.set(PrestoS3FileSystem.S3_USER_AGENT_PREFIX, s3UserAgentPrefix);
216+
217+
// set config for Azure Blob
218+
if (wasbAccessKey != null && wasbStorageAccount != null) {
219+
config.set(String.format("fs.azure.account.key.%s.blob.core.windows.net", wasbStorageAccount), wasbAccessKey);
220+
}
211221
}
212222

213223
public static void configureCompression(Configuration config, HiveCompressionCodec compressionCodec)

presto-hive/src/main/java/com/facebook/presto/hive/HiveClientModule.java

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void configure(Binder binder)
7676
binder.bind(DirectoryLister.class).to(HadoopDirectoryLister.class).in(Scopes.SINGLETON);
7777
configBinder(binder).bindConfig(HiveClientConfig.class);
7878
configBinder(binder).bindConfig(HiveS3Config.class);
79+
configBinder(binder).bindConfig(HiveWasbConfig.class);
7980

8081
binder.bind(HiveSessionProperties.class).in(Scopes.SINGLETON);
8182
binder.bind(HiveTableProperties.class).in(Scopes.SINGLETON);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.hive;
15+
16+
import io.airlift.configuration.Config;
17+
import io.airlift.configuration.ConfigSecuritySensitive;
18+
19+
public class HiveWasbConfig
20+
{
21+
private String wasbStorageAccount;
22+
private String wasbAccessKey;
23+
24+
public String getWasbStorageAccount()
25+
{
26+
return wasbStorageAccount;
27+
}
28+
29+
@ConfigSecuritySensitive
30+
@Config("hive.wasb.storage-account")
31+
public HiveWasbConfig setWasbStorageAccount(String wasbStorageAccount)
32+
{
33+
this.wasbStorageAccount = wasbStorageAccount;
34+
return this;
35+
}
36+
37+
public String getWasbAccessKey()
38+
{
39+
return wasbAccessKey;
40+
}
41+
42+
@ConfigSecuritySensitive
43+
@Config("hive.wasb.access-key")
44+
public HiveWasbConfig setWasbAccessKey(String wasbAccessKey)
45+
{
46+
this.wasbAccessKey = wasbAccessKey;
47+
return this;
48+
}
49+
}

presto-hive/src/test/java/com/facebook/presto/hive/AbstractTestHiveClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ protected final void setup(String databaseName, HiveClientConfig hiveClientConfi
513513
setupHive(connectorId.toString(), databaseName, hiveClientConfig.getTimeZone());
514514

515515
metastoreClient = hiveMetastore;
516-
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, new HiveS3Config()));
516+
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, new HiveS3Config(), new HiveWasbConfig()));
517517
hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveClientConfig, new NoHdfsAuthentication());
518518
locationService = new HiveLocationService(hdfsEnvironment);
519519
JsonCodec<PartitionUpdate> partitionUpdateCodec = JsonCodec.jsonCodec(PartitionUpdate.class);

presto-hive/src/test/java/com/facebook/presto/hive/AbstractTestHiveClientS3.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected void setup(String host, int port, String databaseName, String awsAcces
159159
HiveConnectorId connectorId = new HiveConnectorId("hive-test");
160160
HiveCluster hiveCluster = new TestingHiveCluster(hiveClientConfig, host, port);
161161
ExecutorService executor = newCachedThreadPool(daemonThreadsNamed("hive-s3-%s"));
162-
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config));
162+
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config, new HiveWasbConfig()));
163163
HivePartitionManager hivePartitionManager = new HivePartitionManager(connectorId, TYPE_MANAGER, hiveClientConfig);
164164

165165
hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveClientConfig, new NoHdfsAuthentication());

presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static DistributedQueryRunner createQueryRunner(Iterable<TpchTable<?>> ta
9191

9292
HiveClientConfig hiveClientConfig = new HiveClientConfig();
9393
HiveS3Config s3Config = new HiveS3Config();
94-
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config));
94+
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config, new HiveWasbConfig()));
9595
HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveClientConfig, new NoHdfsAuthentication());
9696

9797
FileHiveMetastore metastore = new FileHiveMetastore(hdfsEnvironment, baseDir.toURI().toString(), "test");

presto-hive/src/test/java/com/facebook/presto/hive/HiveTestUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ public static List<Type> getTypes(List<? extends ColumnHandle> columnHandles)
9393

9494
public static HdfsEnvironment createTestHdfsEnvironment(HiveClientConfig config)
9595
{
96-
return createTestHdfsEnvironment(config, new HiveS3Config());
96+
return createTestHdfsEnvironment(config, new HiveS3Config(), new HiveWasbConfig());
9797
}
9898

99-
public static HdfsEnvironment createTestHdfsEnvironment(HiveClientConfig hiveConfig, HiveS3Config s3Config)
99+
public static HdfsEnvironment createTestHdfsEnvironment(HiveClientConfig hiveConfig, HiveS3Config s3Config, HiveWasbConfig wasbConfig)
100100
{
101-
HdfsConfiguration hdfsConfig = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveConfig, s3Config));
101+
HdfsConfiguration hdfsConfig = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveConfig, s3Config, wasbConfig));
102102
return new HdfsEnvironment(hdfsConfig, hiveConfig, new NoHdfsAuthentication());
103103
}
104104

presto-hive/src/test/java/com/facebook/presto/hive/TestHiveClientFileMetastore.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected ExtendedHiveMetastore createMetastore(File tempDir)
2727
{
2828
File baseDir = new File(tempDir, "metastore");
2929
HiveClientConfig hiveConfig = new HiveClientConfig();
30-
HdfsConfigurationUpdater updator = new HdfsConfigurationUpdater(hiveConfig, new HiveS3Config());
30+
HdfsConfigurationUpdater updator = new HdfsConfigurationUpdater(hiveConfig, new HiveS3Config(), new HiveWasbConfig());
3131
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(updator);
3232
HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveConfig, new NoHdfsAuthentication());
3333
return new FileHiveMetastore(hdfsEnvironment, baseDir.toURI().toString(), "test");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.hive;
15+
16+
import com.google.common.collect.ImmutableMap;
17+
import org.testng.annotations.Test;
18+
19+
import java.util.Map;
20+
21+
import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping;
22+
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults;
23+
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;
24+
25+
public class TestHiveWasbConfig
26+
{
27+
@Test
28+
public void testDefaults()
29+
{
30+
assertRecordedDefaults(recordDefaults(HiveWasbConfig.class)
31+
.setWasbAccessKey(null)
32+
.setWasbStorageAccount(null));
33+
}
34+
35+
@Test
36+
public void testExplicitPropertyMappings()
37+
{
38+
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
39+
.put("hive.wasb.storage-account", "testwasbstorage")
40+
.put("hive.wasb.access-key", "secret")
41+
.build();
42+
43+
HiveWasbConfig expected = new HiveWasbConfig()
44+
.setWasbStorageAccount("testwasbstorage")
45+
.setWasbAccessKey("secret");
46+
47+
assertFullMapping(properties, expected);
48+
}
49+
}

0 commit comments

Comments
 (0)