Просмотр исходного кода

make old kvs compatible with countach/n2o/avz 1.4

Maxim Sokhatsky 11 лет назад
Родитель
Сommit
b2411a416b
13 измененных файлов с 20 добавлено и 180 удалено
  1. 4 0
      include/user.hrl
  2. 2 2
      rebar.config
  3. 1 1
      src/kvs.app.src
  4. 1 1
      src/kvs.erl
  5. 1 1
      src/kvs_acl.erl
  6. 1 1
      src/kvs_feed.erl
  7. 1 21
      src/kvs_group.erl
  8. 1 1
      src/kvs_meeting.erl
  9. 3 29
      src/kvs_product.erl
  10. 3 25
      src/kvs_user.erl
  11. 0 96
      src/store_kai.erl
  12. 1 1
      src/store_mnesia.erl
  13. 1 1
      src/store_riak.erl

+ 4 - 0
include/users.hrl → include/user.hrl

@@ -10,6 +10,10 @@
         twitter_id,
         googleplus_id,
         github_id,
+        tokens,
+        names,
+        surnames,
+        birth,
         auth,
         avatar,
         name = undefined,

+ 2 - 2
rebar.config

@@ -1,6 +1,6 @@
 {deps_dir, ["deps"]}.
 {deps,[
 %    {riak_kv,    ".*",    {git, "git://github.com/spawnproc/riak_kv.git", {tag,"1.3.2-voxoz"}}},
-    {kai,         ".*",   {git, "git://github.com/synrc/kai.git", "master"}},
-    {mqs,        ".*",    {git, "git://github.com/synrc/mqs.git", "master"}}
+%    {kai,         ".*",   {git, "git://github.com/synrc/kai.git", "master"}}
+%    {mqs,        ".*",    {git, "git://github.com/synrc/mqs.git", "master"}}
 ]}.

+ 1 - 1
src/kvs.app.src

@@ -3,7 +3,7 @@
   {description, "SRC KVS Distributed Persistance"},
   {vsn, "1"},
   {registered, []},
-  {applications, [kernel,stdlib,mnesia,mqs]},
+  {applications, [kernel,stdlib,mnesia]},
   {mod, { kvs_app, []}},
   {env, []}
  ]}.

+ 1 - 1
src/kvs.erl

@@ -1,6 +1,6 @@
 -module(kvs).
 -author('Maxim Sokhatsky <maxim@synrc.com>').
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/translations.hrl").
 -include_lib("kvs/include/groups.hrl").
 -include_lib("kvs/include/feeds.hrl").

+ 1 - 1
src/kvs_acl.erl

@@ -3,7 +3,7 @@
 -compile(export_all).
 -include_lib("kvs/include/kvs.hrl").
 -include_lib("kvs/include/acls.hrl").
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/groups.hrl").
 -include_lib("kvs/include/feeds.hrl").
 

+ 1 - 1
src/kvs_feed.erl

@@ -5,7 +5,7 @@
 -compile(export_all).
 -include_lib("kvs/include/kvs.hrl").
 -include_lib("kvs/include/feeds.hrl").
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/groups.hrl").
 -include_lib("kvs/include/feed_state.hrl").
 -define(CACHED_ENTRIES, 20).

+ 1 - 21
src/kvs_group.erl

@@ -1,13 +1,12 @@
 -module(kvs_group).
 -compile(export_all).
 -include_lib("kvs/include/kvs.hrl").
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/groups.hrl").
 -include_lib("kvs/include/feeds.hrl").
 -include_lib("kvs/include/accounts.hrl").
 -include_lib("kvs/include/feed_state.hrl").
 -include_lib("kvs/include/config.hrl").
--include_lib("mqs/include/mqs.hrl").
 
 init(Backend) ->
     ?CREATE_TAB(group_subscription),
@@ -194,24 +193,5 @@ build_group_relations(Group) -> [
     mqs:key( [kvs_feed, group, Group, '*', '*', '*'] )
     ].
 
