// TODO: implement rollback in case of suboperation failure
func (f *frontend) update(ef engine.Frontend, b *backend) error {
	oldf := f.frontend
	f.frontend = ef

	if err := f.updateBackend(b); err != nil {
		return err
	}

	if oldf.Route != ef.Route {
		log.Infof("%v updating route from %v to %v", oldf.Route, ef.Route)
		if err := f.mux.router.Handle(ef.Route, f.handler); err != nil {
			return err
		}
		if err := f.mux.router.Remove(oldf.Route); err != nil {
			return err
		}
	}

	olds := oldf.HTTPSettings()
	news := ef.HTTPSettings()
	if !olds.Equals(news) {
		if err := f.rebuild(); err != nil {
			return err
		}
	}

	return nil
}
Exemple #2
0
func (s *EngineSuite) FrontendCRUD(c *C) {
	b := engine.Backend{Id: "b0", Type: engine.HTTP, Settings: engine.HTTPBackendSettings{}}
	c.Assert(s.Engine.UpsertBackend(b), IsNil)
	s.collectChanges(c, 1)

	f := engine.Frontend{
		Id:        "f1",
		BackendId: b.Id,
		Route:     `Path("/hello")`,
		Type:      engine.HTTP,
		Settings:  engine.HTTPFrontendSettings{},
	}

	c.Assert(s.Engine.UpsertFrontend(f, 0), IsNil)

	fk := engine.FrontendKey{Id: f.Id}
	out, err := s.Engine.GetFrontend(fk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, &f)

	s.expectChanges(c, &engine.FrontendUpserted{
		Frontend: f,
	})

	// Make some updates
	b1 := engine.Backend{Id: "b1", Type: engine.HTTP, Settings: engine.HTTPBackendSettings{}}
	c.Assert(s.Engine.UpsertBackend(b1), IsNil)
	s.collectChanges(c, 1)

	f.BackendId = "b1"
	f.Settings = engine.HTTPFrontendSettings{
		Hostname: "host1",
	}
	c.Assert(s.Engine.UpsertFrontend(f, 0), IsNil)

	out, err = s.Engine.GetFrontend(fk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, &f)

	s.expectChanges(c, &engine.FrontendUpserted{
		Frontend: f,
	})

	// Delete
	c.Assert(s.Engine.DeleteFrontend(fk), IsNil)
	s.expectChanges(c, &engine.FrontendDeleted{
		FrontendKey: fk,
	})
}