@routr/location 2.0.8-alpha.1 → 2.0.8-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -31,8 +31,7 @@ export default class Location implements ILocationService {
31
31
  *
32
32
  * @param {FindRoutesResponse} request - Request to find routes
33
33
  * @param {string} request.aor - AOR of the route
34
- * @param {Map<string, string>} request.labels - Optional Route labels
35
- * @param {string} request.sessionAffinityRef - Optiona session affinity ref
34
+ * @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
36
35
  * @return {Promise<void>}
37
36
  */
38
37
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
package/dist/client.js CHANGED
@@ -75,8 +75,7 @@ class Location {
75
75
  *
76
76
  * @param {FindRoutesResponse} request - Request to find routes
77
77
  * @param {string} request.aor - AOR of the route
78
- * @param {Map<string, string>} request.labels - Optional Route labels
79
- * @param {string} request.sessionAffinityRef - Optiona session affinity ref
78
+ * @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
80
79
  * @return {Promise<void>}
81
80
  */
82
81
  findRoutes(request) {
@@ -53,9 +53,10 @@ const E = __importStar(require("fp-ts/Either"));
53
53
  const errors_1 = require("../errors");
54
54
  const ajv = new ajv_1.default();
55
55
  const validate = ajv.compile(schema_1.schema);
56
- const hasBadCombiniation = (backends) => backends.some((b) => b.balancingAlgorithm === types_1.LB_ALGORITHM.ROUND_ROBIN && b.withSessionAffinity);
57
- const hasBadAlgorithm = (backends) => backends.some((b) => b.balancingAlgorithm !== types_1.LB_ALGORITHM.ROUND_ROBIN &&
58
- b.balancingAlgorithm !== types_1.LB_ALGORITHM.LEAST_SESSIONS);
56
+ const hasBadCombiniation = (backends) => backends.some((b) => b.balancingAlgorithm === types_1.LoadBalancingAlgorithm.ROUND_ROBIN &&
57
+ b.withSessionAffinity);
58
+ const hasBadAlgorithm = (backends) => backends.some((b) => b.balancingAlgorithm !== types_1.LoadBalancingAlgorithm.ROUND_ROBIN &&
59
+ b.balancingAlgorithm !== types_1.LoadBalancingAlgorithm.LEAST_SESSIONS);
59
60
  const getConfig = (path) => {
60
61
  var _a, _b, _c;
61
62
  const c = JSON.parse(fs_1.default.readFileSync(path, "utf8"));
@@ -68,7 +69,7 @@ const getConfig = (path) => {
68
69
  // Setting round-robin by default
69
70
  b.balancingAlgorithm = b.balancingAlgorithm
70
71
  ? b.balancingAlgorithm
71
- : types_1.LB_ALGORITHM.ROUND_ROBIN;
72
+ : types_1.LoadBalancingAlgorithm.ROUND_ROBIN;
72
73
  return b;
73
74
  });
74
75
  if (hasBadCombiniation(config.backends)) {
@@ -78,15 +79,15 @@ const getConfig = (path) => {
78
79
  return E.left(new errors_1.InvalidLoadBalancerAlgorithm());
79
80
  }
80
81
  }
81
- if (!((_a = config === null || config === void 0 ? void 0 : config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
82
+ if (!((_a = config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
82
83
  config.cache = {
83
- provider: types_1.CACHE_PROVIDER.MEMORY
84
+ provider: types_1.CacheProvider.MEMORY
84
85
  };
85
86
  }
86
- if (((_b = config === null || config === void 0 ? void 0 : config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CACHE_PROVIDER.REDIS &&
87
- !((_c = config === null || config === void 0 ? void 0 : config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
87
+ if (((_b = config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CacheProvider.REDIS &&
88
+ !((_c = config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
88
89
  config.cache = {
89
- provider: types_1.CACHE_PROVIDER.REDIS,
90
+ provider: types_1.CacheProvider.REDIS,
90
91
  parameters: "host=localhost,port=6379"
91
92
  };
92
93
  }
@@ -78,5 +78,5 @@ exports.schema = {
78
78
  }
79
79
  }
80
80
  },
81
- required: ["kind", "spec", "apiVersion"]
81
+ required: ["apiVersion", "kind", "metadata", "spec"]
82
82
  };
package/dist/helper.js CHANGED
@@ -32,7 +32,6 @@ const createRoute = (request) => {
32
32
  const sessionCount = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT)
33
33
  ? parseInt(processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT))
34
34
  : -1;
35
- const egressListeningPoint = common_1.Helper.getListeningPoint(request, uri.transportParam.toLowerCase());
36
35
  return {
37
36
  edgePortRef: request.edgePortRef,
38
37
  user: uri.user,
@@ -42,7 +41,9 @@ const createRoute = (request) => {
42
41
  registeredOn: Date.now(),
43
42
  sessionCount,
44
43
  expires: processor_1.Target.getTargetExpires(request),
45
- egressListeningPoint
44
+ listeningPoints: request.listeningPoints,
45
+ localnets: request.localnets,
46
+ externalAddrs: request.externalAddrs
46
47
  };
47
48
  };
48
49
  exports.createRoute = createRoute;
@@ -7,7 +7,6 @@ export default class Location implements ILocationService {
7
7
  private store;
8
8
  private backends;
9
9
  private rrCount;
10
- private affinityStore;
11
10
  /**
12
11
  * Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
13
12
  *
package/dist/location.js CHANGED
@@ -49,8 +49,7 @@ class Location {
49
49
  this.store = store;
50
50
  this.backends = backends;
51
51
  this.rrCount = new Map();
52
- this.affinityStore = new Map();
53
- this.backends.forEach((value, key) => this.rrCount.set(key, 0));
52
+ this.backends.forEach((_, key) => this.rrCount.set(key, 0));
54
53
  }
55
54
  /** @inheritdoc */
56
55
  addRoute(request) {
@@ -64,10 +63,16 @@ class Location {
64
63
  findRoutes(request) {
65
64
  var _a;
66
65
  return __awaiter(this, void 0, void 0, function* () {
67
- const routes = request.labels
66
+ let routes = yield this.store.get(request.callId);
67
+ if (routes.length > 0) {
68
+ return routes;
69
+ }
70
+ routes = request.labels
68
71
  ? (yield this.store.get(request.aor)).filter((0, utils_1.filterOnlyMatchingLabels)(request.labels))
69
72
  : (_a = (yield this.store.get(request.aor))) !== null && _a !== void 0 ? _a : [];
70
73
  if (request.aor.startsWith(AOR_SCHEME.SIP)) {
74
+ // Set call to the last route
75
+ this.store.put(request.callId, routes[0]);
71
76
  return routes;
72
77
  }
73
78
  else if (request.aor.startsWith(AOR_SCHEME.BACKEND)) {
@@ -76,9 +81,12 @@ class Location {
76
81
  throw new errors_1.NotRoutesFoundForAOR(request.aor);
77
82
  }
78
83
  // If it has not affinity sesssion then get next
79
- return backend.withSessionAffinity
80
- ? [this.nextWithAffinity(routes, request.sessionAffinityRef)]
84
+ const r = backend.withSessionAffinity
85
+ ? [yield this.nextWithAffinity(routes, request.sessionAffinityRef)]
81
86
  : [this.next(routes, backend)];
87
+ // Next time we will get the route with callId
88
+ this.store.put(request.callId, r[0]);
89
+ return r;
82
90
  }
83
91
  throw new errors_1.UnsupportedSchema(request.aor);
84
92
  });
@@ -89,7 +97,7 @@ class Location {
89
97
  }
90
98
  // eslint-disable-next-line require-jsdoc
91
99
  next(routes, backend) {
92
- if (backend.balancingAlgorithm === types_1.LB_ALGORITHM.LEAST_SESSIONS) {
100
+ if (backend.balancingAlgorithm === types_1.LoadBalancingAlgorithm.LEAST_SESSIONS) {
93
101
  return routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
94
102
  }
95
103
  // Continues using round-robin
@@ -106,14 +114,16 @@ class Location {
106
114
  }
107
115
  // Backend with session affinity does not support round-robin
108
116
  // eslint-disable-next-line require-jsdoc
109
- nextWithAffinity(routes, sessionAffinityRef) {
110
- let route = this.affinityStore.get(sessionAffinityRef);
111
- if (route) {
112
- return route;
113
- }
114
- route = routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
115
- this.affinityStore.set(sessionAffinityRef, route);
116
- return route;
117
+ nextWithAffinity(routes, sessionAffinityHeader) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const route = yield this.store.get(sessionAffinityHeader);
120
+ if (route.length > 0) {
121
+ return route[0];
122
+ }
123
+ const r = routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
124
+ this.store.put(sessionAffinityHeader, r);
125
+ return r;
126
+ });
117
127
  }
118
128
  }
119
129
  exports.default = Location;
package/dist/service.js CHANGED
@@ -38,7 +38,7 @@ const allowedParameters = ["host", "port", "username", "password", "secure"];
38
38
  function LocationService(config) {
39
39
  const { bindAddr, cache } = config;
40
40
  let store;
41
- if (cache.provider === types_1.CACHE_PROVIDER.REDIS) {
41
+ if (cache.provider === types_1.CacheProvider.REDIS) {
42
42
  store = new redis_store_1.default((0, utils_1.configFromString)(cache.parameters, allowedParameters));
43
43
  }
44
44
  else {
package/dist/types.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Route } from "@routr/common";
2
- export declare enum LB_ALGORITHM {
2
+ export declare enum LoadBalancingAlgorithm {
3
3
  ROUND_ROBIN = "round-robin",
4
4
  LEAST_SESSIONS = "least-sessions"
5
5
  }
6
- export declare enum CACHE_PROVIDER {
6
+ export declare enum CacheProvider {
7
7
  MEMORY = "memory",
8
8
  REDIS = "redis"
9
9
  }
@@ -23,8 +23,9 @@ export interface AddRouteRequest {
23
23
  }
24
24
  export interface FindRoutesRequest {
25
25
  aor: string;
26
- labels?: Map<string, string>;
26
+ callId: string;
27
27
  sessionAffinityRef?: string;
28
+ labels?: Map<string, string>;
28
29
  }
29
30
  export interface FindRoutesResponse {
30
31
  routes: Array<Route>;
@@ -34,14 +35,14 @@ export interface RemoveRoutesRequest {
34
35
  }
35
36
  export interface Backend {
36
37
  ref: string;
37
- balancingAlgorithm?: LB_ALGORITHM;
38
+ balancingAlgorithm?: LoadBalancingAlgorithm;
38
39
  withSessionAffinity?: boolean;
39
40
  }
40
41
  export interface LocationConfig {
41
42
  bindAddr: string;
42
43
  backends?: Backend[];
43
44
  cache?: {
44
- provider: CACHE_PROVIDER;
45
+ provider: CacheProvider;
45
46
  parameters?: string;
46
47
  };
47
48
  }
package/dist/types.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CACHE_PROVIDER = exports.LB_ALGORITHM = void 0;
4
- var LB_ALGORITHM;
5
- (function (LB_ALGORITHM) {
6
- LB_ALGORITHM["ROUND_ROBIN"] = "round-robin";
7
- LB_ALGORITHM["LEAST_SESSIONS"] = "least-sessions";
8
- })(LB_ALGORITHM = exports.LB_ALGORITHM || (exports.LB_ALGORITHM = {}));
9
- var CACHE_PROVIDER;
10
- (function (CACHE_PROVIDER) {
11
- CACHE_PROVIDER["MEMORY"] = "memory";
12
- CACHE_PROVIDER["REDIS"] = "redis";
13
- })(CACHE_PROVIDER = exports.CACHE_PROVIDER || (exports.CACHE_PROVIDER = {}));
3
+ exports.CacheProvider = exports.LoadBalancingAlgorithm = void 0;
4
+ var LoadBalancingAlgorithm;
5
+ (function (LoadBalancingAlgorithm) {
6
+ LoadBalancingAlgorithm["ROUND_ROBIN"] = "round-robin";
7
+ LoadBalancingAlgorithm["LEAST_SESSIONS"] = "least-sessions";
8
+ })(LoadBalancingAlgorithm = exports.LoadBalancingAlgorithm || (exports.LoadBalancingAlgorithm = {}));
9
+ var CacheProvider;
10
+ (function (CacheProvider) {
11
+ CacheProvider["MEMORY"] = "memory";
12
+ CacheProvider["REDIS"] = "redis";
13
+ })(CacheProvider = exports.CacheProvider || (exports.CacheProvider = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/location",
3
- "version": "2.0.8-alpha.1",
3
+ "version": "2.0.8-alpha.11",
4
4
  "description": "Creates and maintains a list of routes to all registered endpoints",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -35,8 +35,8 @@
35
35
  "@opentelemetry/sdk-trace-base": "^1.0.4",
36
36
  "@opentelemetry/sdk-trace-node": "^1.0.4",
37
37
  "@opentelemetry/semantic-conventions": "^1.0.4",
38
- "@routr/common": "^2.0.8-alpha.1",
39
- "@routr/processor": "^2.0.8-alpha.1",
38
+ "@routr/common": "^2.0.8-alpha.11",
39
+ "@routr/processor": "^2.0.8-alpha.11",
40
40
  "ajv": "^6.12.6",
41
41
  "fp-ts": "^2.11.8",
42
42
  "redis": "^4.0.4"
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/fonoster/routr/issues"
50
50
  },
51
- "gitHead": "0824e725362fae3df83467f0f8989a2e4fa1f794"
51
+ "gitHead": "627659ac51d0814a3106bcaac31a15c581a5809f"
52
52
  }