2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-02 18:07:49 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2019-03-02 15:22:20 +00:00
|
|
|
"runtime"
|
2019-01-11 16:18:16 +00:00
|
|
|
"sort"
|
2019-01-02 18:07:49 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2019-02-05 17:22:17 +00:00
|
|
|
"time"
|
2019-01-02 18:07:49 +00:00
|
|
|
|
2019-01-29 14:23:30 +00:00
|
|
|
"github.com/spf13/viper"
|
2019-01-02 18:07:49 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2019-05-14 16:13:18 +01:00
|
|
|
"storj.io/storj/internal/dbutil/pgutil"
|
2019-01-02 18:07:49 +00:00
|
|
|
"storj.io/storj/internal/fpath"
|
|
|
|
"storj.io/storj/internal/processgroup"
|
|
|
|
)
|
|
|
|
|
2019-04-19 16:49:46 +01:00
|
|
|
const (
|
|
|
|
maxInstanceCount = 100
|
|
|
|
maxStoragenodeCount = 200
|
|
|
|
|
|
|
|
folderPermissions = 0744
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// The following values of peer class and endpoints are used
|
|
|
|
// to create a port with a consistent format for storj-sim services.
|
|
|
|
|
|
|
|
// Peer class
|
|
|
|
satellitePeer = 0
|
|
|
|
gatewayPeer = 1
|
|
|
|
versioncontrolPeer = 2
|
|
|
|
bootstrapPeer = 3
|
|
|
|
storagenodePeer = 4
|
|
|
|
|
|
|
|
// Endpoint
|
|
|
|
publicGRPC = 0
|
|
|
|
privateGRPC = 1
|
|
|
|
publicHTTP = 2
|
2019-06-11 16:00:59 +01:00
|
|
|
privateHTTP = 3
|
2019-04-19 16:49:46 +01:00
|
|
|
debugHTTP = 9
|
|
|
|
)
|
|
|
|
|
|
|
|
// port creates a port with a consistent format for storj-sim services.
|
|
|
|
// The port format is: "1PXXE", where P is the peer class, XX is the index of the instance, and E is the endpoint.
|
|
|
|
func port(peerclass, index, endpoint int) string {
|
|
|
|
port := 10000 + peerclass*1000 + index*10 + endpoint
|
|
|
|
return strconv.Itoa(port)
|
|
|
|
}
|
2019-01-02 18:07:49 +00:00
|
|
|
|
|
|
|
func networkExec(flags *Flags, args []string, command string) error {
|
2019-01-08 15:24:15 +00:00
|
|
|
processes, err := newNetwork(flags)
|
2019-01-02 18:07:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := NewCLIContext(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2019-01-18 10:36:58 +00:00
|
|
|
if command == "setup" {
|
|
|
|
identities, err := identitySetup(processes)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = identities.Exec(ctx, command)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 18:07:49 +00:00
|
|
|
err = processes.Exec(ctx, command)
|
|
|
|
closeErr := processes.Close()
|
|
|
|
|
|
|
|
return errs.Combine(err, closeErr)
|
|
|
|
}
|
|
|
|
|
2019-03-23 21:53:03 +00:00
|
|
|
func networkEnv(flags *Flags, args []string) error {
|
|
|
|
flags.OnlyEnv = true
|
|
|
|
processes, err := newNetwork(flags)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// run exec before, since it will load env vars from configs
|
|
|
|
for _, process := range processes.List {
|
|
|
|
if exec := process.ExecBefore["run"]; exec != nil {
|
|
|
|
if err := exec(process); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 02:16:12 +01:00
|
|
|
if len(args) == 1 {
|
|
|
|
envprefix := strings.ToUpper(args[0] + "=")
|
|
|
|
// find the environment value that the environment variable is set to
|
|
|
|
for _, env := range processes.Env() {
|
|
|
|
if strings.HasPrefix(strings.ToUpper(env), envprefix) {
|
|
|
|
fmt.Println(env[len(envprefix):])
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-23 21:53:03 +00:00
|
|
|
for _, env := range processes.Env() {
|
|
|
|
fmt.Println(env)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 18:07:49 +00:00
|
|
|
func networkTest(flags *Flags, command string, args []string) error {
|
2019-01-08 15:24:15 +00:00
|
|
|
processes, err := newNetwork(flags)
|
2019-01-02 18:07:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := NewCLIContext(context.Background())
|
|
|
|
|
|
|
|
var group errgroup.Group
|
|
|
|
processes.Start(ctx, &group, "run")
|
|
|
|
|
2019-01-08 15:24:15 +00:00
|
|
|
for _, process := range processes.List {
|
|
|
|
process.Status.Started.Wait()
|
|
|
|
}
|
2019-01-02 18:07:49 +00:00
|
|
|
|
|
|
|
cmd := exec.CommandContext(ctx, command, args...)
|
|
|
|
cmd.Env = append(os.Environ(), processes.Env()...)
|
|
|
|
stdout := processes.Output.Prefixed("test:out")
|
|
|
|
stderr := processes.Output.Prefixed("test:err")
|
|
|
|
cmd.Stdout, cmd.Stderr = stdout, stderr
|
|
|
|
processgroup.Setup(cmd)
|
|
|
|
|
|
|
|
if printCommands {
|
|
|
|
fmt.Fprintf(processes.Output, "exec: %v\n", strings.Join(cmd.Args, " "))
|
|
|
|
}
|
|
|
|
errRun := cmd.Run()
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
return errs.Combine(errRun, processes.Close(), group.Wait())
|
|
|
|
}
|
|
|
|
|
|
|
|
func networkDestroy(flags *Flags, args []string) error {
|
|
|
|
if fpath.IsRoot(flags.Directory) {
|
|
|
|
return errors.New("safety check: disallowed to remove root directory " + flags.Directory)
|
|
|
|
}
|
|
|
|
if printCommands {
|
2019-01-16 23:09:57 +00:00
|
|
|
fmt.Println("sim | exec: rm -rf", flags.Directory)
|
2019-01-02 18:07:49 +00:00
|
|
|
}
|
|
|
|
return os.RemoveAll(flags.Directory)
|
|
|
|
}
|
|
|
|
|
|
|
|
// newNetwork creates a default network
|
2019-01-08 15:24:15 +00:00
|
|
|
func newNetwork(flags *Flags) (*Processes, error) {
|
|
|
|
// with common adds all common arguments to the process
|
2019-03-19 09:10:23 +00:00
|
|
|
withCommon := func(dir string, all Arguments) Arguments {
|
|
|
|
common := []string{"--metrics.app-suffix", "sim", "--log.level", "debug", "--config-dir", dir}
|
2019-03-12 12:51:06 +00:00
|
|
|
if flags.IsDev {
|
|
|
|
common = append(common, "--dev")
|
|
|
|
}
|
2019-01-08 15:24:15 +00:00
|
|
|
for command, args := range all {
|
2019-03-12 12:51:06 +00:00
|
|
|
all[command] = append(append(common, command), args...)
|
2019-01-08 15:24:15 +00:00
|
|
|
}
|
|
|
|
return all
|
|
|
|
}
|
2019-01-02 18:07:49 +00:00
|
|
|
|
2019-03-19 09:10:23 +00:00
|
|
|
processes := NewProcesses(flags.Directory)
|
|
|
|
|
2019-04-19 16:49:46 +01:00
|
|
|
var host = flags.Host
|
2019-04-03 20:13:39 +01:00
|
|
|
versioncontrol := processes.New(Info{
|
|
|
|
Name: "versioncontrol/0",
|
|
|
|
Executable: "versioncontrol",
|
|
|
|
Directory: filepath.Join(processes.Directory, "versioncontrol", "0"),
|
2019-04-19 16:49:46 +01:00
|
|
|
Address: net.JoinHostPort(host, port(versioncontrolPeer, 0, publicGRPC)),
|
2019-04-03 20:13:39 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
versioncontrol.Arguments = withCommon(versioncontrol.Directory, Arguments{
|
|
|
|
"setup": {
|
|
|
|
"--address", versioncontrol.Address,
|
2019-05-14 16:13:18 +01:00
|
|
|
"--debug.addr", net.JoinHostPort(host, port(versioncontrolPeer, 0, debugHTTP)),
|
2019-04-03 20:13:39 +01:00
|
|
|
},
|
|
|
|
"run": {},
|
|
|
|
})
|
|
|
|
|
|
|
|
versioncontrol.ExecBefore["run"] = func(process *Process) error {
|
|
|
|
return readConfigString(&versioncontrol.Address, versioncontrol.Directory, "address")
|
|
|
|
}
|
|
|
|
|
2019-01-09 15:59:51 +00:00
|
|
|
bootstrap := processes.New(Info{
|
|
|
|
Name: "bootstrap/0",
|
|
|
|
Executable: "bootstrap",
|
2019-03-19 09:10:23 +00:00
|
|
|
Directory: filepath.Join(processes.Directory, "bootstrap", "0"),
|
2019-04-19 16:49:46 +01:00
|
|
|
Address: net.JoinHostPort(host, port(bootstrapPeer, 0, publicGRPC)),
|
2019-01-09 15:59:51 +00:00
|
|
|
})
|
|
|
|
|
2019-04-03 20:13:39 +01:00
|
|
|
// gateway must wait for the versioncontrol to start up
|
|
|
|
bootstrap.WaitForStart(versioncontrol)
|
|
|
|
|
2019-03-19 09:10:23 +00:00
|
|
|
bootstrap.Arguments = withCommon(bootstrap.Directory, Arguments{
|
2019-01-22 12:35:48 +00:00
|
|
|
"setup": {
|
|
|
|
"--identity-dir", bootstrap.Directory,
|
2019-03-05 10:38:21 +00:00
|
|
|
|
2019-04-19 16:49:46 +01:00
|
|
|
"--web.address", net.JoinHostPort(host, port(bootstrapPeer, 0, publicHTTP)),
|
2019-03-05 10:38:21 +00:00
|
|
|
|
2019-01-28 14:48:49 +00:00
|
|
|
"--server.address", bootstrap.Address,
|
2019-04-19 16:49:46 +01:00
|
|
|
"--server.private-address", net.JoinHostPort(host, port(bootstrapPeer, 0, privateGRPC)),
|
2019-01-28 14:48:49 +00:00
|
|
|
|
2019-01-09 15:59:51 +00:00
|
|
|
"--kademlia.bootstrap-addr", bootstrap.Address,
|
|
|
|
"--kademlia.operator.email", "bootstrap@example.com",
|
|
|
|
"--kademlia.operator.wallet", "0x0123456789012345678901234567890123456789",
|
2019-02-11 11:17:32 +00:00
|
|
|
|
|
|
|
"--server.extensions.revocation=false",
|
|
|
|
"--server.use-peer-ca-whitelist=false",
|
2019-04-03 20:13:39 +01:00
|
|
|
|
|
|
|
"--version.server-address", fmt.Sprintf("http://%s/", versioncontrol.Address),
|
2019-04-19 16:49:46 +01:00
|
|
|
|
2019-05-14 16:13:18 +01:00
|
|
|
"--debug.addr", net.JoinHostPort(host, port(bootstrapPeer, 0, debugHTTP)),
|
2019-01-09 15:59:51 +00:00
|
|
|
},
|
2019-01-28 14:48:49 +00:00
|
|
|
"run": {},
|
2019-01-09 15:59:51 +00:00
|
|
|
})
|
2019-02-06 12:47:00 +00:00
|
|
|
bootstrap.ExecBefore["run"] = func(process *Process) error {
|
|
|
|
return readConfigString(&bootstrap.Address, bootstrap.Directory, "server.address")
|
|
|
|
}
|
2019-01-08 15:24:15 +00:00
|
|
|
|
2019-01-17 20:59:26 +00:00
|
|
|
// Create satellites making all satellites wait for bootstrap to start
|
2019-04-19 16:49:46 +01:00
|
|
|
if flags.SatelliteCount > maxInstanceCount {
|
|
|
|
return nil, fmt.Errorf("exceeded the max instance count of %d with Satellite count of %d", maxInstanceCount, flags.SatelliteCount)
|
|
|
|
}
|
|
|
|
|
2019-01-09 15:59:51 +00:00
|
|
|
var satellites []*Process
|
2019-01-08 15:24:15 +00:00
|
|
|
for i := 0; i < flags.SatelliteCount; i++ {
|
|
|
|
process := processes.New(Info{
|
|
|
|
Name: fmt.Sprintf("satellite/%d", i),
|
|
|
|
Executable: "satellite",
|
2019-03-19 09:10:23 +00:00
|
|
|
Directory: filepath.Join(processes.Directory, "satellite", fmt.Sprint(i)),
|
2019-04-19 16:49:46 +01:00
|
|
|
Address: net.JoinHostPort(host, port(satellitePeer, i, publicGRPC)),
|
2019-01-08 15:24:15 +00:00
|
|
|
})
|
2019-01-09 15:59:51 +00:00
|
|
|
satellites = append(satellites, process)
|
2019-01-08 15:24:15 +00:00
|
|
|
|
2019-01-09 15:59:51 +00:00
|
|
|
// satellite must wait for bootstrap to start
|
|
|
|
process.WaitForStart(bootstrap)
|
2019-01-02 18:07:49 +00:00
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
// TODO: find source file, to set static path
|
|
|
|
_, filename, _, ok := runtime.Caller(0)
|
|
|
|
if !ok {
|
|
|
|
return nil, errs.Combine(processes.Close(), errs.New("no caller information"))
|
|
|
|
}
|
|
|
|
storjRoot := strings.TrimSuffix(filename, "/cmd/storj-sim/network.go")
|
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
consoleAuthToken := "secure_token"
|
|
|
|
|
2019-03-19 09:10:23 +00:00
|
|
|
process.Arguments = withCommon(process.Directory, Arguments{
|
2019-01-22 12:35:48 +00:00
|
|
|
"setup": {
|
|
|
|
"--identity-dir", process.Directory,
|
2019-04-19 16:49:46 +01:00
|
|
|
"--console.address", net.JoinHostPort(host, port(satellitePeer, i, publicHTTP)),
|
2019-03-02 15:22:20 +00:00
|
|
|
"--console.static-dir", filepath.Join(storjRoot, "web/satellite/"),
|
2019-03-19 17:55:43 +00:00
|
|
|
// TODO: remove console.auth-token after vanguard release
|
|
|
|
"--console.auth-token", consoleAuthToken,
|
2019-06-11 16:00:59 +01:00
|
|
|
"--marketing.address", net.JoinHostPort(host, port(satellitePeer, i, privateHTTP)),
|
2019-06-12 14:42:39 +01:00
|
|
|
"--marketing.static-dir", filepath.Join(storjRoot, "web/marketing/"),
|
2019-01-08 15:24:15 +00:00
|
|
|
"--server.address", process.Address,
|
2019-04-19 16:49:46 +01:00
|
|
|
"--server.private-address", net.JoinHostPort(host, port(satellitePeer, i, privateGRPC)),
|
2019-01-08 23:41:01 +00:00
|
|
|
|
2019-01-28 14:48:49 +00:00
|
|
|
"--kademlia.bootstrap-addr", bootstrap.Address,
|
2019-02-11 11:17:32 +00:00
|
|
|
|
|
|
|
"--server.extensions.revocation=false",
|
|
|
|
"--server.use-peer-ca-whitelist=false",
|
2019-03-02 15:22:20 +00:00
|
|
|
|
|
|
|
"--mail.smtp-server-address", "smtp.gmail.com:587",
|
|
|
|
"--mail.from", "Storj <yaroslav-satellite-test@storj.io>",
|
|
|
|
"--mail.template-path", filepath.Join(storjRoot, "web/satellite/static/emails"),
|
2019-04-03 20:13:39 +01:00
|
|
|
"--version.server-address", fmt.Sprintf("http://%s/", versioncontrol.Address),
|
2019-05-14 16:13:18 +01:00
|
|
|
"--debug.addr", net.JoinHostPort(host, port(satellitePeer, i, debugHTTP)),
|
2019-01-08 15:24:15 +00:00
|
|
|
},
|
2019-01-28 14:48:49 +00:00
|
|
|
"run": {},
|
2019-01-08 15:24:15 +00:00
|
|
|
})
|
2019-02-06 12:47:00 +00:00
|
|
|
|
2019-05-14 16:13:18 +01:00
|
|
|
if flags.Postgres != "" {
|
|
|
|
process.Arguments["setup"] = append(process.Arguments["setup"],
|
|
|
|
"--database", pgutil.ConnstrWithSchema(flags.Postgres, fmt.Sprintf("satellite/%d", i)),
|
|
|
|
"--metainfo.database-url", pgutil.ConnstrWithSchema(flags.Postgres, fmt.Sprintf("satellite/%d/meta", i)),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:47:00 +00:00
|
|
|
process.ExecBefore["run"] = func(process *Process) error {
|
|
|
|
return readConfigString(&process.Address, process.Directory, "server.address")
|
|
|
|
}
|
2019-01-02 18:07:49 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 15:24:15 +00:00
|
|
|
// Create gateways for each satellite
|
2019-01-09 15:59:51 +00:00
|
|
|
for i, satellite := range satellites {
|
2019-02-06 12:47:00 +00:00
|
|
|
satellite := satellite
|
2019-01-08 15:24:15 +00:00
|
|
|
process := processes.New(Info{
|
|
|
|
Name: fmt.Sprintf("gateway/%d", i),
|
|
|
|
Executable: "gateway",
|
2019-03-19 09:10:23 +00:00
|
|
|
Directory: filepath.Join(processes.Directory, "gateway", fmt.Sprint(i)),
|
2019-04-19 16:49:46 +01:00
|
|
|
Address: net.JoinHostPort(host, port(gatewayPeer, i, publicGRPC)),
|
2019-01-29 14:23:30 +00:00
|
|
|
Extra: []string{},
|
2019-01-08 15:24:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// gateway must wait for the corresponding satellite to start up
|
|
|
|
process.WaitForStart(satellite)
|
2019-03-19 09:10:23 +00:00
|
|
|
process.Arguments = withCommon(process.Directory, Arguments{
|
2019-01-08 15:24:15 +00:00
|
|
|
"setup": {
|
2019-06-07 17:14:40 +01:00
|
|
|
"--non-interactive",
|
|
|
|
|
|
|
|
"--enc.encryption-key=TestEncryptionKey",
|
|
|
|
|
2019-01-22 12:35:48 +00:00
|
|
|
"--identity-dir", process.Directory,
|
2019-01-08 15:24:15 +00:00
|
|
|
"--satellite-addr", satellite.Address,
|
2019-01-28 14:48:49 +00:00
|
|
|
|
2019-01-08 15:24:15 +00:00
|
|
|
"--server.address", process.Address,
|
|
|
|
|
2019-03-22 09:01:49 +00:00
|
|
|
"--satellite-addr", satellite.Address,
|
2019-01-08 15:24:15 +00:00
|
|
|
|
|
|
|
"--rs.min-threshold", strconv.Itoa(1 * flags.StorageNodeCount / 5),
|
|
|
|
"--rs.repair-threshold", strconv.Itoa(2 * flags.StorageNodeCount / 5),
|
|
|
|
"--rs.success-threshold", strconv.Itoa(3 * flags.StorageNodeCount / 5),
|
|
|
|
"--rs.max-threshold", strconv.Itoa(4 * flags.StorageNodeCount / 5),
|
2019-02-11 11:17:32 +00:00
|
|
|
|
|
|
|
"--tls.extensions.revocation=false",
|
|
|
|
"--tls.use-peer-ca-whitelist=false",
|
2019-04-19 16:49:46 +01:00
|
|
|
|
|
|
|
"--debug.addr", net.JoinHostPort(host, port(gatewayPeer, i, debugHTTP)),
|
2019-01-08 15:24:15 +00:00
|
|
|
},
|
2019-06-07 17:14:40 +01:00
|
|
|
"run": {},
|
2019-01-08 15:24:15 +00:00
|
|
|
})
|
2019-01-29 14:23:30 +00:00
|
|
|
|
|
|
|
process.ExecBefore["run"] = func(process *Process) error {
|
2019-02-06 12:47:00 +00:00
|
|
|
err := readConfigString(&process.Address, process.Directory, "server.address")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-29 14:23:30 +00:00
|
|
|
vip := viper.New()
|
|
|
|
vip.AddConfigPath(process.Directory)
|
|
|
|
if err := vip.ReadInConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: maybe all the config flags should be exposed for all processes?
|
|
|
|
|
2019-02-05 17:22:17 +00:00
|
|
|
// check if gateway config has an api key, if it's not
|
|
|
|
// create example project with key and add it to the config
|
|
|
|
// so that gateway can have access to the satellite
|
2019-03-22 09:01:49 +00:00
|
|
|
apiKey := vip.GetString("api-key")
|
2019-03-23 21:53:03 +00:00
|
|
|
if !flags.OnlyEnv && apiKey == "" {
|
2019-02-06 12:47:00 +00:00
|
|
|
var consoleAddress string
|
|
|
|
satelliteConfigErr := readConfigString(&consoleAddress, satellite.Directory, "console.address")
|
|
|
|
if satelliteConfigErr != nil {
|
|
|
|
return satelliteConfigErr
|
|
|
|
}
|
|
|
|
|
2019-03-08 14:01:11 +00:00
|
|
|
host := "http://" + consoleAddress
|
2019-03-19 17:55:43 +00:00
|
|
|
createRegistrationTokenAddress := host + "/registrationToken/?projectsLimit=1"
|
2019-03-08 14:01:11 +00:00
|
|
|
consoleActivationAddress := host + "/activation/?token="
|
|
|
|
consoleAPIAddress := host + "/api/graphql/v0"
|
2019-02-05 17:22:17 +00:00
|
|
|
|
|
|
|
// wait for console server to start
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
if err := addExampleProjectWithKey(&apiKey, createRegistrationTokenAddress, consoleActivationAddress, consoleAPIAddress); err != nil {
|
2019-02-05 17:22:17 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-03-22 09:01:49 +00:00
|
|
|
vip.Set("api-key", apiKey)
|
2019-02-05 17:22:17 +00:00
|
|
|
|
|
|
|
if err := vip.WriteConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-23 21:53:03 +00:00
|
|
|
if apiKey != "" {
|
|
|
|
process.Extra = append(process.Extra, "API_KEY="+apiKey)
|
|
|
|
}
|
|
|
|
|
2019-01-29 14:23:30 +00:00
|
|
|
accessKey := vip.GetString("minio.access-key")
|
|
|
|
secretKey := vip.GetString("minio.secret-key")
|
|
|
|
|
|
|
|
process.Extra = append(process.Extra,
|
|
|
|
"ACCESS_KEY="+accessKey,
|
|
|
|
"SECRET_KEY="+secretKey,
|
|
|
|
)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-01-02 18:07:49 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 15:24:15 +00:00
|
|
|
// Create storage nodes
|
2019-04-19 16:49:46 +01:00
|
|
|
if flags.StorageNodeCount > maxStoragenodeCount {
|
|
|
|
return nil, fmt.Errorf("exceeded the max instance count of %d with Storage Node count of %d", maxStoragenodeCount, flags.StorageNodeCount)
|
|
|
|
}
|
2019-01-08 15:24:15 +00:00
|
|
|
for i := 0; i < flags.StorageNodeCount; i++ {
|
|
|
|
process := processes.New(Info{
|
|
|
|
Name: fmt.Sprintf("storagenode/%d", i),
|
|
|
|
Executable: "storagenode",
|
2019-03-19 09:10:23 +00:00
|
|
|
Directory: filepath.Join(processes.Directory, "storagenode", fmt.Sprint(i)),
|
2019-04-19 16:49:46 +01:00
|
|
|
Address: net.JoinHostPort(host, port(storagenodePeer, i, publicGRPC)),
|
2019-01-08 15:24:15 +00:00
|
|
|
})
|
|
|
|
|
2019-02-22 14:35:51 +00:00
|
|
|
// storage node must wait for bootstrap and satellites to start
|
2019-01-09 15:59:51 +00:00
|
|
|
process.WaitForStart(bootstrap)
|
2019-02-22 14:35:51 +00:00
|
|
|
for _, satellite := range satellites {
|
|
|
|
process.WaitForStart(satellite)
|
|
|
|
}
|
2019-01-08 15:24:15 +00:00
|
|
|
|
2019-03-19 09:10:23 +00:00
|
|
|
process.Arguments = withCommon(process.Directory, Arguments{
|
2019-01-22 12:35:48 +00:00
|
|
|
"setup": {
|
|
|
|
"--identity-dir", process.Directory,
|
2019-01-28 14:48:49 +00:00
|
|
|
"--server.address", process.Address,
|
2019-04-19 16:49:46 +01:00
|
|
|
"--server.private-address", net.JoinHostPort(host, port(storagenodePeer, i, privateGRPC)),
|
2019-01-28 14:48:49 +00:00
|
|
|
|
2019-01-09 15:59:51 +00:00
|
|
|
"--kademlia.bootstrap-addr", bootstrap.Address,
|
2019-01-08 15:24:15 +00:00
|
|
|
"--kademlia.operator.email", fmt.Sprintf("storage%d@example.com", i),
|
|
|
|
"--kademlia.operator.wallet", "0x0123456789012345678901234567890123456789",
|
2019-02-11 11:17:32 +00:00
|
|
|
|
2019-06-10 11:14:50 +01:00
|
|
|
"--storage2.monitor.minimum-disk-space", "25GB",
|
|
|
|
"--storage2.monitor.minimum-bandwidth", "25GB",
|
|
|
|
|
2019-02-11 11:17:32 +00:00
|
|
|
"--server.extensions.revocation=false",
|
|
|
|
"--server.use-peer-ca-whitelist=false",
|
2019-03-22 14:21:16 +00:00
|
|
|
"--storage.satellite-id-restriction=false",
|
2019-04-03 20:13:39 +01:00
|
|
|
|
|
|
|
"--version.server-address", fmt.Sprintf("http://%s/", versioncontrol.Address),
|
2019-05-14 16:13:18 +01:00
|
|
|
"--debug.addr", net.JoinHostPort(host, port(storagenodePeer, i, debugHTTP)),
|
2019-01-08 15:24:15 +00:00
|
|
|
},
|
2019-01-28 14:48:49 +00:00
|
|
|
"run": {},
|
2019-01-08 15:24:15 +00:00
|
|
|
})
|
2019-02-06 12:47:00 +00:00
|
|
|
|
|
|
|
process.ExecBefore["run"] = func(process *Process) error {
|
|
|
|
return readConfigString(&process.Address, process.Directory, "server.address")
|
|
|
|
}
|
2019-01-08 15:24:15 +00:00
|
|
|
}
|
2019-01-02 18:07:49 +00:00
|
|
|
|
2019-01-11 16:18:16 +00:00
|
|
|
{ // verify that we have all binaries
|
|
|
|
missing := map[string]bool{}
|
|
|
|
for _, process := range processes.List {
|
|
|
|
_, err := exec.LookPath(process.Executable)
|
|
|
|
if err != nil {
|
|
|
|
missing[process.Executable] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(missing) > 0 {
|
|
|
|
var list []string
|
|
|
|
for executable := range missing {
|
|
|
|
list = append(list, executable)
|
|
|
|
}
|
|
|
|
sort.Strings(list)
|
|
|
|
return nil, fmt.Errorf("some executables cannot be found: %v", list)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 15:24:15 +00:00
|
|
|
// Create directories for all processes
|
|
|
|
for _, process := range processes.List {
|
|
|
|
if err := os.MkdirAll(process.Directory, folderPermissions); err != nil {
|
2019-01-02 18:07:49 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return processes, nil
|
|
|
|
}
|
2019-01-08 15:24:15 +00:00
|
|
|
|
2019-01-18 10:36:58 +00:00
|
|
|
func identitySetup(network *Processes) (*Processes, error) {
|
2019-03-19 09:10:23 +00:00
|
|
|
processes := NewProcesses(network.Directory)
|
2019-01-18 10:36:58 +00:00
|
|
|
|
|
|
|
for _, process := range network.List {
|
2019-05-10 12:17:58 +01:00
|
|
|
if process.Info.Executable == "gateway" {
|
|
|
|
// gateways don't need an identity
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-01-18 10:36:58 +00:00
|
|
|
identity := processes.New(Info{
|
|
|
|
Name: "identity/" + process.Info.Name,
|
|
|
|
Executable: "identity",
|
|
|
|
Directory: process.Directory,
|
|
|
|
Address: "",
|
|
|
|
})
|
|
|
|
|
|
|
|
identity.Arguments = Arguments{
|
|
|
|
"setup": {
|
2019-01-22 12:35:48 +00:00
|
|
|
"--identity-dir", process.Directory,
|
2019-01-23 11:36:19 +00:00
|
|
|
"--concurrency", "1",
|
|
|
|
"--difficulty", "8",
|
2019-01-24 15:41:16 +00:00
|
|
|
"create", ".",
|
2019-01-18 10:36:58 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// create directories for all processes
|
|
|
|
for _, process := range processes.List {
|
|
|
|
if err := os.MkdirAll(process.Directory, folderPermissions); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return processes, nil
|
|
|
|
}
|
2019-02-06 12:47:00 +00:00
|
|
|
|
|
|
|
// readConfigString reads from dir/config.yaml flagName returns the value in `into`
|
|
|
|
func readConfigString(into *string, dir, flagName string) error {
|
|
|
|
vip := viper.New()
|
|
|
|
vip.AddConfigPath(dir)
|
|
|
|
if err := vip.ReadInConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if v := vip.GetString(flagName); v != "" {
|
|
|
|
*into = v
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|