Esempio n. 1
1
func (e *ListManagersExecutor) Execute(t *Task) (err error) {
	e.reply.Managers, err = datamodel.ListManagers()
	if err != nil {
		e.reply.Status = StatusError
	} else {
		for _, managers := range e.reply.Managers {
			sort.Strings(managers)
		}
		e.reply.Status = StatusOk
	}
	return
}
Esempio n. 2
0
func checkRole(role string, rType string) error {
	log.Printf("[CheckRole] checking myself (%s:%s) for %s:%s", Region, Host, rType, role)
	zkManager, err := datamodel.GetManager(Region, Host)
	if err != nil {
		return err
	}
	log.Printf("[CheckRole] roles: %v", zkManager.Roles)
	if !zkManager.HasRole(role, rType) {
		log.Printf("[CheckRole] role check fail.")
		managersWithRole := ""
		managers, err := datamodel.ListManagers()
		if err != nil {
			return err
		}
		for region, rManagers := range managers {
			for _, manager := range rManagers {
				zm, err := datamodel.GetManager(region, manager)
				if err != nil {
					continue
				}
				if zm.HasRole(role, rType) {
					managersWithRole = managersWithRole + zm.ManagerCName + "\n"
				}
			}
		}
		return errors.New(fmt.Sprintf("This manager does not have the ability to %s %s. "+
			"Please try one of these:\n%s", rType, role, managersWithRole))
	}
	log.Printf("[CheckRole] role check success.")
	return nil
}