Пример #1
0
func DeleteService(svcId string) error {
	// in case of failure
	oldService, err := database.GetService(svcId)
	if err != nil {
		if !strings.Contains(err.Error(), "No Service Found") {
			return err
		}
	}

	// delete backend rule
	err = balance.DeleteService(svcId)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// remove from backend
		err = database.DeleteService(svcId)
		if err != nil {
			// undo balance action
			if oldService != nil {
				if uerr := balance.SetService(oldService); uerr != nil {
					err = fmt.Errorf("%v - %v", err.Error(), uerr.Error())
				}
			}
			return err
		}
	}
	return nil
}
Пример #2
0
func SetServers(svcId string, servers []core.Server) error {
	// in case of failure
	oldService, err := database.GetService(svcId)
	if err != nil {
		return err
	}
	oldServers := oldService.Servers

	// implement in balancer
	err = balance.SetServers(svcId, servers)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// add to backend
		err = database.SetServers(svcId, servers)
		if err != nil {
			// undo balance action
			if uerr := balance.SetServers(svcId, oldServers); uerr != nil {
				err = fmt.Errorf("%v - %v", err.Error(), uerr.Error())
			}
			return err
		}
	}
	return nil
}
Пример #3
0
func TestGetServers(t *testing.T) {
	service, err := database.GetService(testService1.Id)
	if err != nil {
		t.Errorf("Failed to GET service - %v", err)
	}

	if service.Servers[0].Id != testServer2.Id {
		t.Errorf("Read server differs from written server")
	}
}
Пример #4
0
func GetService(id string) (*core.Service, error) {
	return database.GetService(id)
}