/** ** It handles all events from megam engine **/ func EventsHandler(chann []byte) { m := &Message{} parse_err := json.Unmarshal(chann, &m) log.Info(parse_err) if parse_err != nil { log.Error("Error: Message parsing error:\n%s.", parse_err) return } switch m.Action { case "build": log.Info("============Build entry============") comp := global.Component{Id: m.Id} com, err := comp.Get(m.Id) if err != nil { log.Error("Error: Riak didn't cooperate:\n%s.", err) return } go app.BuildApp(com) break } }
return CommandExecutor("stop", &app) }, Backward: func(ctx action.BWContext) { log.Info("[%s] Nothing to recover") }, MinParams: 1, } /** ** restart the application or service **/ var restartComponent = action.Action{ Name: "restartcomponent", Forward: func(ctx action.FWContext) (action.Result, error) { var app global.Component switch ctx.Params[0].(type) { case global.Component: app = ctx.Params[0].(global.Component) case *global.Component: app = *ctx.Params[0].(*global.Component) default: return nil, errors.New("First parameter must be App or *global.Component.") } ctype := strings.Split(app.ToscaType, ".") app.Command = "stop " + ctype[2] + "; " + "start " + ctype[2] return ComponentCommandExecutor(&app) }, Backward: func(ctx action.BWContext) { log.Info("[%s] Nothing to recover") },
func Handler(chann []byte) { m := &Message{} parse_err := json.Unmarshal(chann, &m) log.Info(parse_err) if parse_err != nil { log.Error("Error: Message parsing error:\n%s.", parse_err) return } log.Info("============Request entry===========") apprequest := global.AppRequest{Id: m.Id} req, err := apprequest.Get(m.Id) log.Info(req) if err != nil { log.Error("Error: Riak didn't cooperate->:\n%s.", err) return } assembly := global.Assembly{Id: req.AppId} asm, err := assembly.GetAssemblyWithComponents(req.AppId) if err != nil { log.Error("Error: Riak didn't cooperate-->:\n%s.", err) return } comp := global.Component{Id: asm.Components[0].Id} com, err := comp.Get(asm.Components[0].Id) if err != nil { log.Error("Error: Riak didn't cooperate--->:\n%s.", err) return } switch req.Action { case "reboot": log.Info("============Reboot entry==========") go app.RebootApp(asm) break case "start": log.Info("============Start entry===========") go app.StartApp(asm) break case "stop": log.Info("============Stop entry============") go app.StopApp(asm) break case "restart": log.Info("============Restart entry============") go app.RestartApp(asm) break case "redeploy": log.Info("=============Redeploying=============") go app.BuildApp(com) break /*case "componentstart": log.Info("============Component Start entry======") go app.StartComponent(com) break case "componentstop": log.Info("============Component Stop entry======") go app.StopComponent(com) break case "componentrestart": log.Info("============Component Restart entry======") go app.RestartComponent(com) break */ } }