benchmark.php 24 KB

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