public function register(EtvaNode $etva_node, $vg_info = null) { $etva_cluster = $etva_node->getEtvaCluster(); // check if volumegroup is shared $shared = $this->etva_vg->getStorageType() != EtvaVolumegroup::STORAGE_TYPE_LOCAL_MAP; // force to load volume groups $bulk_responses = array(); if ($shared) { $bulk_responses = $etva_cluster->soapSend(self::GET_SYNC_VOLUMEGROUPS, array('force' => 1)); } else { $node_id = $etva_node->getId(); $bulk_responses[$node_id] = $etva_node->soapSend(self::GET_SYNC_VOLUMEGROUPS, array('force' => 1)); } $vg_info_sync = $this->getVolumegroupInfo($etva_node, $bulk_responses); // merge vg info if ($vg_info_sync) { $vg_info = $vg_info ? array_merge($vg_info_sync, $vg_info) : $vg_info_sync; } // set vg info if needed if ($vg_info) { $this->etva_vg->initData($vg_info); } // for none local storage devices if ($shared) { // check if all nodes see that $check_res = $this->check_all_see_it($etva_node, $bulk_responses); if (!$check_res['success']) { return array('success' => false, 'errors' => $check_res['errors'], 'debug' => 'check_all_see_it'); } } $etva_volgroup = $this->etva_vg; // set cluster $etva_cluster = $etva_node->getEtvaCluster(); $etva_volgroup->setEtvaCluster($etva_cluster); // save it $etva_volgroup->save(); // create relation node_volumegorup $etva_node_volgroup = new EtvaNodeVolumegroup(); $etva_node_volgroup->setEtvaVolumegroup($etva_volgroup); $etva_node_volgroup->setEtvaNode($etva_node); $etva_node_volgroup->save(); if ($vg_info) { /* * associate pvs with vg and update info */ $pvs = isset($vg_info[EtvaVolumegroup::PHYSICALVOLUMES_MAP]) ? (array) $vg_info[EtvaVolumegroup::PHYSICALVOLUMES_MAP] : array(); foreach ($pvs as $pv => $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]; //error_log(sprintf("node name=%s id=%d device=%s uuid=%s type=%s",$etva_node->getName(),$etva_node->getId(),$pv_device,$pv_uuid,$pv_type)); //get physical volume based on node, type, uuid and device $etva_physical = EtvaPhysicalvolumePeer::retrieveByNodeTypeUUIDDevice($etva_node->getId(), $pv_type, $pv_uuid, $pv_device); if (!$etva_physical) { $etva_physical = new EtvaPhysicalvolume(); } $etva_physical->setEtvaCluster($etva_cluster); $etva_physical->initData($pv_info); $etva_physical->save(); $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(); } } // for no local storage type $errors = $this->sync_update($bulk_responses); if (!empty($errors)) { return array('success' => false, 'errors' => $errors); } // update logical volumes $lv_va = new EtvaLogicalvolume_VA(); $lv_errors = $lv_va->send_update($etva_node, true, $shared); if (!empty($lv_errors)) { return array('success' => false, 'errors' => $lv_errors); } return array('success' => true); }
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; } }
public function send_start(EtvaNode $etva_node, $extra = null, $ignoreAdmissionGate = false) { $etva_server = $this->etva_server; $method = self::SERVER_START; $mem_available = $etva_node->getMemfree(); $server_mem_mb = $etva_server->getMem(); $server_mem = Etva::MB_to_Byteconvert($server_mem_mb); error_log(" start_vm mem_available=" . $mem_available . " server_mem=" . $server_mem); if ($server_mem > $mem_available) { //notify event log $msg_i18n = Etva::makeNotifyLogMessage($error['agent'], EtvaNodePeer::_ERR_MEM_AVAILABLE_, array('name' => $etva_node->getName(), 'info' => $server_mem_mb), EtvaServerPeer::_ERR_START_, array('name' => $server)); $error = array('success' => false, 'agent' => $etva_node->getName(), 'info' => $msg_i18n, 'error' => $msg_i18n); return $error; } $etva_cluster = $etva_node->getEtvaCluster(); if (!$ignoreAdmissionGate && $etva_cluster->getHasNodeHA()) { $admissiongate_response = $etva_cluster->getAdmissionGate($etva_server); if (!$admissiongate_response['success']) { //notify event log $msg_i18n = Etva::makeNotifyLogMessage($error['agent'], EtvaClusterPeer::_ERR_ADMISSION_GATE_FAIL_, array('name' => $etva_server->getName(), 'info' => $admissiongate_response['info']), EtvaServerPeer::_ERR_START_, array('name' => $server)); $error = array('success' => false, 'agent' => $etva_node->getName(), 'info' => $msg_i18n, 'error' => $msg_i18n); return $error; } } $params = $extra ? $extra : array(); $params['uuid'] = $etva_server->getUuid(); $boot = $etva_server->getBoot(); $location = $etva_server->getLocation(); $vm_type = $etva_server->getVmType(); $first_boot = $etva_server->getFirstBoot(); if ($first_boot) { $params['first_boot'] = $first_boot; if ($location && $vm_type == 'pv') { $boot = 'location'; } } $params['boot'] = $boot; if ($boot == 'location' || $boot == 'cdrom') { $params['location'] = $location; } $params['vnc_keymap'] = $etva_server->getVncKeymap(); $response = $etva_node->soapSend($method, $params); return $this->processStartStop($etva_node, $response, $method); }