@routr/location 2.0.8-alpha.8 → 2.0.9
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 +2 -2
- package/dist/client.js +3 -3
- package/dist/config/get_config.d.ts +2 -2
- package/dist/config/get_config.js +6 -25
- package/dist/config/schema.d.ts +0 -20
- package/dist/config/schema.js +4 -24
- package/dist/envs.d.ts +1 -0
- package/dist/envs.js +24 -0
- package/dist/errors.d.ts +0 -21
- package/dist/errors.js +2 -28
- package/dist/helper.d.ts +9 -1
- package/dist/helper.js +28 -23
- package/dist/index.js +1 -1
- package/dist/location.d.ts +2 -5
- package/dist/location.js +31 -24
- package/dist/runner.js +1 -1
- package/dist/service.js +4 -5
- package/dist/tracer.js +1 -1
- package/dist/types.d.ts +10 -13
- package/dist/types.js +3 -8
- package/dist/utils.js +1 -1
- package/package.json +6 -6
package/dist/client.d.ts
CHANGED
|
@@ -31,8 +31,8 @@ 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 {
|
|
34
|
+
* @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
|
|
35
|
+
* @param {object} request.backend - Optional Route backend (reserved for future use)
|
|
36
36
|
* @return {Promise<void>}
|
|
37
37
|
*/
|
|
38
38
|
findRoutes(request: FindRoutesRequest): Promise<Route[]>;
|
package/dist/client.js
CHANGED
|
@@ -38,7 +38,7 @@ const container = (self, request, name) => {
|
|
|
38
38
|
return new Promise((resolve, reject) => {
|
|
39
39
|
self.location[name](request, (err, response) => {
|
|
40
40
|
if ((err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE) {
|
|
41
|
-
return reject(new common_1.ServiceUnavailableError(self.config.addr));
|
|
41
|
+
return reject(new common_1.CommonErrors.ServiceUnavailableError(self.config.addr));
|
|
42
42
|
}
|
|
43
43
|
resolve(response);
|
|
44
44
|
});
|
|
@@ -75,8 +75,8 @@ 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 {
|
|
78
|
+
* @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
|
|
79
|
+
* @param {object} request.backend - Optional Route backend (reserved for future use)
|
|
80
80
|
* @return {Promise<void>}
|
|
81
81
|
*/
|
|
82
82
|
findRoutes(request) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { LocationConfig } from "../types";
|
|
2
2
|
import * as E from "fp-ts/Either";
|
|
3
|
-
import {
|
|
4
|
-
export declare const getConfig: (path: string) => E.Either<
|
|
3
|
+
import { InvalidSchemaConfiguration } from "../errors";
|
|
4
|
+
export declare const getConfig: (path: string) => E.Either<InvalidSchemaConfiguration, LocationConfig>;
|
|
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.getConfig = void 0;
|
|
30
30
|
/*
|
|
31
|
-
* Copyright (C)
|
|
31
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
32
32
|
* http://github.com/fonoster/routr
|
|
33
33
|
*
|
|
34
34
|
* This file is part of Routr
|
|
@@ -46,46 +46,27 @@ exports.getConfig = void 0;
|
|
|
46
46
|
* limitations under the License.
|
|
47
47
|
*/
|
|
48
48
|
const types_1 = require("../types");
|
|
49
|
-
const
|
|
49
|
+
const common_1 = require("@routr/common");
|
|
50
50
|
const schema_1 = require("./schema");
|
|
51
51
|
const ajv_1 = __importDefault(require("ajv"));
|
|
52
52
|
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.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);
|
|
60
56
|
const getConfig = (path) => {
|
|
61
57
|
var _a, _b, _c;
|
|
62
|
-
const c =
|
|
58
|
+
const c = common_1.Helper.readConfigFile(path);
|
|
63
59
|
if (!validate(Object.assign({}, c))) {
|
|
64
60
|
return E.left(new errors_1.InvalidSchemaConfiguration(JSON.stringify(validate.errors[0].message)));
|
|
65
61
|
}
|
|
66
62
|
const config = c.spec;
|
|
67
|
-
if (config.
|
|
68
|
-
config.backends.map((b) => {
|
|
69
|
-
// Setting round-robin by default
|
|
70
|
-
b.balancingAlgorithm = b.balancingAlgorithm
|
|
71
|
-
? b.balancingAlgorithm
|
|
72
|
-
: types_1.LoadBalancingAlgorithm.ROUND_ROBIN;
|
|
73
|
-
return b;
|
|
74
|
-
});
|
|
75
|
-
if (hasBadCombiniation(config.backends)) {
|
|
76
|
-
return E.left(new errors_1.BadAlgorithmAndAffinityCombination());
|
|
77
|
-
}
|
|
78
|
-
if (hasBadAlgorithm(config.backends)) {
|
|
79
|
-
return E.left(new errors_1.InvalidLoadBalancerAlgorithm());
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (!((_a = config === null || config === void 0 ? void 0 : config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
|
|
63
|
+
if (!((_a = config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
|
|
83
64
|
config.cache = {
|
|
84
65
|
provider: types_1.CacheProvider.MEMORY
|
|
85
66
|
};
|
|
86
67
|
}
|
|
87
|
-
if (((_b = config
|
|
88
|
-
!((_c = config
|
|
68
|
+
if (((_b = config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CacheProvider.REDIS &&
|
|
69
|
+
!((_c = config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
|
|
89
70
|
config.cache = {
|
|
90
71
|
provider: types_1.CacheProvider.REDIS,
|
|
91
72
|
parameters: "host=localhost,port=6379"
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -34,26 +34,6 @@ export declare const schema: {
|
|
|
34
34
|
};
|
|
35
35
|
required: string[];
|
|
36
36
|
};
|
|
37
|
-
backends: {
|
|
38
|
-
description: string;
|
|
39
|
-
type: string;
|
|
40
|
-
items: {
|
|
41
|
-
type: string;
|
|
42
|
-
};
|
|
43
|
-
properties: {
|
|
44
|
-
ref: {
|
|
45
|
-
type: string;
|
|
46
|
-
};
|
|
47
|
-
balancingAlgorithm: {
|
|
48
|
-
enum: string[];
|
|
49
|
-
};
|
|
50
|
-
withSessionAffinity: {
|
|
51
|
-
description: string;
|
|
52
|
-
type: string;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
required: string[];
|
|
56
|
-
};
|
|
57
37
|
};
|
|
58
38
|
};
|
|
59
39
|
};
|
package/dist/config/schema.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.schema = void 0;
|
|
4
4
|
/*
|
|
5
|
-
* Copyright (C)
|
|
5
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/routr
|
|
7
7
|
*
|
|
8
8
|
* This file is part of Routr
|
|
@@ -29,7 +29,7 @@ exports.schema = {
|
|
|
29
29
|
enum: ["Location", "location"]
|
|
30
30
|
},
|
|
31
31
|
apiVersion: {
|
|
32
|
-
enum: ["
|
|
32
|
+
enum: ["v2beta1", "v2"]
|
|
33
33
|
},
|
|
34
34
|
metadata: {
|
|
35
35
|
description: "Resource metadata",
|
|
@@ -47,36 +47,16 @@ exports.schema = {
|
|
|
47
47
|
type: "object",
|
|
48
48
|
properties: {
|
|
49
49
|
provider: {
|
|
50
|
-
enum: ["memory", "redis"]
|
|
50
|
+
enum: ["Memory", "Redis", "memory", "redis"]
|
|
51
51
|
},
|
|
52
52
|
parameters: {
|
|
53
53
|
type: "string"
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
required: ["provider"]
|
|
57
|
-
},
|
|
58
|
-
backends: {
|
|
59
|
-
description: "Optional SIP backends",
|
|
60
|
-
type: "array",
|
|
61
|
-
items: {
|
|
62
|
-
type: "object"
|
|
63
|
-
},
|
|
64
|
-
properties: {
|
|
65
|
-
ref: {
|
|
66
|
-
type: "string"
|
|
67
|
-
},
|
|
68
|
-
balancingAlgorithm: {
|
|
69
|
-
enum: ["round-robin", "least-sessions"]
|
|
70
|
-
},
|
|
71
|
-
withSessionAffinity: {
|
|
72
|
-
description: "Optional session affinity",
|
|
73
|
-
type: "boolean"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
required: ["ref"]
|
|
77
57
|
}
|
|
78
58
|
}
|
|
79
59
|
}
|
|
80
60
|
},
|
|
81
|
-
required: ["kind", "
|
|
61
|
+
required: ["apiVersion", "kind", "metadata", "spec"]
|
|
82
62
|
};
|
package/dist/envs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CONFIG_PATH: string;
|
package/dist/envs.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONFIG_PATH = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Routr.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const common_1 = require("@routr/common");
|
|
23
|
+
common_1.Assertions.assertEnvsAreSet(["CONFIG_PATH"]);
|
|
24
|
+
exports.CONFIG_PATH = process.env.CONFIG_PATH;
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
export type LocationError = UnsupportedSchema | NotRoutesFoundForAOR;
|
|
3
|
-
export type InvalidConfiguration = BadAlgorithmAndAffinityCombination | InvalidSchemaConfiguration;
|
|
4
3
|
/**
|
|
5
4
|
* Error thrown when the location service returns an unsupported schema.
|
|
6
5
|
*/
|
|
@@ -37,23 +36,3 @@ export declare class InvalidSchemaConfiguration extends Error {
|
|
|
37
36
|
*/
|
|
38
37
|
constructor(msg: string);
|
|
39
38
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Error thrown when the location finds incompatible algorithm and session affinity.
|
|
42
|
-
*/
|
|
43
|
-
export declare class BadAlgorithmAndAffinityCombination extends Error {
|
|
44
|
-
code: grpc.status;
|
|
45
|
-
/**
|
|
46
|
-
* Create a new BadAlgorithmAndAffinityCombination error.
|
|
47
|
-
*/
|
|
48
|
-
constructor();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Error thrown when the location finds an invalid balancing algorithm.
|
|
52
|
-
*/
|
|
53
|
-
export declare class InvalidLoadBalancerAlgorithm extends Error {
|
|
54
|
-
code: grpc.status;
|
|
55
|
-
/**
|
|
56
|
-
* Create a new InvalidLoadBalancerAlgorithm error.
|
|
57
|
-
*/
|
|
58
|
-
constructor();
|
|
59
|
-
}
|
package/dist/errors.js
CHANGED
|
@@ -23,9 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.InvalidSchemaConfiguration = exports.NotRoutesFoundForAOR = exports.UnsupportedSchema = void 0;
|
|
27
27
|
/*
|
|
28
|
-
* Copyright (C)
|
|
28
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
29
29
|
* http://github.com/fonoster/routr
|
|
30
30
|
*
|
|
31
31
|
* This file is part of Routr
|
|
@@ -92,29 +92,3 @@ class InvalidSchemaConfiguration extends Error {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
exports.InvalidSchemaConfiguration = InvalidSchemaConfiguration;
|
|
95
|
-
/**
|
|
96
|
-
* Error thrown when the location finds incompatible algorithm and session affinity.
|
|
97
|
-
*/
|
|
98
|
-
class BadAlgorithmAndAffinityCombination extends Error {
|
|
99
|
-
/**
|
|
100
|
-
* Create a new BadAlgorithmAndAffinityCombination error.
|
|
101
|
-
*/
|
|
102
|
-
constructor() {
|
|
103
|
-
super("session affinity can not be combined with round-robin load balancing");
|
|
104
|
-
Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.BadAlgorithmAndAffinityCombination = BadAlgorithmAndAffinityCombination;
|
|
108
|
-
/**
|
|
109
|
-
* Error thrown when the location finds an invalid balancing algorithm.
|
|
110
|
-
*/
|
|
111
|
-
class InvalidLoadBalancerAlgorithm extends Error {
|
|
112
|
-
/**
|
|
113
|
-
* Create a new InvalidLoadBalancerAlgorithm error.
|
|
114
|
-
*/
|
|
115
|
-
constructor() {
|
|
116
|
-
super("found invalid load balancing algorithm. must be round-robin or least-sessions");
|
|
117
|
-
Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.InvalidLoadBalancerAlgorithm = InvalidLoadBalancerAlgorithm;
|
package/dist/helper.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { MessageRequest, Route } from "@routr/common";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function createRoute(request: MessageRequest): Route;
|
|
3
|
+
/**
|
|
4
|
+
* A request traversing a second EdgePort would have updated the requestUri.
|
|
5
|
+
* Therefore, we are able to re-construct the Route from the request.
|
|
6
|
+
*
|
|
7
|
+
* @param {MessageRequest} request - the request
|
|
8
|
+
* @return {Route} the route
|
|
9
|
+
*/
|
|
10
|
+
export declare function createRouteFromLastMessage(request: MessageRequest): Route;
|
package/dist/helper.js
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRoute = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
6
|
-
* http://github.com/fonoster/routr
|
|
7
|
-
*
|
|
8
|
-
* This file is part of Routr
|
|
9
|
-
*
|
|
10
|
-
* Licensed under the MIT License (the "License")
|
|
11
|
-
* you may not use this file except in compliance with
|
|
12
|
-
* the License. You may obtain a copy of the License at
|
|
13
|
-
*
|
|
14
|
-
* https://opensource.org/licenses/MIT
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
* See the License for the specific language governing permissions and
|
|
20
|
-
* limitations under the License.
|
|
21
|
-
*/
|
|
3
|
+
exports.createRouteFromLastMessage = exports.createRoute = void 0;
|
|
22
4
|
const common_1 = require("@routr/common");
|
|
23
5
|
const processor_1 = require("@routr/processor");
|
|
6
|
+
/* eslint-disable require-jsdoc */
|
|
24
7
|
// TODO: Before finalizing this, consider using the old approach of saving the rport
|
|
25
8
|
// and received values (like here:
|
|
26
9
|
// https://github.com/fonoster/routr/blob/59bc98af86078088aede7e658c0d82a19fa18fa4/mod/registrar/utils.js#L87)
|
|
27
10
|
//
|
|
28
11
|
// Also consider: https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L116
|
|
29
12
|
// and https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L131
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
function buildRoute(request, uri) {
|
|
14
|
+
var _a;
|
|
32
15
|
const sessionCount = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT)
|
|
33
16
|
? parseInt(processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT))
|
|
34
17
|
: -1;
|
|
@@ -37,7 +20,7 @@ const createRoute = (request) => {
|
|
|
37
20
|
user: uri.user,
|
|
38
21
|
host: uri.host,
|
|
39
22
|
port: uri.port,
|
|
40
|
-
transport: uri.transportParam.
|
|
23
|
+
transport: (_a = uri.transportParam) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
41
24
|
registeredOn: Date.now(),
|
|
42
25
|
sessionCount,
|
|
43
26
|
expires: processor_1.Target.getTargetExpires(request),
|
|
@@ -45,5 +28,27 @@ const createRoute = (request) => {
|
|
|
45
28
|
localnets: request.localnets,
|
|
46
29
|
externalAddrs: request.externalAddrs
|
|
47
30
|
};
|
|
48
|
-
}
|
|
31
|
+
}
|
|
32
|
+
function createRoute(request) {
|
|
33
|
+
const via = request.message.via[0];
|
|
34
|
+
const uri = {
|
|
35
|
+
host: via.received || via.host,
|
|
36
|
+
port: via.rPort !== -1 ? via.rPort : via.port,
|
|
37
|
+
transportParam: via.transport.toUpperCase(),
|
|
38
|
+
user: request.message.from.address.uri.user
|
|
39
|
+
};
|
|
40
|
+
return buildRoute(request, uri);
|
|
41
|
+
}
|
|
49
42
|
exports.createRoute = createRoute;
|
|
43
|
+
/**
|
|
44
|
+
* A request traversing a second EdgePort would have updated the requestUri.
|
|
45
|
+
* Therefore, we are able to re-construct the Route from the request.
|
|
46
|
+
*
|
|
47
|
+
* @param {MessageRequest} request - the request
|
|
48
|
+
* @return {Route} the route
|
|
49
|
+
*/
|
|
50
|
+
function createRouteFromLastMessage(request) {
|
|
51
|
+
const uri = request.message.requestUri;
|
|
52
|
+
return buildRoute(request, uri);
|
|
53
|
+
}
|
|
54
|
+
exports.createRouteFromLastMessage = createRouteFromLastMessage;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.LocationClient = exports.Utils = exports.Helper = void 0;
|
|
33
33
|
/*
|
|
34
|
-
* Copyright (C)
|
|
34
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
35
35
|
* http://github.com/fonoster/routr
|
|
36
36
|
*
|
|
37
37
|
* This file is part of Routr
|
package/dist/location.d.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { AddRouteRequest,
|
|
1
|
+
import { AddRouteRequest, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRoutesRequest } from "./types";
|
|
2
2
|
import { Route } from "@routr/common";
|
|
3
3
|
/**
|
|
4
4
|
* A locator store that uses the location service to find routes for AORs.
|
|
5
5
|
*/
|
|
6
6
|
export default class Location implements ILocationService {
|
|
7
7
|
private store;
|
|
8
|
-
private backends;
|
|
9
8
|
private rrCount;
|
|
10
|
-
private affinityStore;
|
|
11
9
|
/**
|
|
12
10
|
* Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
|
|
13
11
|
*
|
|
14
12
|
* @param {ILocatorStore} store - The store to use for the location service
|
|
15
|
-
* @param {Map<string, Backend>} backends - The backends to use for the location service
|
|
16
13
|
*/
|
|
17
|
-
constructor(store: ILocatorStore
|
|
14
|
+
constructor(store: ILocatorStore);
|
|
18
15
|
/** @inheritdoc */
|
|
19
16
|
addRoute(request: AddRouteRequest): Promise<void>;
|
|
20
17
|
/** @inheritdoc */
|
package/dist/location.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
/*
|
|
13
|
-
* Copyright (C)
|
|
13
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
14
14
|
* http://github.com/fonoster/routr
|
|
15
15
|
*
|
|
16
16
|
* This file is part of Routr
|
|
@@ -28,7 +28,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
28
|
* limitations under the License.
|
|
29
29
|
*/
|
|
30
30
|
const errors_1 = require("./errors");
|
|
31
|
-
const
|
|
31
|
+
const common_1 = require("@routr/common");
|
|
32
32
|
const utils_1 = require("./utils");
|
|
33
33
|
var AOR_SCHEME;
|
|
34
34
|
(function (AOR_SCHEME) {
|
|
@@ -43,14 +43,10 @@ class Location {
|
|
|
43
43
|
* Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
|
|
44
44
|
*
|
|
45
45
|
* @param {ILocatorStore} store - The store to use for the location service
|
|
46
|
-
* @param {Map<string, Backend>} backends - The backends to use for the location service
|
|
47
46
|
*/
|
|
48
|
-
constructor(store
|
|
47
|
+
constructor(store) {
|
|
49
48
|
this.store = store;
|
|
50
|
-
this.backends = backends;
|
|
51
49
|
this.rrCount = new Map();
|
|
52
|
-
this.affinityStore = new Map();
|
|
53
|
-
this.backends.forEach((value, key) => this.rrCount.set(key, 0));
|
|
54
50
|
}
|
|
55
51
|
/** @inheritdoc */
|
|
56
52
|
addRoute(request) {
|
|
@@ -64,21 +60,29 @@ class Location {
|
|
|
64
60
|
findRoutes(request) {
|
|
65
61
|
var _a;
|
|
66
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
|
|
63
|
+
let routes = yield this.store.get(`${request.aor}:${request.callId}`);
|
|
64
|
+
if (routes.length > 0) {
|
|
65
|
+
return routes;
|
|
66
|
+
}
|
|
67
|
+
routes = request.labels
|
|
68
68
|
? (yield this.store.get(request.aor)).filter((0, utils_1.filterOnlyMatchingLabels)(request.labels))
|
|
69
69
|
: (_a = (yield this.store.get(request.aor))) !== null && _a !== void 0 ? _a : [];
|
|
70
70
|
if (request.aor.startsWith(AOR_SCHEME.SIP)) {
|
|
71
|
+
// Set call to the last route
|
|
72
|
+
this.store.put(`${request.aor}:${request.callId}`, routes[0]);
|
|
71
73
|
return routes;
|
|
72
74
|
}
|
|
73
75
|
else if (request.aor.startsWith(AOR_SCHEME.BACKEND)) {
|
|
74
|
-
const backend =
|
|
75
|
-
if (!backend) {
|
|
76
|
-
throw new errors_1.NotRoutesFoundForAOR(request.aor);
|
|
77
|
-
}
|
|
76
|
+
const { backend } = request;
|
|
78
77
|
// If it has not affinity sesssion then get next
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const r =
|
|
79
|
+
// Falls back to round-robin if no session affinity ref is provided
|
|
80
|
+
backend.withSessionAffinity && request.sessionAffinityRef
|
|
81
|
+
? [yield this.nextWithAffinity(routes, request.sessionAffinityRef)]
|
|
81
82
|
: [this.next(routes, backend)];
|
|
83
|
+
// Next time we will get the route with callId
|
|
84
|
+
this.store.put(`${request.aor}:${request.callId}`, r[0]);
|
|
85
|
+
return r;
|
|
82
86
|
}
|
|
83
87
|
throw new errors_1.UnsupportedSchema(request.aor);
|
|
84
88
|
});
|
|
@@ -89,11 +93,12 @@ class Location {
|
|
|
89
93
|
}
|
|
90
94
|
// eslint-disable-next-line require-jsdoc
|
|
91
95
|
next(routes, backend) {
|
|
92
|
-
|
|
96
|
+
var _a;
|
|
97
|
+
if (backend.balancingAlgorithm === common_1.CommonTypes.LoadBalancingAlgorithm.LEAST_SESSIONS) {
|
|
93
98
|
return routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
|
|
94
99
|
}
|
|
95
100
|
// Continues using round-robin
|
|
96
|
-
const nextPosition = this.rrCount.get(`${AOR_SCHEME.BACKEND}${backend.ref}`);
|
|
101
|
+
const nextPosition = (_a = this.rrCount.get(`${AOR_SCHEME.BACKEND}${backend.ref}`)) !== null && _a !== void 0 ? _a : 0;
|
|
97
102
|
const result = routes[nextPosition];
|
|
98
103
|
if (nextPosition >= routes.length - 1) {
|
|
99
104
|
// Restarting round-robin counter
|
|
@@ -106,14 +111,16 @@ class Location {
|
|
|
106
111
|
}
|
|
107
112
|
// Backend with session affinity does not support round-robin
|
|
108
113
|
// eslint-disable-next-line require-jsdoc
|
|
109
|
-
nextWithAffinity(routes,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
nextWithAffinity(routes, sessionAffinityHeader) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const route = yield this.store.get(sessionAffinityHeader);
|
|
117
|
+
if (route.length > 0) {
|
|
118
|
+
return route[0];
|
|
119
|
+
}
|
|
120
|
+
const r = routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
|
|
121
|
+
this.store.put(sessionAffinityHeader, r);
|
|
122
|
+
return r;
|
|
123
|
+
});
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
126
|
exports.default = Location;
|
package/dist/runner.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
/*
|
|
8
|
-
* Copyright (C)
|
|
8
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
9
9
|
* http://github.com/fonoster/routr
|
|
10
10
|
*
|
|
11
11
|
* This file is part of Routr
|
package/dist/service.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/*
|
|
7
|
-
* Copyright (C)
|
|
7
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
8
8
|
* http://github.com/fonoster/routr
|
|
9
9
|
*
|
|
10
10
|
* This file is part of Routr
|
|
@@ -36,17 +36,16 @@ const allowedParameters = ["host", "port", "username", "password", "secure"];
|
|
|
36
36
|
* @param {LocationConfig} config - Service configuration
|
|
37
37
|
*/
|
|
38
38
|
function LocationService(config) {
|
|
39
|
+
var _a;
|
|
39
40
|
const { bindAddr, cache } = config;
|
|
40
41
|
let store;
|
|
41
|
-
if (cache.provider === types_1.CacheProvider.REDIS) {
|
|
42
|
+
if (((_a = cache.provider) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === types_1.CacheProvider.REDIS) {
|
|
42
43
|
store = new redis_store_1.default((0, utils_1.configFromString)(cache.parameters, allowedParameters));
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
46
|
store = new memory_store_1.default();
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
config.backends.forEach((b) => backends.set(`backend:${b.ref}`, b));
|
|
49
|
-
(0, common_1.createService)((0, utils_1.getServiceInfo)(bindAddr, new location_1.default(store, backends)));
|
|
48
|
+
(0, common_1.createService)((0, utils_1.getServiceInfo)(bindAddr, new location_1.default(store)));
|
|
50
49
|
logger.info(`using ${cache.provider} as cache provider`);
|
|
51
50
|
}
|
|
52
51
|
exports.default = LocationService;
|
package/dist/tracer.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init = void 0;
|
|
7
7
|
/*
|
|
8
|
-
* Copyright (C)
|
|
8
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
9
9
|
* http://github.com/fonoster/routr
|
|
10
10
|
*
|
|
11
11
|
* This file is part of Routr
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { Route } from "@routr/common";
|
|
2
|
-
export declare enum LoadBalancingAlgorithm {
|
|
3
|
-
ROUND_ROBIN = "round-robin",
|
|
4
|
-
LEAST_SESSIONS = "least-sessions"
|
|
5
|
-
}
|
|
6
|
-
export declare enum CacheProvider {
|
|
7
|
-
MEMORY = "memory",
|
|
8
|
-
REDIS = "redis"
|
|
9
|
-
}
|
|
1
|
+
import { Route, CommonTypes as CT } from "@routr/common";
|
|
10
2
|
export interface ILocationService {
|
|
11
3
|
addRoute(request: AddRouteRequest): Promise<void>;
|
|
12
4
|
findRoutes(request: FindRoutesRequest): Promise<Route[]>;
|
|
@@ -23,8 +15,10 @@ export interface AddRouteRequest {
|
|
|
23
15
|
}
|
|
24
16
|
export interface FindRoutesRequest {
|
|
25
17
|
aor: string;
|
|
26
|
-
|
|
18
|
+
callId: string;
|
|
27
19
|
sessionAffinityRef?: string;
|
|
20
|
+
backend?: Backend;
|
|
21
|
+
labels?: Map<string, string>;
|
|
28
22
|
}
|
|
29
23
|
export interface FindRoutesResponse {
|
|
30
24
|
routes: Array<Route>;
|
|
@@ -34,12 +28,15 @@ export interface RemoveRoutesRequest {
|
|
|
34
28
|
}
|
|
35
29
|
export interface Backend {
|
|
36
30
|
ref: string;
|
|
37
|
-
balancingAlgorithm
|
|
38
|
-
withSessionAffinity
|
|
31
|
+
balancingAlgorithm: CT.LoadBalancingAlgorithm;
|
|
32
|
+
withSessionAffinity: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare enum CacheProvider {
|
|
35
|
+
MEMORY = "MEMORY",
|
|
36
|
+
REDIS = "REDIS"
|
|
39
37
|
}
|
|
40
38
|
export interface LocationConfig {
|
|
41
39
|
bindAddr: string;
|
|
42
|
-
backends?: Backend[];
|
|
43
40
|
cache?: {
|
|
44
41
|
provider: CacheProvider;
|
|
45
42
|
parameters?: string;
|
package/dist/types.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CacheProvider =
|
|
4
|
-
var LoadBalancingAlgorithm;
|
|
5
|
-
(function (LoadBalancingAlgorithm) {
|
|
6
|
-
LoadBalancingAlgorithm["ROUND_ROBIN"] = "round-robin";
|
|
7
|
-
LoadBalancingAlgorithm["LEAST_SESSIONS"] = "least-sessions";
|
|
8
|
-
})(LoadBalancingAlgorithm = exports.LoadBalancingAlgorithm || (exports.LoadBalancingAlgorithm = {}));
|
|
3
|
+
exports.CacheProvider = void 0;
|
|
9
4
|
var CacheProvider;
|
|
10
5
|
(function (CacheProvider) {
|
|
11
|
-
CacheProvider["MEMORY"] = "
|
|
12
|
-
CacheProvider["REDIS"] = "
|
|
6
|
+
CacheProvider["MEMORY"] = "MEMORY";
|
|
7
|
+
CacheProvider["REDIS"] = "REDIS";
|
|
13
8
|
})(CacheProvider = exports.CacheProvider || (exports.CacheProvider = {}));
|
package/dist/utils.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.configFromString = exports.getServiceInfo = exports.filterOnlyMatchingLabels = exports.compareArrays = exports.mergeKeyValue = exports.duplicateFilter = exports.expiredFilter = void 0;
|
|
13
13
|
/*
|
|
14
|
-
* Copyright (C)
|
|
14
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
15
15
|
* http://github.com/fonoster/routr
|
|
16
16
|
*
|
|
17
17
|
* This file is part of Routr
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/location",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
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",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@fonoster/logger": "0.3.
|
|
29
|
-
"@grpc/grpc-js": "^1.
|
|
28
|
+
"@fonoster/logger": "0.3.20",
|
|
29
|
+
"@grpc/grpc-js": "^1.8.4",
|
|
30
30
|
"@opentelemetry/api": "^1.0.4",
|
|
31
31
|
"@opentelemetry/exporter-jaeger": "^1.0.4",
|
|
32
32
|
"@opentelemetry/instrumentation": "^0.27.0",
|
|
@@ -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.
|
|
39
|
-
"@routr/processor": "^2.0.
|
|
38
|
+
"@routr/common": "^2.0.9",
|
|
39
|
+
"@routr/processor": "^2.0.9",
|
|
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": "
|
|
51
|
+
"gitHead": "62eb05f0b3bfa05d84c9ce4b4644de5fb5453295"
|
|
52
52
|
}
|