Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
5aebe7b1
Commit
5aebe7b1
authored
May 04, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: BuilderFactory remote
parent
8a78d4d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
0 deletions
+109
-0
packer/rpc/builder_factory.go
packer/rpc/builder_factory.go
+53
-0
packer/rpc/builder_factory_test.go
packer/rpc/builder_factory_test.go
+52
-0
packer/rpc/server.go
packer/rpc/server.go
+4
-0
No files found.
packer/rpc/builder_factory.go
0 → 100644
View file @
5aebe7b1
package
rpc
import
(
"github.com/mitchellh/packer/packer"
"net/rpc"
"time"
)
// An implementation of packer.BuilderFactory where the factory is actually
// executed over an RPC connection.
type
BuilderFactory
struct
{
client
*
rpc
.
Client
}
// BuilderFactoryServer wraps a packer.BuilderFactory and makes it exportable
// as part of a Golang RPC server.
type
BuilderFactoryServer
struct
{
bf
packer
.
BuilderFactory
}
type
BuilderFactoryCreateArgs
struct
{
Name
string
}
func
(
b
*
BuilderFactory
)
CreateBuilder
(
name
string
)
packer
.
Builder
{
var
reply
string
b
.
client
.
Call
(
"BuilderFactory.CreateBuilder"
,
&
BuilderFactoryCreateArgs
{
name
},
&
reply
)
// TODO: error handling
client
,
_
:=
rpc
.
Dial
(
"tcp"
,
reply
)
return
&
Builder
{
client
}
}
func
(
b
*
BuilderFactoryServer
)
CreateBuilder
(
args
*
BuilderFactoryCreateArgs
,
reply
*
string
)
error
{
// Get the actual builder response
builder
:=
b
.
bf
.
CreateBuilder
(
args
.
Name
)
// Now we wrap that back up into a server, and send it on backwards.
server
:=
NewServer
()
server
.
RegisterBuilder
(
builder
)
server
.
Start
()
// Start a timer where we'll quit the server after some number of seconds.
go
func
()
{
time
.
Sleep
(
30
*
time
.
Second
)
server
.
Stop
()
}()
// Set the reply to the address of the sever
*
reply
=
server
.
Address
()
return
nil
}
packer/rpc/builder_factory_test.go
0 → 100644
View file @
5aebe7b1
package
rpc
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"testing"
)
type
testBuilderFactory
struct
{
createCalled
bool
createName
string
}
func
(
b
*
testBuilderFactory
)
CreateBuilder
(
name
string
)
packer
.
Builder
{
b
.
createCalled
=
true
b
.
createName
=
name
return
&
testBuilder
{}
}
func
TestBuilderFactoryRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
b
:=
new
(
testBuilderFactory
)
// Start the server
server
:=
NewServer
()
server
.
RegisterBuilderFactory
(
b
)
server
.
Start
()
defer
server
.
Stop
()
// Create the client over RPC and run some methods to verify it works
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
server
.
Address
())
assert
.
Nil
(
err
,
"should be able to connect"
)
// Test Create
name
:=
"foo"
bClient
:=
&
BuilderFactory
{
client
}
_
=
bClient
.
CreateBuilder
(
name
)
assert
.
True
(
b
.
createCalled
,
"create should be called"
)
assert
.
Equal
(
b
.
createName
,
"foo"
,
"name should be foo"
)
}
func
TestBuilderFactory_ImplementsBuilderFactory
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
realVar
packer
.
BuilderFactory
b
:=
&
BuilderFactory
{
nil
}
assert
.
Implementor
(
b
,
&
realVar
,
"should be a BuilderFactory"
)
}
packer/rpc/server.go
View file @
5aebe7b1
...
...
@@ -37,6 +37,10 @@ func (s *Server) RegisterBuilder(b packer.Builder) {
s
.
server
.
RegisterName
(
"Builder"
,
&
BuilderServer
{
b
})
}
func
(
s
*
Server
)
RegisterBuilderFactory
(
b
packer
.
BuilderFactory
)
{
s
.
server
.
RegisterName
(
"BuilderFactory"
,
&
BuilderFactoryServer
{
b
})
}
func
(
s
*
Server
)
RegisterUi
(
ui
packer
.
Ui
)
{
s
.
server
.
RegisterName
(
"Ui"
,
&
UiServer
{
ui
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment