Skip to content

Commit

Permalink
BE-730 Multi profile support (#87)
Browse files Browse the repository at this point in the history
* BE-730 Add support switching among multiple profiles

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>

* BE-730 Add test scenarios for multiple profile case

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>

* BE-730 Add e2e test scenario for multiple profile support

In the following evaluation point of view:

- Check if there are unintented double count of metrics
- Check if each profile is isolated each other

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>

* Add explicit trigger for PR to azure pipeline setting

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>

* Add files to be required new test scenarios

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia committed Mar 16, 2020
1 parent 4b00206 commit 0a97490
Show file tree
Hide file tree
Showing 29 changed files with 1,158 additions and 551 deletions.
3 changes: 2 additions & 1 deletion app/middleware/auth-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ module.exports = (req, res, next) => {
return res.status(401).end();
}

const userId = decoded.sub;
const userId = decoded.user;

req.userId = userId;
req.network = decoded.network;

// TODO: check if a user exists, otherwise error

Expand Down
6 changes: 4 additions & 2 deletions app/passport/local-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const strategy = function(platform) {
const userInfo = await proxy.authenticate(reqUser);

const payload = {
sub: userInfo.user
user: userInfo.user,
network: userInfo.network
};

if (userInfo && !userInfo.authenticated) {
Expand All @@ -53,7 +54,8 @@ const strategy = function(platform) {
// @ts-check
const data = {
message: 'logged in',
name: userData.user
name: userData.user,
network: userData.network
};

return done(null, token, data);
Expand Down
144 changes: 89 additions & 55 deletions app/persistence/fabric/CRUDService.js

Large diffs are not rendered by default.

126 changes: 69 additions & 57 deletions app/persistence/fabric/MetricService.js

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions app/persistence/fabric/postgreSQL/db/explorerpg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ CREATE TABLE blocks
prev_blockhash character varying(256) DEFAULT NULL,
blockhash character varying(256) DEFAULT NULL,
channel_genesis_hash character varying(256) DEFAULT NULL,
blksize integer DEFAULT NULL
blksize integer DEFAULT NULL,
network_name varchar(255)
);

ALTER table blocks owner to :user;
Expand All @@ -43,7 +44,8 @@ CREATE TABLE chaincodes
path character varying(255) DEFAULT NULL,
channel_genesis_hash character varying(256) DEFAULT NULL,
txcount integer DEFAULT 0,
createdt Timestamp DEFAULT NULL
createdt Timestamp DEFAULT NULL,
network_name varchar(255)
);

ALTER table chaincodes owner to :user;
Expand All @@ -61,7 +63,8 @@ CREATE TABLE peer_ref_chaincode
chaincodeid varchar(64) DEFAULT NULL,
cc_version varchar(64) DEFAULT NULL,
channelid character varying(256) DEFAULT NULL,
createdt Timestamp DEFAULT NULL
createdt Timestamp DEFAULT NULL,
network_name varchar(255)
);
ALTER table peer_ref_chaincode owner to :user;

Expand All @@ -84,7 +87,8 @@ CREATE TABLE channel
channel_config bytea default NULL,
channel_block bytea DEFAULT NULL,
channel_tx bytea DEFAULT NULL,
channel_version character varying(128) DEFAULT NULL
channel_version character varying(128) DEFAULT NULL,
network_name varchar(255)
);

ALTER table channel owner to :user;
Expand All @@ -106,7 +110,8 @@ CREATE TABLE peer
events varchar(64) DEFAULT NULL,
server_hostname varchar(64) DEFAULT NULL,
createdt timestamp DEFAULT NULL,
peer_type character varying(64) DEFAULT NULL
peer_type character varying(64) DEFAULT NULL,
network_name varchar(255)
);
ALTER table peer owner to :user;
-- ---------------------------
Expand All @@ -120,7 +125,8 @@ CREATE TABLE peer_ref_channel
createdt Timestamp DEFAULT NULL,
peerid varchar(64),
channelid character varying(256),
peer_type character varying(64) DEFAULT NULL
peer_type character varying(64) DEFAULT NULL,
network_name varchar(255)
);
ALTER table peer_ref_channel owner to :user;

Expand All @@ -137,7 +143,8 @@ CREATE TABLE orderer
id SERIAL PRIMARY KEY,
requests varchar(64) DEFAULT NULL,
server_hostname varchar(64) DEFAULT NULL,
createdt timestamp DEFAULT NULL
createdt timestamp DEFAULT NULL,
network_name varchar(255)
);
ALTER table orderer owner to :user;

Expand Down Expand Up @@ -170,7 +177,8 @@ CREATE TABLE transactions
tx_response character varying DEFAULT NULL,
payload_proposal_hash character varying DEFAULT NULL,
endorser_id_bytes character varying DEFAULT NULL,
endorser_signature character varying DEFAULT NULL
endorser_signature character varying DEFAULT NULL,
network_name varchar(255)
);

ALTER table transactions owner to :user;
Expand Down
4 changes: 1 addition & 3 deletions app/persistence/postgreSQL/PgService.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class PgService {
}

// don't log password
const connectionString = `postgres://${this.pgconfig.username}:******@${
this.pgconfig.host
}:${this.pgconfig.port}/${this.pgconfig.database}`;
const connectionString = `postgres://${this.pgconfig.username}:******@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`;

logger.info(`connecting to Postgresql ${connectionString}`);

Expand Down
7 changes: 4 additions & 3 deletions app/platform/fabric/FabricClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class FabricClient {
* @param {*} client_name
* @memberof FabricClient
*/
constructor(client_name) {
constructor(network_name, client_name) {
this.network_name = network_name;
this.client_name = client_name;
this.hfc_client = null;
this.fabricGateway = null;
Expand Down Expand Up @@ -213,7 +214,7 @@ class FabricClient {
const default_peer_name = defaultPeerConfig.name;
const channels = await persistence
.getCrudService()
.getChannelsInfo(default_peer_name);
.getChannelsInfo(this.network_name, default_peer_name);

const default_channel_name = fabricConfig.getDefaultChannel();

Expand All @@ -225,7 +226,7 @@ class FabricClient {
this.setChannelGenHash(channel.channelname, channel.channel_genesis_hash);
const nodes = await persistence
.getMetricService()
.getPeerList(channel.channel_genesis_hash);
.getPeerList(this.network_name, channel.channel_genesis_hash);
let newchannel;
try {
newchannel = this.hfc_client.getChannel(channel.channelname);
Expand Down
65 changes: 25 additions & 40 deletions app/platform/fabric/Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Platform {
}

for (const network_name in this.network_configs) {
this.networks.set(network_name, new Map());
// this.networks.set(network_name, new Map());
const client_configs = this.network_configs[network_name];
// Console.log('network_name ', network_name, ' client_configs ', client_configs)
if (!this.defaultNetwork) {
Expand Down Expand Up @@ -138,23 +138,23 @@ class Platform {
logger.info('FabricUtils.createFabricClient ');
client = await FabricUtils.createFabricClient(
client_configs,
network_name,
client_name,
this.persistence
);
} else {
logger.info('FabricUtils.createDetachClient ');
client = await FabricUtils.createDetachClient(
client_configs,
network_name,
client_name,
this.persistence
);
}
if (client) {
// Set client into clients map
logger.info('FabricUtils.createDetachClient ');
const clients = this.networks.get(network_name);
clients.set(client_name, client);
// Console.log('clients ', clients);
const clientObj = { name: client_name, instance: client };
this.networks.set(network_name, clientObj);
}
// }
}
Expand All @@ -168,19 +168,19 @@ class Platform {
*/
initializeListener(syncconfig) {
/* eslint-disable */
for (const [network_name, clients] of this.networks.entries()) {
for (const [client_name, client] of clients.entries()) {
logger.info(
'initializeListener, client_name, client ',
client_name,
client.client_config
);
if (this.getClient(network_name, client_name).getStatus()) {
const explorerListener = new ExplorerListener(this, syncconfig);
explorerListener.initialize([network_name, client_name, '1']);
explorerListener.send('Successfully send a message to child process');
this.explorerListeners.push(explorerListener);
}
for (const [network_name, clientObj] of this.networks.entries()) {
const client_name = clientObj.name;
const client = clientObj.instance;
logger.info(
'initializeListener, client_name, client ',
client_name,
client.client_config
);
if (this.getClient(network_name).getStatus()) {
const explorerListener = new ExplorerListener(this, syncconfig);
explorerListener.initialize([network_name, client_name, '1']);
explorerListener.send('Successfully send a message to child process');
this.explorerListeners.push(explorerListener);
}
}
/* eslint-enable */
Expand Down Expand Up @@ -210,25 +210,11 @@ class Platform {
* @returns
* @memberof Platform
*/
changeNetwork(network_name, client_name, channel_name) {
const network = this.networks.get(network_name);
if (network) {
changeNetwork(network_name, channel_name) {
const clientObj = this.networks.get(network_name);
if (clientObj) {
this.defaultNetwork = network_name;
let client;
if (client_name) {
client = network.get(client_name);
if (client) {
this.defaultClient = client_name;
} else {
return `Client [${network_name}] is not found in network`;
}
} else {
const iterator = network.values();
client = iterator.next().value;
if (!client) {
return `Client [${network_name}] is not found in network`;
}
}
const client = clientObj.instance;
if (channel_name) {
client.setDefaultChannel(channel_name);
}
Expand All @@ -255,10 +241,9 @@ class Platform {
* @returns
* @memberof Platform
*/
getClient(network_name, client_name) {
return this.networks
.get(network_name || this.defaultNetwork)
.get(client_name || this.defaultClient);
getClient(network_name) {
const clientObj = this.networks.get(network_name || this.defaultNetwork);
return clientObj.instance;
}

/**
Expand Down

0 comments on commit 0a97490

Please sign in to comment.