Exemple #1
0
 /**
  * Reduces the volume group by n physical volumes
  *
  * $request may contain the following keys:    
  * - nid: node ID
  * - vg: volume group name
  * - pvs: json array with physical volumes
  *
  */
 public function executeJsonReduce(sfWebRequest $request)
 {
     $cid = $request->getParameter('cid');
     $level = $request->getParameter('level');
     $nid = $request->getParameter('nid');
     $vg = $request->getParameter('vg');
     $etva_node = EtvaNodePeer::getOrElectNode($request);
     // physical volume id
     $pvs = json_decode($request->getParameter('pvs'), true);
     if (!$etva_node) {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $nid));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n);
         //notify event log
         $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_);
         $message = Etva::getLogMessage(array('name' => $vg, 'info' => $node_log), EtvaVolumegroupPeer::_ERR_REDUCE_);
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         // if is a CLI soap request return json encoded data
         if (sfConfig::get('sf_environment') == 'soap') {
             return json_encode($error);
         }
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     if (!($etva_vg = $etva_node->retrieveVolumegroupByVg($vg))) {
         $msg = Etva::getLogMessage(array('name' => $vg), EtvaVolumegroupPeer::_ERR_NOTFOUND_);
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaVolumegroupPeer::_ERR_NOTFOUND_, array('%name%' => $vg));
         $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n);
         //notify system log
         $message = Etva::getLogMessage(array('name' => $vg, 'info' => $msg), EtvaVolumegroupPeer::_ERR_REMOVE_);
         $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         // if is a CLI soap request return json encoded data
         if (sfConfig::get('sf_environment') == 'soap') {
             return json_encode($error);
         }
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     /*
      * send volume group to VA
      */
     $vg_va = new EtvaVolumegroup_VA($etva_vg);
     $response = $vg_va->send_reduce($etva_node, $pvs);
     if ($response['success']) {
         $return = json_encode($response);
         // if the request is made throught soap request...
         if (sfConfig::get('sf_environment') == 'soap') {
             return $return;
         }
         // if is browser request return text renderer
         $this->getResponse()->setHttpHeader('Content-type', 'application/json');
         return $this->renderText($return);
     } else {
         if (sfConfig::get('sf_environment') == 'soap') {
             return json_encode($response);
         }
         $return = $this->setJsonError($response);
         return $this->renderText($return);
     }
 }