import (
"crypto/rsa"
"net"
+ "sync"
. "git.tizen.org/tools/boruta"
)
Superviser
Workers
workers map[WorkerUUID]*mapWorker
+ mutex *sync.RWMutex
}
// NewWorkerList returns a new WorkerList with all fields set.
func NewWorkerList() *WorkerList {
return &WorkerList{
workers: make(map[WorkerUUID]*mapWorker),
+ mutex: new(sync.RWMutex),
}
}
return ErrMissingUUID
}
uuid := WorkerUUID(capsUUID)
+ wl.mutex.Lock()
+ defer wl.mutex.Unlock()
worker, registered := wl.workers[uuid]
if registered {
// Subsequent Register calls update the caps.
//
// TODO(amistewicz): WorkerList should process the reason and store it.
func (wl *WorkerList) SetFail(uuid WorkerUUID, reason string) error {
+ wl.mutex.Lock()
+ defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
if state != MAINTENANCE && state != IDLE {
return ErrWrongStateArgument
}
+ wl.mutex.Lock()
+ defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
// SetGroups is an implementation of SetGroups from Workers interface.
func (wl *WorkerList) SetGroups(uuid WorkerUUID, groups Groups) error {
+ wl.mutex.Lock()
+ defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
// Deregister is an implementation of Deregister from Workers interface.
func (wl *WorkerList) Deregister(uuid WorkerUUID) error {
+ wl.mutex.Lock()
+ defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
// GetWorkerInfo is an implementation of GetWorkerInfo from Workers interface.
func (wl *WorkerList) GetWorkerInfo(uuid WorkerUUID) (WorkerInfo, error) {
+ wl.mutex.RLock()
+ defer wl.mutex.RUnlock()
worker, ok := wl.workers[uuid]
if !ok {
return WorkerInfo{}, ErrWorkerNotFound
// It should be called after Register by function which is aware of
// the source of the connection and therefore its IP address.
func (wl *WorkerList) SetWorkerIP(uuid WorkerUUID, ip net.IP) error {
+ wl.mutex.Lock()
+ defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
// GetWorkerIP retrieves IP address from the internal structure.
func (wl *WorkerList) GetWorkerIP(uuid WorkerUUID) (net.IP, error) {
+ wl.mutex.RLock()
+ defer wl.mutex.RUnlock()
worker, ok := wl.workers[uuid]
if !ok {
return nil, ErrWorkerNotFound
// 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 {
+ wl.mutex.Lock()
+ defer wl.mutex.Unlock()
worker, ok := wl.workers[uuid]
if !ok {
return ErrWorkerNotFound
// GetWorkerKey retrieves key from the internal structure.
func (wl *WorkerList) GetWorkerKey(uuid WorkerUUID) (rsa.PrivateKey, error) {
+ wl.mutex.RLock()
+ defer wl.mutex.RUnlock()
worker, ok := wl.workers[uuid]
if !ok {
return rsa.PrivateKey{}, ErrWorkerNotFound