benchmark.php 24 KB

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