public function setPhysicalvolumes($v) { if (!($etva_cluster = $this->getEtvaCluster())) { return; } $list = array($v); $criteria = new Criteria(); $criteria->add(EtvaPhysicalvolumePeer::CLUSTER_ID, $etva_cluster->getId()); $etva_volphys = $this->getEtvaVolumePhysicals(); $etva_phys_uuid = array(); if ($etva_volphys) { foreach ($etva_volphys as $etva_volphy) { $etva_phy = $etva_volphy->getEtvaPhysicalvolume(); $etva_phys_uuid[$etva_phy->getUuid()] = $etva_phy; } } foreach ($v as $pv => $device) { $device_array = (array) $device; $dev_uuid = $device_array['uuid']; if (in_array($dev_uuid, array_keys($etva_phys_uuid))) { $etva_physicalvol = $etva_phys_uuid[$dev_uuid]; } else { $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByUUID($dev_uuid, $criteria); } $etva_physicalvol->initData($device_array); if ($etva_physicalvol) { $this->physicalvolumes[] = $etva_physicalvol; } } return $this; }
public function getSharedPvs() { /* * * get shared pvs of defined cluster. */ $criteria = new Criteria(); $criteria->add(EtvaClusterPeer::ID, $this->getId()); $criteria->addJoin(EtvaPhysicalvolumePeer::CLUSTER_ID, EtvaClusterPeer::ID); $criteria->add(EtvaPhysicalvolumePeer::STORAGE_TYPE, EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP, Criteria::ALT_NOT_EQUAL); $etva_shared_pvs = EtvaPhysicalvolumePeer::doSelect($criteria); return $etva_shared_pvs; }
public function clearStorage() { $c = new Criteria(); $c->add(EtvaNodeLogicalvolumePeer::NODE_ID, $this->getId()); EtvaLogicalvolumePeer::doDelete($c); $c = new Criteria(); $c->add(EtvaNodeVolumegroupPeer::NODE_ID, $this->getId()); EtvaVolumegroupPeer::doDelete($c); $c = new Criteria(); $c->add(EtvaNodePhysicalvolumePeer::NODE_ID, $this->getId()); EtvaPhysicalvolumePeer::doDelete($c); }
public static function getOrElectNodeFromArray($arguments) { // get parameters $nid = isset($arguments['node']) ? $arguments['node'] : null; $cid = isset($arguments['cluster']) ? $arguments['cluster'] : null; $level = isset($arguments['level']) ? $arguments['level'] : null; $vg = isset($arguments['volumegroup']) ? $arguments['volumegroup'] : null; $dev = isset($arguments['device']) ? $arguments['device'] : null; $lv = isset($arguments['logicalvolume']) ? $arguments['logicalvolume'] : null; // check level - back compatibility if (!$level) { $level = 'node'; } if ($level == 'cluster') { $etva_cluster = EtvaClusterPeer::retrieveByPK($cid); return EtvaNode::getFirstActiveNode($etva_cluster); } elseif ($level == 'node') { $etva_node = EtvaNodePeer::retrieveByPK($nid); if ($lv) { $c = new Criteria(); $c->add(EtvaLogicalvolumePeer::STORAGE_TYPE, EtvaLogicalvolume::STORAGE_TYPE_LOCAL_MAP, Criteria::ALT_NOT_EQUAL); $etva_lv = EtvaLogicalvolumePeer::retrieveByLv($lv, $c); return $etva_lv ? EtvaNodePeer::ElectNode($etva_node) : $etva_node; } elseif ($dev) { $c = new Criteria(); $c->add(EtvaPhysicalvolumePeer::STORAGE_TYPE, EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP, Criteria::ALT_NOT_EQUAL); $etva_pv = EtvaPhysicalvolumePeer::retrieveByDevice($dev, $c); return $etva_pv ? EtvaNodePeer::ElectNode($etva_node) : $etva_node; } elseif ($vg) { $c = new Criteria(); $c->add(EtvaVolumeGroupPeer::STORAGE_TYPE, EtvaVolumeGroup::STORAGE_TYPE_LOCAL_MAP, Criteria::ALT_NOT_EQUAL); $etva_vg = EtvaVolumegroupPeer::retrieveByVg($vg, $c); return $etva_vg ? EtvaNodePeer::ElectNode($etva_node) : $etva_node; } else { return $etva_node; } } }
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); }
private function check_pvs(EtvaNode $etva_node) { $node_response = $etva_node->soapSend('getpvs_arr', array('force' => 1)); if (!$node_response['success']) { $errors = $node_response['error']; Etva::getLogMessage(array('info' => ''), EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_); //$etva_node->setErrorMessage(EtvaPhysicalvolume_VA::LVINIT); $message = $this->getContext()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_SOAPUPDATE_, array('%info%' => $node_response['info'])); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); $response = array('success' => false, 'error' => $message, 'agent' => $etva_node->getName()); $return = $this->setJsonError($response); return $this->renderText($return); } //verify if cluster has any logical volume that belongs to another cluster... $cluster_id = $etva_node->getClusterId(); $my_pvs = $node_response['response']; $my_pvs = (array) $my_pvs; foreach ($my_pvs as $my_pv) { $pv_info = (array) $my_pv; if ($pv_info['type'] == EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP) { continue; } $c_uuid = new criteria(); $c_uuid->add(EtvaPhysicalvolumePeer::UUID, $pv_info['uuid']); $c_uuid->addAnd(EtvaPhysicalvolumePeer::CLUSTER_ID, $cluster_id, Criteria::NOT_EQUAL); $e_pv = EtvaPhysicalvolumePeer::doSelectOne($c_uuid); if ($e_pv) { $c_c = new Criteria(); $c_c->add(EtvaClusterPeer::ID, $e_pv->getClusterId()); $etva_cluster = EtvaClusterPeer::doSelectOne($c_c); $msg_i18n = $this->getContext()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_INIT_OTHER_CLUSTER_, array('%name%' => $etva_cluster->getName())); $response = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); $return = $this->setJsonError($response); return $this->renderText($return); } } }
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; }
/** * Return pre-formatted data for tree-column extjs * * $request may contain the following keys: * - nid: nid (virtAgent node ID) * @return array json array */ public function executeJsonClusterVgsTree(sfWebRequest $request) { $cluster_id = $request->getParameter('cid'); $criteria = new Criteria(); $criteria->add(EtvaVolumeGroupPeer::CLUSTER_ID, $cluster_id); $criteria->addAnd(EtvaVolumeGroupPeer::STORAGE_TYPE, EtvaVolumeGroup::STORAGE_TYPE_LOCAL_MAP, Criteria::ALT_NOT_EQUAL); $cluster_vgs = EtvaVolumeGroupPeer::doSelect($criteria); // $criteria->add(EtvaNodeVolumeGroupPeer::NODE_ID,$request->getParameter('nid')); // $node_vgs = EtvaNodeVolumeGroupPeer::doSelectJoinEtvaVolumegroup($criteria); $volumes = array(); foreach ($cluster_vgs as $vg) { // $node_id = $data->getNodeId(); // $vg = $data->getEtvaVolumegroup(); $pvs_tree = array(); $etva_vp = $vg->getEtvaVolumePhysicals(); foreach ($etva_vp as $vp) { $pv = $vp->getEtvaPhysicalvolume(); if ($pv) { $id = $pv->getId(); $c_criteria = new Criteria(); $c_criteria->add(EtvaPhysicalvolumePeer::ID, $id); $c_criteria->add(EtvaPhysicalvolumePeer::CLUSTER_ID, $cluster_id); $np = EtvaPhysicalvolumePeer::doSelectOne($c_criteria); // $np = EtvaNodePhysicalvolumePeer::retrieveByPK($node_id, $id); //AKII $elem = $np->getDevice(); $pvdevice = $pv->getPv(); $pretty_size = $size = $pv->getPvsize(); $qtip = ''; $cls = 'dev-pv'; $pvs_tree[] = array('id' => $id, 'cls' => $cls, 'iconCls' => 'task', 'text' => $elem, 'pv' => $pvdevice, 'size' => $size, 'prettysize' => $pretty_size, 'singleClickExpand' => true, 'type' => 'dev-pv', 'qtip' => $qtip, 'leaf' => true); } } $id = $vg->getVg(); $vgid = $vg->getId(); $qtip = ''; $cls = 'vg'; $pretty_size = $size = $vg->getSize(); $free_size = $vg->getFreesize(); $expanded = empty($pvs_tree) ? true : false; $type = $vg->getStorageType(); $is_DiskVG = $id == sfConfig::get('app_volgroup_disk_flag') ? 1 : 0; if ($is_DiskVG) { $type = 'file'; } /* TODO improve this */ if ($vg->getInconsistent()) { $qtip .= ' [INCONSISTENT]'; $cls = 'vg-inc'; } $inuse = $vg->hasLogicalVolumesInUse(); $volumes[] = array('id' => $id, 'expanded' => $expanded, 'vgid' => $vgid, 'iconCls' => 'devices-folder', 'cls' => $cls, 'text' => $id, 'type' => $type, 'size' => $size, 'prettysize' => $pretty_size, 'freesize' => $free_size, 'singleClickExpand' => true, 'qtip' => $qtip, 'children' => $pvs_tree, 'inuse' => $inuse); } if (empty($volumes)) { $msg_i18n = $this->getContext()->getI18N()->__('No data found'); $volumes[] = array('expanded' => true, 'text' => $msg_i18n, 'qtip' => $msg_i18n, 'leaf' => true); } $return = json_encode($volumes); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); }
public function executeJsonListAllocatable(sfWebRequest $request) { $elements = array(); //adding cluster id filter $cid = $request->getParameter('cid'); $nid = $request->getParameter('nid'); $level = $request->getParameter('level'); if (!$level) { $level = 'node'; } //get the $filter = json_decode($request->getParameter('filter'), true); $criteria = new Criteria(); $criteria->add(EtvaPhysicalvolumePeer::ALLOCATABLE, 1); $criteria->add(EtvaPhysicalvolumePeer::PVINIT, 1); foreach ($filter as $field => $value) { $column = EtvaPhysicalvolumePeer::translateFieldName(sfInflector::camelize($field), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); $criteria->add($column, $value); } if ($level == 'cluster') { $etva_cluster = EtvaClusterPeer::retrieveByPK($cid); $etva_pvs = $etva_cluster->getEtvaPhysicalvolumes($criteria); } elseif ($level == 'node') { $etva_node = EtvaNodePeer::retrieveByPK($nid); $etva_pvs = $etva_node->getEtvaNodePhysicalVolumesJoinEtvaPhysicalvolume($criteria); } else { return; } if (!$etva_pvs) { $msg_i18n = $this->getContext()->getI18N()->__(EtvaPhysicalvolumePeer::_NONE_AVAILABLE_); $info = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => $msg_i18n, 'error' => $msg_i18n); if (sfConfig::get('sf_environment') == 'soap') { return json_encode($info); } $error = $this->setJsonError($info); return $this->renderText($error); } if (sfConfig::get('sf_environment') == 'soap') { foreach ($etva_pvs as $elem) { $etva_pv = $elem->getEtvaPhysicalVolume(); $uuid = $etva_pv->getUuid(); $id = $etva_pv->getId(); $name = $etva_pv->getName(); $pv = $etva_pv->getPv(); $elements[$id] = array('id' => $id, 'pv' => $pv, 'name' => $name, 'uuid' => $uuid); } } else { foreach ($etva_pvs as $elem) { if ($level == 'node') { $etva_pv = $elem->getEtvaPhysicalVolume(); } elseif ($level == 'cluster') { $etva_pv = $elem; } $uuid = $etva_pv->getUuid(); $id = $etva_pv->getId(); $name = $etva_pv->getName(); $pv = $etva_pv->getPv(); $elements[] = array('id' => $id, 'pv' => $pv, 'name' => $name, 'uuid' => $uuid); } } $result = array('success' => true, 'total' => count($elements), 'response' => $elements); $return = json_encode($result); if (sfConfig::get('sf_environment') == 'soap') { return $return; } $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); }