Merge pull request #4131 from emqx/dev/v4.3.0
Auto-pull-request-on-2021-02-01
This commit is contained in:
commit
3e1b6394f2
|
@ -326,8 +326,8 @@ jobs:
|
|||
run: |
|
||||
set -e -x -u
|
||||
version=$(echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g")
|
||||
curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip -q awscliv2.zip
|
||||
sudo ./aws/install
|
||||
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
|
|
|
@ -300,7 +300,7 @@ do_update_resource(#{id := Id, type := Type, description := NewDescription, conf
|
|||
cluster_call(init_resource, [Module, Create, Id, Config]),
|
||||
emqx_rule_registry:add_resource(Resource);
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
error({error, Reason})
|
||||
end
|
||||
end.
|
||||
|
||||
|
|
|
@ -273,6 +273,8 @@ do_create_resource(Create, ParsedParams) ->
|
|||
return({ok, record_to_map(Resource)});
|
||||
{error, {resource_type_not_found, Type}} ->
|
||||
return({error, 400, ?ERR_NO_RESOURCE_TYPE(Type)});
|
||||
{error, {init_resource_failure, _}} ->
|
||||
return({error, 500, <<"Init resource failure!">>});
|
||||
{error, Reason} ->
|
||||
?LOG(error, "~p failed: ~0p", [?FUNCTION_NAME, Reason]),
|
||||
return({error, 400, ?ERR_BADARGS(Reason)})
|
||||
|
|
|
@ -196,6 +196,10 @@ on_resource_create(ResId, Conf) ->
|
|||
{ok, _} = application:ensure_all_started(ehttpc),
|
||||
Options = pool_opts(Conf),
|
||||
PoolName = pool_name(ResId),
|
||||
case test_http_connect(Conf) of
|
||||
true -> ok;
|
||||
false -> error({error, check_http_connectivity_failed})
|
||||
end,
|
||||
start_resource(ResId, PoolName, Options),
|
||||
Conf#{<<"pool">> => PoolName, options => Options}.
|
||||
|
||||
|
@ -214,15 +218,8 @@ start_resource(ResId, PoolName, Options) ->
|
|||
end.
|
||||
|
||||
-spec(on_get_resource_status(binary(), map()) -> map()).
|
||||
on_get_resource_status(ResId, #{<<"url">> := Url}) ->
|
||||
#{is_alive =>
|
||||
case emqx_rule_utils:http_connectivity(Url) of
|
||||
ok -> true;
|
||||
{error, Reason} ->
|
||||
?LOG(error, "Connectivity Check for ~p failed, ResId: ~p, ~0p",
|
||||
[?RESOURCE_TYPE_WEBHOOK, ResId, Reason]),
|
||||
false
|
||||
end}.
|
||||
on_get_resource_status(_ResId, Conf) ->
|
||||
#{is_alive => test_http_connect(Conf)}.
|
||||
|
||||
-spec(on_resource_destroy(binary(), map()) -> ok | {error, Reason::term()}).
|
||||
on_resource_destroy(ResId, #{<<"pool">> := PoolName}) ->
|
||||
|
@ -385,4 +382,19 @@ parse_host(Host) ->
|
|||
{ok, _} -> {inet6, Host};
|
||||
{error, _} -> {inet, Host}
|
||||
end
|
||||
end.
|
||||
|
||||
test_http_connect(Conf) ->
|
||||
Url = fun() -> maps:get(<<"url">>, Conf) end,
|
||||
try
|
||||
emqx_rule_utils:http_connectivity(Url())
|
||||
of
|
||||
ok -> true;
|
||||
{error, _Reason} ->
|
||||
?LOG(error, "check http_connectivity failed: ~p", [Url()]),
|
||||
false
|
||||
catch
|
||||
Err:Reason:ST ->
|
||||
?LOG(error, "check http_connectivity failed: ~p, ~0p", [Conf, {Err, Reason, ST}]),
|
||||
false
|
||||
end.
|
Loading…
Reference in New Issue