func (m *Manager) AddEngine(engine *shipyard.Engine) error { stat, err := engine.Ping() if err != nil { return err } if stat != 200 { err := fmt.Errorf("Received status code '%d' when contacting %s", stat, engine.Engine.Addr) return err } if _, err := r.Table(tblNameConfig).Insert(engine).RunWrite(m.session); err != nil { return err } m.init() evt := &shipyard.Event{ Type: "add-engine", Message: fmt.Sprintf("addr=%s", engine.Engine.Addr), Time: time.Now(), Engine: engine.Engine, Tags: []string{"cluster"}, } if err := m.SaveEvent(evt); err != nil { return err } return nil }
func addEngine(w http.ResponseWriter, r *http.Request) { var engine *shipyard.Engine if err := json.NewDecoder(r.Body).Decode(&engine); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } health := &shipyard.Health{ Status: "pending", ResponseTime: 0, } engine.Health = health if err := controllerManager.AddEngine(engine); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } logger.Infof("added engine id=%s addr=%s cpus=%f memory=%f", engine.Engine.ID, engine.Engine.Addr, engine.Engine.Cpus, engine.Engine.Memory) w.WriteHeader(http.StatusCreated) }