FS-3764 --resolve

This commit is contained in:
Anthony Minessale 2011-12-14 13:23:54 -06:00
parent f7f9a43a40
commit 6e7d44af42
6 changed files with 122 additions and 29 deletions

View File

@ -25,7 +25,7 @@
* *
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC) * Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
* * Joseph Sullivan <jossulli@amazon.com>
* *
* switch_core.h -- Core Library * switch_core.h -- Core Library
* *
@ -1955,6 +1955,18 @@ SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel_t channel);
*/ */
SWITCH_DECLARE(switch_bool_t) switch_core_ready(void); SWITCH_DECLARE(switch_bool_t) switch_core_ready(void);
/*!
\brief Determines if the core is ready to take inbound calls
\return SWITCH_TRUE or SWITCH_FALSE
*/
SWITCH_DECLARE(switch_bool_t) switch_core_ready_inbound(void);
/*!
\brief Determines if the core is ready to place outbound calls
\return SWITCH_TRUE or SWITCH_FALSE
*/
SWITCH_DECLARE(switch_bool_t) switch_core_ready_outbound(void);
/*! /*!
\brief return core flags \brief return core flags
\return core flags \return core flags

View File

@ -25,6 +25,7 @@
* *
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Bret McDanel <trixter AT 0xdecafbad dot com> * Bret McDanel <trixter AT 0xdecafbad dot com>
* Joseph Sullivan <jossulli@amazon.com>
* *
* switch_types.h -- Data Types * switch_types.h -- Data Types
* *
@ -293,25 +294,27 @@ typedef uint32_t switch_eavesdrop_flag_t;
typedef enum { typedef enum {
SCF_NONE = 0, SCF_NONE = 0,
SCF_USE_SQL = (1 << 0), SCF_USE_SQL = (1 << 0),
SCF_NO_NEW_SESSIONS = (1 << 1), SCF_NO_NEW_OUTBOUND_SESSIONS = (1 << 1),
SCF_SHUTTING_DOWN = (1 << 2), SCF_NO_NEW_INBOUND_SESSIONS = (1 << 2),
SCF_VG = (1 << 3), SCF_NO_NEW_SESSIONS = (SCF_NO_NEW_OUTBOUND_SESSIONS | SCF_NO_NEW_INBOUND_SESSIONS),
SCF_RESTART = (1 << 4), SCF_SHUTTING_DOWN = (1 << 3),
SCF_SHUTDOWN_REQUESTED = (1 << 5), SCF_VG = (1 << 4),
SCF_USE_AUTO_NAT = (1 << 6), SCF_RESTART = (1 << 5),
SCF_EARLY_HANGUP = (1 << 7), SCF_SHUTDOWN_REQUESTED = (1 << 6),
SCF_CALIBRATE_CLOCK = (1 << 8), SCF_USE_AUTO_NAT = (1 << 7),
SCF_USE_HEAVY_TIMING = (1 << 9), SCF_EARLY_HANGUP = (1 << 8),
SCF_USE_CLOCK_RT = (1 << 10), SCF_CALIBRATE_CLOCK = (1 << 9),
SCF_VERBOSE_EVENTS = (1 << 11), SCF_USE_HEAVY_TIMING = (1 << 10),
SCF_USE_WIN32_MONOTONIC = (1 << 12), SCF_USE_CLOCK_RT = (1 << 11),
SCF_AUTO_SCHEMAS = (1 << 13), SCF_VERBOSE_EVENTS = (1 << 12),
SCF_MINIMAL = (1 << 14), SCF_USE_WIN32_MONOTONIC = (1 << 13),
SCF_USE_NAT_MAPPING = (1 << 15), SCF_AUTO_SCHEMAS = (1 << 14),
SCF_CLEAR_SQL = (1 << 16), SCF_MINIMAL = (1 << 15),
SCF_THREADED_SYSTEM_EXEC = (1 << 17), SCF_USE_NAT_MAPPING = (1 << 16),
SCF_SYNC_CLOCK_REQUESTED = (1 << 18), SCF_CLEAR_SQL = (1 << 17),
SCF_CORE_ODBC_REQ = (1 << 19) SCF_THREADED_SYSTEM_EXEC = (1 << 18),
SCF_SYNC_CLOCK_REQUESTED = (1 << 19),
SCF_CORE_ODBC_REQ = (1 << 20)
} switch_core_flag_enum_t; } switch_core_flag_enum_t;
typedef uint32_t switch_core_flag_t; typedef uint32_t switch_core_flag_t;
@ -1689,6 +1692,8 @@ typedef enum {
typedef enum { typedef enum {
SCSC_PAUSE_INBOUND, SCSC_PAUSE_INBOUND,
SCSC_PAUSE_OUTBOUND,
SCSC_PAUSE_ALL,
SCSC_HUPALL, SCSC_HUPALL,
SCSC_SHUTDOWN, SCSC_SHUTDOWN,
SCSC_CHECK_RUNNING, SCSC_CHECK_RUNNING,
@ -1714,6 +1719,8 @@ typedef enum {
SCSC_MIN_IDLE_CPU, SCSC_MIN_IDLE_CPU,
SCSC_VERBOSE_EVENTS, SCSC_VERBOSE_EVENTS,
SCSC_SHUTDOWN_CHECK, SCSC_SHUTDOWN_CHECK,
SCSC_PAUSE_INBOUND_CHECK,
SCSC_PAUSE_OUTBOUND_CHECK,
SCSC_PAUSE_CHECK, SCSC_PAUSE_CHECK,
SCSC_READY_CHECK, SCSC_READY_CHECK,
SCSC_THREADED_SYSTEM_EXEC, SCSC_THREADED_SYSTEM_EXEC,

View File

@ -32,6 +32,7 @@
* Cesar Cepeda <cesar@auronix.com> * Cesar Cepeda <cesar@auronix.com>
* Massimo Cetra <devel@navynet.it> * Massimo Cetra <devel@navynet.it>
* Rupa Schomaker <rupa@rupa.com> * Rupa Schomaker <rupa@rupa.com>
* Joseph Sullivan <jossulli@amazon.com>
* *
* *
* mod_commands.c -- Misc. Command Module * mod_commands.c -- Misc. Command Module
@ -1792,7 +1793,7 @@ SWITCH_STANDARD_API(status_function)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
#define CTL_SYNTAX "[send_sighup|hupall|pause|resume|shutdown [cancel|elegant|asap|now|restart]|sps|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]" #define CTL_SYNTAX "[send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]"
SWITCH_STANDARD_API(ctl_function) SWITCH_STANDARD_API(ctl_function)
{ {
int argc; int argc;
@ -1815,16 +1816,32 @@ SWITCH_STANDARD_API(ctl_function)
switch_core_session_ctl(SCSC_FLUSH_DB_HANDLES, NULL); switch_core_session_ctl(SCSC_FLUSH_DB_HANDLES, NULL);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "pause")) { } else if (!strcasecmp(argv[0], "pause")) {
switch_session_ctl_t command = SCSC_PAUSE_ALL;
arg = 1; arg = 1;
switch_core_session_ctl(SCSC_PAUSE_INBOUND, &arg); if (argv[1]) {
if (!strcasecmp(argv[1], "inbound")) {
command = SCSC_PAUSE_INBOUND;
} else if (!strcasecmp(argv[1], "outbound")) {
command = SCSC_PAUSE_OUTBOUND;
}
}
switch_core_session_ctl(command, &arg);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "send_sighup")) { } else if (!strcasecmp(argv[0], "send_sighup")) {
arg = 1; arg = 1;
switch_core_session_ctl(SCSC_SEND_SIGHUP, &arg); switch_core_session_ctl(SCSC_SEND_SIGHUP, &arg);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "resume")) { } else if (!strcasecmp(argv[0], "resume")) {
switch_session_ctl_t command = SCSC_PAUSE_ALL;
arg = 0; arg = 0;
switch_core_session_ctl(SCSC_PAUSE_INBOUND, &arg); if (argv[1]) {
if (!strcasecmp(argv[1], "inbound")) {
command = SCSC_PAUSE_INBOUND;
} else if (!strcasecmp(argv[1], "outbound")) {
command = SCSC_PAUSE_OUTBOUND;
}
}
switch_core_session_ctl(command, &arg);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "calibrate_clock")) { } else if (!strcasecmp(argv[0], "calibrate_clock")) {
switch_core_session_ctl(SCSC_CALIBRATE_CLOCK, NULL); switch_core_session_ctl(SCSC_CALIBRATE_CLOCK, NULL);
@ -1855,7 +1872,15 @@ SWITCH_STANDARD_API(ctl_function)
switch_core_session_ctl(SCSC_SAVE_HISTORY, NULL); switch_core_session_ctl(SCSC_SAVE_HISTORY, NULL);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "pause_check")) { } else if (!strcasecmp(argv[0], "pause_check")) {
switch_core_session_ctl(SCSC_PAUSE_CHECK, &arg); switch_session_ctl_t command = SCSC_PAUSE_CHECK;
if (argv[1]) {
if (!strcasecmp(argv[1], "inbound")) {
command = SCSC_PAUSE_INBOUND_CHECK;
} else if (!strcasecmp(argv[1], "outbound")) {
command = SCSC_PAUSE_OUTBOUND_CHECK;
}
}
switch_core_session_ctl(command, &arg);
stream->write_function(stream, arg ? "true" : "false"); stream->write_function(stream, arg ? "true" : "false");
} else if (!strcasecmp(argv[0], "ready_check")) { } else if (!strcasecmp(argv[0], "ready_check")) {
switch_core_session_ctl(SCSC_READY_CHECK, &arg); switch_core_session_ctl(SCSC_READY_CHECK, &arg);
@ -5431,13 +5456,19 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add fsctl max_sessions"); switch_console_set_complete("add fsctl max_sessions");
switch_console_set_complete("add fsctl min_dtmf_duration"); switch_console_set_complete("add fsctl min_dtmf_duration");
switch_console_set_complete("add fsctl pause"); switch_console_set_complete("add fsctl pause");
switch_console_set_complete("add fsctl pause inbound");
switch_console_set_complete("add fsctl pause outbound");
switch_console_set_complete("add fsctl reclaim_mem"); switch_console_set_complete("add fsctl reclaim_mem");
switch_console_set_complete("add fsctl resume"); switch_console_set_complete("add fsctl resume");
switch_console_set_complete("add fsctl resume inbound");
switch_console_set_complete("add fsctl resume outbound");
switch_console_set_complete("add fsctl calibrate_clock"); switch_console_set_complete("add fsctl calibrate_clock");
switch_console_set_complete("add fsctl crash"); switch_console_set_complete("add fsctl crash");
switch_console_set_complete("add fsctl verbose_events"); switch_console_set_complete("add fsctl verbose_events");
switch_console_set_complete("add fsctl save_history"); switch_console_set_complete("add fsctl save_history");
switch_console_set_complete("add fsctl pause_check"); switch_console_set_complete("add fsctl pause_check");
switch_console_set_complete("add fsctl pause_check inbound");
switch_console_set_complete("add fsctl pause_check outbound");
switch_console_set_complete("add fsctl ready_check"); switch_console_set_complete("add fsctl ready_check");
switch_console_set_complete("add fsctl shutdown_check"); switch_console_set_complete("add fsctl shutdown_check");
switch_console_set_complete("add fsctl shutdown"); switch_console_set_complete("add fsctl shutdown");

View File

@ -31,6 +31,7 @@
* Norman Brandinger * Norman Brandinger
* Raymond Chandler <intralanman@gmail.com> * Raymond Chandler <intralanman@gmail.com>
* Nathan Patrick <npatrick at corp.sonic.net> * Nathan Patrick <npatrick at corp.sonic.net>
* Joseph Sullivan <jossulli@amazon.com>
* *
* *
* sofia.c -- SOFIA SIP Endpoint (sofia code) * sofia.c -- SOFIA SIP Endpoint (sofia code)
@ -936,7 +937,7 @@ static void our_sofia_event_callback(nua_event_t event,
uint32_t sess_count = switch_core_session_count(); uint32_t sess_count = switch_core_session_count();
uint32_t sess_max = switch_core_session_limit(0); uint32_t sess_max = switch_core_session_limit(0);
if (sess_count >= sess_max || !sofia_test_pflag(profile, PFLAG_RUNNING) || !switch_core_ready()) { if (sess_count >= sess_max || !sofia_test_pflag(profile, PFLAG_RUNNING) || !switch_core_ready_inbound()) {
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No more sessions allowed at this time.\n"); //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No more sessions allowed at this time.\n");
@ -8351,7 +8352,7 @@ void sofia_handle_sip_i_options(int status,
uint32_t sess_max = switch_core_session_limit(0); uint32_t sess_max = switch_core_session_limit(0);
if (sofia_test_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY) && if (sofia_test_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY) &&
(sess_count >= sess_max || !sofia_test_pflag(profile, PFLAG_RUNNING) || !switch_core_ready())) { (sess_count >= sess_max || !sofia_test_pflag(profile, PFLAG_RUNNING) || !switch_core_ready_inbound())) {
nua_respond(nh, 503, "Maximum Calls In Progress", NUTAG_WITH_THIS_MSG(de->data->e_msg), SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); nua_respond(nh, 503, "Maximum Calls In Progress", NUTAG_WITH_THIS_MSG(de->data->e_msg), SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
} else { } else {
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END()); nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());

View File

@ -27,6 +27,7 @@
* Michael Jerris <mike@jerris.com> * Michael Jerris <mike@jerris.com>
* Paul D. Tinsley <pdt at jackhammer.org> * Paul D. Tinsley <pdt at jackhammer.org>
* Marcel Barbulescu <marcelbarbulescu@gmail.com> * Marcel Barbulescu <marcelbarbulescu@gmail.com>
* Joseph Sullivan <jossulli@amazon.com>
* *
* *
* switch_core.c -- Main Core Library * switch_core.c -- Main Core Library
@ -2000,13 +2001,27 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
case SCSC_SYNC_CLOCK_WHEN_IDLE: case SCSC_SYNC_CLOCK_WHEN_IDLE:
newintval = switch_core_session_sync_clock(); newintval = switch_core_session_sync_clock();
break; break;
case SCSC_PAUSE_INBOUND: case SCSC_PAUSE_ALL:
if (oldintval) { if (oldintval) {
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS); switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
} else { } else {
switch_clear_flag((&runtime), SCF_NO_NEW_SESSIONS); switch_clear_flag((&runtime), SCF_NO_NEW_SESSIONS);
} }
break; break;
case SCSC_PAUSE_INBOUND:
if (oldintval) {
switch_set_flag((&runtime), SCF_NO_NEW_INBOUND_SESSIONS);
} else {
switch_clear_flag((&runtime), SCF_NO_NEW_INBOUND_SESSIONS);
}
break;
case SCSC_PAUSE_OUTBOUND:
if (oldintval) {
switch_set_flag((&runtime), SCF_NO_NEW_OUTBOUND_SESSIONS);
} else {
switch_clear_flag((&runtime), SCF_NO_NEW_OUTBOUND_SESSIONS);
}
break;
case SCSC_HUPALL: case SCSC_HUPALL:
switch_core_session_hupall(SWITCH_CAUSE_MANAGER_REQUEST); switch_core_session_hupall(SWITCH_CAUSE_MANAGER_REQUEST);
break; break;
@ -2069,7 +2084,13 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
} }
break; break;
case SCSC_PAUSE_CHECK: case SCSC_PAUSE_CHECK:
newintval = !!switch_test_flag((&runtime), SCF_NO_NEW_SESSIONS); newintval = !!(switch_test_flag((&runtime), SCF_NO_NEW_SESSIONS) == SCF_NO_NEW_SESSIONS);
break;
case SCSC_PAUSE_INBOUND_CHECK:
newintval = !!switch_test_flag((&runtime), SCF_NO_NEW_INBOUND_SESSIONS);
break;
case SCSC_PAUSE_OUTBOUND_CHECK:
newintval = !!switch_test_flag((&runtime), SCF_NO_NEW_OUTBOUND_SESSIONS);
break; break;
case SCSC_READY_CHECK: case SCSC_READY_CHECK:
newintval = switch_core_ready(); newintval = switch_core_ready();
@ -2169,7 +2190,17 @@ SWITCH_DECLARE(switch_core_flag_t) switch_core_flags(void)
SWITCH_DECLARE(switch_bool_t) switch_core_ready(void) SWITCH_DECLARE(switch_bool_t) switch_core_ready(void)
{ {
return (switch_test_flag((&runtime), SCF_SHUTTING_DOWN) || switch_test_flag((&runtime), SCF_NO_NEW_SESSIONS)) ? SWITCH_FALSE : SWITCH_TRUE; return (switch_test_flag((&runtime), SCF_SHUTTING_DOWN) || switch_test_flag((&runtime), SCF_NO_NEW_SESSIONS) == SCF_NO_NEW_SESSIONS) ? SWITCH_FALSE : SWITCH_TRUE;
}
SWITCH_DECLARE(switch_bool_t) switch_core_ready_inbound(void)
{
return (switch_test_flag((&runtime), SCF_SHUTTING_DOWN) || switch_test_flag((&runtime), SCF_NO_NEW_INBOUND_SESSIONS)) ? SWITCH_FALSE : SWITCH_TRUE;
}
SWITCH_DECLARE(switch_bool_t) switch_core_ready_outbound(void)
{
return (switch_test_flag((&runtime), SCF_SHUTTING_DOWN) || switch_test_flag((&runtime), SCF_NO_NEW_OUTBOUND_SESSIONS)) ? SWITCH_FALSE : SWITCH_TRUE;
} }
SWITCH_DECLARE(switch_status_t) switch_core_destroy(void) SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)

View File

@ -26,6 +26,7 @@
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Michael Jerris <mike@jerris.com> * Michael Jerris <mike@jerris.com>
* Paul D. Tinsley <pdt at jackhammer.org> * Paul D. Tinsley <pdt at jackhammer.org>
* Joseph Sullivan <jossulli@amazon.com>
* *
* *
* switch_core_session.c -- Main Core Library (session routines) * switch_core_session.c -- Main Core Library (session routines)
@ -1781,6 +1782,16 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_
return NULL; return NULL;
} }
if (direction == SWITCH_CALL_DIRECTION_INBOUND && !switch_core_ready_inbound()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any inbound sessions at this time.\n");
return NULL;
}
if (direction == SWITCH_CALL_DIRECTION_OUTBOUND && !switch_core_ready_outbound()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any outbound sessions at this time.\n");
return NULL;
}
if (!switch_core_ready() || endpoint_interface == NULL) { if (!switch_core_ready() || endpoint_interface == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any sessions at this time.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any sessions at this time.\n");
return NULL; return NULL;