public function execute($response)
 {
     $this->getCache()->resetCache();
     $result = null;
     $jsonObj = json_decode($response);
     $scrollId = $jsonObj->_scroll_id;
     $total = $jsonObj->hits->total;
     foreach ($jsonObj->hits->hits as $index => $tmpObj) {
         $this->getCache()->add($tmpObj);
     }
     if ($this->getCache()->getCount() != $total) {
         $cmdb = new CMDB(null);
         $queryObj = new QueryObj();
         $queryObj->setQueryUrl(self::SCROLL_URL);
         $queryObj->setQueryString('{"scroll_id":"' . $scrollId . '"}');
         $queryObj->setExecutorName(self::EXECUTOR_NAME);
         $cmdb->addObserver($queryObj);
         do {
             $results = $cmdb->fetch($queryObj);
             $tmpjsonObj = json_decode($results);
             foreach ($tmpjsonObj->hits->hits as $index => $tmpObj) {
                 $this->getCache()->add($tmpObj);
             }
             unset($tmpjsonObj);
         } while ($this->getCache()->getCount() != $total);
     }
     if (!!($executor = GlobalArgParser::getExecutor())) {
         $executorObj = new $executor();
         $result = $executorObj->execute($this->getCache()->get());
     }
     return $result;
 }
 /**
  * execute 
  *      Main wrapper command for executing cmdb fetches
  *
  * @param mixed $className 
  * @static
  * @access public
  * @return void
  */
 public static function execute($className)
 {
     if (!preg_match(self::CLASSNAME_REGEX, $className)) {
         $className = CMDB_LOC_PREFIX . $className;
     }
     if (!class_exists($className)) {
         throw new QueryWrapperException($className . self::MISSING_CLASS);
     } else {
         if ($className == CMDB_LOC_PREFIX) {
             throw new QueryWrapperException(self::CMDB_COLLISION . CMDB_LOC_PREFIX);
         }
     }
     $queryObj = new QueryObj();
     $queryObj->setQueryUrl(self::QUERY_URL);
     new $className($queryObj);
     $cmdb = new CMDB(NULL);
     $cmdb->addObserver($queryObj);
     return $cmdb->fetch($queryObj);
 }
Beispiel #3
0
 /**
  * fetch 
  * 
  * get the required data from the cmdb by getting the query from
  * the query object
  *
  * @access public
  * @return void
  */
 public function fetch(QueryObj $queryObj)
 {
     /* check return value from query */
     if (!($query = $queryObj->getQueryString())) {
         throw new CMDBException(self::BAD_QUERY_MSG);
     }
     if (!($queryUrl = $queryObj->getQueryUrl())) {
         throw new CMDBException(self::BAD_QUERY_URL);
     }
     /* Initialize Curl and Issue Request */
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPHEADER, $this->m_curl_opt["http_header"]);
     curl_setopt($ch, CURLOPT_URL, $queryUrl);
     curl_setopt($ch, CURLOPT_USERPWD, $this->m_curl_opt["user_pwd"]);
     curl_setopt($ch, CURLOPT_USERAGENT, $this->m_curl_opt["user_agent"]);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, $this->m_curl_opt["return_transfer"]);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->m_curl_opt["ssl_verify_peer"]);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->m_curl_opt["ssl_verify_host"]);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->m_curl_opt["timeout"]);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
     /* Response or No Response ? */
     $response = curl_exec($ch);
     $errno = curl_errno($ch);
     $errstr = curl_error($ch);
     curl_close($ch);
     if ($errno) {
         throw new CMDBException(self::BAD_CURL_MSG . $errno . " " . $errstr);
     }
     $result = NULL;
     if ($executor = $queryObj->getExecutorName()) {
         $result = $this->getObserver($executor)->execute($response);
     } else {
         throw new CMDBException(self::BAD_EXECUTOR_MSG);
     }
     return $result;
 }