func UploadFile(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { metaInfo, _, err := uploadFileReadParam(&ctx.Req.Header) if err != nil { log.Error("[OSS][uploadFile] read param error: %v", err) return http.StatusBadRequest, []byte(err.Error()) } data, err := ctx.Req.Body().Bytes() if err != nil { log.Error("[OSS]read request body error: %s", err) return http.StatusBadRequest, []byte(err.Error()) } statusCode, err := ossupload(data, metaInfo) if err != nil { log.Error("[OSS][uploadFile] upload error: %v", err) return statusCode, []byte(err.Error()) } if err = metaDriver.StoreMetaInfoV1(metaInfo); err != nil { log.Error("[OSS]store metaInfo error: %s", err) return http.StatusInternalServerError, []byte(err.Error()) } log.Info("[OSS][postFile] success. path: %s, fragmentIndex: %d, bytesRange: %d-%d, isLast: %v", metaInfo.Path, metaInfo.Value.Index, metaInfo.Value.Start, metaInfo.Value.End, metaInfo.Value.IsLast) return http.StatusOK, nil }
func HeadBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { digest := ctx.Params(":digest") tarsum := strings.Split(digest, ":")[1] ctx.Resp.Header().Set("Content-Type", "application/json; charset=utf-8") i := new(models.Image) if exists, err := i.Get(tarsum); err != nil { log.Info("[REGISTRY API V2] Failed to get tarsum %v: %v", tarsum, err.Error()) result, _ := json.Marshal(map[string]string{"message": "Failed to get tarsum"}) return http.StatusBadRequest, result } else if !exists { log.Info("[REGISTRY API V2] Not found tarsum: %v", tarsum) result, _ := json.Marshal(map[string]string{"message": "Not found tarsum"}) return http.StatusNotFound, result } ctx.Resp.Header().Set("Content-Type", "application/octet-stream") ctx.Resp.Header().Set("Docker-Content-Digest", digest) ctx.Resp.Header().Set("Content-Length", fmt.Sprint(i.Size)) result, _ := json.Marshal(map[string]string{}) return http.StatusOK, result }
func ReceiveChunkserverInfo(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { header := ctx.Req.Header nodeip := header.Get("nodeip") nodeport := header.Get("nodeport") groupid := header.Get("groupid") stderr := header.Get("stderr") stdout := header.Get("stdout") log.Info("[OSS]Chunkserver %s:%s groupid:%s start error", nodeip, nodeport, groupid) log.Info("[OSS]STDOUT:%s", stdout) log.Info("[OSS]STDERR:%s", stderr) return http.StatusOK, []byte("information recieced") }
func DeleteFile(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { path := ctx.Req.Header.Get(headerPath) log.Info("[OSS][deleteFile] path: %s", path) var err error if err = metaDriver.DeleteFileMetaInfoV1(path); err != nil { log.Error("[OSS]delete metainfo error for path: %s, error: %s", path, err) return http.StatusInternalServerError, []byte(err.Error()) } log.Info("[OSS][deleteFile] success. path: %s", path) return http.StatusNoContent, nil }
func HeadBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { digest := ctx.Params(":digest") tarsum := strings.Split(digest, ":")[1] i := new(models.Image) if has, _ := i.HasTarsum(tarsum); has == false { log.Info("[REGISTRY API V2] Tarsum not found: %v", tarsum) result, _ := json.Marshal(map[string]string{"message": "Tarsum not found"}) return http.StatusNotFound, result } ctx.Resp.Header().Set("Content-Type", "application/x-gzip") ctx.Resp.Header().Set("Docker-Content-Digest", digest) ctx.Resp.Header().Set("Content-Length", fmt.Sprint(i.Size)) result, _ := json.Marshal(map[string]string{}) return http.StatusOK, result }
func GetFileInfo(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { path := ctx.Req.Header.Get(headerPath) log.Info("[OSS][getFileInfo] Path: %s", path) result, err := metaDriver.GetFileMetaInfo(path, false) if err != nil { log.Error("[OSS][getFileInfo] get metainfo error, key: %s, error: %s", path, err) return http.StatusInternalServerError, []byte(err.Error()) } if len(result) == 0 { log.Info("[OSS][getFileInfo] metainfo not exists, key: %s", path) return http.StatusNotFound, []byte(err.Error()) } resultMap := make(map[string]interface{}) resultMap["fragment-info"] = result jsonResult, err := json.Marshal(resultMap) if err != nil { log.Error("json.Marshal error, key: %s, error: %s", path, err) return http.StatusInternalServerError, []byte(err.Error()) } log.Info("[getFileInfo] success, path: %s, result: %s", path, string(jsonResult)) return http.StatusOK, jsonResult }
func DownloadFile(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { header := ctx.Req.Header path := header.Get(headerPath) fragmentIndex := header.Get(headerIndex) bytesRange := header.Get(headerRange) start, end, err := splitRange(bytesRange) if err != nil { log.Error("[OSS]splitRange error, bytesRange: %s, error: %s", bytesRange, err) return http.StatusBadRequest, []byte(err.Error()) } index, err := strconv.ParseUint(fragmentIndex, 10, 64) if err != nil { log.Error("[OSS]parser fragmentIndex: %s, error: %s", fragmentIndex, err) return http.StatusBadRequest, []byte(err.Error()) } log.Info("[OSS]path: %s, fragmentIndex: %d, bytesRange: %d-%d", path, index, start, end) metaInfoValue := &meta.MetaInfoValue{ Index: index, Start: start, End: end, } metaInfo := &meta.MetaInfo{Path: path, Value: metaInfoValue} log.Debug("[OSS]metaInfo: %s", metaInfo) chunkServer, err := getOneNormalChunkServer(metaInfo) if err != nil { if err.Error() == "fragment metainfo not found" { return http.StatusNotFound, []byte(err.Error()) } else { return http.StatusInternalServerError, []byte(err.Error()) } } connPools := GetConnectionPools() conn, err := connPools.GetConn(chunkServer) log.Info("downloadFile getconnection success") if err != nil { log.Error("downloadFile getconnection error: %v", err) return http.StatusInternalServerError, []byte(err.Error()) } data, err := chunkServer.GetData(metaInfo.Value, conn.(*chunkserver.PooledConn)) if err != nil { conn.Close() connPools.ReleaseConn(conn) checkErrorAndConnPool(err, chunkServer, connPools) return http.StatusInternalServerError, []byte(err.Error()) } log.Info("[OSS][downloadFile] success. path: %s, fragmentIndex: %d, bytesRange: %d-%d", path, index, start, end) connPools.ReleaseConn(conn) return http.StatusOK, data }