use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.
the class DsInfoService method dsInfoDetail.
/**
* 根据数据源Id获取数据源详情
*
* @param dataInfoId
* @return
*/
public DsDetailVO dsInfoDetail(Long dataInfoId) {
DsInfo dsInfo = lambdaQuery().eq(DsInfo::getId, dataInfoId).one();
DsDetailVO dsDetailVO = DsDetailTransfer.INSTANCE.toInfoVO(dsInfo);
String dataJson = dsInfo.getDataJson();
JSONObject dataSourceJson = DataSourceUtils.getDataSourceJson(dataJson);
if (DataSourceUtils.judgeOpenKerberos(dataJson) && null == dataSourceJson.getString(FormNames.PRINCIPAL)) {
JSONObject kerberosConfig = dataSourceJson.getJSONObject(FormNames.KERBEROS_CONFIG);
dataSourceJson.put(FormNames.PRINCIPAL, kerberosConfig.getString(FormNames.PRINCIPAL));
}
if (DataSourceUtils.judgeOpenKerberos(dsInfo.getDataJson()) && dsInfo.getDataType().equals(DataSourceTypeEnum.KAFKA.getDataType())) {
// kafka开启了kerberos认证
dataSourceJson.put(FormNames.AUTHENTICATION, FormNames.KERBROS);
}
return dsDetailVO;
}
use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.
the class DatasourceService method kerberosConnectPrepare.
/**
* kerberos认证前预处理 :对kerberos参数替换相对路径为绝对路径等操作
* @param sourceId
* @return
*/
public Map<String, Object> kerberosConnectPrepare(Long sourceId) {
DsInfo dataSource = dsInfoService.getOneById(sourceId);
DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(dataSource.getDataType(), dataSource.getDataVersion());
if (Objects.isNull(typeEnum)) {
throw new PubSvcDefineException(ErrorCode.CAN_NOT_FITABLE_SOURCE_TYPE);
}
Map<String, Object> kerberosConfig = fillKerberosConfig(dataSource.getId());
HashMap<String, Object> tmpKerberosConfig = new HashMap<>(kerberosConfig);
// kerberos获取表操作预处理
if (MapUtils.isNotEmpty(kerberosConfig)) {
String localKerberosPath = kerberosService.getLocalKerberosPath(sourceId);
IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
try {
kerberos.prepareKerberosForConnect(tmpKerberosConfig, localKerberosPath);
} catch (Exception e) {
LOGGER.error("kerberos连接预处理失败!{}", e.getMessage(), e);
throw new DtCenterDefException(String.format("kerberos连接预处理失败,Caused by: %s", e.getMessage()), e);
}
}
return tmpKerberosConfig;
}
use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.
the class DatasourceService method fillKerberosConfig.
/**
* 根据已有数据源主键填充confMap
* @param sourceId
* @return
*/
public Map<String, Object> fillKerberosConfig(Long sourceId) {
DsInfo dataSource = dsInfoService.getOneById(sourceId);
Long tenantId = dataSource.getTenantId();
// 获取Kerberos客户端
JSONObject kerberosConfig = DataSourceUtils.getOriginKerberosConfig(dataSource.getDataJson(), false);
if (MapUtils.isEmpty(kerberosConfig)) {
return Collections.emptyMap();
}
try {
// 获取kerberos本地路径
String localKerberosConf = kerberosService.getLocalKerberosPath(sourceId);
kerberosService.downloadKerberosFromSftp(dataSource.getIsMeta(), sourceId, DataSourceUtils.getDataSourceJson(dataSource.getDataJson()), localKerberosConf, tenantId);
} catch (SftpException e) {
throw new DtCenterDefException(String.format("获取kerberos认证文件失败,Caused by: %s", e.getMessage()), e);
}
return kerberosConfig;
}
use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.
the class DatasourceService method buildDsInfo.
/**
* 构建数据源元数据对象
* @param dataSourceVO
* @return
*/
private DsInfo buildDsInfo(DataSourceVO dataSourceVO) {
DsInfo dsInfo = new DsInfo();
dsInfo.setDataType(dataSourceVO.getDataType());
dsInfo.setDataVersion(dataSourceVO.getDataVersion());
dsInfo.setDataName(dataSourceVO.getDataName());
dsInfo.setDataDesc(dataSourceVO.getDataDesc());
dsInfo.setStatus(1);
dsInfo.setIsMeta(dataSourceVO.getIsMeta());
dsInfo.setTenantId(dataSourceVO.getTenantId());
dsInfo.setTenantId(dataSourceVO.getTenantId());
dsInfo.setSchemaName(dataSourceVO.getSchemaName());
DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(dataSourceVO.getDataType(), dataSourceVO.getDataVersion());
dsInfo.setDataTypeCode(typeEnum.getVal());
// dataJson
if (Objects.nonNull(dataSourceVO.getDataJson())) {
JSONObject dataJson = dataSourceVO.getDataJson();
if (dataSourceVO.getDataType().equals(DataSourceTypeEnum.HBASE2.getDataType())) {
// Hbase需要特殊处理
JSONObject jsonObject = new JSONObject();
jsonObject.put(FormNames.HBASE_ZK_QUORUM, dataJson.get(FormNames.HBASE_QUORUM));
jsonObject.put(FormNames.HBASE_ZK_PARENT, dataJson.get(FormNames.HBASE_PARENT));
dataJson.put("hbaseConfig", jsonObject);
}
JSONObject kerberos;
if ((kerberos = dataJson.getJSONObject(DataSourceUtils.KERBEROS_CONFIG)) != null) {
dataJson.put(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, kerberos.getOrDefault(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, System.currentTimeMillis()));
}
dsInfo.setDataJson(DataSourceUtils.getEncodeDataSource(dataJson, true));
String linkInfo = getDataSourceLinkInfo(dataSourceVO.getDataType(), dataSourceVO.getDataVersion(), dataSourceVO.getDataJson());
dsInfo.setLinkJson(DataSourceUtils.getEncodeDataSource(linkInfo, true));
} else if (Strings.isNotBlank(dataSourceVO.getDataJsonString())) {
JSONObject dataSourceJson = DataSourceUtils.getDataSourceJson(dataSourceVO.getDataJsonString());
if (dataSourceVO.getDataType().equals(DataSourceTypeEnum.HBASE2.getDataType())) {
// Hbase需要特殊处理
JSONObject jsonObject = new JSONObject();
jsonObject.put(FormNames.HBASE_QUORUM, dataSourceJson.get(FormNames.HBASE_QUORUM));
jsonObject.put(FormNames.HBASE_ZK_PARENT, dataSourceJson.get(FormNames.HBASE_PARENT));
dataSourceJson.put("hbaseConfig", jsonObject);
}
JSONObject kerberos;
if ((kerberos = dataSourceJson.getJSONObject(DataSourceUtils.KERBEROS_CONFIG)) != null) {
dataSourceJson.put(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, kerberos.getOrDefault(DataSourceUtils.KERBEROS_FILE_TIMESTAMP, System.currentTimeMillis()));
}
dsInfo.setDataJson(DataSourceUtils.getEncodeDataSource(dataSourceJson, true));
// 获取连接信息
String linkInfo = getDataSourceLinkInfo(dataSourceVO.getDataType(), dataSourceVO.getDataVersion(), dataSourceJson);
dsInfo.setLinkJson(DataSourceUtils.getEncodeDataSource(linkInfo, true));
} else {
throw new PubSvcDefineException(ErrorCode.DATASOURCE_CONF_ERROR);
}
return dsInfo;
}
use of com.dtstack.taier.dao.domain.DsInfo in project Taier by DTStack.
the class DatasourceService method getOne.
public BatchDataSource getOne(Long id) {
DsInfo dsInfo = dsInfoService.getOneById(id);
BatchDataSource batchDataSource = new BatchDataSource();
BeanUtils.copyProperties(dsInfo, batchDataSource);
batchDataSource.setType(dsInfo.getDataTypeCode());
batchDataSource.setIsDefault(dsInfo.getIsMeta());
return batchDataSource;
}
Aggregations