func (z *zkCluster) GetQueryNodes() ([]clustering.QueryNode, errors.Error) { impl, ok := getConfigStoreImplementation(z) if !ok { return nil, errors.NewAdminConnectionError(nil, z.ConfigurationStoreId()) } qryNodes := []clustering.QueryNode{} nodes, _, err := impl.conn.Children("/" + z.Name()) if err != nil { return nil, errors.NewAdminGetClusterError(err, z.Name()) } for _, name := range nodes { nodePath := "/" + z.Name() + "/" + name data, _, err := impl.conn.Get(nodePath) if err != nil { return nil, errors.NewAdminGetNodeError(err, nodePath) } queryNode := &zkQueryNodeConfig{} err = json.Unmarshal(data, queryNode) if err != nil { return nil, errors.NewAdminDecodingError(err) } qryNodes = append(qryNodes, queryNode) } return qryNodes, nil }
func getNodeFromRequest(req *http.Request) (clustering.QueryNode, errors.Error) { var node clustering.QueryNode decoder := json.NewDecoder(req.Body) err := decoder.Decode(&node) if err != nil { return nil, errors.NewAdminDecodingError(err) } return node, nil }
func getClusterFromRequest(req *http.Request) (clustering.Cluster, errors.Error) { var cluster clustering.Cluster decoder := json.NewDecoder(req.Body) err := decoder.Decode(&cluster) if err != nil { return nil, errors.NewAdminDecodingError(err) } return cluster, nil }
func (z *zkConfigStore) ClusterByName(name string) (clustering.Cluster, errors.Error) { data, _, err := z.conn.Get("/" + name) if err != nil { return nil, errors.NewAdminGetClusterError(err, name) } var clusterConfig zkCluster err = json.Unmarshal(data, &clusterConfig) if err != nil { return nil, errors.NewAdminDecodingError(err) } clusterConfig.configStore = z return &clusterConfig, nil }
func (z *zkCluster) QueryNodeByName(name string) (clustering.QueryNode, errors.Error) { impl, ok := getConfigStoreImplementation(z) if !ok { return nil, errors.NewAdminConnectionError(nil, z.ConfigurationStoreId()) } nodePath := "/" + z.ClusterName + "/" + name data, _, err := impl.conn.Get(nodePath) if err != nil { return nil, errors.NewAdminGetNodeError(err, nodePath) } var queryNode zkQueryNodeConfig err = json.Unmarshal(data, &queryNode) if err != nil { return nil, errors.NewAdminDecodingError(err) } return &queryNode, nil }
func wrapAPI(s *server.Server, w http.ResponseWriter, req *http.Request, f apiFunc) { obj, err := f(s, w, req) if err != nil { writeError(w, err) return } if obj == nil { w.WriteHeader(http.StatusNotFound) return } buf, json_err := json.Marshal(obj) if json_err != nil { writeError(w, errors.NewAdminDecodingError(json_err)) return } w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") w.Write(buf) }
func (z *zkConfigStore) GetClusters() ([]clustering.Cluster, errors.Error) { clusters := []clustering.Cluster{} nodes, _, err := z.conn.Children("/") if err != nil { return nil, errors.NewAdminGetClusterError(err, "/") } for _, name := range nodes { if name == _RESERVED_NAME { continue } data, _, err := z.conn.Get("/" + name) if err != nil { return nil, errors.NewAdminGetClusterError(err, name) } cluster := &zkCluster{} err = json.Unmarshal(data, cluster) if err != nil { return nil, errors.NewAdminDecodingError(err) } clusters = append(clusters, cluster) } return clusters, nil }