[REV] record pod events

This commit is contained in:
GLYASAI 2019-08-22 19:31:46 +08:00
parent b6fd61d291
commit de385b8613
9 changed files with 164 additions and 100 deletions

View File

@ -166,25 +166,6 @@ func (m *Manager) callback(controllerID string, err error) {
delete(m.controllers, controllerID)
}
func getLoggerOption(status string) map[string]string {
return map[string]string{"step": "appruntime", "status": status}
}
//GetCallbackLoggerOption get callback logger
func GetCallbackLoggerOption() map[string]string {
return map[string]string{"step": "callback", "status": "failure"}
}
//GetTimeoutLoggerOption get callback logger
func GetTimeoutLoggerOption() map[string]string {
return map[string]string{"step": "callback", "status": "timeout"}
}
//GetLastLoggerOption get last logger
func GetLastLoggerOption() map[string]string {
return map[string]string{"step": "last", "status": "success"}
}
type sequencelist []sequence
type sequence []*v1.AppService

View File

@ -23,11 +23,11 @@ import (
"sync"
"time"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/worker/appm/conversion"
"github.com/Sirupsen/logrus"
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"github.com/goodrain/rainbond/worker/util"
)
type restartController struct {
@ -43,11 +43,11 @@ func (s *restartController) Begin() {
go func(service v1.AppService) {
wait.Add(1)
defer wait.Done()
service.Logger.Info("App runtime begin restart app service "+service.ServiceAlias, getLoggerOption("starting"))
service.Logger.Info("App runtime begin restart app service "+service.ServiceAlias, util.GetLoggerOption("starting"))
if err := s.restartOne(service); err != nil {
logrus.Errorf("restart service %s failure %s", service.ServiceAlias, err.Error())
} else {
service.Logger.Info(fmt.Sprintf("restart service %s success", service.ServiceAlias), GetLastLoggerOption())
service.Logger.Info(fmt.Sprintf("restart service %s success", service.ServiceAlias), util.GetLastLoggerOption())
}
}(service)
}
@ -62,7 +62,7 @@ func (s *restartController) restartOne(app v1.AppService) error {
}
if err := stopController.stopOne(app); err != nil {
if err != ErrWaitTimeOut {
app.Logger.Error("(Restart)Stop app failure %s,you could waiting stoped and manual start it", GetCallbackLoggerOption())
app.Logger.Error("(Restart)Stop app failure %s,you could waiting stoped and manual start it", util.GetCallbackLoggerOption())
return err
}
//waiting app closed,max wait 40 second
@ -82,7 +82,7 @@ func (s *restartController) restartOne(app v1.AppService) error {
newAppService, err := conversion.InitAppService(db.GetManager(), app.ServiceID, app.ExtensionSet)
if err != nil {
logrus.Errorf("Application model init create failure:%s", err.Error())
app.Logger.Error("Application model init create failure", GetCallbackLoggerOption())
app.Logger.Error("Application model init create failure", util.GetCallbackLoggerOption())
return fmt.Errorf("Application model init create failure,%s", err.Error())
}
newAppService.Logger = app.Logger

View File

@ -20,6 +20,7 @@ package controller
import (
"fmt"
"github.com/goodrain/rainbond/worker/util"
"math"
"sync"
"time"
@ -43,16 +44,16 @@ func (s *scalingController) Begin() {
go func(service v1.AppService) {
wait.Add(1)
defer wait.Done()
service.Logger.Info("App runtime begin horizontal scaling app service "+service.ServiceAlias, getLoggerOption("starting"))
service.Logger.Info("App runtime begin horizontal scaling app service "+service.ServiceAlias, util.GetLoggerOption("starting"))
if err := s.scalingOne(service); err != nil {
if err != ErrWaitTimeOut {
service.Logger.Error(fmt.Sprintf("horizontal scaling service %s failure %s", service.ServiceAlias, err.Error()), GetCallbackLoggerOption())
service.Logger.Error(fmt.Sprintf("horizontal scaling service %s failure %s", service.ServiceAlias, err.Error()), util.GetCallbackLoggerOption())
logrus.Errorf("horizontal scaling service %s failure %s", service.ServiceAlias, err.Error())
} else {
service.Logger.Error(fmt.Sprintf("horizontal scaling service timeout,please waiting it complete"), GetTimeoutLoggerOption())
service.Logger.Error(fmt.Sprintf("horizontal scaling service timeout,please waiting it complete"), util.GetTimeoutLoggerOption())
}
} else {
service.Logger.Info(fmt.Sprintf("horizontal scaling service %s success", service.ServiceAlias), GetLastLoggerOption())
service.Logger.Info(fmt.Sprintf("horizontal scaling service %s success", service.ServiceAlias), util.GetLastLoggerOption())
}
}(service)
}

View File

@ -20,6 +20,7 @@ package controller
import (
"fmt"
"github.com/goodrain/rainbond/worker/util"
"sync"
"time"
@ -55,19 +56,19 @@ func (s *startController) Begin() {
wait.Add(1)
defer wait.Done()
logrus.Debugf("App runtime begin start app service(%s)", service.ServiceAlias)
service.Logger.Info("App runtime begin start app service "+service.ServiceAlias, getLoggerOption("starting"))
service.Logger.Info("App runtime begin start app service "+service.ServiceAlias, util.GetLoggerOption("starting"))
if err := s.startOne(service); err != nil {
if err != ErrWaitTimeOut {
service.Logger.Error(fmt.Sprintf("Start service %s failure %s", service.ServiceAlias, err.Error()), GetCallbackLoggerOption())
service.Logger.Error(fmt.Sprintf("Start service %s failure %s", service.ServiceAlias, err.Error()), util.GetCallbackLoggerOption())
logrus.Errorf("start service %s failure %s", service.ServiceAlias, err.Error())
s.errorCallback(service)
} else {
logrus.Debugf("Start service %s timeout, please wait or read service log.", service.ServiceAlias)
service.Logger.Error(fmt.Sprintf("Start service %s timeout,please wait or read service log.", service.ServiceAlias), GetTimeoutLoggerOption())
service.Logger.Error(fmt.Sprintf("Start service %s timeout,please wait or read service log.", service.ServiceAlias), util.GetTimeoutLoggerOption())
}
} else {
logrus.Debugf("Start service %s success", service.ServiceAlias)
service.Logger.Info(fmt.Sprintf("Start service %s success", service.ServiceAlias), GetLastLoggerOption())
service.Logger.Info(fmt.Sprintf("Start service %s success", service.ServiceAlias), util.GetLastLoggerOption())
}
}(*service)
}
@ -76,13 +77,13 @@ func (s *startController) Begin() {
}
}
func (s *startController) errorCallback(app v1.AppService) error {
app.Logger.Info("Begin clean resources that have been created", getLoggerOption("starting"))
app.Logger.Info("Begin clean resources that have been created", util.GetLoggerOption("starting"))
stopController := stopController{
manager: s.manager,
}
if err := stopController.stopOne(app); err != nil {
logrus.Errorf("stop app failure after start failure. %s", err.Error())
app.Logger.Error(fmt.Sprintf("Stop app failure %s", app.ServiceAlias), getLoggerOption("failure"))
app.Logger.Error(fmt.Sprintf("Stop app failure %s", app.ServiceAlias), util.GetLoggerOption("failure"))
return err
}
return nil
@ -145,7 +146,7 @@ func (s *startController) startOne(app v1.AppService) error {
}
}
//step 6: waiting endpoint ready
app.Logger.Info("Create all app model success, will waiting app ready", getLoggerOption("running"))
app.Logger.Info("Create all app model success, will waiting app ready", util.GetLoggerOption("running"))
return s.WaitingReady(app)
}

View File

@ -20,6 +20,7 @@ package controller
import (
"fmt"
"github.com/goodrain/rainbond/worker/util"
"sync"
"time"
@ -44,16 +45,16 @@ func (s *stopController) Begin() {
go func(service v1.AppService) {
wait.Add(1)
defer wait.Done()
service.Logger.Info("App runtime begin stop app service "+service.ServiceAlias, getLoggerOption("starting"))
service.Logger.Info("App runtime begin stop app service "+service.ServiceAlias, util.GetLoggerOption("starting"))
if err := s.stopOne(service); err != nil {
if err != ErrWaitTimeOut {
service.Logger.Error(fmt.Sprintf("stop service %s failure %s", service.ServiceAlias, err.Error()), GetCallbackLoggerOption())
service.Logger.Error(fmt.Sprintf("stop service %s failure %s", service.ServiceAlias, err.Error()), util.GetCallbackLoggerOption())
logrus.Errorf("stop service %s failure %s", service.ServiceAlias, err.Error())
} else {
service.Logger.Error(fmt.Sprintf("stop service timeout,please waiting it closed"), GetTimeoutLoggerOption())
service.Logger.Error(fmt.Sprintf("stop service timeout,please waiting it closed"), util.GetTimeoutLoggerOption())
}
} else {
service.Logger.Info(fmt.Sprintf("stop service %s success", service.ServiceAlias), GetLastLoggerOption())
service.Logger.Info(fmt.Sprintf("stop service %s success", service.ServiceAlias), util.GetLastLoggerOption())
}
}(service)
}
@ -139,7 +140,7 @@ func (s *stopController) stopOne(app v1.AppService) error {
}
}
//step 7: waiting endpoint ready
app.Logger.Info("Delete all app model success, will waiting app closed", getLoggerOption("running"))
app.Logger.Info("Delete all app model success, will waiting app closed", util.GetLoggerOption("running"))
return s.WaitingReady(app)
}
func (s *stopController) Stop() error {

View File

@ -20,6 +20,7 @@ package controller
import (
"fmt"
"github.com/goodrain/rainbond/worker/util"
"sync"
"time"
@ -46,16 +47,16 @@ func (s *upgradeController) Begin() {
go func(service v1.AppService) {
wait.Add(1)
defer wait.Done()
service.Logger.Info("App runtime begin upgrade app service "+service.ServiceAlias, getLoggerOption("starting"))
service.Logger.Info("App runtime begin upgrade app service "+service.ServiceAlias, util.GetLoggerOption("starting"))
if err := s.upgradeOne(service); err != nil {
if err != ErrWaitTimeOut {
service.Logger.Error(fmt.Sprintf("upgrade service %s failure %s", service.ServiceAlias, err.Error()), GetCallbackLoggerOption())
service.Logger.Error(fmt.Sprintf("upgrade service %s failure %s", service.ServiceAlias, err.Error()), util.GetCallbackLoggerOption())
logrus.Errorf("upgrade service %s failure %s", service.ServiceAlias, err.Error())
} else {
service.Logger.Error(fmt.Sprintf("upgrade service timeout,please waiting it complete"), GetTimeoutLoggerOption())
service.Logger.Error(fmt.Sprintf("upgrade service timeout,please waiting it complete"), util.GetTimeoutLoggerOption())
}
} else {
service.Logger.Info(fmt.Sprintf("upgrade service %s success", service.ServiceAlias), GetLastLoggerOption())
service.Logger.Info(fmt.Sprintf("upgrade service %s success", service.ServiceAlias), util.GetLastLoggerOption())
}
}(service)
}
@ -157,14 +158,14 @@ func (s *upgradeController) upgradeOne(app v1.AppService) error {
if deployment := app.GetDeployment(); deployment != nil {
_, err := s.manager.client.AppsV1().Deployments(deployment.Namespace).Patch(deployment.Name, types.MergePatchType, app.UpgradePatch["deployment"])
if err != nil {
app.Logger.Error(fmt.Sprintf("upgrade deployment %s failure %s", app.ServiceAlias, err.Error()), getLoggerOption("failure"))
app.Logger.Error(fmt.Sprintf("upgrade deployment %s failure %s", app.ServiceAlias, err.Error()), util.GetLoggerOption("failure"))
return fmt.Errorf("upgrade deployment %s failure %s", app.ServiceAlias, err.Error())
}
}
if statefulset := app.GetStatefulSet(); statefulset != nil {
_, err := s.manager.client.AppsV1().StatefulSets(statefulset.Namespace).Patch(statefulset.Name, types.MergePatchType, app.UpgradePatch["statefulset"])
if err != nil {
app.Logger.Error(fmt.Sprintf("upgrade statefulset %s failure %s", app.ServiceAlias, err.Error()), getLoggerOption("failure"))
app.Logger.Error(fmt.Sprintf("upgrade statefulset %s failure %s", app.ServiceAlias, err.Error()), util.GetLoggerOption("failure"))
return fmt.Errorf("upgrade statefulset %s failure %s", app.ServiceAlias, err.Error())
}
}

View File

@ -30,9 +30,12 @@ import (
"github.com/goodrain/rainbond/cmd/worker/option"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/util"
"github.com/goodrain/rainbond/worker/appm/conversion"
"github.com/goodrain/rainbond/worker/appm/f"
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
wutil "github.com/goodrain/rainbond/worker/util"
"github.com/jinzhu/gorm"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
@ -241,7 +244,7 @@ func NewStore(clientset *kubernetes.Clientset,
store.informers.Deployment.AddEventHandlerWithResyncPeriod(store, time.Second*10)
store.informers.StatefulSet.AddEventHandlerWithResyncPeriod(store, time.Second*10)
store.informers.Pod.AddEventHandlerWithResyncPeriod(store, time.Second*10)
store.informers.Pod.AddEventHandlerWithResyncPeriod(store.podEventHandler(), time.Second*10)
store.informers.Secret.AddEventHandlerWithResyncPeriod(store, time.Second*10)
store.informers.Service.AddEventHandlerWithResyncPeriod(store, time.Second*10)
store.informers.Ingress.AddEventHandlerWithResyncPeriod(store, time.Second*10)
@ -451,22 +454,6 @@ func (a *appRuntimeStore) OnAdd(obj interface{}) {
}
}
}
if pod, ok := obj.(*corev1.Pod); ok {
serviceID := pod.Labels["service_id"]
version := pod.Labels["version"]
createrID := pod.Labels["creater_id"]
if serviceID != "" && version != "" && createrID != "" {
appservice, err := a.getAppService(serviceID, version, createrID, true)
if err == conversion.ErrServiceNotFound {
a.conf.KubeClient.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{})
}
if appservice != nil {
appservice.SetPods(pod)
a.analyzePodStatus(pod)
return
}
}
}
if secret, ok := obj.(*corev1.Secret); ok {
serviceID := secret.Labels["service_id"]
version := secret.Labels["version"]
@ -593,21 +580,6 @@ func (a *appRuntimeStore) OnDelete(obj interface{}) {
}
}
}
if pod, ok := obj.(*corev1.Pod); ok {
serviceID := pod.Labels["service_id"]
version := pod.Labels["version"]
createrID := pod.Labels["creater_id"]
if serviceID != "" && version != "" && createrID != "" {
appservice, _ := a.getAppService(serviceID, version, createrID, false)
if appservice != nil {
appservice.DeletePods(pod)
if appservice.IsClosed() {
a.DeleteAppService(appservice)
}
return
}
}
}
if secret, ok := obj.(*corev1.Secret); ok {
serviceID := secret.Labels["service_id"]
version := secret.Labels["version"]
@ -1009,3 +981,88 @@ func (a *appRuntimeStore) GetTenantRunningApp(tenantID string) (list []*v1.AppSe
})
return
}
func (a *appRuntimeStore) podEventHandler() cache.ResourceEventHandler {
return cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
pod := obj.(*corev1.Pod)
_, serviceID, version, creatorID := parseLabels(pod.GetLabels())
if serviceID != "" && version != "" && creatorID != "" {
appservice, err := a.getAppService(serviceID, version, creatorID, true)
if err == conversion.ErrServiceNotFound {
a.conf.KubeClient.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{})
}
if appservice != nil {
appservice.SetPods(pod)
a.analyzePodStatus(pod)
return
}
// TODO
// eventID := createSystemEvent(tenantID, "create pod", "create pod; error creating event: %v")
// logger := event.GetManager().GetLogger(eventID)
// defer event.GetManager().ReleaseLogger(logger)
// logger.Info(fmt.Sprintf("create pod %s", pod.GetName()), wutil.GetLastLoggerOption())
}
},
UpdateFunc: func(old, new interface{}) {
opod := old.(*corev1.Pod)
npod := new.(*corev1.Pod)
tenantID, serviceID, version, creatorID := parseLabels(npod.GetLabels())
if serviceID != "" && version != "" && creatorID != "" {
appservice, err := a.getAppService(serviceID, version, creatorID, true)
if err == conversion.ErrServiceNotFound {
a.conf.KubeClient.CoreV1().Pods(npod.Namespace).Delete(npod.Name, &metav1.DeleteOptions{})
}
if appservice != nil {
appservice.SetPods(npod)
a.analyzePodStatus(npod)
return
}
if opod.Status.Phase != npod.Status.Phase {
eventID := createSystemEvent(tenantID, "instance changed", "pod changed; error creating event: %v")
logger := event.GetManager().GetLogger(eventID)
defer event.GetManager().ReleaseLogger(logger)
logger.Info(fmt.Sprintf("instance changed; old instance: %s; new instance: %s", opod.GetName(), npod.GetName()), wutil.GetLastLoggerOption())
}
}
},
DeleteFunc: func(obj interface{}) {
pod := obj.(*corev1.Pod)
tenantID, serviceID, version, creatorID := parseLabels(pod.GetLabels())
eventID := createSystemEvent(tenantID, "instance deleted", "instance deleted; error creating event: %v")
logger := event.GetManager().GetLogger(eventID)
defer event.GetManager().ReleaseLogger(logger)
logger.Info(fmt.Sprintf("instance deleted %s", pod.GetName()), wutil.GetLastLoggerOption())
if serviceID != "" && version != "" && creatorID != "" {
appservice, _ := a.getAppService(serviceID, version, creatorID, false)
if appservice != nil {
appservice.DeletePods(pod)
if appservice.IsClosed() {
a.DeleteAppService(appservice)
}
return
}
}
},
}
}
func createSystemEvent(tenantID, optType, msgFormat string) string {
eventID := util.NewUUID()
et := &model.ServiceEvent{
EventID: eventID,
TenantID: tenantID,
UserName: "system",
StartTime: time.Now().Format(time.RFC3339),
OptType: optType,
}
if err := db.GetManager().ServiceEventDao().AddModel(et); err != nil {
logrus.Warningf(msgFormat, err)
eventID = ""
}
return eventID
}
func parseLabels(labels map[string]string) (string, string, string, string) {
return labels["tenant_id"], labels["service_id"], labels["version"], labels["creatrt_id"]
}

View File

@ -35,6 +35,7 @@ import (
"github.com/goodrain/rainbond/worker/appm/store"
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"github.com/goodrain/rainbond/worker/discover/model"
util "github.com/goodrain/rainbond/worker/util"
)
//Manager manager
@ -128,14 +129,14 @@ func (m *Manager) startExec(task *model.Task) error {
logger := event.GetManager().GetLogger(body.EventID)
appService := m.store.GetAppService(body.ServiceID)
if appService != nil && !appService.IsClosed() {
logger.Info("Application is not closed, can not start", controller.GetLastLoggerOption())
logger.Info("Application is not closed, can not start", util.GetLastLoggerOption())
event.GetManager().ReleaseLogger(logger)
return nil
}
newAppService, err := conversion.InitAppService(m.dbmanager, body.ServiceID, body.Configs)
if err != nil {
logrus.Errorf("Application init create failure:%s", err.Error())
logger.Error("Application init create failure", controller.GetCallbackLoggerOption())
logger.Error("Application init create failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application init create failure")
}
@ -145,7 +146,7 @@ func (m *Manager) startExec(task *model.Task) error {
err = m.controllerManager.StartController(controller.TypeStartController, *newAppService)
if err != nil {
logrus.Errorf("Application run start controller failure:%s", err.Error())
logger.Error("Application run start controller failure", controller.GetCallbackLoggerOption())
logger.Error("Application run start controller failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application start failure")
}
@ -162,7 +163,7 @@ func (m *Manager) stopExec(task *model.Task) error {
logger := event.GetManager().GetLogger(body.EventID)
appService := m.store.GetAppService(body.ServiceID)
if appService == nil {
logger.Info("Application is closed, can not stop", controller.GetLastLoggerOption())
logger.Info("Application is closed, can not stop", util.GetLastLoggerOption())
event.GetManager().ReleaseLogger(logger)
return nil
}
@ -173,7 +174,7 @@ func (m *Manager) stopExec(task *model.Task) error {
err := m.controllerManager.StartController(controller.TypeStopController, *appService)
if err != nil {
logrus.Errorf("Application run stop controller failure:%s", err.Error())
logger.Info("Application run stop controller failure", controller.GetCallbackLoggerOption())
logger.Info("Application run stop controller failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application stop failure")
}
@ -190,7 +191,7 @@ func (m *Manager) restartExec(task *model.Task) error {
logger := event.GetManager().GetLogger(body.EventID)
appService := m.store.GetAppService(body.ServiceID)
if appService == nil {
logger.Info("Application is closed, can not stop", controller.GetLastLoggerOption())
logger.Info("Application is closed, can not stop", util.GetLastLoggerOption())
event.GetManager().ReleaseLogger(logger)
return nil
}
@ -202,7 +203,7 @@ func (m *Manager) restartExec(task *model.Task) error {
err := m.controllerManager.StartController(controller.TypeRestartController, *appService)
if err != nil {
logrus.Errorf("Application run restart controller failure:%s", err.Error())
logger.Info("Application run restart controller failure", controller.GetCallbackLoggerOption())
logger.Info("Application run restart controller failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application restart failure")
}
@ -219,14 +220,14 @@ func (m *Manager) horizontalScalingExec(task *model.Task) error {
logger := event.GetManager().GetLogger(body.EventID)
service, err := db.GetManager().TenantServiceDao().GetServiceByID(body.ServiceID)
if err != nil {
logger.Error("Get app base info failure", controller.GetCallbackLoggerOption())
logger.Error("Get app base info failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
logrus.Errorf("horizontal_scaling get rc error. %v", err)
return fmt.Errorf("a")
}
appService := m.store.GetAppService(body.ServiceID)
if appService == nil || appService.IsClosed() {
logger.Info("service is closed,no need handle", controller.GetLastLoggerOption())
logger.Info("service is closed,no need handle", util.GetLastLoggerOption())
return nil
}
appService.Logger = logger
@ -234,7 +235,7 @@ func (m *Manager) horizontalScalingExec(task *model.Task) error {
err = m.controllerManager.StartController(controller.TypeScalingController, *appService)
if err != nil {
logrus.Errorf("Application run scaling controller failure:%s", err.Error())
logger.Info("Application run scaling controller failure", controller.GetCallbackLoggerOption())
logger.Info("Application run scaling controller failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application scaling failure")
}
@ -252,13 +253,13 @@ func (m *Manager) verticalScalingExec(task *model.Task) error {
service, err := db.GetManager().TenantServiceDao().GetServiceByID(body.ServiceID)
if err != nil {
logrus.Errorf("vertical_scaling get rc error. %v", err)
logger.Error("Get app base info failure", controller.GetCallbackLoggerOption())
logger.Error("Get app base info failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("vertical_scaling get rc error. %v", err)
}
appService := m.store.GetAppService(body.ServiceID)
if appService == nil || appService.IsClosed() {
logger.Info("service is closed,no need handle", controller.GetLastLoggerOption())
logger.Info("service is closed,no need handle", util.GetLastLoggerOption())
event.GetManager().ReleaseLogger(logger)
return nil
}
@ -268,7 +269,7 @@ func (m *Manager) verticalScalingExec(task *model.Task) error {
newAppService, err := conversion.InitAppService(m.dbmanager, body.ServiceID, nil)
if err != nil {
logrus.Errorf("Application init create failure:%s", err.Error())
logger.Error("Application init create failure", controller.GetCallbackLoggerOption())
logger.Error("Application init create failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application init create failure")
}
@ -277,7 +278,7 @@ func (m *Manager) verticalScalingExec(task *model.Task) error {
err = m.controllerManager.StartController(controller.TypeUpgradeController, *newAppService)
if err != nil {
logrus.Errorf("Application run vertical scaling(upgrade) controller failure:%s", err.Error())
logger.Info("Application run vertical scaling(upgrade) controller failure", controller.GetCallbackLoggerOption())
logger.Info("Application run vertical scaling(upgrade) controller failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application vertical scaling(upgrade) failure")
}
@ -295,7 +296,7 @@ func (m *Manager) rollingUpgradeExec(task *model.Task) error {
newAppService, err := conversion.InitAppService(m.dbmanager, body.ServiceID, body.Configs)
if err != nil {
logrus.Errorf("Application init create failure:%s", err.Error())
logger.Error("Application init create failure", controller.GetCallbackLoggerOption())
logger.Error("Application init create failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application init create failure")
}
@ -308,7 +309,7 @@ func (m *Manager) rollingUpgradeExec(task *model.Task) error {
err = m.controllerManager.StartController(controller.TypeStartController, *newAppService)
if err != nil {
logrus.Errorf("Application run start controller failure:%s", err.Error())
logger.Info("Application run start controller failure", controller.GetCallbackLoggerOption())
logger.Info("Application run start controller failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application start failure")
}
@ -317,18 +318,18 @@ func (m *Manager) rollingUpgradeExec(task *model.Task) error {
}
if err := oldAppService.SetUpgradePatch(newAppService); err != nil {
if err.Error() == "no upgrade" {
logger.Info("Application no change no need upgrade.", controller.GetLastLoggerOption())
logger.Info("Application no change no need upgrade.", util.GetLastLoggerOption())
return nil
}
logrus.Errorf("Application get upgrade info error:%s", err.Error())
logger.Error(fmt.Sprintf("Application get upgrade info error:%s", err.Error()), controller.GetCallbackLoggerOption())
logger.Error(fmt.Sprintf("Application get upgrade info error:%s", err.Error()), util.GetCallbackLoggerOption())
return nil
}
//if service already deploy,upgrade it:
err = m.controllerManager.StartController(controller.TypeUpgradeController, *newAppService)
if err != nil {
logrus.Errorf("Application run upgrade controller failure:%s", err.Error())
logger.Info("Application run upgrade controller failure", controller.GetCallbackLoggerOption())
logger.Info("Application run upgrade controller failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application upgrade failure")
}
@ -353,7 +354,7 @@ func (m *Manager) applyRuleExec(task *model.Task) error {
if svc.Kind != dbmodel.ServiceKindThirdParty.String() && !strings.HasPrefix(body.Action, "port") {
if oldAppService == nil || oldAppService.IsClosed() {
logrus.Debugf("service is closed, no need handle")
logger.Info("service is closed,no need handle", controller.GetLastLoggerOption())
logger.Info("service is closed,no need handle", util.GetLastLoggerOption())
event.GetManager().ReleaseLogger(logger)
return nil
}
@ -367,7 +368,7 @@ func (m *Manager) applyRuleExec(task *model.Task) error {
}
if err != nil {
logrus.Errorf("Application init create failure:%s", err.Error())
logger.Error("Application init create failure", controller.GetCallbackLoggerOption())
logger.Error("Application init create failure", util.GetCallbackLoggerOption())
event.GetManager().ReleaseLogger(logger)
return fmt.Errorf("Application init create failure")
}

View File

@ -0,0 +1,21 @@
package util
// GetLoggerOption -
func GetLoggerOption(status string) map[string]string {
return map[string]string{"step": "appruntime", "status": status}
}
//GetCallbackLoggerOption get callback logger
func GetCallbackLoggerOption() map[string]string {
return map[string]string{"step": "callback", "status": "failure"}
}
//GetTimeoutLoggerOption get callback logger
func GetTimeoutLoggerOption() map[string]string {
return map[string]string{"step": "callback", "status": "timeout"}
}
//GetLastLoggerOption get last logger
func GetLastLoggerOption() map[string]string {
return map[string]string{"step": "last", "status": "success"}
}