コード例 #1
0
 public function check_consistency(EtvaNode $etva_node, $sync_node_vgs)
 {
     $errors = array();
     $etva_node->getId();
     $etva_cluster = $etva_node->getEtvaCluster();
     // get node database VGs
     $node_vgs = $etva_node->getEtvaNodeVolumegroups();
     // get shared database VGs
     $shared_vgs = $etva_cluster->getSharedVgs();
     $node_inconsistent = 0;
     foreach ($node_vgs as $rvg) {
         $vg = $rvg->getEtvaVolumegroup();
         $error = array();
         $uuid = $vg->getUuid();
         $vgname = $vg->getVg();
         // init
         $inconsistent = 0;
         // look at volume groups list
         $found_lvm = 0;
         foreach ($sync_node_vgs as $hvg) {
             $arr_hvg = (array) $hvg;
             if ($arr_hvg[EtvaVolumegroup::STORAGE_TYPE_MAP] == $vg->getStorageType()) {
                 if (isset($arr_hvg[EtvaVolumegroup::UUID_MAP])) {
                     if ($arr_hvg[EtvaVolumegroup::UUID_MAP] == $uuid) {
                         $found_lvm = 1;
                     }
                 } else {
                     if ($arr_hvg[EtvaVolumegroup::VG_MAP] == $vgname) {
                         $found_lvm = 1;
                     }
                 }
             }
         }
         $inconsistent = $inconsistent || !$found_lvm;
         if (!$found_lvm) {
             $error['not_found_lvm'] = 1;
         }
         $found_shared_lvm = 0;
         $inconsistent_shared_vgs = 0;
         foreach ($shared_vgs as $s_vg) {
             $s_uuid = $s_vg->getUuid();
             if ($s_uuid == $uuid) {
                 if ($s_vg->getStorageType() != $vg->getStorageType()) {
                     $inconsistent_shared_vgs = 1;
                 } else {
                     $found_shared_lvm = 1;
                 }
             } else {
                 if ($s_vg->getStorageType() == $vg->getStorageType()) {
                     if ($arr_hvg[EtvaVolumegroup::VG_MAP] == $vgname) {
                         $found_shared_lvm = 1;
                     }
                 }
             }
         }
         if ($vg->getStorageType() != EtvaVolumegroup::STORAGE_TYPE_LOCAL_MAP) {
             $inconsistent = $inconsistent || !$found_shared_lvm;
             if (!$found_shared_lvm) {
                 $error['not_found_shared_lvm'] = 1;
             }
         }
         $inconsistent = $inconsistent || $inconsistent_shared_vgs;
         if ($inconsistent_shared_vgs) {
             $error['diff_storage_type'] = 1;
         }
         // update data-base
         $etva_volumegroup = EtvaVolumegroupPeer::retrieveByNodeTypeUUIDVg($etva_node->getId(), $vg->getStorageType(), $vg->getUuid(), $vg->getVg());
         if ($etva_volumegroup) {
             $etva_volumegroup->setInconsistent($inconsistent);
             $etva_volumegroup->save();
         }
         $etva_node_volumegroup = EtvaNodeVolumegroupPeer::retrieveByPK($etva_node->getId(), $vg->getId());
         if ($etva_node_volumegroup) {
             $etva_node_volumegroup->setInconsistent($inconsistent);
             $etva_node_volumegroup->save();
         }
         if ($inconsistent) {
             $message = sfContext::getInstance()->getI18N()->__(EtvaVolumegroupPeer::_ERR_INCONSISTENT_, array('%info%' => sprintf('volume group "%s" with uuid "%s"', $vg->getVg(), $vg->getUuid())));
             if ($error['not_found_shared_lvm'] || $error['diff_storage_type']) {
                 $message = sfContext::getInstance()->getI18N()->__(EtvaVolumegroupPeer::_ERR_SHARED_INCONSISTENT_, array('%info%' => sprintf('volume group "%s" with uuid "%s"', $vg->getVg(), $vg->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['volumegroup'] = $vg->getVg();
             $error['uuid'] = $vg->getUuid();
             $error['message'] = $message;
         }
         if (!empty($error)) {
             $errors[] = $error;
         }
         $node_inconsistent = $node_inconsistent || $inconsistent;
     }
     // check consistency for shared Volume groups
     foreach ($shared_vgs as $vg) {
         $error = array();
         $uuid = $vg->getUuid();
         $vgname = $vg->getVg();
         // init
         $inconsistent = 0;
         // look at physical volumes list
         $found_lvm = 0;
         foreach ($sync_node_vgs as $hvg) {
             $arr_hvg = (array) $hvg;
             if ($arr_hvg[EtvaVolumegroup::STORAGE_TYPE_MAP] == $vg->getStorageType()) {
                 if (isset($arr_hvg[EtvaVolumegroup::UUID_MAP])) {
                     if ($arr_hvg[EtvaVolumegroup::UUID_MAP] == $uuid) {
                         $found_lvm = 1;
                     }
                 } else {
                     if ($arr_hvg[EtvaVolumegroup::VG_MAP] == $vgname) {
                         $found_lvm = 1;
                     }
                 }
             }
         }
         $inconsistent = $inconsistent || !$found_lvm;
         if (!$found_lvm) {
             $error['not_found_lvm'] = 1;
         }
         // update data-base
         $etva_volumegroup = EtvaVolumegroupPeer::retrieveByNodeTypeUUIDVg($etva_node->getId(), $vg->getStorageType(), $vg->getUuid(), $vg->getVg());
         if ($etva_volumegroup) {
             $etva_volumegroup->setInconsistent($inconsistent);
             $etva_volumegroup->save();
         }
         $etva_node_volumegroup = EtvaNodeVolumegroupPeer::retrieveByPK($etva_node->getId(), $vg->getId());
         if ($etva_node_volumegroup) {
             $etva_node_volumegroup->setInconsistent($inconsistent);
             $etva_node_volumegroup->save();
         }
         if ($inconsistent) {
             $message = sfContext::getInstance()->getI18N()->__(EtvaVolumegroupPeer::_ERR_SHARED_INCONSISTENT_, array('%info%' => sprintf('volumegroup "%s" with uuid "%s"', $vg->getVg(), $vg->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['volumegroup'] = $vg->getVg();
             $error['uuid'] = $vg->getUuid();
             $error['message'] = $message;
         }
         if (!empty($error)) {
             $errors[] = $error;
         }
         $node_inconsistent = $node_inconsistent || $inconsistent;
     }
     $return = array();
     if ($node_inconsistent) {
         $etva_node->setErrorMessage(self::VGINIT);
         $return = array('success' => false, 'errors' => $errors);
     } else {
         $etva_node->clearErrorMessage(self::VGINIT);
         $return = array('success' => true);
     }
     return $return;
 }