Exemple #1
0
 public function executeJsonUnregister(sfWebRequest $request)
 {
     $msg_ok_type = EtvaVolumegroupPeer::_OK_UNREGISTER_;
     $msg_err_type = EtvaVolumegroupPeer::_ERR_UNREGISTER_;
     // get node id
     if (!($etva_node = EtvaNodePeer::retrieveByPK($request->getParameter('nid')))) {
         // ... or elect from cluster context
         $etva_node = EtvaNodePeer::getOrElectNode($request);
     }
     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, 'info' => $msg_i18n);
         $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_);
         //notify system log
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $node_log, '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);
     }
     $vg = $request->getParameter('vg');
     if (!($etva_volumegroup = $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_UNREGISTER_);
         $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);
     }
     //error_log("etva_volumegroup: " . print_r($etva_volumegroup,true));
     $etva_vg_va = new EtvaVolumegroup_VA($etva_volumegroup);
     $response = $etva_vg_va->unregister($etva_node);
     if (!$response['success']) {
         $msg_i18n = $this->getContext()->getI18N()->__($msg_err_type, array('%name%' => $vg));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $node_log = Etva::getLogMessage(array('name' => $vg), $msg_err_type);
         //notify system log
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $node_log, '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);
     }
     //notify system log
     $message = Etva::getLogMessage(array('name' => $vg), $msg_ok_type);
     $msg_i18n = sfContext::getInstance()->getI18N()->__($msg_ok_type, array('%name%' => $vg));
     sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
     $result = array('success' => true, 'agent' => $etva_node->getName(), 'response' => $msg_i18n);
     /*$result = array('success'=>true, 'response'=>'unregister ok' );
       $result['agent'] = $etva_node->getName();*/
     $return = json_encode($result);
     if (sfConfig::get('sf_environment') == 'soap') {
         return $return;
     }
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true));
     parent::execute($arguments, $options);
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     $this->log('Checking shared storage cluster consistency...' . "\n");
     $ok = 1;
     $affected = 0;
     $errors = array();
     $clusters = EtvaClusterPeer::doSelect(new Criteria());
     foreach ($clusters as $cluster) {
         $bulk_response_lvs = $cluster->soapSend('getlvs_arr', array('force' => 1));
         $bulk_response_dtable = $cluster->soapSend('device_table');
         $lv_va = new EtvaLogicalvolume_VA();
         foreach ($bulk_response_lvs as $node_id => $node_response) {
             if ($node_response['success']) {
                 //response received ok
                 $lvs = (array) $node_response['response'];
                 $node = EtvaNodePeer::retrieveByPK($node_id);
                 //$consist = $lv_va->check_shared_consistency($node,$lvs);
                 $response_dtable = (array) $bulk_response_dtable[$node_id];
                 $dtable = array();
                 if ($response_dtable['success']) {
                     $dtable = (array) $response_dtable['response'];
                     //$consist_dtable = $lv_va->check_shared_devicetable_consistency($node,$dtable,$bulk_response_dtable);
                 }
                 $check_res = $lv_va->check_consistency($node, $lvs, $dtable, $bulk_response_dtable);
                 if (!$check_res['success']) {
                     $err = $check_res['errors'];
                     $msg = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => ''));
                     $err_msg = sprintf(" node with id=%s is not consistent: %s \n", $node_id, $msg);
                     $errors[] = array('message' => $err_msg, 'debug' => $err);
                     $affected++;
                     $node->setErrorMessage(EtvaLogicalvolume_VA::LVINIT);
                 } else {
                     $node->clearErrorMessage(EtvaLogicalvolume_VA::LVINIT);
                 }
                 /*if( !$consist || !$consist_dtable ){
                                     $errors = $lv_va->get_missing_lv_devices();
                                     $msg = $errors ? $errors['message'] :
                                                     sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_,array('%info%'=>''));
                 
                                     $err_msg = sprintf( " node with id=%s is not consistent: %s \n", $node_id, $msg );
                                     $errors[] = array( 'message'=> $err_msg, 'debug'=>array( 'consist_lvs'=>$consist, 'consist_dtable'=>$consist_dtable ) );
                                     $affected++;
                                     $node->setErrorMessage(EtvaLogicalvolume_VA::LVINIT);
                                 } else {
                                     $node->clearErrorMessage(EtvaLogicalvolume_VA::LVINIT);
                                 }*/
             } else {
                 $errors[] = $node_response;
                 $affected++;
             }
         }
         $bulk_response_pvs = $cluster->soapSend('hash_phydisks', array('force' => 1));
         $pv_va = new EtvaPhysicalvolume_VA();
         foreach ($bulk_response_pvs as $node_id => $node_response) {
             if ($node_response['success']) {
                 //response received ok
                 $pvs = (array) $node_response['response'];
                 $node = EtvaNodePeer::retrieveByPK($node_id);
                 $check_res = $pv_va->check_consistency($node, $pvs);
                 if (!$check_res['success']) {
                     $err = $check_res['errors'];
                     $msg = sfContext::getInstance()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => ''));
                     $err_msg = sprintf(" node with id=%s is not consistent: %s \n", $node_id, $msg);
                     $errors[] = array('message' => $err_msg, 'debug' => $err);
                     $affected++;
                     $node->setErrorMessage(EtvaPhysicalvolume_VA::PVINIT);
                 } else {
                     $node->clearErrorMessage(EtvaPhysicalvolume_VA::PVINIT);
                 }
             } else {
                 $errors[] = $node_response;
                 $affected++;
             }
         }
         $bulk_responses_vgs = $cluster->soapSend('getvgpvs', array('force' => 1));
         $vg_va = new EtvaVolumegroup_VA();
         foreach ($bulk_response_vgs as $node_id => $node_response) {
             if ($node_response['success']) {
                 //response received ok
                 $vgs = (array) $node_response['response'];
                 $node = EtvaNodePeer::retrieveByPK($node_id);
                 $check_res = $vg_va->check_consistency($node, $vgs);
                 if (!$check_res['success']) {
                     $err = $check_res['errors'];
                     $msg = sfContext::getInstance()->getI18N()->__(EtvaVolumegroupPeer::_ERR_INCONSISTENT_, array('%info%' => ''));
                     $err_msg = sprintf(" node with id=%s is not consistent: %s \n", $node_id, $msg);
                     $errors[] = array('message' => $err_msg, 'debug' => $err);
                     $affected++;
                     $node->setErrorMessage(EtvaVolumegroup_VA::VGINIT);
                 } else {
                     $node->clearErrorMessage(EtvaVolumegroup_VA::VGINIT);
                 }
             } else {
                 $errors[] = $node_response;
                 $affected++;
             }
         }
     }
     if (!empty($errors)) {
         $this->log($message);
     } else {
         // log the message!
         $this->log("The check shared storage cluster consistency task ran!", 6);
     }
 }
 public function fix_consistency(EtvaNode $etva_node)
 {
     $ok = 1;
     $etva_lv = $this->etva_lv;
     $lv = $etva_lv->getLv();
     $etva_vg = $etva_lv->getEtvaVolumegroup();
     /*
             $vgInfo = $returned_object[EtvaLogicalvolume::VOLUMEGROUP_MAP];
             $vg_info = (array) $vgInfo;*/
     // removes logical volume
     $insert_id = $etva_lv->getId();
     $uuid = $etva_lv->getUuid();
     $lv_type = $etva_lv->getStorageType();
     $etva_lv->delete();
     // remove snapshots
     $snapshotsObject = $returned_object['SNAPSHOTS'];
     $snapshotsArray = (array) $snapshotsObject;
     foreach ($snapshotsArray as $slv_obj) {
         $slv = (array) $slv_obj;
         if ($etva_slv = $etva_node->retrieveLogicalvolumeByLv($slv[EtvaLogicalvolume::LV_MAP])) {
             $etva_slv->delete();
         }
     }
     /*$etva_vg->initData($vg_info);
       $etva_vg->save();*/
     if ($lv_type != EtvaLogicalvolume::STORAGE_TYPE_LOCAL_MAP) {
         /*
          * need syncronize device table
          */
         $this->sync_device_table_afterremove($etva_node);
         /*
          * if storage type not local send update to nodes...
          */
         $bulk_update = $this->send_update($etva_node);
         if (!empty($bulk_update)) {
             $errors = $this->get_missing_lv_devices();
             $msg_i18n = $errors ? $errors['message'] : sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_SHARED_INCONSISTENT_, array('%info%' => ' processResponse'));
             $response = array('success' => false, 'agent' => $etva_node->getName(), 'info' => $msg_i18n, 'msg_i18n' => $msg_i18n);
             $ok = 0;
         }
     }
     // Update volume groups
     $vg_va = new EtvaVolumegroup_VA($etva_vg);
     $bulk_update = $vg_va->send_update($etva_node);
     // TODO call fix consistency volume group
     if ($ok == 0) {
         $result = $response;
         $errors = $this->get_missing_lv_devices();
         if ($errors) {
             $message = $errors['message'];
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             return array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $message, 'action' => 'reload', 'info' => $message);
         } else {
             $message = Etva::getLogMessage(array('name' => $lv, 'info' => $response['info']), $msg_err_type);
             $msg_i18n = sfContext::getInstance()->getI18N()->__($msg_err_type, array('%name%' => $lv, '%info%' => $response['info']));
             $result['error'] = $msg_i18n;
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($response['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             return $result;
         }
     } else {
         //notify system log
         $message = Etva::getLogMessage(array('name' => $lv), $msg_ok_type);
         $msg_i18n = sfContext::getInstance()->getI18N()->__($msg_ok_type, array('%name%' => $lv));
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
         $result = array('success' => true, 'agent' => $response['agent'], 'response' => $msg_i18n, 'insert_id' => $insert_id, 'uuid' => $uuid);
         return $result;
     }
 }