func PolicyHandler() { log.Info("==>Policy Handler entry==") id, err := config.GetString("id") if err != nil { return } assembly := global.Assembly{Id: id} asm, asmerr := assembly.GetAssemblyWithComponents(id) if asmerr != nil { log.Error("Error: Riak didn't cooperate:\n%s.", asmerr) return } policies.ApplyPolicies(asm) }
func uploadENVVariables(asm *global.AssemblyWithComponents, com *global.Component) error { megam_home, ckberr := config.GetString("megam_home") if ckberr != nil { return ckberr } conn, err := db.Conn("assemblies") if err != nil { return err } act_id, actberr := config.GetString("account_id") if actberr != nil { return actberr } arr, ferr := conn.FetchObjectByIndex("assemblies", ASSEMBLIESINDEX, act_id, "", "") if ferr != nil { return ferr } for i := range arr { s := global.BytesToString(arr[i]) rassemblies := &global.Assemblies{} rams, ramserr := rassemblies.Get(s) if ramserr != nil { return ramserr } for l := range rams.Assemblies { if len(rams.Assemblies[l]) > 0 { assembly := global.Assembly{Id: rams.Assemblies[l]} rasm, rasmerr := assembly.GetAssemblyWithComponents(rams.Assemblies[l]) if rasmerr != nil { log.Error("Error: Riak didn't cooperate:\n%s.", rasmerr) return rasmerr } for j := range com.RelatedComponents { if len(com.RelatedComponents[j]) > 0 { rasmname := strings.Split(com.RelatedComponents[j], "/") assemblyname := strings.Split(rasmname[0], ".")[0] if rasm.Name == assemblyname { for rc := range rasm.Components { if rasm.Components[rc] != nil { if rasmname[1] == rasm.Components[rc].Name { basePath := megam_home dir := path.Join(basePath, com.Name) filePath := path.Join(dir, "env.sh") if _, err := os.Stat(dir); os.IsNotExist(err) { fmt.Printf("no such file or directory: %s", dir) if errm := os.MkdirAll(dir, 0777); errm != nil { return errm } // open output file _, err := os.Create(filePath) if err != nil { return err } } str := "BINDED_HOST_NAME=" + rasm.Components[rc].Name + "\n" + "HOST=" + rasm.Name + "." + GetParsedValue(rasm.Inputs, "domain") + "\n" + "\nDBNAME=" + com.Name + "\n" + "PORT=" + GetParsedValue(rasm.Components[rc].Inputs, "port") + "\nUSERNAME="******"username") + "\nPASSWORD="******"password") + "\nDBUSER="******"username") + "\nDBPASSWORD="******"dbpassword") + "\n" errf := ioutil.WriteFile(filePath, []byte(str), 0644) if errf != nil { return errf } //return nil } } } } } } } } } return nil }
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 */ } }