Beispiel #1
0
func seedRouterGroups(cfg config.Config, logger lager.Logger, database db.DB) {
	// seed router groups from config
	if len(cfg.RouterGroups) > 0 {
		routerGroups, _ := database.ReadRouterGroups()
		// if config not empty and db is empty, seed
		if len(routerGroups) == 0 {
			for _, rg := range cfg.RouterGroups {
				guid, err := uuid.NewV4()
				if err != nil {
					logger.Error("failed to generate a guid for router group", err)
					os.Exit(1)
				}
				rg.Guid = guid.String()
				logger.Info("seeding", lager.Data{"router-group": rg})
				err = database.SaveRouterGroup(rg)
				if err != nil {
					logger.Error("failed to save router group from config", err)
					os.Exit(1)
				}
			}
		}
	}
}
Beispiel #2
0
						g, err := uuid.NewV4()
						Expect(err).NotTo(HaveOccurred())
						guid = g.String()

						routerGroup = models.RouterGroup{
							Name:            "router-group-1",
							Type:            "tcp",
							Guid:            guid,
							ReservablePorts: "10-20,25",
						}
						err = etcd.SaveRouterGroup(routerGroup)
						Expect(err).NotTo(HaveOccurred())
					})

					It("can list the router groups", func() {
						rg, err := etcd.ReadRouterGroups()
						Expect(err).NotTo(HaveOccurred())
						Expect(len(rg)).To(Equal(1))
						Expect(rg[0]).Should(Equal(routerGroup))
					})

					It("updates the router group", func() {
						routerGroup.Type = "http"
						routerGroup.ReservablePorts = "10-20,25,30"

						err := etcd.SaveRouterGroup(routerGroup)
						Expect(err).NotTo(HaveOccurred())

						node, err := etcdClient.Get(db.ROUTER_GROUP_BASE_KEY + "/" + guid)
						Expect(err).NotTo(HaveOccurred())
						Expect(node.TTL).To(Equal(uint64(0)))