simplify remote progress bar as we are using a single instance
This commit is contained in:
parent
d89e1133c3
commit
6d3e36e6ea
|
@ -5,8 +5,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/common/random"
|
|
||||||
|
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,38 +65,27 @@ func (u *Ui) Say(message string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Ui) ProgressBar() packer.ProgressBar {
|
func (u *Ui) ProgressBar() packer.ProgressBar {
|
||||||
var callMeMaybe string
|
if err := u.client.Call("Ui.ProgressBar", new(interface{}), new(interface{})); err != nil {
|
||||||
if err := u.client.Call("Ui.ProgressBar", nil, &callMeMaybe); err != nil {
|
|
||||||
log.Printf("Error in Ui RPC call: %s", err)
|
log.Printf("Error in Ui RPC call: %s", err)
|
||||||
return new(packer.NoopProgressBar)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &RemoteProgressBarClient{
|
|
||||||
id: callMeMaybe,
|
|
||||||
client: u.client,
|
|
||||||
}
|
}
|
||||||
|
return u // Ui is also a progress bar !!
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoteProgressBarClient struct {
|
var _ packer.ProgressBar = new(Ui)
|
||||||
id string // TODO(azr): don't need an id any more since bar is a singleton
|
|
||||||
client *rpc.Client
|
func (pb *Ui) Start(total uint64) {
|
||||||
|
pb.client.Call("Ui.Start", total, new(interface{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ packer.ProgressBar = new(RemoteProgressBarClient)
|
func (pb *Ui) Add(current uint64) {
|
||||||
|
pb.client.Call("Ui.Add", current, new(interface{}))
|
||||||
func (pb *RemoteProgressBarClient) Start(total uint64) {
|
|
||||||
pb.client.Call(pb.id+".Start", total, new(interface{}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *RemoteProgressBarClient) Add(current uint64) {
|
func (pb *Ui) Finish() {
|
||||||
pb.client.Call(pb.id+".Add", current, new(interface{}))
|
pb.client.Call("Ui.Finish", nil, new(interface{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *RemoteProgressBarClient) Finish() {
|
func (pb *Ui) NewProxyReader(r io.Reader) io.Reader {
|
||||||
pb.client.Call(pb.id+".Finish", nil, new(interface{}))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pb *RemoteProgressBarClient) NewProxyReader(r io.Reader) io.Reader {
|
|
||||||
return &packer.ProxyReader{Reader: r, ProgressBar: pb}
|
return &packer.ProxyReader{Reader: r, ProgressBar: pb}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,35 +122,24 @@ func (u *UiServer) Say(message *string, reply *interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UiServer) ProgressBar(_ *string, reply *interface{}) error {
|
func (u *UiServer) ProgressBar(_ *string, reply *interface{}) error {
|
||||||
bar := u.ui.ProgressBar()
|
// No-op for now, this function might be
|
||||||
|
// used in the future if we want to use
|
||||||
callbackName := random.AlphaNum(6)
|
// different progress bars with identifiers.
|
||||||
|
u.ui.ProgressBar()
|
||||||
log.Printf("registering progressbar %s", callbackName)
|
|
||||||
err := u.register(callbackName, &RemoteProgressBarServer{bar})
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("failed to register a new progress bar rpc server, %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*reply = callbackName
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoteProgressBarServer struct {
|
func (pb *UiServer) Finish(_ string, _ *interface{}) error {
|
||||||
pb packer.ProgressBar
|
pb.ui.ProgressBar().Finish()
|
||||||
}
|
|
||||||
|
|
||||||
func (pb *RemoteProgressBarServer) Finish(_ string, _ *interface{}) error {
|
|
||||||
pb.pb.Finish()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *RemoteProgressBarServer) Start(total uint64, _ *interface{}) error {
|
func (pb *UiServer) Start(total uint64, _ *interface{}) error {
|
||||||
pb.pb.Start(total)
|
pb.ui.ProgressBar().Start(total)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *RemoteProgressBarServer) Add(current uint64, _ *interface{}) error {
|
func (pb *UiServer) Add(current uint64, _ *interface{}) error {
|
||||||
pb.pb.Add(current)
|
pb.ui.ProgressBar().Add(current)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue