|
|
|
@@ -21,6 +21,7 @@ import javax.annotation.Resource; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service("serviceService") |
|
|
|
public class ServiceServiceImpl implements ServiceService { |
|
|
|
@@ -28,6 +29,9 @@ public class ServiceServiceImpl implements ServiceService { |
|
|
|
@Value("${argo.url}") |
|
|
|
private String argoUrl; |
|
|
|
|
|
|
|
@Value("${argo.modelService}") |
|
|
|
private String modelService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ServiceDao serviceDao; |
|
|
|
|
|
|
|
@@ -40,14 +44,52 @@ public class ServiceServiceImpl implements ServiceService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Page<ServiceVersion> queryByPageServiceVersion(ServiceVersion serviceVersion, int page, int size) { |
|
|
|
if (serviceVersion.getRunState() != null) { |
|
|
|
PageRequest pageRequest; |
|
|
|
if (StringUtils.isNotEmpty(serviceVersion.getRunState())) { |
|
|
|
pageRequest = PageRequest.of(page, Integer.MAX_VALUE); |
|
|
|
List<ServiceVersion> serviceVersions = serviceDao.queryByPageServiceVersion(serviceVersion, pageRequest); |
|
|
|
|
|
|
|
List<String> deploymentNames = serviceVersions.stream().map(ServiceVersion::getDeploymentName).collect(Collectors.toList()); |
|
|
|
Map<String, String> runStates = getRunState(deploymentNames); |
|
|
|
updateRunState(runStates); |
|
|
|
|
|
|
|
List<ServiceVersion> result = serviceVersions.stream().filter(serviceVersion1 -> { |
|
|
|
String runState = runStates.get(serviceVersion1.getDeploymentName()); |
|
|
|
return serviceVersion1.getRunState().equals(runState); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
PageRequest.of(page, size); |
|
|
|
return new PageImpl<>(result, pageRequest, result.size()); |
|
|
|
} else { |
|
|
|
pageRequest = PageRequest.of(page, size); |
|
|
|
long total = serviceDao.countServiceVersion(serviceVersion); |
|
|
|
List<ServiceVersion> serviceVersions = serviceDao.queryByPageServiceVersion(serviceVersion, pageRequest); |
|
|
|
|
|
|
|
List<String> deploymentNames = serviceVersions.stream().map(ServiceVersion::getDeploymentName).collect(Collectors.toList()); |
|
|
|
Map<String, String> runStates = getRunState(deploymentNames); |
|
|
|
updateRunState(runStates); |
|
|
|
|
|
|
|
return new PageImpl<>(serviceVersions, pageRequest, total); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, String> getRunState(List<String> deploymentNames) { |
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("deployment_names", deploymentNames); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + modelService + "/getStatus", JSON.toJSONString(paramMap)); |
|
|
|
if (StringUtils.isNotEmpty(req)) { |
|
|
|
Map<String, Object> reqMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) reqMap.get("data"); |
|
|
|
return data.get("status"); |
|
|
|
} else { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page, size); |
|
|
|
long total = serviceDao.countServiceVersion(serviceVersion); |
|
|
|
List<ServiceVersion> serviceVersions = serviceDao.queryByPageServiceVersion(serviceVersion, pageRequest); |
|
|
|
return new PageImpl<>(serviceVersions, pageRequest, total); |
|
|
|
void updateRunState(Map<String, String> runStates) { |
|
|
|
for (Map.Entry<String, String> entry : runStates.entrySet()) { |
|
|
|
serviceDao.updateRunState(entry.getKey(), entry.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@@ -126,27 +168,32 @@ public class ServiceServiceImpl implements ServiceService { |
|
|
|
ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); |
|
|
|
com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(serviceVersion.getServiceId()); |
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("code_config", serviceVersion.getCodeConfig()); |
|
|
|
paramMap.put("service_name", service.getServiceName()); |
|
|
|
paramMap.put("description", serviceVersion.getDescription()); |
|
|
|
paramMap.put("resource", serviceVersion.getResource()); |
|
|
|
paramMap.put("mount_path", serviceVersion.getMountPath()); |
|
|
|
paramMap.put("replicas", serviceVersion.getReplicas()); |
|
|
|
paramMap.put("env", JSONObject.parseObject(serviceVersion.getEnvVariables())); |
|
|
|
paramMap.put("code_config", JSONObject.parseObject(serviceVersion.getCodeConfig())); |
|
|
|
paramMap.put("image", serviceVersion.getImage()); |
|
|
|
paramMap.put("model", JSONObject.parseObject(serviceVersion.getModel())); |
|
|
|
paramMap.put("mount_path", serviceVersion.getMountPath()); |
|
|
|
paramMap.put("replicas", serviceVersion.getReplicas()); |
|
|
|
paramMap.put("resource", serviceVersion.getResource()); |
|
|
|
paramMap.put("service_name", service.getServiceName()); |
|
|
|
paramMap.put("service_type", service.getServiceType()); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + "/model/service/create", JSON.toJSONString(paramMap)); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + modelService + "/create", JSON.toJSONString(paramMap)); |
|
|
|
if (StringUtils.isNotEmpty(req)) { |
|
|
|
Map<String, Object> reqMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
serviceVersion.setUrl((String) reqMap.get("url")); |
|
|
|
serviceVersion.setDeploymentName((String) reqMap.get("deployment_name")); |
|
|
|
serviceVersion.setSvcName((String) reqMap.get("svc_name")); |
|
|
|
serviceVersion.setRunState(Constant.State_building); |
|
|
|
editServiceVersion(serviceVersion); |
|
|
|
return "启动成功"; |
|
|
|
if ((Integer) reqMap.get("code") == 200) { |
|
|
|
Map<String, String> data = (Map<String, String>) reqMap.get("data"); |
|
|
|
serviceVersion.setUrl(data.get("url")); |
|
|
|
serviceVersion.setDeploymentName(data.get("deployment_name")); |
|
|
|
serviceVersion.setSvcName(data.get("svc_name")); |
|
|
|
serviceVersion.setRunState(Constant.Init); |
|
|
|
editServiceVersion(serviceVersion); |
|
|
|
return "启动成功"; |
|
|
|
} else { |
|
|
|
throw new RuntimeException("启动失败"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new RuntimeException("创建失败"); |
|
|
|
throw new RuntimeException("启动失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -155,9 +202,9 @@ public class ServiceServiceImpl implements ServiceService { |
|
|
|
ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); |
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("deployment_name", serviceVersion.getDeploymentName()); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + "/model/service/create", JSON.toJSONString(paramMap)); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + modelService + "/stop", JSON.toJSONString(paramMap)); |
|
|
|
if (StringUtils.isNotEmpty(req)) { |
|
|
|
serviceVersion.setRunState(Constant.State_invalid); |
|
|
|
serviceVersion.setRunState(Constant.Stopped); |
|
|
|
editServiceVersion(serviceVersion); |
|
|
|
return "停止成功"; |
|
|
|
} else { |
|
|
|
@@ -173,7 +220,7 @@ public class ServiceServiceImpl implements ServiceService { |
|
|
|
updateMap.put("replicas", serviceVersion.getReplicas()); |
|
|
|
updateMap.put("resource", serviceVersion.getResource()); |
|
|
|
paramMap.put("update_model", JSON.toJSONString(updateMap)); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + "/model/service/update", JSON.toJSONString(paramMap)); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + modelService + "/update", JSON.toJSONString(paramMap)); |
|
|
|
if (StringUtils.isNotEmpty(req)) { |
|
|
|
return editServiceVersion(serviceVersion); |
|
|
|
} else { |
|
|
|
@@ -181,4 +228,36 @@ public class ServiceServiceImpl implements ServiceService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getServiceVersionLog(Long id, String startTime, String endTime) { |
|
|
|
ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); |
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("deployment_name", serviceVersion.getDeploymentName()); |
|
|
|
paramMap.put("start_time", startTime); |
|
|
|
paramMap.put("end_time", endTime); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + modelService + "/getLog", JSON.toJSONString(paramMap)); |
|
|
|
if (StringUtils.isNotEmpty(req)) { |
|
|
|
Map<String, Object> reqMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
HashMap<String, String> data = (HashMap<String, String>) reqMap.get("data"); |
|
|
|
return data.get("log_content"); |
|
|
|
} else { |
|
|
|
throw new RuntimeException("获取日志失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> getServiceVersionDocs(Long id) { |
|
|
|
ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); |
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("deployment_name", serviceVersion.getDeploymentName()); |
|
|
|
String req = HttpUtils.sendPost(argoUrl + modelService + "/getDocs", JSON.toJSONString(paramMap)); |
|
|
|
if (StringUtils.isNotEmpty(req)) { |
|
|
|
Map<String, Object> reqMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
Map<String, Object> data = (Map<String, Object>) reqMap.get("data"); |
|
|
|
return data; |
|
|
|
} else { |
|
|
|
throw new RuntimeException("获取日志失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |