65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package uniss
|
|
|
|
// TODO
|
|
// 1.data center object 2.swarm stop after scheduler
|
|
|
|
import (
|
|
"context"
|
|
"dashboard/logger"
|
|
"dashboard/models"
|
|
"dashboard/pkg/errgroups"
|
|
"dashboard/settings"
|
|
)
|
|
|
|
var log *logger.Logger
|
|
|
|
type UnisStation struct {
|
|
commonService *commonService
|
|
communicateService *communicateService
|
|
dataCenterService *dataCenterService
|
|
}
|
|
|
|
func NewUnis(_log *logger.Logger, conf *settings.UnisConfig) (res *UnisStation, err error) {
|
|
res = new(UnisStation)
|
|
log = _log
|
|
|
|
res.dataCenterService = newDataCenterService(conf)
|
|
res.communicateService, err = newcommunicateService(conf)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
res.commonService = newcommonService(res.communicateService)
|
|
|
|
return
|
|
}
|
|
|
|
func (u *UnisStation) GetHttpChannel() chan *models.UnisHttpRequest {
|
|
return u.communicateService.httpServerHandler.httpC
|
|
}
|
|
|
|
func (u *UnisStation) mainthread(ctx context.Context) error {
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
log.Error("Unis mesageHandle cancel by ctx")
|
|
return ctx.Err()
|
|
case httpMsg := <-u.communicateService.httpServerHandler.httpC:
|
|
u.communicateService.httpServerHandler.httpHandle(httpMsg)
|
|
case httpc := <-u.communicateService.httpClientHandler.httpC:
|
|
u.communicateService.httpClientHandler.httpClientHandle(httpc)
|
|
// default:
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func (u *UnisStation) Run(ctx context.Context) error {
|
|
ewgs := errgroups.NewErrGroupFunc()
|
|
|
|
ewgs.Add(u.communicateService.Run)
|
|
ewgs.Add(u.mainthread)
|
|
|
|
return ewgs.Run(ctx)
|
|
}
|