Skip to content

Commit 7c89430

Browse files
authored
Merge pull request #206 from data-integrations/enable-connection-for-source/sink
Enable connection for source/sink
2 parents 625002e + 0fd972b commit 7c89430

File tree

48 files changed

+297
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+297
-118
lines changed

cloudsql-mysql-plugin/docs/CloudSQLMySQL-batchsink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Properties
1919
----------
2020
**Reference Name:** Name used to uniquely identify this sink for lineage, annotating metadata, etc.
2121

22+
**Use Connection** Whether to use a connection. If a connection is used, you do not need to provide the credentials.
23+
24+
**Connection** Name of the connection to use. Project and service account information will be provided by the connection.
25+
You also can use the macro function ${conn(connection-name)}.
26+
2227
**Driver Name:** Name of the JDBC driver to use.
2328

2429
**Database:** MySQL database name.

cloudsql-mysql-plugin/docs/CloudSQLMySQL-batchsource.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Properties
1818
----------
1919
**Reference Name:** Name used to uniquely identify this source for lineage, annotating metadata, etc.
2020

21+
**Use Connection** Whether to use a connection. If a connection is used, you do not need to provide the credentials.
22+
23+
**Connection** Name of the connection to use. Project and service account information will be provided by the connection.
24+
You also can use the macro function ${conn(connection-name)}.
25+
2126
**Driver Name:** Name of the JDBC driver to use.
2227

