Esempio n. 1
0
 public function executeJson(sfWebRequest $request)
 {
     error_log("EXECUTE JSON CALLED");
     // we only have on service... so...
     if (!$request->getParameter('service')) {
         $etva_service = EtvaServiceQuery::create()->useEtvaServerQuery()->filterById($request->getParameter('id'))->endUse()->findOne();
     } else {
         $etva_service = EtvaServicePeer::retrieveByPK($request->getParameter('service'));
     }
     if (!$etva_service) {
         $msg = array('success' => false, 'error' => 'No service with specified id', 'info' => 'No service with specified id');
         $result = $this->setJsonError($msg);
         $this->getResponse()->setHttpHeader('Content-type', 'application/json');
         return $this->renderText($result);
     }
     $etva_server = $etva_service->getEtvaServer();
     $agent_tmpl = $etva_server->getAgentTmpl();
     $service_tmpl = $etva_service->getNameTmpl();
     $method = $request->getParameter('method');
     $mode = $request->getParameter('mode');
     $params = json_decode($request->getParameter('params'), true);
     if (!$params) {
         $params = array();
     }
     $dispatcher_tmpl = $agent_tmpl . '_' . $service_tmpl;
     if (method_exists($this, $dispatcher_tmpl)) {
         $ret = call_user_func_array(array($this, $dispatcher_tmpl), array($etva_server, $method, $params, $mode));
         //            return $this->renderText($ret);
         if ($ret['success']) {
             $result = json_encode($ret);
         } else {
             $result = $this->setJsonError($ret);
         }
     } else {
         $info = array('success' => false, 'error' => 'No method implemented! ' . $dispatcher_tmpl);
         $result = $this->setJsonError($info);
     }
     // $result = json_encode($ret);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json; charset=utf-8');
     $this->getResponse()->setHttpHeader("X-JSON", '()');
     return $this->renderText($result);
 }
Esempio n. 2
0
 private function initModules()
 {
     $this->modules = array();
     $this->modulesConf = array();
     /*$servers_with_service = EtvaServerQuery::create()
       ->useEtvaServiceQuery("EtvaService","INNER JOIN")
       ->endUse()
       ->orderByAgentTmpl()
       ->find();*/
     $service_with_server = EtvaServiceQuery::create()->useEtvaServerQuery("EtvaServer", "INNER JOIN")->endUse()->find();
     //foreach($servers_with_service as $server){
     foreach ($service_with_server as $service) {
         $server = $service->getEtvaServer();
         $agent_tmpl = $server->getAgentTmpl();
         $s_name_tmpl = $service->getNameTmpl();
         if (!$this->modulesConf["{$agent_tmpl}"]) {
             $this->modulesConf["{$agent_tmpl}"] = array();
             $header = $agent_tmpl;
             $dataIndex = "is" . $agent_tmpl;
             array_push($this->modules, array('header' => $header, 'dataIndex' => $dataIndex, 'id' => $agent_tmpl));
         }
         array_push($this->modulesConf["{$agent_tmpl}"]["{$s_name_tmpl}"] = array('server_id' => $server->getId(), 'agent_port' => $server->getAgentPort(), 'ip' => $server->getIp(), 'state' => $server->getState(), 'vm_state' => $server->getVmState(), 'service_id' => $service->getId(), 'service_params' => $service->getParams()));
     }
 }