benchmark.php 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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. public function __construct($iPlannedCIs = 0, $iPlannedContacts = 0, $iPlannedContracts = 0)
  42. {
  43. $this->m_aRequested = array(
  44. 'CIs' => $iPlannedCIs,
  45. 'Contacts' => $iPlannedContacts,
  46. 'Contracts' => $iPlannedContracts,
  47. );
  48. $this->m_iIfByServer = 2;
  49. $this->m_iIfByNWDevice = 10;
  50. $iServers = ceil($iPlannedCIs * 9 / 10);
  51. $iNWDevices = ceil($iPlannedCIs / 10);
  52. $iBigTicketCIs = ceil($iPlannedCIs / 10);
  53. $iInterfaces = $iServers * $this->m_iIfByServer + $iNWDevices * $this->m_iIfByNWDevice;
  54. $iApplications = $iServers * 5;
  55. $iSolutions = ceil($iApplications / 2);
  56. $iProcesses = ceil($iSolutions / 2);
  57. $this->m_aPlanned = array(
  58. 'Network devices' => $iNWDevices,
  59. 'Servers' => $iServers,
  60. 'Big ticket: CIs' => $iBigTicketCIs,
  61. 'Interfaces' => $iInterfaces,
  62. 'Application SW' => 2,
  63. 'Applications' => $iApplications,
  64. 'Solutions' => $iSolutions,
  65. 'Processes' => $iProcesses,
  66. 'Contacts' => $iPlannedContacts,
  67. 'Contracts' => $iPlannedContracts,
  68. 'Incidents' => 2 * 12 * $iPlannedCIs,
  69. 'ServiceCalls' => 1 * 12 * $iPlannedContacts,
  70. 'Changes' => 1 * 12 * $iPlannedCIs,
  71. 'Documents' => 12 * $iPlannedContracts + $iPlannedCIs,
  72. );
  73. }
  74. public function GetPlans()
  75. {
  76. return $this->m_aPlanned;
  77. }
  78. public function GetRequestInfo()
  79. {
  80. return $this->m_aRequested;
  81. }
  82. protected function CreateObject($sClass, $aData, $oChange, $sClassDesc = '')
  83. {
  84. $mu_t1 = MyHelpers::getmicrotime();
  85. $oMyObject = MetaModel::NewObject($sClass);
  86. foreach($aData as $sProp => $value)
  87. {
  88. $oMyObject->Set($sProp, $value);
  89. }
  90. $iId = $oMyObject->DBInsertTrackedNoReload($oChange);
  91. $sClassId = "$sClass ($sClassDesc)";
  92. $this->m_aCreatedByDesc[$sClassId][] = $iId;
  93. $this->m_aCreatedByClass[$sClass][] = $iId;
  94. $mu_t2 = MyHelpers::getmicrotime();
  95. $this->m_aStatsByClass[$sClass][] = $mu_t2 - $mu_t1;
  96. return $iId;
  97. }
  98. protected function RandomId($sClass, $sClassDesc = '')
  99. {
  100. $sClassId = "$sClass ($sClassDesc)";
  101. return $this->m_aCreatedByDesc[$sClassId][array_rand($this->m_aCreatedByDesc[$sClassId])];
  102. }
  103. static protected function FindId($sClass)
  104. {
  105. $oSet = new DBObjectSet(new DBObjectSearch($sClass));
  106. if ($oSet->Count() < 1)
  107. {
  108. return null;
  109. }
  110. $oObj = $oSet->Fetch();
  111. return $oObj->GetKey();
  112. }
  113. static protected function FindIdFromOQL($sOQL)
  114. {
  115. $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL));
  116. if ($oSet->Count() < 1)
  117. {
  118. return null;
  119. }
  120. $oObj = $oSet->Fetch();
  121. return $oObj->GetKey();
  122. }
  123. protected function MakeFeedback($oP, $sClass)
  124. {
  125. $iSample = reset($this->m_aCreatedByClass[$sClass]);
  126. $sSample = "<a href=\"../pages/UI.php?operation=details&class=$sClass&id=$iSample\">sample</a>";
  127. $iDuration = number_format(array_sum($this->m_aStatsByClass[$sClass]), 3);
  128. $fDurationMin = number_format(min($this->m_aStatsByClass[$sClass]), 3);
  129. $fDurationMax = number_format(max($this->m_aStatsByClass[$sClass]), 3);
  130. $fDurationAverage = number_format(array_sum($this->m_aStatsByClass[$sClass]) / count($this->m_aStatsByClass[$sClass]), 3);
  131. $oP->add("<ul>");
  132. $oP->add("<li>");
  133. $oP->add("$sClass: ".count($this->m_aStatsByClass[$sClass])." - $sSample<br/>");
  134. $oP->add("Duration: $fDurationMin =&gt; $fDurationMax; Avg:$fDurationAverage; Total: $iDuration");
  135. $oP->add("</li>");
  136. $oP->add("</ul>");
  137. }
  138. public function GoProjectionsOrganization(WebPage $oP, $oChange)
  139. {
  140. $aClasses = MetaModel::GetClasses();
  141. $aActions = array('Read', 'Bulk Read', 'Delete', 'Bulk Delete', 'Modify', 'Bulk Modify');
  142. $aStdProfiles = array(2, 3, 4, 5, 6, 7, 8, 9);
  143. ////////////////////////////////////////
  144. // Dimension: Organization
  145. //
  146. $aData = array(
  147. 'name' => 'organization',
  148. 'description' => '',
  149. 'type' => 'Organization',
  150. );
  151. $iDimLocation = $this->CreateObject('URP_Dimensions', $aData, $oChange);
  152. ////////////////////////////////////////
  153. // New specific profile, given access to everything
  154. //
  155. $aData = array(
  156. 'name' => 'data guru',
  157. 'description' => 'could do anything, because everything is granted',
  158. );
  159. $iGuruProfile = $this->CreateObject('URP_Profiles', $aData, $oChange);
  160. foreach($aClasses as $sClass)
  161. {
  162. foreach($aActions as $sAction)
  163. {
  164. $aData = array(
  165. 'profileid' => $iGuruProfile,
  166. 'class' => $sClass,
  167. 'permission' => 'yes',
  168. 'action' => $sAction,
  169. );
  170. $this->CreateObject('URP_ActionGrant', $aData, $oChange);
  171. }
  172. }
  173. $aData = array(
  174. 'dimensionid' => $iDimLocation,
  175. 'profileid' => $iGuruProfile,
  176. 'value' => '<any>',
  177. 'attribute' => 'org_id',
  178. );
  179. $this->CreateObject('URP_ProfileProjection', $aData, $oChange);
  180. // User login with super access rights
  181. //
  182. $aData = array(
  183. 'org_id' => self::FindId('Organization'),
  184. 'location_id' => self::FindId('Location'),
  185. 'first_name' => 'Jesus',
  186. 'name' => 'Deus',
  187. 'email' => '',
  188. );
  189. $iPerson = $this->CreateObject('Person', $aData, $oChange);
  190. $aData = array(
  191. 'contactid' => $iPerson,
  192. 'login' => 'guru',
  193. 'password' => 'guru',
  194. 'language' => 'EN US',
  195. );
  196. $iLogin = $this->CreateObject('UserLocal', $aData, $oChange);
  197. // Assign profiles to the new login
  198. //
  199. $aData = array(
  200. 'userid' => $iLogin,
  201. 'profileid' => $iGuruProfile,
  202. 'reason' => 'he is the one',
  203. );
  204. $this->CreateObject('URP_UserProfile', $aData, $oChange);
  205. ////////////////////////////////////////
  206. // User login having all profiles, but seeing only his organization
  207. //
  208. $aData = array(
  209. 'org_id' => self::FindId('Organization'),
  210. 'location_id' => self::FindId('Location'),
  211. 'first_name' => 'Little ze',
  212. 'name' => 'Foo',
  213. 'email' => '',
  214. );
  215. $iPerson = $this->CreateObject('Person', $aData, $oChange);
  216. $aData = array(
  217. 'contactid' => $iPerson,
  218. 'login' => 'foo',
  219. 'password' => 'foo',
  220. 'language' => 'EN US',
  221. );
  222. $iLogin = $this->CreateObject('UserLocal', $aData, $oChange);
  223. // Assign profiles to the new login
  224. //
  225. foreach($aStdProfiles as $iProfileId)
  226. {
  227. $aData = array(
  228. 'userid' => $iLogin,
  229. 'profileid' => $iProfileId,
  230. 'reason' => '',
  231. );
  232. $this->CreateObject('URP_UserProfile', $aData, $oChange);
  233. }
  234. // Project classes
  235. //
  236. $aMyClassesToProject = array();
  237. foreach($aClasses as $sClass)
  238. {
  239. if (MetaModel::IsValidAttCode($sClass, 'org_id'))
  240. {
  241. $aMyClassesToProject[$sClass] = 'org_id';
  242. }
  243. }
  244. foreach($aMyClassesToProject as $sClass => $sAttCode)
  245. {
  246. $aData = array(
  247. 'dimensionid' => $iDimLocation,
  248. 'class' => $sClass,
  249. 'value' => '<this>',
  250. 'attribute' => $sAttCode,
  251. );
  252. $this->CreateObject('URP_ClassProjection', $aData, $oChange);
  253. }
  254. // Project profiles
  255. //
  256. foreach($aStdProfiles as $iProfileId)
  257. {
  258. $aData = array(
  259. 'dimensionid' => $iDimLocation,
  260. 'profileid' => $iProfileId,
  261. 'value' => 'SELECT Person WHERE id = :user->contactid',
  262. 'attribute' => 'org_id',
  263. );
  264. $this->CreateObject('URP_ProfileProjection', $aData, $oChange);
  265. }
  266. $oP->p('Created projections (Cf. login "foo", pwd "foo")');
  267. $oP->p('* foo can do configuration management for a given customer');
  268. $oP->p('* guru can do everything');
  269. }
  270. // For testing purposes -Romain
  271. public function GoProjectionsLocation(WebPage $oP, $oChange)
  272. {
  273. // User login
  274. //
  275. $aData = array(
  276. 'contactid' => self::FindId('Person'),
  277. 'login' => 'foo',
  278. 'password' => 'foo',
  279. 'language' => 'EN US',
  280. );
  281. $iLogin = $this->CreateObject('UserLocal', $aData, $oChange);
  282. // Assign profiles to the new login
  283. //
  284. $aData = array(
  285. 'userid' => $iLogin,
  286. 'profileid' => self::FindIdFromOQL("SELECT URP_Profiles WHERE name LIKE 'Configuration Manager'"),
  287. 'reason' => '',
  288. );
  289. $this->CreateObject('URP_UserProfile', $aData, $oChange);
  290. // Dimension
  291. //
  292. $aData = array(
  293. 'name' => 'location',
  294. 'description' => '',
  295. 'type' => 'Location',
  296. );
  297. $iDimLocation = $this->CreateObject('URP_Dimensions', $aData, $oChange);
  298. // Project classes
  299. //
  300. $aMyClassesToProject = array('NetworkDevice', 'Server');
  301. foreach($aMyClassesToProject as $sClass)
  302. {
  303. $aData = array(
  304. 'dimensionid' => $iDimLocation,
  305. 'class' => $sClass,
  306. 'value' => '<this>',
  307. 'attribute' => 'location_name',
  308. );
  309. $this->CreateObject('URP_ClassProjection', $aData, $oChange);
  310. }
  311. // Project profiles
  312. //
  313. $aProfilesToProject = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
  314. foreach($aProfilesToProject as $iProfileId)
  315. {
  316. $aData = array(
  317. 'dimensionid' => $iDimLocation,
  318. 'profileid' => $iProfileId,
  319. 'value' => 'Grenoble',
  320. 'attribute' => '',
  321. );
  322. $this->CreateObject('URP_ProfileProjection', $aData, $oChange);
  323. }
  324. $oP->p('Created projections (Cf. login "foo", pwd "foo")');
  325. }
  326. public function GoVolume(WebPage $oP, $oChange)
  327. {
  328. /////////////////////////
  329. //
  330. // Organizations
  331. //
  332. $aData = array(
  333. 'name' => 'Benchmark',
  334. );
  335. $iOrg = $this->CreateObject('Organization', $aData, $oChange);
  336. $this->MakeFeedback($oP, 'Organization');
  337. /////////////////////////
  338. //
  339. // Locations
  340. //
  341. $aData = array(
  342. 'org_id' => $iOrg,
  343. 'name' => 'Rio de Janeiro',
  344. );
  345. $iLoc = $this->CreateObject('Location', $aData, $oChange);
  346. $this->MakeFeedback($oP, 'Location');
  347. /////////////////////////
  348. //
  349. // Teams
  350. //
  351. $aData = array(
  352. 'org_id' => $iOrg,
  353. 'location_id' => $iLoc,
  354. 'name' => 'Fluminense',
  355. 'email' => 'fluminense@nowhere.fr',
  356. );
  357. $iTeam = $this->CreateObject('Team', $aData, $oChange);
  358. $this->MakeFeedback($oP, 'Team');
  359. /////////////////////////
  360. //
  361. // Persons
  362. //
  363. for($i = 0 ; $i < $this->m_aPlanned['Contacts'] ; $i++)
  364. {
  365. $aData = array(
  366. 'org_id' => $iOrg,
  367. 'location_id' => $iLoc,
  368. 'first_name' => 'Joaõ',
  369. 'name' => 'Ningem #'.$i,
  370. 'email' => 'foo'.$i.'@nowhere.fr',
  371. );
  372. $iPerson = $this->CreateObject('Person', $aData, $oChange);
  373. // Contract/Infra
  374. //
  375. $aData = array(
  376. 'contact_id' => $iPerson,
  377. 'team_id' => $this->RandomId('Team'),
  378. );
  379. $this->CreateObject('lnkTeamToContact', $aData, $oChange);
  380. }
  381. $this->MakeFeedback($oP, 'Person');
  382. /////////////////////////
  383. //
  384. // Services
  385. //
  386. $aData = array(
  387. 'name' => 'My Service',
  388. );
  389. $iOrg = $this->CreateObject('Service', $aData, $oChange);
  390. $this->MakeFeedback($oP, 'Service');
  391. /////////////////////////
  392. //
  393. // Service subcategories
  394. //
  395. $aData = array(
  396. 'name' => 'My subcategory',
  397. );
  398. $iOrg = $this->CreateObject('ServiceSubcategory', $aData, $oChange);
  399. $this->MakeFeedback($oP, 'ServiceSubcategory');
  400. /////////////////////////
  401. //
  402. // Contracts
  403. //
  404. for($i = 0 ; $i < $this->m_aPlanned['Contracts'] ; $i++)
  405. {
  406. $aData = array(
  407. 'name' => "Contract #$i",
  408. 'description' => 'Created for benchmarking purposes',
  409. 'org_id' => $this->RandomId('Organization'),
  410. 'provider_id' => $this->RandomId('Organization'),
  411. 'start_date' => '2009-12-25',
  412. 'end_date' => '2019-08-01',
  413. 'support_team_id' => $this->RandomId('Team'),
  414. );
  415. $iContract = $this->CreateObject('CustomerContract', $aData, $oChange);
  416. // Contract/Contact (10% of contacts)
  417. //
  418. $iContactCount = ceil($this->m_aPlanned['Contracts'] / 10);
  419. for($iLinked = 0 ; $iLinked < $iContactCount ; $iLinked++)
  420. {
  421. $aData = array(
  422. 'contact_id' => $this->RandomId('Person'),
  423. 'contract_id' => $iContract,
  424. 'role' => 'role '.$iLinked,
  425. );
  426. $this->CreateObject('lnkContractToContact', $aData, $oChange);
  427. }
  428. }
  429. $this->MakeFeedback($oP, 'CustomerContract');
  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, $oChange);
  443. // Contract/Infra
  444. //
  445. $iContractCount = 1;
  446. for($iLinked = 0 ; $iLinked < $iContractCount ; $iLinked++)
  447. {
  448. $aData = array(
  449. 'contract_id' => $this->RandomId('CustomerContract'),
  450. 'ci_id' => $iServer,
  451. );
  452. $this->CreateObject('lnkContractToCI', $aData, $oChange);
  453. }
  454. // Interfaces
  455. //
  456. for($iLinked = 0 ; $iLinked < $this->m_iIfByServer ; $iLinked++)
  457. {
  458. $aData = array(
  459. 'name' => "eth$iLinked",
  460. 'status' => 'implementation',
  461. 'org_id' => $iOrg,
  462. 'device_id' => $iServer,
  463. 'status' => 'production',
  464. );
  465. $this->CreateObject('NetworkInterface', $aData, $oChange, 'server if');
  466. }
  467. }
  468. $this->MakeFeedback($oP, 'Server');
  469. /////////////////////////
  470. //
  471. // Network devices
  472. //
  473. for($i = 0 ; $i < $this->m_aPlanned['Network devices'] ; $i++)
  474. {
  475. $aData = array(
  476. 'org_id' => $iOrg,
  477. 'location_id' => $iLoc,
  478. 'name' => 'equipment #'.$i,
  479. 'status' => 'production',
  480. );
  481. $iNWDevice = $this->CreateObject('NetworkDevice', $aData, $oChange);
  482. // Contract/Infra
  483. //
  484. $iContractCount = 1;
  485. for($iLinked = 0 ; $iLinked < $iContractCount ; $iLinked++)
  486. {
  487. $aData = array(
  488. 'contract_id' => $this->RandomId('CustomerContract'),
  489. 'ci_id' => $iNWDevice,
  490. );
  491. $this->CreateObject('lnkContractToCI', $aData, $oChange);
  492. }
  493. // Interfaces
  494. //
  495. for($iLinked = 0 ; $iLinked < $this->m_iIfByNWDevice ; $iLinked++)
  496. {
  497. $aData = array(
  498. 'name' => "eth$iLinked",
  499. 'status' => 'implementation',
  500. 'org_id' => $iOrg,
  501. 'device_id' => $iNWDevice,
  502. 'connected_if' => $this->RandomId('NetworkInterface', 'server if'),
  503. 'status' => 'production',
  504. );
  505. $this->CreateObject('NetworkInterface', $aData, $oChange, 'equipment if');
  506. }
  507. }
  508. $this->MakeFeedback($oP, 'NetworkDevice');
  509. $this->MakeFeedback($oP, 'NetworkInterface');
  510. /////////////////////////
  511. //
  512. // Application Software
  513. //
  514. for($i = 0 ; $i < $this->m_aPlanned['Application SW'] ; $i++)
  515. {
  516. $aData = array(
  517. 'name' => 'Software #'.$i,
  518. );
  519. $iNWDevice = $this->CreateObject('Application', $aData, $oChange);
  520. }
  521. $this->MakeFeedback($oP, 'Application');
  522. /////////////////////////
  523. //
  524. // Applications
  525. //
  526. for($i = 0 ; $i < $this->m_aPlanned['Applications'] ; $i++)
  527. {
  528. $aData = array(
  529. 'org_id' => $iOrg,
  530. 'device_id' => $this->RandomId('Server'),
  531. 'software_id' => $this->RandomId('Application'),
  532. 'name' => 'Application #'.$i,
  533. 'status' => 'production',
  534. );
  535. $iNWDevice = $this->CreateObject('ApplicationInstance', $aData, $oChange);
  536. // Contract/Infra
  537. //
  538. $iContractCount = 1;
  539. for($iLinked = 0 ; $iLinked < $iContractCount ; $iLinked++)
  540. {
  541. $aData = array(
  542. 'contract_id' => $this->RandomId('CustomerContract'),
  543. 'ci_id' => $iNWDevice,
  544. );
  545. $this->CreateObject('lnkContractToCI', $aData, $oChange);
  546. }
  547. }
  548. $this->MakeFeedback($oP, 'ApplicationInstance');
  549. /////////////////////////
  550. //
  551. // Application Solution
  552. //
  553. for($i = 0 ; $i < $this->m_aPlanned['Solutions'] ; $i++)
  554. {
  555. $aData = array(
  556. 'org_id' => $iOrg,
  557. 'name' => 'Solution #'.$i,
  558. 'status' => 'production',
  559. );
  560. $iNWDevice = $this->CreateObject('ApplicationSolution', $aData, $oChange);
  561. // Contract/Infra
  562. //
  563. $iContractCount = 1;
  564. for($iLinked = 0 ; $iLinked < $iContractCount ; $iLinked++)
  565. {
  566. $aData = array(
  567. 'contract_id' => $this->RandomId('CustomerContract'),
  568. 'ci_id' => $iNWDevice,
  569. );
  570. $this->CreateObject('lnkContractToCI', $aData, $oChange);
  571. }
  572. }
  573. $this->MakeFeedback($oP, 'ApplicationSolution');
  574. /////////////////////////
  575. //
  576. // Business Process
  577. //
  578. for($i = 0 ; $i < $this->m_aPlanned['Processes'] ; $i++)
  579. {
  580. $aData = array(
  581. 'org_id' => $iOrg,
  582. 'name' => 'Process #'.$i,
  583. 'status' => 'production',
  584. );
  585. $iNWDevice = $this->CreateObject('BusinessProcess', $aData, $oChange);
  586. // Contract/Infra
  587. //
  588. $iContractCount = 1;
  589. for($iLinked = 0 ; $iLinked < $iContractCount ; $iLinked++)
  590. {
  591. $aData = array(
  592. 'contract_id' => $this->RandomId('CustomerContract'),
  593. 'ci_id' => $iNWDevice,
  594. );
  595. $this->CreateObject('lnkContractToCI', $aData, $oChange);
  596. }
  597. }
  598. $this->MakeFeedback($oP, 'BusinessProcess');
  599. /////////////////////////
  600. //
  601. // Incident Tickets
  602. //
  603. for($i = 0 ; $i < $this->m_aPlanned['Incidents'] ; $i++)
  604. {
  605. $aData = array(
  606. 'org_id' => $iOrg,
  607. 'caller_id' => $this->RandomId('Person'),
  608. 'workgroup_id' => $this->RandomId('Team'),
  609. 'agent_id' => $this->RandomId('Person'),
  610. 'service_id' => $this->RandomId('Service'),
  611. 'servicesubcategory_id' => $this->RandomId('ServiceSubcategory'),
  612. 'title' => 'Incident #'.$i,
  613. 'ticket_log' => 'Testing...',
  614. );
  615. $iTicket = $this->CreateObject('Incident', $aData, $oChange);
  616. // Incident/Infra
  617. //
  618. $iInfraCount = rand(0, 6);
  619. for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++)
  620. {
  621. $aData = array(
  622. 'ci_id' => $this->RandomId('Server'),
  623. 'ticket_id' => $iTicket,
  624. );
  625. $this->CreateObject('lnkTicketToCI', $aData, $oChange);
  626. }
  627. // Incident/Contact
  628. //
  629. $iInfraCount = rand(0, 6);
  630. for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++)
  631. {
  632. $aData = array(
  633. 'contact_id' => $this->RandomId('Person'),
  634. 'ticket_id' => $iTicket,
  635. 'role' => 'role '.$iLinked,
  636. );
  637. $this->CreateObject('lnkTicketToContact', $aData, $oChange);
  638. }
  639. }
  640. $this->MakeFeedback($oP, 'Incident');
  641. /////////////////////////
  642. //
  643. // Big Ticket
  644. //
  645. $aData = array(
  646. 'org_id' => $iOrg,
  647. 'caller_id' => $this->RandomId('Person'),
  648. 'workgroup_id' => $this->RandomId('Team'),
  649. 'agent_id' => $this->RandomId('Person'),
  650. 'service_id' => $this->RandomId('Service'),
  651. 'servicesubcategory_id' => $this->RandomId('ServiceSubcategory'),
  652. 'title' => 'Big ticket',
  653. 'ticket_log' => 'Testing...',
  654. );
  655. $iTicket = $this->CreateObject('Incident', $aData, $oChange);
  656. // Incident/Infra
  657. //
  658. $iInfraCount = $this->m_aPlanned['Big ticket: CIs'];
  659. for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++)
  660. {
  661. $aData = array(
  662. 'ci_id' => $this->RandomId('Server'),
  663. 'ticket_id' => $iTicket,
  664. );
  665. $this->CreateObject('lnkTicketToCI', $aData, $oChange);
  666. }
  667. // Incident/Contact
  668. //
  669. $iInfraCount = rand(0, 6) ;
  670. for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++)
  671. {
  672. $aData = array(
  673. 'contact_id' => $this->RandomId('Person'),
  674. 'ticket_id' => $iTicket,
  675. 'role' => 'role '.$iLinked,
  676. );
  677. $this->CreateObject('lnkTicketToContact', $aData, $oChange);
  678. }
  679. /////////////////////////
  680. //
  681. // Change Tickets
  682. //
  683. for($i = 0 ; $i < $this->m_aPlanned['Changes'] ; $i++)
  684. {
  685. $aData = array(
  686. 'org_id' => $iOrg,
  687. 'requestor_id' => $this->RandomId('Person'),
  688. 'workgroup_id' => $this->RandomId('Team'),
  689. 'agent_id' => $this->RandomId('Person'),
  690. 'supervisor_group_id' => $this->RandomId('Team'),
  691. 'supervisor_id' => $this->RandomId('Person'),
  692. 'manager_group_id' => $this->RandomId('Team'),
  693. 'manager_id' => $this->RandomId('Person'),
  694. 'title' => 'change #'.$i,
  695. 'description' => "Let's do something there",
  696. );
  697. $iTicket = $this->CreateObject('NormalChange', $aData, $oChange);
  698. // Change/Infra
  699. //
  700. $iInfraCount = rand(0, 6);
  701. for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++)
  702. {
  703. $aData = array(
  704. 'ci_id' => $this->RandomId('Server'),
  705. 'ticket_id' => $iTicket,
  706. );
  707. $this->CreateObject('lnkTicketToCI', $aData, $oChange);
  708. }
  709. // Change/Contact
  710. //
  711. $iInfraCount = rand(0, 6);
  712. for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++)
  713. {
  714. $aData = array(
  715. 'contact_id' => $this->RandomId('Person'),
  716. 'ticket_id' => $iTicket,
  717. 'role' => 'role '.$iLinked,
  718. );
  719. $this->CreateObject('lnkTicketToContact', $aData, $oChange);
  720. }
  721. }
  722. $this->MakeFeedback($oP, 'NormalChange');
  723. /////////////////////////
  724. //
  725. // Service calls
  726. //
  727. for($i = 0 ; $i < $this->m_aPlanned['ServiceCalls'] ; $i++)
  728. {
  729. $aData = array(
  730. 'org_id' => $iOrg,
  731. 'caller_id' => $this->RandomId('Person'),
  732. 'workgroup_id' => $this->RandomId('Team'),
  733. 'agent_id' => $this->RandomId('Person'),
  734. 'service_id' => $this->RandomId('Service'),
  735. 'servicesubcategory_id' => $this->RandomId('ServiceSubcategory'),
  736. 'title' => 'Call #'.$i,
  737. 'ticket_log' => 'Testing...',
  738. );
  739. $iTicket = $this->CreateObject('UserRequest', $aData, $oChange);
  740. // Call/Infra
  741. //
  742. $iInfraCount = rand(0, 6);
  743. for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++)
  744. {
  745. $aData = array(
  746. 'ci_id' => $this->RandomId('Server'),
  747. 'ticket_id' => $iTicket,
  748. );
  749. $this->CreateObject('lnkTicketToCI', $aData, $oChange);
  750. }
  751. }
  752. $this->MakeFeedback($oP, 'UserRequest');
  753. /////////////////////////
  754. //
  755. // Documents
  756. //
  757. $sMyDoc = '';
  758. for($i = 0 ; $i < 1000 ; $i++)
  759. {
  760. // 100 chars
  761. $sMyDoc .= "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n";
  762. }
  763. $oRefDoc = new ormDocument($sMyDoc, 'text/plain');
  764. for($i = 0 ; $i < $this->m_aPlanned['Documents'] ; $i++)
  765. {
  766. $aData = array(
  767. //'org_id' => $iOrg,
  768. 'name' => "document$i",
  769. 'contents' => $oRefDoc,
  770. );
  771. $this->CreateObject('FileDoc', $aData, $oChange);
  772. }
  773. $this->MakeFeedback($oP, 'FileDoc');
  774. }
  775. }
  776. /**
  777. * Ask the user what are the settings for the data load
  778. */
  779. function DisplayStep1(SetupWebPage $oP)
  780. {
  781. $sNextOperation = 'step2';
  782. $oP->add("<h1>iTop benchmarking</h1>\n");
  783. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Please wait...', 10)\">\n");
  784. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"createprofiles_organization\">\n");
  785. $oP->add("<button type=\"submit\">Create profiles!</button>\n");
  786. $oP->add("</form>\n");
  787. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Please wait...', 10)\">\n");
  788. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"createprofiles_location\">\n");
  789. $oP->add("<button type=\"submit\">Create profiles (unit tests)!</button>\n");
  790. $oP->add("</form>\n");
  791. $oP->add("<h2>Please specify the requested volumes</h2>\n");
  792. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Evaluating real plans...', 10)\">\n");
  793. $oP->add("<fieldset><legend>Data load configuration</legend>\n");
  794. $aForm = array();
  795. $aForm[] = array(
  796. 'label' => "Main CIs:",
  797. 'input' => "<input id=\"to\" type=\"text\" name=\"plannedcis\" value=\"70\">",
  798. 'help' => ' exclude interfaces, subnets or any other type of secondary CI',
  799. );
  800. $aForm[] = array(
  801. 'label' => "Contacts:",
  802. 'input' => "<input id=\"from\" type=\"text\" name=\"plannedcontacts\" value=\"100\">",
  803. 'help' => '',
  804. );
  805. $aForm[] = array(
  806. 'label' => "Contracts:",
  807. 'input' => "<input id=\"from\" type=\"text\" name=\"plannedcontracts\" value=\"10\">",
  808. 'help' => '',
  809. );
  810. $oP->form($aForm);
  811. $oP->add("</fieldset>\n");
  812. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  813. $oP->add("<button type=\"submit\">Next >></button>\n");
  814. $oP->add("</form>\n");
  815. }
  816. /**
  817. * Inform the user how many items will be created
  818. */
  819. function DisplayStep2(SetupWebPage $oP, $oDataCreation)
  820. {
  821. $sNextOperation = 'step3';
  822. $oP->add("<h1>iTop benchmarking</h1>\n");
  823. $oP->add("<h2>Step 2: review planned volumes</h2>\n");
  824. $aPlanned = $oDataCreation->GetPlans();
  825. $aForm = array();
  826. foreach ($aPlanned as $sKey => $iCount)
  827. {
  828. $aForm[] = array(
  829. 'label' => $sKey,
  830. 'input' => $iCount,
  831. );
  832. }
  833. $oP->form($aForm);
  834. $aRequested = $oDataCreation->GetRequestInfo();
  835. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Loading data...', 10)\">\n");
  836. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  837. $oP->add("<input type=\"hidden\" name=\"plannedcis\" value=\"".$aRequested['CIs']."\">\n");
  838. $oP->add("<input type=\"hidden\" name=\"plannedcontacts\" value=\"".$aRequested['Contacts']."\">\n");
  839. $oP->add("<input type=\"hidden\" name=\"plannedcontracts\" value=\"".$aRequested['Contracts']."\">\n");
  840. $oP->add("<button type=\"submit\">Next >></button>\n");
  841. $oP->add("</form>\n");
  842. }
  843. /**
  844. * Do create the data set... could take some time to execute
  845. */
  846. function DisplayStep3(SetupWebPage $oP, $oDataCreation)
  847. {
  848. // $sNextOperation = 'step3';
  849. $oMyChange = MetaModel::NewObject("CMDBChange");
  850. $oMyChange->Set("date", time());
  851. $oMyChange->Set("userinfo", "Administrator");
  852. $iChangeId = $oMyChange->DBInsertNoReload();
  853. $oDataCreation->GoVolume($oP, $oMyChange);
  854. }
  855. /**
  856. * Do create a profile management context
  857. */
  858. function CreateProfilesOrganization(SetupWebPage $oP, $oDataCreation)
  859. {
  860. // $sNextOperation = 'step3';
  861. $oMyChange = MetaModel::NewObject("CMDBChange");
  862. $oMyChange->Set("date", time());
  863. $oMyChange->Set("userinfo", "Administrator");
  864. $iChangeId = $oMyChange->DBInsertNoReload();
  865. $oDataCreation->GoProjectionsOrganization($oP, $oMyChange);
  866. }
  867. /**
  868. * Do create the data set... could take some time to execute
  869. */
  870. function CreateProfilesLocation(SetupWebPage $oP, $oDataCreation)
  871. {
  872. // $sNextOperation = 'step3';
  873. $oMyChange = MetaModel::NewObject("CMDBChange");
  874. $oMyChange->Set("date", time());
  875. $oMyChange->Set("userinfo", "Administrator");
  876. $iChangeId = $oMyChange->DBInsertNoReload();
  877. $oDataCreation->GoProjectionsLocation($oP, $oMyChange);
  878. }
  879. /**
  880. * Main program
  881. */
  882. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  883. $sOperation = Utils::ReadParam('operation', 'step1');
  884. $oP = new SetupWebPage('iTop benchmark utility');
  885. try
  886. {
  887. switch($sOperation)
  888. {
  889. case 'step1':
  890. DisplayStep1($oP);
  891. break;
  892. case 'createprofiles_organization':
  893. $oP->no_cache();
  894. $oDataCreation = new BenchmarkDataCreation();
  895. CreateProfilesOrganization($oP, $oDataCreation);
  896. break;
  897. case 'createprofiles_location':
  898. $oP->no_cache();
  899. $oDataCreation = new BenchmarkDataCreation();
  900. CreateProfilesLocation($oP, $oDataCreation);
  901. break;
  902. case 'step2':
  903. $oP->no_cache();
  904. $iPlannedCIs = Utils::ReadParam('plannedcis');
  905. $iPlannedContacts = Utils::ReadParam('plannedcontacts');
  906. $iPlannedContracts = Utils::ReadParam('plannedcontracts');
  907. $oDataCreation = new BenchmarkDataCreation($iPlannedCIs, $iPlannedContacts, $iPlannedContracts);
  908. DisplayStep2($oP, $oDataCreation);
  909. break;
  910. case 'step3':
  911. $oP->no_cache();
  912. $iPlannedCIs = Utils::ReadParam('plannedcis');
  913. $iPlannedContacts = Utils::ReadParam('plannedcontacts');
  914. $iPlannedContracts = Utils::ReadParam('plannedcontracts');
  915. $oDataCreation = new BenchmarkDataCreation($iPlannedCIs, $iPlannedContacts, $iPlannedContracts);
  916. DisplayStep3($oP, $oDataCreation);
  917. break;
  918. default:
  919. $oP->error("Error: unsupported operation '$sOperation'");
  920. }
  921. }
  922. catch(ZZException $e)
  923. {
  924. $oP->error("Error: '".$e->getMessage()."'");
  925. }
  926. catch(ZZCoreException $e)
  927. {
  928. $oP->error("Error: '".$e->getHtmlDesc()."'");
  929. }
  930. $oP->output();
  931. ?>