|
|
@@ -2,12 +2,14 @@ package nju.seec.SEECdemo.logic.service.impl;
|
|
|
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.*;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.model.Deployment;
|
|
|
+import nju.seec.SEECdemo.logic.api.k8s.model.DeploymentStatus;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.model.Ingress;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.model.Service;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.exception.K8sApiException;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.util.SecretTypeEnum;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.vo.SecretVO;
|
|
|
import nju.seec.SEECdemo.logic.service.ApplicationService;
|
|
|
+import nju.seec.SEECdemo.logic.vo.ApplicationStatusVO;
|
|
|
import nju.seec.SEECdemo.logic.vo.ApplicationVO;
|
|
|
import nju.seec.SEECdemo.util.LoggerUtil;
|
|
|
import nju.seec.SEECdemo.web.dto.ApplicationDTO;
|
|
|
@@ -58,6 +60,10 @@ public class ApplicationServiceImpl implements ApplicationService{
|
|
|
|
|
|
@Override
|
|
|
public ApplicationVO getByName(String projectName, String name) {
|
|
|
+ Deployment deployment = deploymentApi.get(projectName, name);
|
|
|
+ if (deployment == null){
|
|
|
+ //抛出异常
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -86,23 +92,7 @@ public class ApplicationServiceImpl implements ApplicationService{
|
|
|
ingressApi.create(ingress);
|
|
|
|
|
|
//构建返回数据
|
|
|
- ApplicationVO applicationVO = new ApplicationVO();
|
|
|
- applicationVO.setName(applicationDTO.getName());
|
|
|
- applicationVO.setProjectName(applicationDTO.getProjectName());
|
|
|
- if (ingress.getHttpRules() != null) {
|
|
|
- applicationVO.setUrl(
|
|
|
- ingress.getHttpRules().stream()
|
|
|
- .map(rule -> ingress.getHttpHost() + rule).collect(Collectors.toList())
|
|
|
- );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- Thread.sleep(100000);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return applicationVO;
|
|
|
+ return buildApplicationVO(applicationDTO, deployment, ingress);
|
|
|
} catch (K8sApiException e) {
|
|
|
//抛出创建失败异常
|
|
|
deploymentApi.deleteIfExist(applicationDTO.getProjectName(), applicationDTO.getName());
|
|
|
@@ -112,6 +102,13 @@ public class ApplicationServiceImpl implements ApplicationService{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ApplicationStatusVO getStatus(String projectName, String name) {
|
|
|
+ Deployment deployment = deploymentApi.get(projectName, name);
|
|
|
+ if (deployment == null) return null;//抛出异常
|
|
|
+ return buildApplicationStatusVO(deployment);
|
|
|
+ }
|
|
|
+
|
|
|
private Deployment buildDeployment(ApplicationDTO applicationDTO) {
|
|
|
Deployment deployment = applicationDTO.toDeployment();
|
|
|
|
|
|
@@ -171,4 +168,27 @@ public class ApplicationServiceImpl implements ApplicationService{
|
|
|
ingress.setHttpRules(detailDTOS);
|
|
|
return ingress;
|
|
|
}
|
|
|
+
|
|
|
+ private ApplicationVO buildApplicationVO(ApplicationDTO applicationDTO, Deployment deployment, Ingress ingress) {
|
|
|
+ ApplicationVO applicationVO = new ApplicationVO();
|
|
|
+ applicationVO.setName(applicationDTO.getName());
|
|
|
+ applicationVO.setProjectName(applicationDTO.getProjectName());
|
|
|
+ if (ingress.getHttpRules() != null) {
|
|
|
+ applicationVO.setUrl(
|
|
|
+ ingress.getHttpRules().stream()
|
|
|
+ .map(rule -> ingress.getHttpHost() + rule).collect(Collectors.toList())
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+ ApplicationStatusVO applicationStatusVO = buildApplicationStatusVO(deployment);
|
|
|
+ applicationVO.setStatus(applicationStatusVO);
|
|
|
+ return applicationVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ApplicationStatusVO buildApplicationStatusVO(Deployment deployment) {
|
|
|
+ ApplicationStatusVO applicationStatusVO = new ApplicationStatusVO();
|
|
|
+ applicationStatusVO.setReadyReplicas(deployment.getStatus().getReadyReplicas());
|
|
|
+ applicationStatusVO.setDesiredReplicas(deployment.getReplicas());
|
|
|
+ return applicationStatusVO;
|
|
|
+ }
|
|
|
}
|