Commit 8a7d0cf1 authored by mcb's avatar mcb

测试连通性

parent da86cb93
......@@ -6,84 +6,90 @@ import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "接口返回对象", description = "接口返回对象")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class JsonResult<T> {
/**
* 返回代码
*/
@ApiModelProperty(value = "返回代码")
private String code;
/**
* 返回处理消息
*/
@ApiModelProperty(value = "返回处理消息")
private String message;
/**
* 返回数据对象 data
*/
@ApiModelProperty(value = "返回数据对象")
private T data;
public JsonResult() {
this.setCode(ResultCode.SUCCESS);
this.setMessage("成功!");
}
public JsonResult(ResultCode code) {
this.setCode(code);
this.setMessage(code.msg());
}
public JsonResult(ResultCode code, String message) {
this.setCode(code);
this.setMessage(message);
}
public JsonResult(ResultCode code, T data) {
this.setCode(code);
this.setMessage(code.msg());
this.setData(data);
}
public JsonResult(ResultCode code, String message, T data) {
this.setCode(code);
this.setMessage(message);
this.setData(data);
}
public JsonResult(T data) {
this.setCode(ResultCode.SUCCESS);
this.setMessage("成功!");
this.setData(data);
}
public JsonResult(com.jz.dmp.agent.ResultCode code, String message) {
}
public String getCode() {
return code;
}
public void setCode(ResultCode code) {
this.code = code.val();
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public class JsonResult<T> {
/**
* 返回代码
*/
@ApiModelProperty(value = "返回代码")
private String code;
/**
* 返回处理消息
*/
@ApiModelProperty(value = "返回处理消息")
private String message;
/**
* 返回数据对象 data
*/
@ApiModelProperty(value = "返回数据对象")
private T data;
public JsonResult() {
this.setCode(ResultCode.SUCCESS);
this.setMessage("成功!");
}
public JsonResult(ResultCode code) {
this.setCode(code);
this.setMessage(code.msg());
}
public JsonResult(ResultCode code, String message) {
this.setCode(code);
this.setMessage(message);
}
public JsonResult(ResultCode code, T data) {
this.setCode(code);
this.setMessage(code.msg());
this.setData(data);
}
public JsonResult(ResultCode code, String message, T data) {
this.setCode(code);
this.setMessage(message);
this.setData(data);
}
public JsonResult(T data) {
this.setCode(ResultCode.SUCCESS);
this.setMessage("成功!");
this.setData(data);
}
public JsonResult(com.jz.dmp.agent.ResultCode code, String message) {
this.setCode(code);
this.setMessage(message);
}
public void setCode(com.jz.dmp.agent.ResultCode code) {
this.code = code.val();
}
public String getCode() {
return code;
}
public void setCode(ResultCode code) {
this.code = code.val();
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
......@@ -110,4 +110,16 @@ public class DataSourceController {
JsonResult result = dmpSyncingDatasourceService.addDatasourceInfo(saveBody);
return result;
}
/**
* 测试连通性
*
* @return
*/
@ApiOperation(value = "测试连通性", notes = "测试连通性")
@PostMapping(value = "/testConnection")
public JsonResult testConnection(@RequestBody @Validated DmpSyncingDatasourceReq saveBody, HttpServletRequest httpRequest) throws Exception {
JsonResult result = dmpSyncingDatasourceService.testConnection(saveBody);
return result;
}
}
......@@ -105,21 +105,6 @@ public class DmpSyncingDatasourceReq implements Serializable {
*/
@ApiModelProperty(value = "表空间")
private String tableSchema;
/**
* 数据状态
*/
@ApiModelProperty(value = "数据状态")
private String dataStatus;
/**
* 创建用户ID
*/
@ApiModelProperty(value = "创建用户ID")
private String createUserId;
/**
* 数据创建时间
*/
@ApiModelProperty(value = "数据创建时间")
private String createTime;
/**
* 项目ID
......@@ -269,30 +254,6 @@ public class DmpSyncingDatasourceReq implements Serializable {
this.tableSchema = tableSchema;
}
public String getDataStatus() {
return dataStatus;
}
public void setDataStatus(String dataStatus) {
this.dataStatus = dataStatus;
}
public String getCreateUserId() {
return createUserId;
}
public void setCreateUserId(String createUserId) {
this.createUserId = createUserId;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getProjectId() {
return projectId;
}
......
......@@ -4,6 +4,7 @@ import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListDto;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListReq;
import com.jz.dmp.modules.controller.DataIntegration.bean.DmpSyncingDatasourceReq;
import com.jz.dmp.modules.model.DmpSyncingDatasource;
import com.jz.dmp.modules.model.DmpSyncingDatasourceType;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -98,4 +99,5 @@ public interface DmpSyncingDatasourceDao {
int countDatasourceByName(@Param("datasourceName") String datasourceName, @Param("projectId") String projectId);
DmpSyncingDatasourceType queryDatasourceTypeById(@Param("datasourceTypeId") String datasourceTypeId);
}
\ No newline at end of file
......@@ -69,4 +69,6 @@ public interface DmpSyncingDatasourceService {
JsonResult queryGroupDatasourceType() throws Exception;
JsonResult addDatasourceInfo(DmpSyncingDatasourceReq saveBody) throws Exception;
JsonResult testConnection(DmpSyncingDatasourceReq saveBody) throws Exception;
}
\ No newline at end of file
......@@ -4,14 +4,21 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jz.agent.service.DmpDsAgentService;
import com.jz.common.constant.JsonResult;
import com.jz.common.constant.ResultCode;
import com.jz.common.page.PageInfoResponse;
import com.jz.common.utils.JsonMapper;
import com.jz.dmp.agent.DmpAgentResult;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListDto;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListReq;
import com.jz.dmp.modules.controller.DataIntegration.bean.DmpSyncingDatasourceReq;
import com.jz.dmp.modules.dao.DmpProjectDao;
import com.jz.dmp.modules.dao.DmpSyncingDatasourceDao;
import com.jz.dmp.modules.model.DmpAgentDatasourceInfo;
import com.jz.dmp.modules.model.DmpProjectSystemInfo;
import com.jz.dmp.modules.model.DmpSyncingDatasource;
import com.jz.dmp.modules.model.DmpSyncingDatasourceType;
import com.jz.dmp.modules.service.DmpSyncingDatasourceService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -40,6 +47,12 @@ public class DmpSyncingDatasourceServiceImpl implements DmpSyncingDatasourceServ
@Autowired
private DmpSyncingDatasourceDao dmpSyncingDatasourceDao;
@Autowired
private DmpProjectDao dmpProjectDao;
@Autowired
private DmpDsAgentService dmpDsAgentServiceImp;
/**
* 通过ID查询单条数据
*
......@@ -183,10 +196,62 @@ public class DmpSyncingDatasourceServiceImpl implements DmpSyncingDatasourceServ
BeanUtils.copyProperties(saveBody, dsd);
dsd.setCreateTime(new Date());
dsd.setDatasourceType(Integer.valueOf(saveBody.getDatasourceType()));
dsd.setDatasourceType(Integer.valueOf(saveBody.getDatasourceType())); //数据源类型ID
dsd.setProjectId(Integer.valueOf(saveBody.getProjectId()));
dsd.setDataStatus("1");
dmpSyncingDatasourceDao.insert(dsd);
return new JsonResult(dsd);
}
/**
* 测试连通性
*
* @return
*/
@Override
public JsonResult testConnection(DmpSyncingDatasourceReq saveBody) throws Exception {
DmpAgentDatasourceInfo ds = this.dsInfoDTO(saveBody); //查询数据源 对应的 数据库信息
DmpAgentResult rst = dmpDsAgentServiceImp.testConnect(ds); //连接测试
if (!rst.getCode().val().equals("200")) {
return new JsonResult(rst.getCode(), rst.getMessage());
} else {
rst.setResult(JsonMapper.fromJsonString(rst.getMessage(), Boolean.class));
return new JsonResult(ResultCode.SUCCESS, rst);
}
}
private DmpAgentDatasourceInfo dsInfoDTO(DmpSyncingDatasourceReq body) {
//数据源类型ID去查询
DmpSyncingDatasourceType type = dmpSyncingDatasourceDao.queryDatasourceTypeById(body.getDatasourceType());
DmpAgentDatasourceInfo ds = new DmpAgentDatasourceInfo();
ds.setDatasourceType(type.getDatasourceType());
ds.setDatasourceName(body.getDatasourceName());
ds.setDbName(body.getDbName());
ds.setJdbcUrl(body.getJdbcUrl());
ds.setUserName(body.getUserName());
ds.setPassword(body.getPassword());
ds.setDriverClassName(type.getDriverClassName());
ds.setHost(body.getHost());
ds.setPort(body.getPort());
ds.setDelimiter(body.getDelimiter());
ds.setProtocol(body.getProtocol());
ds.setProjectId(body.getProjectId() + "");
ds.setAccessId(body.getAccessId());
ds.setAccessKey(body.getAccessKey());
ds.setIsHaveHeader(body.getIsHaveHeader());
ds.setEndpoint(body.getEndpoint());
ds.setDefaultFs(body.getDefaultFs());
DmpProjectSystemInfo info = dmpProjectDao.queryProjectSystemInfo(Long.valueOf(body.getProjectId()));
ds.setKerberosIsenable(info.getKerberosIsenable());
ds.setKerberosJaasConf(info.getKerberosJaasConf());
ds.setKerberosKrb5Conf(info.getKerberosKrb5Conf());
ds.setKerberosFqdn(info.getKerberosFqdn());
ds.setHdfsDefaultConf(""); // info.getHdfsDefaultConf());
ds.setHdfsConfPath(""); // info.getHdfsConfPath());
ds.setHdfsAuthPath(body.getAccessKey());
ds.setHdfsUserName(info.getHdfsUserName());
ds.setHdfsSyncingPath(info.getHdfsSyncingPath());
return ds;
}
}
\ No newline at end of file
......@@ -313,4 +313,14 @@
and ds.project_id = #{projectId}
</select>
<select id="queryDatasourceTypeById" parameterType="map" resultType="dmpSyncingDatasourceType">
select
datasource as datasourceName,
id ,
datasource_type as datasourceType,
driver_class_name as driverClassName
from dmp_syncing_datasource_type
where id=#{datasourceTypeId}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment