From 1e85a24b8cc48946d8d5443140d0bd074276dc01 Mon Sep 17 00:00:00 2001 From: Maciej Wereski Date: Tue, 12 Sep 2017 12:56:20 +0200 Subject: [PATCH] Rework interfaces definitions Current methods division between interfaces is done in a way that causes situation where no package implements full interface. This change fixes this situation. Change-Id: Ifcfba7d740c86e853410b71da954810ceaf813f3 Signed-off-by: Maciej Wereski Reviewed-on: https://mcdsrvbld02.digital.local/review/49448 Reviewed-by: Aleksander Mistewicz Tested-by: Aleksander Mistewicz --- boruta.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/boruta.go b/boruta.go index 5b320b6..90d34e4 100644 --- a/boruta.go +++ b/boruta.go @@ -120,8 +120,8 @@ type WorkerInfo struct { // ListFilter is used to filter Requests in the Queue. type ListFilter struct{} -// User defines an interaction of the User with the Queue. -type User interface { +// Requests defines an interaction of a user with Requests Queue. +type Requests interface { // NewRequest creates a Request with given features and adds it to the Queue. // It returns ID of the created Request. NewRequest(caps Capabilities, priority Priority, owner UserInfo, @@ -148,15 +148,10 @@ type User interface { // ProlongAccess sets the Job's Deadline to a predefined time.Duration from the time.Now(). // It can be called multiple times, but is limited. ProlongAccess(reqID ReqID) error - // ListWorkers returns a list of all Workers matching Groups and Capabilities - // or all registered Workers if both arguments are empty. - ListWorkers(groups Groups, caps Capabilities) ([]WorkerInfo, error) - // GetWorkerInfo returns WorkerInfo of specified worker. - GetWorkerInfo(uuid WorkerUUID) (WorkerInfo, error) } -// Worker defines actions that can be done by Worker only. -type Worker interface { +// Superviser defines registration and repost actions that can be done by a worker only. +type Superviser interface { // Register adds a new Worker to the system in the MAINTENANCE state. // Capabilities are set on the Worker and can be changed by subsequent Register calls. Register(caps Capabilities) error @@ -165,8 +160,17 @@ type Worker interface { SetFail(uuid WorkerUUID, reason string) error } -// Admin is responsible for management of the Workers. -type Admin interface { +// Workers defines all actions that can be done by users and admins on workers. +// Users (and admins) can also call methods from Requests interface. +type Workers interface { + // ListWorkers returns a list of all Workers matching Groups and Capabilities + // or all registered Workers if both arguments are empty. + ListWorkers(groups Groups, caps Capabilities) ([]WorkerInfo, error) + // GetWorkerInfo returns WorkerInfo of specified worker. + GetWorkerInfo(uuid WorkerUUID) (WorkerInfo, error) + + // Following methods are for administrators only. + // SetState sets the Worker's state to either MAINTENANCE or IDLE. SetState(uuid WorkerUUID, state WorkerState) error // SetGroups updates the groups parameter of the Worker. @@ -179,7 +183,7 @@ type Admin interface { // Server combines all interfaces for regular Users, Admins and Workers // It can also implement HTTP API. type Server interface { - User - Worker - Admin + Requests + Superviser + Workers } -- 2.7.4