packer/rpc: make newXWithMuxConn private
This commit is contained in:
parent
f06cd56e72
commit
74f018df2b
|
@ -40,7 +40,7 @@ func (b *build) Prepare(v map[string]string) ([]string, error) {
|
|||
|
||||
func (b *build) Run(ui packer.Ui, cache packer.Cache) ([]packer.Artifact, error) {
|
||||
nextId := b.mux.NextId()
|
||||
server := NewServerWithMux(b.mux, nextId)
|
||||
server := newServerWithMux(b.mux, nextId)
|
||||
server.RegisterCache(cache)
|
||||
server.RegisterUi(ui)
|
||||
go server.Serve()
|
||||
|
@ -52,7 +52,7 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) ([]packer.Artifact, error)
|
|||
|
||||
artifacts := make([]packer.Artifact, len(result))
|
||||
for i, streamId := range result {
|
||||
client, err := NewClientWithMux(b.mux, streamId)
|
||||
client, err := newClientWithMux(b.mux, streamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func (b *BuildServer) Prepare(v map[string]string, resp *BuildPrepareResponse) e
|
|||
}
|
||||
|
||||
func (b *BuildServer) Run(streamId uint32, reply *[]uint32) error {
|
||||
client, err := NewClientWithMux(b.mux, streamId)
|
||||
client, err := newClientWithMux(b.mux, streamId)
|
||||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ func (b *BuildServer) Run(streamId uint32, reply *[]uint32) error {
|
|||
*reply = make([]uint32, len(artifacts))
|
||||
for i, artifact := range artifacts {
|
||||
streamId := b.mux.NextId()
|
||||
server := NewServerWithMux(b.mux, streamId)
|
||||
server := newServerWithMux(b.mux, streamId)
|
||||
server.RegisterArtifact(artifact)
|
||||
go server.Serve()
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ func (b *builder) Prepare(config ...interface{}) ([]string, error) {
|
|||
|
||||
func (b *builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||
nextId := b.mux.NextId()
|
||||
server := NewServerWithMux(b.mux, nextId)
|
||||
server := newServerWithMux(b.mux, nextId)
|
||||
server.RegisterCache(cache)
|
||||
server.RegisterHook(hook)
|
||||
server.RegisterUi(ui)
|
||||
|
@ -56,7 +56,7 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
client, err := NewClientWithMux(b.mux, responseId)
|
||||
client, err := newClientWithMux(b.mux, responseId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *BuilderPrepareR
|
|||
}
|
||||
|
||||
func (b *BuilderServer) Run(streamId uint32, reply *uint32) error {
|
||||
client, err := NewClientWithMux(b.mux, streamId)
|
||||
client, err := newClientWithMux(b.mux, streamId)
|
||||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func (b *BuilderServer) Run(streamId uint32, reply *uint32) error {
|
|||
*reply = 0
|
||||
if artifact != nil {
|
||||
streamId = b.mux.NextId()
|
||||
server := NewServerWithMux(b.mux, streamId)
|
||||
server := newServerWithMux(b.mux, streamId)
|
||||
server.RegisterArtifact(artifact)
|
||||
go server.Serve()
|
||||
*reply = streamId
|
||||
|
|
|
@ -17,7 +17,7 @@ type Client struct {
|
|||
}
|
||||
|
||||
func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
|
||||
result, err := NewClientWithMux(NewMuxConn(rwc, 0), 0)
|
||||
result, err := newClientWithMux(NewMuxConn(rwc, 0), 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
|
|||
return result, err
|
||||
}
|
||||
|
||||
func NewClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) {
|
||||
func newClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) {
|
||||
clientConn, err := mux.Dial(streamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -37,7 +37,7 @@ func (c *command) Help() (result string) {
|
|||
|
||||
func (c *command) Run(env packer.Environment, args []string) (result int) {
|
||||
nextId := c.mux.NextId()
|
||||
server := NewServerWithMux(c.mux, nextId)
|
||||
server := newServerWithMux(c.mux, nextId)
|
||||
server.RegisterEnvironment(env)
|
||||
go server.Serve()
|
||||
|
||||
|
@ -68,7 +68,7 @@ func (c *CommandServer) Help(args *interface{}, reply *string) error {
|
|||
}
|
||||
|
||||
func (c *CommandServer) Run(args *CommandRunArgs, reply *int) error {
|
||||
client, err := NewClientWithMux(c.mux, args.StreamId)
|
||||
client, err := newClientWithMux(c.mux, args.StreamId)
|
||||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func (e *Environment) Builder(name string) (b packer.Builder, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
client, err := NewClientWithMux(e.mux, streamId)
|
||||
client, err := newClientWithMux(e.mux, streamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func (e *Environment) Cache() packer.Cache {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
client, err := NewClientWithMux(e.mux, streamId)
|
||||
client, err := newClientWithMux(e.mux, streamId)
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Error getting cache client: %s", err)
|
||||
return nil
|
||||
|
@ -66,7 +66,7 @@ func (e *Environment) Hook(name string) (h packer.Hook, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
client, err := NewClientWithMux(e.mux, streamId)
|
||||
client, err := newClientWithMux(e.mux, streamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (e *Environment) PostProcessor(name string) (p packer.PostProcessor, err er
|
|||
return
|
||||
}
|
||||
|
||||
client, err := NewClientWithMux(e.mux, streamId)
|
||||
client, err := newClientWithMux(e.mux, streamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ func (e *Environment) Provisioner(name string) (p packer.Provisioner, err error)
|
|||
return
|
||||
}
|
||||
|
||||
client, err := NewClientWithMux(e.mux, streamId)
|
||||
client, err := newClientWithMux(e.mux, streamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ func (e *Environment) Ui() packer.Ui {
|
|||
var streamId uint32
|
||||
e.client.Call("Environment.Ui", new(interface{}), &streamId)
|
||||
|
||||
client, err := NewClientWithMux(e.mux, streamId)
|
||||
client, err := newClientWithMux(e.mux, streamId)
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Error connecting to Ui: %s", err)
|
||||
return nil
|
||||
|
@ -122,7 +122,7 @@ func (e *EnvironmentServer) Builder(name string, reply *uint32) error {
|
|||
}
|
||||
|
||||
*reply = e.mux.NextId()
|
||||
server := NewServerWithMux(e.mux, *reply)
|
||||
server := newServerWithMux(e.mux, *reply)
|
||||
server.RegisterBuilder(builder)
|
||||
go server.Serve()
|
||||
return nil
|
||||
|
@ -132,7 +132,7 @@ func (e *EnvironmentServer) Cache(args *interface{}, reply *uint32) error {
|
|||
cache := e.env.Cache()
|
||||
|
||||
*reply = e.mux.NextId()
|
||||
server := NewServerWithMux(e.mux, *reply)
|
||||
server := newServerWithMux(e.mux, *reply)
|
||||
server.RegisterCache(cache)
|
||||
go server.Serve()
|
||||
return nil
|
||||
|
@ -150,7 +150,7 @@ func (e *EnvironmentServer) Hook(name string, reply *uint32) error {
|
|||
}
|
||||
|
||||
*reply = e.mux.NextId()
|
||||
server := NewServerWithMux(e.mux, *reply)
|
||||
server := newServerWithMux(e.mux, *reply)
|
||||
server.RegisterHook(hook)
|
||||
go server.Serve()
|
||||
return nil
|
||||
|
@ -163,7 +163,7 @@ func (e *EnvironmentServer) PostProcessor(name string, reply *uint32) error {
|
|||
}
|
||||
|
||||
*reply = e.mux.NextId()
|
||||
server := NewServerWithMux(e.mux, *reply)
|
||||
server := newServerWithMux(e.mux, *reply)
|
||||
server.RegisterPostProcessor(pp)
|
||||
go server.Serve()
|
||||
return nil
|
||||
|
@ -176,7 +176,7 @@ func (e *EnvironmentServer) Provisioner(name string, reply *uint32) error {
|
|||
}
|
||||
|
||||
*reply = e.mux.NextId()
|
||||
server := NewServerWithMux(e.mux, *reply)
|
||||
server := newServerWithMux(e.mux, *reply)
|
||||
server.RegisterProvisioner(prov)
|
||||
go server.Serve()
|
||||
return nil
|
||||
|
@ -186,7 +186,7 @@ func (e *EnvironmentServer) Ui(args *interface{}, reply *uint32) error {
|
|||
ui := e.env.Ui()
|
||||
|
||||
*reply = e.mux.NextId()
|
||||
server := NewServerWithMux(e.mux, *reply)
|
||||
server := newServerWithMux(e.mux, *reply)
|
||||
server.RegisterUi(ui)
|
||||
go server.Serve()
|
||||
return nil
|
||||
|
|
|
@ -28,7 +28,7 @@ type HookRunArgs struct {
|
|||
|
||||
func (h *hook) Run(name string, ui packer.Ui, comm packer.Communicator, data interface{}) error {
|
||||
nextId := h.mux.NextId()
|
||||
server := NewServerWithMux(h.mux, nextId)
|
||||
server := newServerWithMux(h.mux, nextId)
|
||||
server.RegisterCommunicator(comm)
|
||||
server.RegisterUi(ui)
|
||||
go server.Serve()
|
||||
|
@ -50,7 +50,7 @@ func (h *hook) Cancel() {
|
|||
}
|
||||
|
||||
func (h *HookServer) Run(args *HookRunArgs, reply *interface{}) error {
|
||||
client, err := NewClientWithMux(h.mux, args.StreamId)
|
||||
client, err := newClientWithMux(h.mux, args.StreamId)
|
||||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ func (p *postProcessor) Configure(raw ...interface{}) (err error) {
|
|||
|
||||
func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, bool, error) {
|
||||
nextId := p.mux.NextId()
|
||||
server := NewServerWithMux(p.mux, nextId)
|
||||
server := newServerWithMux(p.mux, nextId)
|
||||
server.RegisterArtifact(a)
|
||||
server.RegisterUi(ui)
|
||||
go server.Serve()
|
||||
|
@ -59,7 +59,7 @@ func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Art
|
|||
return nil, false, nil
|
||||
}
|
||||
|
||||
client, err := NewClientWithMux(p.mux, response.StreamId)
|
||||
client, err := newClientWithMux(p.mux, response.StreamId)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func (p *PostProcessorServer) Configure(args *PostProcessorConfigureArgs, reply
|
|||
}
|
||||
|
||||
func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorProcessResponse) error {
|
||||
client, err := NewClientWithMux(p.mux, streamId)
|
||||
client, err := newClientWithMux(p.mux, streamId)
|
||||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorP
|
|||
artifactResult, keep, err := p.p.PostProcess(client.Ui(), client.Artifact())
|
||||
if err == nil && artifactResult != nil {
|
||||
streamId = p.mux.NextId()
|
||||
server := NewServerWithMux(p.mux, streamId)
|
||||
server := newServerWithMux(p.mux, streamId)
|
||||
server.RegisterArtifact(artifactResult)
|
||||
go server.Serve()
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func (p *provisioner) Prepare(configs ...interface{}) (err error) {
|
|||
|
||||
func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||
nextId := p.mux.NextId()
|
||||
server := NewServerWithMux(p.mux, nextId)
|
||||
server := newServerWithMux(p.mux, nextId)
|
||||
server.RegisterCommunicator(comm)
|
||||
server.RegisterUi(ui)
|
||||
go server.Serve()
|
||||
|
@ -60,7 +60,7 @@ func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *error)
|
|||
}
|
||||
|
||||
func (p *ProvisionerServer) Provision(streamId uint32, reply *interface{}) error {
|
||||
client, err := NewClientWithMux(p.mux, streamId)
|
||||
client, err := newClientWithMux(p.mux, streamId)
|
||||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
|
|
|
@ -36,12 +36,12 @@ type Server struct {
|
|||
|
||||
// NewServer returns a new Packer RPC server.
|
||||
func NewServer(conn io.ReadWriteCloser) *Server {
|
||||
result := NewServerWithMux(NewMuxConn(conn, 1), 0)
|
||||
result := newServerWithMux(NewMuxConn(conn, 1), 0)
|
||||
result.closeMux = true
|
||||
return result
|
||||
}
|
||||
|
||||
func NewServerWithMux(mux *MuxConn, streamId uint32) *Server {
|
||||
func newServerWithMux(mux *MuxConn, streamId uint32) *Server {
|
||||
return &Server{
|
||||
mux: mux,
|
||||
streamId: streamId,
|
||||
|
|
Loading…
Reference in New Issue