Add DualClusterClient for live testing phase of backend/frontend split
This commit is contained in:
parent
295c2a41a8
commit
b69bd82a72
12
index.js
12
index.js
|
|
@ -19,6 +19,7 @@ try {
|
||||||
}
|
}
|
||||||
var Config = require("./lib/config");
|
var Config = require("./lib/config");
|
||||||
var Logger = require("./lib/logger");
|
var Logger = require("./lib/logger");
|
||||||
|
const Switches = require("./lib/switches");
|
||||||
require("source-map-support").install();
|
require("source-map-support").install();
|
||||||
|
|
||||||
Config.load("config.yaml");
|
Config.load("config.yaml");
|
||||||
|
|
@ -61,5 +62,16 @@ function handleLine(line) {
|
||||||
Logger.syslog.log("Deleted old channel tables");
|
Logger.syslog.log("Deleted old channel tables");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (line.indexOf("/switch") === 0) {
|
||||||
|
var args = line.split(" ");
|
||||||
|
args.shift();
|
||||||
|
if (args.length === 1) {
|
||||||
|
Logger.syslog.log("Switch " + args[0] + " is " +
|
||||||
|
(Switches.isActive(args[0]) ? "ON" : "OFF"));
|
||||||
|
} else if (args.length === 2) {
|
||||||
|
Switches.setActive(args[0], args[1].toLowerCase() === "on" ? true : false);
|
||||||
|
Logger.syslog.log("Switch " + args[0] + " is now " +
|
||||||
|
(Switches.isActive(args[0]) ? "ON" : "OFF"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
import { RedisClusterClient } from '../io/cluster/redisclusterclient';
|
import { RedisClusterClient } from '../io/cluster/redisclusterclient';
|
||||||
|
import { DualClusterClient } from '../io/cluster/dualclusterclient';
|
||||||
|
import NullClusterClient from '../io/cluster/nullclusterclient';
|
||||||
import { FrontendPool } from 'cytube-common/lib/redis/frontendpool';
|
import { FrontendPool } from 'cytube-common/lib/redis/frontendpool';
|
||||||
import RedisClientProvider from 'cytube-common/lib/redis/redisclientprovider';
|
import RedisClientProvider from 'cytube-common/lib/redis/redisclientprovider';
|
||||||
import { loadFromToml } from 'cytube-common/lib/configuration/configloader';
|
import { loadFromToml } from 'cytube-common/lib/configuration/configloader';
|
||||||
|
|
@ -6,6 +8,9 @@ import path from 'path';
|
||||||
import { BackendConfiguration } from './backendconfiguration';
|
import { BackendConfiguration } from './backendconfiguration';
|
||||||
import logger from 'cytube-common/lib/logger';
|
import logger from 'cytube-common/lib/logger';
|
||||||
import redisAdapter from 'socket.io-redis';
|
import redisAdapter from 'socket.io-redis';
|
||||||
|
import LegacyConfig from '../config';
|
||||||
|
import IOConfiguration from '../configuration/ioconfig';
|
||||||
|
import * as Switches from '../switches';
|
||||||
|
|
||||||
const BACKEND_CONFIG_PATH = path.resolve(__dirname, '..', '..', 'backend.toml');
|
const BACKEND_CONFIG_PATH = path.resolve(__dirname, '..', '..', 'backend.toml');
|
||||||
|
|
||||||
|
|
@ -67,7 +72,19 @@ class BackendModule {
|
||||||
this.redisClusterClient = new RedisClusterClient(this.getFrontendPool());
|
this.redisClusterClient = new RedisClusterClient(this.getFrontendPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.redisClusterClient;
|
if (Switches.isActive(Switches.DUAL_BACKEND) && !this.nullClusterClient) {
|
||||||
|
this.nullClusterClient = new NullClusterClient(
|
||||||
|
IOConfiguration.fromOldConfig(LegacyConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Switches.isActive(Switches.DUAL_BACKEND)) {
|
||||||
|
this.clusterClient = new DualClusterClient(this.nullClusterClient,
|
||||||
|
this.redisClusterClient);
|
||||||
|
} else {
|
||||||
|
this.clusterClient = this.redisClusterClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.clusterClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
27
src/io/cluster/dualclusterclient.js
Normal file
27
src/io/cluster/dualclusterclient.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import logger from 'cytube-common/lib/logger';
|
||||||
|
import * as Switches from '../../switches';
|
||||||
|
|
||||||
|
class DualClusterClient {
|
||||||
|
constructor(authoritativeClient, altClient) {
|
||||||
|
this.authoritativeClient = authoritativeClient;
|
||||||
|
this.altClient = altClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSocketConfig(channel) {
|
||||||
|
return this.authoritativeClient.getSocketConfig(channel).then(result => {
|
||||||
|
if (!Switches.isActive(Switches.DUAL_BACKEND)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.altClient.getSocketConfig(channel).then(altResult => {
|
||||||
|
result.alt = altResult.servers;
|
||||||
|
return result;
|
||||||
|
}).catch(error => {
|
||||||
|
logger.warn(`Error loading alt servers: ${error}`);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DualClusterClient };
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
const ONE_SECOND = 1000;
|
||||||
|
const ERR_TIMEOUT = 'Timed out when retrieving server information';
|
||||||
|
|
||||||
class RedisClusterClient {
|
class RedisClusterClient {
|
||||||
constructor(frontendPool) {
|
constructor(frontendPool) {
|
||||||
this.frontendPool = frontendPool;
|
this.frontendPool = frontendPool;
|
||||||
|
|
@ -10,7 +15,7 @@ class RedisClusterClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
return { servers: result };
|
return { servers: result };
|
||||||
});
|
}).timeout(ONE_SECOND, ERR_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ import WebConfiguration from './configuration/webconfig';
|
||||||
import NullClusterClient from './io/cluster/nullclusterclient';
|
import NullClusterClient from './io/cluster/nullclusterclient';
|
||||||
import session from './session';
|
import session from './session';
|
||||||
import { LegacyModule } from './legacymodule';
|
import { LegacyModule } from './legacymodule';
|
||||||
|
import * as Switches from './switches';
|
||||||
|
console.log(Switches);
|
||||||
|
|
||||||
var Server = function () {
|
var Server = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
@ -62,6 +64,9 @@ var Server = function () {
|
||||||
// backend init
|
// backend init
|
||||||
var initModule;
|
var initModule;
|
||||||
if (Config.get("new-backend")) {
|
if (Config.get("new-backend")) {
|
||||||
|
if (Config.get("dual-backend")) {
|
||||||
|
Switches.setActive(Switches.DUAL_BACKEND, true);
|
||||||
|
}
|
||||||
const BackendModule = require('./backend/backendmodule').BackendModule;
|
const BackendModule = require('./backend/backendmodule').BackendModule;
|
||||||
initModule = new BackendModule();
|
initModule = new BackendModule();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
11
src/switches.js
Normal file
11
src/switches.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const switches = {};
|
||||||
|
|
||||||
|
export function isActive(switchName) {
|
||||||
|
return switches.hasOwnProperty(switchName) && switches[switchName] === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setActive(switchName, active) {
|
||||||
|
switches[switchName] = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DUAL_BACKEND = 'DUAL_BACKEND';
|
||||||
Loading…
Reference in a new issue