File: util.go

package info (click to toggle)
golang-github-mesos-mesos-go 0.0.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,724 kB
  • sloc: makefile: 163
file content (63 lines) | stat: -rw-r--r-- 1,718 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package httpmaster

import (
	"fmt"

	"github.com/mesos/mesos-go/api/v1/lib/client"
	"github.com/mesos/mesos-go/api/v1/lib/httpcli"
	"github.com/mesos/mesos-go/api/v1/lib/master"
)

func classifyResponse(c *master.Call) (rc client.ResponseClass, err error) {
	if c == nil {
		err = httpcli.ProtocolError("nil master.Call not allowed")
		return
	}

	switch t := c.GetType(); t {
	// singleton
	case master.Call_GET_HEALTH,
		master.Call_GET_FLAGS,
		master.Call_GET_VERSION,
		master.Call_GET_METRICS,
		master.Call_GET_LOGGING_LEVEL,
		master.Call_LIST_FILES,
		master.Call_READ_FILE,
		master.Call_GET_STATE,
		master.Call_GET_AGENTS,
		master.Call_GET_FRAMEWORKS,
		master.Call_GET_EXECUTORS,
		master.Call_GET_TASKS,
		master.Call_GET_ROLES,
		master.Call_GET_WEIGHTS,
		master.Call_GET_MASTER,
		master.Call_GET_MAINTENANCE_STATUS,
		master.Call_GET_MAINTENANCE_SCHEDULE,
		master.Call_GET_QUOTA:
		rc = client.ResponseClassSingleton

	// streaming
	case master.Call_SUBSCRIBE:
		// for some reason, the docs say that thr format is recordio (streaming) but HTTP negotiation
		// uses application/json or application/x-protobuf; use "auto" class, similar to sched/exec API
		rc = client.ResponseClassAuto

	// no-data
	case master.Call_SET_LOGGING_LEVEL,
		master.Call_UPDATE_WEIGHTS,
		master.Call_RESERVE_RESOURCES,
		master.Call_UNRESERVE_RESOURCES,
		master.Call_CREATE_VOLUMES,
		master.Call_DESTROY_VOLUMES,
		master.Call_UPDATE_MAINTENANCE_SCHEDULE,
		master.Call_START_MAINTENANCE,
		master.Call_STOP_MAINTENANCE,
		master.Call_SET_QUOTA,
		master.Call_REMOVE_QUOTA:
		rc = client.ResponseClassNoData

	default:
		err = httpcli.ProtocolError(fmt.Sprintf("unsupported master.Call type: %v", t))
	}
	return
}