Exemplo n.º 1
0
// Locks all remote.
func (this *Manager) PartitionLockRemote(partition int) error {
	clients, err := this.Clients(partition)
	if err != nil {
		return err
	}
	for _, c := range clients {
		req := cheshire.NewRequest("/chs/lock", "POST")
		req.Params().Put("partitions", partition)

		res, err := c.ApiCallSync(req, time.Second*10)

		if err != nil {
			//retry once
			res, err = c.ApiCallSync(req, time.Second*10)
			if err != nil {
				log.Printf("Error locking remote: %s", err)
			} else if res.StatusCode() != 200 {
				log.Printf("Error lock %s", res)
			}
		} else if res.StatusCode() != 200 {
			log.Printf("Error lock %s", res)
		}
	}
	//TODO: fail if all locks fail
	return nil
}
Exemplo n.º 2
0
// Does a checkin with the requested client.  returns the
// router table revision of the connection.
func (this *Manager) Checkin(client cheshire.Client) (int64, error) {
	response, err := client.ApiCallSync(cheshire.NewRequest("/chs/checkin", "GET"), 10*time.Second)
	if err != nil {
		return int64(0), err
	}
	revision := response.MustInt64("router_table_revision", int64(0))
	return revision, nil
}
Exemplo n.º 3
0
//Request a new router table for the given client
//Does not call SetRouterTable
func (this *Manager) RequestRouterTable(client cheshire.Client) (*RouterTable, error) {
	response, err := client.ApiCallSync(cheshire.NewRequest("/chs/rt/get", "GET"), 10*time.Second)
	if err != nil {
		return nil, err
	}
	if response.StatusCode() != 200 {
		return nil, fmt.Errorf("Error from server %d %s", response.StatusCode(), response.StatusMessage())
	}

	mp, ok := response.GetDynMap("router_table")
	if !ok {
		return nil, fmt.Errorf("No router_table in response : %s", response)
	}

	table, err := ToRouterTable(mp)
	if err != nil {
		return nil, err
	}
	return table, nil
}