2328
**Database:** MySQL database name.

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected String getTableQuery(String database, String schema, String table, int
8585
protected void setConnectorSpec(ConnectorSpecRequest request, DBConnectorPath path,
8686
ConnectorSpec.Builder builder) {
8787
Map<String, String> properties = new HashMap<>();
88-
setConnectionProperties(properties);
88+
setConnectionProperties(properties, request);
8989
builder
9090
.addRelatedPlugin(new PluginSpec(CloudSQLMySQLConstants.PLUGIN_NAME, BatchSource.PLUGIN_TYPE, properties))
9191
.addRelatedPlugin(new PluginSpec(CloudSQLMySQLConstants.PLUGIN_NAME, BatchSink.PLUGIN_TYPE, properties));
@@ -103,14 +103,4 @@ protected void setConnectorSpec(ConnectorSpecRequest request, DBConnectorPath pa
103103
properties.put(Constants.Reference.REFERENCE_NAME, ReferenceNames.cleanseReferenceName(table));
104104
properties.put(CloudSQLMySQLSink.CloudSQLMySQLSinkConfig.TABLE_NAME, table);
105105
}
106-
107-
@Override
108-
protected void setConnectionProperties(Map<String, String> properties) {
109-
Map<String, String> rawProperties = config.getRawProperties().getProperties();
110-
properties.put(ConnectionConfig.JDBC_PLUGIN_NAME, rawProperties.get(ConnectionConfig.JDBC_PLUGIN_NAME));
111-
properties.put(ConnectionConfig.USER, rawProperties.get(ConnectionConfig.USER));
112-
properties.put(ConnectionConfig.PASSWORD, rawProperties.get(ConnectionConfig.PASSWORD));
113-
properties.put(CloudSQLMySQLConstants.CONNECTION_NAME, rawProperties.get(CloudSQLMySQLConstants.CONNECTION_NAME));
114-
properties.put(CloudSQLMySQLConstants.INSTANCE_TYPE, rawProperties.get(CloudSQLMySQLConstants.INSTANCE_TYPE));
115-
}
116106
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public Map<String, String> getDBSpecificArguments() {
106106
CloudSQLMySQLConstants.CONNECTION_TIMEOUT, String.valueOf(connectionTimeout));
107107
}
108108

109+
@Override
110+
public void validate(FailureCollector collector) {
111+
ConfigUtil.validateConnection(this, useConnection, connection, collector);
112+
super.validate(collector);
113+
}
114+
109115
@Override
110116
@Nullable
111117
protected CloudSQLMySQLConnectorConfig getConnection() {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ protected Map<String, String> getDBSpecificArguments() {
112112
return arguments;
113113
}
114114

115+
@Override
116+
public void validate(FailureCollector collector) {
117+
ConfigUtil.validateConnection(this, useConnection, connection, collector);
118+
super.validate(collector);
119+
}
120+
115121
@Override
116122
protected CloudSQLMySQLConnectorConfig getConnection() {
117123
return connection;

cloudsql-mysql-plugin/widgets/CloudSQLMySQL-batchsink.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88
"label": "Connection",
99
"properties": [
1010
{
11-
"widget-type": "hidden",
11+
"widget-type": "toggle",
12+
"label": "Use connection",
1213
"name": "useConnection",
1314
"widget-attributes": {
15+
"on": {
16+
"value": "true",
17+
"label": "YES"
18+
},
19+
"off": {
20+
"value": "false",
21+
"label": "NO"
22+
},
1423
"default": "false"
1524
}
1625
},

cloudsql-mysql-plugin/widgets/CloudSQLMySQL-batchsource.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88
"label": "Connection",
99
"properties": [
1010
{
11-
"widget-type": "hidden",
11+
"widget-type": "toggle",
12+
"label": "Use connection",
1213
"name": "useConnection",
1314
"widget-attributes": {
15+
"on": {
16+
"value": "true",
17+
"label": "YES"
18+
},
19+
"off": {
20+
"value": "false",
21+
"label": "NO"
22+
},
1423
"default": "false"
1524
}
1625
},

cloudsql-postgresql-plugin/docs/CloudSQLPostgreSQL-batchsink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Properties
1919
----------
2020
**Reference Name:** Name used to uniquely identify this sink for lineage, annotating metadata, etc.
2121

22+
**Use Connection** Whether to use a connection. If a connection is used, you do not need to provide the credentials.
23+
24+
**Connection** Name of the connection to use. Project and service account information will be provided by the connection.
25+
You also can use the macro function ${conn(connection-name)}.
26+
2227
**Driver Name:** Name of the JDBC driver to use.
2328

2429
**Database:** CloudSQL PostgreSQL database name.

cloudsql-postgresql-plugin/docs/CloudSQLPostgreSQL-batchsource.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Properties
1818
----------
1919
**Reference Name:** Name used to uniquely identify this source for lineage, annotating metadata, etc.
2020

21+
**Use Connection** Whether to use a connection. If a connection is used, you do not need to provide the credentials.
22+
23+
**Connection** Name of the connection to use. Project and service account information will be provided by the connection.
24+
You also can use the macro function ${conn(connection-name)}.
25+
2126
**Driver Name:** Name of the JDBC driver to use.
2227

2328
**Database:** CloudSQL PostgreSQL database name.

cloudsql-postgresql-plugin/src/main/java/io/cdap/plugin/cloudsql/postgres/CloudSQLPostgreSQLConnector.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected String getTableQuery(String database, String schema, String table, int
9191
protected void setConnectorSpec(ConnectorSpecRequest request, DBConnectorPath path,
9292
ConnectorSpec.Builder builder) {
9393
Map<String, String> properties = new HashMap<>();
94-
setConnectionProperties(properties);
94+
setConnectionProperties(properties, request);
9595
builder
9696
.addRelatedPlugin(new PluginSpec(CloudSQLPostgreSQLConstants.PLUGIN_NAME, BatchSource.PLUGIN_TYPE, properties))
9797
.addRelatedPlugin(new PluginSpec(CloudSQLPostgreSQLConstants.PLUGIN_NAME, BatchSink.PLUGIN_TYPE, properties));
@@ -108,16 +108,4 @@ protected void setConnectorSpec(ConnectorSpecRequest request, DBConnectorPath pa
108108
properties.put(Constants.Reference.REFERENCE_NAME, ReferenceNames.cleanseReferenceName(table));
109109
properties.put(CloudSQLPostgreSQLSink.CloudSQLPostgreSQLSinkConfig.TABLE_NAME, table);
110110
}
111-
112-
@Override
113-
protected void setConnectionProperties(Map<String, String> properties) {
114-
Map<String, String> rawProperties = config.getRawProperties().getProperties();
115-
properties.put(ConnectionConfig.JDBC_PLUGIN_NAME, rawProperties.get(ConnectionConfig.JDBC_PLUGIN_NAME));
116-
properties.put(ConnectionConfig.USER, rawProperties.get(ConnectionConfig.USER));
117-
properties.put(ConnectionConfig.PASSWORD, rawProperties.get(ConnectionConfig.PASSWORD));
118-
properties.put(CloudSQLPostgreSQLConstants.CONNECTION_NAME,
119-
rawProperties.get(CloudSQLPostgreSQLConstants.CONNECTION_NAME));
120-
properties.put(CloudSQLPostgreSQLConstants.INSTANCE_TYPE,
121-
rawProperties.get(CloudSQLPostgreSQLConstants.INSTANCE_TYPE));
122-
}
123111
}

0 commit comments

Comments
 (0)