summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Mistewicz <a.mistewicz@samsung.com>2017-06-08 13:46:35 +0200
committerMaciej Wereski <m.wereski@partner.samsung.com>2017-09-20 10:48:22 +0200
commit402270e1b97b5a5845a9e6402f3dc2cb8840cf35 (patch)
tree9520ff2c550efb71b01a0f207c38109e2f9ec4d8
parentbfe1f722fcbf2a6a0e2b5017ef7cf8c7e192356e (diff)
downloadboruta-402270e1b97b5a5845a9e6402f3dc2cb8840cf35.tar.gz
boruta-402270e1b97b5a5845a9e6402f3dc2cb8840cf35.tar.bz2
boruta-402270e1b97b5a5845a9e6402f3dc2cb8840cf35.zip
Implement Worker registration
When new Dyrad (MuxPi board + tested device) is attached to network it has all information to join Boruta server. It should register with the server by providing Capabilities which are provided by MuxPi hardware. They include UUID which will be used to identify Dryad. After successful registration worker is put in the MAINTENANCE state, which means that it won't get any jobs until administrator manually puts it in the IDLE state. Tests use new library, which can be downloaded with: go get github.com/satori/go.uuid Change-Id: I75a72cf446dd4ff5bc4540f600bc7840c8a189f4 Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com> Reviewed-on: https://mcdsrvbld02.digital.local/review/49056 Reviewed-by: Maciej Wereski <m.wereski@partner.samsung.com> Tested-by: Maciej Wereski <m.wereski@partner.samsung.com>
-rw-r--r--workers/error.go3
-rw-r--r--workers/worker_list_test.go129
-rw-r--r--workers/workers.go22
-rw-r--r--workers/workers_test.go4
4 files changed, 153 insertions, 5 deletions
diff --git a/workers/error.go b/workers/error.go
index 9141f5c..c6cf519 100644
--- a/workers/error.go
+++ b/workers/error.go
@@ -23,4 +23,7 @@ import (
var (
// ErrNotImplemented is returned when function is not implemented yet.
ErrNotImplemented = errors.New("function not implemented")
+ // ErrMissingUUID is returned when Register is called
+ // with caps, which do not contain "UUID" field.
+ ErrMissingUUID = errors.New("Capabilities are missing UUID entry")
)
diff --git a/workers/worker_list_test.go b/workers/worker_list_test.go
new file mode 100644
index 0000000..40a34c6
--- /dev/null
+++ b/workers/worker_list_test.go
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package workers
+
+import (
+ . "git.tizen.org/tools/boruta"
+
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ "github.com/satori/go.uuid"
+)
+
+var _ = Describe("WorkerList", func() {
+ var wl *WorkerList
+ BeforeEach(func() {
+ wl = NewWorkerList()
+ })
+
+ Describe("Register", func() {
+ var registeredWorkers []string
+
+ BeforeEach(func() {
+ registeredWorkers = make([]string, 0)
+ })
+
+ compareLists := func() {
+ // Check if all registeredWorkers are present
+ for _, uuid := range registeredWorkers {
+ _, ok := wl.workers[WorkerUUID(uuid)]
+ Expect(ok).To(BeTrue())
+ }
+ // Check if all workers from the wl.workers are present
+ for _, workerInfo := range wl.workers {
+ ok := false
+ for _, uuid := range registeredWorkers {
+ if workerInfo.WorkerUUID == WorkerUUID(uuid) {
+ ok = true
+ break
+ }
+ }
+ Expect(ok).To(BeTrue())
+ }
+ }
+
+ It("should fail if UUID is not present", func() {
+ err := wl.Register(nil)
+ Expect(err).To(Equal(ErrMissingUUID))
+ })
+
+ getRandomCaps := func() Capabilities {
+ return Capabilities{
+ UUID: uuid.NewV4().String(),
+ }
+ }
+
+ It("should add Worker in MAINTENANCE state", func() {
+ caps := getRandomCaps()
+ err := wl.Register(caps)
+ Expect(err).ToNot(HaveOccurred())
+ uuid := WorkerUUID(caps[UUID])
+ Expect(wl.workers).To(HaveKey(uuid))
+ Expect(wl.workers[uuid].State).To(Equal(MAINTENANCE))
+ })
+
+ It("should update the caps when called twice for the same worker", func() {
+ var err error
+ Expect(wl.workers).To(BeEmpty())
+ caps := getRandomCaps()
+
+ By("registering worker")
+ err = wl.Register(caps)
+ Expect(err).ToNot(HaveOccurred())
+ registeredWorkers = append(registeredWorkers, caps[UUID])
+ compareLists()
+
+ By("updating the caps")
+ caps["test-key"] = "test-value"
+ err = wl.Register(caps)
+ Expect(err).ToNot(HaveOccurred())
+ Expect(wl.workers[WorkerUUID(caps[UUID])].Caps).To(Equal(caps))
+ compareLists()
+ })
+
+ It("should work when called once", func() {
+ var err error
+ Expect(wl.workers).To(BeEmpty())
+ caps := getRandomCaps()
+
+ By("registering first worker")
+ err = wl.Register(caps)
+ Expect(err).ToNot(HaveOccurred())
+ registeredWorkers = append(registeredWorkers, caps[UUID])
+ compareLists()
+ })
+
+ It("should work when called twice with different caps", func() {
+ var err error
+ Expect(wl.workers).To(BeEmpty())
+ caps1 := getRandomCaps()
+ caps2 := getRandomCaps()
+
+ By("registering first worker")
+ err = wl.Register(caps1)
+ Expect(err).ToNot(HaveOccurred())
+ registeredWorkers = append(registeredWorkers, caps1[UUID])
+ compareLists()
+
+ By("registering second worker")
+ err = wl.Register(caps2)
+ Expect(err).ToNot(HaveOccurred())
+ registeredWorkers = append(registeredWorkers, caps2[UUID])
+ compareLists()
+ })
+ })
+})
diff --git a/workers/workers.go b/workers/workers.go
index 1fc6c54..25e405a 100644
--- a/workers/workers.go
+++ b/workers/workers.go
@@ -21,6 +21,9 @@ import (
. "git.tizen.org/tools/boruta"
)
+// UUID denotes a key in Capabilities where WorkerUUID is stored.
+const UUID string = "UUID"
+
// WorkerList implements Superviser and Workers interfaces.
// It manages a list of Workers.
type WorkerList struct {
@@ -37,8 +40,25 @@ func NewWorkerList() *WorkerList {
}
// Register is an implementation of Register from Superviser interface.
+// UUID, which identifies Worker, must be present in caps.
func (wl *WorkerList) Register(caps Capabilities) error {
- return ErrNotImplemented
+ capsUUID, present := caps[UUID]
+ if !present {
+ return ErrMissingUUID
+ }
+ uuid := WorkerUUID(capsUUID)
+ worker, registered := wl.workers[uuid]
+ if registered {
+ // Subsequent Register calls update the caps.
+ worker.Caps = caps
+ } else {
+ wl.workers[uuid] = &WorkerInfo{
+ WorkerUUID: uuid,
+ State: MAINTENANCE,
+ Caps: caps,
+ }
+ }
+ return nil
}
// SetFail is an implementation of SetFail from Superviser interface.
diff --git a/workers/workers_test.go b/workers/workers_test.go
index d3e7688..57e98c7 100644
--- a/workers/workers_test.go
+++ b/workers/workers_test.go
@@ -38,10 +38,6 @@ var _ = Describe("WorkerList", func() {
groups Groups = nil
)
- By("Register")
- err = wl.Register(caps)
- Expect(err).To(Equal(ErrNotImplemented))
-
By("SetFail")
err = wl.SetFail(uuid, "")
Expect(err).To(Equal(ErrNotImplemented))