Esempio n. 1
0
func (donut API) mergeMultipart(parts *CompleteMultipartUpload, uploadID string, fullObjectWriter *io.PipeWriter) {
	for _, part := range parts.Part {
		recvMD5 := part.ETag
		object, ok := donut.multiPartObjects[uploadID].Get(part.PartNumber)
		if ok == false {
			fullObjectWriter.CloseWithError(probe.WrapError(probe.NewError(InvalidPart{})))
			return
		}
		calcMD5Bytes := md5.Sum(object)
		// complete multi part request header md5sum per part is hex encoded
		recvMD5Bytes, err := hex.DecodeString(strings.Trim(recvMD5, "\""))
		if err != nil {
			fullObjectWriter.CloseWithError(probe.WrapError(probe.NewError(InvalidDigest{Md5: recvMD5})))
			return
		}
		if !bytes.Equal(recvMD5Bytes, calcMD5Bytes[:]) {
			fullObjectWriter.CloseWithError(probe.WrapError(probe.NewError(BadDigest{})))
			return
		}

		if _, err := io.Copy(fullObjectWriter, bytes.NewReader(object)); err != nil {
			fullObjectWriter.CloseWithError(probe.WrapError(probe.NewError(err)))
			return
		}
		object = nil
	}
	fullObjectWriter.Close()
	return
}
Esempio n. 2
0
func (s *MySuite) TestWrappedError(c *C) {
	_, e := os.Stat("this-file-cannot-exit")
	es := probe.NewError(e) // *probe.Error
	e = probe.WrapError(es) // *probe.WrappedError
	_, ok := probe.UnwrapError(e)
	c.Assert(ok, Equals, true)
}
Esempio n. 3
0
func (s *controllerRPCService) GetServerVersion(r *http.Request, args *ControllerArgs, res *VersionRep) error {
	err := proxyRequest("Server.Version", args.Host, args.SSL, res)
	if err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 4
0
func (s *controllerRPCService) GetServerDiskStats(r *http.Request, args *ControllerArgs, res *DiskStatsRep) error {
	err := proxyRequest("Server.DiskStats", args.Host, args.SSL, res)
	if err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 5
0
// RebalaceStats returns dummy rebalance stats
func (s *controllerRPCService) RebalanceStats(r *http.Request, args *ControllerArgs, reply *RebalanceStatsRep) error {
	err := proxyRequest("Donut.RebalanceStats", args.Host, args.SSL, reply)
	if err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 6
0
func (s *controllerRPCService) AddServer(r *http.Request, args *ControllerArgs, res *ServerRep) error {
	err := proxyRequest("Server.Add", args.Host, args.SSL, res)
	if err != nil {
		return probe.WrapError(err)
	}
	s.serverList = append(s.serverList, *res)
	return nil
}
Esempio n. 7
0
// Reset auth keys, generates new set of auth keys
func (s *controllerRPCService) ResetAuth(r *http.Request, args *AuthArgs, reply *AuthRep) error {
	if strings.TrimSpace(args.User) == "" {
		return errors.New("Invalid argument")
	}
	if err := resetAuth(args, reply); err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 8
0
func (s *controllerRPCService) GetServerVersion(r *http.Request, args *ControllerArgs, res *VersionRep) error {
	for _, host := range args.Hosts {
		err := proxyRequest("Server.Version", host, args.SSL, res)
		if err != nil {
			return probe.WrapError(err)
		}
		return nil
	}
	return errors.New("Invalid argument")
}
Esempio n. 9
0
func (s *serverRPCService) SysInfo(r *http.Request, arg *ServerArg, rep *SysInfoRep) error {
	rep.SysARCH = runtime.GOARCH
	rep.SysOS = runtime.GOOS
	rep.SysCPUS = runtime.NumCPU()
	rep.Routines = runtime.NumGoroutine()
	rep.GOVersion = runtime.Version()
	var err error
	rep.Hostname, err = os.Hostname()
	if err != nil {
		return probe.WrapError(probe.NewError(err))
	}
	return nil
}
Esempio n. 10
0
// readObjectData -
func (b bucket) readObjectData(objectName string, writer *io.PipeWriter, objMetadata ObjectMetadata) {
	readers, err := b.getObjectReaders(objectName, "data")
	if err != nil {
		writer.CloseWithError(probe.WrapError(err))
		return
	}
	for _, reader := range readers {
		defer reader.Close()
	}
	var expected512Sum, expectedMd5sum []byte
	{
		var err error
		expectedMd5sum, err = hex.DecodeString(objMetadata.MD5Sum)
		if err != nil {
			writer.CloseWithError(probe.WrapError(probe.NewError(err)))
			return
		}
		expected512Sum, err = hex.DecodeString(objMetadata.SHA512Sum)
		if err != nil {
			writer.CloseWithError(probe.WrapError(probe.NewError(err)))
			return
		}
	}
	hasher := md5.New()
	sum512hasher := sha256.New()
	mwriter := io.MultiWriter(writer, hasher, sum512hasher)
	switch len(readers) > 1 {
	case true:
		if objMetadata.ErasureTechnique == "" {
			writer.CloseWithError(probe.WrapError(probe.NewError(MissingErasureTechnique{})))
			return
		}
		encoder, err := newEncoder(objMetadata.DataDisks, objMetadata.ParityDisks, objMetadata.ErasureTechnique)
		if err != nil {
			writer.CloseWithError(probe.WrapError(err))
			return
		}
		totalLeft := objMetadata.Size
		for i := 0; i < objMetadata.ChunkCount; i++ {
			decodedData, err := b.decodeEncodedData(totalLeft, int64(objMetadata.BlockSize), readers, encoder, writer)
			if err != nil {
				writer.CloseWithError(probe.WrapError(err))
				return
			}
			if _, err := io.Copy(mwriter, bytes.NewReader(decodedData)); err != nil {
				writer.CloseWithError(probe.WrapError(probe.NewError(err)))
				return
			}
			totalLeft = totalLeft - int64(objMetadata.BlockSize)
		}
	case false:
		_, err := io.Copy(writer, readers[0])
		if err != nil {
			writer.CloseWithError(probe.WrapError(probe.NewError(err)))
			return
		}
	}
	// check if decodedData md5sum matches
	if !bytes.Equal(expectedMd5sum, hasher.Sum(nil)) {
		writer.CloseWithError(probe.WrapError(probe.NewError(ChecksumMismatch{})))
		return
	}
	if !bytes.Equal(expected512Sum, sum512hasher.Sum(nil)) {
		writer.CloseWithError(probe.WrapError(probe.NewError(ChecksumMismatch{})))
		return
	}
	writer.Close()
	return
}
Esempio n. 11
0
// Get method
func (s *MemStatsService) Get(r *http.Request, args *Args, reply *MemStatsReply) error {
	if err := setMemStatsReply(reply); err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 12
0
// Get method
func (s *SysInfoService) Get(r *http.Request, args *Args, reply *SysInfoReply) error {
	if err := setSysInfoReply(reply); err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 13
0
// MakeDonut method
func (s *controllerRPCService) MakeDonut(r *http.Request, args *DonutArgs, reply *DefaultRep) error {
	if err := makeDonut(args, reply); err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 14
0
// Set method
func (s *DonutService) Set(r *http.Request, args *DonutArgs, reply *Reply) error {
	if err := setDonut(args, reply); err != nil {
		return probe.WrapError(err)
	}
	return nil
}
Esempio n. 15
0
File: auth.go Progetto: kahing/minio
// Get auth keys
func (s *AuthService) Get(r *http.Request, args *Args, reply *AuthReply) error {
	if err := getAuth(reply); err != nil {
		return probe.WrapError(err)
	}
	return nil
}