mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-19 04:17:44 +00:00
K8s (#57)
* JAMBONES_NETWORK_CIDR not needed for K8S * fix bug setting fsUUID in K8S scenario * bugfix: dial music was not stopped when a dial verb times out (#56)
This commit is contained in:
2
app.js
2
app.js
@@ -7,7 +7,7 @@ assert.ok(process.env.DRACHTIO_PORT || process.env.DRACHTIO_HOST, 'missing DRACH
|
||||
assert.ok(process.env.DRACHTIO_SECRET, 'missing DRACHTIO_SECRET env var');
|
||||
assert.ok(process.env.JAMBONES_FREESWITCH, 'missing JAMBONES_FREESWITCH env var');
|
||||
assert.ok(process.env.JAMBONES_REDIS_HOST, 'missing JAMBONES_REDIS_HOST env var');
|
||||
assert.ok(process.env.JAMBONES_NETWORK_CIDR, 'missing JAMBONES_SUBNET env var');
|
||||
assert.ok(process.env.JAMBONES_NETWORK_CIDR || process.env.K8S, 'missing JAMBONES_SUBNET env var');
|
||||
|
||||
const Srf = require('drachtio-srf');
|
||||
const srf = new Srf();
|
||||
|
||||
@@ -161,6 +161,10 @@ class TaskDial extends Task {
|
||||
|
||||
async kill(cs, reason) {
|
||||
super.kill(cs);
|
||||
if (this.dialMusic && this.epOther) {
|
||||
this.epOther.api('uuid_break', this.epOther.uuid)
|
||||
.catch((err) => this.logger.info(err, 'Error killing dialMusic'));
|
||||
}
|
||||
this.killReason = reason || KillReason.Hangup;
|
||||
if (this.timerMaxCallDuration) {
|
||||
clearTimeout(this.timerMaxCallDuration);
|
||||
|
||||
@@ -5,13 +5,7 @@ const {TaskPreconditions, CallDirection} = require('../utils/constants');
|
||||
const CallInfo = require('../session/call-info');
|
||||
const assert = require('assert');
|
||||
const ConfirmCallSession = require('../session/confirm-call-session');
|
||||
const selectSbc = require('./select-sbc');
|
||||
const Registrar = require('@jambonz/mw-registrar');
|
||||
const AdultingCallSession = require('../session/adulting-call-session');
|
||||
const registrar = new Registrar({
|
||||
host: process.env.JAMBONES_REDIS_HOST,
|
||||
port: process.env.JAMBONES_REDIS_PORT || 6379
|
||||
});
|
||||
const deepcopy = require('deepcopy');
|
||||
const moment = require('moment');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
@@ -89,7 +83,6 @@ class SingleDialer extends Emitter {
|
||||
break;
|
||||
case 'user':
|
||||
assert(this.target.name);
|
||||
const aor = this.target.name;
|
||||
uri = `sip:${this.target.name}`;
|
||||
to = this.target.name;
|
||||
|
||||
@@ -98,16 +91,6 @@ class SingleDialer extends Emitter {
|
||||
'X-Override-To': this.target.overrideTo
|
||||
});
|
||||
}
|
||||
|
||||
// need to send to the SBC registered on
|
||||
const reg = await registrar.query(aor);
|
||||
if (reg) {
|
||||
const sbc = selectSbc(reg.sbcAddress);
|
||||
if (sbc) {
|
||||
this.logger.debug(`SingleDialer:exec retrieved registration details for ${aor}, using sbc at ${sbc}`);
|
||||
this.sbcAddress = sbc;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'sip':
|
||||
assert(this.target.sipUri);
|
||||
|
||||
@@ -90,13 +90,15 @@ module.exports = (logger) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
const {srf} = require('../..');
|
||||
if (process.env.K8S) {
|
||||
logger.info('disabling OPTIONS pings since we are running as a kubernetes service');
|
||||
const {addToSet} = srf.locals.dbHelpers;
|
||||
const uuid = srf.locals.fsUUID = uuidv4();
|
||||
addToSet(FS_UUID_SET_NAME, uuid)
|
||||
.catch((err) => logger.info({err}, `Error adding ${uuid} to set ${FS_UUID_SET_NAME}`));
|
||||
setImmediate(() => {
|
||||
logger.info('disabling OPTIONS pings since we are running as a kubernetes service');
|
||||
const {srf} = require('../..');
|
||||
const {addToSet} = srf.locals.dbHelpers;
|
||||
const uuid = srf.locals.fsUUID = uuidv4();
|
||||
addToSet(FS_UUID_SET_NAME, uuid)
|
||||
.catch((err) => logger.info({err}, `Error adding ${uuid} to set ${FS_UUID_SET_NAME}`));
|
||||
});
|
||||
}
|
||||
else {
|
||||
// OPTIONS ping the SBCs from each feature server every 60 seconds
|
||||
@@ -109,6 +111,7 @@ module.exports = (logger) => {
|
||||
setTimeout(async() => {
|
||||
|
||||
// if SBCs are auto-scaling, monitor them as they come and go
|
||||
const {srf} = require('../..');
|
||||
if (!process.env.JAMBONES_SBCS) {
|
||||
const {monitorSet} = srf.locals.dbHelpers;
|
||||
const setName = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:active-sip`;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
const CIDRMatcher = require('cidr-matcher');
|
||||
const cidrs = process.env.JAMBONES_NETWORK_CIDR
|
||||
.split(',')
|
||||
.map((s) => s.trim());
|
||||
const matcher = new CIDRMatcher(cidrs);
|
||||
|
||||
module.exports = (sbcList) => {
|
||||
const obj = sbcList
|
||||
.split(',')
|
||||
.map((str) => {
|
||||
const arr = /^(.*)\/(.*):(\d+)$/.exec(str);
|
||||
return {protocol: arr[1], host: arr[2], port: arr[3]};
|
||||
})
|
||||
.find((obj) => 'udp' == obj.protocol && matcher.contains(obj.host));
|
||||
if (obj) return `${obj.host}:${obj.port}`;
|
||||
};
|
||||
Reference in New Issue
Block a user