|
@@ -359,30 +359,37 @@ public class ProjectService {
|
|
|
throw new RuntimeException("算法 " + algorithmId + " 的 upload_mode 字段数据有误!");
|
|
|
}
|
|
|
algorithmMapper.updateDockerImportAndDockerImageById("1", dockerImage, algorithmId);
|
|
|
+ LinuxUtil.execute("docker import " + algorithmTarLinuxTempPath + " " + dockerImage);
|
|
|
+ FileUtil.rm(algorithmTarLinuxTempPath);
|
|
|
log.info("ProjectService--handleAlgorithm 已删除算法临时文件:" + algorithmTarLinuxTempPath);
|
|
|
} else {
|
|
|
throw new RuntimeException("算法 " + algorithmId + " 的 mysql 数据有误!");
|
|
|
}
|
|
|
} else { // 从索为算法平台下载算法
|
|
|
log.info("ProjectService--handleAlgorithm 项目" + projectId + "需要从索为平台下载算法 " + algorithmId);
|
|
|
- dockerImage = "algorithm_" + algorithmId + ":latest";
|
|
|
- //查看算法是否已经导入
|
|
|
algorithmTarLinuxTempPath = linuxTempPath + "algorithm/" + algorithmId + ".tar";
|
|
|
- //1 获取 token
|
|
|
- String tokenUrl = algorithmPlatformTokenUri + "?grant_type=client_credential&appid=" + algorithmPlatformAppid + "&secret=" + algorithmPlatformSecret;
|
|
|
- String tokenJson = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
|
|
|
- String token = new ObjectMapper().readTree(tokenJson).path("data").path("access_token").asText();
|
|
|
- //2 获取 下载地址
|
|
|
- String downloadUrl = algorithmPlatformAlgorithmAddrUri + "?access_token=" + token + "&id=" + algorithmId;
|
|
|
- //3 下载算法包
|
|
|
- String downloadUrlJson = HttpUtil.get(closeableHttpClient, requestConfig, downloadUrl);
|
|
|
- String tempDownloadUrl = new ObjectMapper().readTree(downloadUrlJson).path("data").asText();
|
|
|
- InputStream inputStream = HttpUtil.getInputStream(closeableHttpClient, requestConfig, tempDownloadUrl);
|
|
|
- FileUtil.writeInputStreamToLocalFile(inputStream, algorithmTarLinuxTempPath);
|
|
|
+ String dockerImageWithoutVersion = "algorithm_" + algorithmId;
|
|
|
+ dockerImage = dockerImageWithoutVersion + ":latest";
|
|
|
+ //0 查看算法是否已经导入
|
|
|
+ if (!projectUtil.isImported(dockerImageWithoutVersion)) {
|
|
|
+ //1 获取 token
|
|
|
+ String tokenUrl = algorithmPlatformTokenUri + "?grant_type=client_credential&appid=" + algorithmPlatformAppid + "&secret=" + algorithmPlatformSecret;
|
|
|
+ String tokenJson = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
|
|
|
+ String token = new ObjectMapper().readTree(tokenJson).path("data").path("access_token").asText();
|
|
|
+ //2 获取 下载地址
|
|
|
+ String downloadUrl = algorithmPlatformAlgorithmAddrUri + "?access_token=" + token + "&id=" + algorithmId;
|
|
|
+ //3 下载算法包
|
|
|
+ String downloadUrlJson = HttpUtil.get(closeableHttpClient, requestConfig, downloadUrl);
|
|
|
+ String tempDownloadUrl = new ObjectMapper().readTree(downloadUrlJson).path("data").asText();
|
|
|
+ InputStream inputStream = HttpUtil.getInputStream(closeableHttpClient, requestConfig, tempDownloadUrl);
|
|
|
+ FileUtil.writeInputStreamToLocalFile(inputStream, algorithmTarLinuxTempPath);
|
|
|
+ // 本地执行 docker import 算法文件成镜像(可改成用 docker-java 操作仓库)
|
|
|
+ LinuxUtil.execute("docker import " + algorithmTarLinuxTempPath + " " + dockerImage);
|
|
|
+ FileUtil.rm(algorithmTarLinuxTempPath);
|
|
|
+ log.info("ProjectService--handleAlgorithm 已删除算法临时文件:" + algorithmTarLinuxTempPath);
|
|
|
+ }
|
|
|
}
|
|
|
- // 本地执行 docker load 算法文件成镜像(可改成用 docker-java 操作仓库)
|
|
|
- LinuxUtil.execute("docker import " + algorithmTarLinuxTempPath + " " + dockerImage);
|
|
|
- FileUtil.rm(algorithmTarLinuxTempPath);
|
|
|
+
|
|
|
// LinuxUtil.execute("docker tag " + algorithmTarLinuxTempPath + " " + dockerImage); // 标记镜像名称
|
|
|
// LinuxUtil.execute("docker login " + algorithmTarLinuxTempPath + " " + dockerImage); // 登录 harbor
|
|
|
// LinuxUtil.execute("docker push " + algorithmTarLinuxTempPath + " " + dockerImage); // 推送镜像到仓库
|