Browse Source

Merge branch 'dev' into dev-zw

pull/28/head
cp3hnu 1 year ago
parent
commit
b3f1521e24
9 changed files with 121 additions and 59 deletions
  1. +1
    -1
      react-ui/src/components/RightContent/index.tsx
  2. +5
    -6
      react-ui/src/pages/Dataset/index.less
  3. +4
    -4
      react-ui/src/pages/Model/index.less
  4. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java
  5. +20
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java
  6. +55
    -33
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java
  7. +8
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
  8. +11
    -9
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java
  9. +15
    -2
      ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml

+ 1
- 1
react-ui/src/components/RightContent/index.tsx View File

@@ -50,7 +50,7 @@ const GlobalHeaderRight: React.FC = () => {
<QuestionCircleOutlined />
</span>
<Avatar menu={true} />
<SelectLang className={actionClassName} />
{/* <SelectLang className={actionClassName} /> */}
</div>
);
};


+ 5
- 6
react-ui/src/pages/Dataset/index.less View File

@@ -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{


+ 4
- 4
react-ui/src/pages/Model/index.less View File

@@ -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{


+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java View File

@@ -80,5 +80,7 @@ public interface ImageDao {
int deleteById(Integer id);

List<Image> queryByName(String name);

Image getByName(String name);
}


+ 20
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java View File

@@ -26,6 +26,20 @@ public interface ImageService {
*/
Image queryById(Integer id);


Page<Image> 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<Image> queryByName(String name);

String insertImageAndVersion(ImageVo imageVo) throws Exception;

@@ -77,4 +93,6 @@ public interface ImageService {
Map<String, String> createImageFromNet(String imageName, String imageTag, String NetPath) throws Exception;
Map<String, String> uploadImageFiles(MultipartFile file) throws Exception;



}

+ 55
- 33
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java View File

@@ -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;


+ 8
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java View File

@@ -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("容器执行命令异常");
}
}



+ 11
- 9
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java View File

@@ -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;


+ 15
- 2
ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml View File

@@ -26,7 +26,7 @@
<select id="queryAllByLimit" resultMap="ImageMap">
select
img.id, img.name, img.description, img.image_type, img.create_by, img.create_time, img.update_by, img.update_time, img.state,
(SELECT COUNT(*) FROM image_version WHERE image_version.image_id = img.id) as versionCount
(SELECT COUNT(*) FROM image_version WHERE image_version.image_id = img.id and image_version.state = 1) as versionCount
from image img
<where>
img.state = 1
@@ -75,6 +75,18 @@
</where>
</select>

<select id="getByName" resultMap="ImageMap">
select
id, name, description, image_type, create_by, create_time, update_by, update_time, state
from image
<where>
state = 1
<if test="name != null and name != ''">
and name = #{name}
</if>
</where>
</select>


<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
@@ -111,6 +123,7 @@
</if>
</where>
</select>

<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
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
<if test="image.updateTime != null">
update_time = #{image.updateTime},
</if>
<if test="image.state != null and image.state != ''">
<if test="image.state != null">
state = #{image.state},
</if>
</set>


Loading…
Cancel
Save