Remove captplanet (#1070)

This commit is contained in:
Egon Elbre 2019-01-17 04:35:22 -05:00 committed by GitHub
parent f9abb4584c
commit c89609abbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 3 additions and 562 deletions

View File

@ -79,11 +79,6 @@ test: ## Run tests on source code (travis)
go test -race -v -cover -coverprofile=.coverprofile ./...
@echo done
.PHONY: test-captplanet
test-captplanet: ## Test source with captain planet (travis)
@echo "Running ${@}"
@./scripts/test-captplanet.sh
.PHONY: test-sim
test-sim: ## Test source with storj-sim (travis)
@echo "Running ${@}"

View File

@ -1,140 +0,0 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"
"time"
"github.com/spf13/cobra"
monkit "gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/storj/internal/fpath"
"storj.io/storj/internal/memory"
"storj.io/storj/pkg/accounting/rollup"
"storj.io/storj/pkg/accounting/tally"
"storj.io/storj/pkg/audit"
"storj.io/storj/pkg/bwagreement"
"storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/datarepair/checker"
"storj.io/storj/pkg/datarepair/repairer"
"storj.io/storj/pkg/discovery"
"storj.io/storj/pkg/kademlia"
"storj.io/storj/pkg/miniogw"
"storj.io/storj/pkg/overlay"
"storj.io/storj/pkg/piecestore/psserver"
"storj.io/storj/pkg/pointerdb"
"storj.io/storj/pkg/process"
"storj.io/storj/pkg/provider"
"storj.io/storj/pkg/server"
"storj.io/storj/pkg/statdb"
"storj.io/storj/satellite/console/consoleweb"
)
// Captplanet defines Captain Planet configuration
type Captplanet struct {
SatelliteCA provider.CASetupConfig `setup:"true"`
SatelliteIdentity provider.IdentitySetupConfig `setup:"true"`
UplinkCA provider.CASetupConfig `setup:"true"`
UplinkIdentity provider.IdentitySetupConfig `setup:"true"`
StorageNodeCA provider.CASetupConfig `setup:"true"`
StorageNodeIdentity provider.IdentitySetupConfig `setup:"true"`
ListenHost string `help:"the host for providers to listen on" default:"127.0.0.1" setup:"true"`
StartingPort int `help:"all providers will listen on ports consecutively starting with this one" default:"7777" setup:"true"`
APIKey string `default:"abc123" help:"the api key to use for the satellite" setup:"true"`
EncKey string `default:"insecure-default-encryption-key" help:"your root encryption key" setup:"true"`
Overwrite bool `help:"whether to overwrite pre-existing configuration files" default:"false" setup:"true"`
GenerateMinioCerts bool `default:"false" help:"generate sample TLS certs for Minio GW" setup:"true"`
Satellite Satellite
StorageNodes [storagenodeCount]StorageNode
Uplink miniogw.Config
}
// Satellite configuration
type Satellite struct {
Server server.Config
Kademlia kademlia.SatelliteConfig
PointerDB pointerdb.Config
Overlay overlay.Config
Checker checker.Config
Repairer repairer.Config
Audit audit.Config
BwAgreement bwagreement.Config
Web consoleweb.Config
Discovery discovery.Config
Tally tally.Config
Rollup rollup.Config
StatDB statdb.Config
Database string `help:"satellite database connection string" default:"sqlite3://$CONFDIR/master.db"`
}
// StorageNode configuration
type StorageNode struct {
Server server.Config
Kademlia kademlia.StorageNodeConfig
Storage psserver.Config
}
var (
mon = monkit.Package()
rootCmd = &cobra.Command{
Use: "captplanet",
Short: "Captain Planet! With our powers combined!",
}
defaultConfDir = fpath.ApplicationDir("storj", "capt")
confDir *string
)
func main() {
go dumpHandler()
process.Exec(rootCmd)
}
func init() {
dirParam := cfgstruct.FindConfigDirParam()
if dirParam != "" {
defaultConfDir = dirParam
}
confDir = rootCmd.PersistentFlags().String("config-dir", defaultConfDir, "main directory for captplanet configuration")
}
// dumpHandler listens for Ctrl+\ on Unix
func dumpHandler() {
if runtime.GOOS == "windows" {
// unsupported on Windows
return
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGQUIT)
for range sigs {
dumpGoroutines()
}
}
func dumpGoroutines() {
buf := make([]byte, memory.MB)
n := runtime.Stack(buf, true)
p := time.Now().Format("dump-2006-01-02T15-04-05.999999999.log")
if abs, err := filepath.Abs(p); err == nil {
p = abs
}
fmt.Fprintf(os.Stderr, "Writing stack traces to \"%v\"\n", p)
err := ioutil.WriteFile(p, buf[:n], 0644)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
}

View File

@ -1,137 +0,0 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"fmt"
"time"
"github.com/alicebob/miniredis"
"github.com/spf13/cobra"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/storj/pkg/auth/grpcauth"
"storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/process"
"storj.io/storj/pkg/utils"
"storj.io/storj/satellite/satellitedb"
)
const (
storagenodeCount = 10
)
var (
runCmd = &cobra.Command{
Use: "run",
Short: "Run all servers",
RunE: cmdRun,
}
runCfg Captplanet
)
func init() {
rootCmd.AddCommand(runCmd)
cfgstruct.Bind(runCmd.Flags(), &runCfg, cfgstruct.ConfDir(defaultConfDir))
}
func cmdRun(cmd *cobra.Command, args []string) (err error) {
ctx := process.Ctx(cmd)
defer mon.Task()(&ctx)(&err)
if err := process.InitMetrics(ctx, nil, ""); err != nil {
zap.S().Errorf("Failed to initialize telemetry batcher: %+v", err)
}
errch := make(chan error, len(runCfg.StorageNodes)+2)
// start mini redis
m := miniredis.NewMiniRedis()
m.RequireAuth("abc123")
if err = m.StartAddr(":6378"); err != nil {
errch <- err
} else {
defer m.Close()
}
satellite := runCfg.Satellite
// start satellite
go func() {
_, _ = fmt.Printf("Starting satellite on %s\n", satellite.Server.Address)
if satellite.Audit.SatelliteAddr == "" {
satellite.Audit.SatelliteAddr = satellite.Server.Address
}
if satellite.Web.SatelliteAddr == "" {
satellite.Web.SatelliteAddr = satellite.Server.Address
}
database, err := satellitedb.New(satellite.Database)
if err != nil {
errch <- errs.New("Error starting master database on satellite: %+v", err)
return
}
err = database.CreateTables()
if err != nil {
errch <- errs.New("Error creating tables for master database on satellite: %+v", err)
return
}
//nolint ignoring context rules to not create cyclic dependency, will be removed later
satelliteCtx := context.WithValue(ctx, "masterdb", database)
// Run satellite
errch <- satellite.Server.Run(satelliteCtx,
grpcauth.NewAPIKeyInterceptor(),
satellite.Kademlia,
satellite.Overlay,
satellite.Discovery,
satellite.PointerDB,
satellite.Audit,
satellite.Checker,
satellite.Repairer,
satellite.BwAgreement,
satellite.Web,
satellite.Tally,
satellite.Rollup,
satellite.StatDB,
)
}()
// hack-fix t oensure that satellite gets up and running before starting storage nodes
time.Sleep(2 * time.Second)
// start the storagenodes
for i, v := range runCfg.StorageNodes {
go func(i int, v StorageNode) {
identity, err := v.Server.Identity.Load()
if err != nil {
return
}
address := v.Server.Address
storagenode := fmt.Sprintf("%s:%s", identity.ID.String(), address)
_, _ = fmt.Printf("Starting storage node %d %s (kad on %s)\n", i, storagenode, address)
errch <- v.Server.Run(ctx, nil, v.Kademlia, v.Storage)
}(i, v)
}
// start s3 uplink
uplink := runCfg.Uplink
go func() {
_, _ = fmt.Printf("Starting s3-gateway on %s\nAccess key: %s\nSecret key: %s\n",
uplink.Server.Address,
uplink.Minio.AccessKey,
uplink.Minio.SecretKey)
errch <- uplink.Run(ctx)
}()
return utils.CollectErrors(errch, 5*time.Second)
}

View File

@ -1,162 +0,0 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"fmt"
"net"
"os"
"path/filepath"
"github.com/spf13/cobra"
"storj.io/storj/internal/fpath"
"storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/process"
"storj.io/storj/pkg/provider"
)
var (
setupCmd = &cobra.Command{
Use: "setup",
Short: "Set up configurations",
RunE: cmdSetup,
Annotations: map[string]string{"type": "setup"},
}
setupCfg Captplanet
)
func init() {
rootCmd.AddCommand(setupCmd)
cfgstruct.BindSetup(setupCmd.Flags(), &setupCfg, cfgstruct.ConfDir(defaultConfDir))
}
func cmdSetup(cmd *cobra.Command, args []string) (err error) {
setupDir, err := filepath.Abs(*confDir)
if err != nil {
return err
}
valid, _ := fpath.IsValidSetupDir(setupDir)
if !valid {
return fmt.Errorf("captplanet configuration already exists (%v)", setupDir)
}
satellitePath := filepath.Join(setupDir, "satellite")
err = os.MkdirAll(satellitePath, 0700)
if err != nil {
return err
}
setupCfg.SatelliteCA.CertPath = filepath.Join(satellitePath, "ca.cert")
setupCfg.SatelliteCA.KeyPath = filepath.Join(satellitePath, "ca.key")
setupCfg.SatelliteIdentity.CertPath = filepath.Join(satellitePath, "identity.cert")
setupCfg.SatelliteIdentity.KeyPath = filepath.Join(satellitePath, "identity.key")
fmt.Printf("creating identity for satellite\n")
err = provider.SetupIdentity(process.Ctx(cmd), setupCfg.SatelliteCA, setupCfg.SatelliteIdentity)
if err != nil {
return err
}
for i := 0; i < len(runCfg.StorageNodes); i++ {
storagenodePath := filepath.Join(setupDir, fmt.Sprintf("f%d", i))
err = os.MkdirAll(storagenodePath, 0700)
if err != nil {
return err
}
storagenodeCA := setupCfg.StorageNodeCA
storagenodeCA.CertPath = filepath.Join(storagenodePath, "ca.cert")
storagenodeCA.KeyPath = filepath.Join(storagenodePath, "ca.key")
storagenodeIdentity := setupCfg.StorageNodeIdentity
storagenodeIdentity.CertPath = filepath.Join(storagenodePath, "identity.cert")
storagenodeIdentity.KeyPath = filepath.Join(storagenodePath, "identity.key")
fmt.Printf("creating identity for storage node %d\n", i+1)
err := provider.SetupIdentity(process.Ctx(cmd), storagenodeCA, storagenodeIdentity)
if err != nil {
return err
}
}
uplinkPath := filepath.Join(setupDir, "uplink")
err = os.MkdirAll(uplinkPath, 0700)
if err != nil {
return err
}
setupCfg.UplinkCA.CertPath = filepath.Join(uplinkPath, "ca.cert")
setupCfg.UplinkCA.KeyPath = filepath.Join(uplinkPath, "ca.key")
setupCfg.UplinkIdentity.CertPath = filepath.Join(uplinkPath, "identity.cert")
setupCfg.UplinkIdentity.KeyPath = filepath.Join(uplinkPath, "identity.key")
fmt.Printf("creating identity for uplink\n")
err = provider.SetupIdentity(process.Ctx(cmd), setupCfg.UplinkCA, setupCfg.UplinkIdentity)
if err != nil {
return err
}
if setupCfg.GenerateMinioCerts {
minioCertsPath := filepath.Join(uplinkPath, "minio", "certs")
if err := os.MkdirAll(minioCertsPath, 0744); err != nil {
return err
}
if err := os.Link(setupCfg.UplinkIdentity.CertPath, filepath.Join(minioCertsPath, "public.crt")); err != nil {
return err
}
if err := os.Link(setupCfg.UplinkIdentity.KeyPath, filepath.Join(minioCertsPath, "private.key")); err != nil {
return err
}
}
startingPort := setupCfg.StartingPort
overlayAddr := joinHostPort(setupCfg.ListenHost, startingPort+1)
overrides := map[string]interface{}{
"satellite.server.identity.cert-path": setupCfg.SatelliteIdentity.CertPath,
"satellite.server.identity.key-path": setupCfg.SatelliteIdentity.KeyPath,
"satellite.server.address": joinHostPort(setupCfg.ListenHost, startingPort+1),
"satellite.server.revocation-dburl": "redis://127.0.0.1:6378?db=2&password=abc123",
"satellite.kademlia.bootstrap-addr": joinHostPort(setupCfg.ListenHost, startingPort+1),
"satellite.pointer-db.database-url": "bolt://" + filepath.Join(setupDir, "satellite", "pointerdb.db"),
"satellite.kademlia.alpha": 3,
"satellite.repairer.overlay-addr": overlayAddr,
"satellite.repairer.pointer-db-addr": joinHostPort(setupCfg.ListenHost, startingPort+1),
"satellite.repairer.api-key": setupCfg.APIKey,
"uplink.identity.cert-path": setupCfg.UplinkIdentity.CertPath,
"uplink.identity.key-path": setupCfg.UplinkIdentity.KeyPath,
"uplink.server.address": joinHostPort(setupCfg.ListenHost, startingPort),
"uplink.client.overlay-addr": joinHostPort(setupCfg.ListenHost, startingPort+1),
"uplink.client.pointer-db-addr": joinHostPort(setupCfg.ListenHost, startingPort+1),
"uplink.minio.dir": filepath.Join(setupDir, "uplink", "minio"),
"uplink.enc.key": setupCfg.EncKey,
"uplink.client.api-key": setupCfg.APIKey,
"uplink.rs.min-threshold": 1 * len(runCfg.StorageNodes) / 5,
"uplink.rs.repair-threshold": 2 * len(runCfg.StorageNodes) / 5,
"uplink.rs.success-threshold": 3 * len(runCfg.StorageNodes) / 5,
"uplink.rs.max-threshold": 4 * len(runCfg.StorageNodes) / 5,
"kademlia.bucket-size": 4,
"kademlia.replacement-cache-size": 1,
// TODO: this will eventually go away
"pointer-db.auth.api-key": setupCfg.APIKey,
"log.development": true,
"log.level": "debug",
}
for i := 0; i < len(runCfg.StorageNodes); i++ {
storagenodePath := filepath.Join(setupDir, fmt.Sprintf("f%d", i))
storagenode := fmt.Sprintf("storage-nodes.%02d.", i)
overrides[storagenode+"server.identity.cert-path"] = filepath.Join(storagenodePath, "identity.cert")
overrides[storagenode+"server.identity.key-path"] = filepath.Join(storagenodePath, "identity.key")
overrides[storagenode+"server.address"] = joinHostPort(setupCfg.ListenHost, startingPort+i*2+3)
overrides[storagenode+"server.revocation-dburl"] = "redis://127.0.0.1:6378?db=2&password=abc123"
overrides[storagenode+"kademlia.bootstrap-addr"] = joinHostPort(setupCfg.ListenHost, startingPort+1)
overrides[storagenode+"storage.path"] = filepath.Join(storagenodePath, "data")
overrides[storagenode+"kademlia.alpha"] = 3
}
return process.SaveConfigWithAllDefaults(cmd.Flags(), filepath.Join(setupDir, "config.yaml"), overrides)
}
func joinHostPort(host string, port int) string {
return net.JoinHostPort(host, fmt.Sprint(port))
}

View File

@ -44,7 +44,7 @@ func init() {
if dirParam != "" {
defaultConfDir = dirParam
}
confDir = rootCmd.PersistentFlags().String("config-dir", defaultConfDir, "main directory for captplanet configuration")
confDir = rootCmd.PersistentFlags().String("config-dir", defaultConfDir, "main directory for certificates configuration")
rootCmd.AddCommand(runCmd)
cfgstruct.Bind(runCmd.Flags(), &runCfg, cfgstruct.ConfDir(defaultConfDir))

View File

@ -26,8 +26,8 @@ import (
)
var (
// Addr is the address of Capt Planet from command flags
Addr = flag.String("address", "localhost:7778", "address of captplanet to inspect")
// Addr is the address of peer from command flags
Addr = flag.String("address", "localhost:7778", "address of peer to inspect")
// ErrInspectorDial throws when there are errors dialing the inspector server
ErrInspectorDial = errs.Class("error dialing inspector server:")

View File

@ -1,115 +0,0 @@
#!/bin/bash
set -ueo pipefail
go install -race -v storj.io/storj/cmd/captplanet
unamestr=`uname`
if [[ "$unamestr" == 'Darwin' ]]; then
CONFIG_DIR=$HOME/Library/Application\ Support/Storj/Capt
else
CONFIG_DIR=$HOME/.local/share/storj/capt
fi
captplanet setup --config-dir $CONFIG_DIR
sed -i~ 's/interval:.*/interval: 1s/g' $CONFIG_DIR/config.yaml
# run captplanet for 5 seconds to reproduce kademlia problems. See V3-526
captplanet run &
CAPT_PID=$!
sleep 5
kill -9 $CAPT_PID
captplanet run &
CAPT_PID=$!
# Wait 5 seconds for kademlia startup
sleep 5
#setup tmpdir for testfiles and cleanup
TMP_DIR=$(mktemp -d -t tmp.XXXXXXXXXX)
CMP_DIR=$(mktemp -d -t tmp.XXXXXXXXXX)
mkdir -p $TMP_DIR
mkdir -p $CMP_DIR
aws configure set aws_access_key_id insecure-dev-access-key
aws configure set aws_secret_access_key insecure-dev-secret-key
aws configure set default.region us-east-1
head -c 1024 </dev/urandom > $TMP_DIR/small-upload-testfile # create 1mb file of random bytes (inline)
head -c 5120 </dev/urandom > $TMP_DIR/big-upload-testfile # create 5mb file of random bytes (remote)
head -c 5 </dev/urandom > $TMP_DIR/multipart-upload-testfile # create 5kb file of random bytes (remote)
aws s3 --endpoint=http://localhost:7777/ mb s3://bucket
aws configure set default.s3.multipart_threshold 1TB
aws s3 --endpoint=http://localhost:7777/ cp $TMP_DIR/small-upload-testfile s3://bucket/small-testfile
aws s3 --endpoint=http://localhost:7777/ cp $TMP_DIR/big-upload-testfile s3://bucket/big-testfile
# Wait 5 seconds to trigger any error related to one of the different intervals
sleep 5
aws configure set default.s3.multipart_threshold 4KB
aws s3 --endpoint=http://localhost:7777/ cp $TMP_DIR/multipart-upload-testfile s3://bucket/multipart-testfile
aws s3 --endpoint=http://localhost:7777/ ls s3://bucket
aws s3 --endpoint=http://localhost:7777/ cp s3://bucket/small-testfile $CMP_DIR/small-download-testfile
aws s3 --endpoint=http://localhost:7777/ cp s3://bucket/big-testfile $CMP_DIR/big-download-testfile
aws s3 --endpoint=http://localhost:7777/ cp s3://bucket/multipart-testfile $CMP_DIR/multipart-download-testfile
aws s3 --endpoint=http://localhost:7777/ rb s3://bucket --force
if cmp $TMP_DIR/small-upload-testfile $CMP_DIR/small-download-testfile
then
echo "Downloaded file matches uploaded file";
else
echo "Downloaded file does not match uploaded file";
kill -9 $CAPT_PID
exit 1;
fi
if cmp $TMP_DIR/big-upload-testfile $CMP_DIR/big-download-testfile
then
echo "Downloaded file matches uploaded file";
else
echo "Downloaded file does not match uploaded file";
kill -9 $CAPT_PID
exit 1;
fi
if cmp $TMP_DIR/multipart-upload-testfile $CMP_DIR/multipart-download-testfile
then
echo "Downloaded file matches uploaded file";
else
echo "Downloaded file does not match uploaded file";
kill -9 $CAPT_PID
exit 1;
fi
kill -9 $CAPT_PID
rm -rf $CONFIG_DIR
captplanet setup --listen-host ::1 --config-dir $CONFIG_DIR
sed -i~ 's/interval:.*/interval: 1s/g' $CONFIG_DIR/config.yaml
captplanet run &
CAPT_PID=$!
# Wait 5 seconds for kademlia startup
sleep 5
aws s3 --endpoint=http://localhost:7777/ mb s3://bucket
aws s3 --endpoint=http://localhost:7777/ cp $TMP_DIR/big-upload-testfile s3://bucket/big-testfile
aws s3 --endpoint=http://localhost:7777/ cp s3://bucket/big-testfile $CMP_DIR/big-download-testfile-ipv6
aws s3 --endpoint=http://localhost:7777/ rb s3://bucket --force
if cmp $TMP_DIR/big-upload-testfile $CMP_DIR/big-download-testfile-ipv6
then
echo "Downloaded ipv6 file matches uploaded file";
else
echo "Downloaded ipv6 file does not match uploaded file";
kill -9 $CAPT_PID
exit 1;
fi
kill -9 $CAPT_PID
rm -rf $TMP_DIR
rm -rf $CONFIG_DIR