public function check_consistency(EtvaNode $etva_node, $sync_node_pvs) { $errors = array(); $etva_node->getId(); $etva_cluster = $etva_node->getEtvaCluster(); // get node database PVs //$node_pvs = $etva_node->getEtvaPhysicalvolumes(); $node_pvs = $etva_node->getEtvaNodePhysicalvolumes(); // get shared database PVs $shared_pvs = $etva_cluster->getSharedPvs(); $node_inconsistent = 0; foreach ($node_pvs as $rpv) { $pv = $rpv->getEtvaPhysicalvolume(); $error = array(); $uuid = $pv->getUuid(); $device = $pv->getDevice(); // init $inconsistent = 0; // look at physical volumes list $found_lvm = 0; foreach ($sync_node_pvs as $hpv) { $arr_hpv = (array) $hpv; if ($arr_hpv[EtvaPhysicalvolume::STORAGE_TYPE_MAP] == $pv->getStorageType()) { if (isset($arr_hpv[EtvaPhysicalvolume::UUID_MAP])) { if ($arr_hpv[EtvaPhysicalvolume::UUID_MAP] == $uuid) { $found_lvm = 1; } } else { if ($arr_hpv[EtvaPhysicalvolume::DEVICE_MAP] == $device) { $found_lvm = 1; } } } } $inconsistent = $inconsistent || !$found_lvm; if (!$found_lvm) { $error['not_found_lvm'] = 1; } /* TODO * check when have multipath */ $found_shared_lvm = 0; $inconsistent_shared_pvs = 0; foreach ($shared_pvs as $s_pv) { $s_uuid = $s_pv->getUuid(); $s_device = $s_pv->getDevice(); if ($s_uuid == $uuid) { if ($s_pv->getStorageType() != $pv->getStorageType()) { $inconsistent_shared_pvs = 1; } else { $found_shared_lvm = 1; } } else { if ($s_pv->getStorageType() == $pv->getStorageType()) { if ($arr_hpv[EtvaPhysicalvolume::DEVICE_MAP] == $device) { $found_shared_lvm = 1; } } } } if ($pv->getStorageType() != EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP) { $inconsistent = $inconsistent || !$found_shared_lvm; if (!$found_shared_lvm) { $error['not_found_shared_lvm'] = 1; } } $inconsistent = $inconsistent || $inconsistent_shared_pvs; if ($inconsistent_shared_pvs) { $error['diff_storage_type'] = 1; } // update data-base $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeUUIDDevice($etva_node->getId(), $pv->getStorageType(), $pv->getUuid(), $pv->getDevice()); if ($etva_physicalvol) { $etva_physicalvol->setInconsistent($inconsistent); $etva_physicalvol->save(); } $etva_node_physicalvol = EtvaNodePhysicalvolumePeer::retrieveByPK($etva_node->getId(), $pv->getId()); if ($etva_node_physicalvol) { $etva_node_physicalvol->setInconsistent($inconsistent); $etva_node_physicalvol->save(); } if ($inconsistent) { $message = sfContext::getInstance()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => sprintf('device "%s" with uuid "%s"', $pv->getDevice(), $pv->getUuid()))); if ($error['not_found_shared_lvm'] || $error['diff_storage_type']) { $message = sfContext::getInstance()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_SHARED_INCONSISTENT_, array('%info%' => sprintf('device "%s" with uuid "%s"', $pv->getDevice(), $pv->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'] = $pv->getDevice(); $error['device_id'] = $pv->getId(); $error['uuid'] = $pv->getUuid(); $error['message'] = $message; } if (!empty($error)) { $errors[] = $error; } $node_inconsistent = $node_inconsistent || $inconsistent; } // check consistency for shared PVs foreach ($shared_pvs as $pv) { $error = array(); $uuid = $pv->getUuid(); $device = $pv->getDevice(); // init $inconsistent = 0; // look at physical volumes list $found_lvm = 0; foreach ($sync_node_pvs as $hpv) { $arr_hpv = (array) $hpv; if ($arr_hpv[EtvaPhysicalvolume::STORAGE_TYPE_MAP] == $pv->getStorageType()) { if (isset($arr_hpv[EtvaPhysicalvolume::UUID_MAP])) { if ($arr_hpv[EtvaPhysicalvolume::UUID_MAP] == $uuid) { $found_lvm = 1; } } else { if ($arr_hpv[EtvaPhysicalvolume::DEVICE_MAP] == $device) { $found_lvm = 1; } } } } $inconsistent = $inconsistent || !$found_lvm; if (!$found_lvm) { $error['not_found_lvm'] = 1; } /* TODO * check when have multipath */ // update data-base $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeUUIDDevice($etva_node->getId(), $pv->getStorageType(), $pv->getUuid(), $pv->getDevice()); if ($etva_physicalvol) { $etva_physicalvol->setInconsistent($inconsistent); $etva_physicalvol->save(); } $etva_node_physicalvol = EtvaNodePhysicalvolumePeer::retrieveByPK($etva_node->getId(), $pv->getId()); if ($etva_node_physicalvol) { $etva_node_physicalvol->setInconsistent($inconsistent); $etva_node_physicalvol->save(); } if ($inconsistent) { $message = sfContext::getInstance()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_SHARED_INCONSISTENT_, array('%info%' => sprintf('device "%s" with uuid "%s"', $pv->getDevice(), $pv->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'] = $pv->getDevice(); $error['device_id'] = $pv->getId(); $error['uuid'] = $pv->getUuid(); $error['message'] = $message; } if (!empty($error)) { $errors[] = $error; } $node_inconsistent = $node_inconsistent || $inconsistent; } $return = array(); if ($node_inconsistent) { $etva_node->setErrorMessage(self::PVINIT); $return = array('success' => false, 'errors' => $errors); } else { $etva_node->clearErrorMessage(self::PVINIT); $return = array('success' => true); } return $return; //($node_inconsistent) ? false : true; }