public function initialize(EtvaNode $etva_node, $vgs, $force_regist = false) { $etva_cluster = $etva_node->getEtvaCluster(); $volumegroup_names = array(); $errors = array(); /* * check shared vgs consistency */ $check_res = $this->check_consistency($etva_node, $vgs); if (!$check_res['success']) { $errors = $check_res['errors']; $inconsistent_message = Etva::getLogMessage(array('info' => ''), EtvaVolumegroupPeer::_ERR_INCONSISTENT_); $etva_node->setErrorMessage(self::VGINIT); $message = Etva::getLogMessage(array('info' => $inconsistent_message), EtvaVolumegroupPeer::_ERR_SOAPUPDATE_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); //return array('success'=>false,'error'=>$errors); } /*$consist = $this->check_shared_consistency($etva_node,$vgs); if(!$consist){ $errors = $this->missing_vgs[$etva_node->getId()]; $inconsistent_message = Etva::getLogMessage(array('info'=>''), EtvaVolumegroupPeer::_ERR_INCONSISTENT_); $etva_node->setErrorMessage(self::VGINIT); $message = Etva::getLogMessage(array('info'=>$inconsistent_message), EtvaVolumegroupPeer::_ERR_SOAPUPDATE_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(),'event.log',array('message' =>$message,'priority'=>EtvaEventLogger::ERR))); return array('success'=>false,'error'=>$errors); }*/ foreach ($vgs as $vgInfo) { $vg_info = (array) $vgInfo; $vg_name = $vg_info[EtvaVolumegroup::VG_MAP]; $vg_type = $vg_info[EtvaVolumegroup::STORAGE_TYPE_MAP]; //error_log(sprintf("node name=%s id=%d vg_name=%s uuid=%s type=%s",$etva_node->getName(),$etva_node->getId(),$vg_name,$vg_info[EtvaVolumegroup::UUID_MAP],$vg_type)); //error_log(print_r($vg_info,true)); if ($vg_type == EtvaVolumegroup::STORAGE_TYPE_LOCAL_MAP) { $etva_volgroup = EtvaVolumegroupPeer::retrieveByNodeTypeVg($etva_node->getId(), $vg_type, $vg_name); } else { $vg_uuid = $vg_info[EtvaVolumegroup::UUID_MAP]; $etva_volgroup = EtvaVolumegroupPeer::retrieveByUUID($vg_uuid); } if ($force_regist && !$etva_volgroup) { // no vg in db... and force registration ... so create new one $etva_node_volgroup = new EtvaNodeVolumegroup(); $etva_volgroup = new EtvaVolumegroup(); } else { if ($etva_volgroup) { //if vg already in DB we need to make sure if already exists association with node. if not create new one $etva_node_volgroup = EtvaNodeVolumegroupPeer::retrieveByPK($etva_node->getId(), $etva_volgroup->getId()); if (!$etva_node_volgroup) { $etva_node_volgroup = new EtvaNodeVolumegroup(); } } } if ($etva_volgroup) { // only if vg in db... $etva_volgroup->initData($vg_info); $etva_volgroup->setEtvaCluster($etva_cluster); $etva_node_volgroup->setEtvaVolumegroup($etva_volgroup); $etva_node_volgroup->setEtvaNode($etva_node); $etva_node_volgroup->save(); /* * associate pvs with vg */ $pvs = isset($vg_info[EtvaVolumegroup::PHYSICALVOLUMES_MAP]) ? (array) $vg_info[EtvaVolumegroup::PHYSICALVOLUMES_MAP] : array(); foreach ($pvs as $pvInfo) { $pv_info = (array) $pvInfo; $pv_type = $pv_info[EtvaPhysicalvolume::STORAGE_TYPE_MAP]; $pv_uuid = isset($pv_info[EtvaPhysicalvolume::UUID_MAP]) ? $pv_info[EtvaPhysicalvolume::UUID_MAP] : ''; $pv_device = $pv_info[EtvaPhysicalvolume::DEVICE_MAP]; //get physical volume based on node, type, uuid and device $etva_physical = EtvaPhysicalvolumePeer::retrieveByNodeTypeUUIDDevice($etva_node->getId(), $pv_type, $pv_uuid, $pv_device); $etva_node_physical = EtvaNodePhysicalvolumePeer::retrieveByPK($etva_node->getId(), $etva_physical->getId()); if (!$etva_node_physical) { $etva_node_physical = new EtvaNodePhysicalvolume(); $etva_node_physical->setEtvaPhysicalvolume($etva_physical); $etva_node_physical->setEtvaNode($etva_node); } $etva_node_physical->setDevice($pv_device); $etva_node_physical->save(); $etva_volgroup_physical = EtvaVolumePhysicalPeer::retrieveByPK($etva_volgroup->getId(), $etva_physical->getId()); if (!$etva_volgroup_physical) { $etva_volgroup_physical = new EtvaVolumePhysical(); } $etva_volgroup_physical->setEtvaPhysicalvolume($etva_physical); $etva_volgroup_physical->setEtvaVolumegroup($etva_volgroup); $etva_volgroup_physical->save(); } $volumegroup_names[] = $etva_volgroup->getVg(); } } 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_VGS); } $etva_node->clearErrorMessage(self::VGINIT); $message = Etva::getLogMessage(array('info' => implode(', ', $volumegroup_names)), EtvaVolumegroupPeer::_OK_SOAPUPDATE_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message))); return array('success' => true, 'response' => $volumegroup_names); } }
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; }