Skip to content

Commit

Permalink
patching up gen1 mount & blob creation error check
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Storey committed Jun 10, 2020
1 parent 56e0c63 commit ce716b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions databricks/mounts.go
Expand Up @@ -117,16 +117,21 @@ func (m AzureBlobMount) Create(client *service.DBApiClient, clusterID string) er
confKey = fmt.Sprintf("fs.azure.account.key.%s.blob.core.windows.net", m.StorageAccountName)
}
iamMountCommand := fmt.Sprintf(`
for mount in dbutils.fs.mounts():
if mount.mountPoint == "/mnt/%[4]s" and mount.source=="wasbs://%[1]s@%[2]s.blob.core.windows.net%[3]s":
print ("Mount already exists")
dbutils.notebook.exit("success")
try:
dbutils.fs.mount(
source = "wasbs://%s@%s.blob.core.windows.net%s",
mount_point = "/mnt/%s",
extra_configs = {"%s":dbutils.secrets.get(scope = "%s", key = "%s")})
source = "wasbs://%[1]s@%[2]s.blob.core.windows.net%[3]s",
mount_point = "/mnt/%[4]s",
extra_configs = {"%[5]s":dbutils.secrets.get(scope = "%[6]s", key = "%[7]s")})
except Exception as e:
dbutils.fs.unmount("/mnt/%s")
dbutils.fs.unmount("/mnt/%[4]s")
raise e
dbutils.notebook.exit("success")
`, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, confKey, m.SecretScope, m.SecretKey, m.MountName)
`, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, confKey, m.SecretScope, m.SecretKey)
resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand)
if err != nil {
return err
Expand Down
15 changes: 10 additions & 5 deletions databricks/resource_databricks_azure_adls_gen1_mount.go
Expand Up @@ -135,10 +135,6 @@ func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error {
func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error {
client := m.(*service.DBApiClient)
clusterID := d.Get("cluster_id").(string)
err := changeClusterIntoRunningState(clusterID, client)
if err != nil {
return err
}
storageResourceName := d.Get("storage_resource_name").(string)
sparkConfPrefix := d.Get("spark_conf_prefix").(string)
directory := d.Get("directory").(string)
Expand All @@ -147,7 +143,16 @@ func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error {
clientID := d.Get("client_id").(string)
clientSecretScope := d.Get("client_secret_scope").(string)
clientSecretKey := d.Get("client_secret_key").(string)

err := changeClusterIntoRunningState(clusterID, client)
if err != nil {
if isClusterMissing(err.Error(), clusterID) {
log.Printf("Unable to refresh mount '%s' as cluster '%s' is missing", mountName, clusterID)
d.SetId("")
return nil
}
return err
}

adlsGen1Mount := NewAzureADLSGen1Mount(storageResourceName, directory, mountName,
sparkConfPrefix, clientID, tenantID, clientSecretScope, clientSecretKey)

Expand Down

0 comments on commit ce716b9

Please sign in to comment.