summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dryad/conf/conf.go6
-rw-r--r--dryad/rusalka.go6
-rw-r--r--http/error.go4
-rw-r--r--http/filter.go8
-rw-r--r--http/http.go6
-rw-r--r--http/server/api/api.go12
-rw-r--r--http/server/api/v1/api.go24
-rw-r--r--http/server/api/v1/handlers.go18
-rw-r--r--matcher/deadlinematcher.go4
-rw-r--r--matcher/jobs.go18
-rw-r--r--matcher/jobsmanager.go8
-rw-r--r--matcher/matcher.go4
-rw-r--r--matcher/requestsmanager.go14
-rw-r--r--matcher/timeoutmatcher.go4
-rw-r--r--matcher/validmatcher.go6
-rw-r--r--matcher/workersmanager.go10
-rw-r--r--requests/queue.go40
-rw-r--r--requests/queue_test.go35
-rw-r--r--requests/requests.go118
-rw-r--r--requests/requests_requestsmanager_test.go74
-rw-r--r--requests/requests_test.go157
-rw-r--r--requests/requests_workerchange_test.go26
-rw-r--r--requests/times.go4
-rw-r--r--requests/times_test.go16
-rw-r--r--requests/timesheapcontainer.go6
-rw-r--r--rpc/dryad/clientmanager.go4
-rw-r--r--workers/error.go4
-rw-r--r--workers/job.go6
-rw-r--r--workers/worker_list_test.go286
-rw-r--r--workers/workerchange.go6
-rw-r--r--workers/workers.go100
31 files changed, 541 insertions, 493 deletions
diff --git a/dryad/conf/conf.go b/dryad/conf/conf.go
index d8b37cd..3c32c1d 100644
--- a/dryad/conf/conf.go
+++ b/dryad/conf/conf.go
@@ -24,7 +24,7 @@ import (
"github.com/BurntSushi/toml"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// DefaultRPCPort is a port that should be used as default parameter
@@ -39,7 +39,7 @@ func NewConf() *General {
return &General{
Address: fmt.Sprintf(":%d", DefaultRPCPort),
SSHAdress: fmt.Sprintf(":%d", DefaultSSHPort),
- Caps: Capabilities(map[string]string{}),
+ Caps: boruta.Capabilities(map[string]string{}),
User: &User{
Name: "boruta-user",
Groups: []string{},
@@ -70,7 +70,7 @@ type General struct {
//
// TODO(amistewicz): This field should be removed when
// it will be possible to read it from hardware.
- Caps Capabilities `toml:"caps"`
+ Caps boruta.Capabilities `toml:"caps"`
// User refers information necessary to create the user.
User *User `toml:"user"`
// SDcard is a base path to block device of sdcard.
diff --git a/dryad/rusalka.go b/dryad/rusalka.go
index e4af51c..7ce3731 100644
--- a/dryad/rusalka.go
+++ b/dryad/rusalka.go
@@ -23,7 +23,7 @@ import (
"context"
"fmt"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/muxpi/sw/nanopi/stm"
"golang.org/x/crypto/ssh"
)
@@ -31,14 +31,14 @@ import (
// Rusalka implements Dryad interface. It is intended to be used on NanoPi connected to MuxPi.
// It is not safe for concurrent use.
type Rusalka struct {
- Dryad
+ boruta.Dryad
dryadUser *borutaUser
stm *stmHelper
cancelMaintenance context.CancelFunc
}
// NewRusalka returns Dryad interface to Rusalka.
-func NewRusalka(stmConn stm.Interface, username string, groups []string) Dryad {
+func NewRusalka(stmConn stm.Interface, username string, groups []string) boruta.Dryad {
return &Rusalka{
dryadUser: newBorutaUser(username, groups),
stm: &stmHelper{stmConn},
diff --git a/http/error.go b/http/error.go
index 4771f1b..9d1c139 100644
--- a/http/error.go
+++ b/http/error.go
@@ -24,7 +24,7 @@ import (
"io"
"net/http"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// ServerError represents error that occured while creating response.
@@ -56,7 +56,7 @@ var (
// isNotFoundError returns true if passed error is of type NotFoundError.
func isNotFoundError(err error) bool {
- _, ok := err.(NotFoundError)
+ _, ok := err.(boruta.NotFoundError)
return ok
}
diff --git a/http/filter.go b/http/filter.go
index bca0b4d..0c04db2 100644
--- a/http/filter.go
+++ b/http/filter.go
@@ -21,13 +21,13 @@ package http
import (
"strings"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// WorkersFilter contains Groups and Capabilities to be used to filter workers.
type WorkersFilter struct {
- Groups
- Capabilities
+ boruta.Groups
+ boruta.Capabilities
}
// RequestFilter implements ListFilter interface. Currently it is possible to
@@ -52,7 +52,7 @@ func NewRequestFilter(state, priority string) *RequestFilter {
// * ranges,
// * one of given,
// * except of.
-func (filter *RequestFilter) Match(req *ReqInfo) bool {
+func (filter *RequestFilter) Match(req *boruta.ReqInfo) bool {
if req == nil {
return false
}
diff --git a/http/http.go b/http/http.go
index 63d0c22..5d2f128 100644
--- a/http/http.go
+++ b/http/http.go
@@ -21,7 +21,7 @@ import (
"net"
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// DateFormat denotes layout of timestamps used by Boruta HTTP API.
@@ -29,12 +29,12 @@ const DateFormat = time.RFC3339
// ReqIDPack is used for JSON (un)marshaller.
type ReqIDPack struct {
- ReqID
+ boruta.ReqID
}
// WorkerStatePack is used by JSON (un)marshaller.
type WorkerStatePack struct {
- WorkerState
+ boruta.WorkerState
}
// AccessInfo2 structure is used by HTTP instead of AccessInfo when acquiring
diff --git a/http/server/api/api.go b/http/server/api/api.go
index 2b443fb..e7a5cc7 100644
--- a/http/server/api/api.go
+++ b/http/server/api/api.go
@@ -22,7 +22,7 @@ import (
"fmt"
"net/http"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
util "git.tizen.org/tools/boruta/http"
"git.tizen.org/tools/boruta/http/server/api/v1"
"github.com/dimfeld/httptreemux"
@@ -35,8 +35,8 @@ const defaultAPI = v1.Version
// API provides HTTP API handlers.
type API struct {
r *httptreemux.TreeMux
- reqs Requests
- workers Workers
+ reqs boruta.Requests
+ workers boruta.Workers
}
// panicHandler is desired as httptreemux PanicHandler function. It sends
@@ -70,7 +70,7 @@ func redirectToDefault(w http.ResponseWriter, r *http.Request,
// setNotFoundHandler catches all requests that were redirected to default API,
// and not found there.
func notFoundHandler(w http.ResponseWriter, r *http.Request, _ map[string]string) {
- srvErr := util.NewServerError(NotFoundError(r.URL.Path))
+ srvErr := util.NewServerError(boruta.NotFoundError(r.URL.Path))
data, err := json.Marshal(srvErr)
if err != nil {
data = []byte(srvErr.Err)
@@ -103,8 +103,8 @@ func setDefaultAPIRedirect(prefix *httptreemux.Group) {
// NewAPI registers all available Boruta HTTP APIs on provided router. It also
// sets panicHandler for all panics that may occur in any API. Finally it sets
// default API version to which requests that miss API version are redirected.
-func NewAPI(router *httptreemux.TreeMux, requestsAPI Requests,
- workersAPI Workers) (api *API) {
+func NewAPI(router *httptreemux.TreeMux, requestsAPI boruta.Requests,
+ workersAPI boruta.Workers) (api *API) {
api = new(API)
api.reqs = requestsAPI
diff --git a/http/server/api/v1/api.go b/http/server/api/v1/api.go
index 22c5ea9..ff49266 100644
--- a/http/server/api/v1/api.go
+++ b/http/server/api/v1/api.go
@@ -25,7 +25,7 @@ import (
"regexp"
"strconv"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
util "git.tizen.org/tools/boruta/http"
"github.com/dimfeld/httptreemux"
)
@@ -43,8 +43,8 @@ const Version = "v1"
// API provides HTTP API handlers.
type API struct {
r *httptreemux.Group
- reqs Requests
- workers Workers
+ reqs boruta.Requests
+ workers boruta.Workers
}
// uuidRE matches only valid UUID strings.
@@ -77,17 +77,17 @@ func routerSetHandler(grp *httptreemux.Group, path string, fn reqHandler,
if data != nil {
status = data.Status
}
- case ReqInfo:
+ case boruta.ReqInfo:
w.Header().Add("Boruta-Request-State", string(data.State))
- if data.State == INPROGRESS {
+ if data.State == boruta.INPROGRESS {
w.Header().Add("Boruta-Job-Timeout",
data.Job.Timeout.Format(util.DateFormat))
}
- case []ReqInfo:
+ case []boruta.ReqInfo:
w.Header().Add("Boruta-Request-Count", strconv.Itoa(len(data)))
- case WorkerInfo:
+ case boruta.WorkerInfo:
w.Header().Add("Boruta-Worker-State", string(data.State))
- case []WorkerInfo:
+ case []boruta.WorkerInfo:
w.Header().Add("Boruta-Worker-Count", strconv.Itoa(len(data)))
}
if status != http.StatusNoContent {
@@ -106,8 +106,8 @@ func routerSetHandler(grp *httptreemux.Group, path string, fn reqHandler,
// NewAPI takes router and registers HTTP API in it. htttreemux.PanicHandler
// function is set. Also other setting of the router may be modified.
-func NewAPI(router *httptreemux.Group, requestsAPI Requests,
- workersAPI Workers) (api *API) {
+func NewAPI(router *httptreemux.Group, requestsAPI boruta.Requests,
+ workersAPI boruta.Workers) (api *API) {
api = new(API)
api.reqs = requestsAPI
@@ -155,9 +155,9 @@ func NewAPI(router *httptreemux.Group, requestsAPI Requests,
return
}
-func parseReqID(id string) (ReqID, error) {
+func parseReqID(id string) (boruta.ReqID, error) {
reqid, err := strconv.ParseUint(id, 10, 64)
- return ReqID(reqid), err
+ return boruta.ReqID(reqid), err
}
// isValidUUID checks if given string is properly formatted UUID.
diff --git a/http/server/api/v1/handlers.go b/http/server/api/v1/handlers.go
index f1295e5..18ecf8f 100644
--- a/http/server/api/v1/handlers.go
+++ b/http/server/api/v1/handlers.go
@@ -26,14 +26,14 @@ import (
"net"
"net/http"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
util "git.tizen.org/tools/boruta/http"
)
// newRequestHandler parses HTTP request for creating new Boruta request and
// calls NewRequest().
func (api *API) newRequestHandler(r *http.Request, ps map[string]string) responseData {
- var newReq ReqInfo
+ var newReq boruta.ReqInfo
defer r.Body.Close()
if err := json.NewDecoder(r.Body).Decode(&newReq); err != nil {
@@ -41,7 +41,7 @@ func (api *API) newRequestHandler(r *http.Request, ps map[string]string) respons
}
//FIXME: currently UserInfo is ignored. Change when user support is added.
- rid, err := api.reqs.NewRequest(newReq.Caps, newReq.Priority, UserInfo{},
+ rid, err := api.reqs.NewRequest(newReq.Caps, newReq.Priority, boruta.UserInfo{},
newReq.ValidAfter.UTC(), newReq.Deadline.UTC())
if err != nil {
return util.NewServerError(err)
@@ -74,7 +74,7 @@ func (api *API) updateRequestHandler(r *http.Request, ps map[string]string) resp
return util.NewServerError(util.ErrBadID)
}
- var req ReqInfo
+ var req boruta.ReqInfo
if err = json.NewDecoder(r.Body).Decode(&req); err != nil {
return util.NewServerError(err)
}
@@ -198,7 +198,7 @@ func (api *API) getWorkerInfoHandler(r *http.Request, ps map[string]string) resp
return util.NewServerError(util.ErrBadUUID)
}
- workerinfo, err := api.workers.GetWorkerInfo(WorkerUUID(ps["id"]))
+ workerinfo, err := api.workers.GetWorkerInfo(boruta.WorkerUUID(ps["id"]))
if err != nil {
return util.NewServerError(err)
}
@@ -220,14 +220,14 @@ func (api *API) setWorkerStateHandler(r *http.Request, ps map[string]string) res
return util.NewServerError(err)
}
- return util.NewServerError(api.workers.SetState(WorkerUUID(ps["id"]),
+ return util.NewServerError(api.workers.SetState(boruta.WorkerUUID(ps["id"]),
state.WorkerState))
}
// setWorkerGroupsHandler parses HTTP workers for setting worker groups and calls
// workers.SetGroups().
func (api *API) setWorkerGroupsHandler(r *http.Request, ps map[string]string) responseData {
- var groups Groups
+ var groups boruta.Groups
defer r.Body.Close()
if !isValidUUID(ps["id"]) {
@@ -237,7 +237,7 @@ func (api *API) setWorkerGroupsHandler(r *http.Request, ps map[string]string) re
if err := json.NewDecoder(r.Body).Decode(&groups); err != nil {
return util.NewServerError(err)
}
- return util.NewServerError(api.workers.SetGroups(WorkerUUID(ps["id"]), groups))
+ return util.NewServerError(api.workers.SetGroups(boruta.WorkerUUID(ps["id"]), groups))
}
// workerDeregister parses HTTP workers for deregistering worker state and calls
@@ -249,5 +249,5 @@ func (api *API) workerDeregister(r *http.Request, ps map[string]string) response
return util.NewServerError(util.ErrBadUUID)
}
- return util.NewServerError(api.workers.Deregister(WorkerUUID(ps["id"])))
+ return util.NewServerError(api.workers.Deregister(boruta.WorkerUUID(ps["id"])))
}
diff --git a/matcher/deadlinematcher.go b/matcher/deadlinematcher.go
index 1366127..278fa1d 100644
--- a/matcher/deadlinematcher.go
+++ b/matcher/deadlinematcher.go
@@ -21,7 +21,7 @@
package matcher
import (
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// DeadlineMatcher implements Matcher interface for handling pending requests
@@ -47,7 +47,7 @@ func NewDeadlineMatcher(r RequestsManager) *DeadlineMatcher {
// If changing state to TIMEOUT is not possible Timeout returns an error.
// Any errors are ignored as they are false negatives cases from DeadlineMatcher
// point of view.
-func (m DeadlineMatcher) Notify(dead []ReqID) {
+func (m DeadlineMatcher) Notify(dead []boruta.ReqID) {
for _, r := range dead {
m.requests.Timeout(r)
}
diff --git a/matcher/jobs.go b/matcher/jobs.go
index d2f6b3c..c9fdc0f 100644
--- a/matcher/jobs.go
+++ b/matcher/jobs.go
@@ -23,7 +23,7 @@ package matcher
import (
"sync"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/tunnels"
"git.tizen.org/tools/boruta/workers"
)
@@ -36,7 +36,7 @@ const defaultDryadUsername = "boruta-user"
type JobsManagerImpl struct {
JobsManager
// jobs stores all running jobs indexed by ID of the worker they are running on.
- jobs map[WorkerUUID]*workers.Job
+ jobs map[boruta.WorkerUUID]*workers.Job
// workers provides access to workers.
workers WorkersManager
// mutex protects JobsManagerImpl from concurrent access.
@@ -56,7 +56,7 @@ func newTunnel() tunnels.Tunneler {
// NewJobsManager creates and returns new JobsManagerImpl structure.
func NewJobsManager(w WorkersManager) JobsManager {
return &JobsManagerImpl{
- jobs: make(map[WorkerUUID]*workers.Job),
+ jobs: make(map[boruta.WorkerUUID]*workers.Job),
workers: w,
mutex: new(sync.RWMutex),
newTunnel: newTunnel,
@@ -66,7 +66,7 @@ func NewJobsManager(w WorkersManager) JobsManager {
// Create method creates a new job for the request and the worker. It also prepares
// communication to Dryad by creating a tunnel. It is a part of JobsManager
// interface implementation.
-func (m *JobsManagerImpl) Create(req ReqID, worker WorkerUUID) error {
+func (m *JobsManagerImpl) Create(req boruta.ReqID, worker boruta.WorkerUUID) error {
m.mutex.Lock()
defer m.mutex.Unlock()
@@ -90,7 +90,7 @@ func (m *JobsManagerImpl) Create(req ReqID, worker WorkerUUID) error {
}
job := &workers.Job{
- Access: AccessInfo{
+ Access: boruta.AccessInfo{
Addr: t.Addr(),
Key: key,
// TODO (m.wereski) Acquire username from config.
@@ -106,13 +106,13 @@ func (m *JobsManagerImpl) Create(req ReqID, worker WorkerUUID) error {
// Get returns job information related to the worker ID or error if no job for
// that worker was found. It is a part of JobsManager interface implementation.
-func (m *JobsManagerImpl) Get(worker WorkerUUID) (*workers.Job, error) {
+func (m *JobsManagerImpl) Get(worker boruta.WorkerUUID) (*workers.Job, error) {
m.mutex.RLock()
defer m.mutex.RUnlock()
job, present := m.jobs[worker]
if !present {
- return nil, NotFoundError("Job")
+ return nil, boruta.NotFoundError("Job")
}
return job, nil
}
@@ -121,14 +121,14 @@ func (m *JobsManagerImpl) Get(worker WorkerUUID) (*workers.Job, error) {
// from jobs collection.
// The Dryad should be notified and prepared for next job with key regeneration.
// It is a part of JobsManager interface implementation.
-func (m *JobsManagerImpl) Finish(worker WorkerUUID) error {
+func (m *JobsManagerImpl) Finish(worker boruta.WorkerUUID) error {
defer m.workers.PrepareWorker(worker, true)
m.mutex.Lock()
defer m.mutex.Unlock()
job, present := m.jobs[worker]
if !present {
- return NotFoundError("Job")
+ return boruta.NotFoundError("Job")
}
job.Tunnel.Close()
// TODO log an error in case of tunnel closing failure. Nothing more can be done.
diff --git a/matcher/jobsmanager.go b/matcher/jobsmanager.go
index 1af346f..cb3cd49 100644
--- a/matcher/jobsmanager.go
+++ b/matcher/jobsmanager.go
@@ -20,17 +20,17 @@
package matcher
import (
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/workers"
)
// JobsManager defines API for internal boruta management of jobs.
type JobsManager interface {
// Create prepares a new job for the worker.
- Create(ReqID, WorkerUUID) error
+ Create(boruta.ReqID, boruta.WorkerUUID) error
// Get returns pointer to a Job from JobsManager or error if no job for
// the worker is found.
- Get(WorkerUUID) (*workers.Job, error)
+ Get(boruta.WorkerUUID) (*workers.Job, error)
// Finish cleans up after job is done.
- Finish(WorkerUUID) error
+ Finish(boruta.WorkerUUID) error
}
diff --git a/matcher/matcher.go b/matcher/matcher.go
index 9b60236..556fac5 100644
--- a/matcher/matcher.go
+++ b/matcher/matcher.go
@@ -19,7 +19,7 @@
package matcher
import (
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// Matcher defines interface for objects that can be notified about events.
@@ -27,5 +27,5 @@ type Matcher interface {
// Notify triggers action in the matcher. The ReqID slice contain set
// of requests' IDs related to the event. The slice can be empty if the event
// requires generic actions on all requests.
- Notify([]ReqID)
+ Notify([]boruta.ReqID)
}
diff --git a/matcher/requestsmanager.go b/matcher/requestsmanager.go
index 4920166..bb604dd 100644
--- a/matcher/requestsmanager.go
+++ b/matcher/requestsmanager.go
@@ -22,7 +22,7 @@ package matcher
import (
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// RequestsManager interface defines API for internal boruta management of requests.
@@ -36,16 +36,16 @@ type RequestsManager interface {
// Next gets next ID from request queue.
// Method returns {ID, true} if there is pending request
// or {ReqID(0), false} if queue's end has been reached.
- Next() (ReqID, bool)
+ Next() (boruta.ReqID, bool)
// VerifyIfReady checks if the request is ready to be run on worker.
- VerifyIfReady(ReqID, time.Time) bool
+ VerifyIfReady(boruta.ReqID, time.Time) bool
// Get retrieves full request information or error if no request is found.
- Get(ReqID) (ReqInfo, error)
+ Get(boruta.ReqID) (boruta.ReqInfo, error)
// Timeout sets request to TIMEOUT state after Deadline time is exceeded.
- Timeout(ReqID) error
+ Timeout(boruta.ReqID) error
// Close closes request setting it in DONE state, closing job
// and releasing worker after run time of the request has been exceeded.
- Close(ReqID) error
+ Close(boruta.ReqID) error
// Run starts job performing the request on the worker.
- Run(ReqID, WorkerUUID) error
+ Run(boruta.ReqID, boruta.WorkerUUID) error
}
diff --git a/matcher/timeoutmatcher.go b/matcher/timeoutmatcher.go
index c4c6809..5f79680 100644
--- a/matcher/timeoutmatcher.go
+++ b/matcher/timeoutmatcher.go
@@ -21,7 +21,7 @@
package matcher
import (
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// TimeoutMatcher implements Matcher interface for handling running requests
@@ -43,7 +43,7 @@ func NewTimeoutMatcher(r RequestsManager) *TimeoutMatcher {
// matcher. Close method is called on RequestsManager for each request.
// Some of the cases might be invalid, because the request's state has been changed
// to DONE or FAILED. Verification of closing conditions is done inside Close method.
-func (m TimeoutMatcher) Notify(out []ReqID) {
+func (m TimeoutMatcher) Notify(out []boruta.ReqID) {
for _, r := range out {
m.requests.Close(r)
}
diff --git a/matcher/validmatcher.go b/matcher/validmatcher.go
index c89abf1..e4cfd23 100644
--- a/matcher/validmatcher.go
+++ b/matcher/validmatcher.go
@@ -23,7 +23,7 @@ package matcher
import (
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// ValidMatcher implements Matcher interface for handling requests validation.
@@ -49,7 +49,7 @@ func NewValidMatcher(r RequestsManager, w WorkersManager, j JobsManager) *ValidM
// Notify implements Matcher interface. This method reacts on events passed to
// matcher. In this implementation requests' IDs are ignored as requests must be
// matched in order they are placed in requests priority queue.
-func (m ValidMatcher) Notify([]ReqID) {
+func (m ValidMatcher) Notify([]boruta.ReqID) {
// Repeat verification until iterateRequests() returns false indicating that
// there is no more job to be done.
for m.iterateRequests() {
@@ -96,7 +96,7 @@ func (m ValidMatcher) iterateRequests() bool {
// matchWorkers tries to find the best of the idle workers matching capabilities
// and groups of the requests. Best worker is the one with least matching penalty.
// If such worker is found a job is created and the request is processed.
-func (m ValidMatcher) matchWorkers(req ReqInfo) bool {
+func (m ValidMatcher) matchWorkers(req boruta.ReqInfo) bool {
worker, err := m.workers.TakeBestMatchingWorker(req.Owner.Groups, req.Caps)
if err != nil {
diff --git a/matcher/workersmanager.go b/matcher/workersmanager.go
index 64ad1ea..bd9c15b 100644
--- a/matcher/workersmanager.go
+++ b/matcher/workersmanager.go
@@ -23,7 +23,7 @@ import (
"crypto/rsa"
"net"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/workers"
)
@@ -31,22 +31,22 @@ import (
type WorkersManager interface {
// TakeBestMatchingWorker returns best matching worker that meets a criteria.
// An error is returned if no matching worker is found.
- TakeBestMatchingWorker(Groups, Capabilities) (WorkerUUID, error)
+ TakeBestMatchingWorker(boruta.Groups, boruta.Capabilities) (boruta.WorkerUUID, error)
// PrepareWorker makes it ready for running a job.
// Caller of this method can decide (with 2nd parameter) if key generation
// is required for preparing worker.
- PrepareWorker(worker WorkerUUID, withKeyGeneration bool) error
+ PrepareWorker(worker boruta.WorkerUUID, withKeyGeneration bool) error
// GetWorkerSSHAddr returns address of the ssh daemon on the worker that can
// be used for setting up tunnel to the worker. If there is no worker with
// given WorkerUUID an error is returned.
- GetWorkerSSHAddr(WorkerUUID) (net.TCPAddr, error)
+ GetWorkerSSHAddr(boruta.WorkerUUID) (net.TCPAddr, error)
// GetWorkerKey returns private RSA key of the worker that can be used for
// accessing the worker. If there is no worker with given WorkerUUID an error
// is returned.
- GetWorkerKey(WorkerUUID) (rsa.PrivateKey, error)
+ GetWorkerKey(boruta.WorkerUUID) (rsa.PrivateKey, error)
// SetChangeListener stores reference to object, which should be notified
// in case of changes of workers' states.
diff --git a/requests/queue.go b/requests/queue.go
index f91663b..6440cf8 100644
--- a/requests/queue.go
+++ b/requests/queue.go
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2017-2018 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.
@@ -23,7 +23,7 @@ import (
"container/list"
"sync"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// prioQueue is priority queue that stores request IDs.
@@ -41,22 +41,22 @@ type prioQueue struct {
// indicates if ID was found. False means that caller has iterated through
// all elements and pq.releaseIterator() followed by pq.initIterator()
// must be called in order to have a working iterator again.
- next func() (ReqID, bool)
+ next func() (boruta.ReqID, bool)
mtx *sync.Mutex
}
// _emptyIterator is helper function which always returns values which indicate
// that iterator should be initialized. It is desired to be set as next member of
// prioQueue structure whenever iterator needs initialization.
-func _emptyIterator() (ReqID, bool) { return ReqID(0), false }
+func _emptyIterator() (boruta.ReqID, bool) { return boruta.ReqID(0), false }
// newPrioQueue returns pointer to newly created and initialized priority queue.
func newPrioQueue() *prioQueue {
pq := new(prioQueue)
// Prepare queues.
- pq.queue = make([]*list.List, LoPrio+1)
- for i := HiPrio; i <= LoPrio; i++ {
+ pq.queue = make([]*list.List, boruta.LoPrio+1)
+ for i := boruta.HiPrio; i <= boruta.LoPrio; i++ {
pq.queue[i] = new(list.List).Init()
}
pq.length = 0
@@ -71,9 +71,9 @@ func newPrioQueue() *prioQueue {
// _remove removes request with given reqID from the queue. Caller must be sure
// that request with given ID exists in the queue otherwise function will panic.
// It's more convenient to use removeRequest().
-func (pq *prioQueue) _remove(reqID ReqID, priority Priority) {
+func (pq *prioQueue) _remove(reqID boruta.ReqID, priority boruta.Priority) {
for e := pq.queue[priority].Front(); e != nil; e = e.Next() {
- if e.Value.(ReqID) == reqID {
+ if e.Value.(boruta.ReqID) == reqID {
pq.length--
pq.queue[priority].Remove(e)
return
@@ -85,7 +85,7 @@ func (pq *prioQueue) _remove(reqID ReqID, priority Priority) {
// removeRequest removes request from the priority queue. It wraps _remove(),
// which will panic if request is missing from the queue and removeRequest will
// propagate this panic.
-func (pq *prioQueue) removeRequest(req *ReqInfo) {
+func (pq *prioQueue) removeRequest(req *boruta.ReqInfo) {
pq.mtx.Lock()
defer pq.mtx.Unlock()
pq._remove(req.ID, req.Priority)
@@ -93,13 +93,13 @@ func (pq *prioQueue) removeRequest(req *ReqInfo) {
// _push adds request ID at the end of priority queue. It's more convenient to use
// pushRequest().
-func (pq *prioQueue) _push(reqID ReqID, priority Priority) {
+func (pq *prioQueue) _push(reqID boruta.ReqID, priority boruta.Priority) {
pq.queue[priority].PushBack(reqID)
pq.length++
}
// pushRequest adds request to priority queue. It wraps _push().
-func (pq *prioQueue) pushRequest(req *ReqInfo) {
+func (pq *prioQueue) pushRequest(req *boruta.ReqInfo) {
pq.mtx.Lock()
defer pq.mtx.Unlock()
pq._push(req.ID, req.Priority)
@@ -108,7 +108,7 @@ func (pq *prioQueue) pushRequest(req *ReqInfo) {
// setRequestPriority modifies priority of request that was already added to the
// queue. Caller must make sure that request with given ID exists in the queue.
// Panic will occur if such ID doesn't exist.
-func (pq *prioQueue) setRequestPriority(req *ReqInfo, newPrio Priority) {
+func (pq *prioQueue) setRequestPriority(req *boruta.ReqInfo, newPrio boruta.Priority) {
pq.mtx.Lock()
defer pq.mtx.Unlock()
pq._remove(req.ID, req.Priority)
@@ -122,31 +122,31 @@ func (pq *prioQueue) setRequestPriority(req *ReqInfo, newPrio Priority) {
func (pq *prioQueue) initIterator() {
pq.mtx.Lock()
// current priority
- p := HiPrio
+ p := boruta.HiPrio
// current element of list for p priority
e := pq.queue[p].Front()
- pq.next = func() (id ReqID, ok bool) {
+ pq.next = func() (id boruta.ReqID, ok bool) {
// The queue is empty.
if pq.length == 0 {
- p = HiPrio
+ p = boruta.HiPrio
e = nil
- return ReqID(0), false
+ return boruta.ReqID(0), false
}
if e == nil {
// Find next priority.
- for p++; p <= LoPrio && pq.queue[p].Len() == 0; p++ {
+ for p++; p <= boruta.LoPrio && pq.queue[p].Len() == 0; p++ {
}
- if p > LoPrio {
- return ReqID(0), false
+ if p > boruta.LoPrio {
+ return boruta.ReqID(0), false
}
// Get it's first element.
e = pq.queue[p].Front()
}
- id, ok = e.Value.(ReqID), true
+ id, ok = e.Value.(boruta.ReqID), true
e = e.Next()
return
}
diff --git a/requests/queue_test.go b/requests/queue_test.go
index 6f7de75..874e1e1 100644
--- a/requests/queue_test.go
+++ b/requests/queue_test.go
@@ -22,54 +22,55 @@ package requests
import (
"testing"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"github.com/stretchr/testify/assert"
)
func TestRemovePanic(t *testing.T) {
assert := assert.New(t)
queue := newPrioQueue()
- assert.Panics(func() { queue._remove(ReqID(1), LoPrio) })
+ assert.Panics(func() { queue._remove(boruta.ReqID(1), boruta.LoPrio) })
}
func TestQueue(t *testing.T) {
assert := assert.New(t)
queue := newPrioQueue()
var reqs = []struct {
- id ReqID
- pr Priority
+ id boruta.ReqID
+ pr boruta.Priority
}{
- {ReqID(1), Priority(7)},
- {ReqID(2), Priority(1)},
- {ReqID(3), Priority(2)},
- {ReqID(4), Priority(12)},
- {ReqID(5), Priority(3)},
- {ReqID(6), Priority(3)},
+ {boruta.ReqID(1), boruta.Priority(7)},
+ {boruta.ReqID(2), boruta.Priority(1)},
+ {boruta.ReqID(3), boruta.Priority(2)},
+ {boruta.ReqID(4), boruta.Priority(12)},
+ {boruta.ReqID(5), boruta.Priority(3)},
+ {boruta.ReqID(6), boruta.Priority(3)},
}
- sorted := []ReqID{ReqID(2), ReqID(3), ReqID(5), ReqID(6), ReqID(1), ReqID(4)}
+ sorted := []boruta.ReqID{boruta.ReqID(2), boruta.ReqID(3), boruta.ReqID(5), boruta.ReqID(6),
+ boruta.ReqID(1), boruta.ReqID(4)}
// Test for empty queue.
reqid, ok := queue.next()
assert.False(ok)
- assert.Equal(ReqID(0), reqid)
+ assert.Equal(boruta.ReqID(0), reqid)
// Test if iterator was initialized and queue is empty.
queue.initIterator()
reqid, ok = queue.next()
assert.False(ok)
- assert.Equal(ReqID(0), reqid)
+ assert.Equal(boruta.ReqID(0), reqid)
queue.releaseIterator()
req := requestsTests[0].req
// Push requests to the queue.
for _, r := range reqs {
- queue.pushRequest(&ReqInfo{
+ queue.pushRequest(&boruta.ReqInfo{
ID: r.id,
Priority: r.pr,
Owner: req.Owner,
Deadline: req.Deadline,
ValidAfter: req.ValidAfter,
- State: WAIT,
+ State: boruta.WAIT,
Caps: req.Caps,
})
}
@@ -85,7 +86,7 @@ func TestQueue(t *testing.T) {
// Check if call to next() after iterating through whole queue returns false.
reqid, ok = queue.next()
assert.False(ok)
- assert.Equal(ReqID(0), reqid)
+ assert.Equal(boruta.ReqID(0), reqid)
queue.releaseIterator()
// Check if after another initialization next() returns first element.
@@ -98,5 +99,5 @@ func TestQueue(t *testing.T) {
queue.releaseIterator()
reqid, ok = queue.next()
assert.False(ok)
- assert.Equal(ReqID(0), reqid)
+ assert.Equal(boruta.ReqID(0), reqid)
}
diff --git a/requests/requests.go b/requests/requests.go
index 952c55a..2e42061 100644
--- a/requests/requests.go
+++ b/requests/requests.go
@@ -23,14 +23,14 @@ import (
"sync"
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/matcher"
)
// ReqsCollection contains information (also historical) about handled requests.
// It implements Requests, RequestsManager and WorkerChange interfaces.
type ReqsCollection struct {
- requests map[ReqID]*ReqInfo
+ requests map[boruta.ReqID]*boruta.ReqInfo
queue *prioQueue
mutex *sync.RWMutex
iterating bool
@@ -47,7 +47,7 @@ type ReqsCollection struct {
// NewRequestQueue provides initialized priority queue for requests.
func NewRequestQueue(w matcher.WorkersManager, j matcher.JobsManager) *ReqsCollection {
r := &ReqsCollection{
- requests: make(map[ReqID]*ReqInfo),
+ requests: make(map[boruta.ReqID]*boruta.ReqInfo),
queue: newPrioQueue(),
mutex: new(sync.RWMutex),
workers: w,
@@ -82,17 +82,17 @@ func (reqs *ReqsCollection) Finish() {
// NewRequest is part of implementation of Requests interface. It validates
// provided arguments and creates request or returns an error. Caller must make
// sure that provided time values are in UTC.
-func (reqs *ReqsCollection) NewRequest(caps Capabilities,
- priority Priority, owner UserInfo, validAfter time.Time,
- deadline time.Time) (ReqID, error) {
+func (reqs *ReqsCollection) NewRequest(caps boruta.Capabilities,
+ priority boruta.Priority, owner boruta.UserInfo, validAfter time.Time,
+ deadline time.Time) (boruta.ReqID, error) {
- req := &ReqInfo{
- ID: ReqID(len(reqs.requests) + 1),
+ req := &boruta.ReqInfo{
+ ID: boruta.ReqID(len(reqs.requests) + 1),
Priority: priority,
Owner: owner,
Deadline: deadline,
ValidAfter: validAfter,
- State: WAIT,
+ State: boruta.WAIT,
Caps: caps,
}
@@ -114,7 +114,7 @@ func (reqs *ReqsCollection) NewRequest(caps Capabilities,
}
// TODO(mwereski): Check if user has rights to set given priority.
- if req.Priority < HiPrio || req.Priority > LoPrio {
+ if req.Priority < boruta.HiPrio || req.Priority > boruta.LoPrio {
return 0, ErrPriority
}
@@ -135,10 +135,10 @@ func (reqs *ReqsCollection) NewRequest(caps Capabilities,
// It is used by both Close and CloseRequest methods after verification that
// all required conditions to close request are met.
// The method must be called in reqs.mutex critical section.
-func (reqs *ReqsCollection) closeRequest(req *ReqInfo) {
+func (reqs *ReqsCollection) closeRequest(req *boruta.ReqInfo) {
worker := req.Job.WorkerUUID
reqs.jobs.Finish(worker)
- req.State = DONE
+ req.State = boruta.DONE
}
// CloseRequest is part of implementation of Requests interface.
@@ -146,18 +146,18 @@ func (reqs *ReqsCollection) closeRequest(req *ReqInfo) {
// in INPROGRESS state and changes it to DONE. NotFoundError may be returned
// if request with given reqID doesn't exist in the queue
// or ErrModificationForbidden if request is in state which can't be closed.
-func (reqs *ReqsCollection) CloseRequest(reqID ReqID) error {
+func (reqs *ReqsCollection) CloseRequest(reqID boruta.ReqID) error {
reqs.mutex.Lock()
defer reqs.mutex.Unlock()
req, ok := reqs.requests[reqID]
if !ok {
- return NotFoundError("Request")
+ return boruta.NotFoundError("Request")
}
switch req.State {
- case WAIT:
- req.State = CANCEL
+ case boruta.WAIT:
+ req.State = boruta.CANCEL
reqs.queue.removeRequest(req)
- case INPROGRESS:
+ case boruta.INPROGRESS:
reqs.closeRequest(req)
default:
return ErrModificationForbidden
@@ -167,8 +167,8 @@ func (reqs *ReqsCollection) CloseRequest(reqID ReqID) error {
// modificationPossible is simple helper function that checks if it is possible
// to modify request it given state.
-func modificationPossible(state ReqState) bool {
- return state == WAIT
+func modificationPossible(state boruta.ReqState) bool {
+ return state == boruta.WAIT
}
// UpdateRequest is part of implementation of Requests interface. It may be used
@@ -176,8 +176,8 @@ func modificationPossible(state ReqState) bool {
// pointer to new ReqInfo struct which has any of these fields set. Zero value
// means that field shouldn't be changed. All fields that cannot be changed are
// ignored.
-func (reqs *ReqsCollection) UpdateRequest(src *ReqInfo) error {
- if src == nil || (src.Priority == Priority(0) &&
+func (reqs *ReqsCollection) UpdateRequest(src *boruta.ReqInfo) error {
+ if src == nil || (src.Priority == boruta.Priority(0) &&
src.ValidAfter.IsZero() &&
src.Deadline.IsZero()) {
return nil
@@ -196,13 +196,13 @@ func (reqs *ReqsCollection) UpdateRequest(src *ReqInfo) error {
}
// updateRequest is a part of UpdateRequest implementation run in critical section.
-func (reqs *ReqsCollection) updateRequest(src *ReqInfo) (validAfterTime, deadlineTime *requestTime, err error) {
+func (reqs *ReqsCollection) updateRequest(src *boruta.ReqInfo) (validAfterTime, deadlineTime *requestTime, err error) {
reqs.mutex.Lock()
defer reqs.mutex.Unlock()
dst, ok := reqs.requests[src.ID]
if !ok {
- err = NotFoundError("Request")
+ err = boruta.NotFoundError("Request")
return
}
if !modificationPossible(dst.State) {
@@ -215,8 +215,8 @@ func (reqs *ReqsCollection) updateRequest(src *ReqInfo) (validAfterTime, deadlin
return
}
// TODO(mwereski): Check if user has rights to set given priority.
- if src.Priority != Priority(0) && (src.Priority < HiPrio ||
- src.Priority > LoPrio) {
+ if src.Priority != boruta.Priority(0) && (src.Priority < boruta.HiPrio ||
+ src.Priority > boruta.LoPrio) {
err = ErrPriority
return
}
@@ -234,7 +234,7 @@ func (reqs *ReqsCollection) updateRequest(src *ReqInfo) (validAfterTime, deadlin
return
}
- if src.Priority != Priority(0) {
+ if src.Priority != boruta.Priority(0) {
reqs.queue.setRequestPriority(dst, src.Priority)
dst.Priority = src.Priority
}
@@ -252,7 +252,7 @@ func (reqs *ReqsCollection) updateRequest(src *ReqInfo) (validAfterTime, deadlin
// GetRequestInfo is part of implementation of Requests interface. It returns
// ReqInfo for given request ID or NotFoundError if request with given ID doesn't
// exits in the collection.
-func (reqs *ReqsCollection) GetRequestInfo(reqID ReqID) (ReqInfo, error) {
+func (reqs *ReqsCollection) GetRequestInfo(reqID boruta.ReqID) (boruta.ReqInfo, error) {
reqs.mutex.RLock()
defer reqs.mutex.RUnlock()
return reqs.Get(reqID)
@@ -260,9 +260,9 @@ func (reqs *ReqsCollection) GetRequestInfo(reqID ReqID) (ReqInfo, error) {
// ListRequests is part of implementation of Requests interface. It returns slice
// of ReqInfo that matches ListFilter. Returned slice is sorted by request ids.
-func (reqs *ReqsCollection) ListRequests(filter ListFilter) ([]ReqInfo, error) {
+func (reqs *ReqsCollection) ListRequests(filter boruta.ListFilter) ([]boruta.ReqInfo, error) {
reqs.mutex.RLock()
- res := make([]ReqInfo, 0, len(reqs.requests))
+ res := make([]boruta.ReqInfo, 0, len(reqs.requests))
for _, req := range reqs.requests {
if filter == nil || reflect.ValueOf(filter).IsNil() ||
filter.Match(req) {
@@ -279,20 +279,20 @@ func (reqs *ReqsCollection) ListRequests(filter ListFilter) ([]ReqInfo, error) {
// AcquireWorker is part of implementation of Requests interface. When worker is
// assigned to the requests then owner of such requests may call AcquireWorker
// to get all information required to use assigned worker.
-func (reqs *ReqsCollection) AcquireWorker(reqID ReqID) (AccessInfo, error) {
+func (reqs *ReqsCollection) AcquireWorker(reqID boruta.ReqID) (boruta.AccessInfo, error) {
reqs.mutex.RLock()
defer reqs.mutex.RUnlock()
req, ok := reqs.requests[reqID]
if !ok {
- return AccessInfo{}, NotFoundError("Request")
+ return boruta.AccessInfo{}, boruta.NotFoundError("Request")
}
- if req.State != INPROGRESS || req.Job == nil {
- return AccessInfo{}, ErrWorkerNotAssigned
+ if req.State != boruta.INPROGRESS || req.Job == nil {
+ return boruta.AccessInfo{}, ErrWorkerNotAssigned
}
job, err := reqs.jobs.Get(req.Job.WorkerUUID)
if err != nil {
- return AccessInfo{}, err
+ return boruta.AccessInfo{}, err
}
return job.Access, nil
}
@@ -300,14 +300,14 @@ func (reqs *ReqsCollection) AcquireWorker(reqID ReqID) (AccessInfo, error) {
// ProlongAccess is part of implementation of Requests interface. When owner of
// the request has acquired worker that to extend time for which the worker is
// assigned to the request.
-func (reqs *ReqsCollection) ProlongAccess(reqID ReqID) error {
+func (reqs *ReqsCollection) ProlongAccess(reqID boruta.ReqID) error {
reqs.mutex.RLock()
defer reqs.mutex.RUnlock()
req, ok := reqs.requests[reqID]
if !ok {
- return NotFoundError("Request")
+ return boruta.NotFoundError("Request")
}
- if req.State != INPROGRESS || req.Job == nil {
+ if req.State != boruta.INPROGRESS || req.Job == nil {
return ErrWorkerNotAssigned
}
@@ -327,7 +327,7 @@ func (reqs *ReqsCollection) InitIteration() error {
reqs.mutex.Lock()
if reqs.iterating {
reqs.mutex.Unlock()
- return ErrInternalLogicError
+ return boruta.ErrInternalLogicError
}
reqs.queue.initIterator()
reqs.iterating = true
@@ -348,7 +348,7 @@ func (reqs *ReqsCollection) TerminateIteration() {
// Next gets next ID from request queue. Method returns {ID, true} if there is
// pending request or {ReqID(0), false} if queue's end has been reached.
// It is part of implementation of RequestsManager interface.
-func (reqs *ReqsCollection) Next() (ReqID, bool) {
+func (reqs *ReqsCollection) Next() (boruta.ReqID, bool) {
if reqs.iterating {
return reqs.queue.next()
}
@@ -357,34 +357,34 @@ func (reqs *ReqsCollection) Next() (ReqID, bool) {
// VerifyIfReady checks if the request is ready to be run on worker.
// It is part of implementation of RequestsManager interface.
-func (reqs *ReqsCollection) VerifyIfReady(rid ReqID, now time.Time) bool {
+func (reqs *ReqsCollection) VerifyIfReady(rid boruta.ReqID, now time.Time) bool {
req, ok := reqs.requests[rid]
- return ok && req.State == WAIT && req.Deadline.After(now) && !req.ValidAfter.After(now)
+ return ok && req.State == boruta.WAIT && req.Deadline.After(now) && !req.ValidAfter.After(now)
}
// Get retrieves request's information structure for request with given ID.
// It is part of implementation of RequestsManager interface.
-func (reqs *ReqsCollection) Get(rid ReqID) (ReqInfo, error) {
+func (reqs *ReqsCollection) Get(rid boruta.ReqID) (boruta.ReqInfo, error) {
req, ok := reqs.requests[rid]
if !ok {
- return ReqInfo{}, NotFoundError("Request")
+ return boruta.ReqInfo{}, boruta.NotFoundError("Request")
}
return *req, nil
}
// Timeout sets request to TIMEOUT state after Deadline time is exceeded.
// It is part of implementation of RequestsManager interface.
-func (reqs *ReqsCollection) Timeout(rid ReqID) error {
+func (reqs *ReqsCollection) Timeout(rid boruta.ReqID) error {
reqs.mutex.Lock()
defer reqs.mutex.Unlock()
req, ok := reqs.requests[rid]
if !ok {
- return NotFoundError("Request")
+ return boruta.NotFoundError("Request")
}
- if req.State != WAIT || req.Deadline.After(time.Now()) {
+ if req.State != boruta.WAIT || req.Deadline.After(time.Now()) {
return ErrModificationForbidden
}
- req.State = TIMEOUT
+ req.State = boruta.TIMEOUT
reqs.queue.removeRequest(req)
return nil
}
@@ -392,20 +392,20 @@ func (reqs *ReqsCollection) Timeout(rid ReqID) error {
// Close verifies if request time has been exceeded and if so closes it.
// If request is still valid to continue it's job an error is returned.
// It is part of implementation of RequestsManager interface.
-func (reqs *ReqsCollection) Close(reqID ReqID) error {
+func (reqs *ReqsCollection) Close(reqID boruta.ReqID) error {
reqs.mutex.Lock()
defer reqs.mutex.Unlock()
req, ok := reqs.requests[reqID]
if !ok {
- return NotFoundError("Request")
+ return boruta.NotFoundError("Request")
}
- if req.State != INPROGRESS {
+ if req.State != boruta.INPROGRESS {
return ErrModificationForbidden
}
if req.Job == nil {
// TODO log a critical logic error. Job should be assigned to the request
// in INPROGRESS state.
- return ErrInternalLogicError
+ return boruta.ErrInternalLogicError
}
if req.Job.Timeout.After(time.Now()) {
// Request prolonged not yet ready to be closed because of timeout.
@@ -419,18 +419,18 @@ func (reqs *ReqsCollection) Close(reqID ReqID) error {
// Run starts job performing the request on the worker.
// It is part of implementation of RequestsManager interface.
-func (reqs *ReqsCollection) Run(rid ReqID, worker WorkerUUID) error {
+func (reqs *ReqsCollection) Run(rid boruta.ReqID, worker boruta.WorkerUUID) error {
req, ok := reqs.requests[rid]
if !ok {
- return NotFoundError("Request")
+ return boruta.NotFoundError("Request")
}
- if req.State != WAIT {
+ if req.State != boruta.WAIT {
return ErrModificationForbidden
}
- req.State = INPROGRESS
+ req.State = boruta.INPROGRESS
- req.Job = &JobInfo{WorkerUUID: worker}
+ req.Job = &boruta.JobInfo{WorkerUUID: worker}
if reqs.iterating {
reqs.queue.releaseIterator()
@@ -448,12 +448,12 @@ func (reqs *ReqsCollection) Run(rid ReqID, worker WorkerUUID) error {
}
// OnWorkerIdle triggers ValidMatcher to rematch requests with idle worker.
-func (reqs *ReqsCollection) OnWorkerIdle(worker WorkerUUID) {
+func (reqs *ReqsCollection) OnWorkerIdle(worker boruta.WorkerUUID) {
reqs.validAfterTimes.insert(requestTime{time: time.Now()})
}
// OnWorkerFail sets request being processed by failed worker into FAILED state.
-func (reqs *ReqsCollection) OnWorkerFail(worker WorkerUUID) {
+func (reqs *ReqsCollection) OnWorkerFail(worker boruta.WorkerUUID) {
reqs.mutex.Lock()
defer reqs.mutex.Unlock()
@@ -468,5 +468,5 @@ func (reqs *ReqsCollection) OnWorkerFail(worker WorkerUUID) {
panic("request related to job not found")
}
reqs.jobs.Finish(worker)
- req.State = FAILED
+ req.State = boruta.FAILED
}
diff --git a/requests/requests_requestsmanager_test.go b/requests/requests_requestsmanager_test.go
index 6743cb8..67db785 100644
--- a/requests/requests_requestsmanager_test.go
+++ b/requests/requests_requestsmanager_test.go
@@ -22,7 +22,7 @@ import (
"errors"
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
gomock "github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
@@ -79,7 +79,7 @@ var _ = Describe("Requests as RequestsManager", func() {
R.mutex.Unlock()
err := R.InitIteration()
- Expect(err).To(Equal(ErrInternalLogicError))
+ Expect(err).To(Equal(boruta.ErrInternalLogicError))
// Verify that mutex is not locked.
go testMutex()
@@ -110,13 +110,13 @@ var _ = Describe("Requests as RequestsManager", func() {
})
})
Describe("Iterating over requests", func() {
- verify := []ReqID{3, 5, 1, 2, 7, 4, 6}
+ verify := []boruta.ReqID{3, 5, 1, 2, 7, 4, 6}
BeforeEach(func() {
now := time.Now()
tomorrow := now.AddDate(0, 0, 1)
- wm.EXPECT().TakeBestMatchingWorker(gomock.Any(), gomock.Any()).Return(WorkerUUID(""), testErr).AnyTimes()
- insert := func(p Priority) {
- _, err := R.NewRequest(Capabilities{}, p, UserInfo{}, now, tomorrow)
+ wm.EXPECT().TakeBestMatchingWorker(gomock.Any(), gomock.Any()).Return(boruta.WorkerUUID(""), testErr).AnyTimes()
+ insert := func(p boruta.Priority) {
+ _, err := R.NewRequest(boruta.Capabilities{}, p, boruta.UserInfo{}, now, tomorrow)
Expect(err).NotTo(HaveOccurred())
}
insert(3) //1
@@ -128,7 +128,7 @@ var _ = Describe("Requests as RequestsManager", func() {
insert(3) //7
})
It("should properly iterate over requests", func() {
- reqs := make([]ReqID, 0)
+ reqs := make([]boruta.ReqID, 0)
R.InitIteration()
for r, ok := R.Next(); ok; r, ok = R.Next() {
@@ -140,7 +140,7 @@ var _ = Describe("Requests as RequestsManager", func() {
})
It("should restart iterations in new critical section", func() {
for times := 0; times < len(verify); times++ {
- reqs := make([]ReqID, 0)
+ reqs := make([]boruta.ReqID, 0)
i := 0
R.InitIteration()
for r, ok := R.Next(); ok && i < times; r, ok = R.Next() {
@@ -162,14 +162,14 @@ var _ = Describe("Requests as RequestsManager", func() {
})
Describe("With request in the queue", func() {
var now, tomorrow time.Time
- var req, noreq ReqID
- var rinfo *ReqInfo
+ var req, noreq boruta.ReqID
+ var rinfo *boruta.ReqInfo
BeforeEach(func() {
now = time.Now()
tomorrow = now.AddDate(0, 0, 1)
- wm.EXPECT().TakeBestMatchingWorker(gomock.Any(), gomock.Any()).Return(WorkerUUID(""), testErr).AnyTimes()
+ wm.EXPECT().TakeBestMatchingWorker(gomock.Any(), gomock.Any()).Return(boruta.WorkerUUID(""), testErr).AnyTimes()
var err error
- req, err = R.NewRequest(Capabilities{}, 3, UserInfo{}, now, tomorrow)
+ req, err = R.NewRequest(boruta.Capabilities{}, 3, boruta.UserInfo{}, now, tomorrow)
Expect(err).NotTo(HaveOccurred())
var ok bool
R.mutex.Lock()
@@ -183,7 +183,8 @@ var _ = Describe("Requests as RequestsManager", func() {
Expect(R.VerifyIfReady(noreq, now)).To(BeFalse())
})
It("should fail if state is not WAIT", func() {
- states := []ReqState{INPROGRESS, CANCEL, TIMEOUT, INVALID, DONE, FAILED}
+ states := []boruta.ReqState{boruta.INPROGRESS, boruta.CANCEL, boruta.TIMEOUT, boruta.INVALID,
+ boruta.DONE, boruta.FAILED}
for _, s := range states {
R.mutex.Lock()
rinfo.State = s
@@ -208,8 +209,8 @@ var _ = Describe("Requests as RequestsManager", func() {
Describe("Get", func() {
It("should fail if reqID is unknown", func() {
r, err := R.Get(noreq)
- Expect(err).To(Equal(NotFoundError("Request")))
- Expect(r).To(Equal(ReqInfo{}))
+ Expect(err).To(Equal(boruta.NotFoundError("Request")))
+ Expect(r).To(Equal(boruta.ReqInfo{}))
})
It("should succeed if reqID is valid", func() {
r, err := R.Get(req)
@@ -221,7 +222,7 @@ var _ = Describe("Requests as RequestsManager", func() {
It("should fail if reqID is unknown", func() {
Expect(R.queue.length).To(Equal(uint(1)))
err := R.Timeout(noreq)
- Expect(err).To(Equal(NotFoundError("Request")))
+ Expect(err).To(Equal(boruta.NotFoundError("Request")))
Expect(R.queue.length).To(Equal(uint(1)))
})
It("should fail if request is not in WAIT state", func() {
@@ -229,7 +230,8 @@ var _ = Describe("Requests as RequestsManager", func() {
rinfo.Deadline = now.Add(-time.Hour)
R.mutex.Unlock()
Expect(R.queue.length).To(Equal(uint(1)))
- states := []ReqState{INPROGRESS, CANCEL, TIMEOUT, INVALID, DONE, FAILED}
+ states := []boruta.ReqState{boruta.INPROGRESS, boruta.CANCEL, boruta.TIMEOUT, boruta.INVALID,
+ boruta.DONE, boruta.FAILED}
for _, s := range states {
R.mutex.Lock()
rinfo.State = s
@@ -252,17 +254,18 @@ var _ = Describe("Requests as RequestsManager", func() {
Expect(R.queue.length).To(Equal(uint(1)))
err := R.Timeout(req)
Expect(err).NotTo(HaveOccurred())
- Expect(rinfo.State).To(Equal(TIMEOUT))
+ Expect(rinfo.State).To(Equal(boruta.TIMEOUT))
Expect(R.queue.length).To(BeZero())
})
})
Describe("Close", func() {
It("should fail if reqID is unknown", func() {
err := R.Close(noreq)
- Expect(err).To(Equal(NotFoundError("Request")))
+ Expect(err).To(Equal(boruta.NotFoundError("Request")))
})
It("should fail if request is not in INPROGRESS state", func() {
- states := []ReqState{WAIT, CANCEL, TIMEOUT, INVALID, DONE, FAILED}
+ states := []boruta.ReqState{boruta.WAIT, boruta.CANCEL, boruta.TIMEOUT, boruta.INVALID,
+ boruta.DONE, boruta.FAILED}
for _, state := range states {
R.mutex.Lock()
rinfo.State = state
@@ -274,17 +277,17 @@ var _ = Describe("Requests as RequestsManager", func() {
})
It("should fail if request has no job assigned", func() {
R.mutex.Lock()
- rinfo.State = INPROGRESS
+ rinfo.State = boruta.INPROGRESS
Expect(rinfo.Job).To(BeNil())
R.mutex.Unlock()
err := R.Close(req)
- Expect(err).To(Equal(ErrInternalLogicError))
+ Expect(err).To(Equal(boruta.ErrInternalLogicError))
})
It("should fail if job's is not yet timed out", func() {
R.mutex.Lock()
- rinfo.State = INPROGRESS
- rinfo.Job = &JobInfo{
+ rinfo.State = boruta.INPROGRESS
+ rinfo.Job = &boruta.JobInfo{
Timeout: time.Now().AddDate(0, 0, 1),
}
R.mutex.Unlock()
@@ -293,10 +296,10 @@ var _ = Describe("Requests as RequestsManager", func() {
Expect(err).To(Equal(ErrModificationForbidden))
})
It("should close request and release worker", func() {
- testWorker := WorkerUUID("TestWorker")
+ testWorker := boruta.WorkerUUID("TestWorker")
R.mutex.Lock()
- rinfo.State = INPROGRESS
- rinfo.Job = &JobInfo{
+ rinfo.State = boruta.INPROGRESS
+ rinfo.Job = &boruta.JobInfo{
Timeout: time.Now().AddDate(0, 0, -1),
WorkerUUID: testWorker,
}
@@ -306,18 +309,18 @@ var _ = Describe("Requests as RequestsManager", func() {
)
err := R.Close(req)
Expect(err).NotTo(HaveOccurred())
- Expect(rinfo.State).To(Equal(DONE))
+ Expect(rinfo.State).To(Equal(boruta.DONE))
})
})
Describe("Run", func() {
- testWorker := WorkerUUID("TestWorker")
+ testWorker := boruta.WorkerUUID("TestWorker")
It("should fail if reqID is unknown", func() {
R.mutex.Lock()
defer R.mutex.Unlock()
Expect(R.queue.length).To(Equal(uint(1)))
err := R.Run(noreq, testWorker)
- Expect(err).To(Equal(NotFoundError("Request")))
+ Expect(err).To(Equal(boruta.NotFoundError("Request")))
Expect(R.queue.length).To(Equal(uint(1)))
})
It("should fail if reqID is unknown during iteration", func() {
@@ -326,17 +329,18 @@ var _ = Describe("Requests as RequestsManager", func() {
Expect(R.iterating).To(BeTrue())
Expect(R.queue.length).To(Equal(uint(1)))
err := R.Run(noreq, testWorker)
- Expect(err).To(Equal(NotFoundError("Request")))
+ Expect(err).To(Equal(boruta.NotFoundError("Request")))
Expect(R.iterating).To(BeTrue())
Expect(R.queue.length).To(Equal(uint(1)))
})
It("should fail if request is not in WAIT state", func() {
- states := []ReqState{INPROGRESS, CANCEL, TIMEOUT, INVALID, DONE, FAILED}
+ states := []boruta.ReqState{boruta.INPROGRESS, boruta.CANCEL, boruta.TIMEOUT, boruta.INVALID,
+ boruta.DONE, boruta.FAILED}
for _, state := range states {
R.InitIteration()
Expect(R.queue.length).To(Equal(uint(1)), "state = %s", state)
rinfo.State = state
- err := R.Run(req, WorkerUUID("TestWorker"))
+ err := R.Run(req, boruta.WorkerUUID("TestWorker"))
Expect(err).To(Equal(ErrModificationForbidden), "state = %s", state)
Expect(R.queue.length).To(Equal(uint(1)), "state = %s", state)
R.TerminateIteration()
@@ -348,7 +352,7 @@ var _ = Describe("Requests as RequestsManager", func() {
Expect(R.queue.length).To(Equal(uint(1)))
err := R.Run(req, testWorker)
Expect(err).NotTo(HaveOccurred())
- Expect(rinfo.State).To(Equal(INPROGRESS))
+ Expect(rinfo.State).To(Equal(boruta.INPROGRESS))
Expect(rinfo.Job.Timeout).To(BeTemporally(">", time.Now()))
Expect(R.queue.length).To(BeZero())
})
@@ -359,7 +363,7 @@ var _ = Describe("Requests as RequestsManager", func() {
Expect(R.iterating).To(BeTrue())
err := R.Run(req, testWorker)
Expect(err).NotTo(HaveOccurred())
- Expect(rinfo.State).To(Equal(INPROGRESS))
+ Expect(rinfo.State).To(Equal(boruta.INPROGRESS))
Expect(rinfo.Job.Timeout).To(BeTemporally(">", time.Now()))
Expect(R.iterating).To(BeFalse())
Expect(R.queue.length).To(BeZero())
diff --git a/requests/requests_test.go b/requests/requests_test.go
index 993d2c2..3405a04 100644
--- a/requests/requests_test.go
+++ b/requests/requests_test.go
@@ -22,44 +22,80 @@ import (
"testing"
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/workers"
gomock "github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)
var (
- owner UserInfo
- job JobInfo
+ owner boruta.UserInfo
+ job boruta.JobInfo
zeroTime time.Time
- caps = make(Capabilities)
+ caps = make(boruta.Capabilities)
now = time.Now().UTC()
yesterday = now.AddDate(0, 0, -1).UTC()
tomorrow = now.AddDate(0, 0, 1).UTC()
)
var requestsTests = [...]struct {
- req ReqInfo
+ req boruta.ReqInfo
err error
}{
{
// valid request
- req: ReqInfo{ReqID(1), Priority((HiPrio + LoPrio) / 2), owner, tomorrow, now, WAIT, &job, caps},
+ req: boruta.ReqInfo{
+ ID: boruta.ReqID(1),
+ Priority: boruta.Priority((boruta.HiPrio + boruta.LoPrio) / 2),
+ Owner: owner,
+ Deadline: tomorrow,
+ ValidAfter: now,
+ State: boruta.WAIT,
+ Job: &job,
+ Caps: caps,
+ },
err: nil,
},
{
// request with invalid priority
- req: ReqInfo{ReqID(0), Priority(LoPrio + 1), owner, tomorrow, now, WAIT, &job, caps},
+ req: boruta.ReqInfo{
+ ID: boruta.ReqID(0),
+ Priority: boruta.Priority(boruta.LoPrio + 1),
+ Owner: owner,
+ Deadline: tomorrow,
+ ValidAfter: now,
+ State: boruta.WAIT,
+ Job: &job,
+ Caps: caps,
+ },
err: ErrPriority,
},
{
// request with ValidAfter date newer then Deadline
- req: ReqInfo{ReqID(0), Priority((HiPrio + LoPrio) / 2), owner, now.Add(time.Hour), tomorrow, WAIT, &job, caps},
+ req: boruta.ReqInfo{
+ ID: boruta.ReqID(0),
+ Priority: boruta.Priority((boruta.HiPrio + boruta.LoPrio) / 2),
+ Owner: owner,
+ Deadline: now.Add(time.Hour),
+ ValidAfter: tomorrow,
+ State: boruta.WAIT,
+ Job: &job,
+ Caps: caps,
+ },
err: ErrInvalidTimeRange,
},
{
// request with Deadline set in the past.
- req: ReqInfo{ReqID(0), Priority((HiPrio + LoPrio) / 2), owner, yesterday, now, WAIT, &job, caps},
+ req: boruta.ReqInfo{
+ ID: boruta.ReqID(0),
+ Priority: boruta.Priority((boruta.HiPrio + boruta.LoPrio) / 2),
+ Owner: owner,
+ Deadline: yesterday,
+ ValidAfter: now,
+ State: boruta.WAIT,
+ Job: &job,
+ Caps: caps,
+ },
err: ErrDeadlineInThePast,
},
}
@@ -69,7 +105,8 @@ func initTest(t *testing.T) (*assert.Assertions, *ReqsCollection, *gomock.Contro
wm := NewMockWorkersManager(ctrl)
jm := NewMockJobsManager(ctrl)
testErr := errors.New("Test Error")
- wm.EXPECT().TakeBestMatchingWorker(gomock.Any(), gomock.Any()).Return(WorkerUUID(""), testErr).AnyTimes()
+ wm.EXPECT().TakeBestMatchingWorker(gomock.Any(), gomock.Any()).Return(boruta.WorkerUUID(""),
+ testErr).AnyTimes()
wm.EXPECT().SetChangeListener(gomock.Any())
return assert.New(t), NewRequestQueue(wm, jm), ctrl, jm
}
@@ -124,7 +161,7 @@ func TestCloseRequest(t *testing.T) {
defer finiTest(rqueue, ctrl)
req := requestsTests[0].req
- jobInfo := JobInfo{
+ jobInfo := boruta.JobInfo{
WorkerUUID: "Test WorkerUUID",
}
@@ -139,13 +176,13 @@ func TestCloseRequest(t *testing.T) {
err = rqueue.CloseRequest(reqid)
assert.Nil(err)
rqueue.mutex.RLock()
- assert.Equal(ReqState(CANCEL), rqueue.requests[reqid].State)
+ assert.Equal(boruta.ReqState(boruta.CANCEL), rqueue.requests[reqid].State)
assert.Zero(rqueue.queue.length)
rqueue.mutex.RUnlock()
// Try to close non-existent request.
- err = rqueue.CloseRequest(ReqID(2))
- assert.Equal(NotFoundError("Request"), err)
+ err = rqueue.CloseRequest(boruta.ReqID(2))
+ assert.Equal(boruta.NotFoundError("Request"), err)
// Add another valid request.
reqid, err = rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
@@ -155,7 +192,7 @@ func TestCloseRequest(t *testing.T) {
reqinfo, err := rqueue.GetRequestInfo(reqid)
assert.Nil(err)
rqueue.mutex.Lock()
- rqueue.requests[reqid].State = INPROGRESS
+ rqueue.requests[reqid].State = boruta.INPROGRESS
rqueue.requests[reqid].Job = &jobInfo
rqueue.queue.removeRequest(&reqinfo)
rqueue.mutex.Unlock()
@@ -167,11 +204,12 @@ func TestCloseRequest(t *testing.T) {
assert.Nil(err)
rqueue.mutex.RLock()
assert.EqualValues(2, len(rqueue.requests))
- assert.Equal(ReqState(DONE), rqueue.requests[reqid].State)
+ assert.Equal(boruta.ReqState(boruta.DONE), rqueue.requests[reqid].State)
rqueue.mutex.RUnlock()
// Simulation for the rest of states.
- states := [...]ReqState{INVALID, CANCEL, TIMEOUT, DONE, FAILED}
+ states := [...]boruta.ReqState{boruta.INVALID, boruta.CANCEL, boruta.TIMEOUT, boruta.DONE,
+ boruta.FAILED}
reqid, err = rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
assert.Nil(err)
assert.EqualValues(3, reqid)
@@ -207,7 +245,7 @@ func TestUpdateRequest(t *testing.T) {
rqueue.mutex.RUnlock()
reqBefore, err := rqueue.GetRequestInfo(reqid)
assert.Nil(err)
- reqUpdate := new(ReqInfo)
+ reqUpdate := new(boruta.ReqInfo)
rqueue.mutex.RLock()
*reqUpdate = *req
rqueue.mutex.RUnlock()
@@ -217,7 +255,7 @@ func TestUpdateRequest(t *testing.T) {
assert.Nil(err)
reqUpdate.ValidAfter = zeroTime
reqUpdate.Deadline = zeroTime
- reqUpdate.Priority = Priority(0)
+ reqUpdate.Priority = boruta.Priority(0)
err = rqueue.UpdateRequest(reqUpdate)
assert.Nil(err)
rqueue.mutex.RLock()
@@ -227,7 +265,7 @@ func TestUpdateRequest(t *testing.T) {
rqueue.mutex.RUnlock()
reqUpdate.ID++
err = rqueue.UpdateRequest(reqUpdate)
- assert.Equal(NotFoundError("Request"), err)
+ assert.Equal(boruta.NotFoundError("Request"), err)
rqueue.mutex.RLock()
reqUpdate.ID = req.ID
// Change Priority only.
@@ -255,7 +293,7 @@ func TestUpdateRequest(t *testing.T) {
// Change Priority, ValidAfter and Deadline.
reqUpdate.Deadline = tomorrow
reqUpdate.ValidAfter = time.Now().Add(time.Hour)
- reqUpdate.Priority = LoPrio
+ reqUpdate.Priority = boruta.LoPrio
err = rqueue.UpdateRequest(reqUpdate)
assert.Nil(err)
rqueue.mutex.RLock()
@@ -268,7 +306,7 @@ func TestUpdateRequest(t *testing.T) {
assert.Equal(reqUpdate, req)
rqueue.mutex.RUnlock()
// Change Priority to illegal value.
- reqUpdate.Priority = LoPrio + 1
+ reqUpdate.Priority = boruta.LoPrio + 1
err = rqueue.UpdateRequest(reqUpdate)
assert.Equal(ErrPriority, err)
rqueue.mutex.RLock()
@@ -288,7 +326,8 @@ func TestUpdateRequest(t *testing.T) {
err = rqueue.UpdateRequest(reqUpdate)
assert.Equal(ErrInvalidTimeRange, err)
// Try to change values for other changes.
- states := [...]ReqState{INVALID, CANCEL, TIMEOUT, DONE, FAILED, INPROGRESS}
+ states := [...]boruta.ReqState{boruta.INVALID, boruta.CANCEL, boruta.TIMEOUT, boruta.DONE,
+ boruta.FAILED, boruta.INPROGRESS}
for _, state := range states {
rqueue.mutex.Lock()
rqueue.requests[reqid].State = state
@@ -312,8 +351,8 @@ func TestGetRequestInfo(t *testing.T) {
assert.Equal(req, reqUpdate)
// Try to get information for non-existent request.
- req3, err := rqueue.GetRequestInfo(ReqID(2))
- assert.Equal(NotFoundError("Request"), err)
+ req3, err := rqueue.GetRequestInfo(boruta.ReqID(2))
+ assert.Equal(boruta.NotFoundError("Request"), err)
assert.Zero(req3)
}
@@ -322,7 +361,7 @@ type reqFilter struct {
priority string
}
-func (filter *reqFilter) Match(req *ReqInfo) bool {
+func (filter *reqFilter) Match(req *boruta.ReqInfo) bool {
if req == nil {
return false
}
@@ -346,8 +385,8 @@ func TestListRequests(t *testing.T) {
const reqsCnt = 4
// Add few requests.
- reqs := make(map[ReqID]bool, reqsCnt)
- noReqs := make(map[ReqID]bool)
+ reqs := make(map[boruta.ReqID]bool, reqsCnt)
+ noReqs := make(map[boruta.ReqID]bool)
for i := 0; i < reqsCnt; i++ {
reqid, err := rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
assert.Nil(err)
@@ -358,73 +397,73 @@ func TestListRequests(t *testing.T) {
}
if i > 1 {
rqueue.mutex.Lock()
- rqueue.requests[reqid].State = DONE
+ rqueue.requests[reqid].State = boruta.DONE
rqueue.mutex.Unlock()
}
reqs[reqid] = true
}
notFoundPrio := req.Priority - 1
- notFoundState := INVALID
+ notFoundState := boruta.INVALID
var filterTests = [...]struct {
filter reqFilter
- result map[ReqID]bool
+ result map[boruta.ReqID]bool
}{
{
filter: reqFilter{
- state: string(WAIT),
+ state: string(boruta.WAIT),
priority: req.Priority.String(),
},
- result: map[ReqID]bool{ReqID(1): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(1): true},
},
{
filter: reqFilter{
- state: string(WAIT),
+ state: string(boruta.WAIT),
priority: (req.Priority + 1).String(),
},
- result: map[ReqID]bool{ReqID(2): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(2): true},
},
{
filter: reqFilter{
- state: string(DONE),
+ state: string(boruta.DONE),
priority: req.Priority.String(),
},
- result: map[ReqID]bool{ReqID(3): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(3): true},
},
{
filter: reqFilter{
- state: string(DONE),
+ state: string(boruta.DONE),
priority: (req.Priority + 1).String(),
},
- result: map[ReqID]bool{ReqID(4): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(4): true},
},
{
filter: reqFilter{
state: "",
priority: req.Priority.String(),
},
- result: map[ReqID]bool{ReqID(1): true, ReqID(3): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(1): true, boruta.ReqID(3): true},
},
{
filter: reqFilter{
state: "",
priority: (req.Priority + 1).String(),
},
- result: map[ReqID]bool{ReqID(2): true, ReqID(4): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(2): true, boruta.ReqID(4): true},
},
{
filter: reqFilter{
- state: string(WAIT),
+ state: string(boruta.WAIT),
priority: "",
},
- result: map[ReqID]bool{ReqID(1): true, ReqID(2): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(1): true, boruta.ReqID(2): true},
},
{
filter: reqFilter{
- state: string(DONE),
+ state: string(boruta.DONE),
priority: "",
},
- result: map[ReqID]bool{ReqID(3): true, ReqID(4): true},
+ result: map[boruta.ReqID]bool{boruta.ReqID(3): true, boruta.ReqID(4): true},
},
{
filter: reqFilter{
@@ -442,7 +481,7 @@ func TestListRequests(t *testing.T) {
},
{
filter: reqFilter{
- state: string(WAIT),
+ state: string(boruta.WAIT),
priority: notFoundPrio.String(),
},
result: noReqs,
@@ -456,7 +495,7 @@ func TestListRequests(t *testing.T) {
},
}
- checkReqs := func(reqs map[ReqID]bool, resp []ReqInfo) {
+ checkReqs := func(reqs map[boruta.ReqID]bool, resp []boruta.ReqInfo) {
assert.Equal(len(reqs), len(resp))
for _, req := range resp {
assert.True(reqs[req.ID])
@@ -486,14 +525,15 @@ func TestAcquireWorker(t *testing.T) {
assert, rqueue, ctrl, jm := initTest(t)
defer finiTest(rqueue, ctrl)
req := requestsTests[0].req
- empty := AccessInfo{}
+ empty := boruta.AccessInfo{}
testErr := errors.New("Test Error")
// Add valid request.
reqid, err := rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
assert.Nil(err)
- states := [...]ReqState{WAIT, INVALID, CANCEL, TIMEOUT, DONE, FAILED, INPROGRESS}
+ states := [...]boruta.ReqState{boruta.WAIT, boruta.INVALID, boruta.CANCEL, boruta.TIMEOUT,
+ boruta.DONE, boruta.FAILED, boruta.INPROGRESS}
for _, state := range states {
rqueue.mutex.Lock()
rqueue.requests[reqid].State = state
@@ -504,18 +544,18 @@ func TestAcquireWorker(t *testing.T) {
}
// Try to acquire worker for non-existing request.
- ainfo, err := rqueue.AcquireWorker(ReqID(2))
- assert.Equal(NotFoundError("Request"), err)
+ ainfo, err := rqueue.AcquireWorker(boruta.ReqID(2))
+ assert.Equal(boruta.NotFoundError("Request"), err)
assert.Equal(empty, ainfo)
// Try to acquire worker when jobs.Get() fails.
- jobInfo := JobInfo{
+ jobInfo := boruta.JobInfo{
WorkerUUID: "Test WorkerUUID",
}
rqueue.mutex.Lock()
rqueue.requests[reqid].Job = &jobInfo
rqueue.mutex.Unlock()
- ignoredJob := &workers.Job{Req: ReqID(0xBAD)}
+ ignoredJob := &workers.Job{Req: boruta.ReqID(0xBAD)}
jm.EXPECT().Get(jobInfo.WorkerUUID).Return(ignoredJob, testErr)
ainfo, err = rqueue.AcquireWorker(reqid)
assert.Equal(testErr, err)
@@ -524,7 +564,7 @@ func TestAcquireWorker(t *testing.T) {
// AcquireWorker to succeed needs JobInfo to be set. It also needs to be
// in INPROGRESS state, which was set in the loop.
job := &workers.Job{
- Access: AccessInfo{Addr: &net.TCPAddr{IP: net.IPv4(1, 2, 3, 4)}},
+ Access: boruta.AccessInfo{Addr: &net.TCPAddr{IP: net.IPv4(1, 2, 3, 4)}},
}
rqueue.mutex.Lock()
rqueue.requests[reqid].Job = &jobInfo
@@ -544,7 +584,8 @@ func TestProlongAccess(t *testing.T) {
reqid, err := rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
assert.Nil(err)
- states := [...]ReqState{WAIT, INVALID, CANCEL, TIMEOUT, DONE, FAILED, INPROGRESS}
+ states := [...]boruta.ReqState{boruta.WAIT, boruta.INVALID, boruta.CANCEL, boruta.TIMEOUT,
+ boruta.DONE, boruta.FAILED, boruta.INPROGRESS}
for _, state := range states {
rqueue.mutex.Lock()
rqueue.requests[reqid].State = state
@@ -554,13 +595,13 @@ func TestProlongAccess(t *testing.T) {
}
// Try to prolong access of job for non-existing request.
- err = rqueue.ProlongAccess(ReqID(2))
- assert.Equal(NotFoundError("Request"), err)
+ err = rqueue.ProlongAccess(boruta.ReqID(2))
+ assert.Equal(boruta.NotFoundError("Request"), err)
// ProlongAccess to succeed needs JobInfo to be set. It also needs to be
// in INPROGRESS state, which was set in the loop.
rqueue.mutex.Lock()
- rqueue.requests[reqid].Job = new(JobInfo)
+ rqueue.requests[reqid].Job = new(boruta.JobInfo)
rqueue.mutex.Unlock()
err = rqueue.ProlongAccess(reqid)
assert.Nil(err)
diff --git a/requests/requests_workerchange_test.go b/requests/requests_workerchange_test.go
index 1ce2eb8..01b5024 100644
--- a/requests/requests_workerchange_test.go
+++ b/requests/requests_workerchange_test.go
@@ -20,7 +20,7 @@ import (
"errors"
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/workers"
gomock "github.com/golang/mock/gomock"
@@ -34,11 +34,11 @@ var _ = Describe("Requests as WorkerChange", func() {
var jm *MockJobsManager
var R *ReqsCollection
testErr := errors.New("Test Error")
- testWorker := WorkerUUID("Test Worker UUID")
- noWorker := WorkerUUID("")
- testCapabilities := Capabilities{"key": "value"}
- testPriority := (HiPrio + LoPrio) / 2
- testUser := UserInfo{Groups: []Group{"Test Group"}}
+ testWorker := boruta.WorkerUUID("Test Worker UUID")
+ noWorker := boruta.WorkerUUID("")
+ testCapabilities := boruta.Capabilities{"key": "value"}
+ testPriority := (boruta.HiPrio + boruta.LoPrio) / 2
+ testUser := boruta.UserInfo{Groups: []boruta.Group{"Test Group"}}
now := time.Now()
tomorrow := now.AddDate(0, 0, 1)
trigger := make(chan int, 1)
@@ -49,8 +49,8 @@ var _ = Describe("Requests as WorkerChange", func() {
eventuallyTrigger := func(val int) {
EventuallyWithOffset(1, trigger).Should(Receive(Equal(val)))
}
- eventuallyState := func(reqid ReqID, state ReqState) {
- EventuallyWithOffset(1, func() ReqState {
+ eventuallyState := func(reqid boruta.ReqID, state boruta.ReqState) {
+ EventuallyWithOffset(1, func() boruta.ReqState {
info, err := R.GetRequestInfo(reqid)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, info).NotTo(BeNil())
@@ -76,7 +76,7 @@ var _ = Describe("Requests as WorkerChange", func() {
})
It("ValidMatcher should try matching request", func() {
// Add Request. Use trigger to wait for ValidMatcher goroutine to match worker.
- wm.EXPECT().TakeBestMatchingWorker(testUser.Groups, testCapabilities).Return(noWorker, testErr).Do(func(Groups, Capabilities) {
+ wm.EXPECT().TakeBestMatchingWorker(testUser.Groups, testCapabilities).Return(noWorker, testErr).Do(func(boruta.Groups, boruta.Capabilities) {
setTrigger(1)
})
reqid, err := R.NewRequest(testCapabilities, testPriority, testUser, now, tomorrow)
@@ -85,7 +85,7 @@ var _ = Describe("Requests as WorkerChange", func() {
eventuallyTrigger(1)
// Test. Use trigger to wait for ValidMatcher goroutine to match worker.
- wm.EXPECT().TakeBestMatchingWorker(testUser.Groups, testCapabilities).Return(noWorker, testErr).Do(func(Groups, Capabilities) {
+ wm.EXPECT().TakeBestMatchingWorker(testUser.Groups, testCapabilities).Return(noWorker, testErr).Do(func(boruta.Groups, boruta.Capabilities) {
setTrigger(2)
})
R.OnWorkerIdle(testWorker)
@@ -100,7 +100,7 @@ var _ = Describe("Requests as WorkerChange", func() {
}).To(Panic())
})
It("should panic if failing worker was processing unknown Job", func() {
- noReq := ReqID(0)
+ noReq := boruta.ReqID(0)
job := workers.Job{Req: noReq}
jm.EXPECT().Get(testWorker).Return(&job, nil)
Expect(func() {
@@ -109,7 +109,7 @@ var _ = Describe("Requests as WorkerChange", func() {
})
It("should set request to FAILED state if call succeeds", func() {
// Add Request. Use trigger to wait for ValidMatcher goroutine to match worker.
- wm.EXPECT().TakeBestMatchingWorker(testUser.Groups, testCapabilities).Return(noWorker, testErr).Do(func(Groups, Capabilities) {
+ wm.EXPECT().TakeBestMatchingWorker(testUser.Groups, testCapabilities).Return(noWorker, testErr).Do(func(boruta.Groups, boruta.Capabilities) {
setTrigger(3)
})
reqid, err := R.NewRequest(testCapabilities, testPriority, testUser, now, tomorrow)
@@ -122,7 +122,7 @@ var _ = Describe("Requests as WorkerChange", func() {
jm.EXPECT().Get(testWorker).Return(&job, nil)
jm.EXPECT().Finish(testWorker)
R.OnWorkerFail(testWorker)
- eventuallyState(reqid, FAILED)
+ eventuallyState(reqid, boruta.FAILED)
})
})
})
diff --git a/requests/times.go b/requests/times.go
index 456f23f..9f98cc7 100644
--- a/requests/times.go
+++ b/requests/times.go
@@ -26,7 +26,7 @@ import (
"sync"
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/matcher"
)
@@ -95,7 +95,7 @@ func (rt *requestTimes) process(t time.Time) {
// are already in the past. There is no need to set timer for them,
// as it will return immediately. So all past times must be removed
// and timer set to earliest future time.
- past := make([]ReqID, 0)
+ past := make([]boruta.ReqID, 0)
for rt.times.Len() > 0 && t.After(rt.minTime()) {
x := rt.times.Pop()
past = append(past, x.req)
diff --git a/requests/times_test.go b/requests/times_test.go
index 0910ef1..64e736f 100644
--- a/requests/times_test.go
+++ b/requests/times_test.go
@@ -21,20 +21,20 @@ import (
"runtime/debug"
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type TestMatcher struct {
Counter int
- Notified []ReqID
+ Notified []boruta.ReqID
}
-func (m *TestMatcher) Notify(reqs []ReqID) {
+func (m *TestMatcher) Notify(reqs []boruta.ReqID) {
m.Counter++
if m.Notified == nil {
- m.Notified = make([]ReqID, 0)
+ m.Notified = make([]boruta.ReqID, 0)
}
m.Notified = append(m.Notified, reqs...)
}
@@ -74,7 +74,7 @@ var _ = Describe("Times", func() {
defer t.mutex.Unlock()
return t.times.Min()
}
- prepareRequestTime := func(after time.Duration, req ReqID) requestTime {
+ prepareRequestTime := func(after time.Duration, req boruta.ReqID) requestTime {
d := time.Duration(after)
n := time.Now().Add(d)
return requestTime{time: n, req: req}
@@ -191,7 +191,7 @@ var _ = Describe("Times", func() {
var m TestMatcher
t.setMatcher(&m)
- rid := ReqID(100)
+ rid := boruta.ReqID(100)
t.insert(prepareRequestTime(100*time.Millisecond, rid))
Expect(m.Counter).To(BeZero())
@@ -209,7 +209,7 @@ var _ = Describe("Times", func() {
It("should be run once for same times", func() {
var m TestMatcher
r100m := prepareRequestTime(100*time.Millisecond, 0)
- reqs := []ReqID{101, 102, 103, 104, 105}
+ reqs := []boruta.ReqID{101, 102, 103, 104, 105}
t.setMatcher(&m)
for _, r := range reqs {
@@ -230,7 +230,7 @@ var _ = Describe("Times", func() {
var m TestMatcher
t.setMatcher(&m)
- rid := ReqID(200)
+ rid := boruta.ReqID(200)
t.insert(prepareRequestTime(-time.Hour, rid))
// Expect process() to remove element.
diff --git a/requests/timesheapcontainer.go b/requests/timesheapcontainer.go
index 755480d..5c67f9f 100644
--- a/requests/timesheapcontainer.go
+++ b/requests/timesheapcontainer.go
@@ -23,13 +23,13 @@ package requests
import (
"time"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// requestTime combines ReqID with time.Time.
type requestTime struct {
- time time.Time // stores point in time.
- req ReqID // identifies request related to the time.
+ time time.Time // stores point in time.
+ req boruta.ReqID // identifies request related to the time.
}
// timesHeapContainer wraps requestTime slice for implementation of heap.Interface.
diff --git a/rpc/dryad/clientmanager.go b/rpc/dryad/clientmanager.go
index 4ebe3a5..f8c6a55 100644
--- a/rpc/dryad/clientmanager.go
+++ b/rpc/dryad/clientmanager.go
@@ -24,12 +24,12 @@ package dryad
import (
"net"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// ClientManager defines API for managing client RPC calls to Dryad.
type ClientManager interface {
- Dryad
+ boruta.Dryad
// Create creates a new RPC client.
Create(*net.TCPAddr) error
// Close shuts down RPC client connection.
diff --git a/workers/error.go b/workers/error.go
index 455ab1c..3076e40 100644
--- a/workers/error.go
+++ b/workers/error.go
@@ -19,7 +19,7 @@ package workers
import (
"errors"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
var (
@@ -29,7 +29,7 @@ var (
// with caps, which do not contain "UUID" field.
ErrMissingUUID = errors.New("Capabilities are missing UUID entry")
// ErrWorkerNotFound is returned when UUID argument does not match any worker on the list.
- ErrWorkerNotFound = NotFoundError("Worker")
+ ErrWorkerNotFound = boruta.NotFoundError("Worker")
// 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.
diff --git a/workers/job.go b/workers/job.go
index b8ef4c3..4ac4ba5 100644
--- a/workers/job.go
+++ b/workers/job.go
@@ -17,7 +17,7 @@
package workers
import (
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/tunnels"
)
@@ -25,9 +25,9 @@ import (
type Job struct {
// Access describes details of the connection to Dryad. It is returned to the request
// owner when a job for request is run and acquired by the user.
- Access AccessInfo
+ Access boruta.AccessInfo
// Tunnel is a connection to Dryad for the user.
Tunnel tunnels.Tunneler
// Req is ID of the worked request.
- Req ReqID
+ Req boruta.ReqID
}
diff --git a/workers/worker_list_test.go b/workers/worker_list_test.go
index 8c1f368..6c83877 100644
--- a/workers/worker_list_test.go
+++ b/workers/worker_list_test.go
@@ -25,7 +25,7 @@ import (
"fmt"
"net"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/rpc/dryad"
gomock "github.com/golang/mock/gomock"
@@ -79,14 +79,14 @@ var _ = Describe("WorkerList", func() {
defer wl.mutex.RUnlock()
// Check if all registeredWorkers are present
for _, uuid := range registeredWorkers {
- _, ok := wl.workers[WorkerUUID(uuid)]
+ _, ok := wl.workers[boruta.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) {
+ if workerInfo.WorkerUUID == boruta.WorkerUUID(uuid) {
ok = true
break
}
@@ -100,8 +100,8 @@ var _ = Describe("WorkerList", func() {
Expect(err).To(Equal(ErrMissingUUID))
})
- getRandomCaps := func() Capabilities {
- return Capabilities{
+ getRandomCaps := func() boruta.Capabilities {
+ return boruta.Capabilities{
UUID: getUUID(),
}
}
@@ -127,11 +127,11 @@ var _ = Describe("WorkerList", func() {
caps := getRandomCaps()
err := wl.Register(caps, dryadAddr.String(), sshdAddr.String())
Expect(err).ToNot(HaveOccurred())
- uuid := WorkerUUID(caps[UUID])
+ uuid := boruta.WorkerUUID(caps[UUID])
wl.mutex.RLock()
defer wl.mutex.RUnlock()
Expect(wl.workers).To(HaveKey(uuid))
- Expect(wl.workers[uuid].State).To(Equal(MAINTENANCE))
+ Expect(wl.workers[uuid].State).To(Equal(boruta.MAINTENANCE))
})
It("should update the caps when called twice for the same worker", func() {
@@ -152,7 +152,7 @@ var _ = Describe("WorkerList", func() {
err = wl.Register(caps, dryadAddr.String(), sshdAddr.String())
Expect(err).ToNot(HaveOccurred())
wl.mutex.RLock()
- Expect(wl.workers[WorkerUUID(caps[UUID])].Caps).To(Equal(caps))
+ Expect(wl.workers[boruta.WorkerUUID(caps[UUID])].Caps).To(Equal(caps))
wl.mutex.RUnlock()
compareLists()
})
@@ -194,18 +194,18 @@ var _ = Describe("WorkerList", func() {
})
Context("with worker registered", func() {
- var worker WorkerUUID
+ var worker boruta.WorkerUUID
- randomUUID := func() WorkerUUID {
+ randomUUID := func() boruta.WorkerUUID {
newUUID := worker
for newUUID == worker {
- newUUID = WorkerUUID(getUUID())
+ newUUID = boruta.WorkerUUID(getUUID())
}
return newUUID
}
- registerWorker := func() WorkerUUID {
+ registerWorker := func() boruta.WorkerUUID {
capsUUID := randomUUID()
- err := wl.Register(Capabilities{UUID: string(capsUUID)}, dryadAddr.String(), sshdAddr.String())
+ err := wl.Register(boruta.Capabilities{UUID: string(capsUUID)}, dryadAddr.String(), sshdAddr.String())
Expect(err).ToNot(HaveOccurred())
wl.mutex.RLock()
Expect(wl.workers).ToNot(BeEmpty())
@@ -228,26 +228,26 @@ var _ = Describe("WorkerList", func() {
})
It("should work to SetFail", func() {
- for _, state := range []WorkerState{IDLE, RUN} {
+ for _, state := range []boruta.WorkerState{boruta.IDLE, boruta.RUN} {
wl.mutex.Lock()
wl.workers[worker].State = state
wl.mutex.Unlock()
err := wl.SetFail(worker, "")
Expect(err).ToNot(HaveOccurred())
wl.mutex.RLock()
- Expect(wl.workers[worker].State).To(Equal(FAIL))
+ Expect(wl.workers[worker].State).To(Equal(boruta.FAIL))
wl.mutex.RUnlock()
}
})
It("Should fail to SetFail in MAINTENANCE state", func() {
wl.mutex.Lock()
- Expect(wl.workers[worker].State).To(Equal(MAINTENANCE))
+ Expect(wl.workers[worker].State).To(Equal(boruta.MAINTENANCE))
wl.mutex.Unlock()
err := wl.SetFail(worker, "")
Expect(err).To(Equal(ErrInMaintenance))
wl.mutex.RLock()
- Expect(wl.workers[worker].State).To(Equal(MAINTENANCE))
+ Expect(wl.workers[worker].State).To(Equal(boruta.MAINTENANCE))
wl.mutex.RUnlock()
})
})
@@ -279,7 +279,7 @@ var _ = Describe("WorkerList", func() {
})
It("should fail to deregister worker not in MAINTENANCE state", func() {
- for _, state := range []WorkerState{IDLE, RUN, FAIL} {
+ for _, state := range []boruta.WorkerState{boruta.IDLE, boruta.RUN, boruta.FAIL} {
wl.mutex.Lock()
wl.workers[worker].State = state
wl.mutex.Unlock()
@@ -295,14 +295,14 @@ var _ = Describe("WorkerList", func() {
Describe("SetState", func() {
It("should fail to SetState of nonexistent worker", func() {
uuid := randomUUID()
- err := wl.SetState(uuid, MAINTENANCE)
+ err := wl.SetState(uuid, boruta.MAINTENANCE)
Expect(err).To(Equal(ErrWorkerNotFound))
})
It("should fail to SetState for invalid transitions", func() {
- invalidTransitions := [][]WorkerState{
- {RUN, IDLE},
- {FAIL, IDLE},
+ invalidTransitions := [][]boruta.WorkerState{
+ {boruta.RUN, boruta.IDLE},
+ {boruta.FAIL, boruta.IDLE},
}
for _, transition := range invalidTransitions {
fromState, toState := transition[0], transition[1]
@@ -318,13 +318,13 @@ var _ = Describe("WorkerList", func() {
})
It("should fail to SetState for incorrect state argument", func() {
- invalidArgument := [][]WorkerState{
- {MAINTENANCE, RUN},
- {MAINTENANCE, FAIL},
- {IDLE, FAIL},
- {IDLE, RUN},
- {RUN, FAIL},
- {FAIL, RUN},
+ invalidArgument := [][]boruta.WorkerState{
+ {boruta.MAINTENANCE, boruta.RUN},
+ {boruta.MAINTENANCE, boruta.FAIL},
+ {boruta.IDLE, boruta.FAIL},
+ {boruta.IDLE, boruta.RUN},
+ {boruta.RUN, boruta.FAIL},
+ {boruta.FAIL, boruta.RUN},
}
for _, transition := range invalidArgument {
fromState, toState := transition[0], transition[1]
@@ -344,11 +344,11 @@ var _ = Describe("WorkerList", func() {
ip := net.IPv4(2, 4, 6, 8)
testerr := errors.New("Test Error")
var info *mapWorker
- noWorker := WorkerUUID("There's no such worker")
+ noWorker := boruta.WorkerUUID("There's no such worker")
putStr := "maintenance"
- eventuallyState := func(info *mapWorker, state WorkerState) {
- EventuallyWithOffset(1, func() WorkerState {
+ eventuallyState := func(info *mapWorker, state boruta.WorkerState) {
+ EventuallyWithOffset(1, func() boruta.WorkerState {
wl.mutex.RLock()
defer wl.mutex.RUnlock()
return info.State
@@ -385,7 +385,7 @@ var _ = Describe("WorkerList", func() {
Describe("from MAINTENANCE to IDLE", func() {
BeforeEach(func() {
wl.mutex.Lock()
- info.State = MAINTENANCE
+ info.State = boruta.MAINTENANCE
wl.mutex.Unlock()
})
@@ -396,9 +396,9 @@ var _ = Describe("WorkerList", func() {
dcm.EXPECT().Close(),
)
- err := wl.SetState(worker, IDLE)
+ err := wl.SetState(worker, boruta.IDLE)
Expect(err).ToNot(HaveOccurred())
- eventuallyState(info, IDLE)
+ eventuallyState(info, boruta.IDLE)
eventuallyKey(info, Not(Equal(&rsa.PrivateKey{})))
})
@@ -409,18 +409,18 @@ var _ = Describe("WorkerList", func() {
dcm.EXPECT().Close(),
)
- err := wl.SetState(worker, IDLE)
+ err := wl.SetState(worker, boruta.IDLE)
Expect(err).ToNot(HaveOccurred())
- eventuallyState(info, FAIL)
+ eventuallyState(info, boruta.FAIL)
Expect(info.key).To(BeNil())
})
It("should fail to SetState if dryadClientManager fails to create client", func() {
dcm.EXPECT().Create(info.dryad).Return(testerr)
- err := wl.SetState(worker, IDLE)
+ err := wl.SetState(worker, boruta.IDLE)
Expect(err).ToNot(HaveOccurred())
- eventuallyState(info, FAIL)
+ eventuallyState(info, boruta.FAIL)
Expect(info.key).To(BeNil())
})
})
@@ -434,7 +434,7 @@ var _ = Describe("WorkerList", func() {
EventuallyWithOffset(1, trigger).Should(Receive(Equal(val)))
}
- fromStates := []WorkerState{IDLE, RUN, FAIL}
+ fromStates := []boruta.WorkerState{boruta.IDLE, boruta.RUN, boruta.FAIL}
for _, from := range fromStates {
Describe("from "+string(from)+" to MAINTENANCE", func() {
BeforeEach(func() {
@@ -450,9 +450,9 @@ var _ = Describe("WorkerList", func() {
dcm.EXPECT().Close(),
)
- err := wl.SetState(worker, MAINTENANCE)
+ err := wl.SetState(worker, boruta.MAINTENANCE)
Expect(err).ToNot(HaveOccurred())
- eventuallyState(info, MAINTENANCE)
+ eventuallyState(info, boruta.MAINTENANCE)
})
It("should fail to SetState if dryadClientManager fails to put dryad in maintenance state", func() {
@@ -461,30 +461,30 @@ var _ = Describe("WorkerList", func() {
dcm.EXPECT().PutInMaintenance(putStr).Return(testerr),
dcm.EXPECT().Close().Do(func() {
wl.mutex.Lock()
- info.State = WorkerState("TEST")
+ info.State = boruta.WorkerState("TEST")
wl.mutex.Unlock()
setTrigger(1)
}),
)
- err := wl.SetState(worker, MAINTENANCE)
+ err := wl.SetState(worker, boruta.MAINTENANCE)
Expect(err).ToNot(HaveOccurred())
eventuallyTrigger(1)
- eventuallyState(info, FAIL)
+ eventuallyState(info, boruta.FAIL)
})
It("should fail to SetState if dryadClientManager fails to create client", func() {
dcm.EXPECT().Create(info.dryad).Return(testerr).Do(func(*net.TCPAddr) {
wl.mutex.Lock()
- info.State = WorkerState("TEST")
+ info.State = boruta.WorkerState("TEST")
wl.mutex.Unlock()
setTrigger(2)
})
- err := wl.SetState(worker, MAINTENANCE)
+ err := wl.SetState(worker, boruta.MAINTENANCE)
Expect(err).ToNot(HaveOccurred())
eventuallyTrigger(2)
- eventuallyState(info, FAIL)
+ eventuallyState(info, boruta.FAIL)
})
})
}
@@ -534,7 +534,7 @@ var _ = Describe("WorkerList", func() {
})
It("should work to SetGroup", func() {
- var group Groups = []Group{
+ var group boruta.Groups = []boruta.Group{
"group1",
}
@@ -555,14 +555,14 @@ var _ = Describe("WorkerList", func() {
})
Describe("ListWorkers", func() {
- var refWorkerList []WorkerInfo
+ var refWorkerList []boruta.WorkerInfo
- registerAndSetGroups := func(groups Groups, caps Capabilities) WorkerInfo {
+ registerAndSetGroups := func(groups boruta.Groups, caps boruta.Capabilities) boruta.WorkerInfo {
capsUUID := getUUID()
caps[UUID] = capsUUID
err := wl.Register(caps, dryadAddr.String(), sshdAddr.String())
Expect(err).ToNot(HaveOccurred())
- workerID := WorkerUUID(capsUUID)
+ workerID := boruta.WorkerUUID(capsUUID)
err = wl.SetGroups(workerID, groups)
Expect(err).ToNot(HaveOccurred())
@@ -575,48 +575,48 @@ var _ = Describe("WorkerList", func() {
}
BeforeEach(func() {
- refWorkerList = make([]WorkerInfo, 1)
+ refWorkerList = make([]boruta.WorkerInfo, 1)
// Add worker with minimal caps and empty groups.
wl.mutex.RLock()
refWorkerList[0] = wl.workers[worker].WorkerInfo
wl.mutex.RUnlock()
// Add worker with both groups and caps declared.
refWorkerList = append(refWorkerList, registerAndSetGroups(
- Groups{"all", "small_1", "small_2"},
- Capabilities{
+ boruta.Groups{"all", "small_1", "small_2"},
+ boruta.Capabilities{
"target": "yes",
"display": "yes",
}))
// Add worker similar to the second one, but without caps.
refWorkerList = append(refWorkerList, registerAndSetGroups(
- Groups{"all", "small_1", "small_2"},
- Capabilities{},
+ boruta.Groups{"all", "small_1", "small_2"},
+ boruta.Capabilities{},
))
// Add worker similar to the second one, but without groups.
refWorkerList = append(refWorkerList, registerAndSetGroups(
- Groups{},
- Capabilities{
+ boruta.Groups{},
+ boruta.Capabilities{
"target": "yes",
"display": "yes",
}))
// Add worker similar to the second one, but with display set to no.
refWorkerList = append(refWorkerList, registerAndSetGroups(
- Groups{"all", "small_1", "small_2"},
- Capabilities{
+ boruta.Groups{"all", "small_1", "small_2"},
+ boruta.Capabilities{
"target": "yes",
"display": "no",
}))
// Add worker similar to the second one, but absent from small_1 group.
refWorkerList = append(refWorkerList, registerAndSetGroups(
- Groups{"all", "small_2"},
- Capabilities{
+ boruta.Groups{"all", "small_2"},
+ boruta.Capabilities{
"target": "yes",
"display": "yes",
}))
})
- testWorkerList := func(groups Groups, caps Capabilities,
- present, absent []WorkerInfo) {
+ testWorkerList := func(groups boruta.Groups, caps boruta.Capabilities,
+ present, absent []boruta.WorkerInfo) {
workers, err := wl.ListWorkers(groups, caps)
Expect(err).ToNot(HaveOccurred())
for _, workerInfo := range present {
@@ -632,28 +632,28 @@ var _ = Describe("WorkerList", func() {
})
It("should return all workers when parameters are empty", func() {
- testWorkerList(Groups{}, Capabilities{}, refWorkerList, nil)
+ testWorkerList(boruta.Groups{}, boruta.Capabilities{}, refWorkerList, nil)
})
Describe("filterCaps", func() {
It("should return all workers satisfying defined caps", func() {
By("Returning all workers with display")
- testWorkerList(Groups{},
- Capabilities{"display": "yes"},
- []WorkerInfo{refWorkerList[1], refWorkerList[3], refWorkerList[5]},
- []WorkerInfo{refWorkerList[0], refWorkerList[2], refWorkerList[4]})
+ testWorkerList(boruta.Groups{},
+ boruta.Capabilities{"display": "yes"},
+ []boruta.WorkerInfo{refWorkerList[1], refWorkerList[3], refWorkerList[5]},
+ []boruta.WorkerInfo{refWorkerList[0], refWorkerList[2], refWorkerList[4]})
By("Returning all workers without display")
- testWorkerList(Groups{},
- Capabilities{"display": "no"},
- []WorkerInfo{refWorkerList[4]},
- []WorkerInfo{refWorkerList[0], refWorkerList[1],
+ testWorkerList(boruta.Groups{},
+ boruta.Capabilities{"display": "no"},
+ []boruta.WorkerInfo{refWorkerList[4]},
+ []boruta.WorkerInfo{refWorkerList[0], refWorkerList[1],
refWorkerList[2], refWorkerList[3], refWorkerList[5]})
})
It("should return empty list if no worker matches the caps", func() {
- workers, err := wl.ListWorkers(Groups{},
- Capabilities{
+ workers, err := wl.ListWorkers(boruta.Groups{},
+ boruta.Capabilities{
"non-existing-caps": "",
})
Expect(err).ToNot(HaveOccurred())
@@ -664,21 +664,21 @@ var _ = Describe("WorkerList", func() {
Describe("filterGroups", func() {
It("should return all workers satisfying defined groups", func() {
By("Returning all workers in group all")
- testWorkerList(Groups{"all"},
+ testWorkerList(boruta.Groups{"all"},
nil,
- []WorkerInfo{refWorkerList[1], refWorkerList[2],
+ []boruta.WorkerInfo{refWorkerList[1], refWorkerList[2],
refWorkerList[4], refWorkerList[5]},
- []WorkerInfo{refWorkerList[0], refWorkerList[3]})
+ []boruta.WorkerInfo{refWorkerList[0], refWorkerList[3]})
By("Returning all workers in group small_1")
- testWorkerList(Groups{"small_1"},
+ testWorkerList(boruta.Groups{"small_1"},
nil,
- []WorkerInfo{refWorkerList[1], refWorkerList[2], refWorkerList[4]},
- []WorkerInfo{refWorkerList[0], refWorkerList[3], refWorkerList[5]})
+ []boruta.WorkerInfo{refWorkerList[1], refWorkerList[2], refWorkerList[4]},
+ []boruta.WorkerInfo{refWorkerList[0], refWorkerList[3], refWorkerList[5]})
})
It("should return empty list if no worker matches the group", func() {
- workers, err := wl.ListWorkers(Groups{"non-existing-group"}, nil)
+ workers, err := wl.ListWorkers(boruta.Groups{"non-existing-group"}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(workers).To(BeEmpty())
})
@@ -686,23 +686,23 @@ var _ = Describe("WorkerList", func() {
It("should work with many groups and caps defined", func() {
By("Returning all targets with display in both groups")
- testWorkerList(Groups{"small_1", "small_2"},
- Capabilities{
+ testWorkerList(boruta.Groups{"small_1", "small_2"},
+ boruta.Capabilities{
"target": "yes",
"display": "yes",
},
- []WorkerInfo{refWorkerList[1], refWorkerList[5]},
- []WorkerInfo{refWorkerList[0], refWorkerList[2],
+ []boruta.WorkerInfo{refWorkerList[1], refWorkerList[5]},
+ []boruta.WorkerInfo{refWorkerList[0], refWorkerList[2],
refWorkerList[3], refWorkerList[4]})
By("Returning all targets without display in group all and small_1")
- testWorkerList(Groups{"all", "small_1"},
- Capabilities{
+ testWorkerList(boruta.Groups{"all", "small_1"},
+ boruta.Capabilities{
"target": "yes",
"display": "no",
},
- []WorkerInfo{refWorkerList[4]},
- []WorkerInfo{refWorkerList[0], refWorkerList[1],
+ []boruta.WorkerInfo{refWorkerList[4]},
+ []boruta.WorkerInfo{refWorkerList[0], refWorkerList[1],
refWorkerList[2], refWorkerList[3], refWorkerList[5]})
})
})
@@ -724,8 +724,8 @@ var _ = Describe("WorkerList", func() {
})
Describe("Setters and Getters", func() {
- type genericGet func(wl *WorkerList, uuid WorkerUUID, expectedItem interface{}, expectedErr error)
- getDryad := genericGet(func(wl *WorkerList, uuid WorkerUUID, expectedItem interface{}, expectedErr error) {
+ type genericGet func(wl *WorkerList, uuid boruta.WorkerUUID, expectedItem interface{}, expectedErr error)
+ getDryad := genericGet(func(wl *WorkerList, uuid boruta.WorkerUUID, expectedItem interface{}, expectedErr error) {
item, err := wl.GetWorkerAddr(uuid)
if expectedErr != nil {
Expect(item).To(Equal(net.TCPAddr{}))
@@ -735,7 +735,7 @@ var _ = Describe("WorkerList", func() {
Expect(err).ToNot(HaveOccurred())
Expect(item).To(Equal(expectedItem.(net.TCPAddr)))
})
- getSSH := genericGet(func(wl *WorkerList, uuid WorkerUUID, expectedItem interface{}, expectedErr error) {
+ getSSH := genericGet(func(wl *WorkerList, uuid boruta.WorkerUUID, expectedItem interface{}, expectedErr error) {
item, err := wl.GetWorkerSSHAddr(uuid)
if expectedErr != nil {
Expect(item).To(Equal(net.TCPAddr{}))
@@ -745,7 +745,7 @@ var _ = Describe("WorkerList", func() {
Expect(err).ToNot(HaveOccurred())
Expect(item).To(Equal(expectedItem.(net.TCPAddr)))
})
- getKey := genericGet(func(wl *WorkerList, uuid WorkerUUID, expectedItem interface{}, expectedErr error) {
+ getKey := genericGet(func(wl *WorkerList, uuid boruta.WorkerUUID, expectedItem interface{}, expectedErr error) {
item, err := wl.GetWorkerKey(uuid)
if expectedErr != nil {
Expect(err).To(Equal(expectedErr))
@@ -756,8 +756,8 @@ var _ = Describe("WorkerList", func() {
})
getters := []genericGet{getKey, getDryad, getSSH}
- type genericSet func(wl *WorkerList, uuid WorkerUUID, expectedErr error) interface{}
- setKey := genericSet(func(wl *WorkerList, uuid WorkerUUID, expectedErr error) interface{} {
+ type genericSet func(wl *WorkerList, uuid boruta.WorkerUUID, expectedErr error) interface{}
+ setKey := genericSet(func(wl *WorkerList, uuid boruta.WorkerUUID, expectedErr error) interface{} {
key, err := rsa.GenerateKey(rand.Reader, 128)
Expect(err).ToNot(HaveOccurred())
err = wl.SetWorkerKey(uuid, key)
@@ -799,7 +799,7 @@ var _ = Describe("WorkerList", func() {
var dcm *MockDryadClientManager
ip := net.IPv4(2, 4, 6, 8)
testerr := errors.New("Test Error")
- noWorker := WorkerUUID("There's no such worker")
+ noWorker := boruta.WorkerUUID("There's no such worker")
eventuallyKey := func(info *mapWorker, match types.GomegaMatcher) {
EventuallyWithOffset(1, func() *rsa.PrivateKey {
@@ -808,8 +808,8 @@ var _ = Describe("WorkerList", func() {
return info.key
}).Should(match)
}
- eventuallyState := func(info *mapWorker, state WorkerState) {
- EventuallyWithOffset(1, func() WorkerState {
+ eventuallyState := func(info *mapWorker, state boruta.WorkerState) {
+ EventuallyWithOffset(1, func() boruta.WorkerState {
wl.mutex.RLock()
defer wl.mutex.RUnlock()
return info.State
@@ -834,7 +834,7 @@ var _ = Describe("WorkerList", func() {
info, ok := wl.workers[worker]
wl.mutex.RUnlock()
Expect(ok).To(BeTrue())
- Expect(info.State).To(Equal(IDLE))
+ Expect(info.State).To(Equal(boruta.IDLE))
})
It("should fail to prepare not existing worker in without-key preparation", func() {
uuid := randomUUID()
@@ -865,7 +865,7 @@ var _ = Describe("WorkerList", func() {
err := wl.PrepareWorker(worker, true)
Expect(err).NotTo(HaveOccurred())
- eventuallyState(info, IDLE)
+ eventuallyState(info, boruta.IDLE)
eventuallyKey(info, Not(Equal(&rsa.PrivateKey{})))
})
It("should fail to prepare worker if dryadClientManager fails to prepare client", func() {
@@ -878,7 +878,7 @@ var _ = Describe("WorkerList", func() {
err := wl.PrepareWorker(worker, true)
Expect(err).NotTo(HaveOccurred())
- eventuallyState(info, FAIL)
+ eventuallyState(info, boruta.FAIL)
Expect(info.key).To(BeNil())
})
It("should fail to prepare worker if dryadClientManager fails to create client", func() {
@@ -887,7 +887,7 @@ var _ = Describe("WorkerList", func() {
err := wl.PrepareWorker(worker, true)
Expect(err).NotTo(HaveOccurred())
- eventuallyState(info, FAIL)
+ eventuallyState(info, boruta.FAIL)
Expect(info.key).To(BeNil())
})
})
@@ -897,12 +897,12 @@ var _ = Describe("WorkerList", func() {
var ctrl *gomock.Controller
var wc *MockWorkerChange
- set := func(state WorkerState) {
+ set := func(state boruta.WorkerState) {
wl.mutex.Lock()
wl.workers[worker].State = state
wl.mutex.Unlock()
}
- check := func(state WorkerState) {
+ check := func(state boruta.WorkerState) {
wl.mutex.RLock()
Expect(wl.workers[worker].State).To(Equal(state))
wl.mutex.RUnlock()
@@ -917,53 +917,53 @@ var _ = Describe("WorkerList", func() {
ctrl.Finish()
})
DescribeTable("Should change state without calling changeListener",
- func(from, to WorkerState) {
+ func(from, to boruta.WorkerState) {
set(from)
err := wl.setState(worker, to)
Expect(err).NotTo(HaveOccurred())
check(to)
},
- Entry("MAINTENANCE->MAINTENANCE", MAINTENANCE, MAINTENANCE),
- Entry("MAINTENANCE->RUN", MAINTENANCE, RUN),
- Entry("MAINTENANCE->FAIL", MAINTENANCE, FAIL),
- Entry("IDLE->MAINTENANCE", IDLE, MAINTENANCE),
- Entry("IDLE->RUN", IDLE, RUN),
- Entry("IDLE->FAIL", IDLE, FAIL),
- Entry("FAIL->MAINTENANCE", FAIL, MAINTENANCE),
- Entry("FAIL->RUN", FAIL, RUN),
- Entry("FAIL->FAIL", FAIL, FAIL),
+ Entry("MAINTENANCE->MAINTENANCE", boruta.MAINTENANCE, boruta.MAINTENANCE),
+ Entry("MAINTENANCE->RUN", boruta.MAINTENANCE, boruta.RUN),
+ Entry("MAINTENANCE->FAIL", boruta.MAINTENANCE, boruta.FAIL),
+ Entry("IDLE->MAINTENANCE", boruta.IDLE, boruta.MAINTENANCE),
+ Entry("IDLE->RUN", boruta.IDLE, boruta.RUN),
+ Entry("IDLE->FAIL", boruta.IDLE, boruta.FAIL),
+ Entry("FAIL->MAINTENANCE", boruta.FAIL, boruta.MAINTENANCE),
+ Entry("FAIL->RUN", boruta.FAIL, boruta.RUN),
+ Entry("FAIL->FAIL", boruta.FAIL, boruta.FAIL),
)
DescribeTable("Should change state and call OnWorkerIdle",
- func(from, to WorkerState) {
+ func(from, to boruta.WorkerState) {
set(from)
wc.EXPECT().OnWorkerIdle(worker)
err := wl.setState(worker, to)
Expect(err).NotTo(HaveOccurred())
check(to)
},
- Entry("MAINTENANCE->IDLE", MAINTENANCE, IDLE),
- Entry("IDLE->IDLE", IDLE, IDLE),
- Entry("RUN->IDLE", RUN, IDLE),
- Entry("FAIL->IDLE", FAIL, IDLE),
+ Entry("MAINTENANCE->IDLE", boruta.MAINTENANCE, boruta.IDLE),
+ Entry("IDLE->IDLE", boruta.IDLE, boruta.IDLE),
+ Entry("RUN->IDLE", boruta.RUN, boruta.IDLE),
+ Entry("FAIL->IDLE", boruta.FAIL, boruta.IDLE),
)
DescribeTable("Should change state and call OnWorkerFail",
- func(from, to WorkerState) {
+ func(from, to boruta.WorkerState) {
set(from)
wc.EXPECT().OnWorkerFail(worker)
err := wl.setState(worker, to)
Expect(err).NotTo(HaveOccurred())
check(to)
},
- Entry("RUN->MAINTENANCE", RUN, MAINTENANCE),
- Entry("RUN->RUN", RUN, RUN),
- Entry("RUN->FAIL", RUN, FAIL),
+ Entry("RUN->MAINTENANCE", boruta.RUN, boruta.MAINTENANCE),
+ Entry("RUN->RUN", boruta.RUN, boruta.RUN),
+ Entry("RUN->FAIL", boruta.RUN, boruta.FAIL),
)
})
})
Describe("TakeBestMatchingWorker", func() {
- addWorker := func(groups Groups, caps Capabilities) *mapWorker {
+ addWorker := func(groups boruta.Groups, caps boruta.Capabilities) *mapWorker {
capsUUID := getUUID()
- workerUUID := WorkerUUID(capsUUID)
+ workerUUID := boruta.WorkerUUID(capsUUID)
caps[UUID] = capsUUID
wl.Register(caps, dryadAddr.String(), sshdAddr.String())
@@ -971,31 +971,31 @@ var _ = Describe("WorkerList", func() {
w, ok := wl.workers[workerUUID]
wl.mutex.RUnlock()
Expect(ok).To(BeTrue())
- Expect(w.State).To(Equal(MAINTENANCE))
+ Expect(w.State).To(Equal(boruta.MAINTENANCE))
err := wl.SetGroups(workerUUID, groups)
Expect(err).NotTo(HaveOccurred())
return w
}
- addIdleWorker := func(groups Groups, caps Capabilities) *mapWorker {
+ addIdleWorker := func(groups boruta.Groups, caps boruta.Capabilities) *mapWorker {
w := addWorker(groups, caps)
err := wl.PrepareWorker(w.WorkerUUID, false)
Expect(err).NotTo(HaveOccurred())
- Expect(w.State).To(Equal(IDLE))
+ Expect(w.State).To(Equal(boruta.IDLE))
return w
}
- generateGroups := func(count int) Groups {
- var groups Groups
+ generateGroups := func(count int) boruta.Groups {
+ var groups boruta.Groups
for i := 0; i < count; i++ {
- groups = append(groups, Group(fmt.Sprintf("testGroup_%d", i)))
+ groups = append(groups, boruta.Group(fmt.Sprintf("testGroup_%d", i)))
}
return groups
}
- generateCaps := func(count int) Capabilities {
- caps := make(Capabilities)
+ generateCaps := func(count int) boruta.Capabilities {
+ caps := make(boruta.Capabilities)
for i := 0; i < count; i++ {
k := fmt.Sprintf("testCapKey_%d", i)
v := fmt.Sprintf("testCapValue_%d", i)
@@ -1004,22 +1004,22 @@ var _ = Describe("WorkerList", func() {
return caps
}
It("should fail to find matching worker when there are no workers", func() {
- ret, err := wl.TakeBestMatchingWorker(Groups{}, Capabilities{})
+ ret, err := wl.TakeBestMatchingWorker(boruta.Groups{}, boruta.Capabilities{})
Expect(err).To(Equal(ErrNoMatchingWorker))
Expect(ret).To(BeZero())
})
It("should match fitting worker and set it into RUN state", func() {
- w := addIdleWorker(Groups{}, Capabilities{})
+ w := addIdleWorker(boruta.Groups{}, boruta.Capabilities{})
- ret, err := wl.TakeBestMatchingWorker(Groups{}, Capabilities{})
+ ret, err := wl.TakeBestMatchingWorker(boruta.Groups{}, boruta.Capabilities{})
Expect(err).NotTo(HaveOccurred())
Expect(ret).To(Equal(w.WorkerUUID))
- Expect(w.State).To(Equal(RUN))
+ Expect(w.State).To(Equal(boruta.RUN))
})
It("should not match not IDLE workers", func() {
- addWorker(Groups{}, Capabilities{})
+ addWorker(boruta.Groups{}, boruta.Capabilities{})
- ret, err := wl.TakeBestMatchingWorker(Groups{}, Capabilities{})
+ ret, err := wl.TakeBestMatchingWorker(boruta.Groups{}, boruta.Capabilities{})
Expect(err).To(Equal(ErrNoMatchingWorker))
Expect(ret).To(BeZero())
})
@@ -1037,7 +1037,7 @@ var _ = Describe("WorkerList", func() {
ret, err := wl.TakeBestMatchingWorker(generateGroups(1), generateCaps(1))
Expect(err).NotTo(HaveOccurred())
Expect(ret).To(Equal(w.WorkerUUID))
- Expect(w.State).To(Equal(RUN))
+ Expect(w.State).To(Equal(boruta.RUN))
}
ret, err := wl.TakeBestMatchingWorker(generateGroups(1), generateCaps(1))
Expect(err).To(Equal(ErrNoMatchingWorker))
@@ -1045,7 +1045,7 @@ var _ = Describe("WorkerList", func() {
leftWorkers := []*mapWorker{w2g0c, w0g2c}
for _, w := range leftWorkers {
- Expect(w.State).To(Equal(IDLE))
+ Expect(w.State).To(Equal(boruta.IDLE))
}
})
})
diff --git a/workers/workerchange.go b/workers/workerchange.go
index c75a040..9e80209 100644
--- a/workers/workerchange.go
+++ b/workers/workerchange.go
@@ -20,15 +20,15 @@
package workers
import (
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
)
// WorkerChange defines API for implementation to be informed about
// changes in workers.
type WorkerChange interface {
// OnWorkerIdle notifies about available idle worker.
- OnWorkerIdle(WorkerUUID)
+ OnWorkerIdle(boruta.WorkerUUID)
// OnWorkerFail notifies about breaking execution of job by a running worker and
// putting it into FAIL or MAINTENANCE state.
- OnWorkerFail(WorkerUUID)
+ OnWorkerFail(boruta.WorkerUUID)
}
diff --git a/workers/workers.go b/workers/workers.go
index c38ea8a..6d4ff95 100644
--- a/workers/workers.go
+++ b/workers/workers.go
@@ -25,7 +25,7 @@ import (
"net"
"sync"
- . "git.tizen.org/tools/boruta"
+ "git.tizen.org/tools/boruta"
"git.tizen.org/tools/boruta/rpc/dryad"
"golang.org/x/crypto/ssh"
)
@@ -40,9 +40,10 @@ var sizeRSA = 4096
// mapWorker is used by WorkerList to store all
// (public and private) structures representing Worker.
type mapWorker struct {
- WorkerInfo
+ boruta.WorkerInfo
dryad *net.TCPAddr
sshd *net.TCPAddr
+ ip net.IP
key *rsa.PrivateKey
}
@@ -55,9 +56,9 @@ type mapWorker struct {
// The dryad.ClientManager allows managing Dryads' clients for key generation.
// One can be created using newDryadClient function.
type WorkerList struct {
- Superviser
- Workers
- workers map[WorkerUUID]*mapWorker
+ boruta.Superviser
+ boruta.Workers
+ workers map[boruta.WorkerUUID]*mapWorker
mutex *sync.RWMutex
changeListener WorkerChange
newDryadClient func() dryad.ClientManager
@@ -74,7 +75,7 @@ func newDryadClient() dryad.ClientManager {
// NewWorkerList returns a new WorkerList with all fields set.
func NewWorkerList() *WorkerList {
return &WorkerList{
- workers: make(map[WorkerUUID]*mapWorker),
+ workers: make(map[boruta.WorkerUUID]*mapWorker),
mutex: new(sync.RWMutex),
newDryadClient: newDryadClient,
}
@@ -84,12 +85,13 @@ func NewWorkerList() *WorkerList {
// UUID, which identifies Worker, must be present in caps. Both dryadAddress and
// sshAddress must resolve and parse to net.TCPAddr. Neither IP address nor port number
// can not be ommited.
-func (wl *WorkerList) Register(caps Capabilities, dryadAddress string, sshAddress string) error {
+func (wl *WorkerList) Register(caps boruta.Capabilities, dryadAddress string,
+ sshAddress string) error {
capsUUID, present := caps[UUID]
if !present {
return ErrMissingUUID
}
- uuid := WorkerUUID(capsUUID)
+ uuid := boruta.WorkerUUID(capsUUID)
dryad, err := net.ResolveTCPAddr("tcp", dryadAddress)
if err != nil {
@@ -125,9 +127,9 @@ func (wl *WorkerList) Register(caps Capabilities, dryadAddress string, sshAddres
worker.sshd = sshd
} else {
wl.workers[uuid] = &mapWorker{
- WorkerInfo: WorkerInfo{
+ WorkerInfo: boruta.WorkerInfo{
WorkerUUID: uuid,
- State: MAINTENANCE,
+ State: boruta.MAINTENANCE,
Caps: caps,
},
dryad: dryad,
@@ -140,23 +142,23 @@ func (wl *WorkerList) Register(caps Capabilities, dryadAddress string, sshAddres
// SetFail is an implementation of SetFail from Superviser interface.
//
// TODO(amistewicz): WorkerList should process the reason and store it.
-func (wl *WorkerList) SetFail(uuid WorkerUUID, reason string) error {
+func (wl *WorkerList) SetFail(uuid boruta.WorkerUUID, reason string) error {
wl.mutex.Lock()
defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
}
- if worker.State == MAINTENANCE {
+ if worker.State == boruta.MAINTENANCE {
return ErrInMaintenance
}
- return wl.setState(uuid, FAIL)
+ return wl.setState(uuid, boruta.FAIL)
}
// SetState is an implementation of SetState from Workers interface.
-func (wl *WorkerList) SetState(uuid WorkerUUID, state WorkerState) error {
+func (wl *WorkerList) SetState(uuid boruta.WorkerUUID, state boruta.WorkerState) error {
// Only state transitions to IDLE or MAINTENANCE are allowed.
- if state != MAINTENANCE && state != IDLE {
+ if state != boruta.MAINTENANCE && state != boruta.IDLE {
return ErrWrongStateArgument
}
wl.mutex.Lock()
@@ -166,20 +168,20 @@ func (wl *WorkerList) SetState(uuid WorkerUUID, state WorkerState) error {
return ErrWorkerNotFound
}
// State transitions to IDLE are allowed from MAINTENANCE state only.
- if state == IDLE && worker.State != MAINTENANCE {
+ if state == boruta.IDLE && worker.State != boruta.MAINTENANCE {
return ErrForbiddenStateChange
}
switch state {
- case IDLE:
+ case boruta.IDLE:
go wl.prepareKeyAndSetState(uuid)
- case MAINTENANCE:
+ case boruta.MAINTENANCE:
go wl.putInMaintenanceWorker(uuid)
}
return nil
}
// SetGroups is an implementation of SetGroups from Workers interface.
-func (wl *WorkerList) SetGroups(uuid WorkerUUID, groups Groups) error {
+func (wl *WorkerList) SetGroups(uuid boruta.WorkerUUID, groups boruta.Groups) error {
wl.mutex.Lock()
defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
@@ -191,14 +193,14 @@ 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 {
+func (wl *WorkerList) Deregister(uuid boruta.WorkerUUID) error {
wl.mutex.Lock()
defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
}
- if worker.State != MAINTENANCE {
+ if worker.State != boruta.MAINTENANCE {
return ErrNotInMaintenance
}
delete(wl.workers, uuid)
@@ -221,7 +223,7 @@ func (wl *WorkerList) Deregister(uuid WorkerUUID) error {
// "VOLTAGE": "2.9-3.6" should satisfy "VOLTAGE": "3.3"
//
// It is a helper function of ListWorkers.
-func isCapsMatching(worker WorkerInfo, caps Capabilities) bool {
+func isCapsMatching(worker boruta.WorkerInfo, caps boruta.Capabilities) bool {
if len(caps) == 0 {
return true
}
@@ -242,7 +244,7 @@ func isCapsMatching(worker WorkerInfo, caps Capabilities) bool {
// isGroupsMatching returns true if a worker belongs to any of groups in groupsMatcher.
// Empty groupsMatcher is satisfied by every Worker.
// It is a helper function of ListWorkers.
-func isGroupsMatching(worker WorkerInfo, groupsMatcher map[Group]interface{}) bool {
+func isGroupsMatching(worker boruta.WorkerInfo, groupsMatcher map[boruta.Group]interface{}) bool {
if len(groupsMatcher) == 0 {
return true
}
@@ -256,7 +258,7 @@ func isGroupsMatching(worker WorkerInfo, groupsMatcher map[Group]interface{}) bo
}
// ListWorkers is an implementation of ListWorkers from Workers interface.
-func (wl *WorkerList) ListWorkers(groups Groups, caps Capabilities) ([]WorkerInfo, error) {
+func (wl *WorkerList) ListWorkers(groups boruta.Groups, caps boruta.Capabilities) ([]boruta.WorkerInfo, error) {
wl.mutex.RLock()
defer wl.mutex.RUnlock()
@@ -267,10 +269,10 @@ func (wl *WorkerList) ListWorkers(groups Groups, caps Capabilities) ([]WorkerInf
// * any of the groups is matching (or groups is nil)
// * all of the caps is matching (or caps is nil)
// Caller of this method should own the mutex.
-func (wl *WorkerList) listWorkers(groups Groups, caps Capabilities) ([]WorkerInfo, error) {
- matching := make([]WorkerInfo, 0, len(wl.workers))
+func (wl *WorkerList) listWorkers(groups boruta.Groups, caps boruta.Capabilities) ([]boruta.WorkerInfo, error) {
+ matching := make([]boruta.WorkerInfo, 0, len(wl.workers))
- groupsMatcher := make(map[Group]interface{})
+ groupsMatcher := make(map[boruta.Group]interface{})
for _, group := range groups {
groupsMatcher[group] = nil
}
@@ -285,18 +287,18 @@ func (wl *WorkerList) listWorkers(groups Groups, caps Capabilities) ([]WorkerInf
}
// GetWorkerInfo is an implementation of GetWorkerInfo from Workers interface.
-func (wl *WorkerList) GetWorkerInfo(uuid WorkerUUID) (WorkerInfo, error) {
+func (wl *WorkerList) GetWorkerInfo(uuid boruta.WorkerUUID) (boruta.WorkerInfo, error) {
wl.mutex.RLock()
defer wl.mutex.RUnlock()
worker, ok := wl.workers[uuid]
if !ok {
- return WorkerInfo{}, ErrWorkerNotFound
+ return boruta.WorkerInfo{}, ErrWorkerNotFound
}
return worker.WorkerInfo, nil
}
// GetWorkerAddr retrieves IP address from the internal structure.
-func (wl *WorkerList) GetWorkerAddr(uuid WorkerUUID) (net.TCPAddr, error) {
+func (wl *WorkerList) GetWorkerAddr(uuid boruta.WorkerUUID) (net.TCPAddr, error) {
wl.mutex.RLock()
defer wl.mutex.RUnlock()
worker, ok := wl.workers[uuid]
@@ -307,7 +309,7 @@ func (wl *WorkerList) GetWorkerAddr(uuid WorkerUUID) (net.TCPAddr, error) {
}
// GetWorkerSSHAddr retrieves address of worker's ssh daemon from the internal structure.
-func (wl *WorkerList) GetWorkerSSHAddr(uuid WorkerUUID) (net.TCPAddr, error) {
+func (wl *WorkerList) GetWorkerSSHAddr(uuid boruta.WorkerUUID) (net.TCPAddr, error) {
wl.mutex.RLock()
defer wl.mutex.RUnlock()
worker, ok := wl.workers[uuid]
@@ -319,7 +321,7 @@ func (wl *WorkerList) GetWorkerSSHAddr(uuid WorkerUUID) (net.TCPAddr, error) {
// SetWorkerKey stores private key in the worker structure referenced by uuid.
// It is safe to modify key after call to this function.
-func (wl *WorkerList) SetWorkerKey(uuid WorkerUUID, key *rsa.PrivateKey) error {
+func (wl *WorkerList) SetWorkerKey(uuid boruta.WorkerUUID, key *rsa.PrivateKey) error {
wl.mutex.Lock()
defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
@@ -333,7 +335,7 @@ func (wl *WorkerList) SetWorkerKey(uuid WorkerUUID, key *rsa.PrivateKey) error {
}
// GetWorkerKey retrieves key from the internal structure.
-func (wl *WorkerList) GetWorkerKey(uuid WorkerUUID) (rsa.PrivateKey, error) {
+func (wl *WorkerList) GetWorkerKey(uuid boruta.WorkerUUID) (rsa.PrivateKey, error) {
wl.mutex.RLock()
defer wl.mutex.RUnlock()
worker, ok := wl.workers[uuid]
@@ -349,7 +351,7 @@ func (wl *WorkerList) GetWorkerKey(uuid WorkerUUID) (rsa.PrivateKey, error) {
// it is put into RUN state and its UUID is returned. An error is returned if no
// matching IDLE worker is found.
// It is a part of WorkersManager interface implementation by WorkerList.
-func (wl *WorkerList) TakeBestMatchingWorker(groups Groups, caps Capabilities) (bestWorker WorkerUUID, err error) {
+func (wl *WorkerList) TakeBestMatchingWorker(groups boruta.Groups, caps boruta.Capabilities) (bestWorker boruta.WorkerUUID, err error) {
wl.mutex.Lock()
defer wl.mutex.Unlock()
@@ -357,7 +359,7 @@ func (wl *WorkerList) TakeBestMatchingWorker(groups Groups, caps Capabilities) (
matching, _ := wl.listWorkers(groups, caps)
for _, info := range matching {
- if info.State != IDLE {
+ if info.State != boruta.IDLE {
continue
}
score := len(info.Caps) + len(info.Groups)
@@ -371,7 +373,7 @@ func (wl *WorkerList) TakeBestMatchingWorker(groups Groups, caps Capabilities) (
return
}
- err = wl.setState(bestWorker, RUN)
+ err = wl.setState(bestWorker, boruta.RUN)
return
}
@@ -384,11 +386,11 @@ func (wl *WorkerList) TakeBestMatchingWorker(groups Groups, caps Capabilities) (
// As key creation can take some time, the method is asynchronous and the worker's
// state might not be changed when it returns.
// It is a part of WorkersManager interface implementation by WorkerList.
-func (wl *WorkerList) PrepareWorker(worker WorkerUUID, withKeyGeneration bool) error {
+func (wl *WorkerList) PrepareWorker(worker boruta.WorkerUUID, withKeyGeneration bool) error {
if !withKeyGeneration {
wl.mutex.Lock()
defer wl.mutex.Unlock()
- return wl.setState(worker, IDLE)
+ return wl.setState(worker, boruta.IDLE)
}
go wl.prepareKeyAndSetState(worker)
@@ -399,45 +401,45 @@ func (wl *WorkerList) PrepareWorker(worker WorkerUUID, withKeyGeneration bool) e
// prepareKeyAndSetState prepares private RSA key for the worker and sets worker
// into IDLE state in case of success. In case of failure of key preparation,
// worker is put into FAIL state instead.
-func (wl *WorkerList) prepareKeyAndSetState(worker WorkerUUID) {
+func (wl *WorkerList) prepareKeyAndSetState(worker boruta.WorkerUUID) {
err := wl.prepareKey(worker)
wl.mutex.Lock()
defer wl.mutex.Unlock()
if err != nil {
// TODO log error.
- wl.setState(worker, FAIL)
+ wl.setState(worker, boruta.FAIL)
return
}
- wl.setState(worker, IDLE)
+ wl.setState(worker, boruta.IDLE)
}
// putInMaintenanceWorker puts Dryad into maintenance mode and sets worker
// into MAINTENANCE state in case of success. In case of failure of entering
// maintenance mode, worker is put into FAIL state instead.
-func (wl *WorkerList) putInMaintenanceWorker(worker WorkerUUID) {
+func (wl *WorkerList) putInMaintenanceWorker(worker boruta.WorkerUUID) {
err := wl.putInMaintenance(worker)
wl.mutex.Lock()
defer wl.mutex.Unlock()
if err != nil {
- wl.setState(worker, FAIL)
+ wl.setState(worker, boruta.FAIL)
return
}
- wl.setState(worker, MAINTENANCE)
+ wl.setState(worker, boruta.MAINTENANCE)
}
// setState changes state of worker. It does not contain any verification if change
// is feasible. It should be used only for internal boruta purposes. It must be
// called inside WorkerList critical section guarded by WorkerList.mutex.
-func (wl *WorkerList) setState(worker WorkerUUID, state WorkerState) error {
+func (wl *WorkerList) setState(worker boruta.WorkerUUID, state boruta.WorkerState) error {
w, ok := wl.workers[worker]
if !ok {
return ErrWorkerNotFound
}
if wl.changeListener != nil {
- if state == IDLE {
+ if state == boruta.IDLE {
wl.changeListener.OnWorkerIdle(worker)
} else {
- if w.State == RUN {
+ if w.State == boruta.RUN {
wl.changeListener.OnWorkerFail(worker)
}
}
@@ -447,7 +449,7 @@ func (wl *WorkerList) setState(worker WorkerUUID, state WorkerState) error {
}
// prepareKey generates key, installs public part on worker and stores private part in WorkerList.
-func (wl *WorkerList) prepareKey(worker WorkerUUID) error {
+func (wl *WorkerList) prepareKey(worker boruta.WorkerUUID) error {
addr, err := wl.GetWorkerAddr(worker)
if err != nil {
return err
@@ -475,7 +477,7 @@ func (wl *WorkerList) prepareKey(worker WorkerUUID) error {
}
// putInMaintenance orders Dryad to enter maintenance mode.
-func (wl *WorkerList) putInMaintenance(worker WorkerUUID) error {
+func (wl *WorkerList) putInMaintenance(worker boruta.WorkerUUID) error {
addr, err := wl.GetWorkerAddr(worker)
if err != nil {
return err