Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ coverage:

tutorial-test: binaries
@echo "+ $@"
./scripts/tutorial-test
./scripts/tutorial-test2

test-full:
@echo "+ $@"
Expand Down
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ machine:
GOPATH: "$HOME/.go_workspace"
WORKDIR: "$GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
DOCKER_RM: "false"
SKIP_CLEANUP: "true"

dependencies:
pre:
Expand Down
23 changes: 14 additions & 9 deletions pkg/launch/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ import (

var errNoConfig = errors.New("no-counfig")

// ExecRule encapsulates what's required to exec a plugin
type ExecRule struct {
// Exec is the name of the exec to use to start the plugin
Exec string
// Properties is the properties for the executor
Properties *Config
}

// Rule provides the instructions on starting the plugin
type Rule struct {

// Plugin is the name of the plugin
Plugin string

// Exec is the name of the exec to use to start the plugin
Exec string

// Launch is encoded form of the rule on how to start/exec the process
Launch *Config
// Launch is the rule for starting / launching the plugin.
Launch ExecRule
}

// Monitor runs continuously receiving requests to start a plugin.
Expand All @@ -39,7 +44,7 @@ func NewMonitor(l Exec, rules []Rule) *Monitor {
m := map[string]Rule{}
// index by name of plugin
for _, r := range rules {
if r.Exec == l.Name() {
if r.Launch.Exec == l.Name() {
m[r.Plugin] = r
}
}
Expand Down Expand Up @@ -95,13 +100,13 @@ func (m *Monitor) Start() (chan<- StartPlugin, error) {
r, has := m.rules[req.Plugin]
if !has {
log.Warningln("no plugin:", req)
req.reportError(r.Launch, errNoConfig)
req.reportError(r.Launch.Properties, errNoConfig)
continue loop
}

configCopy := &Config{}
if r.Launch != nil {
*configCopy = *r.Launch
if r.Launch.Properties != nil {
*configCopy = *r.Launch.Properties
}

block, err := m.exec.Exec(r.Plugin, configCopy)
Expand Down
6 changes: 4 additions & 2 deletions pkg/launch/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ func TestMonitorLoopValidRule(t *testing.T) {
var receivedArgs *Config
rule := Rule{
Plugin: "hello",
Exec: "test",
Launch: raw,
Launch: ExecRule{
Exec: "test",
Properties: raw,
},
}
monitor := NewMonitor(&testLauncher{
name: "test",
Expand Down
42 changes: 24 additions & 18 deletions scripts/tutorial-start-plugins.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
[
{
"Plugin" : "group-default",
"Exec" : "os",
"Launch" : {
"Cmd" : "infrakit-group-default --poll-interval 500ms --name group-stateless --log 5 > {{env "LOG_DIR"}}/group-default-{{unixtime}}.log 2>&1 &",
"SamePgID" : true
}
"Plugin" : "group-default",
"Launch" : {
"Exec" : "os",
"Properties": {
"Cmd" : "infrakit-group-default --poll-interval 500ms --name group-stateless --log 5 > {{env "LOG_DIR"}}/group-default-{{unixtime}}.log 2>&1 &",
"SamePgID" : true
}
}
}
,
{
"Plugin" : "instance-file",
"Exec" : "os",
"Launch" : {
"Cmd" : "infrakit-instance-file --dir {{env "TUTORIAL_DIR"}} --log 5 > {{env "LOG_DIR"}}/instance-file-{{unixtime}}.log 2>&1",
"SamePgID" : true
}
"Plugin" : "instance-file",
"Launch" : {
"Exec" : "os",
"Properties" : {
"Cmd" : "infrakit-instance-file --dir {{env "TUTORIAL_DIR"}} --log 5 > {{env "LOG_DIR"}}/instance-file-{{unixtime}}.log 2>&1",
"SamePgID" : true
}
}
}
,
{
"Plugin" : "flavor-vanilla",
"Exec" : "os",
"Launch" : {
"Cmd" : "infrakit-flavor-vanilla --log 5 > {{env "LOG_DIR"}}/flavor-vanilla-{{unixtime}}.log 2>&1",
"SamePgID" : true
}
"Plugin" : "flavor-vanilla",
"Launch" : {
"Exec" : "os",
"Properties" : {
"Cmd" : "infrakit-flavor-vanilla --log 5 > {{env "LOG_DIR"}}/flavor-vanilla-{{unixtime}}.log 2>&1",
"SamePgID" : true
}
}
}
]
58 changes: 35 additions & 23 deletions scripts/tutorial-test2
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ set -o nounset
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$HERE/.."

export PATH=$PWD/build:$PATH

SKIP_CLEANUP=${SKIP_CLEANUP:-false}

starterpid="" # pid of the cli plugin starter
cleanup() {
kill $(jobs -p)
rm -rf tutorial
pgid=$(ps -o pgid= -p $starterpid)
echo "Stopping plugin starter utility - $starterpid , pgid=$pgid"
kill -TERM -$pgid
echo "Stopping other jobs"
kill $(jobs -p)
rm -rf tutorial
}
trap cleanup EXIT

if [ "$SKIP_CLEANUP" != "true" ]; then
trap cleanup EXIT
fi

# infrakit directories
plugins=~/.infrakit/plugins
Expand All @@ -27,9 +39,9 @@ echo group > $leaderfile

# start up multiple instances of manager -- typically we want multiple SETS of plugins and managers
# but here for simplicity just start up with multiple managers and one set of plugins
build/infrakit-manager --name group --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
build/infrakit-manager --name group1 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
build/infrakit-manager --name group2 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
infrakit-manager --name group --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
infrakit-manager --name group1 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
infrakit-manager --name group2 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &

sleep 5 # manager needs to detect leadership

Expand All @@ -47,10 +59,10 @@ export LOG_DIR=$LOG_DIR
export TUTORIAL_DIR=$TUTORIAL_DIR

# note -- on exit, this won't clean up the plugins started by the cli since they will be in a separate process group
build/infrakit plugin start --wait --config-url file:///$PWD/scripts/tutorial-start-plugins.json --os group-default instance-file flavor-vanilla &
infrakit plugin start --wait --config-url file:///$PWD/scripts/tutorial-start-plugins.json --os group-default instance-file flavor-vanilla &

lastpid=$!
echo "plugin start pid=$lastpid"
starterpid=$!
echo "plugin start pid=$starterpid"

sleep 5

Expand Down Expand Up @@ -90,33 +102,33 @@ expect_output_lines() {
fi
}

expect_output_lines "6 plugins should be discoverable" "build/infrakit plugin ls -q" "6"
expect_output_lines "0 instances should exist" "build/infrakit instance describe -q --name instance-file" "0"
expect_output_lines "6 plugins should be discoverable" "infrakit plugin ls -q" "6"
expect_output_lines "0 instances should exist" "infrakit instance describe -q --name instance-file" "0"

echo "Commiting"
build/infrakit group commit docs/cattle.json
infrakit group commit docs/cattle.json

echo 'Waiting for group to be provisioned'
sleep 2

expect_output_lines "5 instances should exist in group" "build/infrakit group describe cattle -q" "5"
expect_output_lines "5 instances should exist" "build/infrakit instance describe -q --name instance-file" "5"
expect_output_lines "5 instances should exist in group" "infrakit group describe cattle -q" "5"
expect_output_lines "5 instances should exist" "infrakit instance describe -q --name instance-file" "5"

build/infrakit group free cattle
build/infrakit group commit docs/cattle.json
infrakit group free cattle
infrakit group commit docs/cattle.json

expect_exact_output "Should be watching one group" "build/infrakit group ls -q" "cattle"
expect_exact_output "Should be watching one group" "infrakit group ls -q" "cattle"

expect_exact_output \
"Update should roll 5 and scale group to 10" \
"build/infrakit group commit docs/cattle2.json --pretend" \
"infrakit group commit docs/cattle2.json --pretend" \
"Committing cattle would involve: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10"

build/infrakit group commit docs/cattle2.json
infrakit group commit docs/cattle2.json

sleep 5

expect_output_lines "10 instances should exist in group" "build/infrakit group describe cattle -q" "10"
expect_output_lines "10 instances should exist in group" "infrakit group describe cattle -q" "10"

# Terminate 3 instances.
pushd $TUTORIAL_DIR
Expand All @@ -125,9 +137,9 @@ popd

sleep 5

expect_output_lines "10 instances should exist in group" "build/infrakit group describe cattle -q" "10"
expect_output_lines "10 instances should exist in group" "infrakit group describe cattle -q" "10"

build/infrakit group destroy cattle
expect_output_lines "0 instances should exist" "build/infrakit instance describe -q --name instance-file" "0"
infrakit group destroy cattle
expect_output_lines "0 instances should exist" "infrakit instance describe -q --name instance-file" "0"

echo 'ALL TESTS PASSED'