Package com.snowflake.kafka.connector
Class Utils
- java.lang.Object
-
- com.snowflake.kafka.connector.Utils
-
public class Utils extends Object
Various arbitrary helper functions
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static net.snowflake.client.jdbc.internal.apache.http.client.methods.HttpPostbuildOAuthHttpPostRequest(SnowflakeURL url, String path, Map<String,String> headers, net.snowflake.client.jdbc.internal.apache.http.entity.StringEntity entity)Build OAuth http post request base on headers and payloadstatic voidconvertAppName(Map<String,String> config)modify invalid application name in config and return the generated application namestatic StringformatLogMessage(String format, Object... vars)the following method wraps log messages with Snowflake tag.static StringformatString(String format, Object... vars)static StringgenerateValidName(String topic, Map<String,String> topic2table)verify topic name, and generate valid table/application namestatic StringgetExceptionMessage(String customMessage, Exception ex)Get the message and cause of a missing exception, handling the null or empty cases of eachstatic StringgetSnowflakeOAuthAccessToken(SnowflakeURL url, String clientId, String clientSecret, String refreshToken)Get OAuth access token given refresh tokenstatic StringgetSnowflakeOAuthToken(SnowflakeURL url, String clientId, String clientSecret, String credential, String grantType, String credentialType, String tokenType)Get OAuth token given integration info Snowflake OAuth Overviewstatic booleanisSingleFieldValid(org.apache.kafka.common.config.Config result)static Map<String,String>parseTopicToTableMap(String input)static StringpipeName(String appName, String table, int partition)generate pipe name by given table and partitionstatic StringquoteNameIfNeeded(String name)Quote the column name if needed: When there is quote already, we do nothing; otherwise we convert the name to upper case and add quotestatic voidsetJDBCLoggingDirectory()Read JDBC logging directory from environment variable JDBC_LOG_DIR and set that in System propertystatic StringstageName(String appName, String table)generate stage name by given tablestatic StringtableName(String topic, Map<String,String> topic2table)verify topic name, and generate valid table namestatic voidupdateConfigErrorMessage(org.apache.kafka.common.config.Config result, String key, String msg)static Map<String,org.apache.kafka.common.config.ConfigValue>validateConfigToMap(org.apache.kafka.common.config.Config result)
-
-
-
Field Detail
-
VERSION
public static final String VERSION
- See Also:
- Constant Field Values
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
SF_DATABASE
public static final String SF_DATABASE
- See Also:
- Constant Field Values
-
SF_SCHEMA
public static final String SF_SCHEMA
- See Also:
- Constant Field Values
-
SF_USER
public static final String SF_USER
- See Also:
- Constant Field Values
-
SF_PRIVATE_KEY
public static final String SF_PRIVATE_KEY
- See Also:
- Constant Field Values
-
SF_URL
public static final String SF_URL
- See Also:
- Constant Field Values
-
SF_SSL
public static final String SF_SSL
- See Also:
- Constant Field Values
-
SF_WAREHOUSE
public static final String SF_WAREHOUSE
- See Also:
- Constant Field Values
-
PRIVATE_KEY_PASSPHRASE
public static final String PRIVATE_KEY_PASSPHRASE
- See Also:
- Constant Field Values
-
SF_AUTHENTICATOR
public static final String SF_AUTHENTICATOR
- See Also:
- Constant Field Values
-
SF_OAUTH_CLIENT_ID
public static final String SF_OAUTH_CLIENT_ID
- See Also:
- Constant Field Values
-
SF_OAUTH_CLIENT_SECRET
public static final String SF_OAUTH_CLIENT_SECRET
- See Also:
- Constant Field Values
-
SF_OAUTH_REFRESH_TOKEN
public static final String SF_OAUTH_REFRESH_TOKEN
- See Also:
- Constant Field Values
-
SNOWFLAKE_JWT
public static final String SNOWFLAKE_JWT
- See Also:
- Constant Field Values
-
OAUTH
public static final String OAUTH
- See Also:
- Constant Field Values
-
SF_ROLE
public static final String SF_ROLE
This value should be present if ingestion method isIngestionMethodConfig.SNOWPIPE_STREAMING- See Also:
- Constant Field Values
-
TASK_ID
public static final String TASK_ID
- See Also:
- Constant Field Values
-
HTTP_USE_PROXY
public static final String HTTP_USE_PROXY
- See Also:
- Constant Field Values
-
HTTPS_PROXY_HOST
public static final String HTTPS_PROXY_HOST
- See Also:
- Constant Field Values
-
HTTPS_PROXY_PORT
public static final String HTTPS_PROXY_PORT
- See Also:
- Constant Field Values
-
HTTP_PROXY_HOST
public static final String HTTP_PROXY_HOST
- See Also:
- Constant Field Values
-
HTTP_PROXY_PORT
public static final String HTTP_PROXY_PORT
- See Also:
- Constant Field Values
-
HTTP_NON_PROXY_HOSTS
public static final String HTTP_NON_PROXY_HOSTS
- See Also:
- Constant Field Values
-
JDK_HTTP_AUTH_TUNNELING
public static final String JDK_HTTP_AUTH_TUNNELING
- See Also:
- Constant Field Values
-
HTTPS_PROXY_USER
public static final String HTTPS_PROXY_USER
- See Also:
- Constant Field Values
-
HTTPS_PROXY_PASSWORD
public static final String HTTPS_PROXY_PASSWORD
- See Also:
- Constant Field Values
-
HTTP_PROXY_USER
public static final String HTTP_PROXY_USER
- See Also:
- Constant Field Values
-
HTTP_PROXY_PASSWORD
public static final String HTTP_PROXY_PASSWORD
- See Also:
- Constant Field Values
-
JAVA_IO_TMPDIR
public static final String JAVA_IO_TMPDIR
- See Also:
- Constant Field Values
-
TABLE_COLUMN_CONTENT
public static final String TABLE_COLUMN_CONTENT
- See Also:
- Constant Field Values
-
TABLE_COLUMN_METADATA
public static final String TABLE_COLUMN_METADATA
- See Also:
- Constant Field Values
-
GET_EXCEPTION_FORMAT
public static final String GET_EXCEPTION_FORMAT
- See Also:
- Constant Field Values
-
GET_EXCEPTION_MISSING_MESSAGE
public static final String GET_EXCEPTION_MISSING_MESSAGE
- See Also:
- Constant Field Values
-
GET_EXCEPTION_MISSING_CAUSE
public static final String GET_EXCEPTION_MISSING_CAUSE
- See Also:
- Constant Field Values
-
-
Method Detail
-
quoteNameIfNeeded
public static String quoteNameIfNeeded(String name)
Quote the column name if needed: When there is quote already, we do nothing; otherwise we convert the name to upper case and add quote
-
stageName
public static String stageName(String appName, String table)
generate stage name by given table- Parameters:
appName- connector nametable- table name- Returns:
- stage name
-
pipeName
public static String pipeName(String appName, String table, int partition)
generate pipe name by given table and partition- Parameters:
appName- connector nametable- table namepartition- partition name- Returns:
- pipe name
-
setJDBCLoggingDirectory
public static void setJDBCLoggingDirectory()
Read JDBC logging directory from environment variable JDBC_LOG_DIR and set that in System property
-
convertAppName
public static void convertAppName(Map<String,String> config)
modify invalid application name in config and return the generated application name- Parameters:
config- input config object
-
tableName
public static String tableName(String topic, Map<String,String> topic2table)
verify topic name, and generate valid table name- Parameters:
topic- input topic nametopic2table- topic to table map- Returns:
- valid table name
-
generateValidName
public static String generateValidName(String topic, Map<String,String> topic2table)
verify topic name, and generate valid table/application name- Parameters:
topic- input topic nametopic2table- topic to table map- Returns:
- valid table/application name
-
isSingleFieldValid
public static boolean isSingleFieldValid(org.apache.kafka.common.config.Config result)
-
validateConfigToMap
public static Map<String,org.apache.kafka.common.config.ConfigValue> validateConfigToMap(org.apache.kafka.common.config.Config result)
-
updateConfigErrorMessage
public static void updateConfigErrorMessage(org.apache.kafka.common.config.Config result, String key, String msg)
-
formatLogMessage
public static String formatLogMessage(String format, Object... vars)
the following method wraps log messages with Snowflake tag. For example,[SF_KAFKA_CONNECTOR] this is a log message
[SF_KAFKA_CONNECTOR] this is the second line
All log messages should be wrapped by Snowflake tag. Then user can filter out log messages output from Snowflake Kafka connector by these tags.
- Parameters:
format- log message format stringvars- variable list- Returns:
- log message wrapped by snowflake tag
-
getSnowflakeOAuthAccessToken
public static String getSnowflakeOAuthAccessToken(SnowflakeURL url, String clientId, String clientSecret, String refreshToken)
Get OAuth access token given refresh token- Parameters:
url- OAuth server urlclientId- OAuth clientIdclientSecret- OAuth clientSecretrefreshToken- OAuth refresh token- Returns:
- OAuth access token
-
getSnowflakeOAuthToken
public static String getSnowflakeOAuthToken(SnowflakeURL url, String clientId, String clientSecret, String credential, String grantType, String credentialType, String tokenType)
Get OAuth token given integration info Snowflake OAuth Overview- Parameters:
url- OAuth server urlclientId- OAuth clientIdclientSecret- OAuth clientSecretcredential- OAuth credential, either az code or refresh tokengrantType- OAuth grant type, either authorization_code or refresh_tokencredentialType- OAuth credential key, either code or refresh_tokentokenType- type of OAuth token to get, either access_token or refresh_token- Returns:
- OAuth token
-
buildOAuthHttpPostRequest
public static net.snowflake.client.jdbc.internal.apache.http.client.methods.HttpPost buildOAuthHttpPostRequest(SnowflakeURL url, String path, Map<String,String> headers, net.snowflake.client.jdbc.internal.apache.http.entity.StringEntity entity)
Build OAuth http post request base on headers and payload- Parameters:
url- target urlheaders- headers key value pairsentity- payload entity- Returns:
- HttpPost request for OAuth
-
getExceptionMessage
public static String getExceptionMessage(String customMessage, Exception ex)
Get the message and cause of a missing exception, handling the null or empty cases of each- Parameters:
customMessage- A custom message to prepend to the exceptionex- The message to parse through- Returns:
- A string with the custom message and the exceptions message or cause, if exists
-
-