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 //#define DEBUG
45 #include <time.h>
46 //Windows
47 #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
48 #include <windows.h> /* for DWORD etc. */
49 typedef DWORD pid_t; /* getpid() and others */
50 #include <process.h>
51 #elif !defined(PEGASUS_OS_OS400)
52 #include <unistd.h>
53 #endif
54
55
56 /**
57 Signal handler set up SIGALARM.
58 */
59 static Boolean useDefaults = false;
60
61
62 /**
63 * Message resource name
64 j.alex 1.1.2.1 */
65 static const char MSG_PATH [] = "pegasus/pegasusCLI";
66
67 static const char REQUIRED_ARGS_MISSING [] =
68 "Required arguments missing.";
69 static const char REQUIRED_ARGS_MISSING_KEY [] =
70 "Clients.cimuser.CIMUserCommand.REQUIRED_ARGS_MISSING";
71
72 static const char ERR_OPTION_NOT_SUPPORTED [] =
73 "Invalid option. Use '--help' to obtain command syntax.";
74
75 static const char ERR_OPTION_NOT_SUPPORTED_KEY[] =
76 "Clients.cimuser.CIMUserCommand..ERR_OPTION_NOT_SUPPORTED";
77
78 static const char ERR_USAGE [] =
79 "Incorrect usage. Use '--help' to obtain command syntax.";
80
81 static const char ERR_USAGE_KEY [] =
82 "Clients.cimuser.CIMUserCommand..ERR_USAGE";
83
84
85 j.alex 1.1.2.1 // exclude main from the Pegasus Namespace
86 PEGASUS_USING_PEGASUS;
87 PEGASUS_USING_STD;
88
89
90 int main (int argc, char* argv [])
91 {
92 char strTime[256];
93 struct tm tmTime;
94 int rc;
95 String fileName = String::EMPTY;
96 ofstream log_file;
97
98
99 tmTime = getCurrentActualTime();
100 strftime(strTime,256,"%d%m%Y%H%M%S.",&tmTime);
101
102 StressTestControllerCommand command=StressTestControllerCommand();
103
104 // generate log files and PID files
105 if(!command.generateRequiredFileNames(strTime))
106 j.alex 1.1.2.1 {
107 cout<<StressTestControllerCommand::COMMAND_NAME<<"::Failed to generate required files for tests. "<<endl;
108 command.removeUnusedFiles();
109 exit (Command::RC_ERROR);
110 }
111
112 // open the log file
113 OpenAppend(log_file,command.getStressTestLogFile());
114
115 if (!log_file)
116 {
117 log_file.close();
118 cout<<"Cannot get file "<<command.getStressTestLogFile()<<endl;
119 command.removeUnusedFiles();
120 exit (Command::RC_ERROR);
121
122 }
123 strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
124 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Initiated on "<<strTime<<endl;
125 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Process ID: "<<getpid()<<endl;
126
127 j.alex 1.1.2.1
128 MessageLoader::setPegasusMsgHomeRelative(argv[0]);
129 try
130 {
131 log_file<<StressTestControllerCommand::COMMAND_NAME;
132 log_file<<"::Geting Command Options."<<endl;
133 if(verboseEnabled)
134 {
135 cout<<StressTestControllerCommand::COMMAND_NAME;
136 cout<<"::Getting Command options."<<endl;
137 }
138 //
139 // validate and set command arguments
140 //
141 command.setCommand (argc, argv);
142 }
143 catch (const CommandFormatException& cfe)
144 {
145 String msg(cfe.getMessage());
146
147 log_file << StressTestControllerCommand::COMMAND_NAME << "::" << msg << endl;
148 j.alex 1.1.2.1 cerr << StressTestControllerCommand::COMMAND_NAME << "::" << msg << endl;
149
150 if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND)
151 {
152 MessageLoaderParms parms(ERR_OPTION_NOT_SUPPORTED_KEY,ERR_OPTION_NOT_SUPPORTED);
153 parms.msg_src_path = MSG_PATH;
154 cerr << StressTestControllerCommand::COMMAND_NAME <<
155 ": " << MessageLoader::getMessage(parms) << endl;
156 log_file<< StressTestControllerCommand::COMMAND_NAME <<
157 ": " << MessageLoader::getMessage(parms) << endl;
158 }
159 else
160 {
161 MessageLoaderParms parms(ERR_USAGE_KEY,ERR_USAGE);
162 parms.msg_src_path = MSG_PATH;
163 cerr << StressTestControllerCommand::COMMAND_NAME <<
164 ": " << MessageLoader::getMessage(parms) << endl;
165 log_file << StressTestControllerCommand::COMMAND_NAME <<
166 ": " << MessageLoader::getMessage(parms) << endl;
167 }
168
169 j.alex 1.1.2.1 log_file.close();
170 command.removeUnusedFiles();
171 exit (Command::RC_ERROR);
172 }
173 catch(...)
174 {
175 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Unknown exception caught when setting commands."<<endl;
176 cerr<<StressTestControllerCommand::COMMAND_NAME<<"::Unknown exception caught when setting commands."<<endl;
177 log_file.close();
178 command.removeUnusedFiles();
179 exit (Command::RC_ERROR);
180 }
181
182
183 // For help or version options execute usage/version and
184 // exit
185 if((command.getOperationType() == OPERATION_TYPE_HELP)
186 ||(command.getOperationType() == OPERATION_TYPE_VERSION))
187 {
188 rc = command.execute (cout, cerr);
189 log_file.close();
190 j.alex 1.1.2.1 //
191 // Log file not required when help or verbose is opted.
192 //
193 FileSystem::removeFile(command.getStressTestLogFile());
194 exit (rc);
195 }
196
197 String filename;
198
199 //
200 // If a configuration file is specified then:
201 // Check if it exists as indicated, if not
202 // also look for it in the default config dir.
203 //
204 if(command.IsConfigFilePathSpecified())
205 {
206 filename = command.getConfigFilePath();
207 FileSystem::translateSlashes(filename);
208 //
209 // Check whether the file exists or not
210 //
211 j.alex 1.1.2.1 if (!FileSystem::exists(filename))
212 {
213 // Check for file in default directory as well
214 fileName = String::EMPTY;
215 fileName.append(command.pegasusRoot);
216 fileName.append(StressTestControllerCommand::DEFAULT_CFGDIR);
217 fileName.append(filename);
218
219 if (!FileSystem::exists(fileName))
220 {
221 cerr << StressTestControllerCommand::COMMAND_NAME ;
222 cerr << "::Specified Configuration file \""<<filename;
223 cerr << "\" does not exist."<<endl;
224 log_file.close();
225 command.removeUnusedFiles();
226 exit (Command::RC_ERROR);
227 }
228 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Using config file: "<<fileName<<endl;
229 }
230 else
231 fileName = filename;
232 j.alex 1.1.2.1
233 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Using config file: "<<fileName<<endl;
234 cout<<StressTestControllerCommand::COMMAND_NAME<<"::Using config file: "<<fileName<<endl;
235 }
236 else
237 {
238 //
239 // Use default file in default dir.
240 //
241 fileName = String::EMPTY;
242 fileName.append(command.pegasusRoot);
243 fileName.append(StressTestControllerCommand::DEFAULT_CFGDIR);
244 fileName.append(StressTestControllerCommand::FILENAME);
245 //
246 // Use hard coded default configuration values if default conf. file
247 // was not found.
248 if (!FileSystem::exists(fileName))
249 {
250 //
251 // Use Hard-coded default values
252 //
253 j.alex 1.1.2.1 useDefaults = true;
254 }
255 else
256 {
257 log_file << StressTestControllerCommand::COMMAND_NAME <<
258 "::Using default file: " << fileName<<endl;
259 cout << StressTestControllerCommand::COMMAND_NAME <<
260 "::Using default file: " << fileName<<endl;
261 }
262 }
263
264 //
265 // Read the contents of the file
266 //
267 try
268 {
269 //
270 // Use Hard-coded default values
271 //
272 if(useDefaults)
273 {
274 j.alex 1.1.2.1 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Using hard coded default config values."<<endl;
275 cout<<StressTestControllerCommand::COMMAND_NAME<<"::Using hard coded default config values."<<endl;
276 command.getDefaultClients(log_file);
277 }
278 else
279 {
280 log_file << StressTestControllerCommand::COMMAND_NAME <<
281 "::Reading config file: " << fileName<<endl;
282 if(verboseEnabled)
283 {
284 cout << StressTestControllerCommand::COMMAND_NAME <<
285 "::Reading config file: " << fileName<<endl;
286 }
287 command.getFileContent(fileName,log_file);
288 }
289 }
290 catch(NoSuchFile& e)
291 {
292 String msg(e.getMessage());
293
294 log_file << StressTestControllerCommand::COMMAND_NAME << ": " << msg << endl;
295 j.alex 1.1.2.1 cerr << StressTestControllerCommand::COMMAND_NAME << ": " << msg << endl;
296 log_file.close();
297 command.removeUnusedFiles();
298 exit (Command::RC_ERROR);
299
300 }
301 catch(Exception& e )
302 {
303 String msg(e.getMessage());
304 log_file << StressTestControllerCommand::COMMAND_NAME << "::" << msg << endl;
305 cerr << StressTestControllerCommand::COMMAND_NAME << "::Invalid Configuration ";
306 cerr << "in File: " << fileName << endl;
307 cerr << msg << endl;
308 log_file.close();
309 command.removeUnusedFiles();
310 exit (Command::RC_ERROR);
311 }
312 catch(...)
313 {
314 // throw what was caught
315 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Unknown exception caught when acquiring configuration."<<endl;
316 j.alex 1.1.2.1 cerr<<StressTestControllerCommand::COMMAND_NAME<<"::Unknown exception caught when acquiring configuration."<<endl;
317 log_file.close();
318 command.removeUnusedFiles();
319 exit (Command::RC_ERROR);
320 }
321
322 log_file << StressTestControllerCommand::COMMAND_NAME << "::Generating Client Commands"<< endl;
323 if(verboseEnabled)
324 cout << StressTestControllerCommand::COMMAND_NAME << "::Generating Client Commands"<< endl;
325
326
327 //
328 // TimeStamp
329 //
330 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Initiated on "<<strTime<<endl;
331 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::Process ID: "<<getpid()<<endl;
332 cout<<StressTestControllerCommand::COMMAND_NAME<<"::Initiated on "<<strTime<<endl;
333 cout<<StressTestControllerCommand::COMMAND_NAME<<"::Process ID: "<<getpid()<<endl;
334
335
336 if(!command.generateClientCommands(log_file))
337 j.alex 1.1.2.1 {
338 cerr << StressTestControllerCommand::COMMAND_NAME << "::Failed to Generate Client Commands."<< endl;
339 log_file << StressTestControllerCommand::COMMAND_NAME << "::Failed to Generate Client Commands."<< endl;
340 log_file.close();
341 command.removeUnusedFiles();
342 exit (Command::RC_ERROR);
343 }
344 //
345 // Getting current time
346 //
347 tmTime = getCurrentActualTime();
348 strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
349 log_file << StressTestControllerCommand::COMMAND_NAME <<endl;
350 log_file << " Preparing to execute Clients on "<<strTime<<endl;
351 // Begin to run stress Tests
352 rc = command.execute (cout, cerr);
353 //
354 // Getting current time after stress Tests are completed
355 //
356 tmTime = getCurrentActualTime();
357 strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
358 j.alex 1.1.2.1 //
359 // Check overall status of tests
360 //
361 if(rc)
362 {
363 log_file << StressTestControllerCommand::COMMAND_NAME;
364 log_file << "::execution interrupted on "<<strTime<<endl;
365 cout << StressTestControllerCommand::COMMAND_NAME;
366 cout << "::execution interrupted on "<<strTime<<endl;
367 } else {
368 log_file << StressTestControllerCommand::COMMAND_NAME;
369 log_file << "::successfully completed on "<<strTime<<endl;
370 cout << StressTestControllerCommand::COMMAND_NAME;
371 cout << "::successfully completed on "<<strTime<<endl;
372 }
373 log_file.close();
374 exit (rc);
375 return rc;
376 }
|