예제 #1
0
 public function get_sync_logicalvolumes($force_sync = false, $sharedonly = false)
 {
     $elements = array();
     $criteria = new Criteria();
     $criteria->add(EtvaNodeLogicalvolumePeer::NODE_ID, $this->etva_node->getId());
     $db_node_lvs = EtvaNodeLogicalvolumePeer::doSelectJoinEtvaLogicalvolume($criteria);
     $force_flag = $force_sync ? 1 : 0;
     $response_lvs = $this->etva_node->soapSend(EtvaLogicalvolume_VA::GET_SYNC_LOGICALVOLUMES, array('force' => $force_flag));
     if ($response_lvs['success']) {
         $lvs = $response_lvs['response'];
         foreach ($lvs as $k => $e) {
             $lv_e = (array) $e;
             if (!$sharedonly || $lv_e[EtvaLogicalvolume::STORAGE_TYPE_MAP] != EtvaLogicalvolume::STORAGE_TYPE_LOCAL_MAP) {
                 $found = false;
                 foreach ($db_node_lvs as $data) {
                     $lv = $data->getEtvaLogicalvolume();
                     if ($lv_e[EtvaLogicalvolume::STORAGE_TYPE_MAP] == $lv->getStorageType()) {
                         if ($lv->getUuid() && $lv_e[EtvaLogicalvolume::UUID_MAP]) {
                             if ($lv->getUuid() == $lv_e[EtvaLogicalvolume::UUID_MAP]) {
                                 $found = true;
                             }
                         } else {
                             if ($lv->getLvdevice() == $lv_e[EtvaLogicalvolume::LVDEVICE_MAP]) {
                                 $found = true;
                             }
                         }
                     }
                 }
                 $etva_lv = new EtvaLogicalvolume();
                 $etva_volgroup = new EtvaVolumegroup();
                 $etva_volgroup->initData((array) $lv_e[EtvaLogicalvolume::VOLUMEGROUP_MAP]);
                 /*$vg_ar = $lv_e[EtvaLogicalvolume::VOLUMEGROUP_MAP];
                   $vg_type = $vg_ar[EtvaVolumegroup::STORAGE_TYPE_MAP];
                   $vg_uuid = $vg_ar[EtvaVolumegroup::UUID_MAP];
                   $vg_name = $vg_ar[EtvaVolumegroup::VG_MAP];
                   $etva_volgroup = EtvaVolumegroupPeer::retrieveByNodeTypeUUIDVg($this->etva_node->getId(), $vg_type, $vg_uuid, $vg_name);*/
                 $etva_lv->initData($lv_e);
                 $etva_lv->setEtvaVolumegroup($etva_volgroup);
                 $arr_e = $etva_lv->_VA();
                 $arr_e['registered'] = $found;
                 $elements[] = $arr_e;
             }
         }
     }
     foreach ($db_node_lvs as $data) {
         $lv = $data->getEtvaLogicalvolume();
         if (!$sharedonly || $lv->getStorageType() != EtvaLogicalvolume::STORAGE_TYPE_LOCAL_MAP) {
             $found = false;
             foreach ($lvs as $k => $e) {
                 $lv_e = (array) $e;
                 if ($lv_e[EtvaLogicalvolume::STORAGE_TYPE_MAP] == $lv->getStorageType()) {
                     if ($lv->getUuid() && $lv_e[EtvaLogicalvolume::UUID_MAP]) {
                         if ($lv->getUuid() == $lv_e[EtvaLogicalvolume::UUID_MAP]) {
                             $found = true;
                         }
                     } else {
                         if ($lv->getLvdevice() == $lv_e[EtvaLogicalvolume::LVDEVICE_MAP]) {
                             $found = true;
                         }
                     }
                 }
             }
             if (!$found) {
                 $arr_e = $lv->_VA();
                 $arr_e['inconsistent'] = true;
                 $arr_e['registered'] = true;
                 $elements[] = $arr_e;
             }
         }
     }
     return $elements;
 }
