Commit fd361591 authored by 赵啸非's avatar 赵啸非

添加实例查询

parent 676c6471
...@@ -2,6 +2,7 @@ package com.mortals.xhx.module.setup.web; ...@@ -2,6 +2,7 @@ package com.mortals.xhx.module.setup.web;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil; import cn.hutool.core.util.ZipUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
...@@ -43,13 +44,14 @@ import static com.mortals.framework.web.BaseController.*; ...@@ -43,13 +44,14 @@ import static com.mortals.framework.web.BaseController.*;
public class SetupProjectController { public class SetupProjectController {
@Value("${upload.path}") @Value("${upload.path}")
@Getter
private String filePath; private String filePath;
@Value("${project.publishPath}") @Value("${project.publishPath}")
@Getter
private String publishPath; private String publishPath;
@Value("${project.nacosUrl}")
private String nacosUrl;
@Autowired @Autowired
private UploadService uploadService; private UploadService uploadService;
...@@ -106,13 +108,68 @@ public class SetupProjectController { ...@@ -106,13 +108,68 @@ public class SetupProjectController {
String sourcePath = "/project/" + ProductDisEnum.getByValue(projectSetupEntity.getProjectValue()).getDesc() + "/" + projectSetupEntity.getProjectValue() + ".tar.gz"; String sourcePath = "/project/" + ProductDisEnum.getByValue(projectSetupEntity.getProjectValue()).getDesc() + "/" + projectSetupEntity.getProjectValue() + ".tar.gz";
InputStream inputStream = this.getClass().getResourceAsStream(sourcePath); InputStream inputStream = this.getClass().getResourceAsStream(sourcePath);
ZipUtils.unGzip(inputStream, unZipPath); ZipUtils.unGzip(inputStream, unZipPath);
ret.put(KEY_RESULT_MSG, "项目资源部署成功");
} catch (Exception e) { } catch (Exception e) {
code = VALUE_RESULT_FAILURE; code = VALUE_RESULT_FAILURE;
log.error("导入资源文件失败", e); log.error("导入资源文件失败", e);
ret.put(KEY_RESULT_MSG, e.getMessage()); ret.put(KEY_RESULT_MSG, e.getMessage());
} }
ret.put(KEY_RESULT_CODE, code); ret.put(KEY_RESULT_CODE, code);
ret.put(KEY_RESULT_MSG, "项目资源部署成功");
return ret.toJSONString();
}
/**
* 服务列表查询
*
* @param projectSetupEntity
* @return
*/
@PostMapping("/list")
@UnAuth
public String list(@RequestBody ProjectSetupEntity projectSetupEntity) {
JSONObject ret = new JSONObject();
int code = VALUE_RESULT_SUCCESS;
try {
// curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/catalog/services?pageNo=1&pageSize=100&namespaceId=smart-gov'
String resp = HttpUtil.get(nacosUrl + "/v1/ns/catalog/services?pageNo=1&pageSize=100&namespaceId=smart-gov");
ret.put(KEY_RESULT_DATA, resp);
ret.put(KEY_RESULT_MSG, "项目资源部署成功");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
log.error("查询服务状态失败", e);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/**
* 服务实例详细查询
*
* @param projectSetupEntity
* @return
*/
@PostMapping("/instances")
@UnAuth
public String instances(@RequestBody ProjectSetupEntity projectSetupEntity) {
JSONObject ret = new JSONObject();
int code = VALUE_RESULT_SUCCESS;
try {
// curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/catalog/instances?serviceName=base-manager&clusterName=DEFAULT&groupName=DEFAULT_GROUP&pageSize=10&pageNo=1&namespaceId=smart-gov'
String resp = HttpUtil.get(nacosUrl + "/v1/ns/catalog/instances?serviceName=" + projectSetupEntity.getProjectValue() + "&clusterName=DEFAULT&groupName=DEFAULT_GROUP&pageSize=10&pageNo=1&namespaceId=smart-gov");
ret.put(KEY_RESULT_DATA, resp);
ret.put(KEY_RESULT_MSG, "服务实例详细查询成功");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
log.error("服务实例详细查询失败", e);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString(); return ret.toJSONString();
} }
......
...@@ -37,7 +37,7 @@ import static com.mortals.framework.web.BaseController.*; ...@@ -37,7 +37,7 @@ import static com.mortals.framework.web.BaseController.*;
@RestController @RestController
@RequestMapping("resource") @RequestMapping("resource")
@Slf4j @Slf4j
public class SetupResourceController { public class SetupResourceController {
@Value("${upload.path}") @Value("${upload.path}")
@Getter @Getter
...@@ -64,9 +64,9 @@ public class SetupResourceController { ...@@ -64,9 +64,9 @@ public class SetupResourceController {
throw new AppException("部署只支持zip文件!"); throw new AppException("部署只支持zip文件!");
} }
if(!FileUtil.isDirectory(filePath)){ if (!FileUtil.isDirectory(filePath)) {
//部署路径是否存在 如果不存在 创建目录, //部署路径是否存在 如果不存在 创建目录,
FileUtil.mkdir(filePath); FileUtil.mkdir(filePath);
} }
String fileEncode = "UTF-8"; String fileEncode = "UTF-8";
...@@ -88,20 +88,6 @@ public class SetupResourceController { ...@@ -88,20 +88,6 @@ public class SetupResourceController {
return ret.toJSONString(); return ret.toJSONString();
} }
//检查bank数据库是否存在
private boolean databaseExists(Connection conn, String dbName) throws SQLException {
ResultSet resultSet = conn.getMetaData().getCatalogs();
while (resultSet.next()) {
if (dbName.equals(resultSet.getString(1))) {
return true;
}
}
return false;
}
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(FileUtil.isDirectory("E://pic")); System.out.println(FileUtil.isDirectory("E://pic"));
......
...@@ -28,3 +28,4 @@ upload: ...@@ -28,3 +28,4 @@ upload:
path: E:/pic path: E:/pic
project: project:
publishPath: E:\pic\zip\ publishPath: E:\pic\zip\
nacosUrl: http://127.0.0.1:8848
...@@ -82,7 +82,7 @@ POST http://localhost:8081/project/distribute ...@@ -82,7 +82,7 @@ POST http://localhost:8081/project/distribute
Content-Type: application/json Content-Type: application/json
{ {
"projectValue": "base-manager" "projectValue": "portal-manager"
} }
......
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