This topic describes how to use Object Storage Service (OSS) SDK for Go to manage resource pool quality of service (QoS).
Usage notes
The sample code in this topic uses the region ID
cn-hangzhou
of the China (Hangzhou) region. By default, a public endpoint is used to access resources in a bucket. If you want to access resources in the bucket by using other Alibaba Cloud services in the same region in which the bucket is located, use an internal endpoint. For more information about OSS regions and endpoints, see Regions and endpoints.
Bucket bandwidth management
Configure throttling rules for a bucket in a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func PutBucketQoSInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the bucket.
bucketName := "hz-rp-test-01"
// Read the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, display the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash value of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutBucketQoSInfo", // The name of the operation.
Method: "PUT", // The type of the HTTP method.
Parameters: map[string]string{
"qosInfo": "", // The QoS-related parameters.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // The MD5 verification code of the request body, which is used to verify data integrity.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configurations.
Bucket: oss.Ptr(bucketName), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of PutBucketQoSInfo:", res.Status)
}
Query the throttling configurations of a bucket
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func GetBucketQoSInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the bucket.
bucketName := "hz-rp-test-01"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetBucketQoSInfo", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{
"qosInfo": "", // The QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: oss.Ptr(bucketName), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of GetBucketQoSInfo:", string(body))
}
Delete the throttling configurations of a bucket in a resource pool
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func DeleteBucketQoSInfo() {
// Specify the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the bucket.
bucketName := "hz-rp-test-01"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteBucketQoSInfo", // The name of the operation.
Method: "DELETE", // The type of the HTTP method.
Parameters: map[string]string{
"qosInfo": "", // The QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for DELETE requests.
Bucket: oss.Ptr(bucketName), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of DeleteBucketQoSInfo:", res.Status)
}
Bucket-level bandwidth management for different requesters
Configure throttling rules for a requester accessing a bucket
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func PutBucketRequesterQoSInfo() {
// Specify the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the bucket and the ID of the request.
bucketName := "hz-rp-test-01"
requester := "25987322222222222"
// Read the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, display the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash value of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutBucketRequesterQoSInfo", // The operation name must match the actual operation.
Method: "PUT", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS-related parameters.
"qosRequester": requester, // The ID of the requester.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // The MD5 verification code of the request body, which is used to verify data integrity.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configurations.
Bucket: oss.Ptr(bucketName), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of PutBucketRequesterQoSInfo:", res.Status)
}
Query the throttling configurations of a requester accessing a bucket
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func GetBucketRequesterQoSInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the bucket and the ID of the request.
bucketName := "hz-rp-test-01"
requester := "25987322222222222"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetBucketRequesterQoSInfo", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS-related parameters.
"qosRequester": requester, // The ID of the requester.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: oss.Ptr(bucketName), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of GetBucketRequesterQoSInfo:", string(body))
}
Query the throttling configurations of all requesters accessing a bucket
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func ListBucketRequesterQoSInfos() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the bucket.
bucketName := "hz-rp-test-01"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListBucketRequesterQoSInfos", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS related parameters.
// The optional parameters.
// "continuation-token": "259873111111111111", // The token that is used to obtain results in pages.
// "max-keys": "1", // The maximum number of entries returned each time.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: oss.Ptr(bucketName), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of ListBucketRequesterQoSInfos:", string(body))
}
Delete the throttling configurations of a requester accessing a bucket
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func DeleteBucketRequesterQoSInfo() {
// Specify the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the bucket and the ID of the request.
bucketName := "hz-rp-test-01"
requester := "203331xxxx0434633"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteBucketRequesterQoSInfo", // The name of the operation.
Method: "DELETE", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS-related parameters.
"qosRequester": requester, // The ID of the requester.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for DELETE requests.
Bucket: oss.Ptr(bucketName), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of DeleteBucketRequesterQoSInfo:", res.Status)
}
Resource pool-level bandwidth management for different requesters
List all resource pools in the current Alibaba Cloud account
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func ListResourcePools() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePools", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{
"resourcePool": "", // The resource pool parameters.
// The optional parameters.
// "continuation-token": "hz-rp-01", // The token that is used to obtain results in pages.
// "max-keys": "1", // The maximum number of entries returned each time.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: nil, // This operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of ListResourcePools:", string(body))
}
Query the information about a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func GetResourcePoolInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolInfo", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{
"resourcePoolInfo": "", // The resource pool parameters.
"resourcePool": "hz-rp-01", // The name of the resource pool whose information you want to query.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: nil, // This operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of GetResourcePoolInfo:", string(body))
}
Query the buckets in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func ListResourcePoolBuckets() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolBucketGroups", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{ // The parameters.
"resourcePool": "hz-rp-01", // The name of the resource pool.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body.
Bucket: nil, // The name of the bucket, which is empty. The operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of ListResourcePoolBucketGroups:", string(body))
}
Configure bandwidth throttling rules for a requester in a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func PutResourcePoolRequesterQoSInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the resource pool and the ID of the request.
resourcePool := "hz-rp-01"
requester := "25987333333333333"
// Read the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, display the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash value of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutResourcePoolRequesterQoSInfo", // The name of the operation.
Method: "PUT", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS-related parameters.
"resourcePool": resourcePool, // The name of the resource pool.
"qosRequester": requester, // The ID of the requester.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // The MD5 verification code of the request body, which is used to verify data integrity.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configurations.
Bucket: nil, // This operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of PutResourcePoolRequesterQoSInfo:", res.Status)
}
Query the throttling configurations of a requester in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func GetResourcePoolRequesterQoSInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the resource pool and the ID of the request.
resourcePool := "hz-rp-01"
requester := "25987322222222222"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolRequesterQoSInfo", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS-related parameters.
"resourcePool": resourcePool, // The name of the resource pool.
"qosRequester": requester, // The ID of the requester.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: nil, // This operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of GetResourcePoolRequesterQoSInfo:", string(body))
}
Query the throttling configurations of all requesters in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func ListResourcePoolRequesterQoSInfos() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// The name of the resource pool.
resourcePool := "hz-rp-01"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolRequesterQoSInfos", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS-related parameters.
"resourcePool": resourcePool, // The name of the resource pool.
// The optional parameters.
// "continuation-token": "259873111111111111", // The token that is used to obtain results in pages.
// "max-keys": "1", // The maximum number of entries returned each time.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: nil, // This operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of ListResourcePoolRequesterQoSInfos:", string(body))
}
Delete the throttling configurations of a requester in a resource pool
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func DeleteResourcePoolRequesterQoSInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the resource pool and the ID of the request.
resourcePool := "hz-rp-01"
requester := "25987322222222222"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteResourcePoolRequesterQoSInfo", // The name of the operation.
Method: "DELETE", // The type of the HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // The QoS-related parameters.
"resourcePool": resourcePool, // The name of the resource pool.
"qosRequester": requester, // The ID of the requester.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for DELETE requests.
Bucket: nil, // This operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of DeleteResourcePoolRequesterQoSInfo:", res.Status)
}
Bandwidth management for a bucket group
Add buckets in a resource pool to a bucket group
package main
import (
"context"
"fmt"
"io"
"os"
"strings"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// Call the PutBucketResourcePoolBucketGroup function to add a bucket to a bucket group.
func PutBucketResourcePoolBucketGroup() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutBucketResourcePoolBucketGroup", // The name of the operation.
Method: "PUT", // The type of the HTTP method.
Parameters: map[string]string{ // The parameters.
"resourcePoolBucketGroup": "test-group", // The name of the bucket group in the resource pool.
"resourcePool": "resource-pool-for-ai", // The name of the resource pool.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body.
Bucket: oss.Ptr("test-bucket"), // The name of the bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
var body []byte
if b, ok := res.Body.(io.Reader); ok {
buf := new(strings.Builder)
_, _ = io.Copy(buf, b)
body = []byte(buf.String())
} else {
body = []byte(fmt.Sprintf("%v", res.Body))
}
// Display the results.
fmt.Println("The result of PutBucketResourcePoolBucketGroup:", string(body))
}
Query bucket groups in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// Call the ListResourcePoolBucketGroups function to list bucket groups in a resource pool.
func ListResourcePoolBucketGroups() {
// Specify the region. In this example, cn-hangzhou is used.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolBucketGroups", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{ // The parameters.
"resourcePool": "hz-rp-01", // The name of the resource pool.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body.
Bucket: nil, // The name of the bucket, which is empty. The operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of ListResourcePoolBucketGroups:", string(body))
}
Modify the throttling configurations of a bucket group in a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func PutResourcePoolBucketGroupQosInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the resource pool and the name of the bucket group.
resourcePool := "hz-rp-01"
group := "test-grp"
// Read the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, display the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash value of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutResourcePoolBucketGroupQoSInfo", // The name of the operation.
Method: "PUT", // The type of the HTTP method.
Parameters: map[string]string{ // The parameters.
"resourcePool": resourcePool, //The name of the resource pool.
"resourcePoolBucketGroup": group, // The name of the resource pool.
"resourcePoolBucketGroupQosInfo": "", // The QoS-related parameters.
},
Headers: map[string]string{ // The HTTP headers.
"Content-MD5": calcMd5(qosConf), // The MD5 verification code of the request body, which is used to verify data integrity.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configurations.
Bucket: nil, // The name of the bucket. This header is empty because this operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of PutResourcePoolBucketGroupQoSInfo:", res.Status)
}
Query the throttling configurations of a bucket group in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// Call the GetResourcePoolBucketGroupQosInfo function to query the throttling configurations of a bucket group in a resource pool.
func GetResourcePoolBucketGroupQosInfo() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the resource pool and the name of the bucket group.
resourcePool := "hz-rp-01"
ResourcePoolBucketGroup := "test-grp"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolBucketGroupQoSInfo", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{ // The parameters.
"resourcePool": resourcePool, //The name of the resource pool.
"resourcePoolBucketGroup": ResourcePoolBucketGroup, // The name of the bucket group.
"resourcePoolBucketGroupQoSInfo": "", // The QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: nil, // The name of the bucket, which is empty. The operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of GetResourcePoolBucketGroupQoSInfo:", string(body))
}
List the throttling configurations of bucket groups in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// Call the ListResourcePoolBucketGroupQosInfos function to list the throttling configurations of bucket groups in a resource pool.
func ListResourcePoolBucketGroupQosInfos() {
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// The name of the resource pool.
resourcePool := "hz-rp-01"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolBucketGroupQoSInfos", // The name of the operation.
Method: "GET", // The type of the HTTP method.
Parameters: map[string]string{ // The parameters.
"resourcePool": resourcePool, // The name of the resource pool.
// The optional parameters.
// "continuation-token": "259873111111111111", // The token that is used to obtain results in pages.
// "max-keys": "1", // The maximum number of entries that can be returned.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for GET requests.
Bucket: nil, // The name of the bucket, which is empty. The operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, display the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body and make sure that resources are released as expected.
if res.Body != nil {
res.Body.Close()
}
// Display the results.
fmt.Println("The result of ListResourcePoolBucketGroupQoSInfos:", string(body))
}
Delete the throttling configurations of a bucket group in a resource pool
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// Call the DeleteResourcePoolBucketGroupQosInfo function to delete the throttling configurations of a bucket group in a resource pool.
func DeleteResourcePoolBucketGroupQosInfo() {
// Specify the region. In this example, cn-hangzhou is used.
var region = "cn-hangzhou"
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSSClient instance.
client := oss.NewClient(cfg)
// Specify the name of the resource pool and the name of the bucket group.
resourcePool := "hz-rp-01"
group := "test-grp"
// Specify input parameters for the operation, including the operation name, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteResourcePoolBucketGroupQoSInfo", // The name of the operation.
Method: "DELETE", // The type of the HTTP method.
Parameters: map[string]string{ // The parameters.
"resourcePool": resourcePool, //The name of the resource pool.
"resourcePoolBucketGroup": group, // The name of the bucket group.
"resourcePoolBucketGroupQoSInfo": "", // The QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body, which is not required for DELETE requests.
Bucket: nil, // The name of the bucket, which is empty. The operation is not performed on a specific bucket.
}
// Send the request and obtain the response or error message.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, display the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Display the results.
fmt.Println("The result of DeleteResourcePoolBucketGroupQoSInfo:", res.Status)
}
References
For more information about the API operations related to resource pool QoS, see Operations related to the resource pool QoS.
For more information about how to configure bandwidth throttling for buckets and requesters, see Examples of resource pool QoS configuration.