Skip to content

Fix DS & Add Retry #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion powerflex/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
func GetFirstSystem(rc *goscaleio.Client) (*goscaleio.System, error) {
allSystems, err := rc.GetSystems()
if err != nil {
return nil, fmt.Errorf("Error in goscaleio GetSystems")
return nil, fmt.Errorf("Error in goscaleio GetSystems %s", err.Error())
}
if numSys := len((allSystems)); numSys == 0 {
return nil, fmt.Errorf("no systems found")
Expand Down
62 changes: 42 additions & 20 deletions powerflex/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"
"os"
"strconv"
"strings"
"time"

"github.com/dell/goscaleio"
"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand Down Expand Up @@ -102,7 +104,7 @@ func (p *powerflexProvider) Schema(_ context.Context, _ provider.SchemaRequest,
// Configure - provider pre-initiate calle function.
func (p *powerflexProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
tflog.Info(ctx, "Configuring powerflex client")

retryEOFCounter := 5
var config powerflexProviderModel
var timeout int
diags := req.Config.Get(ctx, &config)
Expand Down Expand Up @@ -233,30 +235,50 @@ func (p *powerflexProvider) Configure(ctx context.Context, req provider.Configur
goscaleioConf.Password = password
goscaleioConf.Insecure = insecure

// Create a new PowerFlex gateway client using the configuration values
gatewayClient, err := goscaleio.NewGateway(goscaleioConf.Endpoint, goscaleioConf.Username, goscaleioConf.Password, goscaleioConf.Insecure, true)
if err != nil {
resp.Diagnostics.AddError(
"Unable to Create gateway API Client",
"An unexpected error occurred when creating the gateway API client. "+
"If the error is not clear, please contact the provider developers.\n\n"+
"gateway Client Error: "+err.Error(),
)
return
}

p.gatewayClient = gatewayClient
for i := 0; i < retryEOFCounter; i++ {
// Create a new PowerFlex gateway client using the configuration values
gatewayClient, err := goscaleio.NewGateway(goscaleioConf.Endpoint, goscaleioConf.Username, goscaleioConf.Password, goscaleioConf.Insecure, true)
if err != nil {
// Sometimes the Powerflex Gateway gets inidated with requests
// In these cases just wait 5 seconds and try again
// We will retry up to 5 times before just failing
if strings.Contains(err.Error(), "EOF") {
time.Sleep(2 * time.Second)
continue
}
resp.Diagnostics.AddError(
"Unable to Create gateway API Client",
"An unexpected error occurred when creating the gateway API client. "+
"If the error is not clear, please contact the provider developers.\n\n"+
"gateway Client Error: "+err.Error(),
)
return
}

_, err = Client.Authenticate(&goscaleioConf)
p.gatewayClient = gatewayClient
break
}

if err != nil {
for i := 0; i < retryEOFCounter; i++ {
// Create a new PowerFlex gateway client using the configuration values
_, err = Client.Authenticate(&goscaleioConf)

p.clientError = "An unexpected error occurred when authenticating the Goscaleio API Client. " +
"Unable to Authenticate Goscaleio API Client.\n\n" +
"powerflex Client Error: " + err.Error()
if err != nil {
// Sometimes the Powerflex Gateway gets inidated with request
// In these cases just wait 2 seconds and try again
// We will retry up to 5 times before just failing
if strings.Contains(err.Error(), "EOF") {
time.Sleep(2 * time.Second)
continue
}
p.clientError = "An unexpected error occurred when authenticating the Goscaleio API Client. " +
"Unable to Authenticate Goscaleio API Client.\n\n" +
"powerflex Client Error: " + err.Error()
return
}

} else {
p.client = Client
break
}

resp.DataSourceData = p
Expand Down
21 changes: 13 additions & 8 deletions powerflex/provider/sdc_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package provider

import (
"context"
"strings"

"terraform-provider-powerflex/powerflex/helper"
"terraform-provider-powerflex/powerflex/models"
Expand Down Expand Up @@ -96,16 +97,20 @@ func (d *sdcDataSource) Read(ctx context.Context, req datasource.ReadRequest, re
)
return
}

// SDC endpoints returns both SDC and NVMe host. Need to filter out NVMe host
n := 0
for _, sdc := range sdcs {
if sdc.HostType == "SdcHost" {
sdcs[n] = sdc
n++
tflog.Info(ctx, "system Version"+system.System.SystemVersionName)

// If it is < 4_0 there is no NVME/HostType value so we should skip this filter
if !strings.Contains(system.System.SystemVersionName, "3_6") {
// SDC endpoints returns both SDC and NVMe host. Need to filter out NVMe host
n := 0
for _, sdc := range sdcs {
if sdc.HostType == "SdcHost" {
sdcs[n] = sdc
n++
}
}
sdcs = sdcs[:n]
}
sdcs = sdcs[:n]

// Set state
searchFilter := helper.SdcFilterType.All
Expand Down
Loading