mirror of https://github.com/etcd-io/dbtester.git
agent: separate etcd,cetcd,zetcd
This commit is contained in:
parent
3baa50e015
commit
0a6f487393
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2017 CoreOS, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/dbtester/agent/agentpb"
|
||||
)
|
||||
|
||||
// startCetcd starts cetcd. This assumes that etcd is already started.
|
||||
func startCetcd(fs *flags, t *transporterServer, req *agentpb.Request) (*exec.Cmd, error) {
|
||||
if !exist(fs.cetcdExec) {
|
||||
return nil, fmt.Errorf("cetcd binary %q does not exist", globalFlags.cetcdExec)
|
||||
}
|
||||
peerIPs := strings.Split(req.PeerIPString, "___")
|
||||
clientURLs := make([]string, len(peerIPs))
|
||||
for i, u := range peerIPs {
|
||||
clientURLs[i] = fmt.Sprintf("http://%s:2379", u)
|
||||
}
|
||||
|
||||
flags := []string{
|
||||
// "-consuladdr", "0.0.0.0:8500",
|
||||
"-consuladdr", fmt.Sprintf("%s:8500", peerIPs[t.req.ServerIndex]),
|
||||
"-etcd", clientURLs[t.req.ServerIndex], // etcd endpoint
|
||||
}
|
||||
flagString := strings.Join(flags, " ")
|
||||
|
||||
cmd := exec.Command(fs.cetcdExec, flags...)
|
||||
cmd.Stdout = t.proxyDatabaseLogfile
|
||||
cmd.Stderr = t.proxyDatabaseLogfile
|
||||
cs := fmt.Sprintf("%s %s", cmd.Path, flagString)
|
||||
|
||||
plog.Infof("starting database %q", cs)
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.proxyCmd = cmd
|
||||
t.proxyPid = int64(cmd.Process.Pid)
|
||||
plog.Infof("started database %q (PID: %d)", cs, t.pid)
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright 2017 CoreOS, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/dbtester/agent/agentpb"
|
||||
)
|
||||
|
||||
// startEtcd starts etcd v2 and v3.
|
||||
func startEtcd(fs *flags, t *transporterServer, req *agentpb.Request) (*exec.Cmd, error) {
|
||||
if err := os.RemoveAll(fs.etcdDataDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exist(fs.etcdExec) {
|
||||
return nil, fmt.Errorf("etcd binary %q does not exist", globalFlags.etcdExec)
|
||||
}
|
||||
peerIPs := strings.Split(req.PeerIPString, "___")
|
||||
|
||||
names := make([]string, len(peerIPs))
|
||||
clientURLs := make([]string, len(peerIPs))
|
||||
peerURLs := make([]string, len(peerIPs))
|
||||
members := make([]string, len(peerIPs))
|
||||
for i, u := range peerIPs {
|
||||
names[i] = fmt.Sprintf("etcd-%d", i+1)
|
||||
clientURLs[i] = fmt.Sprintf("http://%s:2379", u)
|
||||
peerURLs[i] = fmt.Sprintf("http://%s:2380", u)
|
||||
members[i] = fmt.Sprintf("%s=%s", names[i], peerURLs[i])
|
||||
}
|
||||
|
||||
flags := []string{
|
||||
"--name", names[req.ServerIndex],
|
||||
"--data-dir", fs.etcdDataDir,
|
||||
|
||||
"--listen-client-urls", clientURLs[req.ServerIndex],
|
||||
"--advertise-client-urls", clientURLs[req.ServerIndex],
|
||||
|
||||
"--listen-peer-urls", peerURLs[req.ServerIndex],
|
||||
"--initial-advertise-peer-urls", peerURLs[req.ServerIndex],
|
||||
|
||||
"--initial-cluster-token", "dbtester-etcd-token",
|
||||
"--initial-cluster", strings.Join(members, ","),
|
||||
"--initial-cluster-state", "new",
|
||||
}
|
||||
flagString := strings.Join(flags, " ")
|
||||
|
||||
cmd := exec.Command(fs.etcdExec, flags...)
|
||||
cmd.Stdout = t.databaseLogFile
|
||||
cmd.Stderr = t.databaseLogFile
|
||||
cs := fmt.Sprintf("%s %s", cmd.Path, flagString)
|
||||
|
||||
plog.Infof("starting database %q", cs)
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.cmd = cmd
|
||||
t.pid = int64(cmd.Process.Pid)
|
||||
plog.Infof("started database %q (PID: %d)", cs, t.pid)
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2017 CoreOS, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/dbtester/agent/agentpb"
|
||||
)
|
||||
|
||||
// startZetcd starts zetcd. This assumes that etcd is already started.
|
||||
func startZetcd(fs *flags, t *transporterServer, req *agentpb.Request) (*exec.Cmd, error) {
|
||||
if !exist(fs.zetcdExec) {
|
||||
return nil, fmt.Errorf("zetcd binary %q does not exist", globalFlags.zetcdExec)
|
||||
}
|
||||
peerIPs := strings.Split(req.PeerIPString, "___")
|
||||
clientURLs := make([]string, len(peerIPs))
|
||||
for i, u := range peerIPs {
|
||||
clientURLs[i] = fmt.Sprintf("http://%s:2379", u)
|
||||
}
|
||||
|
||||
flags := []string{
|
||||
// "-zkaddr", "0.0.0.0:2181",
|
||||
"-zkaddr", fmt.Sprintf("%s:2181", peerIPs[t.req.ServerIndex]),
|
||||
"-endpoint", clientURLs[t.req.ServerIndex],
|
||||
}
|
||||
flagString := strings.Join(flags, " ")
|
||||
|
||||
cmd := exec.Command(fs.zetcdExec, flags...)
|
||||
cmd.Stdout = t.proxyDatabaseLogfile
|
||||
cmd.Stderr = t.proxyDatabaseLogfile
|
||||
cs := fmt.Sprintf("%s %s", cmd.Path, flagString)
|
||||
|
||||
plog.Infof("starting database %q", cs)
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.proxyCmd = cmd
|
||||
t.proxyPid = int64(cmd.Process.Pid)
|
||||
plog.Infof("started database %q (PID: %d)", cs, t.pid)
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
Loading…
Reference in New Issue