diff --git a/setup/benchmark.php b/setup/benchmark.php new file mode 100644 index 000000000..5df808129 --- /dev/null +++ b/setup/benchmark.php @@ -0,0 +1,439 @@ + + * @author Romain Quetiez + * @author Denis Flaven + * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL + */ + +require_once('../application/application.inc.php'); +require_once('../application/itopwebpage.class.inc.php'); +require_once('../application/wizardhelper.class.inc.php'); +require_once('../application/startup.inc.php'); +require_once('../application/loginwebpage.class.inc.php'); +require_once('../application/utils.inc.php'); +require_once('./setuppage.class.inc.php'); + +class BenchmarkDataCreation +{ + var $m_aPlanned = array(); + var $m_aCreated = array(); + + var $m_aStatsByClass = array(); + + public function __construct($iPlannedCIs, $iPlannedContacts, $iPlannedContracts) + { + $this->m_aPlanned = array( + 'CIs' => $iPlannedCIs, + 'Contacts' => $iPlannedContacts, + 'Contracts' => $iPlannedContracts, + 'SubCIs' => 10 * $iPlannedCIs, + 'Incidents' => 2 * 12 * $iPlannedCIs, + 'ServiceCalls' => 1 * 12 * $iPlannedContacts, + 'Changes' => 1 * 12 * $iPlannedCIs, + 'Documents' => 12 * $iPlannedContracts + $iPlannedCIs, + ); + } + + public function GetPlan() + { + return $this->m_aPlanned; + } + + protected function CreateObject($sClass, $aData, $oChange) + { + $mu_t1 = MyHelpers::getmicrotime(); + + $oMyObject = MetaModel::NewObject($sClass); + foreach($aData as $sProp => $value) + { + $oMyObject->Set($sProp, $value); + } + + $iId = $oMyObject->DBInsertTrackedNoReload($oChange); + + $this->m_aCreated[$sClass][] = $iId; + + $mu_t2 = MyHelpers::getmicrotime(); + $this->m_aStatsByClass[$sClass][] = $mu_t2 - $mu_t1; + + return $iId; + } + + protected function RandomId($sClass) + { + return $this->m_aCreated[$sClass][array_rand($this->m_aCreated[$sClass])]; + } + + protected function MakeFeedback($oP, $sClass) + { + $iSample = reset($this->m_aCreated[$sClass]); + $sSample = "sample"; + + $iDuration = number_format(array_sum($this->m_aStatsByClass[$sClass]), 3); + $fDurationMin = number_format(min($this->m_aStatsByClass[$sClass]), 3); + $fDurationMax = number_format(max($this->m_aStatsByClass[$sClass]), 3); + $fDurationAverage = number_format(array_sum($this->m_aStatsByClass[$sClass]) / count($this->m_aStatsByClass[$sClass]), 3); + + $oP->add(""); + } + + public function Go(WebPage $oP, $oChange) + { + + // 1 - Organizations + // + $aData = array( + 'name' => 'benchmark', + ); + $iOrg = $this->CreateObject('bizOrganization', $aData, $oChange); + $this->MakeFeedback($oP, 'bizOrganization'); + + // 2 - Locations + // + $aData = array( + 'org_id' => $iOrg, + 'name' => 'rio', + ); + $iLoc = $this->CreateObject('bizLocation', $aData, $oChange); + $this->MakeFeedback($oP, 'bizLocation'); + + // 3 - Teams + // + $aData = array( + 'org_id' => $iOrg, + 'location_id' => $iLoc, + 'name' => 'fluminense', + ); + $iTeam = $this->CreateObject('bizTeam', $aData, $oChange); + $this->MakeFeedback($oP, 'bizTeam'); + + // 3' - Workgroups + // + $iAnyTeam = $this->RandomId('bizTeam'); + $aData = array( + 'org_id' => $iOrg, + 'team_id' => $iAnyTeam, + 'name' => 'trabolhogrupo'.$iAnyTeam, + ); + $iTeam = $this->CreateObject('bizWorkgroup', $aData, $oChange); + $this->MakeFeedback($oP, 'bizWorkgroup'); + + // 4 - Persons + // + for($i = 0 ; $i < $this->m_aPlanned['Contacts'] ; $i++) + { + $aData = array( + 'org_id' => $iOrg, + 'location_id' => $iLoc, + 'name' => 'ningem'.$i, + ); + $this->CreateObject('bizPerson', $aData, $oChange); + } + $this->MakeFeedback($oP, 'bizPerson'); + + // 5 - Servers + // + for($i = 0 ; $i < $this->m_aPlanned['CIs'] ; $i++) + { + $aData = array( + 'org_id' => $iOrg, + 'location_id' => $iLoc, + 'name' => 'server'.$i, + ); + $this->CreateObject('bizServer', $aData, $oChange); + } + $this->MakeFeedback($oP, 'bizServer'); + + // 6 - Incident Tickets + // + for($i = 0 ; $i < $this->m_aPlanned['Incidents'] ; $i++) + { + $aData = array( + 'org_id' => $iOrg, + 'caller_id' => $this->RandomId('bizPerson'), + 'workgroup_id' => $this->RandomId('bizWorkgroup'), + 'agent_id' => $this->RandomId('bizPerson'), + 'title' => 'someevent'.$i, + ); + $iTicket = $this->CreateObject('bizIncidentTicket', $aData, $oChange); + + // Incident/Infra + // + $iInfraCount = rand(0, 6); + for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++) + { + $aData = array( + 'infra_id' => $this->RandomId('bizServer'), + 'ticket_id' => $iTicket, + 'impact' => 'info on impact '.$iLinked, + ); + $this->CreateObject('lnkInfraTicket', $aData, $oChange); + } + + // Incident/Contact + // + $iInfraCount = rand(0, 6); + for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++) + { + $aData = array( + 'contact_id' => $this->RandomId('bizPerson'), + 'ticket_id' => $iTicket, + 'role' => 'role '.$iLinked, + ); + $this->CreateObject('lnkContactTicket', $aData, $oChange); + } + } + $this->MakeFeedback($oP, 'bizIncidentTicket'); + + + // 7 - Change Tickets + // + for($i = 0 ; $i < $this->m_aPlanned['Changes'] ; $i++) + { + $aData = array( + 'org_id' => $iOrg, + 'requestor_id' => $this->RandomId('bizPerson'), + 'workgroup_id' => $this->RandomId('bizWorkgroup'), + 'agent_id' => $this->RandomId('bizPerson'), + 'supervisorgroup_id' => $this->RandomId('bizWorkgroup'), + 'supervisor_id' => $this->RandomId('bizPerson'), + 'managergroup_id' => $this->RandomId('bizWorkgroup'), + 'manager_id' => $this->RandomId('bizPerson'), + 'title' => "change$i", + ); + $iTicket = $this->CreateObject('bizChangeTicket', $aData, $oChange); + + // Change/Infra + // + $iInfraCount = rand(0, 6); + for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++) + { + $aData = array( + 'infra_id' => $this->RandomId('bizServer'), + 'ticket_id' => $iTicket, + 'impact' => 'info on impact '.$iLinked, + ); + $this->CreateObject('lnkInfraChangeTicket', $aData, $oChange); + } + + // Change/Contact + // + $iInfraCount = rand(0, 6); + for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++) + { + $aData = array( + 'contact_id' => $this->RandomId('bizPerson'), + 'change_id' => $iTicket, + 'role' => 'role '.$iLinked, + ); + $this->CreateObject('lnkContactChange', $aData, $oChange); + } + } + $this->MakeFeedback($oP, 'bizChangeTicket'); + + // 8 - Service calls + // + for($i = 0 ; $i < $this->m_aPlanned['ServiceCalls'] ; $i++) + { + $aData = array( + 'org_id' => $iOrg, + 'caller_id' => $this->RandomId('bizPerson'), + 'workgroup_id' => $this->RandomId('bizWorkgroup'), + 'agent_id' => $this->RandomId('bizPerson'), + 'title' => "call$i", + ); + $iTicket = $this->CreateObject('bizServiceCall', $aData, $oChange); + + // Call/Infra + // + $iInfraCount = rand(0, 6); + for($iLinked = 0 ; $iLinked < $iInfraCount ; $iLinked++) + { + $aData = array( + 'infra_id' => $this->RandomId('bizServer'), + 'call_id' => $iTicket, + 'impact' => 'info on impact '.$iLinked, + ); + $this->CreateObject('lnkInfraCall', $aData, $oChange); + } + } + $this->MakeFeedback($oP, 'bizServiceCall'); + + // 8 - Documents + // + $sMyDoc = ''; + for($i = 0 ; $i < 1000 ; $i++) + { + // 100 chars + $sMyDoc .= "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n"; + } + $oRefDoc = new ormDocument($sMyDoc, 'text/plain'); + + for($i = 0 ; $i < $this->m_aPlanned['Documents'] ; $i++) + { + $aData = array( + 'org_id' => $iOrg, + 'name' => "document$i", + 'contents' => $oRefDoc, + ); + $this->CreateObject('bizDocument', $aData, $oChange); + } + $this->MakeFeedback($oP, 'bizDocument'); + } +} + +/** + * Ask the user what are the settings for the data load + */ +function DisplayStep1(SetupWebPage $oP) +{ + $sNextOperation = 'step2'; + $oP->add("

iTop benchmarking

\n"); + $oP->add("

Please specify the requested volumes

\n"); + $oP->add("
\n"); + $oP->add("
Data load configuration\n"); + $aForm = array(); + $aForm[] = array( + 'label' => "Main CIs:", + 'input' => "", + 'help' => ' exclude interfaces, subnets or any other type of secondary CI', + ); + $aForm[] = array( + 'label' => "Contacts:", + 'input' => "", + 'help' => '', + ); + $aForm[] = array( + 'label' => "Contracts:", + 'input' => "", + 'help' => '', + ); + $oP->form($aForm); + $oP->add("
\n"); + $oP->add("\n"); + $oP->add("\n"); + $oP->add("
\n"); +} + + +/** + * Inform the user how many items will be created + */ +function DisplayStep2(SetupWebPage $oP, $oDataCreation) +{ + $sNextOperation = 'step3'; + $oP->add("

iTop benchmarking

\n"); + $oP->add("

Step 2: review planned volumes

\n"); + + $aPlanned = $oDataCreation->GetPlan(); + + $aForm = array(); + foreach ($aPlanned as $sKey => $iCount) + { + $aForm[] = array( + 'label' => $sKey, + 'input' => $iCount, + ); + } + $oP->form($aForm); + + $oP->add("
\n"); + $oP->add("\n"); + $oP->add("\n"); + $oP->add("\n"); + $oP->add("\n"); + $oP->add("\n"); + $oP->add("
\n"); +} + + +/** + * Do create the data set... could take some time to execute + */ +function DisplayStep3(SetupWebPage $oP, $oDataCreation) +{ +// $sNextOperation = 'step3'; + + $oMyChange = MetaModel::NewObject("CMDBChange"); + $oMyChange->Set("date", time()); + $oMyChange->Set("userinfo", "Administrator"); + $iChangeId = $oMyChange->DBInsertNoReload(); + + $oDataCreation->Go($oP, $oMyChange); +} + +/** + * Main program + */ + +LoginWebPage::DoLogin(); // Check user rights and prompt if needed + +$sOperation = Utils::ReadParam('operation', 'step1'); +$oP = new SetupWebPage('iTop benchmark utility'); + +try +{ + switch($sOperation) + { + case 'step1': + DisplayStep1($oP); + break; + + case 'step2': + $oP->no_cache(); + $iPlannedCIs = Utils::ReadParam('plannedcis'); + $iPlannedContacts = Utils::ReadParam('plannedcontacts'); + $iPlannedContracts = Utils::ReadParam('plannedcontracts'); + + $oDataCreation = new BenchmarkDataCreation($iPlannedCIs, $iPlannedContacts, $iPlannedContracts); + DisplayStep2($oP, $oDataCreation); + break; + + case 'step3': + $oP->no_cache(); + $iPlannedCIs = Utils::ReadParam('plannedcis'); + $iPlannedContacts = Utils::ReadParam('plannedcontacts'); + $iPlannedContracts = Utils::ReadParam('plannedcontracts'); + + $oDataCreation = new BenchmarkDataCreation($iPlannedCIs, $iPlannedContacts, $iPlannedContracts); + DisplayStep3($oP, $oDataCreation); + break; + + default: + $oP->error("Error: unsupported operation '$sOperation'"); + + } +} +catch(ZZException $e) +{ + $oP->error("Error: '".$e->getMessage()."'"); +} +catch(ZZCoreException $e) +{ + $oP->error("Error: '".$e->getHtmlDesc()."'"); +} +$oP->output(); +?> diff --git a/setup/setuppage.class.inc.php b/setup/setuppage.class.inc.php index 8d6533f76..a637fbd96 100644 --- a/setup/setuppage.class.inc.php +++ b/setup/setuppage.class.inc.php @@ -149,7 +149,7 @@ table.formTable { foreach($aData as $aRow) { $this->add("\n"); - if (isset($aRow['label']) && isset($aRow['label']) && isset($aRow['help'])) + if (isset($aRow['label']) && isset($aRow['input']) && isset($aRow['help'])) { $this->add("{$aRow['label']}\n"); $this->add("{$aRow['input']}\n"); diff --git a/toolkit.php b/toolkit.php index d816778e3..d0b92b45a 100644 --- a/toolkit.php +++ b/toolkit.php @@ -16,6 +16,7 @@ echo "Check m echo "Backup and restore (shortcut)
\n"; echo "Objects schema (shortcut)
\n"; echo "Setup the email
\n"; +echo "Generate data for benchmarking purposes
\n"; echo "

Web services

\n"; echo "Available functions
\n"; echo "WSDL (dynamically generated)
\n";