Beispiel #1
0
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	user := args.UserID
	_, err := ts.Libstore.Get(user)
	switch err {
	case nil: // expected case, do nothing
	case libstore.ErrorKeyNotFound:
		reply.Status = tribrpc.NoSuchUser
		return nil
	default:
		return err
	}

	subscListKey := makeSubscListKey(user)
	userIDs, err := ts.Libstore.GetList(subscListKey)
	switch err {
	case nil:
	case libstore.ErrorKeyNotFound:
		userIDs = make([]string, 0)
	default:
		return err
	}
	reply.UserIDs = userIDs
	reply.Status = tribrpc.OK
	return nil
}
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	subkey := util.FormatSubListKey(args.UserID)
	userkey := util.FormatUserKey(args.UserID)
	_, userErr := ts.libstore.Get(userkey)
	if userErr != nil {
		reply.Status = tribrpc.NoSuchUser
	} else {
		list, _ := ts.libstore.GetList(subkey)
		reply.Status = tribrpc.OK
		reply.UserIDs = list
	}
	return nil
}
Beispiel #3
0
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	if ts.userExist(args.UserID) == false {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	UserIDs, err := ts.ls.GetList(util.FormatSubListKey(args.UserID))
	if err == nil {
		reply.Status = tribrpc.OK
		reply.UserIDs = UserIDs
	} else {
		reply.Status = tribrpc.OK
		reply.UserIDs = make([]string, 0)
	}
	return nil
}
Beispiel #4
0
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	key := util.FormatUserKey(args.UserID)
	if ts.checkIfKnown(key) {
		sublist_key := util.FormatSubListKey(args.UserID)
		sub_ids, err := ts.storage.GetList(sublist_key)
		if err != nil {
			sub_ids = []string{}
		}
		reply.UserIDs = sub_ids
		reply.Status = tribrpc.OK
	} else {
		reply.Status = tribrpc.NoSuchUser
	}
	return nil
}
Beispiel #5
0
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {

	userkey := util.FormatUserKey(args.UserID)

	usersubs := util.FormatSubListKey(args.UserID)

	// Make sure user exists
	if _, eu := ts.ls.Get(userkey); eu != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	if lst, err := ts.ls.GetList(usersubs); err == nil {
		reply.Status = tribrpc.OK
		reply.UserIDs = lst
		return nil
	} else {
		// The user has no subscriptions yet
		reply.Status = tribrpc.OK
		reply.UserIDs = make([]string, 0)
		return nil
	}
}
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	user_id := util.FormatUserKey(args.UserID)

	// If the user_id doesn't exist
	// Reture NoSuchUser
	_, err := ts.lib_store.Get(user_id)
	if err != nil {
		fmt.Println("===========", err, "============")
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	user_id_list := util.FormatSubListKey(args.UserID)
	user_list, err := ts.lib_store.GetList(user_id_list)
	//if err != nil {
	//		reply.Status = tribrpc.NoSuchUser
	//		return nil
	//	}

	reply.UserIDs = user_list
	reply.Status = tribrpc.OK
	return nil
}
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	userid := args.UserID
	useridkey := util.FormatUserKey(userid)

	_, userExists := ts.ls.Get(useridkey)

	if userExists != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	userSubListKey := util.FormatSubListKey(userid)
	nodes, err := ts.ls.GetList(userSubListKey)

	if err != nil {
		reply.Status = tribrpc.OK
		reply.UserIDs = nil
		return nil
	}

	reply.Status = tribrpc.OK
	reply.UserIDs = nodes
	return nil
}
Beispiel #8
0
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	UserKey := GenerateUserKey(args.UserID)

	_, err := ts.lib.Get(UserKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.UserIDs = nil
		return nil
	}

	SubsKey := GenerateSubsKey(args.UserID)
	SubsList, err := ts.lib.GetList(SubsKey)
	if err != nil {
		reply.Status = tribrpc.OK
		reply.UserIDs = nil
		return nil
	}

	reply.Status = tribrpc.OK
	reply.UserIDs = SubsList
	return nil
}
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	LOGE.Printf("GetSubscriptions:: args=%s\n", string(marshal(*args)))
	userIDKey := GetUserKey(args.UserID)
	_, err := ts.lib.Get(userIDKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.UserIDs = nil
		return nil
	}

	userSubsKey := GetsSubsKey(args.UserID)
	userSubsList, err := ts.lib.GetList(userSubsKey)
	if err != nil {
		reply.Status = tribrpc.OK
		reply.UserIDs = nil
		return nil
	}

	reply.Status = tribrpc.OK
	reply.UserIDs = userSubsList
	LOGE.Printf("GetSubscriptions:: reply=%s\n", string(marshal(reply)))
	return nil
}
func (ts *tribServer) GetSubscriptions(args *tribrpc.GetSubscriptionsArgs, reply *tribrpc.GetSubscriptionsReply) error {
	if DBG {
		fmt.Println("-----> GetSubscriptions")
	}
	/*
		formatsublistkey
	*/
	var thisUsrId string = args.UserID

	//check if user present in server
	_, err := ts.libStore.Get(util.FormatUserKey(thisUsrId))

	if err != nil {
		switch err.Error() {
		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchUser
			return nil

		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
			return errors.New("WRONG error message")
		}

		//user not found
		reply.Status = tribrpc.NoSuchUser
		//return err
		return nil
	}

	subscrList, err := ts.libStore.GetList(util.FormatSubListKey(thisUsrId))

	if err == nil {
		reply.Status = tribrpc.OK
		reply.UserIDs = subscrList
		return nil
	}

	//error not nil

	switch err.Error() {
	case KEY_NOT_FOUND:
		//User present, no subscriptions
		reply.Status = tribrpc.OK
		//Empty list of user IDs
		reply.UserIDs = make([]string, 0)
		return nil
		break

	case WRONG_SERVER:
		fmt.Println("ERROR: WRONG SERVER in tribserver")
		return nil
		break
	default:
		fmt.Println("ERROR in tribserver: wrong error message received")
	}

	return nil
}