protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', 'dev', true));
     parent::execute($arguments, $options);
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     $this->log('[INFO] Checking VirtAgents state...' . "\n");
     $offset = sfConfig::get('app_node_keepalive_update') + sfConfig::get('app_node_keepalive_update_offset');
     $total_nodes = EtvaNodePeer::doCount(new Criteria());
     if ($total_nodes > 0) {
         $con->beginTransaction();
         $affected = 0;
         try {
             $offset_date = date("c", time() - $offset);
             /*
              * get nodes that have last_keepalive field outdated
              */
             $c1 = new Criteria();
             $c1->add(EtvaNodePeer::LAST_KEEPALIVE, $offset_date, Criteria::LESS_THAN);
             $c1->add(EtvaNodePeer::STATE, EtvaNode::NODE_ACTIVE);
             // only active
             //update statement
             $c2 = new Criteria();
             $c2->add(EtvaNodePeer::STATE, EtvaNode::NODE_INACTIVE);
             $affected += BasePeer::doUpdate($c1, $c2, $con);
             // update maintenance and running to maintenance
             $c1 = new Criteria();
             $c1->add(EtvaNodePeer::LAST_KEEPALIVE, $offset_date, Criteria::LESS_THAN);
             $c1->add(EtvaNodePeer::STATE, EtvaNode::NODE_MAINTENANCE_UP);
             //update statement
             $c2 = new Criteria();
             $c2->add(EtvaNodePeer::STATE, EtvaNode::NODE_MAINTENANCE);
             $affected += BasePeer::doUpdate($c1, $c2, $con);
             // update fail and running to fail
             $c1 = new Criteria();
             $c1->add(EtvaNodePeer::LAST_KEEPALIVE, $offset_date, Criteria::LESS_THAN);
             $c1->add(EtvaNodePeer::STATE, EtvaNode::NODE_FAIL_UP);
             // only active
             //update statement
             $c2 = new Criteria();
             $c2->add(EtvaNodePeer::STATE, EtvaNode::NODE_FAIL);
             $affected += BasePeer::doUpdate($c1, $c2, $con);
             $con->commit();
             $message = sprintf('%d Node(s) NOT received update in time offset of %d seconds', $affected, $offset);
             if ($affected > 0) {
                 $context->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             }
             $this->log('[INFO]' . $message);
         } catch (PropelException $e) {
             $con->rollBack();
             throw $e;
         }
     }
     $logger = new sfFileLogger($context->getEventDispatcher(), array('file' => sfConfig::get("sf_log_dir") . '/cron_status.log'));
     // log the message!
     $logger->log("[INFO] The check virtAgents task ran!", 6);
 }
示例#2
0
 /**
  * Moves an unaccepted node to the given cluster
  * @param sfWebRequest $request
  * json, cluster id (target) and node id
  * @return json, success
  */
 public function executeJsonMoveNode(sfWebRequest $request)
 {
     $cluster_id = $request->getParameter('to_cluster_id');
     $node_id = $request->getParameter('node_id');
     try {
         $c = new Criteria();
         $c->add(EtvaNodePeer::ID, $node_id, Criteria::EQUAL);
         if (EtvaNodePeer::doCount($c) == 1) {
             $etva_node = EtvaNodePeer::doSelectOne($c);
             $etva_node->setClusterId($cluster_id);
             $etva_node->save();
         } else {
             $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $node_id));
             $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
             // if is browser request return text renderer
             $error = json_encode($error);
             return $this->renderText($error);
         }
     } catch (Exception $e) {
         error_log("CLUSTER[ERROR] Move of node " . $node_id . " into cluster " . $cluster_id . " failed!");
         $error = array('success' => false, 'error' => array('cluster' => $e->getMessage()));
         $error = json_encode($error);
         return $this->renderText($error);
     }
     $msg_i18n = $this->getContext()->getI18N()->__('Node %name% moved successfully', array('%name%' => $etva_node->getName()));
     // EtvaServerPeer::_ERR_NOTFOUND_ID_,array('%id%'=>$sid));
     $return = array('agent' => sfConfig::get('config_acronym'), 'success' => true, 'info' => $msg_i18n);
     $result = json_encode($return);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($result);
 }