Skip to content
This repository has been archived by the owner on Dec 31, 2021. It is now read-only.

Commit

Permalink
Arguments are ok
Browse files Browse the repository at this point in the history
  • Loading branch information
owulveryck committed Dec 12, 2015
1 parent 81d7276 commit 0deb1cb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
5 changes: 5 additions & 0 deletions orchestrator/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type Graph struct {
Nodes []Node `json:"nodes"`
}

func (v *Graph) getNodeFromName(n string) (Node, error) {
var nn Node
return nn, nil
}

// Run executes the Graph structure
func (v *Graph) Run(stop <-chan time.Time) {
v.State = Running
Expand Down
27 changes: 27 additions & 0 deletions orchestrator/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ import (
"testing"
)

func TestRun(t *testing.T) {
e := valid.Check()
if e.Code != 0 {
t.Errorf("Struct should be valid, error is: %v", e.Error())
}
e = notValid.Check()
if e.Code == 0 {
t.Errorf("Struct should not be valid, error is: %v", e.Error())
}

var wg sync.WaitGroup
count := 1
vs := make([]Graph, count)
wg.Add(count)
for i := 0; i < count; i++ {
vs[i] = valid
vs[i].Name = fmt.Sprintf("%v", i)
go func(v Graph, wg *sync.WaitGroup) {
v.Run(nil)
wg.Done()
}(vs[i], &wg)
}
wg.Wait()
for i := 0; i < count; i++ {
t.Log(vs[i])
}
}
func BenchmarkRun(b *testing.B) {
e := valid.Check()
if e.Code != 0 {
Expand Down
15 changes: 15 additions & 0 deletions orchestrator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package orchestrator

import (
"fmt"
"math/rand"
"regexp"
"time"
)

Expand All @@ -39,6 +41,8 @@ type Node struct {
func (n *Node) Run() <-chan Message {
c := make(chan Message)
waitForIt := make(chan Graph) // Shared between all messages.
var ga = regexp.MustCompile(`^get_attribute (.+):(.+)$`)

go func() {
n.State = ToRun
for n.State <= ToRun {
Expand All @@ -60,6 +64,16 @@ func (n *Node) Run() <-chan Message {
c <- Message{n.ID, n.State, waitForIt}
}
if n.State == Running {
// Check and find the arguments
for i, arg := range n.Args {
// If argument is a get_attribute node:attribute
// Then substitute it to its actual value
subargs := ga.FindStringSubmatch(arg)
if len(subargs) == 4 {
nn, _ := g.getNodeFromName(subargs[2])
n.Args[i] = nn.Outputs[subargs[3]]
}
}
c <- Message{n.ID, n.State, waitForIt}
switch n.Engine {
case "nil":
Expand All @@ -69,6 +83,7 @@ func (n *Node) Run() <-chan Message {
time.Sleep(time.Duration(rand.Intn(1e4)) * time.Millisecond)
rand.Seed(time.Now().Unix())
n.State = Success
n.Outputs["result"] = fmt.Sprintf("%v_%v", n.Name, time.Now().Unix())
default:
// Send the message to the appropriate backend
n.State = Success
Expand Down
6 changes: 3 additions & 3 deletions orchestrator/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func init() {
},
[]Node{
{0, 0, "a", "nil", "myplaybook.yml", nil, nil},
{1, 0, "b", "shell", "myscript.sh", nil,
{1, 0, "b", "sleep", "myscript.sh", nil,
map[string]string{
"output1": "",
"result": "",
},
},
{2, 0, "c", "shell", "myscript2.sh",
[]string{
"-e", "get_attribute 1:output1",
"-e", "get_attribute b:result",
}, nil},
{3, 0, "d", "nil", "myplaybook3.yml", nil, nil},
{4, 0, "e", "nil", "myplaybook4.yml", nil, nil},
Expand Down

0 comments on commit 0deb1cb

Please sign in to comment.