func DeleteServer(svcId, srvId string) error { // in case of failure srv, err := database.GetServer(svcId, srvId) if err != nil { if !strings.Contains(err.Error(), "No Server Found") { return err } } // delete rule from balancer if err = balance.DeleteServer(svcId, srvId); err != nil { if !strings.Contains(err.Error(), "No Server Found") { return err } } if !database.CentralStore { // remove from backend if err = database.DeleteServer(svcId, srvId); err != nil && !strings.Contains(err.Error(), "No Server Found") { // undo balance action if uerr := balance.SetServer(svcId, srv); uerr != nil { err = fmt.Errorf("%v - %v", err.Error(), uerr.Error()) } return err } } return nil }
func (n None) DeleteServer(svcId, srvId string) error { err := common.DeleteServer(svcId, srvId) if err != nil { return err } if database.CentralStore { return database.DeleteServer(svcId, srvId) } return nil }
func TestDeleteServer(t *testing.T) { err := database.DeleteServer(testService1.Id, testServer2.Id) if err != nil { t.Errorf("Failed to DELETE server - %v", err) } service, err := ioutil.ReadFile("/tmp/scribbleTest/services/tcp-192_168_0_15-80.json") if err != nil { t.Error(err) } jService, err := toJson(testService1) if err != nil { t.Error(err) } if string(service) != string(jService) { t.Errorf("Read service differs from written service") } }
// DeleteServer tells all members to remove the server from their database. // rolls back on failure func (r *Redis) DeleteServer(svcId, srvId string) error { conn := pool.Get() defer conn.Close() oldServer, err := common.GetServer(svcId, srvId) // mustn't return nil here to ensure cluster removes the server if err != nil && !strings.Contains(err.Error(), "No Server Found") { return err } // publishStringJson to others // todo: swap srv/svc ids to match backender interface for better readability err = r.publishString(conn, "delete-server", srvId, svcId) if err != nil { return err } actionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("delete-server %s %s", srvId, svcId)))) // ensure all members applied action err = r.waitForMembers(conn, actionHash) if err != nil { uActionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("set-server %s %s", *oldServer, svcId)))) // 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.publishStringJson(conn, "set-server", svcId, oldServer) if uerr != nil { err = fmt.Errorf("%v - %v", err, uerr) } return err } if database.CentralStore { return database.DeleteServer(svcId, srvId) } return nil }