public function getVolumegroupInfo(EtvaNode $etva_node, $bulk_responses)
 {
     foreach ($bulk_responses as $node_id => $node_response) {
         if ($node_id == $etva_node->getId()) {
             if ($node_response['success']) {
                 $vgs = (array) $node_response['response'];
                 $found = false;
                 foreach ($vgs as $vgInfo) {
                     $vg_info = (array) $vgInfo;
                     $vg_type = $vg_info[EtvaVolumegroup::STORAGE_TYPE_MAP];
                     $vg_name = $vg_info[EtvaVolumegroup::VG_MAP];
                     if ($vg_type == $this->etva_vg->getStorageType()) {
                         if ($vg_type == EtvaVolumegroup::STORAGE_TYPE_LOCAL_MAP) {
                             if ($vg_name == $this->etva_vg->getVg()) {
                                 $found = true;
                             }
                         } else {
                             if (isset($vg_info[EtvaVolumegroup::UUID_MAP])) {
                                 $vg_uuid = $vg_info[EtvaVolumegroup::UUID_MAP];
                                 if ($vg_uuid == $this->etva_vg->getUuid()) {
                                     $found = true;
                                 }
                             } else {
                                 if ($vg_name == $this->etva_vg->getVg()) {
                                     $found = true;
                                 }
                             }
                         }
                     }
                     if ($found) {
                         return $vg_info;
                     }
                 }
             }
         }
     }
     return null;
 }
 public function check_consistency(EtvaNode $etva_node, $sync_node_lvs, $sync_node_dtable, $sync_bulk_dtable)
 {
     $errors = array();
     $etva_node->getId();
     $etva_cluster = $etva_node->getEtvaCluster();
     // get node database LVs
     $node_lvs = $etva_node->getEtvaLogicalvolumes();
     $node_inconsistent = 0;
     foreach ($node_lvs as $lv) {
         $error = array();
         $uuid = $lv->getUuid();
         $device = $lv->getLvdevice();
         $etva_vg = $lv->getEtvaVolumegroup();
         $vgname = $etva_vg->getVg();
         $is_FileDiskVG = $vgname == sfConfig::get('app_volgroup_disk_flag') ? true : false;
         // init
         $inconsistent = 0;
         // look at logical volumes list
         $found_lvm = 0;
         foreach ($sync_node_lvs as $hlv) {
             $arr_hlv = (array) $hlv;
             if ($arr_hlv[EtvaLogicalvolume::STORAGE_TYPE_MAP] == $lv->getStorageType()) {
                 if ($arr_hlv[EtvaLogicalvolume::UUID_MAP]) {
                     if ($arr_hlv[EtvaLogicalvolume::UUID_MAP] == $uuid) {
                         $found_lvm = 1;
                     }
                 } else {
                     if ($arr_hlv[EtvaLogicalvolume::LVDEVICE_MAP] == $device) {
                         $found_lvm = 1;
                     }
                 }
             }
         }
         $inconsistent = $inconsistent || !$found_lvm;
         if (!$found_lvm) {
             $error['not_found_lvm'] = 1;
         }
         if (!$is_FileDiskVG) {
             // if not file disk volume
             // look at devices table
             $clvdev = $device;
             $clvdev = str_replace("/dev/", "", $clvdev);
             $clvdev = str_replace("-", "--", $clvdev);
             $clvdev = str_replace("/", "-", $clvdev);
             $re_clvdev = "/" . $clvdev . ":/";
             // found device table of node
             $node_lv_dtable_aux = preg_grep($re_clvdev, $sync_node_dtable);
             // ignore snapshots
             $node_lv_dtable = preg_grep("/(?:(?! snapshot ).)/", $node_lv_dtable_aux);
             // check if found
             $found_node_dt = empty($node_lv_dtable) ? 0 : 1;
             $inconsistent = $inconsistent || !$found_node_dt;
             if (!$found_node_dt) {
                 $error['not_found_node_device_table'] = 1;
             }
         }
         // update data-base
         $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByNodeTypeUUIDLv($etva_node->getId(), $lv->getStorageType(), $lv->getUuid(), $lv->getLv());
         if ($etva_logicalvol) {
             $etva_logicalvol->setInconsistent($inconsistent);
             $etva_logicalvol->save();
         }
         $etva_node_logicalvol = EtvaNodeLogicalvolumePeer::retrieveByPK($etva_node->getId(), $lv->getId());
         if ($etva_node_logicalvol) {
             $etva_node_logicalvol->setInconsistent($inconsistent);
             $etva_node_logicalvol->save();
         }
         if ($inconsistent) {
             $message = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => sprintf('device "%s" with uuid "%s"', $lv->getLvdevice(), $lv->getUuid())));
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             $error['node'] = array('name' => $etva_node->getName(), 'id' => $etva_node->getId(), 'uuid' => $etva_node->getUuid());
             $error['device'] = $lv->getLvdevice();
             $error['uuid'] = $lv->getUuid();
             $error['message'] = $message;
         }
         if (!empty($error)) {
             $errors[] = $error;
         }
         $node_inconsistent = $node_inconsistent || $inconsistent;
     }
     // get shared database LVs
     $shared_lvs = $etva_cluster->getSharedLvs();
     // check consistency for shared LVs
     foreach ($shared_lvs as $lv) {
         $error = array();
         $uuid = $lv->getUuid();
         $device = $lv->getLvdevice();
         $etva_vg = $lv->getEtvaVolumegroup();
         $vgname = $etva_vg->getVg();
         // init
         $inconsistent = 0;
         // look at logical volumes list
         $found_lvm = 0;
         foreach ($sync_node_lvs as $hlv) {
             $arr_hlv = (array) $hlv;
             if ($arr_hlv[EtvaLogicalvolume::STORAGE_TYPE_MAP] == $lv->getStorageType()) {
                 if (isset($arr_hlv[EtvaLogicalvolume::UUID_MAP])) {
                     if ($arr_hlv[EtvaLogicalvolume::UUID_MAP] == $uuid) {
                         $found_lvm = 1;
                     }
                 } else {
                     if ($arr_hlv[EtvaLogicalvolume::LVDEVICE_MAP] == $device) {
                         $found_lvm = 1;
                     }
                 }
             }
         }
         $inconsistent = $inconsistent || !$found_lvm;
         if (!$found_lvm) {
             $error['not_found_lvm'] = 1;
         }
         // look at devices table
         $clvdev = $device;
         $clvdev = str_replace("/dev/", "", $clvdev);
         $clvdev = str_replace("-", "--", $clvdev);
         $clvdev = str_replace("/", "-", $clvdev);
         $re_clvdev = "/" . $clvdev . ":/";
         // found device table of node
         $node_lv_dtable_aux = preg_grep($re_clvdev, $sync_node_dtable);
         // ignore snapshots
         $node_lv_dtable = preg_grep("/(?:(?! snapshot ).)/", $node_lv_dtable_aux);
         // check if found
         $found_node_dt = empty($node_lv_dtable) ? 0 : 1;
         $inconsistent = $inconsistent || !$found_node_dt;
         if (!$found_node_dt) {
             $error['not_found_node_device_table'] = 1;
         }
         // look at all nodes devices table
         $found_all_nodes_dt = 1;
         foreach ($sync_bulk_dtable as $e_id => $e_response) {
             if ($e_response['success']) {
                 //response received ok
                 $dtable = (array) $e_response['response'];
                 // found device table of node
                 $lv_dtable = preg_grep($re_clvdev, $dtable);
                 $found = empty($lv_dtable) ? 0 : 1;
                 $is_eq = count($lv_dtable) == count($node_lv_dtable) ? 1 : 0;
                 if ($is_eq) {
                     foreach ($lv_dtable as $e_line) {
                         // TODO fix this
                         if (!in_array($e_line, $node_lv_dtable)) {
                             $is_eq = 0;
                         }
                     }
                 }
                 $found_all_nodes_dt = $found_all_nodes_dt && $found && $is_eq;
             }
         }
         $inconsistent = $inconsistent || !$found_all_nodes_dt;
         if (!$found_all_nodes_dt) {
             $error['not_found_all_nodes_device_table'] = 1;
         }
         // update data-base
         $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByNodeTypeUUIDLv($etva_node->getId(), $lv->getStorageType(), $lv->getUuid(), $lv->getLv());
         if ($etva_logicalvol) {
             $etva_logicalvol->setInconsistent($inconsistent);
             $etva_logicalvol->save();
         }
         $etva_node_logicalvol = EtvaNodeLogicalvolumePeer::retrieveByPK($etva_node->getId(), $lv->getId());
         if ($etva_node_logicalvol) {
             $etva_node_logicalvol->setInconsistent($inconsistent);
             $etva_node_logicalvol->save();
         }
         if ($inconsistent) {
             $message = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_SHARED_INCONSISTENT_, array('%info%' => sprintf('device "%s" with uuid "%s"', $lv->getLvdevice(), $lv->getUuid())));
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             $error['node'] = array('name' => $etva_node->getName(), 'id' => $etva_node->getId(), 'uuid' => $etva_node->getUuid());
             $error['device'] = $lv->getLvdevice();
             $error['uuid'] = $lv->getUuid();
             $error['message'] = $message;
         }
         if (!empty($error)) {
             $errors[] = $error;
         }
         $node_inconsistent = $node_inconsistent || $inconsistent;
     }
     $return = array();
     if ($node_inconsistent) {
         $etva_node->setErrorMessage(self::LVINIT);
         $return = array('success' => false, 'errors' => $errors);
     } else {
         $etva_node->clearErrorMessage(self::LVINIT);
         $return = array('success' => true);
     }
     return $return;
 }
 public function send_expand(EtvaNode $etva_node)
 {
     $msg_ok_type = EtvaPhysicalvolumePeer::_OK_EXPAND_;
     $msg_err_type = EtvaPhysicalvolumePeer::_ERR_EXPAND_;
     $method = self::DEVICERESIZE;
     $etva_pv_uuid = $this->etva_pv->getUuid();
     $etva_pv_type = $this->etva_pv->getStorageType();
     $etva_pv_device = $this->etva_pv->getDevice();
     $params = array('device' => $etva_pv_device, 'uuid' => $etva_pv_uuid);
     // check if physical volume is shared
     $shared = $this->etva_pv->getStorageType() != EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP;
     $etva_cluster = $etva_node->getEtvaCluster();
     $bulk_responses = array();
     if ($shared) {
         // call resize at all nodes
         $bulk_responses = $etva_cluster->soapSend($method, $params);
     } else {
         $node_id = $etva_node->getId();
         // call resize
         $bulk_responses[$node_id] = $etva_node->soapSend($method, $params);
     }
     // sync physical volumes size
     $errors = $this->send_update($etva_node);
     if (!empty($errors)) {
         $result = array('success' => false, 'errors' => $errors);
         $msg_i18n = Etva::makeNotifyLogMessage($etva_node->getName(), $msg_err_type, array('name' => $this->etva_pv->getName(), 'info' => ''));
         $result['error'] = $msg_i18n;
         return $result;
     } else {
         //notify system log
         $message = Etva::getLogMessage(array('name' => $this->etva_pv->getName()), $msg_ok_type);
         $msg_i18n = sfContext::getInstance()->getI18N()->__($msg_ok_type, array('%name%' => $this->etva_pv->getName()));
         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);
         return $result;
     }
 }
Exemple #4
0
 public function canAssignTo(EtvaNode $etva_node)
 {
     $nodes_toassign = $this->listNodesAssignTo();
     foreach ($nodes_toassign as $i => $node) {
         if ($etva_node->getId() == $node->getId()) {
             return true;
         }
     }
     return false;
 }