1 |
|
2 |
|
3 |
|
4 |
|
5 | var ndKeywordFileModelObj = require('./ndKeywordFileModel');
|
6 | var agentSetting = require("./agent-setting");
|
7 | var btManager = require('./BT/btManager.js')
|
8 | var util = require('./util');
|
9 | var btRuleList = require('./BT/btPatternRule.js') ;
|
10 | var ndMthMonitor = require('./method-monitor/ndMethodMonitor.js');
|
11 | var btGlobalRule = require ('./BT/btGlobalRule.js');
|
12 | var btConfig = require('./BT/btConfig');
|
13 | var keywordName = null;
|
14 | var size;
|
15 | var lmd;
|
16 | var keyword;
|
17 | var newFileBasedKeyword = null;
|
18 | var isNewFileExist = -1;
|
19 | var keyWordModel = new Object();
|
20 | function NDFileBasedKeywordHandler()
|
21 | {
|
22 |
|
23 | }
|
24 | NDFileBasedKeywordHandler.clearFileMap = function(ndMethodMonFile)
|
25 | {
|
26 | delete keyWordModel[ndMethodMonFile]
|
27 | }
|
28 |
|
29 | NDFileBasedKeywordHandler.parseFileBasedKeywords = function(clientMsg, clientSocket) {
|
30 | try {
|
31 | var allFields = clientMsg;
|
32 |
|
33 | for (var i = 0; i < allFields.length; i++) {
|
34 | newFileBasedKeyword = null;
|
35 | isNewFileExist = -1;
|
36 |
|
37 | if (allFields[i].toString().startsWith("ndMethodMonFile=")) {
|
38 | keywordName = "ndMethodMonFile";
|
39 |
|
40 | if(allFields[i].toString().indexOf("ndMethodMonFile=NA") != -1) {
|
41 | this.clearFileMap(keywordName);
|
42 | ndMthMonitor.clearMMList();
|
43 | continue;
|
44 | }
|
45 |
|
46 | var oldModel = keyWordModel[keywordName];
|
47 | getFileContent(allFields[i],oldModel, clientSocket, keywordName);
|
48 | }
|
49 |
|
50 | else if (allFields[i].toString().startsWith("BTRuleConfig=")) {
|
51 | keywordName = "BTRuleConfig";
|
52 | if(allFields[i].toString().indexOf("BTRuleConfig=NA") != -1){
|
53 | this.clearFileMap(keywordName);
|
54 | btGlobalRule.clearGlobalObj();
|
55 | btConfig.isPatternBasedRulePresnt = false;
|
56 | btManager.clear();
|
57 | btRuleList.clearList();
|
58 | btConfig.resetBtId();
|
59 | continue ;
|
60 | }
|
61 | var oldModel = keyWordModel[keywordName];
|
62 |
|
63 | getFileContent(allFields[i],oldModel, clientSocket, keywordName);
|
64 | }
|
65 |
|
66 | else if (allFields[i].toString().startsWith("BTTConfig=")) {
|
67 |
|
68 | if(allFields[i].toString().indexOf("BTTConfig=NA") != -1)
|
69 | continue ;
|
70 |
|
71 | keywordName = "BTTConfig";
|
72 | var oldModel = keyWordModel[keywordName];
|
73 |
|
74 | getFileContent(allFields[i],oldModel, clientSocket, keywordName);
|
75 | }
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 | else if (allFields[i].toString().startsWith("ndMethodMonFile=") && (allFields[i].toString().indexOf("ndMethodMonFile=NA;") != -1)) {
|
83 |
|
84 | }
|
85 | else if (allFields[i].toString().startsWith("ndMethodMonFile=") && (allFields[i].toString().indexOf("ndMethodMonFile=NA;") != -1)) {
|
86 |
|
87 | }
|
88 | else if (allFields[i].toString().startsWith("ndMethodMonFile=") && (allFields[i].toString().indexOf("ndMethodMonFile=NA;") != -1)) {
|
89 |
|
90 | }
|
91 | else if (allFields[i].toString().startsWith("ndMethodMonFile=") && (allFields[i].toString().indexOf("ndMethodMonFile=NA;") != -1)) {
|
92 |
|
93 | }
|
94 | else if (allFields[i].toString().startsWith("ndMethodMonFile=") && (allFields[i].toString().indexOf("ndMethodMonFile=NA;") != -1)) {
|
95 |
|
96 | }
|
97 | else if (allFields[i].toString().startsWith("ndMethodMonFile=") && (allFields[i].toString().indexOf("ndMethodMonFile=NA;") != -1)) {
|
98 |
|
99 | }
|
100 | }
|
101 | }
|
102 | catch(err)
|
103 | {util.logger.warn(err)}
|
104 | }
|
105 |
|
106 | function getFileContent(allFields,oldModel,clientSocket,keywordName)
|
107 | {
|
108 | var fileContent = [];
|
109 | var KeywithValue ;
|
110 |
|
111 | try
|
112 | {
|
113 | KeywithValue = allFields.split("=");
|
114 |
|
115 | var newFileName = new ndKeywordFileModelObj();
|
116 |
|
117 | newFileName.ndKeywordFileModel(keywordName,KeywithValue[1]);
|
118 |
|
119 | keyWordModel[newFileName.keywordName] = newFileName;
|
120 |
|
121 | NDFileBasedKeywordHandler.compareAndGetFileContents(oldModel,newFileName,clientSocket);
|
122 |
|
123 | }
|
124 | catch (err) {
|
125 | util.logger.warn(err);
|
126 | }
|
127 | }
|
128 | NDFileBasedKeywordHandler.compareAndGetFileContents = function(oldModel,newModel, clientSocket) {
|
129 | var isChanged = false;
|
130 |
|
131 | if(oldModel) {
|
132 | if ((newModel.lmd != oldModel.lmd) || (newModel.size != oldModel.size) || (newModel.fileName != oldModel.fileName)) {
|
133 | isChanged = true;
|
134 | util.logger.info(agentSetting.currentTestRun," | File Missmatched : lmd prev :" + oldModel.lmd + " ,Size : " + oldModel.size + " ,Name : "+oldModel.name +"\n New file lmd : "+newModel.lmd + " ,Size : " + newModel.size + " ,Name : "+newModel.name);
|
135 | }
|
136 | }
|
137 | else
|
138 | isChanged = true;
|
139 |
|
140 |
|
141 | {
|
142 | try {
|
143 | if(newModel.keywordName == "ndMethodMonFile") {
|
144 | ndMthMonitor.clearMMList();
|
145 | }
|
146 | else if(newModel.keywordName == "BTRuleConfig"){
|
147 | btManager.clear();
|
148 | btGlobalRule.clearGlobalObj();
|
149 | btRuleList.clearList();
|
150 | btConfig.isPatternBasedRulePresnt = false;
|
151 | btConfig.resetBtId();
|
152 | }
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 | clientSocket.write("nd_control_req:action=send_file;keyword="+newModel.keywordName+";" + '\n');
|
159 | util.logger.info(agentSetting.currentTestRun+" | nd_control_req:action=send_file;keyword="+newModel.keywordName+";" + '\n');
|
160 | }
|
161 | catch (err) {
|
162 | util.logger.warn(err);
|
163 | }
|
164 | return 1;
|
165 | }
|
166 | |
167 | ;
|
168 | }
|
169 |
|
170 | NDFileBasedKeywordHandler.readFileContent = function (clientMsg) {
|
171 | try {
|
172 | var allFields = [];
|
173 | var KeywithValue = [];
|
174 |
|
175 | clientMsg = decodeURIComponent(clientMsg);
|
176 | util.logger.info(agentSetting.currentTestRun+" | "+clientMsg)
|
177 | allFields = clientMsg.split(";");
|
178 |
|
179 | if(allFields[0].toString().trim().startsWith("keyword="))
|
180 | {
|
181 | KeywithValue = allFields[0].toString().split("=");
|
182 | if("keyword" == (KeywithValue[0]))
|
183 | {
|
184 | keyword = KeywithValue[1];
|
185 | }
|
186 |
|
187 | KeywithValue = allFields[1].toString().split("=");
|
188 | if("size" == (KeywithValue[0]))
|
189 | {
|
190 | size = Number(KeywithValue[1]);
|
191 | }
|
192 |
|
193 | KeywithValue = allFields[2].toString().split("=");
|
194 | if("lmd" == (KeywithValue[0]))
|
195 | {
|
196 | lmd = KeywithValue[1];
|
197 | }
|
198 | }
|
199 | var mthObj = {"keywordName":keyword,"size":size,"lmd":lmd,type:'file'};
|
200 | return mthObj;
|
201 | }
|
202 | catch (err) {
|
203 | util.logger.warn(err);
|
204 | }
|
205 | }
|
206 | NDFileBasedKeywordHandler.readInstrProfileContent = function (allFields) {
|
207 | try {
|
208 | var KeywithValue = [],size,lmd,keyword;
|
209 |
|
210 | for (var i=0 ; i< allFields.length ;i++) {
|
211 | if (allFields[i].toString().startsWith("InstrProfile=") || allFields[i].toString().indexOf("InstrProfile=/") != -1 || allFields[i].toString().startsWith("instrProfile=") || allFields[i].toString().indexOf("instrProfile=") != -1) {
|
212 | keyword=allFields[i].toString().split('=')[1]
|
213 | if (allFields[i+1].toString().indexOf("size") != -1) {
|
214 | size = allFields[i+1].toString().split('=')[1]
|
215 | }
|
216 |
|
217 | if (allFields[i+2].toString().indexOf("lmd") != -1) {
|
218 | lmd = allFields[i+2].toString().split('=')[1]
|
219 | }
|
220 | break;
|
221 | }
|
222 | }
|
223 | return {"keywordName":keyword,"size":size,"lmd":lmd,type:"instrumentationProfile"};
|
224 | }
|
225 | catch (err) {
|
226 | util.logger.warn(err);
|
227 | }
|
228 | }
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 | NDFileBasedKeywordHandler.setFileContent = function(clientMsg){
|
235 |
|
236 | try {
|
237 | if (keyword == "ndMethodMonFile") {
|
238 | util.logger.info(agentSetting.currentTestRun + " | Reading method monitor file");
|
239 | ndMthMonitor.parseMethodMonitor(clientMsg);
|
240 | }
|
241 | else if (keyword == "BTTConfig") {
|
242 | btConfig.parseThresholdFile(clientMsg);
|
243 | }
|
244 | else if (keyword == "BTRuleConfig") {
|
245 | btConfig.parseBTRuleConfigfile(clientMsg);
|
246 | }
|
247 | }
|
248 | catch(err)
|
249 | {
|
250 | util.logger.warn(err)
|
251 | }
|
252 |
|
253 | }
|
254 | module.exports = NDFileBasedKeywordHandler; |
\ | No newline at end of file |