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);
 }
Example #2
0
 public function get_sync_diskdevices($force_sync = false, $sharedonly = false)
 {
     $elements = array();
     $db_node_devs = EtvaPhysicalvolumeQuery::create()->useEtvaNodePhysicalVolumeQuery()->filterByNodeId($this->etva_node->getId())->endUse()->useEtvaVolumePhysicalQuery('volphy', 'LEFT JOIN')->useEtvaVolumegroupQuery('volgroup', 'LEFT JOIN')->endUse()->endUse()->withColumn('volgroup.Vg', 'Vg')->find();
     $force_flag = $force_sync ? 1 : 0;
     $response_devs = $this->etva_node->soapSend(EtvaPhysicalvolume_VA::GET_SYNC_DISKDEVICES, array('force' => $force_flag));
     if ($response_devs['success']) {
         $devs = $response_devs['response'];
         foreach ($devs as $k => $e) {
             $dev = (array) $e;
             if (!$sharedonly || $dev[EtvaPhysicalvolume::STORAGE_TYPE_MAP] != EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP) {
                 $found = false;
                 foreach ($db_node_devs as $pv) {
                     if ($dev[EtvaPhysicalvolume::STORAGE_TYPE_MAP] == $pv->getStorageType()) {
                         if ($pv->getUuid() && $dev[EtvaPhysicalvolume::UUID_MAP]) {
                             if ($pv->getUuid() == $dev[EtvaPhysicalvolume::UUID_MAP]) {
                                 $found = true;
                             }
                         } else {
                             if ($pv->getDevice() == $dev[EtvaPhysicalvolume::DEVICE_MAP]) {
                                 $found = true;
                             }
                         }
                     }
                 }
                 $etva_pv = new EtvaPhysicalvolume();
                 $etva_pv->initData($dev);
                 $arr_e = $etva_pv->_VA();
                 $arr_e[EtvaPhysicalvolume::VG_MAP] = $dev[EtvaPhysicalvolume::VG_MAP];
                 $arr_e['registered'] = $found;
                 $elements[] = $arr_e;
             }
         }
     }
     foreach ($db_node_devs as $pv) {
         if (!$sharedonly || $pv->getStorageType() != EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP) {
             $found = false;
             foreach ($devs as $k => $e) {
                 $dev = (array) $e;
                 if ($dev[EtvaPhysicalvolume::STORAGE_TYPE_MAP] == $pv->getStorageType()) {
                     if ($pv->getUuid() && $dev[EtvaPhysicalvolume::UUID_MAP]) {
                         if ($pv->getUuid() == $dev[EtvaPhysicalvolume::UUID_MAP]) {
                             $found = true;
                         }
                     } else {
                         if ($pv->getDevice() == $dev[EtvaPhysicalvolume::DEVICE_MAP]) {
                             $found = true;
                         }
                     }
                 }
             }
             if (!$found) {
                 $arr_e = $pv->_VA();
                 $arr_e['inconsistent'] = true;
                 $arr_e['registered'] = true;
                 $arr_e[EtvaPhysicalvolume::VG_MAP] = $pv->getVg();
                 $elements[] = $arr_e;
             }
         }
     }
     return $elements;
 }
 public function initialize(EtvaNode $etva_node, $devs, $force_regist = false)
 {
     $etva_cluster = $etva_node->getEtvaCluster();
     $volumegroup_names = array();
     $errors = array();
     /*
      * check shared vgs consistency (applies only for enterprise)
      */
     $etva_data = Etva::getEtvaModelFile();
     /*$etvamodel = $etva_data['model'];
       $consist = 1;
       if($etvamodel != 'standard') $consist = $this->check_shared_consistency($etva_node,$devs);*/
     $check_res = $this->check_consistency($etva_node, $devs);
     if (!$check_res['success']) {
         $errors = $check_res['errors'];
         $inconsistent_message = Etva::getLogMessage(array('info' => ''), EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_);
         $etva_node->setErrorMessage(self::PVINIT);
         $message = Etva::getLogMessage(array('info' => $inconsistent_message), EtvaPhysicalvolumePeer::_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);
     }
     /*if(!$consist){
                 $errors = $this->missing_pvs[$etva_node->getId()];
     
                 $inconsistent_message = Etva::getLogMessage(array('info'=>''), EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_);
     
                 $etva_node->setErrorMessage(self::PVINIT);
     
                 $message = Etva::getLogMessage(array('info'=>$inconsistent_message), EtvaPhysicalvolumePeer::_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);
             }*/
     $physical_names = array();
     foreach ($devs as $dev => $devInfo) {
         $dev_info = (array) $devInfo;
         $dev_type = $dev_info[EtvaPhysicalvolume::STORAGE_TYPE_MAP];
         $dev_device = $dev_info[EtvaPhysicalvolume::DEVICE_MAP];
         //error_log(sprintf("node name=%s id=%d device=%s uuid=%s type=%s",$etva_node->getName(),$etva_node->getId(),$dev_device,$dev_info[EtvaPhysicalvolume::UUID_MAP],$dev_type));
         if ($dev_type == EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP) {
             $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeDevice($etva_node->getId(), $dev_type, $dev_device);
         } else {
             if (isset($dev_info[EtvaPhysicalvolume::UUID_MAP])) {
                 $dev_uuid = $dev_info[EtvaPhysicalvolume::UUID_MAP];
                 $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByUUID($dev_uuid);
             } else {
                 $dev_info[EtvaPhysicalvolume::UUID_MAP] = '';
                 // clean uuid
                 $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeDevice($etva_node->getId(), $dev_type, $dev_device);
             }
             if (!$etva_physicalvol) {
                 $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeDevice($etva_node->getId(), $dev_type, $dev_device);
             }
             if (!$etva_physicalvol) {
                 $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByClusterTypeUUIDDevice($etva_node->getClusterId(), $dev_type, $dev_info[EtvaPhysicalvolume::UUID_MAP], $dev_device);
             }
         }
         if ($force_regist && !$etva_physicalvol) {
             // no pv in db... and force registration ... so create new one
             $etva_node_physicalvol = new EtvaNodePhysicalvolume();
             $etva_physicalvol = new EtvaPhysicalvolume();
         } else {
             if ($etva_physicalvol) {
                 //if pv  already in DB we need to make sure if already exists association with node. if not create new one
                 $etva_node_physicalvol = EtvaNodePhysicalvolumePeer::retrieveByPK($etva_node->getId(), $etva_physicalvol->getId());
                 if (!$etva_node_physicalvol) {
                     $etva_node_physicalvol = new EtvaNodePhysicalvolume();
                 }
             }
         }
         if ($etva_physicalvol) {
             $etva_physicalvol->initData($dev_info);
             $etva_physicalvol->setEtvaCluster($etva_cluster);
             $etva_node_physicalvol->setEtvaPhysicalvolume($etva_physicalvol);
             $etva_node_physicalvol->setEtvaNode($etva_node);
             $etva_node_physicalvol->setDevice($dev_device);
             $etva_node_physicalvol->save();
             $physical_names[] = $etva_physicalvol->getName();
         }
         // TODO treat ignoring cases
     }
     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_PVS);
         }
         $etva_node->clearErrorMessage(self::PVINIT);
         $message = Etva::getLogMessage(array('info' => implode(', ', $physical_names)), EtvaPhysicalvolumePeer::_OK_SOAPUPDATE_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
         return array('success' => true, 'response' => $physical_names);
     }
 }
