-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e135bf5
commit 1f8ee08
Showing
84 changed files
with
9,815 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package lind | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
_ "net/http/pprof" // for profiling | ||
"os" | ||
|
||
"github.com/eleme/lindb/broker/rest" | ||
"github.com/eleme/lindb/config" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
brokerCfgPath = "" | ||
brokerDebug = false | ||
) | ||
|
||
const ( | ||
brokerCfgName = "broker.toml" | ||
defaultBrokerCfgFile = cfgFilePath + "/" + brokerCfgName | ||
) | ||
|
||
// newBrokerCmd returns a new broker-cmd | ||
func newBrokerCmd() *cobra.Command { | ||
brokerCmd := &cobra.Command{ | ||
Use: "broker", | ||
Aliases: []string{"bro"}, | ||
Short: "The compute layer of LinDB", | ||
} | ||
runBrokerCmd.PersistentFlags().StringVar(&brokerCfgPath, "config", "", | ||
fmt.Sprintf("broker config file path, default is %s", defaultBrokerCfgFile)) | ||
runBrokerCmd.PersistentFlags().BoolVar(&brokerDebug, "debug", false, | ||
"profiling Go programs with pprof") | ||
brokerCmd.AddCommand( | ||
runBrokerCmd, | ||
initializeBrokerConfigCmd, | ||
) | ||
return brokerCmd | ||
} | ||
|
||
var runBrokerCmd = &cobra.Command{ | ||
Use: "run", | ||
Short: "starts the broker", | ||
RunE: serveBroker, | ||
} | ||
|
||
// initialize config for broker | ||
var initializeBrokerConfigCmd = &cobra.Command{ | ||
Use: "initialize-config", | ||
Short: "initialize a new broker-config by steps", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// todo: @codingcrush | ||
}, | ||
} | ||
|
||
// serveBroker runs the broker | ||
func serveBroker(cmd *cobra.Command, args []string) error { | ||
ctx := newCtxWithSignals() | ||
go func() { | ||
<-ctx.Done() | ||
os.Exit(0) | ||
}() | ||
|
||
if brokerCfgPath == "" { | ||
brokerCfgPath = defaultBrokerCfgFile | ||
} | ||
if _, err := os.Stat(brokerCfgPath); err != nil { | ||
return fmt.Errorf("config file doesn't exist, see how to initialize the config by `lind broker -h`") | ||
} | ||
fmt.Printf("load config file: %v successfully\n", brokerCfgPath) | ||
|
||
brokerConfig := config.BrokerConfig{} | ||
if _, err := toml.DecodeFile(brokerCfgPath, &brokerConfig); err != nil { | ||
return err | ||
} | ||
fmt.Printf("HTTP server listening on: %d\n", brokerConfig.HTTP.Port) | ||
|
||
router := rest.NewRouter(&brokerConfig) | ||
if err := http.ListenAndServe(fmt.Sprintf(":%d", brokerConfig.HTTP.Port), router); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package lind | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// These variables are populated via the Go linker. | ||
var ( | ||
// release version, ldflags | ||
version string | ||
// binary build-time, ldflags | ||
buildTime string | ||
) | ||
|
||
const ( | ||
defaultVersion = "alpha" | ||
) | ||
|
||
func printVersion() { | ||
var releaseVersion = defaultVersion | ||
if version != "" { | ||
releaseVersion = version | ||
} | ||
fmt.Printf("LinDB %v, BuildDate: %v\n", releaseVersion, buildTime) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version of LinDB", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
printVersion() | ||
}, | ||
} | ||
|
||
var envCmd = &cobra.Command{ | ||
Use: "env", | ||
Short: "Print environment info of LinDB", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
printVersion() | ||
fmt.Printf("GOOS=%q\n", runtime.GOOS) | ||
fmt.Printf("GOARCH=%q\n", runtime.GOARCH) | ||
fmt.Printf("GOVERSION=%q\n", runtime.Version()) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package lind | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
// default config file location of LinDB | ||
cfgFilePath = "/etc/lindb" | ||
|
||
linDBText = ` | ||
__ _ ____ ____ | ||
/ / (_) ____ / __ \ / __ ) | ||
/ / / / / __ \ / / / / / __ | | ||
/ /___ / / / / / / / /_/ / / /_/ / | ||
/_____//_/ /_/ /_/ /_____/ /_____/ | ||
LinDB is a scalable, distributed, high performance, high availability Time Series Database, produced by Eleme-CI. | ||
Complete documentation is available at https://github.com/eleme/lindb | ||
` | ||
) | ||
|
||
// RootCmd command of cobra | ||
var RootCmd = &cobra.Command{ | ||
Use: "lind", | ||
Short: "lind is the main command, used to control LinDB", | ||
Long: linDBText, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand( | ||
envCmd, | ||
versionCmd, | ||
newStorageCmd(), | ||
newBrokerCmd(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package lind | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
// newCtxWithSignals returns a context which will can be canceled by sending signal. | ||
func newCtxWithSignals() context.Context { | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt, syscall.SIGTERM) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
go func() { | ||
defer cancel() | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-c: | ||
return | ||
} | ||
}() | ||
return ctx | ||
} |
Oops, something went wrong.