Class SnowflakeAzureClient
- java.lang.Object
-
- net.snowflake.client.jdbc.cloud.storage.SnowflakeAzureClient
-
- All Implemented Interfaces:
SnowflakeStorageClient
public class SnowflakeAzureClient extends Object implements SnowflakeStorageClient
Encapsulates the Azure Storage client and all Azure Storage operations and logic- Author:
- lgiakoumakis
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDigestMetadata(StorageObjectMetadata meta, String digest)Adds digest metadata to the StorageObjectMetadata objectvoidaddEncryptionMetadata(StorageObjectMetadata meta, MatDesc matDesc, byte[] ivData, byte[] encKeK, long contentLength)Adds encryption metadata to the StorageObjectMetadata objectvoidaddStreamingIngestMetadata(StorageObjectMetadata meta, String clientName, String clientKey)Adds streaming ingest metadata to the StorageObjectMetadata object, used for streaming ingest per client billing calculationstatic SnowflakeAzureClientcreateSnowflakeAzureClient(StageInfo stage, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, SFBaseSession sfSession)voiddownload(SFSession session, String command, String localLocation, String destFileName, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion, String presignedUrl)Download a file from remote storage.InputStreamdownloadToStream(SFSession session, String command, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion, String presignedUrl)Download a file from remote storageStringgetDigestMetadata(StorageObjectMetadata meta)Gets digest metadata to the StorageObjectMetadata objectintgetEncryptionKeySize()StringgetMatdescKey()Returns the material descriptor keyintgetMaxRetries()StorageObjectMetadatagetObjectMetadata(String remoteStorageLocation, String prefix)Returns the metadata properties for a remote storage objectintgetRetryBackoffMaxExponent()Returns the max exponent for multiplying backoff with the power of 2, the value of 4 will give us 16secs as the max number of time to sleep before retryintgetRetryBackoffMin()StringgetStreamingIngestClientKey(StorageObjectMetadata meta)Gets streaming ingest client key to the StorageObjectMetadata objectStringgetStreamingIngestClientName(StorageObjectMetadata meta)Gets streaming ingest client name to the StorageObjectMetadata objectvoidhandleStorageException(Exception ex, int retryCount, String operation, SFSession session, String command)Handles exceptions thrown by Azure StoragebooleanisEncrypting()StorageObjectSummaryCollectionlistObjects(String remoteStorageLocation, String prefix)For a set of remote storage objects under a remote location and a given prefix/path returns their properties wrapped in ObjectSummary objectsvoidrenew(Map<?,?> stageCredentials)Re-creates the encapsulated storage client with a fresh access tokenvoidshutdown()shuts down the clientvoidupload(SFSession session, String command, int parallelism, boolean uploadFromStream, String remoteStorageLocation, File srcFile, String destFileName, InputStream inputStream, FileBackedOutputStream fileBackedOutputStream, StorageObjectMetadata meta, String stageRegion, String presignedUrl)Upload a file/stream to remote storage-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.snowflake.client.jdbc.cloud.storage.SnowflakeStorageClient
requirePresignedUrl, uploadWithPresignedUrlWithoutConnection
-
-
-
-
Method Detail
-
createSnowflakeAzureClient
public static SnowflakeAzureClient createSnowflakeAzureClient(StageInfo stage, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, SFBaseSession sfSession) throws SnowflakeSQLException
- Throws:
SnowflakeSQLException
-
getMaxRetries
public int getMaxRetries()
- Specified by:
getMaxRetriesin interfaceSnowflakeStorageClient- Returns:
- Returns the Max number of retry attempts
-
getRetryBackoffMaxExponent
public int getRetryBackoffMaxExponent()
Description copied from interface:SnowflakeStorageClientReturns the max exponent for multiplying backoff with the power of 2, the value of 4 will give us 16secs as the max number of time to sleep before retry- Specified by:
getRetryBackoffMaxExponentin interfaceSnowflakeStorageClient- Returns:
- Returns the exponent
-
getRetryBackoffMin
public int getRetryBackoffMin()
- Specified by:
getRetryBackoffMinin interfaceSnowflakeStorageClient- Returns:
- Returns the min number of milliseconds to sleep before retry
-
isEncrypting
public boolean isEncrypting()
- Specified by:
isEncryptingin interfaceSnowflakeStorageClient- Returns:
- Returns true if encryption is enabled
-
getEncryptionKeySize
public int getEncryptionKeySize()
- Specified by:
getEncryptionKeySizein interfaceSnowflakeStorageClient- Returns:
- Returns the size of the encryption key
-
renew
public void renew(Map<?,?> stageCredentials) throws SnowflakeSQLException
Re-creates the encapsulated storage client with a fresh access token- Specified by:
renewin interfaceSnowflakeStorageClient- Parameters:
stageCredentials- a Map (as returned by GS) which contains the new credential properties- Throws:
SnowflakeSQLException- failure to renew the client
-
shutdown
public void shutdown()
shuts down the client- Specified by:
shutdownin interfaceSnowflakeStorageClient
-
listObjects
public StorageObjectSummaryCollection listObjects(String remoteStorageLocation, String prefix) throws StorageProviderException
For a set of remote storage objects under a remote location and a given prefix/path returns their properties wrapped in ObjectSummary objects- Specified by:
listObjectsin interfaceSnowflakeStorageClient- Parameters:
remoteStorageLocation- location, i.e. container for Azureprefix- the prefix/path to list under- Returns:
- a collection of storage summary objects
- Throws:
StorageProviderException- Azure storage exception
-
getObjectMetadata
public StorageObjectMetadata getObjectMetadata(String remoteStorageLocation, String prefix) throws StorageProviderException
Returns the metadata properties for a remote storage object- Specified by:
getObjectMetadatain interfaceSnowflakeStorageClient- Parameters:
remoteStorageLocation- location, i.e. bucket for S3prefix- the prefix/path of the object to retrieve- Returns:
- storage metadata object
- Throws:
StorageProviderException- azure storage exception
-
download
public void download(SFSession session, String command, String localLocation, String destFileName, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion, String presignedUrl) throws SnowflakeSQLException
Download a file from remote storage.- Specified by:
downloadin interfaceSnowflakeStorageClient- Parameters:
session- session objectcommand- command to download filelocalLocation- local file pathdestFileName- destination file nameparallelism- number of threads for parallel downloadingremoteStorageLocation- remote storage location, i.e. bucket for S3stageFilePath- stage file pathstageRegion- region name where the stage persistspresignedUrl- Unused in Azure- Throws:
SnowflakeSQLException- download failure
-
downloadToStream
public InputStream downloadToStream(SFSession session, String command, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion, String presignedUrl) throws SnowflakeSQLException
Download a file from remote storage- Specified by:
downloadToStreamin interfaceSnowflakeStorageClient- Parameters:
session- session objectcommand- command to download fileparallelism- number of threads for parallel downloadingremoteStorageLocation- remote storage location, i.e. bucket for s3stageFilePath- stage file pathstageRegion- region name where the stage persistspresignedUrl- Unused in Azure- Returns:
- input file stream
- Throws:
SnowflakeSQLException- when download failure
-
upload
public void upload(SFSession session, String command, int parallelism, boolean uploadFromStream, String remoteStorageLocation, File srcFile, String destFileName, InputStream inputStream, FileBackedOutputStream fileBackedOutputStream, StorageObjectMetadata meta, String stageRegion, String presignedUrl) throws SnowflakeSQLException
Upload a file/stream to remote storage- Specified by:
uploadin interfaceSnowflakeStorageClient- Parameters:
session- session objectcommand- upload commandparallelism- number of threads for parallel uploadinguploadFromStream- true if upload source is streamremoteStorageLocation- storage container namesrcFile- source file if not uploading from a streamdestFileName- file name on remote storage after uploadinputStream- stream used for uploading if fileBackedOutputStream is nullfileBackedOutputStream- stream used for uploading if not nullmeta- object meta datastageRegion- region name where the stage persistspresignedUrl- Unused in Azure- Throws:
SnowflakeSQLException- if upload failed even after retry
-
handleStorageException
public void handleStorageException(Exception ex, int retryCount, String operation, SFSession session, String command) throws SnowflakeSQLException
Handles exceptions thrown by Azure Storage- Specified by:
handleStorageExceptionin interfaceSnowflakeStorageClient- Parameters:
ex- the exception to handleretryCount- current number of retries, incremented by the caller before each calloperation- string that indicates the function/operation that was taking place, when the exception was raised, for example "upload"session- the current SFSession object used by the clientcommand- the command attempted at the time of the exception- Throws:
SnowflakeSQLException- exceptions not handled
-
getMatdescKey
public String getMatdescKey()
Returns the material descriptor key- Specified by:
getMatdescKeyin interfaceSnowflakeStorageClient- Returns:
- the material descriptor key
-
addEncryptionMetadata
public void addEncryptionMetadata(StorageObjectMetadata meta, MatDesc matDesc, byte[] ivData, byte[] encKeK, long contentLength)
Adds encryption metadata to the StorageObjectMetadata object- Specified by:
addEncryptionMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the storage metadata object to add the encryption info tomatDesc- the material descriptorivData- the initialization vectorencKeK- the key encryption keycontentLength- the length of the encrypted content
-
addDigestMetadata
public void addDigestMetadata(StorageObjectMetadata meta, String digest)
Adds digest metadata to the StorageObjectMetadata object- Specified by:
addDigestMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the storage metadata object to add the digest todigest- the digest metadata to add
-
getDigestMetadata
public String getDigestMetadata(StorageObjectMetadata meta)
Gets digest metadata to the StorageObjectMetadata object- Specified by:
getDigestMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the metadata object to extract the digest metadata from- Returns:
- the digest metadata value
-
addStreamingIngestMetadata
public void addStreamingIngestMetadata(StorageObjectMetadata meta, String clientName, String clientKey)
Adds streaming ingest metadata to the StorageObjectMetadata object, used for streaming ingest per client billing calculation- Specified by:
addStreamingIngestMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the storage metadata object to add the digest toclientName- streaming ingest client nameclientKey- streaming ingest client key, provided by Snowflake
-
getStreamingIngestClientName
public String getStreamingIngestClientName(StorageObjectMetadata meta)
Gets streaming ingest client name to the StorageObjectMetadata object- Specified by:
getStreamingIngestClientNamein interfaceSnowflakeStorageClient
-
getStreamingIngestClientKey
public String getStreamingIngestClientKey(StorageObjectMetadata meta)
Gets streaming ingest client key to the StorageObjectMetadata object- Specified by:
getStreamingIngestClientKeyin interfaceSnowflakeStorageClient
-
-