Example #4
0
 public function executeJsonRegister(sfWebRequest $request)
 {
     $msg_ok_type = EtvaPhysicalvolumePeer::_OK_REGISTER_;
     $msg_err_type = EtvaPhysicalvolumePeer::_ERR_REGISTER_;
     //adding cluster id filter
     $elements = array();
     // get node id from cluster context
     $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);
         $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_);
         //notify system log
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $node_log, '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);
     }
     $device = $request->getParameter('device');
     $uuid = $request->getParameter('uuid');
     $etva_physicalvolume = new EtvaPhysicalvolume();
     if ($uuid) {
         $etva_physicalvolume->setUuid($uuid);
     }
     $etva_physicalvolume->setDevice($device);
     $dev_info = json_decode($request->getParameter('physicalvolume'), true);
     error_log("dev_info: " . print_r($dev_info, true));
     $etva_pv_va = new EtvaPhysicalvolume_VA($etva_physicalvolume);
     $response = $etva_pv_va->register($etva_node, $dev_info);
     //$response = array( 'success'=>true );
     //error_log("register response: " . print_r($response,true));
     if (!$response['success']) {
         $msg_i18n = $this->getContext()->getI18N()->__($msg_err_type, array('%name%' => $device, '%info%' => ''));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $node_log = Etva::getLogMessage(array('name' => $device, 'info' => ''), $msg_err_type);
         //notify system log
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $node_log, '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);
     }
     //notify system log
     $message = Etva::getLogMessage(array('name' => $device), $msg_ok_type);
     $msg_i18n = sfContext::getInstance()->getI18N()->__($msg_ok_type, array('%name%' => $device));
     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 = json_encode($result);
     if (sfConfig::get('sf_environment') == 'soap') {
         return $return;
     }
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }