Example #1
0
func mustConnectToMDS() torus.MetadataService {
	cfg := flagconfig.BuildConfigFromFlags()
	mds, err := torus.CreateMetadataService("etcd", cfg)
	if err != nil {
		die("couldn't connect to etcd: %v", err)
	}
	return mds
}
Example #2
0
func createServer() *torus.Server {
	cfg := flagconfig.BuildConfigFromFlags()
	srv, err := torus.NewServer(cfg, "etcd", "temp")
	if err != nil {
		die("Couldn't start: %s\n", err)
	}
	err = distributor.OpenReplication(srv)
	if err != nil {
		die("Couldn't start: %s", err)
	}
	return srv
}
Example #3
0
File: main.go Project: coreos/torus
func configureServer(cmd *cobra.Command, args []string) {
	if version {
		fmt.Printf("torusd\nVersion: %s\n", torus.Version)
		os.Exit(0)
	}
	switch {
	case debug:
		capnslog.SetGlobalLogLevel(capnslog.DEBUG)
	default:
		capnslog.SetGlobalLogLevel(capnslog.INFO)
	}
	if logpkg != "" {
		capnslog.SetGlobalLogLevel(capnslog.NOTICE)
		rl := capnslog.MustRepoLogger("github.com/coreos/torus")
		llc, err := rl.ParseLogLevelConfig(logpkg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error parsing logpkg: %s\n", err)
			os.Exit(1)
		}
		rl.SetLogLevel(llc)
	}

	if host != "" {
		httpAddress = fmt.Sprintf("%s:%d", host, port)
	}

	var (
		err  error
		size uint64
	)
	if strings.Contains(sizeStr, "%") {
		percent, err := parsePercentage(sizeStr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error parsing size %s: %s\n", sizeStr, err)
			os.Exit(1)
		}
		directory, _ := filepath.Abs(dataDir)
		size = du.NewDiskUsage(directory).Size() * percent / 100
	} else {
		size, err = humanize.ParseBytes(sizeStr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error parsing size %s: %s\n", sizeStr, err)
			os.Exit(1)
		}
	}

	cfg = flagconfig.BuildConfigFromFlags()
	cfg.DataDir = dataDir
	cfg.StorageSize = size
}
func configureServer(cmd *cobra.Command, args []string) {
	capnslog.SetGlobalLogLevel(capnslog.NOTICE)
	if logpkg != "" {
		rl := capnslog.MustRepoLogger("github.com/coreos/torus")
		llc, err := rl.ParseLogLevelConfig(logpkg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error parsing logpkg: %s\n", err)
			os.Exit(1)
		}
		rl.SetLogLevel(llc)
	}

	cfg = flagconfig.BuildConfigFromFlags()
	cfg.MetadataAddress = etcdAddress
}
Example #5
0
File: ring.go Project: coreos/torus
func ringChangeAction(cmd *cobra.Command, args []string) {
	if mds == nil {
		mds = mustConnectToMDS()
	}
	currentRing, err := mds.GetRing()
	if err != nil {
		die("couldn't get ring: %v", err)
	}
	var newRing torus.Ring
	switch ringType {
	case "empty":
		newRing, err = ring.CreateRing(&models.Ring{
			Type:    uint32(ring.Empty),
			Version: uint32(currentRing.Version() + 1),
		})
	case "single":
		newRing, err = ring.CreateRing(&models.Ring{
			Type:    uint32(ring.Single),
			Peers:   peers,
			Version: uint32(currentRing.Version() + 1),
		})
	case "mod":
		newRing, err = ring.CreateRing(&models.Ring{
			Type:              uint32(ring.Mod),
			Peers:             peers,
			ReplicationFactor: uint32(repFactor),
			Version:           uint32(currentRing.Version() + 1),
		})
	case "ketama":
		newRing, err = ring.CreateRing(&models.Ring{
			Type:              uint32(ring.Ketama),
			Peers:             peers,
			ReplicationFactor: uint32(repFactor),
			Version:           uint32(currentRing.Version() + 1),
		})
	default:
		panic("still unknown ring type")
	}
	if err != nil {
		die("couldn't create new ring: %v", err)
	}
	cfg := flagconfig.BuildConfigFromFlags()
	err = torus.SetRing("etcd", cfg, newRing)
	if err != nil {
		die("couldn't set new ring: %v", err)
	}
}
Example #6
0
File: wipe.go Project: coreos/torus
func wipeAction(cmd *cobra.Command, args []string) {
	if !yesIAmSurePleaseWipe {
		reader := bufio.NewReader(os.Stdin)
		fmt.Println("This will wipe all metadata for torus.\nPlease type `YES`, all caps to confirm: ")
		text, _ := reader.ReadString('\n')
		text = strings.TrimSpace(text)
		if text != "YES" {
			fmt.Println("`YES` not entered, exiting")
			os.Exit(1)
		}
	}
	cfg := flagconfig.BuildConfigFromFlags()
	err := torus.WipeMDS("etcd", cfg)
	if err != nil {
		die("error wiping metadata: %v", err)
	}
}
Example #7
0
File: init.go Project: coreos/torus
func initAction(cmd *cobra.Command, args []string) {
	var err error
	md := torus.GlobalMetadata{}
	md.BlockSize = blockSize
	md.DefaultBlockSpec, err = blockset.ParseBlockLayerSpec(blockSpec)
	if err != nil {
		die("error parsing block-spec: %v", err)
	}

	cfg := flagconfig.BuildConfigFromFlags()
	ringType := ring.Ketama
	if noMakeRing {
		ringType = ring.Empty
	}
	err = torus.InitMDS("etcd", cfg, md, ringType)
	if err != nil {
		die("error writing metadata: %v", err)
	}
}
Example #8
0
File: main.go Project: coreos/torus
func configureServer(cmd *cobra.Command, args []string) {
	switch {
	case debug:
		capnslog.SetGlobalLogLevel(capnslog.DEBUG)
	default:
		capnslog.SetGlobalLogLevel(capnslog.INFO)
	}
	if logpkg != "" {
		capnslog.SetGlobalLogLevel(capnslog.NOTICE)
		rl := capnslog.MustRepoLogger("github.com/coreos/torus")
		llc, err := rl.ParseLogLevelConfig(logpkg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error parsing logpkg: %s\n", err)
			os.Exit(1)
		}
		rl.SetLogLevel(llc)
	}

	cfg = flagconfig.BuildConfigFromFlags()
}