-init_mq(Group=#group{}) ->
-    GroupExchange = ?GROUP_EXCHANGE(Group#group.id),
-    ExchangeOptions = [{type, <<"fanout">>}, durable, {auto_delete, false}],
-    case mqs:open([]) of
-        {ok, Channel} ->
-            mqs_channel:create_exchange(Channel, GroupExchange, ExchangeOptions),
-            Relations = build_group_relations(Group),
-            [mqs_channel:bind_exchange(Channel, ?GROUP_EXCHANGE(Group#group.id), ?NOTIFICATIONS_EX, Route) || Route <- Relations],
-            mqs_channel:close(Channel);
-        {error, Reason} -> error_logger:info_msg("init_mq error: ~p",[Reason]) end.
-
 rk_group_feed(Group) -> mqs_lib:list_to_key([kvs_feed, group, Group, '*', '*', '*']).
 
-subscription_mq(Type, Action, Who, Where) ->
-    case mqs:open([]) of
-        {ok,Channel} ->
-            case {Type,Action} of 
-                {group,add}     -> mqs_channel:bind_exchange(Channel, ?GROUP_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_group_feed(Where));
-                {groupr,remove}  -> mqs_channel:unbind_exchange(Channel, ?GROUP_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_group_feed(Where)) end,
-            mqs_channel:close(Channel);
-        {error,Reason} -> error_logger:info_msg("subscription_mq error: ~p",[Reason]) end.

+ 1 - 1
src/kvs_meeting.erl

@@ -1,6 +1,6 @@
 -module(kvs_meeting).
 -include_lib("kvs/include/kvs.hrl").
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/meetings.hrl").
 -include_lib("kvs/include/feed_state.hrl").
 -include_lib("kvs/include/config.hrl").

+ 3 - 29
src/kvs_product.erl

@@ -3,13 +3,12 @@
 -include_lib("kvs/include/kvs.hrl").
 -include_lib("kvs/include/products.hrl").
 -include_lib("kvs/include/purchases.hrl").
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/groups.hrl").
 -include_lib("kvs/include/feeds.hrl").
 -include_lib("kvs/include/accounts.hrl").
 -include_lib("kvs/include/config.hrl").
 -include_lib("kvs/include/feed_state.hrl").
--include_lib("mqs/include/mqs.hrl").
 -compile(export_all).
 
 init(Backend) ->
@@ -26,31 +25,6 @@ delete(Name) ->
       {ok, Product};
     E -> E end.
 
-subscription_mq(Type, Action, Who, Whom) ->
-    case mqs:open([]) of
-    {ok,Channel} ->
-        case {Type,Action} of
-        {user,add}->
-            mqs_channel:bind_exchange(Channel, ?USER_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_product_feed(Whom));
-        {user,remove} ->
-            mqs_channel:unbind_exchange(Channel, ?USER_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_product_feed(Whom)) end,
-        mqs_channel:close(Channel);
-    {error,Reason} -> error_logger:info_msg("subscription_mq error: ~p",[Reason]) end.
-
-init_mq(Product=#product{}) ->
-    Groups = kvs_group:participate(Product),
-    ProductExchange = ?USER_EXCHANGE(Product#product.id),
-    ExchangeOptions = [{type, <<"fanout">>}, durable, {auto_delete, false}],
-    case mqs:open([]) of
-    {ok, Channel} ->
-        error_logger:info_msg("Cration Exchange: ~p,",[{Channel,ProductExchange,ExchangeOptions}]),
-        mqs_channel:create_exchange(Channel, ProductExchange, ExchangeOptions),
-        Relations = build_product_relations(Product, Groups),
-        [ mqs_channel:bind_exchange(Channel, ?USER_EXCHANGE(Product#product.id), ?NOTIFICATIONS_EX, Route)
-            || Route <- Relations],
-        mqs_channel:close(Channel);
-    {error,Reason} -> error_logger:info_msg("init_mq error: ~p",[Reason]) end.
-
 build_product_relations(Product, Groups) -> [
     mqs:key( [kvs_product, '*', Product]),
     mqs:key( [kvs_feed, product, Product, '*', '*', '*']),
@@ -86,14 +60,14 @@ handle_notice(["kvs_product", "subscribe", Who],
     Message, #state{owner = _Owner, type =_Type} = State) ->
     {Whom} = Message,
     kvs_product:subscribe(Who, Whom),
-    subscription_mq(user, add, Who, Whom),
+%    subscription_mq(user, add, Who, Whom),
     {noreply, State};
 
 handle_notice(["kvs_product", "unsubscribe", Who],
     Message, #state{owner = _Owner, type =_Type} = State) ->
     {Whom} = Message,
     kvs_product:unsubscribe(Who, Whom),
-    subscription_mq(user, remove, Who, Whom),
+%    subscription_mq(user, remove, Who, Whom),
     {noreply, State};
 
 handle_notice([kvs_product, Owner, add],

+ 3 - 25
src/kvs_user.erl

@@ -1,6 +1,6 @@
 -module(kvs_user).
 -copyright('Synrc Research Center s.r.o.').
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/purchases.hrl").
 -include_lib("kvs/include/payments.hrl").
 -include_lib("kvs/include/groups.hrl").
@@ -9,7 +9,6 @@
 -include_lib("kvs/include/config.hrl").
 -include_lib("kvs/include/feeds.hrl").
 -include_lib("kvs/include/feed_state.hrl").
--include_lib("mqs/include/mqs.hrl").
 -include_lib("kvs/include/kvs.hrl").
 -compile(export_all).
 
@@ -61,27 +60,6 @@ subscribed(Who, Whom) ->
         {ok, _} -> true;
         _ -> false end.
 
-subscription_mq(Type, Action, Who, Whom) ->
-    case mqs:open([]) of
-        {ok,Channel} ->
-            case {Type,Action} of 
-                {user,add}     -> mqs_channel:bind_exchange(Channel, ?USER_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_user_feed(Whom));
-                {user,remove}  -> mqs_channel:unbind_exchange(Channel, ?USER_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_user_feed(Whom)) end,
-            mqs_channel:close(Channel);
-        {error,Reason} -> error_logger:info_msg("subscription_mq error: ~p",[Reason]) end.
-
-init_mq(User=#user{}) ->
-    Groups = kvs_group:participate(User),
-    UserExchange = ?USER_EXCHANGE(User#user.username),
-    ExchangeOptions = [{type, <<"fanout">>}, durable, {auto_delete, false}],
-    case mqs:open([]) of
-        {ok, Channel} ->
-            error_logger:info_msg("Cration Exchange: ~p,",[{Channel,UserExchange,ExchangeOptions}]),
-            mqs_channel:create_exchange(Channel, UserExchange, ExchangeOptions),
-            Relations = build_user_relations(User, Groups),
-            [ mqs_channel:bind_exchange(Channel, ?USER_EXCHANGE(User#user.username), ?NOTIFICATIONS_EX, Route) || Route <- Relations],
-            mqs_channel:close(Channel);
-        {error,Reason} -> error_logger:info_msg("init_mq error: ~p",[Reason]) end.
 
 build_user_relations(User, Groups) -> [
     mqs:key( [kvs_user, '*', User]),
@@ -155,14 +133,14 @@ handle_notice(["kvs_user", "subscribe", Who] = Route,
     Message, #state{owner = Owner, type =Type} = State) ->
     {Whom} = Message,
     kvs_user:subscribe(Who, Whom),
-    subscription_mq(user, add, Who, Whom),
+%    subscription_mq(user, add, Who, Whom),
     {noreply, State};
 
 handle_notice(["kvs_user", "unsubscribe", Who] = Route,
     Message, #state{owner = Owner, type =Type} = State) ->
     {Whom} = Message,
     kvs_user:unsubscribe(Who, Whom),
-    subscription_mq(user, remove, Who, Whom),
+%    subscription_mq(user, remove, Who, Whom),
     {noreply, State};
 
 handle_notice(["kvs_user", "update", Who] = Route,

+ 0 - 96
src/store_kai.erl

@@ -1,96 +0,0 @@
--module(store_kai).
--author('Maxim Sokhatsky <maxim@synrc.com>').
--copyright('Synrc Research Center s.r.o.').
--include_lib("kai/include/kai.hrl").
--include_lib("kvs/include/config.hrl").
--include_lib("kvs/include/users.hrl").
--include_lib("kvs/include/groups.hrl").
--include_lib("kvs/include/feeds.hrl").
--include_lib("kvs/include/acls.hrl").
--include_lib("kvs/include/invites.hrl").
--include_lib("kvs/include/meetings.hrl").
--include_lib("kvs/include/membership.hrl").
--include_lib("kvs/include/payments.hrl").
--include_lib("kvs/include/purchases.hrl").
--include_lib("kvs/include/accounts.hrl").
--include_lib("stdlib/include/qlc.hrl").
--compile(export_all).
-
-start() -> kai:start(), ok.
-stop() -> kai_store:stop(), ok.
-version() -> {version,"KVS KAI PURE XEN"}.
-join() -> initialize(), ok.
-join(Node) -> initialize(), ok.
-initialize() -> ok.
-dir() -> kvs:modules().
-
-put(Records) when is_list(Records) -> lists:foreach(fun kai_put/1, Records);
-put(Record) -> kai_put(Record).
-
-kai_put(Record) ->
-    Data = #data{key = element(2,Record), bucket = table_to_num(element(1,Record)),
-        last_modified = now(), checksum = erlang:md5(term_to_binary(Record)),
-        vector_clocks = vclock:fresh(), value = Record },
-    kai_store:put(Data).
-
-update(Record, Object) -> ok.
-
-get(Tab, Key) ->
-    Data = #data{key=Key,bucket=table_to_num(Tab)},
-    kai_get(Data).
-
-kai_get(Data) ->
-    case kai_store:get(Data) of
-         #data{value=Value} -> Value;
-         undefined -> {error,not_found};
-         E -> {error,E} end.
-
-delete(Tab, Key) ->
-    ok.
-
-key_to_bin(Key) ->
-    if is_integer(Key) -> erlang:list_to_binary(integer_to_list(Key));
-       is_list(Key) -> erlang:list_to_binary(Key);
-       is_atom(Key) -> erlang:list_to_binary(erlang:atom_to_list(Key));
-       is_binary(Key) -> Key;
-       true ->  [ListKey] = io_lib:format("~p", [Key]), erlang:list_to_binary(ListKey) end.
-
-all(RecordName) ->
-    {list_of_data,List} = kai_store:list(table_to_num(RecordName)),
-    [ kai_get(Data) || Data <- List ].
-
-all_by_index(Tab, IndexId, IndexVal) -> [].
-
-% index funs
-
-products(UId) -> all_by_index(user_product, <<"user_bin">>, list_to_binary(UId)).
-subscriptions(UId) -> all_by_index(subsciption, <<"subs_who_bin">>, list_to_binary(UId)).
-subscribed(Who) -> all_by_index(subscription, <<"subs_whom_bin">>, list_to_binary(Who)).
-participate(UserName) -> all_by_index(group_subscription, <<"who_bin">>, UserName).
-members(GroupName) -> all_by_index(group_subscription, <<"where_bin">>, GroupName).
-user_tournaments(UId) -> all_by_index(play_record, <<"play_record_who_bin">>, list_to_binary(UId)).
-tournament_users(TId) -> all_by_index(play_record, <<"play_record_tournament_bin">>, list_to_binary(integer_to_list(TId))).
-author_comments(Who) ->
-    EIDs = [E || #comment{entry_id=E} <- all_by_index(comment,<<"author_bin">>, Who) ],
-    lists:flatten([ all_by_index(entry,<<"entry_bin">>,EID) || EID <- EIDs]).
-
-table_to_num(user) -> 10;
-table_to_num(user_status) -> 20;
-table_to_num(subscription) -> 30;
-table_to_num(group) -> 40;
-table_to_num(group_subscription) -> 50;
-table_to_num(payment) -> 60;
-table_to_num(user_payment) -> 70;
-table_to_num(account) -> 80;
-table_to_num(transaction) -> 90;
-table_to_num(id_seq) -> 100;
-table_to_num(team) -> 110;
-table_to_num(membership) -> 120;
-table_to_num(product) -> 130;
-table_to_num(product_category) -> 140;
-table_to_num(user_product) -> 150;
-table_to_num(acl) -> 160;
-table_to_num(acl_entry) -> 170;
-table_to_num(feed) -> 180;
-table_to_num(entry) -> 190;
-table_to_num(comment) -> 200.

+ 1 - 1
src/store_mnesia.erl

@@ -2,7 +2,7 @@
 -author('Maxim Sokhatsky').
 -copyright('Synrc Research Center s.r.o.').
 -include_lib("kvs/include/config.hrl").
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/groups.hrl").
 -include_lib("kvs/include/feeds.hrl").
 -include_lib("kvs/include/acls.hrl").

+ 1 - 1
src/store_riak.erl

@@ -2,7 +2,7 @@
 -author('Maxim Sokhatsky <maxim@synrc.com>').
 -copyright('Synrc Research Center s.r.o.').
 -include_lib("kvs/include/config.hrl").
--include_lib("kvs/include/users.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("kvs/include/groups.hrl").
 -include_lib("kvs/include/feeds.hrl").
 -include_lib("kvs/include/acls.hrl").