|
|
@ -490,29 +490,37 @@ public class PythonGateway { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get datasource by given datasource name. It return map contain datasource id, type, name. |
|
|
|
* Get single datasource by given datasource name. if type is not null, |
|
|
|
* Useful in Python API create sql task which need datasource information. |
|
|
|
* it will return the datasource match the type. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param datasourceName user who create or update schedule |
|
|
|
* @param datasourceName datasource name of datasource |
|
|
|
|
|
|
|
* @param type datasource type |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, Object> getDatasourceInfo(String datasourceName) { |
|
|
|
public DataSource getDatasource(String datasourceName, String type) { |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(datasourceName); |
|
|
|
List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(datasourceName); |
|
|
|
if (dataSourceList == null || dataSourceList.isEmpty()) { |
|
|
|
if (dataSourceList == null || dataSourceList.isEmpty()) { |
|
|
|
String msg = String.format("Can not find any datasource by name %s", datasourceName); |
|
|
|
String msg = String.format("Can not find any datasource by name %s", datasourceName); |
|
|
|
log.error(msg); |
|
|
|
log.error(msg); |
|
|
|
throw new IllegalArgumentException(msg); |
|
|
|
throw new IllegalArgumentException(msg); |
|
|
|
} else if (dataSourceList.size() > 1) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<DataSource> dataSourceListMatchType = dataSourceList.stream() |
|
|
|
|
|
|
|
.filter(dataSource -> type == null || StringUtils.equalsIgnoreCase(dataSource.getType().name(), type)) |
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("Get the datasource list match the type are: {}", dataSourceListMatchType); |
|
|
|
|
|
|
|
if (dataSourceListMatchType.size() > 1) { |
|
|
|
String msg = String.format("Get more than one datasource by name %s", datasourceName); |
|
|
|
String msg = String.format("Get more than one datasource by name %s", datasourceName); |
|
|
|
log.error(msg); |
|
|
|
log.error(msg); |
|
|
|
throw new IllegalArgumentException(msg); |
|
|
|
throw new IllegalArgumentException(msg); |
|
|
|
} else { |
|
|
|
|
|
|
|
DataSource dataSource = dataSourceList.get(0); |
|
|
|
|
|
|
|
result.put("id", dataSource.getId()); |
|
|
|
|
|
|
|
result.put("type", dataSource.getType().name()); |
|
|
|
|
|
|
|
result.put("name", dataSource.getName()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
return dataSourceListMatchType.stream().findFirst().orElseThrow(() -> { |
|
|
|
|
|
|
|
String msg = String.format("Can not find any datasource by name %s and type %s", datasourceName, type); |
|
|
|
|
|
|
|
log.error(msg); |
|
|
|
|
|
|
|
return new IllegalArgumentException(msg); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|