Commit 0c886069 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5c24c361
......@@ -23,7 +23,7 @@ import (
"fmt"
"os"
"../../../neo"
"../../../neo/neotools"
)
func usage() {
......@@ -38,7 +38,7 @@ Usage:
The commands are:
`)
for _, cmd := range neo.Commands {
for _, cmd := range neotools.Commands {
fmt.Fprintf(w, "\t%-11s %s\n", cmd.Name, cmd.Summary)
}
......@@ -51,7 +51,7 @@ Additional help topics:
`)
for _, topic := range neo.HelpTopics {
for _, topic := range neotools.HelpTopics {
fmt.Fprintf(w, "\t%-11s %s\n", topic.Name, topic.Summary)
}
......@@ -72,13 +72,13 @@ func help(argv []string) {
topic := argv[1]
// topic can either be a command name or a help topic
command := neo.Commands.Lookup(topic)
command := neotools.Commands.Lookup(topic)
if command != nil {
command.Usage(os.Stdout)
os.Exit(0)
}
helpTopic := neo.HelpTopics.Lookup(topic)
helpTopic := neotools.HelpTopics.Lookup(topic)
if helpTopic != nil {
fmt.Println(helpTopic.Text)
os.Exit(0)
......@@ -108,7 +108,7 @@ func main() {
}
// run subcommand
cmd := neo.Commands.Lookup(command)
cmd := neotools.Commands.Lookup(command)
if cmd == nil {
fmt.Fprintf(os.Stderr, "neo: unknown subcommand \"%s\"\n", command)
fmt.Fprintf(os.Stderr, "Run 'neo help' for usage.\n")
......
......@@ -15,10 +15,10 @@
//
// See COPYING file for full licensing terms.
package main
package neotools
// registry of all commands & help topics
import "../../../zodb/zodbtools"
import "../../zodb/zodbtools"
var Commands = zodbtools.CommandRegistry{
{"master", masterSummary, masterUsage, masterMain},
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// Package neotools provides tools for running and managing NEO databases
package neotools
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package neotools
// cli to run master node
import (
"context"
"flag"
"fmt"
"log"
"io"
"os"
"../../neo"
"../../neo/server"
)
const masterSummary = "run master node"
// TODO options:
// cluster, masterv ...
func masterUsage(w io.Writer) {
fmt.Fprintf(w,
`Usage: neo master [options]
Run NEO master node.
`)
// FIXME use w (see flags.SetOutput)
}
func masterMain(argv []string) {
var bind string
var cluster string
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.Usage = func() { masterUsage(os.Stderr); flags.PrintDefaults() } // XXX prettify
flags.StringVar(&bind, "bind", bind, "address to serve on")
flags.StringVar(&cluster, "cluster", cluster, "cluster name")
flags.Parse(argv[1:])
argv = flags.Args()
if len(argv) < 1 {
flags.Usage()
os.Exit(2)
}
masterSrv := server.NewMaster(cluster)
ctx := context.Background()
/*
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.Sleep(3 * time.Second)
cancel()
}()
*/
net := neo.NetPlain("tcp") // TODO + TLS; not only "tcp" ?
err := server.ListenAndServe(ctx, net, bind, masterSrv)
if err != nil {
log.Fatal(err)
}
}
// Copyright (C) 2016-2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package neotools
// cli to run storage node
import (
"context"
"flag"
"fmt"
"log"
"io"
"os"
"strings"
"../../neo"
"../../neo/server"
"../../zodb/storage/fs1"
)
const storageSummary = "run storage node"
// TODO options:
// cluster, masterv ...
func storageUsage(w io.Writer) {
fmt.Fprintf(w,
`Usage: neo storage [options] zstor XXX
Run NEO storage node.
`)
// FIXME use w (see flags.SetOutput)
}
func storageMain(argv []string) {
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.Usage = func() { storageUsage(os.Stderr); flags.PrintDefaults() } // XXX prettify
cluster := flags.String("cluster", "", "the cluster name")
masters := flags.String("masters", "", "list of masters")
bind := flags.String("bind", "", "address to serve on")
flags.Parse(argv[1:])
if *cluster == "" {
// XXX vvv -> die or log.Fatalf ?
fmt.Fprintf(os.Stderr, "cluster name must be provided")
os.Exit(2)
}
masterv := strings.Split(*masters, ",")
if len(masterv) == 0 {
fmt.Fprintf(os.Stderr, "master list must be provided")
os.Exit(2)
}
if len(masterv) > 1 {
fmt.Fprintf(os.Stderr, "BUG neo/go POC currently supports only 1 master")
os.Exit(2)
}
master := masterv[0]
argv = flags.Args()
if len(argv) < 1 {
flags.Usage()
os.Exit(2)
}
// XXX hack to use existing zodb storage for data
zstor, err := fs1.Open(context.Background(), argv[0]) // XXX context.Background -> ?
if err != nil {
log.Fatal(err)
}
net := neo.NetPlain("tcp") // TODO + TLS; not only "tcp" ?
storSrv := server.NewStorage(*cluster, master, *bind, net, zstor)
ctx := context.Background()
/*
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.Sleep(3 * time.Second)
cancel()
}()
*/
err = storSrv.Run(ctx)
if err != nil {
log.Fatal(err)
}
}
......@@ -22,12 +22,8 @@ package server
import (
"context"
"errors"
"flag"
"fmt"
"io"
"log"
"math"
"os"
"sync"
"../../neo"
......@@ -960,53 +956,3 @@ func (m *Master) ServeAdmin(ctx context.Context, conn *neo.Conn) {
func (m *Master) ServeMaster(ctx context.Context, conn *neo.Conn) {
// TODO (for elections)
}
// ----------------------------------------
const masterSummary = "run master node"
// TODO options:
// cluster, masterv ...
func masterUsage(w io.Writer) {
fmt.Fprintf(w,
`Usage: neo master [options]
Run NEO master node.
`)
// FIXME use w (see flags.SetOutput)
}
func masterMain(argv []string) {
var bind string
var cluster string
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.Usage = func() { masterUsage(os.Stderr); flags.PrintDefaults() } // XXX prettify
flags.StringVar(&bind, "bind", bind, "address to serve on")
flags.StringVar(&cluster, "cluster", cluster, "cluster name")
flags.Parse(argv[1:])
argv = flags.Args()
if len(argv) < 1 {
flags.Usage()
os.Exit(2)
}
masterSrv := NewMaster(cluster)
ctx := context.Background()
/*
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.Sleep(3 * time.Second)
cancel()
}()
*/
net := neo.NetPlain("tcp") // TODO + TLS; not only "tcp" ?
err := ListenAndServe(ctx, net, bind, masterSrv)
if err != nil {
log.Fatal(err)
}
}
......@@ -20,17 +20,11 @@ package server
import (
"context"
"flag"
"fmt"
"io"
"log"
"os"
"strings"
"time"
"../../neo"
"../../zodb"
"../../zodb/storage/fs1"
)
// XXX fmt -> log
......@@ -326,76 +320,3 @@ func (stor *Storage) ServeClient(ctx context.Context, conn *neo.Conn) {
//req.Put(...)
}
}
// ----------------------------------------
const storageSummary = "run storage node"
// TODO options:
// cluster, masterv ...
func storageUsage(w io.Writer) {
fmt.Fprintf(w,
`Usage: neo storage [options] zstor XXX
Run NEO storage node.
`)
// FIXME use w (see flags.SetOutput)
}
func storageMain(argv []string) {
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.Usage = func() { storageUsage(os.Stderr); flags.PrintDefaults() } // XXX prettify
cluster := flags.String("cluster", "", "the cluster name")
masters := flags.String("masters", "", "list of masters")
bind := flags.String("bind", "", "address to serve on")
flags.Parse(argv[1:])
if *cluster == "" {
// XXX vvv -> die or log.Fatalf ?
fmt.Fprintf(os.Stderr, "cluster name must be provided")
os.Exit(2)
}
masterv := strings.Split(*masters, ",")
if len(masterv) == 0 {
fmt.Fprintf(os.Stderr, "master list must be provided")
os.Exit(2)
}
if len(masterv) > 1 {
fmt.Fprintf(os.Stderr, "BUG neo/go POC currently supports only 1 master")
os.Exit(2)
}
master := masterv[0]
argv = flags.Args()
if len(argv) < 1 {
flags.Usage()
os.Exit(2)
}
// XXX hack to use existing zodb storage for data
zstor, err := fs1.Open(context.Background(), argv[0]) // XXX context.Background -> ?
if err != nil {
log.Fatal(err)
}
net := neo.NetPlain("tcp") // TODO + TLS; not only "tcp" ?
storSrv := NewStorage(*cluster, master, *bind, net, zstor)
ctx := context.Background()
/*
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.Sleep(3 * time.Second)
cancel()
}()
*/
err = storSrv.Run(ctx)
if err != nil {
log.Fatal(err)
}
}
......@@ -27,5 +27,5 @@ package wks
import (
_ "../../zodb/storage/mem"
_ "../../zodb/storage/fs1"
_ "../../neo" // XXX split into neo/client ?
_ "../../neo/client"
)
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// Package zodbtools provides tools for managing ZODB databases
package zodbtools
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment