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,10 @@ stop_scenario() ->
107108update_settings (Settings ) ->
108109 gen_server :call (? SERVER , {update_settings , Settings }).
109110
111+ -spec propagate_config (node (), amoc_config :config ()) -> ok .
112+ propagate_config (Node , Config ) ->
113+ gen_server :cast ({? SERVER , Node }, {propagate_config , Config }).
114+
110115-spec add_users (amoc_scenario :user_id (), amoc_scenario :user_id ()) ->
111116 ok | {error , term ()}.
112117add_users (StartId , EndId ) ->
@@ -123,9 +128,9 @@ get_status() ->
123128 {ok , Status } = gen_server :call (? SERVER , get_status ),
124129 Status .
125130
126- -spec disable () -> ok | {error , term ()}.
127- disable () ->
128- gen_server :call (? SERVER , disable ).
131+ -spec disable (amoc : scenario (), amoc_config : settings () ) -> ok | {error , term ()}.
132+ disable (Scenario , Settings ) ->
133+ gen_server :call (? SERVER , { disable , Scenario , Settings } ).
129134
130135% % @private
131136-spec verify_user_rate (any ()) -> boolean ().
@@ -178,8 +183,8 @@ handle_call({remove, Count, ForceRemove}, _From, State) ->
178183handle_call (get_status , _From , State ) ->
179184 RetValue = handle_status (State ),
180185 {reply , {ok , RetValue }, State };
181- handle_call (disable , _From , State ) ->
182- {RetValue , NewState } = handle_disable (State ),
186+ handle_call ({ disable , Scenario , Settings } , _From , State ) ->
187+ {RetValue , NewState } = handle_disable (Scenario , Settings , State ),
183188 {reply , RetValue , NewState };
184189handle_call (_Request , _From , State ) ->
185190 {reply , {error , not_implemented }, State }.
@@ -189,6 +194,9 @@ handle_call(_Request, _From, State) ->
189194handle_cast (zero_users_running , State ) ->
190195 NewSate = handle_zero_users_running (State ),
191196 {noreply , NewSate };
197+ handle_cast ({propagate_config , Config }, State ) ->
198+ handle_propagate_config (Config ),
199+ {noreply , State };
192200handle_cast (_Msg , State ) ->
193201 {noreply , State }.
194202
@@ -236,14 +244,19 @@ handle_stop_scenario(#state{status = Status} = State) ->
236244 {{error , {invalid_status , Status }}, State }.
237245
238246-spec handle_update_settings (amoc_config :settings (), state ()) -> handle_call_res ().
239- handle_update_settings (Settings , # state {status = running }) ->
247+ handle_update_settings (Settings , # state {status = Status }) when Status =:= disabled ;
248+ Status =:= running ->
240249 case amoc_config_scenario :update_settings (Settings ) of
241250 ok -> ok ;
242251 {error , Type , Reason } -> {error , {Type , Reason }}
243252 end ;
244253handle_update_settings (_Settings , # state {status = Status }) ->
245254 {error , {invalid_status , Status }}.
246255
256+ -spec handle_propagate_config (amoc_config :config ()) -> ok .
257+ handle_propagate_config (Config ) ->
258+ amoc_config_utils :store_scenario_config (Config ).
259+
247260-spec handle_add (amoc_scenario :user_id (), amoc_scenario :user_id (), state ()) ->
248261 {handle_call_res (), state ()}.
249262handle_add (StartId , EndId , # state {status = running ,
@@ -281,10 +294,14 @@ handle_status(#state{status = finished, scenario = Scenario}) ->
281294handle_status (# state {status = Status }) ->
282295 Status . % % idle, disabled or {error, Reason}.
283296
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 ) ->
297+ -spec handle_disable (amoc :scenario (), amoc_config :settings (), state ()) ->
298+ {handle_call_res (), state ()}.
299+ handle_disable (Scenario , Settings , # state {status = idle } = State ) ->
300+ case amoc_config_scenario :parse_scenario_settings (Scenario , Settings ) of
301+ ok -> {ok , State # state {status = disabled }};
302+ {error , Type , Reason } -> {error , {Type , Reason }}
303+ end ;
304+ handle_disable (_Scenario , _Settings , # state {status = Status } = State ) ->
288305 {{error , {invalid_status , Status }}, State }.
289306
290307% % ------------------------------------------------------------------
0 commit comments