예제 #2
0
 public function initialize(EtvaNode $etva_node, $lvs, $dtable, $bulk_dtable)
 {
     $etva_cluster = $etva_node->getEtvaCluster();
     $logical_names = array();
     $errors = array();
     /*
      * check lv consistency
      */
     $check_res = $this->check_consistency($etva_node, $lvs, $dtable, $bulk_dtable);
     if (!$check_res['success']) {
         $errors = $check_res['errors'];
         $inconsistent_message = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => ''));
         $etva_node->setErrorMessage(self::LVINIT);
         $message = Etva::getLogMessage(array('info' => $inconsistent_message), EtvaLogicalvolumePeer::_ERR_SOAPUPDATE_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         // dont stop process
         //return array('success'=>false,'error'=>$errors);
     }
     /*
      * check shared lvs consistency
      */
     /*$consist = $this->check_shared_consistency($etva_node,$lvs);        
             $consist_dtable = $this->check_shared_devicetable_consistency($etva_node,$dtable,$bulk_dtable);
     
             if(!$consist || !$consist_dtable){
                 $errors = $this->get_missing_lv_devices($etva_node);
                 $inconsistent_message = $errors ? $errors['message'] :
                                 sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_,array('%info%'=>'initialize'));
     
                 $etva_node->setErrorMessage(self::LVINIT);
     
                 $message = Etva::getLogMessage(array('info'=>$inconsistent_message), EtvaLogicalvolumePeer::_ERR_SOAPUPDATE_);
                 sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(),'event.log',array('message' =>$message,'priority'=>EtvaEventLogger::ERR)));
     
                 // dont stop process
                 //return array('success'=>false,'error'=>$errors);
             }*/
     foreach ($lvs as $lvInfo) {
         if (!empty($lvInfo)) {
             $lv_info = (array) $lvInfo;
             // set mounted 0 when not mounted
             if (!isset($lv_info[EtvaLogicalvolume::MOUNTED_MAP])) {
                 $lv_info[EtvaLogicalvolume::MOUNTED_MAP] = 0;
             }
             //error_log("device " . $lv_info[EtvaLogicalvolume::LVDEVICE_MAP] . " EtvaLogicalvolume::MOUNTED_MAP " . $lv_info[EtvaLogicalvolume::MOUNTED_MAP]);
             $lv_dev = $lv_info[EtvaLogicalvolume::LVDEVICE_MAP];
             $lv_type = $lv_info[EtvaLogicalvolume::STORAGE_TYPE_MAP];
             $lv_uuid = isset($lv_info[EtvaLogicalvolume::UUID_MAP]) ? $lv_info[EtvaLogicalvolume::UUID_MAP] : '';
             // vg info
             $vg_info = (array) $lv_info[EtvaLogicalvolume::VOLUMEGROUP_MAP];
             $vg_name = $vg_info[EtvaVolumegroup::VG_MAP];
             $vg_type = $vg_info[EtvaVolumegroup::STORAGE_TYPE_MAP];
             $vg_uuid = isset($vg_info[EtvaVolumegroup::UUID_MAP]) ? $vg_info[EtvaVolumegroup::UUID_MAP] : '';
             //get volume group based on node, type, uuid and vg
             $etva_volgroup = EtvaVolumegroupPeer::retrieveByNodeTypeUUIDVg($etva_node->getId(), $vg_type, $vg_uuid, $vg_name);
             if ($etva_volgroup) {
                 if ($lv_type == EtvaLogicalvolume::STORAGE_TYPE_LOCAL_MAP) {
                     $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByNodeTypeLvDevice($etva_node->getId(), $lv_type, $lv_dev);
                 } else {
                     $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByUUID($lv_uuid);
                 }
                 if (!$etva_logicalvol) {
                     // no lv in db...so create new one
                     $etva_node_logicalvol = new EtvaNodeLogicalvolume();
                     $etva_logicalvol = new EtvaLogicalvolume();
                 } else {
                     //if lv already in DB we need to make sure if already exists association with node. if not create new one
                     $etva_node_logicalvol = EtvaNodeLogicalvolumePeer::retrieveByPK($etva_node->getId(), $etva_logicalvol->getId());
                     if (!$etva_node_logicalvol) {
                         $etva_node_logicalvol = new EtvaNodeLogicalvolume();
                     }
                 }
                 $etva_logicalvol->initData($lv_info);
                 $etva_logicalvol->setEtvaVolumegroup($etva_volgroup);
                 $etva_logicalvol->setEtvaCluster($etva_cluster);
                 $etva_logicalvol->save();
                 $etva_node_logicalvol->setEtvaLogicalvolume($etva_logicalvol);
                 $etva_node_logicalvol->setEtvaNode($etva_node);
                 $etva_node_logicalvol->save();
                 $logical_names[] = $etva_logicalvol->getLv();
             }
         }
     }
     if (!empty($errors)) {
         // if have some errors, return it
         return array('success' => false, 'error' => $errors);
     } else {
         /*
          * check if is an appliance restore operation...
          */
         $apli = new Appliance();
         $action = $apli->getStage(Appliance::RESTORE_STAGE);
         if ($action) {
             $apli->setStage(Appliance::RESTORE_STAGE, Appliance::VA_UPDATE_LVS);
         }
         $etva_node->clearErrorMessage(self::LVINIT);
         $message = Etva::getLogMessage(array('info' => implode(', ', $logical_names)), EtvaLogicalvolumePeer::_OK_SOAPUPDATE_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
         return array('success' => true, 'response' => $logical_names);
     }
 }