示例#1
0
func PutImageChecksumV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	imageId := ctx.Params(":imageId")

	checksum := strings.Split(ctx.Req.Header.Get("X-Docker-Checksum"), ":")[1]
	payload := strings.Split(ctx.Req.Header.Get("X-Docker-Checksum-Payload"), ":")[1]

	log.Debug("[REGISTRY API V1] Image Checksum : %v", checksum)
	log.Debug("[REGISTRY API V1] Image Payload: %v", payload)

	i := new(models.Image)
	if err := i.PutChecksum(imageId, checksum, true, payload); err != nil {
		log.Error("[REGISTRY API V1] Put Image Checksum & Payload Error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Put Image Checksum & Payload Error"})
		return http.StatusBadRequest, result
	}

	if err := i.PutAncestry(imageId); err != nil {
		log.Error("[REGISTRY API V1] Put Image Ancestry Error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Put Image Ancestry Error"})
		return http.StatusBadRequest, result
	}

	result, _ := json.Marshal(map[string]string{})
	return http.StatusOK, result
}
示例#2
0
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
}
示例#3
0
func PutTagV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	tag := ctx.Params(":tag")

	bodystr, _ := ctx.Req.Body().String()
	log.Debug("[REGISTRY API V1] Repository Tag : %v", bodystr)

	r, _ := regexp.Compile(`"([[:alnum:]]+)"`)
	imageIds := r.FindStringSubmatch(bodystr)

	repo := new(models.Repository)
	if err := repo.PutTag(imageIds[1], namespace, repository, tag); err != nil {
		log.Error("[REGISTRY API V1] Put repository tag error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": err.Error()})
		return http.StatusBadRequest, result
	}

	result, _ := json.Marshal(map[string]string{})
	return http.StatusOK, result
}