예제 #1
0
파일: manager.go 프로젝트: way-2-go/logyard
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
}
예제 #2
0
파일: status.go 프로젝트: way-2-go/logyard
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
	}
}