Commit cde9d2d8 authored by Artyom Kartasov's avatar Artyom Kartasov

fix: rename clone diff size field, remove pointers from clone fields (#122)

parent ff15218e
Pipeline #138149258 passed with stages
in 6 minutes and 1 second
......@@ -95,7 +95,7 @@ func (c *Client) CreateClone(ctx context.Context, cloneRequest types.CloneCreate
return nil, errors.Wrap(err, "failed to decode a response body")
}
if clone.Status == nil {
if clone.Status.Code == "" {
return nil, errors.New("empty clone status given")
}
......@@ -139,7 +139,7 @@ func (c *Client) watchCloneStatus(ctx context.Context, cloneID string, initialSt
return nil, errors.Wrap(err, "failed to get clone info")
}
if clone.Status != nil && clone.Status.Code != initialStatusCode {
if clone.Status.Code != initialStatusCode {
return clone, nil
}
......@@ -232,7 +232,7 @@ func (c *Client) ResetClone(ctx context.Context, cloneID string) error {
return errors.Wrap(err, "failed to watch the clone status")
}
if clone.Status != nil && clone.Status.Code == models.StatusOK {
if clone.Status.Code == models.StatusOK {
return nil
}
......
......@@ -20,18 +20,18 @@ import (
func TestClientListClones(t *testing.T) {
expectedClones := []*models.Clone{{
ID: "testCloneID",
Metadata: &models.CloneMetadata{
CloneSize: 450,
CloningTime: 1,
Metadata: models.CloneMetadata{
CloneDiffSize: 450,
CloningTime: 1,
},
Protected: true,
DeleteAt: "2020-01-10 00:00:05.000 UTC",
CreatedAt: "2020-01-10 00:00:00.000 UTC",
Status: &models.Status{
Status: models.Status{
Code: "OK",
Message: "Instance is ready",
},
DB: &models.Database{
DB: models.Database{
Username: "john",
Password: "doe",
},
......@@ -94,18 +94,18 @@ func TestClientListClonesWithFailedRequest(t *testing.T) {
func TestClientCreateClone(t *testing.T) {
expectedClone := models.Clone{
ID: "testCloneID",
Metadata: &models.CloneMetadata{
CloneSize: 450,
CloningTime: 1,
Metadata: models.CloneMetadata{
CloneDiffSize: 450,
CloningTime: 1,
},
Protected: true,
DeleteAt: "2020-01-10 00:00:05.000 UTC",
CreatedAt: "2020-01-10 00:00:00.000 UTC",
Status: &models.Status{
Status: models.Status{
Code: "OK",
Message: "Clone is ready",
},
DB: &models.Database{
DB: models.Database{
Username: "john",
Password: "doe",
},
......@@ -127,7 +127,7 @@ func TestClientCreateClone(t *testing.T) {
err = json.Unmarshal(requestBody, &cloneRequest)
require.NoError(t, err)
clone = expectedClone
clone.Status = &models.Status{
clone.Status = models.Status{
Code: models.StatusCreating,
Message: models.CloneMessageCreating,
}
......@@ -174,18 +174,18 @@ func TestClientCreateClone(t *testing.T) {
func TestClientCreateCloneAsync(t *testing.T) {
expectedClone := models.Clone{
ID: "testCloneID",
Metadata: &models.CloneMetadata{
CloneSize: 450,
CloningTime: 1,
Metadata: models.CloneMetadata{
CloneDiffSize: 450,
CloningTime: 1,
},
Protected: true,
DeleteAt: "2020-01-10 00:00:05.000 UTC",
CreatedAt: "2020-01-10 00:00:00.000 UTC",
Status: &models.Status{
Status: models.Status{
Code: "OK",
Message: "Clone is ready",
},
DB: &models.Database{
DB: models.Database{
Username: "john",
Password: "doe",
},
......@@ -267,18 +267,18 @@ func TestClientCreateCloneWithFailedRequest(t *testing.T) {
func TestClientGetClone(t *testing.T) {
expectedClone := &models.Clone{
ID: "testCloneID",
Metadata: &models.CloneMetadata{
CloneSize: 450,
CloningTime: 1,
Metadata: models.CloneMetadata{
CloneDiffSize: 450,
CloningTime: 1,
},
Protected: true,
DeleteAt: "2020-01-10 00:00:05.000 UTC",
CreatedAt: "2020-01-10 00:00:00.000 UTC",
Status: &models.Status{
Status: models.Status{
Code: "OK",
Message: "Instance is ready",
},
DB: &models.Database{
DB: models.Database{
Username: "john",
Password: "doe",
},
......@@ -341,18 +341,18 @@ func TestClientGetCloneWithFailedRequest(t *testing.T) {
func TestClientUpdateClone(t *testing.T) {
cloneModel := &models.Clone{
ID: "testCloneID",
Metadata: &models.CloneMetadata{
CloneSize: 450,
CloningTime: 1,
Metadata: models.CloneMetadata{
CloneDiffSize: 450,
CloningTime: 1,
},
Protected: true,
DeleteAt: "2020-01-10 00:00:05.000 UTC",
CreatedAt: "2020-01-10 00:00:00.000 UTC",
Status: &models.Status{
Status: models.Status{
Code: "OK",
Message: "Instance is ready",
},
DB: &models.Database{
DB: models.Database{
Username: "john",
Password: "doe",
},
......@@ -549,7 +549,7 @@ func TestClientResetClone(t *testing.T) {
clone := models.Clone{
ID: "testCloneID",
Status: &models.Status{
Status: models.Status{
Code: models.StatusOK,
Message: models.CloneMessageOK,
},
......
......@@ -30,18 +30,18 @@ func TestClientStatus(t *testing.T) {
NumClones: 1,
Clones: []*models.Clone{{
ID: "testCloneID",
Metadata: &models.CloneMetadata{
CloneSize: 45054685181,
CloningTime: 1,
Metadata: models.CloneMetadata{
CloneDiffSize: 45054685181,
CloningTime: 1,
},
Protected: true,
DeleteAt: "2020-01-10 00:00:05.000 UTC",
CreatedAt: "2020-01-10 00:00:00.000 UTC",
Status: &models.Status{
Status: models.Status{
Code: "OK",
Message: "Instance is ready",
},
DB: &models.Database{
DB: models.Database{
Username: "john",
Password: "doe",
},
......
......@@ -6,14 +6,14 @@ package models
// Clone defines a clone model.
type Clone struct {
ID string `json:"id"`
Snapshot *Snapshot `json:"snapshot"`
Protected bool `json:"protected"`
DeleteAt string `json:"deleteAt"`
CreatedAt string `json:"createdAt"`
Status *Status `json:"status"`
DB *Database `json:"db"`
Metadata *CloneMetadata `json:"metadata"`
ID string `json:"id"`
Snapshot *Snapshot `json:"snapshot"`
Protected bool `json:"protected"`
DeleteAt string `json:"deleteAt"`
CreatedAt string `json:"createdAt"`
Status Status `json:"status"`
DB Database `json:"db"`
Metadata CloneMetadata `json:"metadata"`
// TODO(anatoly): Remove?
Project string `json:"project"`
......@@ -21,7 +21,7 @@ type Clone struct {
// CloneMetadata contains fields describing a clone model.
type CloneMetadata struct {
CloneSize uint64 `json:"cloneSize"`
CloneDiffSize uint64 `json:"cloneDiffSize"`
CloningTime float64 `json:"cloningTime"`
MaxIdleMinutes uint `json:"maxIdleMinutes"`
}
......
......@@ -25,8 +25,8 @@ const (
// ModeMock defines a mock mode of cloning.
ModeMock = "mock"
// cloneSize defines a default clone size.
cloneSize = 10
// cloneDiffSize defines a default clone size.
cloneDiffSize = 10
)
// Config contains a cloning configuration.
......
......@@ -117,11 +117,11 @@ func (c *baseCloning) CreateClone(cloneRequest *types.CloneCreateRequest) (*mode
Snapshot: &snapshot,
Protected: cloneRequest.Protected,
CreatedAt: util.FormatTime(createdAt),
Status: &models.Status{
Status: models.Status{
Code: models.StatusCreating,
Message: models.CloneMessageCreating,
},
DB: &models.Database{
DB: models.Database{
Username: cloneRequest.DB.Username,
Password: cloneRequest.DB.Password,
},
......@@ -169,7 +169,7 @@ func (c *baseCloning) CreateClone(cloneRequest *types.CloneCreateRequest) (*mode
w.timeStartedAt = time.Now()
clone := w.clone
clone.Status = &models.Status{
clone.Status = models.Status{
Code: models.StatusOK,
Message: models.CloneMessageOK,
}
......@@ -180,8 +180,8 @@ func (c *baseCloning) CreateClone(cloneRequest *types.CloneCreateRequest) (*mode
clone.DB.Host, clone.DB.Port, clone.DB.Username)
// TODO(anatoly): Remove mock data.
clone.Metadata = &models.CloneMetadata{
CloneSize: cloneSize,
clone.Metadata = models.CloneMetadata{
CloneDiffSize: cloneDiffSize,
CloningTime: w.timeStartedAt.Sub(w.timeCreatedAt).Seconds(),
MaxIdleMinutes: c.Config.MaxIdleMinutes,
}
......@@ -252,7 +252,7 @@ func (c *baseCloning) GetClone(id string) (*models.Clone, error) {
return w.clone, nil
}
w.clone.Metadata.CloneSize = sessionState.CloneSize
w.clone.Metadata.CloneDiffSize = sessionState.CloneDiffSize
return w.clone, nil
}
......@@ -388,7 +388,7 @@ func (c *baseCloning) updateCloneStatus(cloneID string, status models.Status) er
return errors.Errorf("clone %q not found", cloneID)
}
w.clone.Status = &status
w.clone.Status = status
return nil
}
......@@ -420,9 +420,7 @@ func (c *baseCloning) getExpectedCloningTime() float64 {
c.cloneMutex.RLock()
for _, cloneWrapper := range c.clones {
if cloneWrapper.clone.Metadata != nil {
sum += cloneWrapper.clone.Metadata.CloningTime
}
sum += cloneWrapper.clone.Metadata.CloningTime
}
c.cloneMutex.RUnlock()
......
......@@ -48,7 +48,7 @@ func (s *BaseCloningSuite) TestFindWrapper() {
}
func (s *BaseCloningSuite) TestUpdateStatus() {
s.cloning.setWrapper("testCloneID", &CloneWrapper{clone: &models.Clone{Status: &models.Status{
s.cloning.setWrapper("testCloneID", &CloneWrapper{clone: &models.Clone{Status: models.Status{
Code: models.StatusCreating,
Message: models.CloneMessageCreating,
}}})
......@@ -70,7 +70,7 @@ func (s *BaseCloningSuite) TestUpdateStatus() {
assert.Equal(s.T(), models.Status{
Code: models.StatusOK,
Message: models.CloneMessageOK,
}, *wrapper.clone.Status)
}, wrapper.clone.Status)
}
func (s *BaseCloningSuite) TestDeleteClone() {
......
......@@ -52,21 +52,21 @@ const (
// NewMockClone instances a new Clone model.
func NewMockClone() *models.Clone {
db := &models.Database{}
db := models.Database{}
snapshot := &models.Snapshot{}
return &models.Clone{
ID: "id",
Snapshot: snapshot,
Metadata: &models.CloneMetadata{
CloneSize: mockCloneSize,
Metadata: models.CloneMetadata{
CloneDiffSize: mockCloneSize,
CloningTime: mockCloningTime,
MaxIdleMinutes: mockMaxIdleMinutes,
},
Protected: false,
DeleteAt: "10000",
CreatedAt: "10000",
Status: &models.Status{
Status: models.Status{
Code: models.StatusOK,
Message: models.CloneMessageOK,
},
......
......@@ -44,5 +44,5 @@ type Snapshot struct {
// SessionState defines current state of a Session.
type SessionState struct {
CloneSize uint64
CloneDiffSize uint64
}
......@@ -47,7 +47,7 @@ func (m *managerZFS) ListClonesNames() ([]string, error) {
func (m *managerZFS) GetSessionState(name string) (*resources.SessionState, error) {
state := &resources.SessionState{
CloneSize: defaultSessionCloneSize,
CloneDiffSize: defaultSessionCloneSize,
}
entries, err := zfs.ListFilesystems(m.runner, m.config.Pool)
......@@ -70,7 +70,7 @@ func (m *managerZFS) GetSessionState(name string) (*resources.SessionState, erro
return nil, errors.New("cannot get session state: specified ZFS pool does not exist")
}
state.CloneSize = sEntry.Used
state.CloneDiffSize = sEntry.Used
return state, nil
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment