Exemple #1
0
func (j AddAliasRequest) Execute(resp jobs.Response) {
	value, ok := router.GlobalRoutes[j.Frontend]
	if ok {
		router.AddAlias(j.Alias, value.Name)
	} else {
		router.CreateFrontend(j.Frontend, j.Alias)
	}
	resp.Success(jobs.ResponseOk)
}
Exemple #2
0
func (j CreateFrontendRequest) Execute(resp jobs.Response) {
	value, ok := router.GlobalRoutes[j.Frontend]
	if !ok {
		router.CreateFrontend(j.Frontend, j.Alias)
	} else {
		log.Printf("Error : Frontend %s already exists.", value.Name)
	}
	resp.Success(jobs.ResponseOk)
}
Exemple #3
0
func (e *Command) test(cmd *cobra.Command, args []string) {
	fmt.Println("Router testing.")
	frontendname := "geard-router-test"
	alias := "www.alias.com"
	router.CreateFrontend(frontendname, alias)

	// empty the global datastucture and re-read to confirm that correct output has been generated
	router.GlobalRoutes = nil
	router.ReadRoutes()
	frontend, ok := router.GlobalRoutes[frontendname]
	if !ok {
		fmt.Println("Test failed. Frontend created was not persisted.")
		return
	}
	if frontend.HostAliases[0] != alias {
		fmt.Println("Test failed. Frontend created did not persist its alias.")
		return
	}

	// create a route
	s := router.Endpoint{}
	s.IP = "localhost"
	s.Port = "4001"
	endpoints := make([]router.Endpoint, 1)
	endpoints[0] = s
	router.AddRoute(frontendname, "", "", nil, endpoints)

	// empty the db again and check for routes
	router.GlobalRoutes = nil
	router.ReadRoutes()
	frontend, ok = router.GlobalRoutes[frontendname]
	if !ok {
		fmt.Println("Test failed. Frontend created was not persisted.")
		return
	}
	if len(frontend.EndpointTable) != 1 {
		fmt.Println("Test failed. Created one route, but %d found.", len(frontend.EndpointTable))
		return
	}
	for _, ep := range frontend.EndpointTable {
		if ep.IP != "localhost" || ep.Port != "4001" {
			fmt.Println("Test failed. Created one route, but invalid values were persisted.", len(frontend.EndpointTable))
			return
		}
	}

	// good so far, now delete the testfrontend
	router.DeleteFrontend(frontendname)
	_, ok = router.GlobalRoutes[frontendname]
	if ok {
		fmt.Println("Test failed. Frontend deletion does not actually remove the frontend from the routing table.")
	}

	// all good
	fmt.Println(router.PrintRoutes())
}