diff options
Diffstat (limited to 'controller')
-rw-r--r-- | controller/boruterimpl.go | 2 | ||||
-rw-r--r-- | controller/boruterimpl_test.go | 18 | ||||
-rw-r--r-- | controller/controller.go | 6 | ||||
-rw-r--r-- | controller/controller_test.go | 8 | ||||
-rw-r--r-- | controller/downloaderimpl.go | 16 | ||||
-rw-r--r-- | controller/downloaderimpl_test.go | 38 | ||||
-rw-r--r-- | controller/dryaderimpl.go | 2 | ||||
-rw-r--r-- | controller/dryaderimpl_test.go | 4 | ||||
-rw-r--r-- | controller/jobscontrollerimpl.go | 46 | ||||
-rw-r--r-- | controller/jobscontrollerimpl_test.go | 93 | ||||
-rw-r--r-- | controller/parserimpl.go | 4 | ||||
-rw-r--r-- | controller/parserimpl_test.go | 24 |
12 files changed, 132 insertions, 129 deletions
diff --git a/controller/boruterimpl.go b/controller/boruterimpl.go index 25c2866..b45b871 100644 --- a/controller/boruterimpl.go +++ b/controller/boruterimpl.go @@ -265,7 +265,7 @@ func (h *BoruterImpl) getDeadline(config weles.Config) time.Time { // Request registers new request in Boruta and adds it to monitored requests. func (h *BoruterImpl) Request(j weles.JobID) { - err := h.jobs.SetStatusAndInfo(j, weles.JOB_WAITING, "") + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusWAITING, "") if err != nil { h.SendFail(j, fmt.Sprintf("Internal Weles error while changing Job status : %s", err.Error())) return diff --git a/controller/boruterimpl_test.go b/controller/boruterimpl_test.go index 6512505..0c646e6 100644 --- a/controller/boruterimpl_test.go +++ b/controller/boruterimpl_test.go @@ -120,7 +120,7 @@ var _ = Describe("BoruterImpl", func() { It("should ignore ListRequests errors", func() { counter := 5 mutex := &sync.Mutex{} - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil) req.EXPECT().ListRequests(nil).AnyTimes().Return([]boruta.ReqInfo{}, err).Do(func(boruta.ListFilter) { @@ -142,7 +142,7 @@ var _ = Describe("BoruterImpl", func() { Describe("Request", func() { It("should register job successfully", func() { var va, dl time.Time - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil).Do( func(c boruta.Capabilities, p boruta.Priority, ui boruta.UserInfo, validAfter time.Time, deadline time.Time) { @@ -167,7 +167,7 @@ var _ = Describe("BoruterImpl", func() { config.Timeouts.JobTimeout = weles.ValidPeriod(0) defaultDelay := 24 * time.Hour - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil).Do( func(c boruta.Capabilities, p boruta.Priority, ui boruta.UserInfo, validAfter time.Time, deadline time.Time) { @@ -188,7 +188,7 @@ var _ = Describe("BoruterImpl", func() { expectRegistered(1) }) It("should fail if NewRequest fails", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(boruta.ReqID(0), err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -199,7 +199,7 @@ var _ = Describe("BoruterImpl", func() { eventuallyEmpty(1) }) It("should fail if GetConfig fails", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(weles.Config{}, err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -209,7 +209,7 @@ var _ = Describe("BoruterImpl", func() { eventuallyEmpty(1) }) It("should fail if SetStatusAndInfo fails", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "").Return(err) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "").Return(err) req.EXPECT().ListRequests(nil).AnyTimes() h.Request(j) @@ -219,7 +219,7 @@ var _ = Describe("BoruterImpl", func() { }) It("should call NewRequest with empty caps if no device type provided", func() { config.DeviceType = "" - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(boruta.Capabilities{}, priority, owner, gomock.Any(), gomock.Any()).Return(boruta.ReqID(0), err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -238,7 +238,7 @@ var _ = Describe("BoruterImpl", func() { } for k, v := range m { config.Priority = k - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, v, owner, gomock.Any(), gomock.Any()).Return(boruta.ReqID(0), err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -264,7 +264,7 @@ var _ = Describe("BoruterImpl", func() { ai := boruta.AccessInfo{Addr: &net.IPNet{IP: net.IPv4(1, 2, 3, 4), Mask: net.IPv4Mask(5, 6, 7, 8)}} BeforeEach(func() { var va, dl time.Time - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil).Do( func(c boruta.Capabilities, p boruta.Priority, ui boruta.UserInfo, validAfter time.Time, deadline time.Time) { diff --git a/controller/controller.go b/controller/controller.go index 59d39ba..55b5f0c 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -109,7 +109,7 @@ func (c *Controller) CreateJob(yaml []byte) (weles.JobID, error) { // CancelJob cancels Job identified by argument. Job execution is stopped. // It is a part of JobManager implementation. func (c *Controller) CancelJob(j weles.JobID) error { - err := c.jobs.SetStatusAndInfo(j, weles.JOB_CANCELED, "") + err := c.jobs.SetStatusAndInfo(j, weles.JobStatusCANCELED, "") if err != nil { return err } @@ -165,13 +165,13 @@ func (c *Controller) loop() { // fail sets Job in FAILED state and if needed stops Job's execution on Dryad // and releases Dryad to Boruta. func (c *Controller) fail(j weles.JobID, msg string) { - c.jobs.SetStatusAndInfo(j, weles.JOB_FAILED, msg) + c.jobs.SetStatusAndInfo(j, weles.JobStatusFAILED, msg) c.dryader.CancelJob(j) c.boruter.Release(j) } // succeed sets Job in COMPLETED state. func (c *Controller) succeed(j weles.JobID) { - c.jobs.SetStatusAndInfo(j, weles.JOB_COMPLETED, "") + c.jobs.SetStatusAndInfo(j, weles.JobStatusCOMPLETED, "") c.boruter.Release(j) } diff --git a/controller/controller_test.go b/controller/controller_test.go index b792a95..1d5a9fc 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -149,7 +149,7 @@ var _ = Describe("Controller", func() { Describe("CancelJob", func() { It("should cancel Job, stop execution on Dryad and release Dryad to Boruta", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_CANCELED, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusCANCELED, "") dry.EXPECT().CancelJob(j) bor.EXPECT().Release(j) @@ -158,7 +158,7 @@ var _ = Describe("Controller", func() { Expect(retErr).To(BeNil()) }) It("should return error if Job fails to be cancelled", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_CANCELED, "").Return(testErr) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusCANCELED, "").Return(testErr) retErr := h.CancelJob(j) @@ -203,13 +203,13 @@ var _ = Describe("Controller", func() { }, &borChan), Entry("should complete Job after Dryad Job is done", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_COMPLETED, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusCOMPLETED, "") bor.EXPECT().Release(j).Do(setDone) }, &dryChan), ) DescribeTable("Action fail", func(cnn *chan notifier.Notification) { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_FAILED, testMsg) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusFAILED, testMsg) dry.EXPECT().CancelJob(j) bor.EXPECT().Release(j) *cnn <- notiFail diff --git a/controller/downloaderimpl.go b/controller/downloaderimpl.go index 6f3a14f..c5e2a8d 100644 --- a/controller/downloaderimpl.go +++ b/controller/downloaderimpl.go @@ -99,10 +99,10 @@ func (h *DownloaderImpl) pathStatusChange(path string, status weles.ArtifactStat return } switch status { - case weles.AM_READY: + case weles.ArtifactStatusREADY: i.ready++ info = fmt.Sprintf(formatReady, i.ready, i.paths) - case weles.AM_FAILED: + case weles.ArtifactStatusFAILED: i.failed++ info = "Failed to download artifact" default: @@ -136,7 +136,7 @@ func (h *DownloaderImpl) loop() { continue } - err := h.jobs.SetStatusAndInfo(j, weles.JOB_DOWNLOADING, info) + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, info) if err != nil { h.removePath(string(change.Path)) h.fail(j, fmt.Sprintf(formatJobStatus, err.Error())) @@ -211,7 +211,7 @@ func (h *DownloaderImpl) push(j weles.JobID, t weles.ArtifactType, alias string, func (h *DownloaderImpl) pullCreate(j weles.JobID, alias string) (string, error) { p, err := h.artifacts.CreateArtifact(weles.ArtifactDescription{ JobID: j, - Type: weles.AM_TESTFILE, + Type: weles.ArtifactTypeTEST, Alias: weles.ArtifactAlias(alias), }) return string(p), err @@ -272,7 +272,7 @@ func (h *DownloaderImpl) sendIfReady(j weles.JobID) { func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { h.initializeJobInfo(j) - err := h.jobs.SetStatusAndInfo(j, weles.JOB_DOWNLOADING, "") + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, "") if err != nil { h.fail(j, fmt.Sprintf(formatJobStatus, err.Error())) return @@ -286,7 +286,7 @@ func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { for i, image := range config.Action.Deploy.Images { if image.URI != "" { - path, err := h.push(j, weles.AM_IMAGEFILE, fmt.Sprintf("Image_%d", i), image.URI) + path, err := h.push(j, weles.ArtifactTypeIMAGE, fmt.Sprintf("Image_%d", i), image.URI) if err != nil { h.fail(j, fmt.Sprintf(formatURI, image.URI, err.Error())) return @@ -294,7 +294,7 @@ func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { config.Action.Deploy.Images[i].Path = path } if image.ChecksumURI != "" { - path, err := h.push(j, weles.AM_IMAGEFILE, fmt.Sprintf("ImageMD5_%d", i), image.ChecksumURI) + path, err := h.push(j, weles.ArtifactTypeIMAGE, fmt.Sprintf("ImageMD5_%d", i), image.ChecksumURI) if err != nil { h.fail(j, fmt.Sprintf(formatURI, image.ChecksumURI, err.Error())) return @@ -307,7 +307,7 @@ func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { switch ta.(type) { case weles.Push: action := ta.(weles.Push) - path, err := h.push(j, weles.AM_TESTFILE, action.Alias, action.URI) + path, err := h.push(j, weles.ArtifactTypeTEST, action.Alias, action.URI) if err != nil { h.fail(j, fmt.Sprintf(formatURI, action.URI, err.Error())) return diff --git a/controller/downloaderimpl_test.go b/controller/downloaderimpl_test.go index 28e9098..1d401bf 100644 --- a/controller/downloaderimpl_test.go +++ b/controller/downloaderimpl_test.go @@ -172,7 +172,7 @@ var _ = Describe("DownloaderImpl", func() { eventuallyNoti(offset+1, false, msg) expectPath(offset+1, 0, pathsNo) eventuallyInfoEmpty(offset + 1) - sendChange(0, pathsNo, weles.AM_READY) + sendChange(0, pathsNo, weles.ArtifactStatusREADY) eventuallyPathEmpty(offset + 1) } defaultSetStatusAndInfo := func(successfulEntries int, fail bool) *gomock.Call { @@ -180,14 +180,14 @@ var _ = Describe("DownloaderImpl", func() { var prev, call *gomock.Call for i = 0; i < successfulEntries; i++ { - call = jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, infos[i]) + call = jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, infos[i]) if prev != nil { call.After(prev) } prev = call } if fail { - call = jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, infos[i]).Return(err) + call = jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, infos[i]).Return(err) if prev != nil { call.After(prev) } @@ -198,7 +198,7 @@ var _ = Describe("DownloaderImpl", func() { jc.EXPECT().GetConfig(j).Return(config, nil) } defaultPush := func(successfulEntries int, fail bool) *gomock.Call { - types := []weles.ArtifactType{weles.AM_IMAGEFILE, weles.AM_IMAGEFILE, weles.AM_IMAGEFILE, weles.AM_IMAGEFILE, weles.AM_TESTFILE, weles.AM_TESTFILE, weles.AM_TESTFILE} + types := []weles.ArtifactType{weles.ArtifactTypeIMAGE, weles.ArtifactTypeIMAGE, weles.ArtifactTypeIMAGE, weles.ArtifactTypeIMAGE, weles.ArtifactTypeTEST, weles.ArtifactTypeTEST, weles.ArtifactTypeTEST} aliases := []weles.ArtifactAlias{"Image_0", "ImageMD5_0", "Image_1", "ImageMD5_2", "alias_0", "alias_1", "alias_3"} uris := []weles.ArtifactURI{"image_0", "md5_0", "image_1", "md5_2", "uri_0", "uri_1", "uri_3"} var i int @@ -222,7 +222,7 @@ var _ = Describe("DownloaderImpl", func() { return call } defaultCreate := func(successfulEntries int, fail bool) *gomock.Call { - types := []weles.ArtifactType{weles.AM_TESTFILE, weles.AM_TESTFILE} + types := []weles.ArtifactType{weles.ArtifactTypeTEST, weles.ArtifactTypeTEST} aliases := []weles.ArtifactAlias{"alias_2", "alias_4"} returnPaths := []weles.ArtifactPath{weles.ArtifactPath(paths[7]), weles.ArtifactPath(paths[8])} var i int @@ -260,7 +260,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, true, "") eventuallyEmpty(1) @@ -365,7 +365,7 @@ var _ = Describe("DownloaderImpl", func() { }) It("should handle downloading failure", func() { c := defaultSetStatusAndInfo(4, false) - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, "Failed to download artifact").After(c) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, "Failed to download artifact").After(c) defaultGetConfig() defaultPush(7, false) defaultCreate(2, false) @@ -376,14 +376,14 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 3, weles.AM_READY) - sendChange(3, 4, weles.AM_FAILED) + sendChange(0, 3, weles.ArtifactStatusREADY) + sendChange(3, 4, weles.ArtifactStatusFAILED) eventuallyNoti(1, false, formatDownload) expectPath(1, 4, 7) eventuallyInfoEmpty(1) - sendChange(4, 7, weles.AM_DOWNLOADING) + sendChange(4, 7, weles.ArtifactStatusDOWNLOADING) eventuallyPathEmpty(1) }) It("should block reply until configuration is saved and all artifacts are downloaded", func() { @@ -409,7 +409,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, false, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) holdDownload.Done() eventuallyNoti(1, true, "") @@ -427,7 +427,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, false, "Internal Weles error while changing Job status : test error") eventuallyEmpty(1) @@ -454,7 +454,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, false, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, false, "Internal Weles error while changing Job status : test error") @@ -464,7 +464,7 @@ var _ = Describe("DownloaderImpl", func() { }) It("should leave no data left if failure response is sent while pushing", func() { c := defaultSetStatusAndInfo(1, false) - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, "1 / 1 artifacts ready").Return(err).After(c) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, "1 / 1 artifacts ready").Return(err).After(c) defaultGetConfig() holdDownload := sync.WaitGroup{} holdDownload.Add(1) @@ -482,12 +482,12 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 1) expectInfo(1, false, 1) - sendChange(0, 1, weles.AM_READY) + sendChange(0, 1, weles.ArtifactStatusREADY) eventuallyNoti(1, false, "Internal Weles error while changing Job status : test error") holdDownload.Done() - sendChange(1, 2, weles.AM_READY) + sendChange(1, 2, weles.ArtifactStatusREADY) eventuallyEmpty(1) }) @@ -503,13 +503,13 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_DOWNLOADING) - sendChange(0, 7, weles.AM_PENDING) + sendChange(0, 7, weles.ArtifactStatusDOWNLOADING) + sendChange(0, 7, weles.ArtifactStatusPENDING) expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, true, "") eventuallyEmpty(1) diff --git a/controller/dryaderimpl.go b/controller/dryaderimpl.go index ac5b1d3..b4e4eae 100644 --- a/controller/dryaderimpl.go +++ b/controller/dryaderimpl.go @@ -90,7 +90,7 @@ func (h *DryaderImpl) remove(j weles.JobID) { // setStatus sets Jobs status to RUNNING and updates info. func (h *DryaderImpl) setStatus(j weles.JobID, msg string) { - err := h.jobs.SetStatusAndInfo(j, weles.JOB_RUNNING, msg) + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusRUNNING, msg) if err != nil { h.remove(j) h.SendFail(j, fmt.Sprintf("Internal Weles error while changing Job status : %s", err.Error())) diff --git a/controller/dryaderimpl_test.go b/controller/dryaderimpl_test.go index 4e11997..deac3cf 100644 --- a/controller/dryaderimpl_test.go +++ b/controller/dryaderimpl_test.go @@ -162,7 +162,7 @@ var _ = Describe("DryaderImpl", func() { It("should update status of the Job", func() { for i, s := range updateStates { change := weles.DryadJobInfo{Job: j, Status: s} - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_RUNNING, updateMsgs[i]) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusRUNNING, updateMsgs[i]) h.(*DryaderImpl).listener <- weles.DryadJobStatusChange(change) @@ -179,7 +179,7 @@ var _ = Describe("DryaderImpl", func() { DescribeTable("should fail if updating status of the Job fails", func(s weles.DryadJobStatus, msg string) { change := weles.DryadJobInfo{Job: j, Status: s} - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_RUNNING, msg).Return(err) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusRUNNING, msg).Return(err) h.(*DryaderImpl).listener <- weles.DryadJobStatusChange(change) diff --git a/controller/jobscontrollerimpl.go b/controller/jobscontrollerimpl.go index b7cd51c..49fbd5e 100644 --- a/controller/jobscontrollerimpl.go +++ b/controller/jobscontrollerimpl.go @@ -23,6 +23,8 @@ import ( "sync" "time" + "github.com/go-openapi/strfmt" + "git.tizen.org/tools/weles" ) @@ -80,13 +82,13 @@ func (js *JobsControllerImpl) NewJob(yaml []byte) (weles.JobID, error) { j := js.nextID() - now := time.Now() + now := strfmt.DateTime(time.Now()) js.jobs[j] = &Job{ JobInfo: weles.JobInfo{ JobID: j, Created: now, Updated: now, - Status: weles.JOB_NEW, + Status: weles.JobStatusNEW, }, yaml: yaml, } @@ -120,7 +122,7 @@ func (js *JobsControllerImpl) SetConfig(j weles.JobID, conf weles.Config) error } job.config = conf - job.Updated = time.Now() + job.Updated = strfmt.DateTime(time.Now()) return nil } @@ -131,29 +133,29 @@ func isStatusChangeValid(oldStatus, newStatus weles.JobStatus) bool { return true } switch oldStatus { - case weles.JOB_NEW: + case weles.JobStatusNEW: switch newStatus { - case weles.JOB_PARSING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusPARSING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_PARSING: + case weles.JobStatusPARSING: switch newStatus { - case weles.JOB_DOWNLOADING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusDOWNLOADING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_DOWNLOADING: + case weles.JobStatusDOWNLOADING: switch newStatus { - case weles.JOB_WAITING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusWAITING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_WAITING: + case weles.JobStatusWAITING: switch newStatus { - case weles.JOB_RUNNING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusRUNNING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_RUNNING: + case weles.JobStatusRUNNING: switch newStatus { - case weles.JOB_COMPLETED, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusCOMPLETED, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } } @@ -162,15 +164,15 @@ func isStatusChangeValid(oldStatus, newStatus weles.JobStatus) bool { // SetStatusAndInfo changes status of the Job and updates info. Only valid // changes are allowed. -// There are 3 terminal statuses: JOB_FAILED, JOB_CANCELED, JOB_COMPLETED; -// and 5 non-terminal statuses: JOB_NEW, JOB_PARSING, JOB_DOWNLOADING, -// JOB_WAITING, JOB_RUNNING. +// There are 3 terminal statuses: JobStatusFAILED, JobStatusCANCELED, JobStatusCOMPLETED; +// and 5 non-terminal statuses: JobStatusNEW, JobStatusPARSING, JobStatusDOWNLOADING, +// JobStatusWAITING, JobStatusRUNNING. // Only below changes of statuses are allowed: -// * JOB_NEW --> {JOB_PARSING, JOB_CANCELED, JOB_FAILED} -// * JOB_PARSING --> {JOB_DOWNLOADING, JOB_CANCELED, JOB_FAILED} -// * JOB_DOWNLOADING --> {JOB_WAITING, JOB_CANCELED, JOB_FAILED} -// * JOB_WAITING --> {JOB_RUNNING, JOB_CANCELED, JOB_FAILED} -// * JOB_RUNNING --> {JOB_COMPLETED, JOB_CANCELED, JOB_FAILED} +// * JobStatusNEW --> {JobStatusPARSING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusPARSING --> {JobStatusDOWNLOADING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusDOWNLOADING --> {JobStatusWAITING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusWAITING --> {JobStatusRUNNING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusRUNNING --> {JobStatusCOMPLETED, JobStatusCANCELED, JobStatusFAILED} func (js *JobsControllerImpl) SetStatusAndInfo(j weles.JobID, newStatus weles.JobStatus, msg string) error { js.mutex.Lock() defer js.mutex.Unlock() @@ -186,7 +188,7 @@ func (js *JobsControllerImpl) SetStatusAndInfo(j weles.JobID, newStatus weles.Jo job.Status = newStatus job.Info = msg - job.Updated = time.Now() + job.Updated = strfmt.DateTime(time.Now()) return nil } diff --git a/controller/jobscontrollerimpl_test.go b/controller/jobscontrollerimpl_test.go index 8598f4a..bead78b 100644 --- a/controller/jobscontrollerimpl_test.go +++ b/controller/jobscontrollerimpl_test.go @@ -21,9 +21,10 @@ import ( "net" "time" - "git.tizen.org/tools/weles" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + + "git.tizen.org/tools/weles" ) var _ = Describe("JobsControllerImpl", func() { @@ -75,9 +76,9 @@ var _ = Describe("JobsControllerImpl", func() { Expect(ok).To(BeTrue()) Expect(job.JobID).To(Equal(j)) Expect(job.Created).To(Equal(job.Updated)) - Expect(job.Created).To(BeTemporally(">=", before)) - Expect(job.Created).To(BeTemporally("<=", after)) - Expect(job.Status).To(Equal(weles.JOB_NEW)) + Expect(time.Time(job.Created)).To(BeTemporally(">=", before)) + Expect(time.Time(job.Created)).To(BeTemporally("<=", after)) + Expect(job.Status).To(Equal(weles.JobStatusNEW)) Expect(job.yaml).To(Equal(yaml)) }) }) @@ -95,54 +96,54 @@ var _ = Describe("JobsControllerImpl", func() { }) Describe("SetStatus", func() { allStatus := []weles.JobStatus{ - weles.JOB_NEW, - weles.JOB_PARSING, - weles.JOB_DOWNLOADING, - weles.JOB_WAITING, - weles.JOB_RUNNING, - weles.JOB_FAILED, - weles.JOB_CANCELED, - weles.JOB_COMPLETED, + weles.JobStatusNEW, + weles.JobStatusPARSING, + weles.JobStatusDOWNLOADING, + weles.JobStatusWAITING, + weles.JobStatusRUNNING, + weles.JobStatusFAILED, + weles.JobStatusCANCELED, + weles.JobStatusCOMPLETED, } validChanges := map[weles.JobStatus](map[weles.JobStatus]bool){ - weles.JOB_NEW: map[weles.JobStatus]bool{ - weles.JOB_NEW: true, - weles.JOB_PARSING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusNEW: map[weles.JobStatus]bool{ + weles.JobStatusNEW: true, + weles.JobStatusPARSING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_PARSING: map[weles.JobStatus]bool{ - weles.JOB_PARSING: true, - weles.JOB_DOWNLOADING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusPARSING: map[weles.JobStatus]bool{ + weles.JobStatusPARSING: true, + weles.JobStatusDOWNLOADING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_DOWNLOADING: map[weles.JobStatus]bool{ - weles.JOB_DOWNLOADING: true, - weles.JOB_WAITING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusDOWNLOADING: map[weles.JobStatus]bool{ + weles.JobStatusDOWNLOADING: true, + weles.JobStatusWAITING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_WAITING: map[weles.JobStatus]bool{ - weles.JOB_WAITING: true, - weles.JOB_RUNNING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusWAITING: map[weles.JobStatus]bool{ + weles.JobStatusWAITING: true, + weles.JobStatusRUNNING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_RUNNING: map[weles.JobStatus]bool{ - weles.JOB_RUNNING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, - weles.JOB_COMPLETED: true, + weles.JobStatusRUNNING: map[weles.JobStatus]bool{ + weles.JobStatusRUNNING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, + weles.JobStatusCOMPLETED: true, }, - weles.JOB_FAILED: map[weles.JobStatus]bool{ - weles.JOB_FAILED: true, + weles.JobStatusFAILED: map[weles.JobStatus]bool{ + weles.JobStatusFAILED: true, }, - weles.JOB_CANCELED: map[weles.JobStatus]bool{ - weles.JOB_CANCELED: true, + weles.JobStatusCANCELED: map[weles.JobStatus]bool{ + weles.JobStatusCANCELED: true, }, - weles.JOB_COMPLETED: map[weles.JobStatus]bool{ - weles.JOB_COMPLETED: true, + weles.JobStatusCOMPLETED: map[weles.JobStatus]bool{ + weles.JobStatusCOMPLETED: true, }, } It("should return error for not existing job", func() { @@ -172,7 +173,7 @@ var _ = Describe("JobsControllerImpl", func() { Expect(err).NotTo(HaveOccurred()) Expect(job.Status).To(Equal(newStatus)) Expect(job.Info).To(Equal(info)) - Expect(job.Updated).To(BeTemporally(">=", oldUpdated)) + Expect(time.Time(job.Updated)).To(BeTemporally(">=", time.Time(oldUpdated))) }) } } @@ -188,8 +189,8 @@ var _ = Describe("JobsControllerImpl", func() { Expect(err).NotTo(HaveOccurred()) Expect(jc.(*JobsControllerImpl).jobs[j].config).To(Equal(config)) - Expect(jc.(*JobsControllerImpl).jobs[j].Updated).To(BeTemporally(">=", before)) - Expect(jc.(*JobsControllerImpl).jobs[j].Updated).To(BeTemporally("<=", after)) + Expect(time.Time(jc.(*JobsControllerImpl).jobs[j].Updated)).To(BeTemporally(">=", before)) + Expect(time.Time(jc.(*JobsControllerImpl).jobs[j].Updated)).To(BeTemporally("<=", after)) }) It("should return error for not existing job", func() { config := weles.Config{JobName: "Test Job"} diff --git a/controller/parserimpl.go b/controller/parserimpl.go index 613623a..17f0643 100644 --- a/controller/parserimpl.go +++ b/controller/parserimpl.go @@ -52,7 +52,7 @@ func NewParser(j JobsController, a weles.ArtifactManager, p weles.Parser) Parser // Parse prepares new Job to be processed by saving yaml file in ArtifactDB, // parsing yaml and preparing Job's configuration. func (h *ParserImpl) Parse(j weles.JobID) { - err := h.jobs.SetStatusAndInfo(j, weles.JOB_PARSING, "") + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusPARSING, "") if err != nil { h.SendFail(j, fmt.Sprintf("Internal Weles error while changing Job status : %s", err.Error())) return @@ -66,7 +66,7 @@ func (h *ParserImpl) Parse(j weles.JobID) { path, err := h.artifacts.CreateArtifact(weles.ArtifactDescription{ JobID: j, - Type: weles.AM_YAMLFILE, + Type: weles.ArtifactTypeYAML, }) if err != nil { h.SendFail(j, fmt.Sprintf("Internal Weles error while creating file path in ArtifactDB : %s", err.Error())) diff --git a/controller/parserimpl_test.go b/controller/parserimpl_test.go index 0f48ff3..9ff7556 100644 --- a/controller/parserimpl_test.go +++ b/controller/parserimpl_test.go @@ -66,9 +66,9 @@ var _ = Describe("ParserImpl", func() { Describe("Parse", func() { It("should handle job successfully", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(goodpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(goodpath, nil), yp.EXPECT().ParseYaml(yaml).Return(&config, nil), jc.EXPECT().SetConfig(j, config), ) @@ -82,9 +82,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to set config", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(goodpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(goodpath, nil), yp.EXPECT().ParseYaml(yaml).Return(&config, nil), jc.EXPECT().SetConfig(j, config).Return(err), ) @@ -100,9 +100,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to parse yaml", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(goodpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(goodpath, nil), yp.EXPECT().ParseYaml(yaml).Return(&weles.Config{}, err), ) @@ -117,9 +117,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to write yaml file", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(badpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(badpath, nil), ) h.Parse(j) @@ -133,9 +133,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to create path in ArtifactDB", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(weles.ArtifactPath(""), err), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(weles.ArtifactPath(""), err), ) h.Parse(j) @@ -149,7 +149,7 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to get yaml", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return([]byte{}, err), ) @@ -163,7 +163,7 @@ var _ = Describe("ParserImpl", func() { Eventually(r).Should(Receive(Equal(expectedNotification))) }) It("should fail when unable to change job status", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, "").Return(err) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, "").Return(err) h.Parse(j) |