creating Keyspace - erlang

I am trying to access cassandra from erlang, as a test I am trying to create a new keyspace. I do it as follows:
1> rr(cassandra_thrift).
[authenticationException,authenticationRequest,
authorizationException,cfDef,column,columnDef,
columnOrSuperColumn,columnParent,columnPath,counterColumn,
counterSuperColumn,cqlMetadata,cqlResult,cqlRow,deletion,
endpointDetails,indexClause,indexExpression,
invalidRequestException,keyCount,keyRange,keySlice,ksDef,
mutation,notFoundException,schemaDisagreementException,
slicePredicate,sliceRange,superColumn|...]
2> {ok,C1}=thrift_client_util:new("127.0.0.1",9160,thrift_cassandra,[]).
{ok,{tclient,thrift_cassandra,
{protocol,thrift_binary_protocol,
{binary_protocol,
{transport,thrift_buffered_transport,
{buffered_transport,
{transport,thrift_socket_transport,
{data,#Port<0.593>,infinity}},
[]}},
true,true}},
0}}
3> Reply1=thrift_client:call(C1,set_keyspace,["Test_KS"]).
** exception exit: undef
in function thrift_cassandra:function_info/2
called as thrift_cassandra:function_info(set_keyspace,params_type)
in call from thrift_client:send_function_call/3 (thrift_client.erl, line 70)
in call from thrift_client:call/3 (thrift_client.erl, line 40)
Am I doing something wrong, or does my erlang not have access to the cassandra functions? How can I fix it?

I would use https://github.com/ostinelli/erlcassa over raw Thrift from Erlang.

Related

crypto_server exception exit: {einval, [{erlang,open_port,[{spawn, "crypto_drv elibcrypto

I having crypto_server problems:
=CRASH REPORT==== 23-Jul-2019::10:20:17 ===
crasher:
pid: <0.49.0>
registered_name: crypto_server
exception exit: {einval,
[{erlang,open_port,
[{spawn,
"crypto_drv elibcrypto
c:/myapp/lib/crypto-1.5.3/priv/lib/win32/elibcrypto"},
[]]},
{crypto_server,open_ports,2},
{gen_server,init_it,6},
{proc_lib,init_p_do_apply,3}]}
in function gen_server:init_it/6
initial call: crypto_server:init/1
ancestors: [crypto_sup,<0.47.0>]
messages: []
links: [<0.48.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 610
stack_size: 23
reductions: 425
neighbours:
and the application doesn't start:
Kernel pid terminated (application_controller)
({application_start_failure,crypto,{shutdown,{crypto_app,start,[normal,[]]}}})
einval is a is a linux error that means invalid argument. Erlang returns quite a few of those types of errors back to the user. If you need a handy lookup table, you check look here.
I'm guessing the version of OpenSSL you have installed is incompatible with the old version of erlang. You could always start a trace on the init and see what's happening in during all of the message passing. You'll have to add the trace to your start up code before starting up the crypto lib. Here's a basic primer on tracing.
You must start the tracer program:
dbg:tracer().
Then you need to identify which process(es) you'd like to trace. The simple version is to watch all processes. (c is short for [call], which means trace all function calls.)
dbg:p(all, c).
Finally, say what function calls you're interested in tracing by Module; Module and Function; or Module, Function, and Arity. You can use '_' in place of any of them.
dbg:tpl(Module, cx).
dbg:tpl(Module, Function, cx).
dbg:tpl(Module, Function, Arity, cx).
You can turn tracing off with a similar function that disables tracing for all functions; by Module; by Module and Function; or by Module, Function, and Arity. Again, you can use '_' in place of any of them.
dbg:ctpl().
dbg:ctpl(Module).
dbg:ctpl(Module, Function).
dbg:ctpl(Module, Function, Arity).
A simple, working example that you can copy/paste into a fresh repl:
dbg:tracer().
dbg:p(all, c).
dbg:tpl(file, open, cx).
file:open("idontexist", []).
dbg:ctpl(file).
file:open("idontexist", []).
That should produce something like:
1> dbg:tracer().
{ok,<0.299.0>}
2> dbg:p(all, c).
{ok,[{matched,engine#ryan,215}]}
3> dbg:tpl(file, open, cx).
{ok,[{matched,node#sam,1},{saved,cx}]}
4> file:open("idontexist", []).
(<0.50.0>) call file:open("idontexist",[]) ({erl_eval,do_apply,6})
(<0.50.0>) returned from file:open/2 -> {error,enoent}
{error,enoent}
5> dbg:ctpl(file).
{ok,[{matched,node#sam,95}]}
6> file:open("idontexist", []).
{error,enoent}
7>

Ejabberd module do not compile after update

I, i have updated ejabberd from 16.01 to 16.03, i have a problem with my module, before update this line of code
Type = Packet#xmlel.attrs,
io:format("types:~p~n" , [Type]),
%Get raw data of message
Message = xml:element_to_binary(Packet).
works fine, now after update produce this:
types:[{<<"type">>,<<"chat">>}, {<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}]
16:57:13.393 [error]
{undef,
[{xml,element_to_binary,
[{xmlel,<<"message">>,
[{<<"type">>,<<"chat">>},
{<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}],
[{xmlel,<<"composing">>,
[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],
[]}]}], []},
{ejabberd_hooks,safe_apply,3,
[{file,"src/ejabberd_hooks.erl"},{line,382}]},
{ejabberd_hooks,run1,3,
[{file,"src/ejabberd_hooks.erl"},{line,329}]},
{ejabberd_sm,route,3,
[{file,"src/ejabberd_sm.erl"},{line,114}]},
{ejabberd_local,route,3,
[{file,"src/ejabberd_local.erl"},{line,112}]},
{ejabberd_router,route,3,
[{file,"src/ejabberd_router.erl"},{line,77}]},
{ejabberd_c2s,check_privacy_route,5,
[{file,"src/ejabberd_c2s.erl"},{line,2110}]},
{ejabberd_c2s,session_established2,2,
[{file,"src/ejabberd_c2s.erl"},{line,1271}]}]}
running hook:
{offline_message_hook,
[{jid,<<"121">>,<<"node0.frind.it">>,
<<"97395769126380428951460048231139020">>,<<"121">>,
<<"node0.frind.it">>,
<<"97395769126380428951460048231139020">>},
{jid,<<"154">>,<<"node0.frind.it">>,<<>>,<<"154">>,
<<"node0.frind.it">>,<<>>},
{xmlel,<<"message">>,
[{<<"type">>,<<"chat">>},
{<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}],
[{xmlel,<<"composing">>,
[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]}]}
]}
Anyone can help me?
Latest ejabberd move to library fast_xml. Use fxml module instead of xml.

Call an Erlang function to create a user in ejabberd

I am using erlang 18, ejabberd 15.09. I am trying to create chat application. For that I have to create user for ejabberd using Erlang.
I used the erlang function ejabberd_auth:try_register for that:
ejabberd_auth:try_register(<<"username">>, <<"example.com">>, <<"secret_password">>).
It produced the following error:
exception error: undefined function stringprep:nameprep/1
in function jlib:nameprep/1 (src/jlib.erl, line 331)
in call from ejabberd_auth:auth_modules/1 (src/ejabberd_auth.erl, line 429)
in call from ejabberd_auth:is_user_exists/2 (src/ejabberd_auth.erl, line 323)
in call from ejabberd_auth:try_register/3 (src/ejabberd_auth.erl, line 187)
How to resolve the issue?
You do not seem to have the stringprep dependency installed. the p1_stringprep (https://github.com/processone/stringprep) dependency is downloaded automatically during build or included in official packages.
Your error suggest an incorrectly build or incorrectly installed ejabberd.

Erlang: misunderstanding of an error that is connected with ranch

I am trying to make this application FIX protocol
I start the Erlang shell using erl -pa ./ebin -pa ebin ./deps/*/ebin.
And run the application like this: application:start(fix).
After that I invoke "start_listener" function like this: fix:start_listener().
As a result this mistake appears:
exception error: no match of right hand side value
{error,
{{shutdown,
{failed_to_start_child,ranch_acceptors_sup,
badarg}},
{child,undefined,
{ranch_listener_sup,fix_listener},
{ranch_listener_sup,start_link,
[fix_listener,10,ranch_tcp,
[{port,[8501]}],
fix_server,[]]},
permanent,5000,supervisor,
[ranch_listener_sup]}}}
in function fix:start_listener/0 (src/fix.erl, line 21)
What does it all mean? And how to fix this mistake?
My code is:
`-module(fix).
-author('Max Lapshin <max#maxidoors.ru>').
-include("log.hrl").
% -include("../include/admin.hrl").
-include("../include/business.hrl").
-compile(export_all).
%% #doc Start acceptor with `ranch' on port, specified in application environment under fix_port%%
-spec start_listener() -> {ok, pid()}.
start_listener() ->
application:start(ranch),
Spec = ranch:child_spec(fix_listener, 10,
ranch_tcp, [{port, fix:get_value(fix_port)}],
fix_server, []
),
{ok, Pid} = supervisor:start_child(fix_sup, Spec),
error_logger:info_msg("Starting FIX server on port ~p~n",[fix:get_value(fix_port)]),
{ok, Pid}.
`
This is a piece of code that shows a mistake.
This is incorrect:
[{port,[8501]}]
Port value must be an integer.
Your fix:get_value function returns list [8501] instead 8501 and you get this badarg error.

Getting DynamoDB working from Erlang

I am trying to use the Erlang ddb module to interface with amazon's DynamoDB and I am getting a strange error while trying to set things up. I call ddb_iam:credentials() and it returns 'ok', but the ddb_iam:token() function crashes with an error as such: (this example is taken right from the manual page.
ddb_iam:credentials(AccessKey, SecretKey).
{ok, Key, Secret, Token} = ddb_iam:token(129600).
** exception error: bad argument
in function ets:lookup/2
called as ets:lookup(ibrowse_lb,{"sts.amazonaws.com",443})
in call from ibrowse:send_req/6 (src/ibrowse.erl, line 313)
in call from ddb_aws:retry/4 (src/ddb_aws.erl, line 50)
in call from ddb_iam:token/1 (src/ddb_iam.erl, line 63)
8>
It sounds like ibrowse is not started:
ibrowse:start().

Resources