|
|
|
@ -10,16 +10,42 @@ import ( |
|
|
|
|
// ActionType ...
|
|
|
|
|
type ActionType byte |
|
|
|
|
|
|
|
|
|
// Constants ...
|
|
|
|
|
// Constants for Action Type.
|
|
|
|
|
const ( |
|
|
|
|
SyncingAction ActionType = iota |
|
|
|
|
KillSyncingAction |
|
|
|
|
Start ActionType = iota |
|
|
|
|
Stop |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Type is service type.
|
|
|
|
|
type Type byte |
|
|
|
|
|
|
|
|
|
// Constants for Type.
|
|
|
|
|
const ( |
|
|
|
|
SyncingSupport Type = iota |
|
|
|
|
SupportClient |
|
|
|
|
SupportExplorer |
|
|
|
|
SyncingActionTest |
|
|
|
|
Test |
|
|
|
|
Done |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func (t Type) String() string { |
|
|
|
|
switch t { |
|
|
|
|
case SupportClient: |
|
|
|
|
return "SupportClient" |
|
|
|
|
case SyncingSupport: |
|
|
|
|
return "SyncingSupport" |
|
|
|
|
case SupportExplorer: |
|
|
|
|
return "SupportExplorer" |
|
|
|
|
case Test: |
|
|
|
|
return "Test" |
|
|
|
|
case Done: |
|
|
|
|
return "Done" |
|
|
|
|
default: |
|
|
|
|
return "Unknown" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Constants for timing.
|
|
|
|
|
const ( |
|
|
|
|
// WaitForStatusUpdate is the delay time to update new status. Currently set 1 second for development. Should be 30 minutes for production.
|
|
|
|
|
WaitForStatusUpdate = time.Second * 1 |
|
|
|
@ -27,8 +53,20 @@ const ( |
|
|
|
|
|
|
|
|
|
// Action is type of service action.
|
|
|
|
|
type Action struct { |
|
|
|
|
t ActionType |
|
|
|
|
params map[string]interface{} |
|
|
|
|
action ActionType |
|
|
|
|
serviceType Type |
|
|
|
|
params map[string]interface{} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ServiceInterface ...
|
|
|
|
|
type ServiceInterface interface { |
|
|
|
|
Start() |
|
|
|
|
Stop() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ServiceStore stores all services for service manager.
|
|
|
|
|
type ServiceStore struct { |
|
|
|
|
services map[Type]ServiceInterface |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Start node.
|
|
|
|
@ -43,18 +81,19 @@ func (node *Node) SendAction(action *Action) { |
|
|
|
|
|
|
|
|
|
// TakeAction ...
|
|
|
|
|
func (node *Node) TakeAction(action *Action) { |
|
|
|
|
switch action.t { |
|
|
|
|
case SyncingActionTest: |
|
|
|
|
fmt.Println("Running syncing support") |
|
|
|
|
case SyncingAction: |
|
|
|
|
utils.GetLogInstance().Info("Running syncing support") |
|
|
|
|
go node.SupportSyncing() |
|
|
|
|
case KillSyncingAction: |
|
|
|
|
utils.GetLogInstance().Info("Killing syncing") |
|
|
|
|
case SupportClient: |
|
|
|
|
go node.SupportClient() |
|
|
|
|
case SupportExplorer: |
|
|
|
|
go node.SupportExplorer() |
|
|
|
|
if node.serviceStore == nil { |
|
|
|
|
utils.GetLogInstance().Error("Service store is not initialized.") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if service, ok := node.serviceStore.services[action.serviceType]; ok { |
|
|
|
|
switch action.action { |
|
|
|
|
case Start: |
|
|
|
|
fmt.Printf("Start %s\n", action.serviceType) |
|
|
|
|
service.Start() |
|
|
|
|
case Stop: |
|
|
|
|
fmt.Printf("Stop %s\n", action.serviceType) |
|
|
|
|
service.Stop() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,7 +105,7 @@ func (node *Node) StartServiceManager() chan *Action { |
|
|
|
|
select { |
|
|
|
|
case action := <-ch: |
|
|
|
|
node.TakeAction(action) |
|
|
|
|
if action.t == Done { |
|
|
|
|
if action.serviceType == Done { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
case <-time.After(WaitForStatusUpdate): |
|
|
|
|