1 j.alex 1.1.2.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 j.alex 1.1.2.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: John Alex
33 //
34 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include <iostream>
39 #include <Pegasus/getoopt/getoopt.h>
40 #include <Clients/cliutils/CommandException.h>
41 #include "StressTestController.h"
42 #include <Pegasus/Common/TimeValue.h>
43 j.alex 1.1.2.1 #include <Pegasus/Common/FileSystem.h>
|
44 j.alex 1.1.2.2
|
45 j.alex 1.1.2.1 //#define DEBUG
46 #include <time.h>
|
47 j.alex 1.1.2.2
48 //
49 // For Windows
50 //
51 #ifdef PEGASUS_OS_TYPE_WINDOWS
52 #include <windows.h> /* for DWORD etc. */
53 typedef DWORD pid_t; /* getpid() and others */
54 #include <process.h>
|
55 j.alex 1.1.2.1 #elif !defined(PEGASUS_OS_OS400)
|
56 j.alex 1.1.2.2 #include <unistd.h>
|
57 j.alex 1.1.2.1 #endif
58
59
60 /**
61 Signal handler set up SIGALARM.
62 */
|
63 j.alex 1.1.2.2 static Boolean useDefaults = false;
|
64 j.alex 1.1.2.1
65
66 /**
67 * Message resource name
68 */
69
|
70 j.alex 1.1.2.2 static const char REQUIRED_ARGS_MISSING [] =
|
71 j.alex 1.1.2.1 "Required arguments missing.";
|
72 j.alex 1.1.2.2 static const char REQUIRED_ARGS_MISSING_KEY [] =
|
73 j.alex 1.1.2.1 "Clients.cimuser.CIMUserCommand.REQUIRED_ARGS_MISSING";
74
|
75 j.alex 1.1.2.2 static const char ERR_OPTION_NOT_SUPPORTED [] =
|
76 j.alex 1.1.2.1 "Invalid option. Use '--help' to obtain command syntax.";
77
|
78 j.alex 1.1.2.2 static const char ERR_OPTION_NOT_SUPPORTED_KEY[] =
|
79 j.alex 1.1.2.1 "Clients.cimuser.CIMUserCommand..ERR_OPTION_NOT_SUPPORTED";
80
|
81 j.alex 1.1.2.2 static const char ERR_USAGE [] =
|
82 j.alex 1.1.2.1 "Incorrect usage. Use '--help' to obtain command syntax.";
83
|
84 j.alex 1.1.2.2 static const char ERR_USAGE_KEY [] =
|
85 j.alex 1.1.2.1 "Clients.cimuser.CIMUserCommand..ERR_USAGE";
86
87
88 // exclude main from the Pegasus Namespace
89 PEGASUS_USING_PEGASUS;
90 PEGASUS_USING_STD;
91
92
93 int main (int argc, char* argv [])
94 {
|
95 j.alex 1.1.2.2 char strTime[256];
|
96 j.alex 1.1.2.1 struct tm tmTime;
|
97 j.alex 1.1.2.2 int rc;
98 String fileName = String::EMPTY;
|
99 j.alex 1.1.2.1 ofstream log_file;
100
101
102 tmTime = getCurrentActualTime();
103 strftime(strTime,256,"%d%m%Y%H%M%S.",&tmTime);
104
|
105 j.alex 1.1.2.2 StressTestControllerCommand command=StressTestControllerCommand();
106
107 //
108 // Generate log files and PID files
109 //
110 if (!command.generateRequiredFileNames(strTime))
|
111 j.alex 1.1.2.1 {
|
112 j.alex 1.1.2.2 cout<<StressTestControllerCommand::COMMAND_NAME\
113 <<"::Failed to generate required files for tests. "<<endl;
114 command.removeUnusedFiles();
115 exit (Command::RC_ERROR);
|
116 j.alex 1.1.2.1 }
117
118 // open the log file
119 OpenAppend(log_file,command.getStressTestLogFile());
120
121 if (!log_file)
122 {
123 log_file.close();
124 cout<<"Cannot get file "<<command.getStressTestLogFile()<<endl;
125 command.removeUnusedFiles();
126 exit (Command::RC_ERROR);
127 }
128 strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
|
129 j.alex 1.1.2.2 log_file<<StressTestControllerCommand::COMMAND_NAME\
130 <<"::Initiated on "<<strTime<<endl;
131 log_file<<StressTestControllerCommand::COMMAND_NAME\
132 <<"::Process ID: "<<getpid()<<endl;
|
133 j.alex 1.1.2.1
134 try
135 {
136 log_file<<StressTestControllerCommand::COMMAND_NAME;
137 log_file<<"::Geting Command Options."<<endl;
138 if(verboseEnabled)
139 {
140 cout<<StressTestControllerCommand::COMMAND_NAME;
141 cout<<"::Getting Command options."<<endl;
142 }
143 //
144 // validate and set command arguments
145 //
146 command.setCommand (argc, argv);
147 }
148 catch (const CommandFormatException& cfe)
149 {
150 String msg(cfe.getMessage());
151
|
152 j.alex 1.1.2.2 log_file<< StressTestControllerCommand::COMMAND_NAME << "::" \
153 << msg << endl;
154 cerr<< StressTestControllerCommand::COMMAND_NAME << "::"\
155 << msg << endl;
|
156 j.alex 1.1.2.1
157 if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND)
158 {
|
159 j.alex 1.1.2.2
160 cerr<< StressTestControllerCommand::COMMAND_NAME <<
161 "::" << ERR_OPTION_NOT_SUPPORTED << endl;
162 log_file<< StressTestControllerCommand::COMMAND_NAME <<
163 "::" << ERR_OPTION_NOT_SUPPORTED << endl;
|
164 j.alex 1.1.2.1 }
165 else
166 {
|
167 j.alex 1.1.2.2 cerr<< StressTestControllerCommand::COMMAND_NAME <<
168 "::" << ERR_USAGE << endl;
169 log_file<< StressTestControllerCommand::COMMAND_NAME <<
170 "::" << ERR_USAGE << endl;
|
171 j.alex 1.1.2.1 }
172
173 log_file.close();
174 command.removeUnusedFiles();
175 exit (Command::RC_ERROR);
176 }
|
177 j.alex 1.1.2.2 catch (...)
|
178 j.alex 1.1.2.1 {
|
179 j.alex 1.1.2.2 log_file<<StressTestControllerCommand::COMMAND_NAME<<
180 "::Unknown exception caught when setting commands."<<endl;
181 cerr<<StressTestControllerCommand::COMMAND_NAME<<
182 "::Unknown exception caught when setting commands."<<endl;
|
183 j.alex 1.1.2.1 log_file.close();
184 command.removeUnusedFiles();
185 exit (Command::RC_ERROR);
186 }
187
188
189 // For help or version options execute usage/version and
190 // exit
|
191 j.alex 1.1.2.2 if ((command.getOperationType() == OPERATION_TYPE_HELP)
|
192 j.alex 1.1.2.1 ||(command.getOperationType() == OPERATION_TYPE_VERSION))
193 {
194 rc = command.execute (cout, cerr);
195 log_file.close();
196 //
197 // Log file not required when help or verbose is opted.
198 //
199 FileSystem::removeFile(command.getStressTestLogFile());
200 exit (rc);
201 }
202
203 String filename;
204
205 //
206 // If a configuration file is specified then:
207 // Check if it exists as indicated, if not
208 // also look for it in the default config dir.
209 //
|
210 j.alex 1.1.2.2 if (command.IsConfigFilePathSpecified())
|
211 j.alex 1.1.2.1 {
|
212 j.alex 1.1.2.2 filename = command.getConfigFilePath();
213 FileSystem::translateSlashes(filename);
214 //
215 // Check whether the file exists or not
216 //
217 if (!FileSystem::exists(filename))
218 {
219 // Check for file in default directory as well
220 fileName = String::EMPTY;
221 fileName.append(StressTestControllerCommand::DEFAULT_CFGDIR);
222 fileName.append(filename);
223
224 if (!FileSystem::exists(fileName))
225 {
226 cerr << StressTestControllerCommand::COMMAND_NAME ;
227 cerr << "::Specified Configuration file \""<<filename;
228 cerr << "\" does not exist."<<endl;
229 log_file.close();
230 command.removeUnusedFiles();
231 exit (Command::RC_ERROR);
232 }
233 j.alex 1.1.2.2 log_file<<StressTestControllerCommand::COMMAND_NAME<<
234 "::Using config file: "<<fileName<<endl;
235 }
236 else
237 {
238 fileName = filename;
239 }
|
240 j.alex 1.1.2.1
|
241 j.alex 1.1.2.2 log_file<<StressTestControllerCommand::COMMAND_NAME<<
242 "::Using config file: "<<fileName<<endl;
243 cout<<StressTestControllerCommand::COMMAND_NAME<<
244 "::Using config file: "<<fileName<<endl;
|
245 j.alex 1.1.2.1 }
246 else
247 {
|
248 j.alex 1.1.2.2 //
249 // Use default file in default dir.
250 //
251 fileName = String::EMPTY;
252 fileName.append(StressTestControllerCommand::DEFAULT_CFGDIR);
253 fileName.append(StressTestControllerCommand::FILENAME);
254 //
255 // Use hard coded default configuration values if default conf. file
256 // was not found.
257 if (!FileSystem::exists(fileName))
258 {
|
259 j.alex 1.1.2.1 //
260 // Use Hard-coded default values
261 //
262 useDefaults = true;
|
263 j.alex 1.1.2.2 }
264 else
265 {
266 log_file << StressTestControllerCommand::COMMAND_NAME <<
|
267 j.alex 1.1.2.1 "::Using default file: " << fileName<<endl;
|
268 j.alex 1.1.2.2 cout << StressTestControllerCommand::COMMAND_NAME <<
|
269 j.alex 1.1.2.1 "::Using default file: " << fileName<<endl;
|
270 j.alex 1.1.2.2 }
|
271 j.alex 1.1.2.1 }
272
273 //
274 // Read the contents of the file
275 //
276 try
277 {
|
278 j.alex 1.1.2.2 //
279 // Use Hard-coded default values
280 //
281 if (useDefaults)
282 {
283 log_file<<StressTestControllerCommand::COMMAND_NAME<<
284 "::Using hard coded default config values."<<endl;
285 cout<<StressTestControllerCommand::COMMAND_NAME<<
286 "::Using hard coded default config values."<<endl;
287 command.getDefaultClients(log_file);
288 }
289 else
290 {
291 log_file << StressTestControllerCommand::COMMAND_NAME <<
|
292 j.alex 1.1.2.1 "::Reading config file: " << fileName<<endl;
|
293 j.alex 1.1.2.2 if (verboseEnabled)
294 {
295 cout<< StressTestControllerCommand::COMMAND_NAME <<
296 "::Reading config file: " << fileName<<endl;
297 }
298 command.getFileContent(fileName,log_file);
299 }
|
300 j.alex 1.1.2.1 }
|
301 j.alex 1.1.2.2 catch (NoSuchFile& e)
|
302 j.alex 1.1.2.1 {
303 String msg(e.getMessage());
304
|
305 j.alex 1.1.2.2 log_file << StressTestControllerCommand::COMMAND_NAME <<
306 ": " << msg << endl;
307 cerr << StressTestControllerCommand::COMMAND_NAME <<
308 ": " << msg << endl;
|
309 j.alex 1.1.2.1 log_file.close();
310 command.removeUnusedFiles();
311 exit (Command::RC_ERROR);
312
313 }
|
314 j.alex 1.1.2.2 catch (Exception& e )
|
315 j.alex 1.1.2.1 {
316 String msg(e.getMessage());
|
317 j.alex 1.1.2.2 log_file << StressTestControllerCommand::COMMAND_NAME <<
318 "::" << msg << endl;
319 cerr << StressTestControllerCommand::COMMAND_NAME <<
320 "::Invalid Configuration ";
|
321 j.alex 1.1.2.1 cerr << "in File: " << fileName << endl;
322 cerr << msg << endl;
323 log_file.close();
324 command.removeUnusedFiles();
325 exit (Command::RC_ERROR);
326 }
|
327 j.alex 1.1.2.2 catch (...)
|
328 j.alex 1.1.2.1 {
329 // throw what was caught
|
330 j.alex 1.1.2.2 log_file<<StressTestControllerCommand::COMMAND_NAME<<
331 "::Unknown exception caught when acquiring configuration."<<endl;
332 cerr<<StressTestControllerCommand::COMMAND_NAME<<
333 "::Unknown exception caught when acquiring configuration."<<endl;
|
334 j.alex 1.1.2.1 log_file.close();
335 command.removeUnusedFiles();
336 exit (Command::RC_ERROR);
337 }
338
|
339 j.alex 1.1.2.2 log_file << StressTestControllerCommand::COMMAND_NAME <<
340 "::Generating Client Commands"<< endl;
|
341 j.alex 1.1.2.1 if(verboseEnabled)
|
342 j.alex 1.1.2.2 {
343 cout << StressTestControllerCommand::COMMAND_NAME <<
344 "::Generating Client Commands"<< endl;
345 }
|
346 j.alex 1.1.2.1
347 //
348 // TimeStamp
349 //
|
350 j.alex 1.1.2.2 log_file<<StressTestControllerCommand::COMMAND_NAME<<
351 "::Initiated on "<<strTime<<endl;
352 log_file<<StressTestControllerCommand::COMMAND_NAME<<
353 "::Process ID: "<<getpid()<<endl;
354 cout<<StressTestControllerCommand::COMMAND_NAME<<
355 "::Initiated on "<<strTime<<endl;
356 cout<<StressTestControllerCommand::COMMAND_NAME<<
357 "::Process ID: "<<getpid()<<endl;
|
358 j.alex 1.1.2.1
359 if(!command.generateClientCommands(log_file))
360 {
|
361 j.alex 1.1.2.2 cerr << StressTestControllerCommand::COMMAND_NAME <<
362 "::Failed to Generate Client Commands."<< endl;
363 log_file << StressTestControllerCommand::COMMAND_NAME <<
364 "::Failed to Generate Client Commands."<< endl;
365 log_file.close();
366 command.removeUnusedFiles();
367 exit (Command::RC_ERROR);
|
368 j.alex 1.1.2.1 }
|
369 j.alex 1.1.2.2
|
370 j.alex 1.1.2.1 //
371 // Getting current time
372 //
373 tmTime = getCurrentActualTime();
374 strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
375 log_file << StressTestControllerCommand::COMMAND_NAME <<endl;
376 log_file << " Preparing to execute Clients on "<<strTime<<endl;
|
377 j.alex 1.1.2.2
|
378 j.alex 1.1.2.1 // Begin to run stress Tests
379 rc = command.execute (cout, cerr);
|
380 j.alex 1.1.2.2
|
381 j.alex 1.1.2.1 //
382 // Getting current time after stress Tests are completed
383 //
384 tmTime = getCurrentActualTime();
|
385 j.alex 1.1.2.2
|
386 j.alex 1.1.2.1 strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
|
387 j.alex 1.1.2.2
|
388 j.alex 1.1.2.1 //
389 // Check overall status of tests
390 //
391 if(rc)
392 {
393 log_file << StressTestControllerCommand::COMMAND_NAME;
394 log_file << "::execution interrupted on "<<strTime<<endl;
395 cout << StressTestControllerCommand::COMMAND_NAME;
396 cout << "::execution interrupted on "<<strTime<<endl;
397 } else {
398 log_file << StressTestControllerCommand::COMMAND_NAME;
399 log_file << "::successfully completed on "<<strTime<<endl;
400 cout << StressTestControllerCommand::COMMAND_NAME;
401 cout << "::successfully completed on "<<strTime<<endl;
402 }
|
403 j.alex 1.1.2.2 cout <<"IMPORTANT: ";
404 cout <<"Please check the Controller and the Client log file"
405 <<endl;
406 cout <<" for individual errors which may or may not have caused"
407 <<endl;
408 cout <<" a stress test failure. "<< endl;
409 cout <<" Log Directory:"<<endl;
410 cout <<" "<<
411 FileSystem::extractFilePath(command.getStressTestLogFile())<<endl;
412 cout <<"\n Controller log: "<<
413 FileSystem::extractFileName(command.getStressTestLogFile())<<endl;
414 cout <<" Client log: "<<
415 FileSystem::extractFileName(command.getStressClientLogFile())<<endl;
|
416 j.alex 1.1.2.1 log_file.close();
417 exit (rc);
418 return rc;
|
419 j.alex 1.1.2.2 } /* main */
|