3 // A sample Orchestra submission client.
16 type JobRequest struct {
18 Score string `json:"score"`
19 Players []string `json:"players"`
20 Scope string `json:"scope"`
21 Params map[string]string `json:"params"`
25 AllOf = flag.Bool("all-of", false, "Send request to all named players")
26 AudienceSock = flag.String("audience-sock", "/var/spool/orchestra/conductor.sock", "Path for the audience submission socket")
29 func NewJobRequest() (jr *JobRequest) {
31 jr.Params = make(map[string]string)
37 fmt.Fprintf(os.Stderr, "Usage:\n")
38 fmt.Fprintf(os.Stderr, " %s [<options>] <score> <player1> [<player2>...] [! [<key1> <value1>]...]\n", os.Args[0])
63 for k = 1; k < len(args); k++ {
68 if nil == jr.Players {
69 jr.Players = make([]string, 1)
71 insertionpoint = len(jr.Players)
72 newplayers := make([]string, insertionpoint+1)
73 copy(newplayers, jr.Players)
74 jr.Players = newplayers
76 jr.Players[insertionpoint] = args[k]
81 if (len(args) - (k))%2 != 0 {
82 fmt.Fprintf(os.Stderr, "Error: Odd number of param arguments.\n")
85 for ; k < len(args); k+=2 {
86 jr.Params[args[k]] = args[k+1]
90 raddr, err := net.ResolveUnixAddr("unix", *AudienceSock)
92 fmt.Fprintf(os.Stderr, "Failed to resolve sockaddr: %s\n", err)
95 conn, err := net.DialUnix("unix", nil, raddr)
97 fmt.Fprintf(os.Stderr, "Failed to connect to sockaddr: %s\n", err)
107 r, _ := nc.(io.Reader)
108 w, _ := nc.(io.Writer)
110 dec := json.NewDecoder(r)
111 enc := json.NewEncoder(w)
116 fmt.Fprintf(os.Stderr, "Failed to marshal & send: %s\n", err)
120 response := new([2]interface{})
121 err = dec.Decode(response)
123 fmt.Fprintf(os.Stderr, "Error decoding response: %s\n", err)
126 // coerce field 0 back into a string.
127 rerr,ok := response[0].(string)
130 // all OK! get the JobID
131 jobid, _ := response[1].(float64)
132 fmt.Printf("%d\n", uint64(jobid))
135 fmt.Fprintf(os.Stderr, "Server Error: %s\n", rerr)
139 fmt.Fprintf(os.Stderr, "Couldn't unmarshal response correctly.\n");