From 353a857b0225199e5f64eba3d9d85a254a98c5f4 Mon Sep 17 00:00:00 2001 From: wb-xxh498912 Date: Tue, 3 Nov 2020 20:22:48 +0800 Subject: [PATCH] fix comment --- client_etl_job.go | 24 ++++++++++++------------ client_etl_job_test.go | 38 +++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/client_etl_job.go b/client_etl_job.go index 6f1f1167..e3691ac4 100644 --- a/client_etl_job.go +++ b/client_etl_job.go @@ -7,7 +7,7 @@ import ( "time" ) -type ETLJobV2 struct { +type ETL struct { Configuration ETLConfiguration `json:"configuration"` Description string `json:"description"` DisplayName string `json:"displayName"` @@ -15,8 +15,8 @@ type ETLJobV2 struct { Schedule ETLSchedule `json:"schedule"` Type string `json:"type"` Status string `json:"status"` - CreateTime int32 `json:"createTime"` - LastModifiedTime int32 `json:"lastModifiedTime"` + CreateTime int32 `json:"createTime,omitempty"` + LastModifiedTime int32 `json:"lastModifiedTime,omitempty"` } type ETLConfiguration struct { @@ -25,7 +25,7 @@ type ETLConfiguration struct { FromTime int64 `json:"fromTime"` Logstore string `json:"logstore"` Parameters map[string]string `json:"parameters"` - RoleArn string `json:"roleArn"` + RoleArn string `json:"roleArn,omitempty"` Script string `json:"script"` ToTime int32 `json:"toTime"` Version int8 `json:"version"` @@ -43,17 +43,17 @@ type ETLSink struct { Logstore string `json:"logstore"` Name string `json:"name"` Project string `json:"project"` - RoleArn string `json:"roleArn"` + RoleArn string `json:"roleArn,omitempty"` } type ListETLResponse struct { Total int `json:"total"` Count int `json:"count"` - Results []*ETLJobV2 `json:"results"` + Results []*ETL `json:"results"` } -func NewLogETLJobV2(endpoint, accessKeyId, accessKeySecret, logstore, name, project string) ETLJobV2 { +func NewETL(endpoint, accessKeyId, accessKeySecret, logstore, name, project string) ETL { sink := ETLSink{ AccessKeyId:accessKeyId, AccessKeySecret:accessKeySecret, @@ -76,7 +76,7 @@ func NewLogETLJobV2(endpoint, accessKeyId, accessKeySecret, logstore, name, proj schedule := ETLSchedule{ Type:"Resident", } - etljob := ETLJobV2 { + etljob := ETL { Configuration:config, DisplayName:"displayname", Description:"go sdk case", @@ -90,7 +90,7 @@ func NewLogETLJobV2(endpoint, accessKeyId, accessKeySecret, logstore, name, proj -func (c *Client) CreateETL(project string, etljob ETLJobV2) error { +func (c *Client) CreateETL(project string, etljob ETL) error { body, err := json.Marshal(etljob) if err != nil { return NewClientError(err) @@ -109,7 +109,7 @@ func (c *Client) CreateETL(project string, etljob ETLJobV2) error { return nil } -func (c *Client) GetETL(project string, etlName string) (ETLJob *ETLJobV2, err error) { +func (c *Client) GetETL(project string, etlName string) (ETLJob *ETL, err error) { h := map[string]string{ "x-log-bodyrawsize": "0", "Content-Type": "application/json", @@ -121,14 +121,14 @@ func (c *Client) GetETL(project string, etlName string) (ETLJob *ETLJobV2, err e } defer r.Body.Close() buf, _ := ioutil.ReadAll(r.Body) - etlJob := &ETLJobV2{} + etlJob := &ETL{} if err = json.Unmarshal(buf, etlJob); err != nil { err = NewClientError(err) } return etlJob, nil } -func (c *Client) UpdateETL(project string, etljob ETLJobV2) error { +func (c *Client) UpdateETL(project string, etljob ETL) error { body, err := json.Marshal(etljob) if err != nil { return NewClientError(err) diff --git a/client_etl_job_test.go b/client_etl_job_test.go index 7b42fd47..5f6218b9 100644 --- a/client_etl_job_test.go +++ b/client_etl_job_test.go @@ -59,7 +59,7 @@ func (s *ETLJobTestV2Suite) createETLJobV2() error { schedule := ETLSchedule{ Type: "Resident", } - etljob := ETLJobV2{ + etljob := ETL{ Configuration: config, DisplayName: "displayName", Description: "go sdk case", @@ -116,17 +116,33 @@ func (s *ETLJobTestV2Suite) TestClient_ListETLJobV2() { func (s *ETLJobTestV2Suite) TestClient_StartStopETLJobV2() { err := s.createETLJobV2() s.Require().Nil(err) - etljob, err := s.client.GetETL(s.projectName, s.etlName) - s.Require().Equal("RUNNING", etljob.Status) + for { + etljob, err := s.client.GetETL(s.projectName, s.etlName) + s.Require().Nil(err) + time.Sleep(10 * time.Second) + if etljob.Status == "RUNNING" { + break + } + } - err = s.client.StopETL(s.projectName, s.etlName) - time.Sleep(time.Second * 120) - etljob, err = s.client.GetETL(s.projectName, s.etlName) - s.Require().Equal("STOPPED", etljob.Status) + err = s.client.StopETL(s.projectName, s.etlName) + for { + etljob, err := s.client.GetETL(s.projectName, s.etlName) + s.Require().Nil(err) + time.Sleep(10 * time.Second) + if etljob.Status == "STOPPED" { + break + } + } + err = s.client.StartETL(s.projectName, s.etlName) + for { + etljob, err := s.client.GetETL(s.projectName, s.etlName) + s.Require().Nil(err) + time.Sleep(10 * time.Second) + if etljob.Status == "RUNNING" { + break + } + } - err = s.client.StartETL(s.projectName, s.etlName) - time.Sleep(time.Second * 120) - etljob, err = s.client.GetETL(s.projectName, s.etlName) - s.Require().Equal("RUNNING", etljob.Status) }