benchmark.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Page designed to help in benchmarkink the scalability of itop
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once('../application/application.inc.php');
  25. require_once('../application/itopwebpage.class.inc.php');
  26. require_once('../application/wizardhelper.class.inc.php');
  27. require_once('../application/startup.inc.php');
  28. require_once('../application/loginwebpage.class.inc.php');
  29. require_once('../application/utils.inc.php');
  30. require_once('./setuppage.class.inc.php');
  31. //ini_set('memory_limit', '2048M');
  32. class BenchmarkDataCreation
  33. {
  34. var $m_iIfByServer;
  35. var $m_iIfByNWDevice;
  36. var $m_aRequested;
  37. var $m_aPlanned;
  38. var $m_aCreatedByClass = array();
  39. var $m_aCreatedByDesc = array();
  40. var $m_aStatsByClass = array();
  41. var $m_oChange;
  42. public function __construct()
  43. {
  44. $this->m_oChange = MetaModel::NewObject("CMDBChange");
  45. $this->m_oChange->Set("date", time());
  46. $this->m_oChange->Set("userinfo", "Benchmark setup");
  47. $iChangeId = $this->m_oChange->DBInsertNoReload();
  48. }
  49. public function PlanStructure($iPlannedContacts, $iPlannedContracts)
  50. {
  51. $this->m_aRequested = array(
  52. 'plannedcontacts' => $iPlannedContacts,
  53. 'plannedcontracts' => $iPlannedContracts,
  54. );
  55. $this->m_aPlanned = array(
  56. 'Contacts' => $iPlannedContacts,
  57. 'Contracts' => $iPlannedContracts,
  58. 'Documents' => $iPlannedContracts * 2,
  59. );
  60. }
  61. public function PlanCis($iPlannedCIs)
  62. {
  63. $this->m_aRequested = array(
  64. 'plannedcis' => $iPlannedCIs,
  65. );
  66. $this->m_iIfByServer = 2;
  67. $this->m_iIfByNWDevice = 10;
  68. $iServers = ceil($iPlannedCIs * 9 / 10);
  69. $iNWDevices = ceil($iPlannedCIs / 10);
  70. $iInterfaces = $iServers * $this->m_iIfByServer + $iNWDevices * $this->m_iIfByNWDevice;
  71. $iApplications = $iServers * 5;
  72. $iSolutions = ceil($iApplications / 2);
  73. $iProcesses = ceil($iSolutions / 2);
  74. $this->m_aPlanned = array(
  75. 'Network devices' => $iNWDevices,
  76. 'Servers' => $iServers,
  77. 'Interfaces' => $iInterfaces,
  78. 'Application SW' => 2,
  79. 'Applications' => $iApplications,
  80. 'Solutions' => $iSolutions,
  81. 'Processes' => $iProcesses,
  82. );
  83. }
  84. public function PlanTickets($iPlannedTickets, $iBigTicketCis)
  85. {
  86. $this->m_aRequested = array(
  87. 'plannedtickets' => $iPlannedTickets,
  88. 'plannedbigticketcis' => $iBigTicketCis,
  89. );
  90. $this->m_aPlanned = array(
  91. 'Incidents' => ceil($iPlannedTickets / 2),
  92. 'Changes' => ceil($iPlannedTickets / 2),
  93. 'Big ticket: CIs' => $iBigTicketCis,
  94. );
  95. }
  96. public function ShowPlans($oP)
  97. {
  98. $oP->add("<h2>Planned creations</h2>\n");
  99. $aPlanned = $this->m_aPlanned;
  100. $aForm = array();
  101. foreach ($aPlanned as $sKey => $iCount)
  102. {
  103. $aForm[] = array(
  104. 'label' => $sKey,
  105. 'input' => $iCount,
  106. );
  107. }
  108. $oP->form($aForm);
  109. }
  110. public function ShowForm($oP, $sNextOperation)
  111. {
  112. $aRequested = $this->m_aRequested;
  113. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Loading data...', 10)\">\n");
  114. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  115. foreach($this->m_aRequested as $sName => $sValue)
  116. {
  117. $oP->add("<input type=\"hidden\" name=\"$sName\" value=\"$sValue\">\n");
  118. }
  119. $oP->add("<button type=\"submit\">Next >></button>\n");
  120. $oP->add("</form>\n");
  121. }
  122. protected function CreateObject($sClass, $aData, $sClassDesc = '')
  123. {
  124. $mu_t1 = MyHelpers::getmicrotime();
  125. $oMyObject = MetaModel::NewObject($sClass);
  126. foreach($aData as $sProp => $value)
  127. {
  128. $oMyObject->Set($sProp, $value);
  129. }
  130. $iId = $oMyObject->DBInsertTrackedNoReload($this->m_oChange);
  131. $sClassId = "$sClass ($sClassDesc)";
  132. $this->m_aCreatedByDesc[$sClassId][] = $iId;
  133. $this->m_aCreatedByClass[$sClass][] = $iId;
  134. $mu_t2 = MyHelpers::getmicrotime();
  135. $this->m_aStatsByClass[$sClass][] = $mu_t2 - $mu_t1;
  136. return $iId;
  137. }
  138. static $m_aClassIdCache = array();
  139. protected function GetClassIds($sClass)
  140. {
  141. if (!isset(self::$m_aClassIdCache[$sClass]))
  142. {
  143. // Load the cache now
  144. self::$m_aClassIdCache[$sClass] = array();
  145. $oSet = new DBObjectSet(new DBObjectSearch($sClass));
  146. while($oObj = $oSet->Fetch())
  147. {
  148. self::$m_aClassIdCache[$sClass][] = $oObj->GetKey();
  149. }
  150. }
  151. return self::$m_aClassIdCache[$sClass];
  152. }
  153. protected function RandomId($sClass, $sClassDesc = '')
  154. {
  155. $sClassId = "$sClass ($sClassDesc)";
  156. if (isset($this->m_aCreatedByDesc[$sClassId]))
  157. {
  158. return $this->m_aCreatedByDesc[$sClassId][array_rand($this->m_aCreatedByDesc[$sClassId])];
  159. }
  160. $aIds = self::GetClassIds($sClass);
  161. return $aIds[array_rand($aIds)];
  162. }
  163. static protected function FindId($sClass)
  164. {
  165. $oSet = new DBObjectSet(new DBObjectSearch($sClass));
  166. if ($oSet->Count() < 1)
  167. {
  168. return null;
  169. }
  170. $oObj = $oSet->Fetch();
  171. return $oObj->GetKey();
  172. }
  173. static protected function FindIdFromOQL($sOQL)
  174. {
  175. $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL));
  176. if ($oSet->Count() < 1)
  177. {
  178. return null;
  179. }
  180. $oObj = $oSet->Fetch();
  181. return $oObj->GetKey();
  182. }
  183. protected function my_array_rand($aData, $iCount)
  184. {
  185. if ($iCount == 0)
  186. {
  187. return array();
  188. }
  189. elseif ($iCount == 1)
  190. {
  191. $aSample = array(array_rand($aData));
  192. }
  193. elseif ($iCount <= count($aData))
  194. {
  195. $aSample = array_rand($aData, $iCount);
  196. }
  197. else
  198. {
  199. $aSample = array_merge(array_rand($aData, count($aData)), self::my_array_rand($aData, $iCount - count($aData)));
  200. }
  201. return $aSample;
  202. }
  203. protected function CreateLinks($iFrom, $iCount, $sLinkClass, $sAttCodeFrom, $sAttCodeTo)
  204. {
  205. $oAttTo = MetaModel::GetAttributeDef($sLinkClass, $sAttCodeTo);
  206. $sToClass = $oAttTo->GetTargetClass();
  207. $aTargets = self::GetClassIds($sToClass);
  208. $aSample = self::my_array_rand($aTargets, $iCount);
  209. for($iLinked = 0 ; $iLinked < $iCount ; $iLinked++)
  210. {
  211. $aData = array(
  212. $sAttCodeFrom => $iFrom,
  213. $sAttCodeTo => $aSample[$iLinked],
  214. );
  215. $this->CreateObject($sLinkClass, $aData);
  216. }
  217. }
  218. public function CreateStructure($oP)
  219. {
  220. $aClasses = MetaModel::GetClasses();
  221. $aActions = array('Read', 'Bulk Read', 'Delete', 'Bulk Delete', 'Modify', 'Bulk Modify');
  222. $aStdProfiles = array(2, 3, 4, 5, 6, 7, 8, 9);
  223. ////////////////////////////////////////
  224. // New specific profile, giving access to everything
  225. //
  226. $aData = array(
  227. 'name' => 'Data guru',
  228. 'description' => 'Could do anything, because everything is granted',
  229. );
  230. $iGuruProfile = $this->CreateObject('URP_Profiles', $aData);
  231. foreach($aClasses as $sClass)
  232. {
  233. foreach($aActions as $sAction)
  234. {
  235. $aData = array(
  236. 'profileid' => $iGuruProfile,
  237. 'class' => $sClass,
  238. 'permission' => 'yes',
  239. 'action' => $sAction,
  240. );
  241. $this->CreateObject('URP_ActionGrant', $aData);
  242. }
  243. }
  244. // User login with super access rights
  245. //
  246. $aData = array(
  247. 'org_id' => self::FindId('Organization'),
  248. 'location_id' => self::FindId('Location'),
  249. 'first_name' => 'Jesus',
  250. 'name' => 'Deus',
  251. 'email' => '',
  252. );
  253. $iPerson = $this->CreateObject('Person', $aData);
  254. $aData = array(
  255. 'contactid' => $iPerson,
  256. 'login' => 'guru',
  257. 'password' => 'guru',
  258. 'language' => 'EN US',
  259. );
  260. $iLogin = $this->CreateObject('UserLocal', $aData);
  261. // Assign the guru profile to the new login
  262. //
  263. $aData = array(
  264. 'userid' => $iLogin,
  265. 'profileid' => $iGuruProfile,
  266. 'reason' => 'he is the one',
  267. );
  268. $this->CreateObject('URP_UserProfile', $aData);
  269. ////////////////////////////////////////
  270. // User login having all std profiles
  271. //
  272. $aData = array(
  273. 'org_id' => self::FindId('Organization'),
  274. 'location_id' => self::FindId('Location'),
  275. 'first_name' => 'Little ze',
  276. 'name' => 'Foo',
  277. 'email' => '',
  278. );
  279. $iPerson = $this->CreateObject('Person', $aData);
  280. $aData = array(
  281. 'contactid' => $iPerson,
  282. 'login' => 'foo',
  283. 'password' => 'foo',
  284. 'language' => 'EN US',
  285. );
  286. $iLogin = $this->CreateObject('UserLocal', $aData);
  287. // Assign profiles to the new login
  288. //
  289. foreach($aStdProfiles as $iProfileId)
  290. {
  291. $aData = array(
  292. 'userid' => $iLogin,
  293. 'profileid' => $iProfileId,
  294. 'reason' => '',
  295. );
  296. $this->CreateObject('URP_UserProfile', $aData);
  297. }
  298. /////////////////////////
  299. //
  300. // Organizations
  301. //
  302. $aData = array(
  303. 'name' => 'Benchmark',
  304. );
  305. $iOrg = $this->CreateObject('Organization', $aData);
  306. /////////////////////////
  307. //
  308. // Locations
  309. //
  310. $aData = array(
  311. 'org_id' => $iOrg,
  312. 'name' => 'Rio de Janeiro',
  313. );
  314. $iLoc = $this->CreateObject('Location', $aData);
  315. /////////////////////////
  316. //
  317. // Teams
  318. //
  319. $aData = array(
  320. 'org_id' => $iOrg,
  321. 'location_id' => $iLoc,
  322. 'name' => 'Fluminense',
  323. 'email' => 'fluminense@nowhere.fr',
  324. );
  325. $iTeam = $this->CreateObject('Team', $aData);
  326. /////////////////////////
  327. //
  328. // Persons
  329. //
  330. for($i = 0 ; $i < $this->m_aPlanned['Contacts'] ; $i++)
  331. {
  332. $aData = array(
  333. 'org_id' => $iOrg,
  334. 'location_id' => $iLoc,
  335. 'first_name' => 'Joaõ',
  336. 'name' => 'Ningem #'.$i,
  337. 'email' => 'foo'.$i.'@nowhere.fr',
  338. );
  339. $iPerson = $this->CreateObject('Person', $aData);
  340. // Contract/Infra
  341. //
  342. $aData = array(
  343. 'contact_id' => $iPerson,
  344. 'team_id' => $this->RandomId('Team'),
  345. );
  346. $this->CreateObject('lnkTeamToContact', $aData);
  347. }
  348. /////////////////////////
  349. //
  350. // Services
  351. //
  352. $aData = array(
  353. 'org_id' => $iOrg,
  354. 'name' => 'My Service',
  355. );
  356. $iOrg = $this->CreateObject('Service', $aData);
  357. /////////////////////////
  358. //
  359. // Service subcategories
  360. //
  361. $aData = array(
  362. 'name' => 'My subcategory',
  363. );
  364. $iOrg = $this->CreateObject('ServiceSubcategory', $aData);
  365. /////////////////////////
  366. //
  367. // Contracts
  368. //
  369. for($i = 0 ; $i < $this->m_aPlanned['Contracts'] ; $i++)
  370. {
  371. $aData = array(
  372. 'name' => "Contract #$i",
  373. 'description' => 'Created for benchmarking purposes',
  374. 'org_id' => $this->RandomId('Organization'),
  375. 'provider_id' => $this->RandomId('Organization'),
  376. 'start_date' => '2009-12-25',
  377. 'end_date' => '2019-08-01',
  378. 'support_team_id' => $this->RandomId('Team'),
  379. );
  380. $iContract = $this->CreateObject('CustomerContract', $aData);
  381. // Contract/Contact (10% of contacts)
  382. //
  383. $iContactCount = ceil($this->m_aPlanned['Contracts'] / 10);
  384. for($iLinked = 0 ; $iLinked < $iContactCount ; $iLinked++)
  385. {
  386. $aData = array(
  387. 'contact_id' => $this->RandomId('Person'),
  388. 'contract_id' => $iContract,
  389. 'role' => 'role '.$iLinked,
  390. );
  391. $this->CreateObject('lnkContractToContact', $aData);
  392. }
  393. }
  394. /////////////////////////
  395. //
  396. // Documents
  397. //
  398. $sMyDoc = '';
  399. for($i = 0 ; $i < 1000 ; $i++)
  400. {
  401. // 100 chars
  402. $sMyDoc .= "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n";
  403. }
  404. $oRefDoc = new ormDocument($sMyDoc, 'text/plain');
  405. for($i = 0 ; $i < $this->m_aPlanned['Documents'] ; $i++)
  406. {
  407. $aData = array(
  408. //'org_id' => $iOrg,
  409. 'name' => "document$i",
  410. 'contents' => $oRefDoc,
  411. );
  412. $this->CreateObject('FileDoc', $aData);
  413. }
  414. }
  415. public function CreateCis($oP)
  416. {
  417. $iOrg = $this->FindIdFromOQL("SELECT Organization WHERE name = 'Benchmark'");
  418. $iLoc = $this->FindIdFromOQL("SELECT Location WHERE org_id = $iOrg");
  419. /////////////////////////
  420. //
  421. // Servers
  422. //
  423. for($i = 0 ; $i < $this->m_aPlanned['Servers'] ; $i++)
  424. {
  425. $aData = array(
  426. 'org_id' => $iOrg,
  427. 'location_id' => $iLoc,
  428. 'name' => 'server'.$i,
  429. 'status' => 'production',
  430. );
  431. $iServer = $this->CreateObject('Server', $aData);
  432. // Contract/Infra
  433. $this->CreateLinks($iServer, 1, 'lnkContractToCI', 'ci_id', 'contract_id');
  434. // Interfaces
  435. for($iLinked = 0 ; $iLinked < $this->m_iIfByServer ; $iLinked++)
  436. {
  437. $aData = array(
  438. 'name' => "eth$iLinked",
  439. 'status' => 'implementation',
  440. 'org_id' => $iOrg,
  441. 'device_id' => $iServer,
  442. 'status' => 'production',
  443. );
  444. $this->CreateObject('NetworkInterface', $aData, 'server if');
  445. }
  446. }
  447. /////////////////////////
  448. //
  449. // Network devices
  450. //
  451. for($i = 0 ; $i < $this->m_aPlanned['Network devices'] ; $i++)
  452. {
  453. $aData = array(
  454. 'org_id' => $iOrg,
  455. 'location_id' => $iLoc,
  456. 'name' => 'equipment #'.$i,
  457. 'status' => 'production',
  458. );
  459. $iNWDevice = $this->CreateObject('NetworkDevice', $aData);
  460. // Contract/Infra
  461. $this->CreateLinks($iNWDevice, 1, 'lnkContractToCI', 'ci_id', 'contract_id');
  462. // Interfaces
  463. //
  464. for($iLinked = 0 ; $iLinked < $this->m_iIfByNWDevice ; $iLinked++)
  465. {
  466. $aData = array(
  467. 'name' => "eth$iLinked",
  468. 'status' => 'implementation',
  469. 'org_id' => $iOrg,
  470. 'device_id' => $iNWDevice,
  471. 'connected_if' => $this->RandomId('NetworkInterface', 'server if'),
  472. 'status' => 'production',
  473. );
  474. $this->CreateObject('NetworkInterface', $aData, 'equipment if');
  475. }
  476. }
  477. /////////////////////////
  478. //
  479. // Application Software
  480. //
  481. for($i = 0 ; $i < $this->m_aPlanned['Application SW'] ; $i++)
  482. {
  483. $aData = array(
  484. 'name' => 'Software #'.$i,
  485. );
  486. $iNWDevice = $this->CreateObject('Application', $aData);
  487. }
  488. /////////////////////////
  489. //
  490. // Applications
  491. //
  492. for($i = 0 ; $i < $this->m_aPlanned['Applications'] ; $i++)
  493. {
  494. $aData = array(
  495. 'org_id' => $iOrg,
  496. 'device_id' => $this->RandomId('Server'),
  497. 'software_id' => $this->RandomId('Application'),
  498. 'name' => 'Application #'.$i,
  499. 'status' => 'production',
  500. );
  501. $iAppInstance = $this->CreateObject('ApplicationInstance', $aData);
  502. // Contract/Infra
  503. $this->CreateLinks($iAppInstance, 1, 'lnkContractToCI', 'ci_id', 'contract_id');
  504. }
  505. /////////////////////////
  506. //
  507. // Application Solution
  508. //
  509. for($i = 0 ; $i < $this->m_aPlanned['Solutions'] ; $i++)
  510. {
  511. $aData = array(
  512. 'org_id' => $iOrg,
  513. 'name' => 'Solution #'.$i,
  514. 'status' => 'production',
  515. );
  516. $iAppSolution = $this->CreateObject('ApplicationSolution', $aData);
  517. // Contract/Infra
  518. $this->CreateLinks($iAppSolution, 1, 'lnkContractToCI', 'ci_id', 'contract_id');
  519. }
  520. /////////////////////////
  521. //
  522. // Business Process
  523. //
  524. for($i = 0 ; $i < $this->m_aPlanned['Processes'] ; $i++)
  525. {
  526. $aData = array(
  527. 'org_id' => $iOrg,
  528. 'name' => 'Process #'.$i,
  529. 'status' => 'production',
  530. );
  531. $iProcess = $this->CreateObject('BusinessProcess', $aData);
  532. // Contract/Infra
  533. $this->CreateLinks($iProcess, 1, 'lnkContractToCI', 'ci_id', 'contract_id');
  534. }
  535. }
  536. public function CreateTickets($oP)
  537. {
  538. $iOrg = $this->FindIdFromOQL("SELECT Organization WHERE name = 'Benchmark'");
  539. $iLoc = $this->FindIdFromOQL("SELECT Location WHERE org_id = $iOrg");
  540. /////////////////////////
  541. //
  542. // Incident Tickets
  543. //
  544. for($i = 0 ; $i < $this->m_aPlanned['Incidents'] ; $i++)
  545. {
  546. $aData = array(
  547. 'org_id' => $iOrg,
  548. 'caller_id' => $this->RandomId('Person'),
  549. 'workgroup_id' => $this->RandomId('Team'),
  550. 'agent_id' => $this->RandomId('Person'),
  551. 'service_id' => $this->RandomId('Service'),
  552. 'servicesubcategory_id' => $this->RandomId('ServiceSubcategory'),
  553. 'title' => 'Incident #'.$i,
  554. 'ticket_log' => 'Testing...',
  555. );
  556. $iTicket = $this->CreateObject('Incident', $aData);
  557. // Incident/Infra
  558. $iInfraCount = rand(1, 6);
  559. $this->CreateLinks($iTicket, $iInfraCount, 'lnkTicketToCI', 'ticket_id', 'ci_id');
  560. // Incident/Infra
  561. $iContactCount = rand(1, 6);
  562. $this->CreateLinks($iTicket, $iContactCount, 'lnkTicketToContact', 'ticket_id', 'contact_id');
  563. }
  564. /////////////////////////
  565. //
  566. // Big Ticket
  567. //
  568. $aData = array(
  569. 'org_id' => $iOrg,
  570. 'caller_id' => $this->RandomId('Person'),
  571. 'workgroup_id' => $this->RandomId('Team'),
  572. 'agent_id' => $this->RandomId('Person'),
  573. 'service_id' => $this->RandomId('Service'),
  574. 'servicesubcategory_id' => $this->RandomId('ServiceSubcategory'),
  575. 'title' => 'Big ticket',
  576. 'ticket_log' => 'Testing...',
  577. );
  578. $iTicket = $this->CreateObject('Incident', $aData);
  579. // Incident/Infra
  580. $iInfraCount = $this->m_aPlanned['Big ticket: CIs'];
  581. $this->CreateLinks($iTicket, $iInfraCount, 'lnkTicketToCI', 'ticket_id', 'ci_id');
  582. // Incident/Infra
  583. $iContactCount = rand(1, 6);
  584. $this->CreateLinks($iTicket, $iContactCount, 'lnkTicketToContact', 'ticket_id', 'contact_id');
  585. /////////////////////////
  586. //
  587. // Change Tickets
  588. //
  589. for($i = 0 ; $i < $this->m_aPlanned['Changes'] ; $i++)
  590. {
  591. $aData = array(
  592. 'org_id' => $iOrg,
  593. 'requestor_id' => $this->RandomId('Person'),
  594. 'workgroup_id' => $this->RandomId('Team'),
  595. 'agent_id' => $this->RandomId('Person'),
  596. 'supervisor_group_id' => $this->RandomId('Team'),
  597. 'supervisor_id' => $this->RandomId('Person'),
  598. 'manager_group_id' => $this->RandomId('Team'),
  599. 'manager_id' => $this->RandomId('Person'),
  600. 'title' => 'change #'.$i,
  601. 'description' => "Let's do something there",
  602. );
  603. $iTicket = $this->CreateObject('NormalChange', $aData);
  604. // Incident/Infra
  605. $iInfraCount = rand(1, 6);
  606. $this->CreateLinks($iTicket, $iInfraCount, 'lnkTicketToCI', 'ticket_id', 'ci_id');
  607. // Incident/Infra
  608. $iContactCount = rand(1, 6);
  609. $this->CreateLinks($iTicket, $iContactCount, 'lnkTicketToContact', 'ticket_id', 'contact_id');
  610. }
  611. }
  612. public function MakeFeedback($oP)
  613. {
  614. foreach($this->m_aCreatedByClass as $sClass => $aClassIds)
  615. {
  616. $iSample = reset($aClassIds);
  617. $sSample = "<a href=\"../pages/UI.php?operation=details&class=$sClass&id=$iSample\">sample</a>";
  618. $iDuration = number_format(array_sum($this->m_aStatsByClass[$sClass]), 3);
  619. $fDurationMin = number_format(min($this->m_aStatsByClass[$sClass]), 3);
  620. $fDurationMax = number_format(max($this->m_aStatsByClass[$sClass]), 3);
  621. $fDurationAverage = number_format(array_sum($this->m_aStatsByClass[$sClass]) / count($this->m_aStatsByClass[$sClass]), 3);
  622. $oP->add("<ul>");
  623. $oP->add("<li>");
  624. $oP->add("$sClass: ".count($this->m_aStatsByClass[$sClass])." - $sSample<br/>");
  625. $oP->add("Duration: $fDurationMin =&gt; $fDurationMax; Avg:$fDurationAverage; Total: $iDuration");
  626. $oP->add("</li>");
  627. $oP->add("</ul>");
  628. }
  629. }
  630. }
  631. /**
  632. * Ask the user what are the settings for the data load
  633. */
  634. function DisplayStep1(SetupWebPage $oP)
  635. {
  636. $sNextOperation = 'step2';
  637. $oP->add("<h1>iTop benchmarking</h1>\n");
  638. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Evaluating real plans...', 10)\">\n");
  639. $oP->add("<fieldset><legend>Data load configuration</legend>\n");
  640. $aForm = array();
  641. $aForm[] = array(
  642. 'label' => "Contacts:",
  643. 'input' => "<input id=\"from\" type=\"text\" name=\"plannedcontacts\" value=\"100\">",
  644. 'help' => '',
  645. );
  646. $aForm[] = array(
  647. 'label' => "Contracts:",
  648. 'input' => "<input id=\"from\" type=\"text\" name=\"plannedcontracts\" value=\"10\">",
  649. 'help' => '',
  650. );
  651. $oP->form($aForm);
  652. $oP->add("</fieldset>\n");
  653. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_structure\">\n");
  654. $oP->add("<button type=\"submit\">Next >></button>\n");
  655. $oP->add("</form>\n");
  656. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Evaluating real plans...', 10)\">\n");
  657. $oP->add("<fieldset><legend>Data load configuration</legend>\n");
  658. $aForm = array();
  659. $aForm[] = array(
  660. 'label' => "Main CIs:",
  661. 'input' => "<input id=\"to\" type=\"text\" name=\"plannedcis\" value=\"70\">",
  662. 'help' => ' exclude interfaces, subnets or any other type of secondary CI',
  663. );
  664. $oP->form($aForm);
  665. $oP->add("</fieldset>\n");
  666. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_cis\">\n");
  667. $oP->add("<button type=\"submit\">Next >></button>\n");
  668. $oP->add("</form>\n");
  669. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Evaluating real plans...', 10)\">\n");
  670. $oP->add("<fieldset><legend>Data load configuration</legend>\n");
  671. $aForm = array();
  672. $aForm[] = array(
  673. 'label' => "Tickets:",
  674. 'input' => "<input id=\"to\" type=\"text\" name=\"plannedtickets\" value=\"200\">",
  675. 'help' => ' 50% incidents, 50% changes',
  676. );
  677. $aForm[] = array(
  678. 'label' => "CIs for the big ticket:",
  679. 'input' => "<input id=\"to\" type=\"text\" name=\"plannedbigticketcis\" value=\"200\">",
  680. 'help' => 'Number of CI for the single big ticket',
  681. );
  682. $oP->form($aForm);
  683. $oP->add("</fieldset>\n");
  684. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_tickets\">\n");
  685. $oP->add("<button type=\"submit\">Next >></button>\n");
  686. $oP->add("</form>\n");
  687. }
  688. /**
  689. * Main program
  690. */
  691. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  692. $sOperation = Utils::ReadParam('operation', 'step1');
  693. $oP = new SetupWebPage('iTop benchmark utility');
  694. try
  695. {
  696. switch($sOperation)
  697. {
  698. case 'step1':
  699. DisplayStep1($oP);
  700. break;
  701. case 'create_structure':
  702. $oP->no_cache();
  703. $iPlannedContacts = Utils::ReadParam('plannedcontacts');
  704. $iPlannedContracts = Utils::ReadParam('plannedcontracts');
  705. $oDataCreation = new BenchmarkDataCreation();
  706. $oDataCreation->PlanStructure($iPlannedContacts, $iPlannedContracts);
  707. $oDataCreation->ShowPlans($oP);
  708. $oDataCreation->ShowForm($oP, 'create_structure_go');
  709. break;
  710. case 'create_structure_go':
  711. $oP->no_cache();
  712. $iPlannedContacts = Utils::ReadParam('plannedcontacts');
  713. $iPlannedContracts = Utils::ReadParam('plannedcontracts');
  714. $oDataCreation = new BenchmarkDataCreation();
  715. $oDataCreation->PlanStructure($iPlannedContacts, $iPlannedContracts);
  716. $oDataCreation->CreateStructure($oP);
  717. $oDataCreation->MakeFeedback($oP);
  718. break;
  719. case 'create_cis':
  720. $oP->no_cache();
  721. $iPlannedCIs = Utils::ReadParam('plannedcis');
  722. $oDataCreation = new BenchmarkDataCreation();
  723. $oDataCreation->PlanCis($iPlannedCIs);
  724. $oDataCreation->ShowPlans($oP);
  725. $oDataCreation->ShowForm($oP, 'create_cis_go');
  726. break;
  727. case 'create_cis_go':
  728. $oP->no_cache();
  729. $iPlannedCIs = Utils::ReadParam('plannedcis');
  730. $oDataCreation = new BenchmarkDataCreation();
  731. $oDataCreation->PlanCis($iPlannedCIs);
  732. $oDataCreation->CreateCis($oP);
  733. $oDataCreation->MakeFeedback($oP);
  734. break;
  735. case 'create_tickets':
  736. $oP->no_cache();
  737. $iPlannedTickets = Utils::ReadParam('plannedtickets');
  738. $iBigTicketCis = Utils::ReadParam('plannedbigticketcis');
  739. $oDataCreation = new BenchmarkDataCreation();
  740. $oDataCreation->PlanTickets($iPlannedTickets, $iBigTicketCis);
  741. $oDataCreation->ShowPlans($oP);
  742. $oDataCreation->ShowForm($oP, 'create_tickets_go');
  743. break;
  744. case 'create_tickets_go':
  745. $oP->no_cache();
  746. $iPlannedTickets = Utils::ReadParam('plannedtickets');
  747. $iBigTicketCis = Utils::ReadParam('plannedbigticketcis');
  748. $oDataCreation = new BenchmarkDataCreation();
  749. $oDataCreation->PlanTickets($iPlannedTickets, $iBigTicketCis);
  750. $oDataCreation->CreateTickets($oP);
  751. $oDataCreation->MakeFeedback($oP);
  752. break;
  753. default:
  754. $oP->error("Error: unsupported operation '$sOperation'");
  755. }
  756. }
  757. catch(ZZException $e)
  758. {
  759. $oP->error("Error: '".$e->getMessage()."'");
  760. }
  761. catch(ZZCoreException $e)
  762. {
  763. $oP->error("Error: '".$e->getHtmlDesc()."'");
  764. }
  765. $oP->output();
  766. ?>