|
25 | 25 | import org.apache.doris.job.cdc.DataSourceConfigKeys; |
26 | 26 | import org.apache.doris.job.cdc.request.FetchRecordRequest; |
27 | 27 | import org.apache.doris.job.common.DataSourceType; |
| 28 | +import org.apache.doris.job.extensions.insert.streaming.DataSourceConfigValidator; |
28 | 29 | import org.apache.doris.job.util.StreamingJobUtils; |
29 | 30 | import org.apache.doris.thrift.TBrokerFileStatus; |
30 | 31 | import org.apache.doris.thrift.TFileType; |
@@ -106,18 +107,77 @@ private String generateParams(Map<String, String> properties) throws AnalysisExc |
106 | 107 | } |
107 | 108 |
|
108 | 109 | private void validate(Map<String, String> properties) throws AnalysisException { |
109 | | - if (!properties.containsKey(DataSourceConfigKeys.JDBC_URL)) { |
| 110 | + if (StringUtils.isEmpty(properties.get(DataSourceConfigKeys.JDBC_URL))) { |
110 | 111 | throw new AnalysisException("jdbc_url is required"); |
111 | 112 | } |
112 | | - if (!properties.containsKey(DataSourceConfigKeys.TYPE)) { |
| 113 | + if (StringUtils.isEmpty(properties.get(DataSourceConfigKeys.TYPE))) { |
113 | 114 | throw new AnalysisException("type is required"); |
114 | 115 | } |
115 | | - if (!properties.containsKey(DataSourceConfigKeys.TABLE)) { |
| 116 | + if (StringUtils.isEmpty(properties.get(DataSourceConfigKeys.TABLE))) { |
116 | 117 | throw new AnalysisException("table is required"); |
117 | 118 | } |
118 | | - if (!properties.containsKey(DataSourceConfigKeys.OFFSET)) { |
| 119 | + if (StringUtils.isEmpty(properties.get(DataSourceConfigKeys.OFFSET))) { |
119 | 120 | throw new AnalysisException("offset is required"); |
120 | 121 | } |
| 122 | + DataSourceType sourceType; |
| 123 | + try { |
| 124 | + sourceType = DataSourceType.valueOf(properties.get(DataSourceConfigKeys.TYPE).toUpperCase()); |
| 125 | + } catch (IllegalArgumentException e) { |
| 126 | + throw new AnalysisException("Unsupported type: " + properties.get(DataSourceConfigKeys.TYPE)); |
| 127 | + } |
| 128 | + switch (sourceType) { |
| 129 | + case MYSQL: |
| 130 | + if (StringUtils.isEmpty(properties.get(DataSourceConfigKeys.DATABASE))) { |
| 131 | + throw new AnalysisException("database is required for MySQL"); |
| 132 | + } |
| 133 | + break; |
| 134 | + case POSTGRES: |
| 135 | + if (StringUtils.isEmpty(properties.get(DataSourceConfigKeys.SCHEMA))) { |
| 136 | + throw new AnalysisException("schema is required for PostgreSQL"); |
| 137 | + } |
| 138 | + validatePgIdentifierIfPresent(properties, DataSourceConfigKeys.SLOT_NAME); |
| 139 | + validatePgIdentifierIfPresent(properties, DataSourceConfigKeys.PUBLICATION_NAME); |
| 140 | + break; |
| 141 | + default: |
| 142 | + throw new AnalysisException("Unsupported type: " + sourceType); |
| 143 | + } |
| 144 | + String offset = properties.get(DataSourceConfigKeys.OFFSET); |
| 145 | + if (!DataSourceConfigValidator.isValidOffset(offset, sourceType.name())) { |
| 146 | + throw new AnalysisException("Invalid value for key 'offset': " + offset); |
| 147 | + } |
| 148 | + String sslMode = properties.get(DataSourceConfigKeys.SSL_MODE); |
| 149 | + if (sslMode != null && !DataSourceConfigValidator.isValidSslMode(sslMode)) { |
| 150 | + throw new AnalysisException("Invalid value for key 'ssl_mode': " + sslMode); |
| 151 | + } |
| 152 | + try { |
| 153 | + DataSourceConfigValidator.validateSslVerifyCaPair(properties); |
| 154 | + } catch (IllegalArgumentException e) { |
| 155 | + throw new AnalysisException(e.getMessage()); |
| 156 | + } |
| 157 | + validatePositiveIntIfPresent(properties, DataSourceConfigKeys.SNAPSHOT_SPLIT_SIZE); |
| 158 | + validatePositiveIntIfPresent(properties, DataSourceConfigKeys.SNAPSHOT_PARALLELISM); |
| 159 | + } |
| 160 | + |
| 161 | + private static void validatePositiveIntIfPresent(Map<String, String> properties, String key) |
| 162 | + throws AnalysisException { |
| 163 | + String value = properties.get(key); |
| 164 | + if (value == null) { |
| 165 | + return; |
| 166 | + } |
| 167 | + if (!DataSourceConfigValidator.isPositiveInt(value)) { |
| 168 | + throw new AnalysisException("Invalid value for key '" + key + "': " + value); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + private static void validatePgIdentifierIfPresent(Map<String, String> properties, String key) |
| 173 | + throws AnalysisException { |
| 174 | + String value = properties.get(key); |
| 175 | + if (value == null) { |
| 176 | + return; |
| 177 | + } |
| 178 | + if (!DataSourceConfigValidator.isValidPgIdentifier(value)) { |
| 179 | + throw new AnalysisException("Invalid value for key '" + key + "': " + value); |
| 180 | + } |
121 | 181 | } |
122 | 182 |
|
123 | 183 | private void generateFileStatus() { |
|
0 commit comments