protected function execute($arguments = array(), $options = array()) { $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true)); parent::execute($arguments, $options); // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // add your code here $this->log('Checking shared storage cluster consistency...' . "\n"); $ok = 1; $affected = 0; $errors = array(); $clusters = EtvaClusterPeer::doSelect(new Criteria()); foreach ($clusters as $cluster) { $bulk_response_lvs = $cluster->soapSend('getlvs_arr', array('force' => 1)); $bulk_response_dtable = $cluster->soapSend('device_table'); $lv_va = new EtvaLogicalvolume_VA(); foreach ($bulk_response_lvs as $node_id => $node_response) { if ($node_response['success']) { //response received ok $lvs = (array) $node_response['response']; $node = EtvaNodePeer::retrieveByPK($node_id); //$consist = $lv_va->check_shared_consistency($node,$lvs); $response_dtable = (array) $bulk_response_dtable[$node_id]; $dtable = array(); if ($response_dtable['success']) { $dtable = (array) $response_dtable['response']; //$consist_dtable = $lv_va->check_shared_devicetable_consistency($node,$dtable,$bulk_response_dtable); } $check_res = $lv_va->check_consistency($node, $lvs, $dtable, $bulk_response_dtable); if (!$check_res['success']) { $err = $check_res['errors']; $msg = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => '')); $err_msg = sprintf(" node with id=%s is not consistent: %s \n", $node_id, $msg); $errors[] = array('message' => $err_msg, 'debug' => $err); $affected++; $node->setErrorMessage(EtvaLogicalvolume_VA::LVINIT); } else { $node->clearErrorMessage(EtvaLogicalvolume_VA::LVINIT); } /*if( !$consist || !$consist_dtable ){ $errors = $lv_va->get_missing_lv_devices(); $msg = $errors ? $errors['message'] : sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_,array('%info%'=>'')); $err_msg = sprintf( " node with id=%s is not consistent: %s \n", $node_id, $msg ); $errors[] = array( 'message'=> $err_msg, 'debug'=>array( 'consist_lvs'=>$consist, 'consist_dtable'=>$consist_dtable ) ); $affected++; $node->setErrorMessage(EtvaLogicalvolume_VA::LVINIT); } else { $node->clearErrorMessage(EtvaLogicalvolume_VA::LVINIT); }*/ } else { $errors[] = $node_response; $affected++; } } $bulk_response_pvs = $cluster->soapSend('hash_phydisks', array('force' => 1)); $pv_va = new EtvaPhysicalvolume_VA(); foreach ($bulk_response_pvs as $node_id => $node_response) { if ($node_response['success']) { //response received ok $pvs = (array) $node_response['response']; $node = EtvaNodePeer::retrieveByPK($node_id); $check_res = $pv_va->check_consistency($node, $pvs); if (!$check_res['success']) { $err = $check_res['errors']; $msg = sfContext::getInstance()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => '')); $err_msg = sprintf(" node with id=%s is not consistent: %s \n", $node_id, $msg); $errors[] = array('message' => $err_msg, 'debug' => $err); $affected++; $node->setErrorMessage(EtvaPhysicalvolume_VA::PVINIT); } else { $node->clearErrorMessage(EtvaPhysicalvolume_VA::PVINIT); } } else { $errors[] = $node_response; $affected++; } } $bulk_responses_vgs = $cluster->soapSend('getvgpvs', array('force' => 1)); $vg_va = new EtvaVolumegroup_VA(); foreach ($bulk_response_vgs as $node_id => $node_response) { if ($node_response['success']) { //response received ok $vgs = (array) $node_response['response']; $node = EtvaNodePeer::retrieveByPK($node_id); $check_res = $vg_va->check_consistency($node, $vgs); if (!$check_res['success']) { $err = $check_res['errors']; $msg = sfContext::getInstance()->getI18N()->__(EtvaVolumegroupPeer::_ERR_INCONSISTENT_, array('%info%' => '')); $err_msg = sprintf(" node with id=%s is not consistent: %s \n", $node_id, $msg); $errors[] = array('message' => $err_msg, 'debug' => $err); $affected++; $node->setErrorMessage(EtvaVolumegroup_VA::VGINIT); } else { $node->clearErrorMessage(EtvaVolumegroup_VA::VGINIT); } } else { $errors[] = $node_response; $affected++; } } } if (!empty($errors)) { $this->log($message); } else { // log the message! $this->log("The check shared storage cluster consistency task ran!", 6); } }
public function processRemoveResponse($etva_node, $response) { $etva_volgroup = $this->etva_vg; $vg = $etva_volgroup->getVg(); $ok = 1; if ($response['success']) { $response_decoded = (array) $response['response']; $returned_status = $response_decoded['_okmsg_']; $returned_object = (array) $response_decoded['_obj_']; // removes volgroup and updates physical volume info $vg_type = $etva_volgroup->getStorageType(); $pvs = (array) $returned_object[EtvaVolumegroup::PHYSICALVOLUMES_MAP]; $etva_volgroup->delete(); if ($vg_type != EtvaVolumegroup::STORAGE_TYPE_LOCAL_MAP) { //if vg remove send physical volumes update to other nodes to update physical volume device tag $pv = new EtvaPhysicalvolume_VA(); $bulk_update = $pv->send_update($etva_node); /* * if storage type not local send update to nodes... */ //$bulk_update = $this->send_update($etva_node); if (!empty($bulk_update)) { //$response = $bulk_update; $ok = 0; } } if ($ok) { $message = Etva::getLogMessage(array('name' => $vg), EtvaVolumegroupPeer::_OK_REMOVE_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($response['agent'], 'event.log', array('message' => $message))); $msg_i18n = sfContext::getInstance()->getI18N()->__(EtvaVolumegroupPeer::_OK_REMOVE_, array('%name%' => $vg)); $result = array('success' => true, 'agent' => $response['agent'], 'response' => $msg_i18n); return $result; } } else { $ok = 0; } // soap response error.... // DB information not updated if ($ok == 0) { $result = $response; if ($this->missing_vgs) { $errors = $this->missing_vgs; $names = array(); foreach ($errors as $node_id => $error_data) { $names[] = $error_data['name']; } $message = Etva::getLogMessage(array('info' => implode(', ', $names)), EtvaVolumegroupPeer::_ERR_INCONSISTENT_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $message, 'action' => 'reload', 'info' => $message); } else { $message = Etva::getLogMessage(array('name' => $vg, 'info' => $response['info']), EtvaVolumegroupPeer::_ERR_REMOVE_); $msg_i18n = sfContext::getInstance()->getI18N()->__(EtvaVolumegroupPeer::_ERR_REMOVE_, array('%name%' => $vg, '%info%' => $response['info'])); $result['error'] = $msg_i18n; sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($response['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $result; } } }
/** * Expanad the physical volume * * Expand size of physical volume, * * $request may contain the following keys: * - nid: virt agent node ID * - dev: device name Ex: /dev/sdb1 * * Returns json array('success'=>true,'response'=>$resp) on success * <br>or<br> * json array('success'=>false,'error'=>$error) on error * */ public function executeJsonExpand(sfWebRequest $request) { $nid = $request->getParameter('nid'); $dev = $request->getParameter('dev'); $etva_node = EtvaNodePeer::getOrElectNode($request); if (!$etva_node) { $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $nid)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); //notify system log $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_); $message = Etva::getLogMessage(array('name' => $dev, 'info' => $node_log), EtvaPhysicalvolumePeer::_ERR_UNINIT_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($error); } // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } // get DB info if (!($etva_pv = $etva_node->retrievePhysicalvolumeByDevice($dev))) { $msg = Etva::getLogMessage(array('name' => $etva_node->getName(), 'dev' => $dev), EtvaNodePeer::_ERR_NODEV_); $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NODEV_, array('%name%' => $etva_node->getName(), '%dev%' => $dev)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); //notify system log $message = Etva::getLogMessage(array('name' => $dev, 'info' => $msg), EtvaPhysicalvolumePeer::_ERR_UNINIT_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($error); } $error = $this->setJsonError($error); return $this->renderText($error); } /* * send physical volume to VA */ $pv_va = new EtvaPhysicalvolume_VA($etva_pv); $response = $pv_va->send_expand($etva_node); if ($response['success']) { $return = json_encode($response); // if the request is made throught soap request... if (sfConfig::get('sf_environment') == 'soap') { return $return; } // if is browser request return text renderer $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); } else { if (sfConfig::get('sf_environment') == 'soap') { return json_encode($response); } $return = $this->setJsonError($response); return $this->renderText($return); } }