| @@ -165,7 +165,9 @@ public class DatasetVersionServiceImpl implements DatasetVersionService { | |||||
| .findFirst() | .findFirst() | ||||
| .ifPresent(datasetVersion -> { | .ifPresent(datasetVersion -> { | ||||
| String url = datasetVersion.getUrl(); | String url = datasetVersion.getUrl(); | ||||
| response.put("path", url); | |||||
| // response.put("path", url); | |||||
| String path = bucketName + '/' + url.substring(0, url.lastIndexOf('/')); | |||||
| response.put("path", path); | |||||
| }); | }); | ||||
| response.put("content", datasetVersionList); | response.put("content", datasetVersionList); | ||||
| @@ -61,7 +61,9 @@ public class ImageServiceImpl implements ImageService { | |||||
| @Resource | @Resource | ||||
| private MinioService minioService; | private MinioService minioService; | ||||
| @Value("${minio.dataReleaseBucketName}") | |||||
| // @Value("${minio.dataReleaseBucketName}") | |||||
| // private String bucketName; | |||||
| @Value("${harbor.bucketName}") | |||||
| private String bucketName; | private String bucketName; | ||||
| @Value("${harbor.repository}") | @Value("${harbor.repository}") | ||||
| private String repository; | private String repository; | ||||
| @@ -90,23 +90,25 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| // 提取数据集,模型信息,得到数据集模型的path | // 提取数据集,模型信息,得到数据集模型的path | ||||
| Map<String, Object> dataset = JacksonUtil.parseJSONStr2Map(devEnvironment.getDataset()); | Map<String, Object> dataset = JacksonUtil.parseJSONStr2Map(devEnvironment.getDataset()); | ||||
| String datasetPath = (String) dataset.get("path"); | |||||
| String datasetPath = "argo-workflow" + "/" + dataset.get("path"); | |||||
| // String datasetPath = (String) dataset.get("path"); | |||||
| Map<String, Object> model = JacksonUtil.parseJSONStr2Map(devEnvironment.getModel()); | Map<String, Object> model = JacksonUtil.parseJSONStr2Map(devEnvironment.getModel()); | ||||
| String modelPath = (String) model.get("path"); | |||||
| String modelPath = "argo-workflow" + "/" + model.get("path"); | |||||
| // String modelPath = (String) model.get("path"); | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| //构造pod名称 | //构造pod名称 | ||||
| String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id; | String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id; | ||||
| //新建编辑器的pvc | //新建编辑器的pvc | ||||
| // String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | |||||
| // V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | |||||
| String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | |||||
| V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | |||||
| //TODO 设置镜像可配置,这里先用默认镜像启动pod | //TODO 设置镜像可配置,这里先用默认镜像启动pod | ||||
| // 调用修改后的 createPod 方法,传入额外的参数 | // 调用修改后的 createPod 方法,传入额外的参数 | ||||
| // Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment, minioPvcName, datasetPath, modelPath); | |||||
| Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, null, devEnvironment, minioPvcName, datasetPath, modelPath); | |||||
| Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment, minioPvcName, datasetPath, modelPath); | |||||
| // Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, null, devEnvironment, minioPvcName, datasetPath, modelPath); | |||||
| String url = masterIp + ":" + podPort; | String url = masterIp + ":" + podPort; | ||||
| redisService.setCacheObject(podName, masterIp + ":" + podPort); | redisService.setCacheObject(podName, masterIp + ":" + podPort); | ||||
| devEnvironment.setStatus("Pending"); | devEnvironment.setStatus("Pending"); | ||||
| @@ -59,13 +59,17 @@ public class TensorBoardServiceImpl implements TensorBoardService { | |||||
| @Override | @Override | ||||
| public String runTensorBoard(FrameLogPathVo frameLogPathVo) throws Exception { | public String runTensorBoard(FrameLogPathVo frameLogPathVo) throws Exception { | ||||
| if (StringUtils.isEmpty(frameLogPathVo.getPath())) { | |||||
| throw new Exception("存储路径为空"); | |||||
| if (StringUtils.isEmpty(frameLogPathVo.getPath())||StringUtils.isEmpty(frameLogPathVo.getPvcName())){ | |||||
| throw new Exception("存储路径或存储为空"); | |||||
| } | } | ||||
| // if (StringUtils.isEmpty(frameLogPathVo.getPath())) { | |||||
| // throw new Exception("存储路径为空"); | |||||
| // } | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String podName = loginUser.getUsername().toLowerCase()+"-"+frameLogPathVo.getPath().split("/")[2]+ "-tensorboard-pod"; | String podName = loginUser.getUsername().toLowerCase()+"-"+frameLogPathVo.getPath().split("/")[2]+ "-tensorboard-pod"; | ||||
| Integer podPort = k8sClientUtil.createPodWithSubPath(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace(), port, mountPath, frameLogPathVo.getPath(), image); | |||||
| Integer podPort = k8sClientUtil.createPodWithSubPath(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace(), port, mountPath, frameLogPathVo.getPath(), frameLogPathVo.getPvcName(), image); | |||||
| // Integer podPort = k8sClientUtil.createPodWithSubPath(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace(), port, mountPath, frameLogPathVo.getPath(), image); | |||||
| redisService.setCacheObject(podName, masterIp + ":" + podPort); | redisService.setCacheObject(podName, masterIp + ":" + podPort); | ||||
| return masterIp + ":" + podPort; | return masterIp + ":" + podPort; | ||||
| } | } | ||||
| @@ -34,8 +34,8 @@ import java.util.*; | |||||
| @Component | @Component | ||||
| public class K8sClientUtil { | public class K8sClientUtil { | ||||
| @Value("${jupyter.hostPath}") | |||||
| private String hostPath; | |||||
| // @Value("${jupyter.hostPath}") | |||||
| // private String hostPath; | |||||
| private String http; | private String http; | ||||
| private String token; | private String token; | ||||
| @@ -314,8 +314,8 @@ public class K8sClientUtil { | |||||
| * @param image 镜像 | * @param image 镜像 | ||||
| * @return 创建成功的pod,的nodePort端口 | * @return 创建成功的pod,的nodePort端口 | ||||
| */ | */ | ||||
| public Integer createPodWithSubPath(String podName, String namespace, Integer port, String mountPath, String subPath, String image) { | |||||
| public Integer createPodWithSubPath(String podName, String namespace, Integer port, String mountPath, String subPath, String pvcName, String image) { | |||||
| // public Integer createPodWithSubPath(String podName, String namespace, Integer port, String mountPath, String subPath, String image) { | |||||
| Map<String, String> selector = new LinkedHashMap<>(); | Map<String, String> selector = new LinkedHashMap<>(); | ||||
| selector.put("k8s-jupyter", podName); | selector.put("k8s-jupyter", podName); | ||||
| @@ -366,8 +366,8 @@ public class K8sClientUtil { | |||||
| .endContainer() | .endContainer() | ||||
| .addNewVolume() | .addNewVolume() | ||||
| .withName("workspace") | .withName("workspace") | ||||
| .withHostPath(new V1HostPathVolumeSource().path(hostPath).type("DirectoryOrCreate")) | |||||
| // .withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvcName)) | |||||
| // .withHostPath(new V1HostPathVolumeSource().path(hostPath).type("DirectoryOrCreate")) | |||||
| .withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvcName)) | |||||
| .endVolume() | .endVolume() | ||||
| .withTerminationGracePeriodSeconds(14400L) | .withTerminationGracePeriodSeconds(14400L) | ||||
| .endSpec() | .endSpec() | ||||
| @@ -449,25 +449,25 @@ public class K8sClientUtil { | |||||
| } | } | ||||
| } | } | ||||
| // 配置卷和卷挂载 | |||||
| List<V1VolumeMount> volumeMounts = new ArrayList<>(); | |||||
| volumeMounts.add(new V1VolumeMount().name("workspace").mountPath("/opt/notebooks")); | |||||
| volumeMounts.add(new V1VolumeMount().name("data").mountPath("/opt/dataset").subPath(datasetPath).readOnly(true)); | |||||
| volumeMounts.add(new V1VolumeMount().name("data").mountPath("/opt/model").subPath(modelPath).readOnly(true)); | |||||
| List<V1Volume> volumes = new ArrayList<>(); | |||||
| volumes.add(new V1Volume().name("workspace").hostPath(new V1HostPathVolumeSource().path(hostPath + "/" + podName + "/notebooks").type("DirectoryOrCreate"))); | |||||
| volumes.add(new V1Volume().name("data").hostPath(new V1HostPathVolumeSource().path(hostPath).type("DirectoryOrCreate"))); | |||||
| // 配置卷和卷挂载 | // 配置卷和卷挂载 | ||||
| // List<V1VolumeMount> volumeMounts = new ArrayList<>(); | // List<V1VolumeMount> volumeMounts = new ArrayList<>(); | ||||
| // volumeMounts.add(new V1VolumeMount().name("workspace").mountPath(mountPath)); | |||||
| // volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/data").subPath(datasetPath).readOnly(true)); | |||||
| // volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/model").subPath(modelPath).readOnly(true)); | |||||
| // volumeMounts.add(new V1VolumeMount().name("workspace").mountPath("/opt/notebooks")); | |||||
| // volumeMounts.add(new V1VolumeMount().name("data").mountPath("/opt/dataset").subPath(datasetPath).readOnly(true)); | |||||
| // volumeMounts.add(new V1VolumeMount().name("data").mountPath("/opt/model").subPath(modelPath).readOnly(true)); | |||||
| // | // | ||||
| // List<V1Volume> volumes = new ArrayList<>(); | // List<V1Volume> volumes = new ArrayList<>(); | ||||
| // volumes.add(new V1Volume().name("workspace").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvc.getMetadata().getName()))); | |||||
| // volumes.add(new V1Volume().name("minio-pvc").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(dataPvcName))); | |||||
| // volumes.add(new V1Volume().name("workspace").hostPath(new V1HostPathVolumeSource().path(hostPath + "/" + podName + "/notebooks").type("DirectoryOrCreate"))); | |||||
| // volumes.add(new V1Volume().name("data").hostPath(new V1HostPathVolumeSource().path(hostPath).type("DirectoryOrCreate"))); | |||||
| // 配置卷和卷挂载 | |||||
| List<V1VolumeMount> volumeMounts = new ArrayList<>(); | |||||
| volumeMounts.add(new V1VolumeMount().name("workspace").mountPath(mountPath)); | |||||
| volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/data").subPath(datasetPath).readOnly(true)); | |||||
| volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/model").subPath(modelPath).readOnly(true)); | |||||
| List<V1Volume> volumes = new ArrayList<>(); | |||||
| volumes.add(new V1Volume().name("workspace").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvc.getMetadata().getName()))); | |||||
| volumes.add(new V1Volume().name("minio-pvc").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(dataPvcName))); | |||||
| //配置资源 | //配置资源 | ||||
| @@ -10,6 +10,7 @@ public class FrameLogPathVo implements Serializable { | |||||
| String path; | String path; | ||||
| String namespace; | String namespace; | ||||
| String pvcName; | |||||
| public String getPath() { | public String getPath() { | ||||
| return path; | return path; | ||||
| } | } | ||||
| @@ -25,4 +26,12 @@ public class FrameLogPathVo implements Serializable { | |||||
| public void setNamespace(String namespace) { | public void setNamespace(String namespace) { | ||||
| this.namespace = namespace; | this.namespace = namespace; | ||||
| } | } | ||||
| public String getPvcName() { | |||||
| return pvcName; | |||||
| } | |||||
| public void setPvcName(String pvcName) { | |||||
| this.pvcName = pvcName; | |||||
| } | |||||
| } | } | ||||