示例#1
0
 public function migrateAllServers(EtvaNode $etva_sparenode = null, $off = false, $ignoreAdmissionGate = false)
 {
     // migrate all servers
     // order by priority HA
     $querysrvs = EtvaServerQuery::create();
     $querysrvs->orderByPriorityHa('desc');
     $etva_servers = $this->etva_node->getEtvaServers($querysrvs);
     foreach ($etva_servers as $etva_server) {
         $server_va = new EtvaServer_VA($etva_server);
         $response = array();
         $etva_tonode = $etva_sparenode;
         if (!$etva_tonode) {
             $list_nodes_toassign = $etva_server->listNodesAssignTo(true);
             if (count($list_nodes_toassign)) {
                 $etva_tonode = $list_nodes_toassign[0];
             }
             // get first
         }
         if ($etva_tonode) {
             if (!$off && $etva_server->getVmState() == 'running') {
                 error_log("migrate server=" . $etva_server->getName() . " to node=" . $etva_tonode->getName());
                 $response = $server_va->send_migrate($this->etva_node, $etva_tonode);
             } else {
                 error_log("move server=" . $etva_server->getName() . " to node=" . $etva_tonode->getName());
                 $response = $server_va->send_move($this->etva_node, $etva_tonode);
                 // start it server is running or has autostart  or has HA or has priority HA
                 if ($off && ($etva_server->getVmState() == 'running' || $etva_server->getAutostart())) {
                     // send start server
                     $start_res = $server_va->send_start($etva_tonode, null, $ignoreAdmissionGate);
                 }
             }
             if ($response['success']) {
                 Etva::makeNotifyLogMessage($this->etva_node->getName(), sprintf('Server %s migrate ok', $etva_server->getName()), array(), null, array(), EtvaEventLogger::INFO);
                 error_log(sprintf('Server %s migrate ok', $etva_server->getName()));
             } else {
                 Etva::makeNotifyLogMessage($this->etva_node->getName(), sprintf('Server %s migrate nok', $etva_server->getName()));
                 error_log(sprintf('Server %s migrate nok', $etva_server->getName()));
             }
         } else {
             Etva::makeNotifyLogMessage($this->etva_node->getName(), sprintf('Can\'t migrate server %s. No node free available.', $etva_server->getName()));
             error_log(sprintf('Can\'t migrate server %s. No node free available.', $etva_server->getName()));
         }
     }
 }
示例#2
0
 /**
  *
  *
  * move server to other node.
  * Removes server from current node and add to other
  *
  * request object is like this;
  * <code>
  * $request['id'] = $id; //server ID
  * $request['nid'] = $id; //node destination ID
  * </code>
  *
  * @param sfWebRequest $request A request object
  *     
  * @return string json string representation of array('success'=>true,'agent'=>$agent, 'response'=>$response)
  *
  */
 public function executeJsonMove(sfWebRequest $request)
 {
     $sid = $request->getParameter('id');
     $nid = $request->getParameter('nid');
     if (!($etva_server = EtvaServerPeer::retrieveByPK($sid))) {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $sid));
         $error = array('agent' => sfConfig::get('config_acronym'), 'success' => false, 'error' => $msg_i18n);
         //notify event log
         $server_log = Etva::getLogMessage(array('id' => $sid), EtvaServerPeer::_ERR_NOTFOUND_ID_);
         $message = Etva::getLogMessage(array('info' => $server_log), EtvaServerPeer::_ERR_MOVE_UNKNOWN_);
         $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     if (!($to_etva_node = EtvaNodePeer::retrieveByPK($nid))) {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $nid));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         //notify event log
         $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_);
         $message = Etva::getLogMessage(array('name' => $etva_server->getName(), 'info' => $node_log), EtvaServerPeer::_ERR_MOVE_);
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     $from_etva_node = $etva_server->getEtvaNode();
     $server_va = new EtvaServer_VA($etva_server);
     $response = $server_va->send_move($from_etva_node, $to_etva_node);
     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);
     }
 }