code that verifies the Docker daemon connection before adding

This commit is contained in:
Brad Rydzewski 2015-10-19 17:46:58 -07:00
parent ffd42a1a0e
commit 0e3b11c44d
3 changed files with 26 additions and 12 deletions

View file

@ -58,19 +58,19 @@ func PostNode(c *gin.Context) {
node.CA = in.CA node.CA = in.CA
node.Arch = "linux_amd64" node.Arch = "linux_amd64"
err = engine.Allocate(node)
if err != nil {
c.String(http.StatusBadRequest, err.Error())
return
}
err = model.InsertNode(db, node) err = model.InsertNode(db, node)
if err != nil { if err != nil {
c.AbortWithStatus(http.StatusInternalServerError) c.AbortWithStatus(http.StatusInternalServerError)
return return
} }
ok := engine.Allocate(node) c.IndentedJSON(http.StatusOK, node)
if !ok {
c.AbortWithStatus(http.StatusInternalServerError)
} else {
c.IndentedJSON(http.StatusOK, node)
}
} }
func DeleteNode(c *gin.Context) { func DeleteNode(c *gin.Context) {

View file

@ -26,7 +26,7 @@ type Engine interface {
Cancel(int64, int64, *model.Node) error Cancel(int64, int64, *model.Node) error
Stream(int64, int64, *model.Node) (io.ReadCloser, error) Stream(int64, int64, *model.Node) (io.ReadCloser, error)
Deallocate(*model.Node) Deallocate(*model.Node)
Allocate(*model.Node) bool Allocate(*model.Node) error
Subscribe(chan *Event) Subscribe(chan *Event)
Unsubscribe(chan *Event) Unsubscribe(chan *Event)
} }
@ -124,9 +124,23 @@ func (e *engine) Unsubscribe(c chan *Event) {
e.bus.unsubscribe(c) e.bus.unsubscribe(c)
} }
func (e *engine) Allocate(node *model.Node) bool { func (e *engine) Allocate(node *model.Node) error {
log.Infof("registered docker daemon %s", node.Addr)
return e.pool.allocate(node) // run the full build!
client, err := newDockerClient(node.Addr, node.Cert, node.Key, node.CA)
if err != nil {
log.Errorf("error creating docker client %s. %s.", node.Addr, err)
return err
}
version, err := client.Version()
if err != nil {
log.Errorf("error connecting to docker daemon %s. %s.", node.Addr, err)
return err
}
log.Infof("registered docker daemon %s running version %s", node.Addr, version.Version)
e.pool.allocate(node)
return nil
} }
func (e *engine) Deallocate(n *model.Node) { func (e *engine) Deallocate(n *model.Node) {

View file

@ -423,7 +423,7 @@ body.login div.alert { position: fixed; top: 0px; left: 0px; right: 0px; line-he
.tt-open { position: absolute; top: 34px; left: 0px; z-index: 100; display: none; background: #FFF; min-width: 100%; border: 1px solid #eee; border-radius: 0px; } .tt-open { position: absolute; top: 34px; left: 0px; z-index: 100; display: none; background: #FFF; min-width: 100%; border: 1px solid #eee; border-radius: 0px; }
.tt-selectable:hover, .tt-cursor { background: #f4f4f4; } .tt-selectable:hover, .tt-cursor { background: #eff1f5; }
.tt-selectable { padding: 1rem 0.75rem; cursor: pointer; display: flex; } .tt-selectable { padding: 1rem 0.75rem; cursor: pointer; display: flex; }