1111-define (DEFAULT_USER_RATE , 1200 ).
1212
1313-required_variable (#{name => user_rate , default_value => ? DEFAULT_USER_RATE ,
14- verification => {? MODULE , verify_user_rate , 1 },
14+ verification => {? MODULE , verify_user_rate , 1 }, scope => global ,
1515 description => " Throttle rate for the Scenario:start/1,2 callback" ,
1616 update => {? MODULE , update_user_rate , 2 }}).
1717
6363 start_scenario /2 ,
6464 stop_scenario /0 ,
6565 update_settings /1 ,
66+ propagate_config /2 ,
6667 add_users /2 ,
6768 remove_users /2 ,
6869 get_status /0 ,
69- disable /0 ]).
70+ disable /2 ]).
7071
7172% % ------------------------------------------------------------------
7273% % Parameters verification functions
@@ -107,6 +108,11 @@ stop_scenario() ->
107108update_settings (Settings ) ->
108109 gen_server :call (? SERVER , {update_settings , Settings }).
109110
111+ -spec propagate_config (node (), amoc_config :config ()) ->
112+ ok | {error , term ()}.
113+ propagate_config (Node , Config ) ->
114+ gen_server :cast ({? SERVER , Node }, {propagate_config , Config }).
115+
110116-spec add_users (amoc_scenario :user_id (), amoc_scenario :user_id ()) ->
111117 ok | {error , term ()}.
112118add_users (StartId , EndId ) ->
@@ -123,9 +129,9 @@ get_status() ->
123129 {ok , Status } = gen_server :call (? SERVER , get_status ),
124130 Status .
125131
126- -spec disable () -> ok | {error , term ()}.
127- disable () ->
128- gen_server :call (? SERVER , disable ).
132+ -spec disable (amoc : scenario (), amoc_config : settings () ) -> ok | {error , term ()}.
133+ disable (Scenario , Settings ) ->
134+ gen_server :call (? SERVER , { disable , Scenario , Settings } ).
129135
130136% % @private
131137-spec verify_user_rate (any ()) -> boolean ().
@@ -178,8 +184,8 @@ handle_call({remove, Count, ForceRemove}, _From, State) ->
178184handle_call (get_status , _From , State ) ->
179185 RetValue = handle_status (State ),
180186 {reply , {ok , RetValue }, State };
181- handle_call (disable , _From , State ) ->
182- {RetValue , NewState } = handle_disable (State ),
187+ handle_call ({ disable , Scenario , Settings } , _From , State ) ->
188+ {RetValue , NewState } = handle_disable (Scenario , Settings , State ),
183189 {reply , RetValue , NewState };
184190handle_call (_Request , _From , State ) ->
185191 {reply , {error , not_implemented }, State }.
@@ -189,6 +195,9 @@ handle_call(_Request, _From, State) ->
189195handle_cast (zero_users_running , State ) ->
190196 NewSate = handle_zero_users_running (State ),
191197 {noreply , NewSate };
198+ handle_cast ({propagate_config , Config }, State ) ->
199+ handle_propagate_config (Config ),
200+ {noreply , State };
192201handle_cast (_Msg , State ) ->
193202 {noreply , State }.
194203
@@ -236,14 +245,19 @@ handle_stop_scenario(#state{status = Status} = State) ->
236245 {{error , {invalid_status , Status }}, State }.
237246
238247-spec handle_update_settings (amoc_config :settings (), state ()) -> handle_call_res ().
239- handle_update_settings (Settings , # state {status = running }) ->
248+ handle_update_settings (Settings , # state {status = Status }) when Status =:= disabled ;
249+ Status =:= running ->
240250 case amoc_config_scenario :update_settings (Settings ) of
241251 ok -> ok ;
242252 {error , Type , Reason } -> {error , {Type , Reason }}
243253 end ;
244254handle_update_settings (_Settings , # state {status = Status }) ->
245255 {error , {invalid_status , Status }}.
246256
257+ -spec handle_propagate_config (amoc_config :config ()) -> ok .
258+ handle_propagate_config (Config ) ->
259+ amoc_config_utils :store_scenario_config (Config ).
260+
247261-spec handle_add (amoc_scenario :user_id (), amoc_scenario :user_id (), state ()) ->
248262 {handle_call_res (), state ()}.
249263handle_add (StartId , EndId , # state {status = running ,
@@ -281,10 +295,14 @@ handle_status(#state{status = finished, scenario = Scenario}) ->
281295handle_status (# state {status = Status }) ->
282296 Status . % % idle, disabled or {error, Reason}.
283297
284- -spec handle_disable (state ()) -> {handle_call_res (), state ()}.
285- handle_disable (# state {status = idle } = State ) ->
286- {ok , State # state {status = disabled }};
287- handle_disable (# state {status = Status } = State ) ->
298+ -spec handle_disable (amoc :scenario (), amoc_config :settings (), state ()) ->
299+ {handle_call_res (), state ()}.
300+ handle_disable (Scenario , Settings , # state {status = idle } = State ) ->
301+ case amoc_config_scenario :parse_scenario_settings (Scenario , Settings ) of
302+ ok -> {ok , State # state {status = disabled }};
303+ {error , Type , Reason } -> {error , {Type , Reason }}
304+ end ;
305+ handle_disable (_Scenario , _Settings , # state {status = Status } = State ) ->
288306 {{error , {invalid_status , Status }}, State }.
289307
290308% % ------------------------------------------------------------------
0 commit comments