Search in sources :

Example 6 with AdsException

use of com.alibaba.datax.plugin.writer.adswriter.AdsException in project DataX by alibaba.

the class AdsHelper method checkLoadDataJobStatusWithRetry.

private String checkLoadDataJobStatusWithRetry(final String jobId) throws AdsException {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        final String finalAdsUrl = this.adsURL;
        final String finalSchema = this.schema;
        final Long finalSocketTimeout = this.socketTimeout;
        final String suffix = this.suffix;
        return RetryUtil.executeWithRetry(new Callable<String>() {

            @Override
            public String call() throws Exception {
                Connection connection = null;
                Statement statement = null;
                ResultSet rs = null;
                try {
                    String url = AdsUtil.prepareJdbcUrl(finalAdsUrl, finalSchema, finalSocketTimeout, suffix);
                    Properties connectionProps = new Properties();
                    connectionProps.put("user", userName);
                    connectionProps.put("password", password);
                    connection = DriverManager.getConnection(url, connectionProps);
                    statement = connection.createStatement();
                    String sql = "select state from information_schema.job_instances where job_id like '" + jobId + "'";
                    rs = statement.executeQuery(sql);
                    String state = null;
                    while (DBUtil.asyncResultSetNext(rs)) {
                        state = rs.getString(1);
                    }
                    return state;
                } finally {
                    if (rs != null) {
                        try {
                            rs.close();
                        } catch (SQLException e) {
                        // Ignore exception
                        }
                    }
                    if (statement != null) {
                        try {
                            statement.close();
                        } catch (SQLException e) {
                        // Ignore exception
                        }
                    }
                    if (connection != null) {
                        try {
                            connection.close();
                        } catch (SQLException e) {
                        // Ignore exception
                        }
                    }
                }
            }
        }, 3, 1000L, true);
    } catch (Exception e) {
        throw new AdsException(AdsException.OTHER, e.getMessage(), e);
    }
}
Also used : Properties(java.util.Properties) DataXException(com.alibaba.datax.common.exception.DataXException) AdsException(com.alibaba.datax.plugin.writer.adswriter.AdsException) AdsException(com.alibaba.datax.plugin.writer.adswriter.AdsException)

Aggregations

AdsException (com.alibaba.datax.plugin.writer.adswriter.AdsException)6 TableInfo (com.alibaba.datax.plugin.writer.adswriter.ads.TableInfo)4 DataXException (com.alibaba.datax.common.exception.DataXException)3 ColumnInfo (com.alibaba.datax.plugin.writer.adswriter.ads.ColumnInfo)3 AdsHelper (com.alibaba.datax.plugin.writer.adswriter.load.AdsHelper)3 Properties (java.util.Properties)3 ArrayList (java.util.ArrayList)2