Commit 3a5f3a45 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent cc8de1a8
......@@ -47,7 +47,7 @@ type NEOSrv interface {
// XXX kill or restore?
//ClusterName() string // name of the cluster
//MasterAddr() string // address of the master
ZUrl() string // zurl to access this NEO server
URL() string // zurl to access this NEO server
Bugs() []string // list of known server bugs
}
......@@ -60,7 +60,6 @@ type NEOSrvOptions struct {
// npartition
// nreplica
SSL bool // whether to use SSL for node-node exchange
}
......@@ -89,7 +88,6 @@ func (_ *NEOPySrv) Bugs() []string {
}
// StartNEOPySrv starts NEO/py server specified by options.
// XXX dup wrt zeo?
func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
workdir := opt.workdir
defer xerr.Contextf(&err, "start neo/py %s/%s", workdir, opt.name)
......@@ -106,19 +104,13 @@ func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
}
n := &NEOPySrv{opt: opt, cancel: cancel, done: make(chan struct{})}
if opt.SSL {
npytests := "../../neo/tests/"
n.CA = npytests + "ca.crt"
n.Cert = npytests + "node.crt"
n.Key = npytests + "node.key"
}
// XXX $PYTHONPATH to top, so that `import neo` works?
n.pysrv = xexec.Command("./py/runneo.py", workdir, opt.name)
if opt.SSL {
n.pysrv.Args = append(n.pysrv.Args, "ca=" +n.CA)
n.pysrv.Args = append(n.pysrv.Args, "cert="+n.Cert)
n.pysrv.Args = append(n.pysrv.Args, "key=" +n.Key)
n.pysrv.Args = append(n.pysrv.Args, "ca=" +opt.CA())
n.pysrv.Args = append(n.pysrv.Args, "cert="+opt.Cert())
n.pysrv.Args = append(n.pysrv.Args, "key=" +opt.Key())
}
// $TEMP -> workdir (else NEO/py creates another one for e.g. coverage)
n.pysrv.Env = append(os.Environ(), "TEMP="+workdir)
......@@ -179,20 +171,8 @@ func (n *NEOPySrv) MasterAddr() string {
return n.masterAddr
}
func (n *NEOPySrv) ZUrl() string {
zurl := ""
if !n.opt.SSL {
zurl = "neo://"
} else {
zurl = "neos://"
zurl += "ca=" + url.QueryEscape(n.CA) +";"
zurl += "cert=" + url.QueryEscape(n.Cert) +";"
zurl += "key=" + url.QueryEscape(n.Key)
zurl += "@"
}
zurl += fmt.Sprintf("%s/%s", n.MasterAddr(), n.ClusterName())
return zurl
func (n *NEOPySrv) URL() string {
return fmt.Sprintf("%s%s/%s", n.opt.URLPrefix(), n.MasterAddr(), n.ClusterName())
}
func (n *NEOPySrv) Close() (err error) {
......@@ -246,7 +226,7 @@ func StartNEOGoSrv(opt NEOSrvOptions) (_ *NEOGoSrv, err error) {
// FIXME tune glog to write logs into workdir
net := xnet.NetPlain("tcp") // FIXME
net := xnet.NetPlain("tcp") // FIXME TLS on SSL
n.Ml, err = net.Listen(ctx, ""); if err != nil { return nil, err }
n.Sl, err = net.Listen(ctx, ""); if err != nil { return nil, err }
......@@ -261,7 +241,7 @@ func StartNEOGoSrv(opt NEOSrvOptions) (_ *NEOGoSrv, err error) {
if err != nil {
return nil, err
}
n.S = NewStorage(opt.name, n.Ml.Addr().String(), net, n.Sback)
n.S = NewStorage(opt.name, n.MasterAddr(), net, n.Sback)
serveWG.Go(func(ctx context.Context) error {
return n.S.Run(ctx, n.Sl)
})
......@@ -274,10 +254,11 @@ func StartNEOGoSrv(opt NEOSrvOptions) (_ *NEOGoSrv, err error) {
}
err = n.M.Start()
if err != nil {
if !strings.HasSuffix(err.Error(), "start: cluster is non-operational") { // XXX
return nil, err
}
if err == nil {
break
}
if !strings.HasSuffix(err.Error(), "start: cluster is non-operational") { // XXX
return nil, err
}
time.Sleep(10*time.Millisecond)
......@@ -315,8 +296,48 @@ func (n *NEOGoSrv) Close() (err error) {
return err
}
func (n *NEOGoSrv) ZUrl() string {
panic("TODO")
func (n *NEOGoSrv) MasterAddr() string {
return n.Ml.Addr().String()
}
func (n *NEOGoSrv) URL() string {
return fmt.Sprintf("%s%s/%s", n.opt.URLPrefix(), n.MasterAddr(), n.opt.name)
}
// ----------------
const npytests = "../../neo/tests/"
// CA/Cert/Key files to use if opt.SSL=y
func (opt NEOSrvOptions) CA() string {
if !opt.SSL { return "" }
return npytests + "ca.crt"
}
func (opt NEOSrvOptions) Cert() string {
if !opt.SSL { return "" }
return npytests + "node.crt"
}
func (opt NEOSrvOptions) Key() string {
if !opt.SSL { return "" }
return npytests + "node.key"
}
// URLPrefix returns start of URL for a NEO server started with opt.
// e.g. neo:// or neos://ca=1;cert=2;key=3@
// To be come complete returned URL has to be appended with host and path parts.
func (opt NEOSrvOptions) URLPrefix() string {
zurl := ""
if !opt.SSL {
zurl = "neo://"
} else {
zurl = "neos://"
zurl += "ca=" + url.QueryEscape(opt.CA()) +";"
zurl += "cert=" + url.QueryEscape(opt.Cert()) +";"
zurl += "key=" + url.QueryEscape(opt.Key())
zurl += "@"
}
return zurl
}
......@@ -443,7 +464,7 @@ func withNEO(t *testing.T, f func(t *testing.T, nsrv NEOSrv, ndrv *Client), optv
withNEOSrv(t, func(t *testing.T, nsrv NEOSrv) {
t.Helper()
X := xtesting.FatalIf(t)
ndrv, _, err := neoOpen(nsrv.ZUrl(),
ndrv, _, err := neoOpen(nsrv.URL(),
&zodb.DriverOptions{ReadOnly: true}); X(err)
defer func() {
err := ndrv.Close(); X(err)
......@@ -479,7 +500,7 @@ func TestLoad(t *testing.T) {
func TestWatch(t *testing.T) {
withNEOSrv(t, func(t *testing.T, nsrv NEOSrv) {
xtesting.DrvTestWatch(t, nsrv.ZUrl(), openClientByURL)
xtesting.DrvTestWatch(t, nsrv.URL(), openClientByURL)
})
}
......
......@@ -72,7 +72,6 @@ type ZEOPyOptions struct {
}
// StartZEOPySrv starts ZEO/py server for FileStorage database located at fs1path.
// XXX dup wrt neo?
func StartZEOPySrv(fs1path string, opt ZEOPyOptions) (_ *ZEOPySrv, err error) {
defer xerr.Contextf(&err, "startzeo %s", fs1path)
......
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