|
|
|
@@ -49,6 +49,7 @@ func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
|
os.Remove(saveFile) |
|
|
|
} |
|
|
|
fs, _ := os.OpenFile(saveFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, os.ModeAppend|os.ModePerm) |
|
|
|
defer fs.Close() |
|
|
|
var wg sync.WaitGroup |
|
|
|
filesCount := len(files) |
|
|
|
if filesCount != len(filesSort) { |
|
|
|
@@ -66,7 +67,6 @@ func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
|
} |
|
|
|
wg.Wait() |
|
|
|
os.RemoveAll(chunksPath) |
|
|
|
defer fs.Close() |
|
|
|
|
|
|
|
// 保存到数据库表里 |
|
|
|
svcCtx.DbEngin.Create(&model.File{ |
|
|
|
@@ -77,17 +77,20 @@ func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
|
Bucket: "pcm"}) |
|
|
|
|
|
|
|
// 根据数据类型按需上传(镜像推送到nexus 数据集和算法推送到云际存储) |
|
|
|
//switch dataType { |
|
|
|
//case "image": |
|
|
|
// pushImage(svcCtx, name) |
|
|
|
//case "dataSet", "algorithm": |
|
|
|
// uploadStorage(svcCtx, name) |
|
|
|
//} |
|
|
|
switch dataType { |
|
|
|
case "image": |
|
|
|
pushImage(svcCtx, name) |
|
|
|
case "dataSet", "algorithm": |
|
|
|
uploadStorage(svcCtx, name) |
|
|
|
} |
|
|
|
|
|
|
|
err := pushImage(svcCtx, name) |
|
|
|
if err != nil { |
|
|
|
result2.HttpResult(r, w, nil, err) |
|
|
|
return |
|
|
|
} |
|
|
|
// 删除本地文件 避免占用本地存储资源 |
|
|
|
err = os.Remove(filepath.Join(uploadPath, name)) |
|
|
|
result2.HttpResult(r, w, nil, err) |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -103,6 +106,7 @@ func uploadStorage(svcCtx *svc.ServiceContext, name string) error { |
|
|
|
func pushImage(svcCtx *svc.ServiceContext, name string) error { |
|
|
|
// 加载镜像文件到docker |
|
|
|
fileInfo, err := os.Open(filepath.Join(uploadPath, name)) |
|
|
|
defer fileInfo.Close() |
|
|
|
reader := bufio.NewReader(fileInfo) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
@@ -111,12 +115,15 @@ func pushImage(svcCtx *svc.ServiceContext, name string) error { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
bytes, err := ioutil.ReadAll(body.Body) |
|
|
|
|
|
|
|
loadBody := LoadBody{} |
|
|
|
err = json.Unmarshal(bytes, &loadBody) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
imageName := strings.TrimSpace(loadBody.Stream[13:]) |
|
|
|
privateImageName := "hub.jcce.dev:18445/" + imageName |
|
|
|
// 给镜像打上私有仓库的tag |
|
|
|
@@ -141,11 +148,6 @@ func pushImage(svcCtx *svc.ServiceContext, name string) error { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
// 删除本地文件 避免占用本地存储资源 |
|
|
|
err = os.Remove(filepath.Join(uploadPath, name)) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
|