Пример #1
0
// NewSandbox creates a new transport instance, part of a sandbox network in memory
func NewSandbox() circuit.Transport {
	s.lk.Lock()
	defer s.lk.Unlock()

	l := &listener{
		id: circuit.ChooseWorkerID(),
		ch: make(chan *halfconn),
	}
	l.a = &addr{ID: l.id, l: l}
	s.l[l.id] = l
	return l
}
Пример #2
0
func (c *Config) Spawn(host string, anchors ...string) (circuit.Addr, error) {

	cmd := exec.Command("ssh", host, "sh")

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return nil, err
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return nil, err
	}
	//posix.ForwardStderrBatch(stderr)
	id := circuit.ChooseWorkerID()

	// Forward the stderr of the ssh process to this process' stderr
	posix.ForwardStderr(fmt.Sprintf("%s:kicker/err| ", id), stderr)

	// Start process
	if err := cmd.Start(); err != nil {
		return nil, err
	}
	defer cmd.Wait() /// Make sure that ssh does not remain zombie

	// Feed shell script to execute circuit binary
	bindir, _ := path.Split(c.Binary)
	if bindir == "" {
		panic("binary path not absolute")
	}
	var sh string
	if c.LibPath == "" {
		sh = fmt.Sprintf("cd %s\n%s=%s %s\n", bindir, config.RoleEnv, config.Daemonizer, c.Binary)
	} else {
		sh = fmt.Sprintf(
			"cd %s\nLD_LIBRARY_PATH=%s DYLD_LIBRARY_PATH=%s %s=%s %s\n",
			bindir, c.LibPath, c.LibPath, config.RoleEnv, config.Daemonizer, c.Binary)
	}
	stdin.Write([]byte(sh))

	// Write worker configuration to stdin of running worker process
	wc := &config.WorkerConfig{
		Spark: &config.SparkConfig{
			ID:       id,
			BindAddr: "",
			Host:     host,
			Anchor:   append(anchors, fmt.Sprintf("/host/%s", host)),
		},
		Zookeeper: config.Config.Zookeeper,
		Deploy:    config.Config.Deploy,
	}
	if err := json.NewEncoder(stdin).Encode(wc); err != nil {
		return nil, err
	}

	// Close stdin
	if err = stdin.Close(); err != nil {
		return nil, err
	}

	// Read the first two lines of stdout. They should hold the Port and PID of the runtime process.
	stdoutBuffer := bufio.NewReader(stdout)

	// First line equals PID
	line, err := stdoutBuffer.ReadString('\n')
	if err != nil {
		return nil, err
	}
	line = line[:len(line)-1]
	pid, err := strconv.Atoi(line)
	if err != nil {
		return nil, err
	}

	// Second line equals port
	line, err = stdoutBuffer.ReadString('\n')
	if err != nil {
		return nil, err
	}
	line = line[:len(line)-1]
	port, err := strconv.Atoi(line)
	if err != nil {
		return nil, err
	}

	addr, err := transport.NewAddr(id, pid, fmt.Sprintf("%s:%d", host, port))
	if err != nil {
		return nil, err
	}

	return addr.(*transport.Addr), nil
}
Пример #3
0
// See the License for the specific language governing permissions and
// limitations under the License.

package config

import "circuit/use/circuit"

// SparkConfig captures a few worker startup parameters that can be configured on each execution
type SparkConfig struct {
	// ID is the ID of the worker instance
	ID circuit.WorkerID

	// BindAddr is the network address the worker will listen to for incoming connections
	BindAddr string

	// Host is the host name of the hosting machine
	Host string

	// Anchor is the set of anchor directories that the worker registers with
	Anchor []string
}

// DefaultSpark is the default configuration used for workers started from the command line, which
// are often not intended to be contacted back from other workers
var DefaultSpark = &SparkConfig{
	ID:       circuit.ChooseWorkerID(),
	BindAddr: "",         // Don't accept incoming circuit calls from other workers
	Host:     "",         // "
	Anchor:   []string{}, // Don't register within the anchor file system
}