diff --git a/react-ui/src/components/RightContent/index.tsx b/react-ui/src/components/RightContent/index.tsx index 52a49bbd..c2a4a7bf 100644 --- a/react-ui/src/components/RightContent/index.tsx +++ b/react-ui/src/components/RightContent/index.tsx @@ -50,7 +50,7 @@ const GlobalHeaderRight: React.FC = () => { - + {/* */} ); }; diff --git a/react-ui/src/pages/Dataset/index.less b/react-ui/src/pages/Dataset/index.less index d22c8dbe..2ff0b580 100644 --- a/react-ui/src/pages/Dataset/index.less +++ b/react-ui/src/pages/Dataset/index.less @@ -210,7 +210,6 @@ display: flex; flex: 1; flex-direction: column; - font-family: 'Alibaba'; height: 100%; padding: 22px 30px 26px 30px; background: #ffffff; @@ -229,11 +228,11 @@ flex: 1; flex-wrap: wrap; align-content: flex-start; - font-family: 'Alibaba'; - width: 103%; + + width: 102%; .dataItem { position: relative; - width: 23%; + width: 23.5%; height:164px; background:#ffffff; border:1px solid; @@ -250,7 +249,7 @@ line-height: 0px; color:#1d1d20; font-size:16px; - + font-family: 'Alibaba'; } .itemDescripition{ position: absolute; @@ -286,7 +285,7 @@ } .dataItem:hover{ border-color: #1664FF; - box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2) + box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.1) } .dataItem:hover .itemText{ diff --git a/react-ui/src/pages/Model/index.less b/react-ui/src/pages/Model/index.less index 5bf1cc1b..7bee2701 100644 --- a/react-ui/src/pages/Model/index.less +++ b/react-ui/src/pages/Model/index.less @@ -219,10 +219,10 @@ flex: 1; flex-wrap: wrap; align-content: flex-start; - width: 100%; + width: 102%; .dataItem { position: relative; - width: 23%; + width: 23.5%; height:164px; background:#ffffff; border:1px solid; @@ -239,7 +239,7 @@ line-height: 0px; color:#1d1d20; font-size:16px; - + font-family: 'Alibaba'; } .itemDescripition{ position: absolute; @@ -275,7 +275,7 @@ } .dataItem:hover{ border-color: #1664FF; - box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2) + box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.1) } .dataItem:hover .itemText{ diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java index d0aa74c4..915a2425 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java @@ -80,5 +80,7 @@ public interface ImageDao { int deleteById(Integer id); List queryByName(String name); + + Image getByName(String name); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java index 4e6290dd..59614ac9 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java @@ -26,6 +26,20 @@ public interface ImageService { */ Image queryById(Integer id); + + Page queryByName(String name); + + /** + * 通过名字精确查询单条数据 + * + * @param name 名字 + * @return 实例对象 + */ + + Image getByName(String name); + + + /** * 分页查询 * @@ -59,9 +73,11 @@ public interface ImageService { */ boolean deleteById(Integer id); - String removeById(Integer id); + String removeById(Integer id) throws Exception; + + + - Page queryByName(String name); String insertImageAndVersion(ImageVo imageVo) throws Exception; @@ -77,4 +93,6 @@ public interface ImageService { Map createImageFromNet(String imageName, String imageTag, String NetPath) throws Exception; Map uploadImageFiles(MultipartFile file) throws Exception; + + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java index 831c242f..d7e835f8 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java @@ -88,6 +88,8 @@ public class ImageServiceImpl implements ImageService { return new PageImpl<>(this.imageDao.queryAllByLimit(image, pageRequest), pageRequest, total); } + + /** * 新增数据 * @@ -138,10 +140,10 @@ public class ImageServiceImpl implements ImageService { } @Override - public String removeById(Integer id) { + public String removeById(Integer id) throws Exception { Image image = this.imageDao.queryById(id); if (image == null){ - return "镜像不存在"; + throw new Exception("镜像不存在"); } //判断权限,只有admin和创建者本身可以删除该数据集 @@ -150,11 +152,11 @@ public class ImageServiceImpl implements ImageService { String createdBy = image.getCreateBy(); - if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ - return "无权限删除该镜像"; + if (!(StringUtils.equals(username,"admin") || !StringUtils.equals(username,createdBy))){ + throw new Exception("无权限删除该镜像"); } if (!imageVersionService.queryByImageId(id).isEmpty()){ - return "请先删除该镜像下的版本文件"; + throw new Exception("请先删除该镜像下的版本文件"); } image.setState(0); return this.imageDao.update(image)>0?"删除成功":"删除失败"; @@ -167,27 +169,46 @@ public class ImageServiceImpl implements ImageService { return new PageImpl<>(this.imageDao.queryByName(name)); } + + /** + * 通过名字精确查询镜像 + * + * @param name 名字 + * @return 镜像 + */ + @Override + public Image getByName(String name) { + return this.imageDao.getByName(name); + } + @Override @Transactional public String insertImageAndVersion(ImageVo imageVo) throws Exception { - Image image = new Image(); - image.setName(imageVo.getName()); - image.setDescription(imageVo.getDescription()); - image.setImageType(imageVo.getImageType()); - Image imageInsert = this.insert(image); - if (imageInsert == null){ - throw new Exception("新增镜像失败"); + Image existingImage = getByName(imageVo.getName()); + Image imageToUse; + if(existingImage == null) { + // 如果不存在相同名称的镜像,则创建新的镜像记录 + Image newImage = new Image(); + newImage.setName(imageVo.getName()); + newImage.setDescription(imageVo.getDescription()); + newImage.setImageType(imageVo.getImageType()); + imageToUse = this.insert(newImage); + if (imageToUse == null) { + throw new Exception("新增镜像失败"); + } + }else{ + // 如果已存在相同名称的镜像,使用已存在的镜像 + imageToUse = existingImage; } ImageVersion imageVersion = new ImageVersion(); - imageVersion.setImageId(imageInsert.getId()); + imageVersion.setImageId(imageToUse.getId()); imageVersion.setVersion(imageVo.getVersion()); - imageVersion.setUrl(imageVo.getUrl()); imageVersion.setTagName(imageVo.getTagName()); imageVersion.setFileSize(imageVo.getFileSize()); imageVersion.setStatus("building"); ImageVersion imageVersionInsert = this.imageVersionService.insert(imageVersion); if (imageVersionInsert == null) { - throw new Exception("新增镜像失败"); + throw new Exception("新增镜像版本失败"); } // 使用CompletableFuture异步执行不同的镜像构建逻辑 CompletableFuture.supplyAsync(() -> { @@ -207,7 +228,7 @@ public class ImageServiceImpl implements ImageService { }).thenAccept(resultMap ->{ try { String imageUrl = resultMap.get("url"); - String fileSize = resultMap.get("filesize"); + String fileSize = resultMap.get("fileSize"); imageVersion.setUrl(imageUrl); imageVersion.setFileSize(fileSize); imageVersion.setStatus("available"); @@ -241,18 +262,18 @@ public class ImageServiceImpl implements ImageService { String logs2 = k8sClientUtil.executeCommand(pod,"docker pull "+ netPath); // 在容器里执行 docker tag name:tag nexus3.kube-system.svc:8083/imageName:imageTag if (StringUtils.isNoneBlank(logs2)){ - String substring = logs2.substring(logs2.indexOf(harborUrl), logs2.length()); + String substring = logs2.substring(logs2.lastIndexOf(harborUrl)); String cleanedString = substring.replaceAll("(\\r|\\n)", ""); - String cmd1 = "docker tag " + cleanedString+ " " + harborUrl+"/"+repository+"/"+username+"/" + imageName + imageTag; - String imageUrl = harborUrl+"/"+repository+"/"+username+"/" + imageName + imageTag; - String cmd2 = "docker push " + imageUrl; - String cmd3 = "docker inspect --format='{{.Size}}' " + imageUrl; - - String s = k8sClientUtil.executeCommand(pod, cmd1); - if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, cmd2))){ + String tagCmd = "docker tag " + cleanedString + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; + String imageUrl = harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; + String pushCmd = "docker push " + imageUrl; + String sizeCmd = "docker inspect --format='{{.Size}}' " + imageUrl; + String s = k8sClientUtil.executeCommand(pod, tagCmd); + if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, pushCmd))){ resultMap.put("url", imageUrl); //得到镜像文件大小 - long sizeInBytes = Long.parseLong(k8sClientUtil.executeCommand(pod, cmd3)); + String imageSizeStr = k8sClientUtil.executeCommand(pod, sizeCmd); + long sizeInBytes = Long.parseLong(imageSizeStr.trim()); String formattedImageSize = FileUtil.formatFileSize(sizeInBytes); // 格式化镜像文件大小 resultMap.put("fileSize", formattedImageSize); return resultMap; @@ -283,17 +304,18 @@ public class ImageServiceImpl implements ImageService { String logs2 = k8sClientUtil.executeCommand(pod,"docker load -i "+filePath); // 在容器里执行 docker tag name:tag nexus3.kube-system.svc:8083/imageName:imageTag if (StringUtils.isNoneBlank(logs2)){ - String substring = logs2.substring(logs2.indexOf(harborUrl), logs2.length()); + String substring = logs2.substring(logs2.lastIndexOf(harborUrl)); String cleanedString = substring.replaceAll("(\\r|\\n)", ""); - String cmd1 = "docker tag " + cleanedString+ " " + harborUrl+"/"+repository+"/"+username+"/" + imageName + imageTag; - String imageUrl = harborUrl+"/"+repository+"/"+username+"/" + imageName + imageTag; - String cmd2 = "docker push " + imageUrl; - String cmd3 = "docker inspect --format='{{.Size}}' " + imageUrl; - String s = k8sClientUtil.executeCommand(pod, cmd1); - if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, cmd2))){ + String tagCmd = "docker tag " + cleanedString + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; + String imageUrl = harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; + String pushCmd = "docker push " + imageUrl; + String sizeCmd = "docker inspect --format='{{.Size}}' " + imageUrl; + String s = k8sClientUtil.executeCommand(pod, tagCmd); + if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, pushCmd))){ resultMap.put("url", imageUrl); //得到镜像文件大小 - long sizeInBytes = Long.parseLong(k8sClientUtil.executeCommand(pod, cmd3)); + String imageSizeStr = k8sClientUtil.executeCommand(pod, sizeCmd); + long sizeInBytes = Long.parseLong(imageSizeStr.trim()); String formattedImageSize = FileUtil.formatFileSize(sizeInBytes); // 格式化镜像文件大小 resultMap.put("fileSize", formattedImageSize); return resultMap; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index 58bdabfe..b23b0143 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -406,10 +406,16 @@ public class K8sClientUtil { builder.append(line); builder.append(System.getProperty("line.separator")); } + // 等待进程结束,并获取退出值 + int exitValue = proc.waitFor(); + if (exitValue != 0) { + // 如果进程的退出值不为0,表示命令执行失败 + throw new RuntimeException("容器中命令执行失败,退出值:" + exitValue); + } return builder.toString(); } catch (Exception e) { - log.error("执行命令异常", e); - throw new RuntimeException("执行命令异常"); + log.error("容器执行命令异常", e); + throw new RuntimeException("容器执行命令异常"); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java index 1f6319cf..c4b313c2 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java @@ -33,11 +33,13 @@ public class ImageVo implements Serializable { */ @ApiModelProperty(name = "version") private String version; + /** * 镜像推送地址 */ - @ApiModelProperty(name = "url") - private String url; +// @ApiModelProperty(name = "url") +// private String url; + /** * 镜像tag名称 */ @@ -102,13 +104,13 @@ public class ImageVo implements Serializable { this.version = version; } - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } +// public String getUrl() { +// return url; +// } +// +// public void setUrl(String url) { +// this.url = url; +// } public String getTagName() { return tagName; diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml index c9e80b5f..9b46775f 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml @@ -26,7 +26,7 @@ + + + insert into image(name,description,image_type,create_by,create_time,update_by,update_time,state) @@ -161,7 +174,7 @@ name = values(name)description = values(description)image_type = values(image_ty update_time = #{image.updateTime}, - + state = #{image.state},