Skip to content

Commit

Permalink
Add support for replication on a PowerFlex 4.0 array (#44)
Browse files Browse the repository at this point in the history
* Add support for replication on a PowerFlex 4.0 array

* Handle defer close function
  • Loading branch information
falfaroc authored Feb 10, 2023
1 parent 4484a6d commit 57ee14d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
20 changes: 17 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ func (c *Client) getVersion() (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()

defer func() {
if err := resp.Body.Close(); err != nil {
doLog(log.WithError(err).Error, "")
}
}()

// parse the response
switch {
Expand Down Expand Up @@ -143,7 +148,12 @@ func (c *Client) Authenticate(configConnect *ConfigConnect) (Cluster, error) {
doLog(log.WithError(err).Error, "")
return Cluster{}, err
}
defer resp.Body.Close()

defer func() {
if err := resp.Body.Close(); err != nil {
doLog(log.WithError(err).Error, "")
}
}()

// parse the response
switch {
Expand Down Expand Up @@ -238,7 +248,11 @@ func (c *Client) getStringWithRetry(
addMetaData(headers, body)

checkResponse := func(resp *http.Response) (string, bool, error) {
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
doLog(log.WithError(err).Error, "")
}
}()

// parse the response
switch {
Expand Down
15 changes: 13 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ func (c *client) DoWithHeaders(
if err != nil {
return err
}
defer res.Body.Close()

defer func() {
if err := res.Body.Close(); err != nil {
c.doLog(log.WithError(err).Error, "")
}
}()

// parse the response
switch {
Expand Down Expand Up @@ -319,7 +324,13 @@ func (c *client) DoAndGetResponseBody(
// marshal the message body (assumes json format)
if r, ok := body.(io.ReadCloser); ok {
req, err = http.NewRequest(method, u.String(), r)
defer r.Close()

defer func() {
if err := r.Close(); err != nil {
c.doLog(log.WithError(err).Error, "")
}
}()

if v, ok := headers[HeaderKeyContentType]; ok {
req.Header.Set(HeaderKeyContentType, v)
} else {
Expand Down
2 changes: 1 addition & 1 deletion inttests/init_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func initClient2() bool {
}

C2, err = goscaleio.NewClientWithArgs(
os.Getenv(replicationEnpoint),
endpoint2,
os.Getenv("GOSCALEIO_VERSION"),
math.MaxInt64,
os.Getenv("GOSCALEIO_INSECURE") == "true",
Expand Down
6 changes: 5 additions & 1 deletion inttests/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestGetPeerMDMs(t *testing.T) {

var targetSystemID string
for i := 0; i < len(tgtpeers); i++ {
fmt.Printf("Peer %d, %+v", i, tgtpeers[i])
targetSystemID = tgtpeers[i].SystemID
}

Expand Down Expand Up @@ -131,6 +132,7 @@ func TestGetTargetSystem(t *testing.T) {
}

rep.targetSystem = getTargetSystem()
fmt.Printf("Target: %+v", rep.targetSystem.System)
assert.NotNil(t, rep.targetSystem)
}

Expand Down Expand Up @@ -362,6 +364,7 @@ func TestCreateReplicationConsistencyGroupSnapshot(t *testing.T) {
resp, err := rep.rcg.CreateReplicationConsistencyGroupSnapshot(false)
assert.Nil(t, err)

t.Logf("Consistency Group Snapshot ID: %s", resp.SnapshotGroupID)
rep.snapshotGroupID = resp.SnapshotGroupID
}

Expand Down Expand Up @@ -456,7 +459,7 @@ func TestExecutePauseOnReplicationGroup(t *testing.T) {
err := waitForConsistency(t)
assert.Nil(t, err)

err = rep.rcg.ExecutePauseOnReplicationGroup(siotypes.OnlyTrackChanges)
err = rep.rcg.ExecutePauseOnReplicationGroup()
assert.Nil(t, err)
}

Expand Down Expand Up @@ -622,6 +625,7 @@ func ensureFailover(t *testing.T) error {

if group.FailoverType != "None" && group.FailoverState == "Done" && group.DisasterRecoveryState == "Neutral" && group.RemoteDisasterRecoveryState == "Neutral" {
t.Logf("Consistency Group is in %s", group.FailoverType)
time.Sleep(1 * time.Second)
return nil
}

Expand Down
10 changes: 4 additions & 6 deletions replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,9 @@ func (rcg *ReplicationConsistencyGroup) CreateReplicationConsistencyGroupSnapsho

uri := "/api/instances/ReplicationConsistencyGroup::" + rcg.ReplicationConsistencyGroup.ID + "/action/createReplicationConsistencyGroupSnapshots"
param := &types.CreateReplicationConsistencyGroupSnapshot{
Force: "false",
}
if force {
param.Force = "true"
Force: force,
}

resp := &types.CreateReplicationConsistencyGroupSnapshotResp{}

err := rcg.client.getJSONWithRetry(http.MethodPost, uri, param, resp)
Expand Down Expand Up @@ -286,12 +284,12 @@ func (rcg *ReplicationConsistencyGroup) ExecuteReverseOnReplicationGroup() error
}

// ExecutePauseOnReplicationGroup pauses the replication of the ConsistencyGroup.
func (rcg *ReplicationConsistencyGroup) ExecutePauseOnReplicationGroup(mode types.PauseMode) error {
func (rcg *ReplicationConsistencyGroup) ExecutePauseOnReplicationGroup() error {
defer TimeSpent("ExecutePauseOnReplicationGroup", time.Now())

uri := "/api/instances/ReplicationConsistencyGroup::" + rcg.ReplicationConsistencyGroup.ID + "/action/pauseReplicationConsistencyGroup"
param := types.PauseReplicationConsistencyGroup{
PauseMode: string(mode),
PauseMode: string(types.StopDataTransfer),
}

err := rcg.client.getJSONWithRetry(http.MethodPost, uri, param, nil)
Expand Down
23 changes: 12 additions & 11 deletions types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,16 +824,17 @@ type SnapshotPolicyQueryIDByKeyParam struct {

// PeerMDM defines a replication peer system.
type PeerMDM struct {
ID string `json:"id"`
Name string `json:"name"`
Port int `json:"port"`
PeerSystemID string `json:"peerSystemId"`
SystemID string `json:"systemId"`
SoftwareVersionInfo string `json:"softwareVersionInfo"`
MembershipState string `json:"membershipState"`
PerfProfile string `json:"perfProfile"`
NetworkType string `json:"networkType"`
CouplingRC string `json:"couplingRC"`
ID string `json:"id"`
Name string `json:"name"`
Port int `json:"port"`
PeerSystemID string `json:"peerSystemId"`
SystemID string `json:"systemId"`
SoftwareVersionInfo string `json:"softwareVersionInfo"`
MembershipState string `json:"membershipState"`
PerfProfile string `json:"perfProfile"`
NetworkType string `json:"networkType"`
CouplingRC string `json:"couplingRC"`
IPList []*PeerMDM `json:"ipList"`
}

// ReplicationConsistencyGroup (RCG) has information about a replication session
Expand Down Expand Up @@ -920,7 +921,7 @@ type RemoveReplicationPair struct {

// CreateReplicationConsistencyGroupSnapshot defines struct for CreateReplicationConsistencyGroupSnapshot.
type CreateReplicationConsistencyGroupSnapshot struct {
Force string `json:"force,omitempty"`
Force bool `json:"force,omitempty"`
}

// CreateReplicationConsistencyGroupSnapshotResp defines struct for CreateReplicationConsistencyGroupSnapshotResp.
Expand Down

0 comments on commit 57ee14d

Please sign in to comment.