benchmark.php 24 KB

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