Ejemplo n.º 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
}
Ejemplo n.º 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
	}
}
Ejemplo n.º 3
0
func (d *RedisDrain) Start(config *DrainConfig) {
	defer d.Done()

	// store messages under `redisKey` (redis key). if it is empty,
	// store them under that message's key.
	redisKey := config.GetParam("key", "")

	limit, err := config.GetParamInt("limit", 1500)
	if err != nil {
		d.Killf("limit key from `params` is not a number -- %s", err)
		go d.finishedStarting(false)
		return
	}

	database, err := config.GetParamInt("database", 0)
	if err != nil {
		d.Killf("invalid database specified: %s", err)
		go d.finishedStarting(false)
		return
	}

	// HACK (stackato-specific): "core" translates to the applog redis on core node
	coreIP := server.GetClusterConfig().MbusIp
	if config.Host == "stackato-core" {
		config.Host = coreIP
	} else if strings.HasPrefix(config.Host, "stackato-core:") {
		config.Host = fmt.Sprintf("%s:%s",
			coreIP, config.Host[len("stackato-core:"):])
	}

	if err = d.connect(config.Host, int64(database)); err != nil {
		d.Kill(err)
		go d.finishedStarting(false)
		return
	}
	defer d.disconnect()

	sub := logyard.Broker.Subscribe(config.Filters...)
	defer sub.Stop()

	go d.finishedStarting(true)

	for {
		select {
		case msg := <-sub.Ch:
			key := msg.Key
			if redisKey != "" {
				key = redisKey
			}
			data, err := config.FormatJSON(msg)
			if err != nil {
				d.Kill(err)
				return
			}
			_, err = d.Lpushcircular(key, string(data), int64(limit))
			if err != nil {
				d.Kill(err)
				return
			}
		case <-d.Dying():
			return
		}
	}
}