Skip to content

Commit c1663bf

Browse files
committed
Add ExternalDocumentationLink in abstract sink
1 parent 00c5e96 commit c1663bf

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

cloudsql-mysql-plugin/src/main/java/io/cdap/plugin/cloudsql/mysql/CloudSQLMySQLSink.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ protected String getErrorDetailsProviderClassName() {
108108
return CloudSQLMySQLErrorDetailsProvider.class.getName();
109109
}
110110

111+
@Override
112+
protected String getExternalDocumentationLink() {
113+
return DBUtils.CLOUDSQLMYSQL_SUPPORTED_DOC_URL;
114+
}
115+
111116
@Override
112117
protected LineageRecorder getLineageRecorder(BatchSinkContext context) {
113118
String host;

database-commons/src/main/java/io/cdap/plugin/db/sink/AbstractDBSink.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import io.cdap.cdap.api.data.format.StructuredRecord;
2626
import io.cdap.cdap.api.data.schema.Schema;
2727
import io.cdap.cdap.api.dataset.lib.KeyValue;
28+
import io.cdap.cdap.api.exception.ErrorCategory;
29+
import io.cdap.cdap.api.exception.ErrorCodeType;
30+
import io.cdap.cdap.api.exception.ErrorType;
31+
import io.cdap.cdap.api.exception.ErrorUtils;
2832
import io.cdap.cdap.api.plugin.PluginConfig;
2933
import io.cdap.cdap.etl.api.Emitter;
3034
import io.cdap.cdap.etl.api.FailureCollector;
@@ -175,6 +179,16 @@ protected String getErrorDetailsProviderClassName() {
175179
return DBErrorDetailsProvider.class.getName();
176180
}
177181

182+
/**
183+
* Returns the external documentation link.
184+
* Override this method to provide a custom external documentation link.
185+
*
186+
* @return external documentation link
187+
*/
188+
protected String getExternalDocumentationLink() {
189+
return null;
190+
}
191+
178192
@Override
179193
public void prepareRun(BatchSinkContext context) {
180194
String connectionString = dbSinkConfig.getConnectionString();
@@ -296,8 +310,21 @@ private Schema inferSchema(Class<? extends Driver> driverClass) {
296310
inferredFields.addAll(getSchemaReader().getSchemaFields(rs));
297311
}
298312
} catch (SQLException e) {
299-
throw new InvalidStageException("Error while reading table metadata", e);
300-
313+
// wrap exception to ensure SQLException-child instances not exposed to contexts without jdbc driver in classpath
314+
String errorMessageWithDetails = String.format("Error while reading table metadata." +
315+
"Error message: '%s'. Error code: '%s'. SQLState: '%s'", e.getMessage(), e.getErrorCode(), e.getSQLState());
316+
String externalDocumentationLink = getExternalDocumentationLink();
317+
if (!Strings.isNullOrEmpty(externalDocumentationLink)) {
318+
if (!errorMessageWithDetails.endsWith(".")) {
319+
errorMessageWithDetails = errorMessageWithDetails + ".";
320+
}
321+
errorMessageWithDetails = String.format("%s For more details, see %s", errorMessageWithDetails,
322+
externalDocumentationLink);
323+
}
324+
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
325+
e.getMessage(), errorMessageWithDetails, ErrorType.USER, false, ErrorCodeType.SQLSTATE,
326+
e.getSQLState(), externalDocumentationLink, new SQLException(e.getMessage(),
327+
e.getSQLState(), e.getErrorCode()));
301328
}
302329
} catch (IllegalAccessException | InstantiationException | SQLException e) {
303330
throw new InvalidStageException("JDBC Driver unavailable: " + dbSinkConfig.getJdbcPluginName(), e);

database-commons/src/main/java/io/cdap/plugin/db/source/AbstractDBSource.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ protected Class<? extends DBWritable> getDBRecordType() {
373373
return DBRecord.class;
374374
}
375375

376+
/**
377+
* Returns the external documentation link.
378+
* Override this method to provide a custom external documentation link.
379+
*
380+
* @return external documentation link
381+
*/
376382
protected String getExternalDocumentationLink() {
377383
return null;
378384
}

mysql-plugin/src/main/java/io/cdap/plugin/mysql/MysqlSink.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ protected String getErrorDetailsProviderClassName() {
114114
return MysqlErrorDetailsProvider.class.getName();
115115
}
116116

117+
@Override
118+
protected String getExternalDocumentationLink() {
119+
return DBUtils.MYSQL_SUPPORTED_DOC_URL;
120+
}
121+
117122
/**
118123
* MySQL action configuration.
119124
*/

postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresSink.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ protected String getErrorDetailsProviderClassName() {
121121
return PostgresErrorDetailsProvider.class.getName();
122122
}
123123

124+
@Override
125+
protected String getExternalDocumentationLink() {
126+
return DBUtils.POSTGRES_SUPPORTED_DOC_URL;
127+
}
128+
124129
/**
125130
* PostgreSQL action configuration.
126131
*/

0 commit comments

Comments
 (0)