diff options
author | Aleksander Mistewicz <a.mistewicz@samsung.com> | 2017-06-08 14:51:47 +0200 |
---|---|---|
committer | Maciej Wereski <m.wereski@partner.samsung.com> | 2017-09-20 11:49:59 +0200 |
commit | 7d5188c948d29597adf13d780833d665673a96a8 (patch) | |
tree | fd32acd2e9da019b13bd6351d4dfacd9a7a48f16 /workers | |
parent | 46e1236e609298cc2cbd181c37cb7d2920664b00 (diff) | |
download | boruta-7d5188c948d29597adf13d780833d665673a96a8.tar.gz boruta-7d5188c948d29597adf13d780833d665673a96a8.tar.bz2 boruta-7d5188c948d29597adf13d780833d665673a96a8.zip |
Implement worker removal from the pool
When Worker will not be used anymore, it should be removed in order
to free the resources. Administrator should first put Worker
in the MAINTENANCE state, using SetState, and then remove it,
using Deregister.
Change-Id: Ic9bb5e705418fae664857f3f541e9543ca7da9e2
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
Reviewed-on: https://mcdsrvbld02.digital.local/review/49058
Reviewed-by: Maciej Wereski <m.wereski@partner.samsung.com>
Tested-by: Maciej Wereski <m.wereski@partner.samsung.com>
Diffstat (limited to 'workers')
-rw-r--r-- | workers/error.go | 3 | ||||
-rw-r--r-- | workers/worker_list_test.go | 32 | ||||
-rw-r--r-- | workers/workers.go | 10 | ||||
-rw-r--r-- | workers/workers_test.go | 4 |
4 files changed, 44 insertions, 5 deletions
diff --git a/workers/error.go b/workers/error.go index 1b0f7d6..bd51509 100644 --- a/workers/error.go +++ b/workers/error.go @@ -30,4 +30,7 @@ var ( ErrWorkerNotFound = errors.New("Worker is not present on the list") // ErrInMaintenance is returned when SetFail has been called for Worker in MAINTENANCE state. ErrInMaintenance = errors.New("It is forbidden to set FAIL state when Worker is in MAINTENANCE state") + // ErrNotInMaintenance is returned when Deregister is called for a worker not in MAINTENANCE state. + // Only workers in MAINTENANCE state can be removed from the list. + ErrNotInMaintenance = errors.New("Worker is not in MAINTENANCE state") ) diff --git a/workers/worker_list_test.go b/workers/worker_list_test.go index 562f452..2800cbf 100644 --- a/workers/worker_list_test.go +++ b/workers/worker_list_test.go @@ -173,5 +173,37 @@ var _ = Describe("WorkerList", func() { Expect(wl.workers[worker].State).To(Equal(MAINTENANCE)) }) }) + + Describe("Deregister", func() { + It("should fail to deregister nonexistent worker", func() { + uuid := randomUUID() + err := wl.Deregister(uuid) + Expect(err).To(Equal(ErrWorkerNotFound)) + }) + + It("should work to deregister", func() { + err := wl.Deregister(worker) + Expect(err).ToNot(HaveOccurred()) + Expect(wl.workers).ToNot(HaveKey(worker)) + }) + + It("should fail to deregister same worker twice", func() { + err := wl.Deregister(worker) + Expect(err).ToNot(HaveOccurred()) + Expect(wl.workers).ToNot(HaveKey(worker)) + + err = wl.Deregister(worker) + Expect(err).To(Equal(ErrWorkerNotFound)) + }) + + It("should fail to deregister worker not in MAINTENANCE state", func() { + for _, state := range []WorkerState{IDLE, RUN, FAIL} { + wl.workers[worker].State = state + err := wl.Deregister(worker) + Expect(err).To(Equal(ErrNotInMaintenance)) + Expect(wl.workers).To(HaveKey(worker)) + } + }) + }) }) }) diff --git a/workers/workers.go b/workers/workers.go index 3c27582..ff21f09 100644 --- a/workers/workers.go +++ b/workers/workers.go @@ -88,7 +88,15 @@ func (wl *WorkerList) SetGroups(uuid WorkerUUID, groups Groups) error { // Deregister is an implementation of Deregister from Workers interface. func (wl *WorkerList) Deregister(uuid WorkerUUID) error { - return ErrNotImplemented + worker, ok := wl.workers[uuid] + if !ok { + return ErrWorkerNotFound + } + if worker.State != MAINTENANCE { + return ErrNotInMaintenance + } + delete(wl.workers, uuid) + return nil } // ListWorkers is an implementation of ListWorkers from Workers interface. diff --git a/workers/workers_test.go b/workers/workers_test.go index c6cc3e6..dc2fed5 100644 --- a/workers/workers_test.go +++ b/workers/workers_test.go @@ -46,10 +46,6 @@ var _ = Describe("WorkerList", func() { err = wl.SetGroups(uuid, groups) Expect(err).To(Equal(ErrNotImplemented)) - By("Deregister") - err = wl.Deregister(uuid) - Expect(err).To(Equal(ErrNotImplemented)) - By("ListWorkers") _, err = wl.ListWorkers(groups, caps) Expect(err).To(Equal(ErrNotImplemented)) |