github.com/weaviate/weaviate@v1.24.6/adapters/handlers/rest/clusterapi/serve.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package clusterapi 13 14 import ( 15 "encoding/json" 16 "fmt" 17 "net/http" 18 19 "github.com/weaviate/weaviate/adapters/handlers/rest/state" 20 ) 21 22 func Serve(appState *state.State) { 23 port := appState.ServerConfig.Config.Cluster.DataBindPort 24 auth := NewBasicAuthHandler(appState.ServerConfig.Config.Cluster.AuthConfig) 25 26 appState.Logger.WithField("port", port). 27 WithField("action", "cluster_api_startup"). 28 Debugf("serving cluster api on port %d", port) 29 30 schema := NewSchema(appState.SchemaManager.TxManager(), auth) 31 indices := NewIndices(appState.RemoteIndexIncoming, appState.DB, auth) 32 replicatedIndices := NewReplicatedIndices(appState.RemoteReplicaIncoming, appState.Scaler, auth) 33 classifications := NewClassifications(appState.ClassificationRepo.TxManager(), auth) 34 nodes := NewNodes(appState.RemoteNodeIncoming, auth) 35 backups := NewBackups(appState.BackupManager, auth) 36 37 mux := http.NewServeMux() 38 mux.Handle("/schema/transactions/", 39 http.StripPrefix("/schema/transactions/", schema.Transactions())) 40 mux.Handle("/classifications/transactions/", 41 http.StripPrefix("/classifications/transactions/", 42 classifications.Transactions())) 43 44 mux.Handle("/nodes/", nodes.Nodes()) 45 mux.Handle("/indices/", indices.Indices()) 46 mux.Handle("/replicas/indices/", replicatedIndices.Indices()) 47 48 mux.Handle("/backups/can-commit", backups.CanCommit()) 49 mux.Handle("/backups/commit", backups.Commit()) 50 mux.Handle("/backups/abort", backups.Abort()) 51 mux.Handle("/backups/status", backups.Status()) 52 53 mux.Handle("/", index()) 54 http.ListenAndServe(fmt.Sprintf(":%d", port), mux) 55 } 56 57 func index() http.Handler { 58 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 59 if r.URL.String() != "" && r.URL.String() != "/" { 60 http.NotFound(w, r) 61 return 62 } 63 64 payload := map[string]string{ 65 "description": "Weaviate's cluster-internal API for cross-node communication", 66 } 67 68 json.NewEncoder(w).Encode(payload) 69 }) 70 }