The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [4.0.7] - Sep 12 2017
+* Further unit testing
+* Update dependency to a Leptus PR that fixes the CORS port issue
+
## [4.0.6] - Sep 11 2017
* Get meck working for better unit tests
* More unit tests
#!/usr/local/bin/fish
rm -rf /tmp/log/cdapbroker/*;
+rm -rf _build/;
+rebar3 upgrade;
rebar3 release;
set -x CDAP_CLUSTER_TO_MANAGE "cdap";
set -x CONSUL_HOST "XXXX";
#!/usr/local/bin/fish
rm -rf /tmp/log/cdapbroker/*;
+rm -rf _build/*
+rebar3 upgrade;
rebar3 release;
set -x NEXUS_RAW_ROOT "XXXX";
set -x CDAP_CLUSTER_TO_MANAGE "cdap";
{relx, [
{release,
- {cdapbroker,"4.0.6"},
+ {cdapbroker,"4.0.7"},
[cdapbroker]
},
%{extend_start_script,true},
{deps, [
{jiffy, ".*", {git, "git://github.com/davisp/jiffy.git", {branch, "master"}}},
%{leptus, ".*", {git, "git://github.com/s1n4/leptus.git", {branch, "master"}}},
- {leptus, ".*", {git, "git://github.com/tommyjcarpenter/leptus.git", {branch, "version"}}},
+ {leptus, ".*", {git, "git://github.com/tommyjcarpenter/leptus.git", {branch, "master"}}},
{lager, ".*", {git, "git://github.com/basho/lager.git", {branch, "master"}}},
%generate RFC compliant UUIDs
{uuid, ".*", {git, "https://github.com/avtobiff/erlang-uuid.git", {branch, "master"}}},
{application, cdapbroker,
[{description, "Interface between Consul and CDAP in DCAE"},
- {vsn, "4.0.6"},
+ {vsn, "4.0.7"},
{registered, []},
{mod, { cdapbroker_app, []}},
{applications,
-export([get/3, put/3, delete/3, post/3]).
-export([cross_domains/3]).
--export([appname_to_field_vals/2]).
-
%%for keeping state
%%The application record is defined in application.hrl
%%In Mnesia, the first element is the type of record and the second element is the key
%lazy shorthand to write info audit records. man I miss defines in python. c ftw.
-define(AUDI(Req, Bts, XER, Rcode), audit(info, Req, [{bts, Bts}, {xer,XER}, {rcode, RCode}, {mod, mod()}])).
+%need this for the ?MODULE:FUNCTION to work with meck unit tests
+-export([delete_app_helper/4, appname_to_field_vals/2]).
%%%
%%Helper functions
end
end.
+handle_post_multidelete_app(Req, State, XER, ReqBody) ->
+ %handler method for the multi delete post ala AWS
+ case
+ try
+ B = maps:get(<<"appnames">>, jiffy:decode(ReqBody, [return_maps])),
+ true = erlang:is_list(B),
+ B
+ catch _:_ ->
+ invalid
+ end
+ of
+ invalid -> {400, "Invalid PUT Body", State};
+ IDs ->
+ case IDs of
+ [] -> {200, "EMPTY PUT BODY", State};
+ _ ->
+ %<<"*">> ->
+ %this block deleted all apps, but decided this backdoor wasn't very RESTy
+ %% {atomic, Apps} = mnesia:transaction(fun() -> mnesia:match_object(application, {application, '_', '_', '_', '_', '_', '_', '_', '_', '_'}, read) end),
+ % AppsToDelete = lists:map(fun(X) -> {application, Appname, _,_,_,_,_,_,_,_} = X, Appname end, Apps),
+ Returns = lists:map(fun(X) -> ?MODULE:delete_app_helper(X, State, XER, Req) end, IDs),
+ RL = lists:map(fun({RC, _, _}) -> RC end, Returns),
+ {200, jiffy:encode(RL), State}
+ end
+ end.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% HTTP API CALLBACKS %%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%
init(_Route, _Req, State) ->
{ok, State}.
terminate(_Reason, _Route, _Req, _State) ->
%%%FOR Cors support
%%%Note! only matches on host. Does not handle ports. See: https://github.com/s1n4/leptus/issues/55
cross_domains(_Route, _Req, State) ->
- {['_'], State}.
-
+ {['_'], State}.
%%%GET Methods
get("/", Req, State) ->
%The broker's "info" endpoint; returns some possibly useful information
{RCode, RBody, RState} = handle_reconfigure_put(Req, State, XER, Appname, ReqBody),
?AUDI(Req, Bts, XER, Rcode),
{RCode, RBody, RState}.
-
%%%POST methods
post("/application/delete", Req, State) ->
%This follows the AWS S3 Multi Key Delete: http://docs.aws.amazon.com/AmazonS3/latest/API/multiobjectdeleteapi.html
- %Except I added an additional special value called "*"
{Bts, XER} = init_api_call(Req),
- {RCode, RBody, RState} = case try
- B = maps:get(<<"appnames">>, jiffy:decode(leptus_req:body_raw(Req), [return_maps])),
- true = erlang:is_list(B),
- B
- catch _:_ ->
- invalid
- end
- of
- invalid -> {400, "Invalid PUT Body", State};
- IDs ->
- case IDs of
- [] -> {200, "EMPTY PUT BODY", State};
- _ ->
- %<<"*">> ->
- %this block deleted all apps, but decided this backdoor wasn't very RESTy
- %% {atomic, Apps} = mnesia:transaction(fun() -> mnesia:match_object(application, {application, '_', '_', '_', '_', '_', '_', '_', '_', '_'}, read) end),
- % AppsToDelete = lists:map(fun(X) -> {application, Appname, _,_,_,_,_,_,_,_} = X, Appname end, Apps),
- Returns = lists:map(fun(X) -> delete_app_helper(X, State, XER, Req) end, IDs),
- RL = lists:map(fun({RC, _, _}) -> RC end, Returns),
- {200, jiffy:encode(RL), State}
- end
- end,
+ ReqBody = leptus_req:body_raw(Req),
+ {RCode, RBody, RState} = handle_post_multidelete_app(Req, State, XER, ReqBody),
?AUDI(Req, Bts, XER, Rcode),
{RCode, RBody, RState}.
parse_put_body/1,
parse_reconfiguration_put_body/1,
handle_reconfigure_put/5,
- handle_put/6
+ handle_put/6,
+ handle_post_multidelete_app/4
]).
-parse_put_body_test() ->
+put_test() ->
Valid = {[
{<<"cdap_application_type">>, <<"program-flowlet">>},
{<<"namespace">>, <<"ns">>},
meck:unload(resource_handler).
+delete_test() ->
+ EmptyD = dict:new(),
+
+ %test failure: appnames missing
+ Invalid1 = jiffy:encode({[{<<"ids">>, [<<"hwtest">>]}]}),
+ ?assert(handle_post_multidelete_app(notused, EmptyD, notused, Invalid1) == {400,"Invalid PUT Body", EmptyD}),
+
+ %test invalid: not a list
+ Invalid2 = jiffy:encode({[{<<"appnames">>, <<"hwtest">>}]}),
+ ?assert(handle_post_multidelete_app(notused, EmptyD, notused, Invalid2) == {400,"Invalid PUT Body", EmptyD}),
+
+ %mock out delete_app_helper(X, State, XER, Req)
+ meck:new(resource_handler, [passthrough]),
+ meck:expect(resource_handler,
+ delete_app_helper,
+ fun(Appname, State, _XER, _Req) ->
+ case Appname of
+ <<"noexist">> -> {404, "Tried to delete an application that was not registered", State};
+ <<"exist">> -> {200, "", State}
+ end
+ end),
+ %est empty
+ Empty = jiffy:encode({[{<<"appnames">>, []}]}),
+ ?assert(handle_post_multidelete_app(notused, EmptyD, notused, Empty) == {200, "EMPTY PUT BODY", EmptyD}),
+
+ %test one app that is registered (in the mock...) and one app that is not regustered
+ Valid = jiffy:encode({[{<<"appnames">>, [<<"exist">>, <<"noexist">>]}]}),
+ ?assert(handle_post_multidelete_app(notused, EmptyD, notused, Valid) == {200, <<"[200,404]">>, EmptyD}),
+ meck:unload(resource_handler).
<body>
<div class="container">
<h1>CDAP Broker API</h1>
- <p class="sw-info">Version: <span class="sw-info-version">4.0.6</span></p>
+ <p class="sw-info">Version: <span class="sw-info-version">4.0.7</span></p>
<p></p>
{
"swagger": "2.0",
"info": {
- "version": "4.0.6",
+ "version": "4.0.7",
"title": "CDAP Broker API"
},
"paths": {
# This is your document metadata
info:
- version: "4.0.6"
+ version: "4.0.7"
title: CDAP Broker API
paths:
-include_lib("common_test/include/ct.hrl").
-include("../../src/application.hrl").
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1]).
--export([server_health_test/1, app_deploy/1, hydrator_deploy/1, app_teardown/1, app_test/1, app_reconfigure/1, test_failures/1, app_botch_flows/1, app_botch_delete/1, app_botch_consul_delete/1, delete_all/1,
+-export([server_health_test/1, app_deploy/1, hydrator_deploy/1, app_teardown/1, app_test/1, app_reconfigure/1, test_failures/1, app_botch_flows/1, app_botch_delete/1, app_botch_consul_delete/1,
hydrator_app_teardown/1, hydrator_test/1,
hydrator_wdeps_deploy/1,
hydrator_wdeps_test/1,
{group, hydratorapi},
{group, apibotchedflows},
{group, apibotcheddeleted},
- {group, apibotchedconsuldeleted},
- {group, apideleteall}
+ {group, apibotchedconsuldeleted}
].
groups() -> [
{progapi, %prog-flow test
app_deploy,
app_botch_consul_delete,
app_teardown
- ]},
- {apideleteall,
- [],
- [
- server_health_test,
- app_deploy,
- delete_all
]}
].
]
.
-end_per_suite(_C) ->
+end_per_suite(C) ->
+ %teardown the fake service and make sure it is gone
+ erlang:display("Tearing down fake service"),
+ {200, Srv} = setup_fake_testing_service(C, teardown),
+ true = Srv == "[]",
_ = application:stop(cdapbroker).
server_health_test(C) ->
{<<"program_preferences">>, [{[{<<"program_type">>,<<"flows">>}, {<<"program_id">>, <<"WhoFlow">>}, {<<"program_pref">>, ?PLG(whoflowpref, C)}]}]}
]},
{404, _} = httpabs:put(?XER, URL, "application/json", jiffy:encode(Body3)).
-
-delete_all(C) ->
- %test invalid key
- Body1 = jiffy:encode({[{<<"ids">>, [<<"hwtest">>]}]}),
- {400,"State: Bad Request. Return Body: Invalid PUT Body"} = httpabs:post(?XER, ?SC([?PLG(broker_url, C), "/application/delete"]), "application/json", Body1),
- %test invalid: not a list
- Body2 = jiffy:encode({[{<<"appnames">>, <<"hwtest">>}]}),
- {400,"State: Bad Request. Return Body: Invalid PUT Body"} = httpabs:post(?XER, ?SC([?PLG(broker_url, C), "/application/delete"]), "application/json", Body2),
- %test undeploy a real app and also an app that is not deployed
- Body3 = jiffy:encode({[{<<"appnames">>, [<<"hwtest">>, <<"dissapointment">>]}]}),
- {200, "[200,404]"} = httpabs:post(?XER, ?SC([?PLG(broker_url, C), "/application/delete"]), "application/json", Body3),
- %teardown the fake service and make sure it is gone
- {200, Srv} = setup_fake_testing_service(C, teardown),
- true = Srv == "[]".
-