Skip to content

Commit

Permalink
feat(GaussDB): gaussdb mysql proxy support version (#5263)
Browse files Browse the repository at this point in the history
  • Loading branch information
houpeng80 authored Jul 23, 2024
1 parent a92cadb commit 938ec83
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/resources/gaussdb_mysql_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ In addition to all arguments above, the following attributes are exported:
* `nodes` - Indicates the node information of the proxy.
The [nodes](#nodes_struct) structure is documented below.

* `current_version` - Indicates the current version of the proxy.

* `can_upgrade` - Indicates whether the proxy can be upgrade.

<a name="nodes_struct"></a>
The `nodes` block supports:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ func TestAccGaussDBMySQLProxy_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "parameters.0.value", "Loose"),
resource.TestCheckResourceAttr(resourceName, "parameters.0.elem_type", "system"),
resource.TestCheckResourceAttr(resourceName, "consistence_mode", "session"),
resource.TestCheckResourceAttrSet(resourceName, "address"),
resource.TestCheckResourceAttrSet(resourceName, "current_version"),
resource.TestCheckResourceAttrSet(resourceName, "can_upgrade"),
resource.TestCheckResourceAttrSet(resourceName, "nodes.#"),
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.id"),
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.status"),
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.name"),
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.role"),
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.az_code"),
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.frozen_flag"),
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
// @API GaussDBforMySQL POST /v3/{project_id}/instances/{instance_id}/proxy/transaction-split
// @API GaussDBforMySQL PUT /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/session-consistence
// @API GaussDBforMySQL GET /v3/{project_id}/instances/{instance_id}/proxies
// @API GaussDBforMySQL GET /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/{engine_name}/proxy-version
// @API GaussDBforMySQL GET /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/configurations
// @API GaussDBforMySQL DELETE /v3/{project_id}/instances/{instance_id}/proxy
func ResourceGaussDBProxy() *schema.Resource {
Expand Down Expand Up @@ -163,6 +164,14 @@ func ResourceGaussDBProxy() *schema.Resource {
Computed: true,
Elem: gaussDBMysqlProxyNodeSchema(),
},
"current_version": {
Type: schema.TypeString,
Computed: true,
},
"can_upgrade": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -380,6 +389,16 @@ func resourceGaussDBProxyRead(_ context.Context, d *schema.ResourceData, meta in
mErr = multierror.Append(d.Set("parameters", parameters))
}

version, err := getGaussDBProxyVersion(d, client)
if err != nil {
log.Printf("[WARN] fetching GaussDB MySQL proxy version failed: %s", err)
} else {
mErr = multierror.Append(
d.Set("current_version", utils.PathSearch("current_version", version, nil)),
d.Set("can_upgrade", utils.PathSearch("can_upgrade", version, nil)),
)
}

return diag.FromErr(mErr.ErrorOrNil())
}

Expand Down Expand Up @@ -503,6 +522,29 @@ func getGaussDBProxyParameters(d *schema.ResourceData, client *golangsdk.Service
return flattenGaussDBProxyParameters(listRespBody, d), nil
}

func getGaussDBProxyVersion(d *schema.ResourceData, client *golangsdk.ServiceClient) (interface{}, error) {
var (
httpUrl = "v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/{engine_name}/proxy-version"
)

getPath := client.Endpoint + httpUrl
getPath = strings.ReplaceAll(getPath, "{project_id}", client.ProjectID)
getPath = strings.ReplaceAll(getPath, "{instance_id}", d.Get("instance_id").(string))
getPath = strings.ReplaceAll(getPath, "{proxy_id}", d.Id())
getPath = strings.ReplaceAll(getPath, "{engine_name}", "taurusproxy")

getOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
MoreHeaders: map[string]string{"Content-Type": "application/json"},
}
getResp, err := client.Request("GET", getPath, &getOpt)
if err != nil {
return nil, err
}

return utils.FlattenResponse(getResp)
}

func flattenGaussDBProxyParameters(resp interface{}, d *schema.ResourceData) []interface{} {
if resp == nil {
return nil
Expand Down

0 comments on commit 938ec83

Please sign in to comment.