Fix dynamic IPC

This commit is contained in:
Anthony Laibe 2018-09-05 10:39:09 +01:00
parent 0f1f3a782a
commit c92f6f8865
4 changed files with 74 additions and 63 deletions

View File

@ -79,18 +79,20 @@ class EmbarkController {
context: self.context, context: self.context,
useDashboard: options.useDashboard, useDashboard: options.useDashboard,
webServerConfig: webServerConfig, webServerConfig: webServerConfig,
webpackConfigName: options.webpackConfigName, webpackConfigName: options.webpackConfigName
ipcRole: 'server'
}); });
engine.init();
if (!options.useDashboard) { async.waterfall([
engine.logger.info('========================'.bold.green); function initEngine(callback) {
engine.logger.info((__('Welcome to Embark') + ' ' + this.version).yellow.bold); engine.init({}, () => {
engine.logger.info('========================'.bold.green); if (!options.useDashboard) {
} engine.logger.info('========================'.bold.green);
engine.logger.info((__('Welcome to Embark') + ' ' + engine.version).yellow.bold);
async.parallel([ engine.logger.info('========================'.bold.green);
}
callback();
});
},
function startDashboard(callback) { function startDashboard(callback) {
if (!options.useDashboard) { if (!options.useDashboard) {
return callback(); return callback();
@ -182,9 +184,12 @@ class EmbarkController {
context: this.context, context: this.context,
webpackConfigName: options.webpackConfigName webpackConfigName: options.webpackConfigName
}); });
engine.init();
async.waterfall([ async.waterfall([
function initEngine(callback) {
engine.init({}, callback);
},
function startServices(callback) { function startServices(callback) {
let pluginList = engine.plugins.listPlugins(); let pluginList = engine.plugins.listPlugins();
if (pluginList.length > 0) { if (pluginList.length > 0) {
@ -250,8 +255,11 @@ class EmbarkController {
context: this.context, context: this.context,
webpackConfigName: options.webpackConfigName webpackConfigName: options.webpackConfigName
}); });
engine.init();
async.waterfall([ async.waterfall([
function initEngine(callback) {
engine.init({}, callback);
},
function startServices(callback) { function startServices(callback) {
let pluginList = engine.plugins.listPlugins(); let pluginList = engine.plugins.listPlugins();
if (pluginList.length > 0) { if (pluginList.length > 0) {
@ -350,9 +358,12 @@ class EmbarkController {
logFile: options.logFile, logFile: options.logFile,
context: this.context context: this.context
}); });
engine.init();
async.waterfall([ async.waterfall([
function (callback) {
engine.init({}, callback);
},
function (callback) { function (callback) {
let pluginList = engine.plugins.listPlugins(); let pluginList = engine.plugins.listPlugins();
if (pluginList.length > 0) { if (pluginList.length > 0) {
@ -436,12 +447,17 @@ class EmbarkController {
context: this.context, context: this.context,
webpackConfigName: options.webpackConfigName webpackConfigName: options.webpackConfigName
}); });
engine.init();
let platform = engine.config.storageConfig.upload.provider;
let platform;
async.waterfall([ async.waterfall([
function initEngine(callback) {
engine.init({}, () => {
platform = engine.config.storageConfig.upload.provider;
callback();
});
},
function startServices(callback) { function startServices(callback) {
engine.startService("processManager"); engine.startService("processManager");

View File

@ -17,11 +17,11 @@ class Engine {
this.context = options.context; this.context = options.context;
this.useDashboard = options.useDashboard; this.useDashboard = options.useDashboard;
this.webServerConfig = options.webServerConfig; this.webServerConfig = options.webServerConfig;
this.ipcRole = options.ipcRole;
this.webpackConfigName = options.webpackConfigName; this.webpackConfigName = options.webpackConfigName;
} }
init(_options) { init(_options, callback) {
callback = callback || function() {};
const Events = require('./events.js'); const Events = require('./events.js');
const Logger = require('./logger.js'); const Logger = require('./logger.js');
const Config = require('./config.js'); const Config = require('./config.js');
@ -38,22 +38,13 @@ class Engine {
utils.interceptLogs(console, this.logger); utils.interceptLogs(console, this.logger);
} }
if (this.ipcRole) {
this.ipc = new IPC({logger: this.logger, ipcRole: this.ipcRole});
if(this.ipc.isServer()) {
this.ipc.serve();
}
return;
}
this.ipc = new IPC({logger: this.logger, ipcRole: 'client'}); this.ipc = new IPC({logger: this.logger, ipcRole: 'client'});
this.ipc.connect((err) => { this.ipc.connect((err) => {
if(err) { if(err) {
this.ipc = new IPC({logger: this.logger, ipcRole: 'server'}); this.ipc = new IPC({logger: this.logger, ipcRole: 'server'});
this.ipc.serve(); this.ipc.serve();
} }
callback();
}); });
} }

View File

@ -6,7 +6,7 @@ class IPC {
constructor(options) { constructor(options) {
this.logger = options.logger; this.logger = options.logger;
this.socketPath = options.socketPath || fs.dappPath(".embark/embark.ipc"); this.socketPath = options.socketPath || fs.dappPath(".embark/embark.ipc");
this.ipcRole = options.ipcRole || "server"; this.ipcRole = options.ipcRole;
ipc.config.silent = true; ipc.config.silent = true;
this.connected = false; this.connected = false;
} }

View File

@ -116,48 +116,52 @@ class Test {
} }
init(callback) { init(callback) {
let self = this;
this.engine = new Engine({ this.engine = new Engine({
env: this.options.env || 'test', env: this.options.env || 'test',
// TODO: config will need to detect if this is a obj // TODO: config will need to detect if this is a obj
embarkConfig: this.options.embarkConfig || 'embark.json', embarkConfig: this.options.embarkConfig || 'embark.json',
interceptLogs: false, interceptLogs: false
ipcRole: 'client'
}); });
async.waterfall([
function initEngine(cb) {
self.engine.init({
logger: new TestLogger({logLevel: self.options.loglevel})
}, cb);
},
function startServices(cb) {
self.versions_default = self.engine.config.contractsConfig.versions;
// Reset contract config to nothing to make sure we deploy only what we want
self.engine.config.contractsConfig = {
contracts: {},
versions: self.versions_default
};
this.engine.init({ self.engine.startService("libraryManager");
logger: new TestLogger({logLevel: this.options.loglevel}) self.engine.startService("codeRunner");
}); self.initDeployServices();
self.engine.startService("codeGenerator");
self.engine.startService("codeCoverage");
this.versions_default = this.engine.config.contractsConfig.versions; if (self.options.node === 'embark') {
// Reset contract config to nothing to make sure we deploy only what we want return self.engine.ipc.connect((err) => {
this.engine.config.contractsConfig = { if (err) {
contracts: {}, this.engine.logger.error(err.message || err);
versions: this.versions_default this.engine.logger.error("Could not connect to Embark's IPC. Is embark running?");
}; process.exit(1);
}
this.engine.startService("libraryManager"); self.engine.ipc.request('blockchain:node', {}, (err, node) => {
this.engine.startService("codeRunner"); if (err) {
this.initDeployServices(); return self.engine.logger.error(err.message || err);
this.engine.startService("codeGenerator"); }
this.engine.startService("codeCoverage"); self.options.node = node;
cb();
if (this.options.node === 'embark') { });
return this.engine.ipc.connect((err) => { });
if (err) {
this.engine.logger.error(err.message || err);
this.engine.logger.error("Could not connect to Embark's IPC. Is embark running?");
process.exit(1);
} }
this.engine.ipc.request('blockchain:node', {}, (err, node) => { cb();
if (err) { }
return this.engine.logger.error(err.message || err); ], callback);
}
this.options.node = node;
callback();
});
});
}
callback();
} }
onReady(callback) { onReady(callback) {