benchmark.php 24 KB

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