Beispiel #1
0
func NewDrainManager() *DrainManager {
	manager := new(DrainManager)
	manager.stopCh = make(chan bool)
	manager.stmMap = make(map[string]*state.StateMachine)
	client, err := server.NewRedisClientRetry(
		server.GetClusterConfig().MbusIp+":6464",
		"",
		0,
		-1)
	if err != nil {
		log.Fatalf("Unable to connect to applog_redis; %v", err)
	}
	manager.stateCache = &statecache.StateCache{
		"logyard:drainstatus:",
		server.LocalIPMust(),
		client}
	return manager
}
Beispiel #2
0
func (cmd *status) Run(args []string) (string, error) {
	cache := &statecache.StateCache{
		"logyard:drainstatus:",
		server.LocalIPMust(),
		server.NewRedisClientMust(
			server.GetClusterConfig().MbusIp+":6464",
			"",
			0)}

	drains, err := cmd.GetDrains(args)
	if err != nil {
		return "", err
	}
	data := make(map[string]map[string]statecache.StateInfo)

	for _, name := range drains {
		states, err := cache.GetState(name)
		if err != nil {
			return "", fmt.Errorf("Unable to retrieve cached state: %v", err)
		}
		data[name] = states
	}

	if cmd.json {
		b, err := json.Marshal(data)
		return string(b), err
	} else {
		for name, states := range data {
			for _, nodeip := range sortedKeysStateMap(states) {
				running := strings.Contains(states[nodeip]["name"], "RUNNING")
				if cmd.notrunning && running {
					continue
				}
				printStatus(name, nodeip, states[nodeip])
			}
		}
		return "", nil
	}
}