public function assignHostToHostGroup(Host &$host, HostGroup &$hostGroup) { if ($host == null || $host->getId() == -1 || $hostGroup == null) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host or HostGroup object is not valid or Host.id|HostGroup.id is not set"); } Utils::log(LOG_DEBUG, "Assigning the host to the host group [host=" . $host->getHostname() . ",hostGroupName=" . $hostGroup->getName() . "]", __FILE__, __LINE__); # Check if the hostGroup name is valid if ($hostGroup->getName() == "") { $hostGroup->setName(Constants::$NA); } $hostGroupId = $this->getHostGroupIdByName($hostGroup->getName()); if ($hostGroupId == -1) { # HostGroup doesn't exist, so create it $this->getPakiti()->getDao("HostGroup")->create($hostGroup); } else { $hostGroup->setId($hostGroupId); } Utils::log(LOG_DEBUG, "Assinging the host to the hostGroup [hostId=" . $host->getId() . ",hostGroupId=" . $hostGroup->getId() . "]", __FILE__, __LINE__); # Check if the tag already exists $isAssigned = $this->getPakiti()->getManager("DbManager")->queryToSingleValue("select 1 from HostHostGroup where \n \t \t\thostId=" . $this->getPakiti()->getManager("DbManager")->escape($host->getId()) . " and \n \t \t\thostGroupId=" . $this->getPakiti()->getManager("DbManager")->escape($hostGroup->getId())); if ($isAssigned == null) { # Association between host and hostTag doesn't exist, so create it $this->getPakiti()->getManager("DbManager")->query("insert into HostHostGroup set \n hostId=" . $this->getPakiti()->getManager("DbManager")->escape($host->getId()) . ",\n \t \t\thostGroupId=" . $this->getPakiti()->getManager("DbManager")->escape($hostGroup->getId())); } }
public function prepareReport() { Utils::log(LOG_DEBUG, "Preparing the report", __FILE__, __LINE__); $tag = null; $hostGroup = null; switch ($this->_version) { case "4": Utils::log(LOG_DEBUG, "Client in version 4", __FILE__, __LINE__); # Get the rest of HTTP variables # host, os, arch, kernel, site, version, type, pkgs $this->_host->setOsName($this->_report_os); $this->_host->setArchName($this->_report_arch); $this->_host->setKernel($this->_report_kernel); $this->_host->setType($this->_report_type); break; case "cern_1": Utils::log(LOG_DEBUG, "Client in version CERN 1", __FILE__, __LINE__); # Get the rest of HTTP variables # host, os, arch, kernel, site, version, type, pkgs $this->_host->setOsName($this->_report_os); $this->_host->setArchName($this->_report_arch); $this->_host->setKernel($this->_report_kernel); $this->_host->setType($this->_report_type); break; } # Parse the packages list $this->_pkgs = $this->parsePkgs($this->_report_pkgs); # Set the initial information about the report $this->_report->setReceivedOn(time()); # Get the host object from the DB, if the host doesn't exist in the DB, this routine will create it $this->_host = $this->getPakiti()->getManager("HostsManager")->getHostFromReport($this->_host, $this->_pkgs); # Get the host group $hostGroup = new HostGroup(); $hostGroup->setName($this->_report_site); # If the host is already member of the host group, no operation is done $this->getPakiti()->getManager("HostGroupsManager")->assignHostToHostGroup($this->_host, $hostGroup); # Get the host tag and assign it to the host $tag = new Tag(); $tag->setName($this->_report_tag); # If the tag is already assigned, no operation is done $this->getPakiti()->getManager("TagsManager")->assignTagToHost($this->_host, $tag); $this->_report->setNumOfInstalledPkgs(sizeof($this->_pkgs)); }