Exemple #1
0
func (c *Client) GetBackend(bk engine.BackendKey) (*engine.Backend, error) {
	response, err := c.Get(c.endpoint("backends", bk.Id), url.Values{})
	if err != nil {
		return nil, err
	}
	return engine.BackendFromJSON(response)
}
Exemple #2
0
func (n *ng) parseBackends(node *etcd.Node, skipServers ...bool) ([]engine.BackendSpec, error) {
	backendSpecs := make([]engine.BackendSpec, len(node.Nodes))
	for idx, node := range node.Nodes {
		backendId := suffix(node.Key)
		for _, node := range node.Nodes {
			switch suffix(node.Key) {
			case "backend":
				backend, err := engine.BackendFromJSON([]byte(node.Value), backendId)
				if err != nil {
					return nil, err
				}
				backendSpecs[idx].Backend = *backend
			case "servers":
				if len(skipServers) == 1 && skipServers[0] {
					break
				}
				servers := make([]engine.Server, len(node.Nodes))
				for idx, node := range node.Nodes {
					serverId := suffix(node.Key)
					server, err := engine.ServerFromJSON([]byte(node.Value), serverId)
					if err != nil {
						return nil, err
					}
					servers[idx] = *server
				}
				backendSpecs[idx].Servers = servers
			}
		}
		if backendSpecs[idx].Backend.Id != backendId {
			return nil, fmt.Errorf("Backend %s parameters missing", backendId)
		}
	}
	return backendSpecs, nil
}
Exemple #3
0
func (n *ng) GetBackend(key engine.BackendKey) (*engine.Backend, error) {
	backendKey := n.path("backends", key.Id, "backend")

	bytes, err := n.getVal(backendKey)
	if err != nil {
		return nil, err
	}
	return engine.BackendFromJSON([]byte(bytes), key.Id)
}
Exemple #4
0
func parseBackendPack(v []byte) (*engine.Backend, error) {
	var bp *backendReadPack
	if err := json.Unmarshal(v, &bp); err != nil {
		return nil, err
	}
	if bp == nil || len(bp.Backend) == 0 {
		return nil, &scroll.MissingFieldError{Field: "Backend"}
	}
	return engine.BackendFromJSON(bp.Backend)
}
Exemple #5
0
func (n *ng) parseBackends(keyValues []*mvccpb.KeyValue, skipServers ...bool) ([]engine.BackendSpec, error) {
	backendSpecs := []engine.BackendSpec{}

	for _, keyValue := range keyValues {
		if backendIds := backendIdRegex.FindStringSubmatch(string(keyValue.Key)); len(backendIds) == 2 {
			backendId := backendIds[1]
			backend, err := engine.BackendFromJSON([]byte(keyValue.Value), backendId)
			if err != nil {
				return nil, err
			}

			backendSpec := engine.BackendSpec{
				Backend: *backend,
			}

			if len(skipServers) != 1 || !skipServers[0] {
				//get all keys under this frontend
				subKeyValues := filterByPrefix(keyValues, string(keyValue.Key)) //Get all keys below this frontend "/vulcand/frontends/foo/*"
				servers := []engine.Server{}

				for _, subKeyValue := range subKeyValues {
					if serverId := suffix(string(subKeyValue.Key)); suffix(prefix(string(subKeyValue.Key))) == "servers" {
						server, err := engine.ServerFromJSON([]byte(subKeyValue.Value), serverId)
						if err != nil {
							return nil, err
						}
						servers = append(servers, *server)
					}
				}

				backendSpec.Servers = servers
			}

			backendSpecs = append(backendSpecs, backendSpec)

		}
	}
	return backendSpecs, nil
}