3 // A sample Orchestra status polling client.
17 type StatusRequest struct {
22 type PlayerStatus struct {
23 Status *string `json:"status"`
24 Response map[string]*string `json:"response"`
27 type StatusResponse struct {
28 Status *string `json:"status"`
29 Players map[string]*PlayerStatus `json:"players"`
33 AudienceSock = flag.String("audience-sock", "/var/spool/orchestra/conductor.sock", "Path for the audience submission socket")
36 func NewStatusRequest() (sr *StatusRequest) {
37 sr = new(StatusRequest)
43 fmt.Fprintf(os.Stderr, "Usage:\n")
44 fmt.Fprintf(os.Stderr, " %s [<options>] <jobid>\n", os.Args[0])
57 sr := NewStatusRequest()
59 sr.Id, err = strconv.Atoui64(flag.Arg(0))
61 fmt.Fprintf(os.Stderr, "Failed to parse JobID: %s\n", err)
65 raddr, err := net.ResolveUnixAddr("unix", *AudienceSock)
67 fmt.Fprintf(os.Stderr, "Failed to resolve sockaddr: %s\n", err)
70 conn, err := net.DialUnix("unix", nil, raddr)
72 fmt.Fprintf(os.Stderr, "Failed to connect to sockaddr: %s\n", err)
82 r, _ := nc.(io.Reader)
83 w, _ := nc.(io.Writer)
85 dec := json.NewDecoder(r)
86 enc := json.NewEncoder(w)
91 fmt.Fprintf(os.Stderr, "Failed to marshal & send: %s\n", err)
95 response := new([2]interface{})
96 sresp := new(StatusResponse)
98 err = dec.Decode(response)
100 // OK, the problem here is that an in the request will throw a null in the second field.
101 // This will cause Decode to softfault. We'll ignore these softfaults.
102 utye, ok := err.(*json.UnmarshalTypeError)
104 fmt.Fprintf(os.Stderr, "Unmarshalling error: %s of Type %s\n", utye.Value, utye.Type)
106 ufe, ok := err.(*json.UnmarshalFieldError)
108 fmt.Fprintf(os.Stderr, "Error decoding response: UFE %s of Type %s\n", ufe.Key, ufe.Type)
111 ute, ok := err.(*json.UnsupportedTypeError)
113 fmt.Fprintf(os.Stderr, "Error decoding response: UTE of Type %s\n", ute.Type)
117 fmt.Fprintf(os.Stderr, "Error decoding response: %s\n", err)
122 // coerce field 0 back into a string.
123 rerr,ok := response[0].(string)
126 // all OK, process the sresp.
127 fmt.Printf("Aggregate: %s\n", *sresp.Status)
130 fmt.Fprintf(os.Stderr, "Server Error: %s\n", rerr)
134 fmt.Fprintf(os.Stderr, "Couldn't unmarshal response correctly.\n");