rpc: implement provisioner update
This commit is contained in:
parent
8b129babe5
commit
02d01141ca
|
@ -101,6 +101,7 @@ func (c *Client) ResourceProvisioner() (terraform.ResourceProvisioner, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ResourceProvisioner{
|
return &ResourceProvisioner{
|
||||||
|
Broker: c.broker,
|
||||||
Client: rpc.NewClient(conn),
|
Client: rpc.NewClient(conn),
|
||||||
Name: "ResourceProvisioner",
|
Name: "ResourceProvisioner",
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -60,9 +60,10 @@ func TestClient_ResourceProvisioner(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply
|
// Apply
|
||||||
|
output := &terraform.MockUIOutput{}
|
||||||
state := &terraform.InstanceState{}
|
state := &terraform.InstanceState{}
|
||||||
conf := &terraform.ResourceConfig{}
|
conf := &terraform.ResourceConfig{}
|
||||||
err = provisioner.Apply(state, conf)
|
err = provisioner.Apply(output, state, conf)
|
||||||
if !p.ApplyCalled {
|
if !p.ApplyCalled {
|
||||||
t.Fatal("apply should be called")
|
t.Fatal("apply should be called")
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
// ResourceProvisioner is an implementation of terraform.ResourceProvisioner
|
// ResourceProvisioner is an implementation of terraform.ResourceProvisioner
|
||||||
// that communicates over RPC.
|
// that communicates over RPC.
|
||||||
type ResourceProvisioner struct {
|
type ResourceProvisioner struct {
|
||||||
|
Broker *muxBroker
|
||||||
Client *rpc.Client
|
Client *rpc.Client
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
@ -36,12 +37,19 @@ func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) ([]string, [
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ResourceProvisioner) Apply(
|
func (p *ResourceProvisioner) Apply(
|
||||||
|
output terraform.UIOutput,
|
||||||
s *terraform.InstanceState,
|
s *terraform.InstanceState,
|
||||||
c *terraform.ResourceConfig) error {
|
c *terraform.ResourceConfig) error {
|
||||||
|
id := p.Broker.NextId()
|
||||||
|
go acceptAndServe(p.Broker, id, "UIOutput", &UIOutputServer{
|
||||||
|
UIOutput: output,
|
||||||
|
})
|
||||||
|
|
||||||
var resp ResourceProvisionerApplyResponse
|
var resp ResourceProvisionerApplyResponse
|
||||||
args := &ResourceProvisionerApplyArgs{
|
args := &ResourceProvisionerApplyArgs{
|
||||||
State: s,
|
OutputId: id,
|
||||||
Config: c,
|
State: s,
|
||||||
|
Config: c,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := p.Client.Call(p.Name+".Apply", args, &resp)
|
err := p.Client.Call(p.Name+".Apply", args, &resp)
|
||||||
|
@ -65,8 +73,9 @@ type ResourceProvisionerValidateResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceProvisionerApplyArgs struct {
|
type ResourceProvisionerApplyArgs struct {
|
||||||
State *terraform.InstanceState
|
OutputId uint32
|
||||||
Config *terraform.ResourceConfig
|
State *terraform.InstanceState
|
||||||
|
Config *terraform.ResourceConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceProvisionerApplyResponse struct {
|
type ResourceProvisionerApplyResponse struct {
|
||||||
|
@ -76,13 +85,29 @@ type ResourceProvisionerApplyResponse struct {
|
||||||
// ResourceProvisionerServer is a net/rpc compatible structure for serving
|
// ResourceProvisionerServer is a net/rpc compatible structure for serving
|
||||||
// a ResourceProvisioner. This should not be used directly.
|
// a ResourceProvisioner. This should not be used directly.
|
||||||
type ResourceProvisionerServer struct {
|
type ResourceProvisionerServer struct {
|
||||||
|
Broker *muxBroker
|
||||||
Provisioner terraform.ResourceProvisioner
|
Provisioner terraform.ResourceProvisioner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ResourceProvisionerServer) Apply(
|
func (s *ResourceProvisionerServer) Apply(
|
||||||
args *ResourceProvisionerApplyArgs,
|
args *ResourceProvisionerApplyArgs,
|
||||||
result *ResourceProvisionerApplyResponse) error {
|
result *ResourceProvisionerApplyResponse) error {
|
||||||
err := s.Provisioner.Apply(args.State, args.Config)
|
conn, err := s.Broker.Dial(args.OutputId)
|
||||||
|
if err != nil {
|
||||||
|
*result = ResourceProvisionerApplyResponse{
|
||||||
|
Error: NewBasicError(err),
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
client := rpc.NewClient(conn)
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
output := &UIOutput{
|
||||||
|
Client: client,
|
||||||
|
Name: "UIOutput",
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.Provisioner.Apply(output, args.State, args.Config)
|
||||||
*result = ResourceProvisionerApplyResponse{
|
*result = ResourceProvisionerApplyResponse{
|
||||||
Error: NewBasicError(err),
|
Error: NewBasicError(err),
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,18 +13,21 @@ func TestResourceProvisioner_impl(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResourceProvisioner_apply(t *testing.T) {
|
func TestResourceProvisioner_apply(t *testing.T) {
|
||||||
p := new(terraform.MockResourceProvisioner)
|
client, server := testNewClientServer(t)
|
||||||
client, server := testClientServer(t)
|
defer client.Close()
|
||||||
name, err := Register(server, p)
|
|
||||||
|
p := server.ProvisionerFunc().(*terraform.MockResourceProvisioner)
|
||||||
|
|
||||||
|
provisioner, err := client.ResourceProvisioner()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
provisioner := &ResourceProvisioner{Client: client, Name: name}
|
|
||||||
|
|
||||||
// Apply
|
// Apply
|
||||||
|
output := &terraform.MockUIOutput{}
|
||||||
state := &terraform.InstanceState{}
|
state := &terraform.InstanceState{}
|
||||||
conf := &terraform.ResourceConfig{}
|
conf := &terraform.ResourceConfig{}
|
||||||
err = provisioner.Apply(state, conf)
|
err = provisioner.Apply(output, state, conf)
|
||||||
if !p.ApplyCalled {
|
if !p.ApplyCalled {
|
||||||
t.Fatal("apply should be called")
|
t.Fatal("apply should be called")
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ func (d *dispenseServer) ResourceProvisioner(
|
||||||
}
|
}
|
||||||
|
|
||||||
serve(conn, "ResourceProvisioner", &ResourceProvisionerServer{
|
serve(conn, "ResourceProvisioner", &ResourceProvisionerServer{
|
||||||
|
Broker: d.broker,
|
||||||
Provisioner: d.ProvisionerFunc(),
|
Provisioner: d.ProvisionerFunc(),
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue