/
commands.js
180 lines (169 loc) · 4.89 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const path = require('path');
function newCommand(CmdInfo, TurnInfo) {
const command = {
DryRun: false,
tps: false,
};
if (CmdInfo.DryRun) {
command.DryRun = true;
}
command.config = {
cwd:path.resolve(CmdInfo.Path)
};
return command;
}
exports.PrepareTape = function PrepareTape(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.tps = true;
command.command = 'docker';
command.args = ['run',
'--name',
'tape',
'-e',
'TAPE_LOGLEVEL=debug',
'--network',
'host',
'-v',
path.resolve('./') + ':/config',
'guoger/tape',
'tape',
'-c',
'/config/config.yaml',
'-n',
CmdInfo.tapeCount];
command.info = 'tape start';
return command;
};
exports.prepareEnv = function prepareEnv(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = CmdInfo.PrepareCLI;
command.args = [
TurnInfo.BatchTimeout,
TurnInfo.MaxMessageCount,
TurnInfo.AbsoluteMaxBytes,
TurnInfo.PreferredMaxBytes,
];
command.info = 'prepare genesis block config ' + JSON.stringify(TurnInfo);
return command;
};
exports.prepareStartup = function prepareStartup(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = CmdInfo.StartCLI;
command.args = [
'up', 'createChannel', '-i', '2.2'
];
command.info = 'network up';
return command;
};
exports.prepareCCDeploy = function prepareCCDeploy(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = CmdInfo.CCDeployCLI;
command.args = [
'deployCC', '-d', TurnInfo.BatchTimeout, '-ccn', 'basic', '-ccp', '../asset-transfer-basic/chaincode-go/', '-ccl', 'go'
];
command.config = {
cwd:path.resolve(CmdInfo.Path)
};
command.info = 'deployCC';
return command;
};
exports.prepareSleep = function prepareSleep(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = 'sleep';
command.args = [
CmdInfo.CoolDown
];
command.config = {
cwd:path.resolve(CmdInfo.Path)
};
command.info = 'cool down';
return command;
};
exports.PrepareTapeTearDown = function PrepareTapeTearDown(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = 'docker';
command.args = [
'rm', 'tape'
];
command.config = {
cwd:path.resolve(CmdInfo.Path)
};
command.info = 'tape down';
return command;
};
exports.PrepareTearDown = function PrepareTearDown(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = CmdInfo.ShutDownCLI;
command.args = [
'down'
];
command.config = {
cwd:path.resolve(CmdInfo.Path)
};
command.info = 'network down';
return command;
};
exports.PrepareMonitorUP = function PrepareMonitorUP(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = 'docker';
command.args = [
'network', 'connect', 'net_test', 'prometheus'
];
command.config = {
cwd:path.resolve(CmdInfo.Path)
};
command.info = 'monitor up';
return command;
};
exports.PrepareMonitorDown = function PrepareMonitorDown(CmdInfo, TurnInfo) {
const command = newCommand(CmdInfo, TurnInfo);
command.command = 'docker';
command.args = [
'network', 'disconnect', 'net_test', 'prometheus'
];
command.config = {
cwd:path.resolve(CmdInfo.Path)
};
command.info = 'monitor down';
return command;
};
exports.newVersionCommand = function newVersionCommand(cmd, thePath, dryRun,
BatchTimeout, MaxMessageCountElement, AbsoluteMaxBytes, PreferredMaxBytes) {
const command = {
DryRun: false,
tps: false,
};
if (dryRun) {
command.DryRun = true;
}
command.config = {
cwd : path.resolve(thePath)
};
command.args = [];
command.command = cmd.args[0];
if (cmd.cmdType === 'Shell') {
for (let i = 1; i < cmd.args.length; i++) {
command.args[i - 1] = cmd.args[i];
}
}
if (cmd.cmdType === 'Tape') {
command.tps = true;
let vmount = false;
for (let i = 1; i < cmd.args.length; i++) {
command.args[i - 1] = cmd.args[i];
if (vmount) {
const arr = cmd.args[i].split(':');
command.args[i - 1] = path.resolve(arr[0]) + ':' + arr[1];
vmount = false;
}
if (cmd.args[i] === '-v') {
vmount = true;
}
}
}
if (cmd.cmdType === 'PrePare') {
command.args = [BatchTimeout, MaxMessageCountElement, AbsoluteMaxBytes, PreferredMaxBytes];
}
// console.log(JSON.stringify(command));
return command;
};