Exemplo n.º 1
0
 public function soapSend($method, $params = null, $forceRequest = false, $rcv_timeout = 0)
 {
     $dispatcher = sfContext::getInstance()->getEventDispatcher();
     $addr = $this->getIP();
     $port = $this->getPort();
     $proto = "tcp";
     $host = "" . $proto . "://" . $addr . ":" . $port;
     $state = $this->getState();
     $agent = $this->getName();
     if (!$params) {
         $params = array("nil" => "true");
     }
     $request_array = array('request' => array('agent' => $agent, 'host' => $host, 'port' => $port, 'method' => $method, 'params' => $params));
     if (!$state && !$forceRequest) {
         /*
          * if current state is 0 DO NOT send soap request
          * this approach avoids generating unnecessary traffic since if
          *  the agent is alive it should update its state
          *
          */
         // if current state is 0 DO NOT send soap request
         $info = sfContext::getInstance()->getI18N()->__('VirtAgent down! Request not sent!');
         $error = sfContext::getInstance()->getI18N()->__('VirtAgent down');
         $response = array('success' => false, 'agent' => $this->getName(), 'error' => $error, 'info' => $info);
     } else {
         //if state reports 1 send request....
         $soap = new soapClient_($host, $port);
         if ($rcv_timeout) {
             $soap->set_rcv_timeout($rcv_timeout);
         } else {
             if ($this->rcv_timeout) {
                 $soap->set_rcv_timeout($this->rcv_timeout);
             }
         }
         $response = $soap->processSoap($method, $params);
         $response['agent'] = $this->getName();
         /*
          * if response is TCP failure then VirtAgent is not reachable
          * set state to 0
          */
         if (isset($response['faultcode']) && $response['faultcode'] == 'TCP') {
             if ($this->getState() >= self::NODE_INACTIVE) {
                 $this->setState(self::NODE_INACTIVE);
             }
             $this->save();
         } else {
             //keepalive update
             if ($this->getState() >= self::NODE_INACTIVE) {
                 $this->setState(self::NODE_ACTIVE);
             }
             $this->setLastKeepalive('NOW');
             $this->save();
         }
     }
     $response_array = array('response' => $response);
     $all_params = array_merge($request_array, $response_array);
     $dispatcher->notify(new sfEvent($this, sfConfig::get('app_virtsoap_log'), $all_params));
     return $response;
 }
Exemplo n.º 2
0
 public function soapSend($method, $params = null)
 {
     if (!$params) {
         $params = array("nil" => "true");
     }
     $node = $this->getEtvaNode();
     // try to send from node
     if ($node && $node->getState() == EtvaNode::NODE_ACTIVE) {
         /*
          * send soap request to management agent via node agent
          */
         $params['server_name'] = $this->getName();
         $params['server_uuid'] = $this->getUuid();
         $params['method'] = $method;
         $params['force_call'] = $this->getState() ? 0 : 1;
         $response = $node->soapSend('forward_to_mngtagent', $params);
         // only if response is ok
         // TODO check if fail connect via node agent
         if ($response) {
             if ($response['success'] || !$this->isRetryResponse($response)) {
                 return $response;
             }
         }
     }
     // else send directly from HTTP
     $dispatcher = sfContext::getInstance()->getEventDispatcher();
     $addr = $this->getIP();
     $port = $this->getAgentPort();
     $proto = "tcp";
     $host = "" . $proto . "://" . $addr . ":" . $port;
     $agent = $this->getName();
     $request_array = array('request' => array('agent' => $agent, 'host' => $host, 'port' => $port, 'method' => $method, 'params' => $params));
     $soap = new soapClient_($host, $port);
     if ($this->rcv_timeout) {
         $soap->set_rcv_timeout($this->rcv_timeout);
     }
     $response = $soap->processSoap($method, $params);
     $response['agent'] = $this->getName();
     $response_array = array('response' => $response);
     $all_params = array_merge($request_array, $response_array);
     $dispatcher->notify(new sfEvent($this, sfConfig::get('app_virtsoap_log'), $all_params));
     return $response;
 }