in api/key.go [62:95]
func (ozoneClient *OzoneClient) GetKey(volume string, bucket string, key string, destination io.Writer) (common.Key, error) {
keyInfo, err := ozoneClient.OmClient.GetKey(volume, bucket, key)
if err != nil {
return common.Key{}, err
}
if len(keyInfo.KeyLocationList) == 0 {
return common.Key{}, errors.New("Get key returned with zero key location version " + volume + "/" + bucket + "/" + key)
}
if len(keyInfo.KeyLocationList[0].KeyLocations) == 0 {
return common.Key{}, errors.New("Key location doesn't have any datanode for key " + volume + "/" + bucket + "/" + key)
}
for _, location := range keyInfo.KeyLocationList[0].KeyLocations {
pipeline := location.Pipeline
dnBlockId := ConvertBlockId(location.BlockID)
dnClient, err := datanode.CreateDatanodeClient(pipeline)
chunks, err := dnClient.GetBlock(dnBlockId)
if err != nil {
return common.Key{}, err
}
for _, chunk := range chunks {
data, err := dnClient.ReadChunk(dnBlockId, chunk)
if err != nil {
return common.Key{}, err
}
destination.Write(data)
}
dnClient.Close()
}
return common.Key{}, nil
}