Пример #1
0
func DeleteRoute(route core.Route) error {
	// in case of failure
	oldRoutes, err := database.GetRoutes()
	if err != nil {
		return err
	}

	// apply to proxymgr
	err = proxymgr.DeleteRoute(route)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// save to backend
		err = database.DeleteRoute(route)
		if err != nil {
			// undo proxymgr action
			if uerr := proxymgr.SetRoutes(oldRoutes); uerr != nil {
				err = fmt.Errorf("%v - %v", err.Error(), uerr.Error())
			}
			return err
		}
	}
	return nil
}
Пример #2
0
func (n None) DeleteRoute(route core.Route) error {
	err := common.DeleteRoute(route)
	if err != nil {
		return err
	}
	if database.CentralStore {
		return database.DeleteRoute(route)
	}
	return nil
}
Пример #3
0
func TestDeleteRoute(t *testing.T) {
	if err := database.DeleteRoute(testRoute); err != nil {
		t.Errorf("Failed to DELETE route - %v", err)
	}

	routes, err := database.GetRoutes()
	if err != nil {
		t.Error(err)
	}

	if len(routes) != 0 {
		t.Errorf("Failed to delete route")
	}
}
Пример #4
0
// DeleteRoute tells all members to remove the route from their database.
// rolls back on failure
func (r Redis) DeleteRoute(route core.Route) error {
	conn := pool.Get()
	defer conn.Close()

	oldRoutes, err := common.GetRoutes()
	// this should not return nil to ensure the route is gone from entire cluster
	if err != nil && !strings.Contains(err.Error(), "No Route Found") {
		return err
	}

	// publishJson to others
	err = r.publishJson(conn, "delete-route", route)
	if err != nil {
		// if i failed to publishJson, request should fail
		return err
	}

	actionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("delete-route %s", route))))

	// ensure all members applied action
	err = r.waitForMembers(conn, actionHash)
	if err != nil {
		uActionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("set-routes", oldRoutes))))
		// cleanup rollback cruft. clear actionHash ensures no mistakes on re-submit
		defer conn.Do("DEL", uActionHash, actionHash)
		// attempt rollback - no need to waitForMembers here
		uerr := r.publishJson(conn, "set-routes", oldRoutes)
		if uerr != nil {
			err = fmt.Errorf("%v - %v", err, uerr)
		}
		return err
	}

	if database.CentralStore {
		return database.DeleteRoute(route)
	}

	return nil
}