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);
     }
 }
Example #2
0
 public function initialize($data)
 {
     $uuid = $data['uuid'];
     $etva_data = Etva::getEtvaModelFile();
     if (!$etva_data) {
         $error_msg = 'Could not process etva-model.conf';
         $error = array('success' => false, 'error' => $error_msg);
         //notify system log
         $message = Etva::getLogMessage(array('name' => $data['name'], 'info' => $error_msg), EtvaNodePeer::_ERR_SOAPINIT_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         return $error;
     }
     $etvamodel = $etva_data['model'];
     $c = new Criteria();
     $c->add(EtvaNodePeer::UUID, $uuid);
     $etva_node = EtvaNodePeer::doSelectOne($c);
     if ($etva_node) {
         if ($etva_node->getState() < EtvaNode::NODE_INACTIVE) {
             // dont touch
             //$data['state'] = $etva_node->getState();
             $data['state'] = $this->calcState($etva_node, EtvaNode::NODE_ACTIVE);
         }
         if (!isset($data['isSpareNode'])) {
             $data['isSpareNode'] = $etva_node->getIssparenode() ? 1 : 0;
         }
         if (!isset($data['fencingconf'])) {
             $data['fencingconf'] = $etva_node->getFencingconf();
         }
         $data['cluster_id'] = $etva_node->getClusterId();
         $node_initialize = $etva_node->getInitialize();
         $data['initialize'] = $node_initialize;
         if (empty($node_initialize)) {
             $data['initialize'] = self::INITIALIZE_PENDING;
         }
         if ($etvamodel == 'standard') {
             $data['initialize'] = self::INITIALIZE_OK;
         } else {
             if ($node_initialize != self::INITIALIZE_OK) {
                 return array('success' => true);
             }
         }
         $data['id'] = $etva_node->getId();
         /*
          * calculate free mem
          */
         $etva_node->setMemtotal($data['memtotal']);
         $etva_node->updateMemFree();
         $data['memfree'] = $etva_node->getMemfree();
         $uuid = $etva_node->getUuid();
         $form = new EtvaNodeForm($etva_node);
     } else {
         /*
          * add default cluster ID to node
          */
         if (!($default_cluster = EtvaClusterPeer::retrieveDefaultCluster())) {
             $error_msg = sprintf('Default Object etva_cluster does not exist ');
             $error = array('success' => false, 'error' => $error_msg);
             //notify system log
             $cluster_message = Etva::getLogMessage(array('info' => $error_msg), EtvaClusterPeer::_ERR_DEFAULT_CLUSTER_);
             $message = Etva::getLogMessage(array('name' => $data['name'], 'info' => $cluster_message), EtvaNodePeer::_ERR_SOAPINIT_);
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             return $error;
         }
         $data['cluster_id'] = $default_cluster->getId();
         $form = new EtvaNodeForm();
         $uuid = EtvaNodePeer::generateUUID();
         $data['initialize'] = self::INITIALIZE_PENDING;
         if ($etvamodel == 'standard') {
             $data['initialize'] = self::INITIALIZE_OK;
         }
         /*
          * calculate free mem
          */
         $etva_node = new EtvaNode();
         $etva_node->setMemtotal($data['memtotal']);
         $etva_node->updateMemFree();
         $etva_node->setClusterId($default_cluster->getId());
         $data['memfree'] = $etva_node->getMemfree();
         $data['uuid'] = $uuid;
     }
     $this->clearLastMessage();
     $result = $this->processNodeForm($data, $form);
     if (!$result['success']) {
         return $result;
     }
     // reset guest agent info
     $this->reset_gas_info($etva_node);
     /*
      *
      * check if has restore to perform....
      */
     $apli = new Appliance();
     $action = $apli->getStage(Appliance::RESTORE_STAGE);
     if ($action) {
         $backup_url = $apli->get_backupconf_url(Appliance::VA_ARCHIVE_FILE, $uuid, 'VA');
         if ($backup_url) {
             $result['reset'] = 1;
             $result['backup_url'] = $backup_url;
             /*
              * send pvs, vgs, lvs
              */
             $node_devs = $etva_node->getEtvaNodePhysicalvolumesJoinEtvaPhysicalvolume();
             $devs_va = array();
             foreach ($node_devs as $data) {
                 $dev = $data->getEtvaPhysicalvolume();
                 $devs_va[] = $dev->_VA();
             }
             $result['pvs'] = $devs_va;
             $node_vgs = $etva_node->getEtvaNodeVolumegroupsJoinEtvaVolumegroup();
             $vgs_va = array();
             foreach ($node_vgs as $data) {
                 $vg = $data->getEtvaVolumegroup();
                 $vgs_va[] = $vg->_VA();
             }
             $result['vgs'] = $vgs_va;
             $node_lvs = $etva_node->getEtvaNodeLogicalvolumesJoinEtvaLogicalvolume();
             $lvs_va = array();
             foreach ($node_lvs as $data) {
                 $lv = $data->getEtvaLogicalvolume();
                 $lvs_va[] = $lv->_VA();
             }
             $result['lvs'] = $lvs_va;
         }
         $apli->setStage(Appliance::RESTORE_STAGE, Appliance::VA_INIT);
     }
     return $result;
 }
 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 executeJsonRestoreProgress(sfWebRequest $request)
 {
     $serial = $request->getParameter('sn');
     $apli = new Appliance($serial);
     $action = $apli->getStage(Appliance::RESTORE_STAGE);
     switch ($action) {
         case Appliance::GET_RESTORE:
             $cache = new apc_CACHE($serial);
             $total_download = $cache->get(cURL::PROGRESS_DOWNLOAD_TOTAL);
             $partial_download = $cache->get(cURL::PROGRESS_DOWNLOAD_NOW);
             $percent = $partial_download / $total_download;
             $result = array('success' => true, 'action' => $action, 'total_down' => $total_download, 'partial_down' => $partial_download, 'percent' => $percent);
             break;
         case Appliance::ARCHIVE_RESTORE:
             $txt = 'Uncompressing archive...';
             $result = array('success' => true, 'txt' => $txt, 'action' => $action);
             break;
         case Appliance::DB_RESTORE:
             $txt = 'Restoring DB...';
             $result = array('success' => true, 'txt' => $txt, 'action' => $action);
             break;
         case Appliance::VA_ERROR_STORAGE:
             $result = array('success' => true, 'txt' => 'Storage not restored! Getting actual storage...', 'action' => $action);
             break;
         default:
             $txt = $action;
             $result = array('success' => true, 'txt' => $txt, 'action' => $action);
     }
     if (!$result['success']) {
         $error = $this->setJsonError($result);
         return $this->renderText($error);
     }
     $json_encoded = json_encode($result);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($json_encoded);
 }
Example #5
0
 public function executeSoapRestore(sfWebRequest $request)
 {
     if (sfConfig::get('sf_environment') == 'soap') {
         $macaddr = $request->getParameter('macaddr');
         $ok = $request->getParameter('ok');
         /*
          * restore ok...
          */
         $c = new Criteria();
         $c->add(EtvaNetworkPeer::MAC, $macaddr);
         $etva_network = EtvaNetworkPeer::doSelectOne($c);
         if (!$etva_network) {
             $error_msg = sprintf('Object etva_network does not exist (%s).', $macaddr);
             $error = array('success' => false, 'error' => $error_msg);
             return $error;
         }
         $etva_server = $etva_network->getEtvaServer();
         $agent = $etva_server->getAgentTmpl();
         $message = "MA {$agent} restore ok";
         //notify system log
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_server->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::INFO)));
         /*
          * check if is an appliance restore operation...it should be...
          */
         $apli = new Appliance();
         $action = $apli->getStage(Appliance::RESTORE_STAGE);
         if ($action) {
             $apli->setStage(Appliance::RESTORE_STAGE, Appliance::MA_COMPLETED);
         }
         // remove backup MA file
         $apli->del_backupconf_file(Appliance::MA_ARCHIVE_FILE, $etva_server->getUuid(), $etva_server->getAgentTmpl());
         return array('success' => true);
     }
 }
 public function initialize(EtvaNode $etva_node, $lvs, $dtable, $bulk_dtable)
 {
     $etva_cluster = $etva_node->getEtvaCluster();
     $logical_names = array();
     $errors = array();
     /*
      * check lv consistency
      */
     $check_res = $this->check_consistency($etva_node, $lvs, $dtable, $bulk_dtable);
     if (!$check_res['success']) {
         $errors = $check_res['errors'];
         $inconsistent_message = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => ''));
         $etva_node->setErrorMessage(self::LVINIT);
         $message = Etva::getLogMessage(array('info' => $inconsistent_message), EtvaLogicalvolumePeer::_ERR_SOAPUPDATE_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         // dont stop process
         //return array('success'=>false,'error'=>$errors);
     }
     /*
      * check shared lvs consistency
      */
     /*$consist = $this->check_shared_consistency($etva_node,$lvs);        
             $consist_dtable = $this->check_shared_devicetable_consistency($etva_node,$dtable,$bulk_dtable);
     
             if(!$consist || !$consist_dtable){
                 $errors = $this->get_missing_lv_devices($etva_node);
                 $inconsistent_message = $errors ? $errors['message'] :
                                 sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_,array('%info%'=>'initialize'));
     
                 $etva_node->setErrorMessage(self::LVINIT);
     
                 $message = Etva::getLogMessage(array('info'=>$inconsistent_message), EtvaLogicalvolumePeer::_ERR_SOAPUPDATE_);
                 sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(),'event.log',array('message' =>$message,'priority'=>EtvaEventLogger::ERR)));
     
                 // dont stop process
                 //return array('success'=>false,'error'=>$errors);
             }*/
     foreach ($lvs as $lvInfo) {
         if (!empty($lvInfo)) {
             $lv_info = (array) $lvInfo;
             // set mounted 0 when not mounted
             if (!isset($lv_info[EtvaLogicalvolume::MOUNTED_MAP])) {
                 $lv_info[EtvaLogicalvolume::MOUNTED_MAP] = 0;
             }
             //error_log("device " . $lv_info[EtvaLogicalvolume::LVDEVICE_MAP] . " EtvaLogicalvolume::MOUNTED_MAP " . $lv_info[EtvaLogicalvolume::MOUNTED_MAP]);
             $lv_dev = $lv_info[EtvaLogicalvolume::LVDEVICE_MAP];
             $lv_type = $lv_info[EtvaLogicalvolume::STORAGE_TYPE_MAP];
             $lv_uuid = isset($lv_info[EtvaLogicalvolume::UUID_MAP]) ? $lv_info[EtvaLogicalvolume::UUID_MAP] : '';
             // vg info
             $vg_info = (array) $lv_info[EtvaLogicalvolume::VOLUMEGROUP_MAP];
             $vg_name = $vg_info[EtvaVolumegroup::VG_MAP];
             $vg_type = $vg_info[EtvaVolumegroup::STORAGE_TYPE_MAP];
             $vg_uuid = isset($vg_info[EtvaVolumegroup::UUID_MAP]) ? $vg_info[EtvaVolumegroup::UUID_MAP] : '';
             //get volume group based on node, type, uuid and vg
             $etva_volgroup = EtvaVolumegroupPeer::retrieveByNodeTypeUUIDVg($etva_node->getId(), $vg_type, $vg_uuid, $vg_name);
             if ($etva_volgroup) {
                 if ($lv_type == EtvaLogicalvolume::STORAGE_TYPE_LOCAL_MAP) {
                     $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByNodeTypeLvDevice($etva_node->getId(), $lv_type, $lv_dev);
                 } else {
                     $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByUUID($lv_uuid);
                 }
                 if (!$etva_logicalvol) {
                     // no lv in db...so create new one
                     $etva_node_logicalvol = new EtvaNodeLogicalvolume();
                     $etva_logicalvol = new EtvaLogicalvolume();
                 } else {
                     //if lv already in DB we need to make sure if already exists association with node. if not create new one
                     $etva_node_logicalvol = EtvaNodeLogicalvolumePeer::retrieveByPK($etva_node->getId(), $etva_logicalvol->getId());
                     if (!$etva_node_logicalvol) {
                         $etva_node_logicalvol = new EtvaNodeLogicalvolume();
                     }
                 }
                 $etva_logicalvol->initData($lv_info);
                 $etva_logicalvol->setEtvaVolumegroup($etva_volgroup);
                 $etva_logicalvol->setEtvaCluster($etva_cluster);
                 $etva_logicalvol->save();
                 $etva_node_logicalvol->setEtvaLogicalvolume($etva_logicalvol);
                 $etva_node_logicalvol->setEtvaNode($etva_node);
                 $etva_node_logicalvol->save();
                 $logical_names[] = $etva_logicalvol->getLv();
             }
         }
     }
     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_LVS);
         }
         $etva_node->clearErrorMessage(self::LVINIT);
         $message = Etva::getLogMessage(array('info' => implode(', ', $logical_names)), EtvaLogicalvolumePeer::_OK_SOAPUPDATE_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
         return array('success' => true, 'response' => $logical_names);
     }
 }
Example #7
0
 public static function getAgentFiles($method)
 {
     $apli = new Appliance();
     switch ($method) {
         case 'get_diagnostic_progress':
             $action = $apli->getStage(Appliance::BACKUP_STAGE);
             error_log("[ACTION] {$action}");
             switch ($action) {
                 case Appliance::DB_BACKUP:
                     $txt = 'Perfoming DB backup...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 case Appliance::ARCHIVE_BACKUP:
                     $txt = 'Creating compressed archive...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 default:
                     $result = array('success' => true, 'txt' => $action, 'action' => $action);
             }
             break;
         case 'diagnostic':
             #                $force = $request->getParameter('force');
             $result = $apli->backup(true, true);
             // generate tarball with logs
             $filepath = sfConfig::get("app_remote_log_file");
             $scriptfile = sfConfig::get("app_remote_log_script");
             #                putenv("ETVADIAGNOSTIC=symfony");
             $command = "/bin/bash {$scriptfile} {$filepath}";
             $node_list = EtvaNodePeer::doSelect(new Criteria());
             foreach ($node_list as $node) {
                 $name = $node->getName();
                 $ip = $node->getIp();
                 $port = $node->getPort();
                 $command .= " {$name} {$ip} {$port}";
             }
             $command .= ' 2>&1';
             error_log('[COMMAND]' . $command);
             $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils";
             error_log("[INFO] PATH TO SUDOEXEC" . $path . DIRECTORY_SEPARATOR);
             ob_start();
             passthru('echo ' . $command . ' | sudo /usr/bin/php -f ' . $path . DIRECTORY_SEPARATOR . 'sudoexec.php', $return);
             #$content_grabbed=ob_get_contents();
             ob_end_clean();
             #$output = shell_exec($command);
             error_log("[INFO] Script diagnostic_ball has exited.");
             error_log("[INFO] " . $return);
             if ($return != 0) {
                 $result['success'] = false;
             } else {
                 $mail_success = diagnostic::sendDiagnosticEmail();
                 if (!$mail_success) {
                     //$str = implode("\n", $mail_success);
                     $result['mail_errors'] = 'email errors';
                 }
             }
             if (!$result['success']) {
                 if ($result['action'] == Appliance::LOGIN_BACKUP) {
                     $result['txt'] = 'Could not login!';
                 }
                 if ($result['action'] == Appliance::DB_BACKUP) {
                     $result['txt'] = 'DB backup error...';
                 }
                 if ($result['action'] == Appliance::MA_BACKUP) {
                     $result['txt'] = 'MA backup error...';
                 }
             }
             break;
         default:
             $result = array('success' => true, 'data' => array());
             break;
     }
     return $result;
 }
Example #8
0
 /**
  * process soap update requests of virtual machines
  *
  * $request['uuid'] //node uuid
  * $request['action'] // domains_stats (updates vms state) or domains_init (initializes agent servers)
  * $request['vms'] //list of virtual machines sent by VA
  *
  * @return array servers array on CM DB
  *
  */
 public function executeSoapUpdate(sfWebRequest $request)
 {
     if (sfConfig::get('sf_environment') == 'soap') {
         $action = $request->getParameter('action');
         $c = new Criteria();
         $c->add(EtvaNodePeer::UUID, $request->getParameter('uuid'));
         if (!($etva_node = EtvaNodePeer::doSelectOne($c))) {
             $error_msg = sprintf('Object etva_node does not exist (%s).', $request->getParameter('uuid'));
             $error = array('success' => false, 'error' => $error_msg);
             //notify event log
             $node_message = Etva::getLogMessage(array('name' => $request->getParameter('uuid')), EtvaNodePeer::_ERR_NOTFOUND_UUID_);
             $message = Etva::getLogMessage(array('info' => $node_message), EtvaServerPeer::_ERR_SOAPUPDATE_);
             $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             return $error;
         }
         $node_initialize = $etva_node->getInitialize();
         if ($node_initialize != EtvaNode_VA::INITIALIZE_OK) {
             $error_msg = sprintf('Etva node initialize status: %s', $node_initialize);
             $error = array('success' => false, 'error' => $error_msg);
             return $error;
         }
         $querysrvs = EtvaServerQuery::create();
         $querysrvs->orderByPriorityHa('desc');
         $node_servers = $etva_node->getEtvaServers($querysrvs);
         switch ($action) {
             case 'domains_stats':
                 $vms = (array) $request->getParameter('vms');
                 $vms_uuids = array();
                 $vms = !empty($vms) ? (array) $vms : array();
                 $not_affected = 0;
                 foreach ($vms as $vm) {
                     $vms_uuids[$vm->uuid] = (array) $vm;
                 }
                 foreach ($node_servers as $node_server) {
                     //error_log(sprintf('node_servers id=%s name=%s priority_ha=%s',$node_server->getId(),$node_server->getName(),$node_server->getPriorityHa()));
                     $server_uuid = $node_server->getUuid();
                     if (!$node_server->getUnassigned()) {
                         // assigned only
                         // and is not migrating
                         if ($node_server->getVmState() !== EtvaServer::STATE_MIGRATING) {
                             if (isset($vms_uuids[$server_uuid])) {
                                 $node_server->setVmState($vms_uuids[$server_uuid]['state']);
                                 if (isset($vms_uuids[$server_uuid]['has_snapshots'])) {
                                     // set snapshots flags
                                     $node_server->setHassnapshots($vms_uuids[$server_uuid]['has_snapshots']);
                                 }
                                 $node_server->save();
                             } else {
                                 $message_s = sprintf('Node %s could not check state for virtual machine %s(%s)', $etva_node->getName(), $node_server->getName(), $server_uuid);
                                 $not_affected++;
                                 $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message_s, 'priority' => EtvaEventLogger::ERR)));
                                 error_log($message_s);
                             }
                         } else {
                             $message_s = sprintf('Node %s could not check state for virtual machine %s(%s) beacuse is migrating', $etva_node->getName(), $node_server->getName(), $server_uuid);
                             error_log($message_s);
                         }
                     }
                 }
                 // update free memory
                 $etva_node->updateMemFree();
                 $etva_node->save();
                 //notify system log
                 if ($not_affected > 0) {
                     $message = sprintf('Node %s could not check for %d virtual machine(s) state', $etva_node->getName(), $not_affected);
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
                     return array('success' => false, 'reason' => '_servers_inconsistency_');
                 }
                 return array('success' => true);
                 break;
             case 'domains_gainfo':
                 $vms = (array) $request->getParameter('vms');
                 $vms_uuids = array();
                 $vms = !empty($vms) ? (array) $vms : array();
                 foreach ($vms as $vm) {
                     $vms_uuids[$vm->uuid] = (array) $vm;
                 }
                 foreach ($node_servers as $node_server) {
                     $server_uuid = $node_server->getUuid();
                     if (!$node_server->getUnassigned()) {
                         // assigned only
                         if (isset($vms_uuids[$server_uuid])) {
                             //$str = json_encode($vms_uuids[$server_uuid]['msg']);
                             $str = $vms_uuids[$server_uuid]['msg'];
                             $obj = json_decode($str);
                             $node_server->mergeGaInfo($str);
                             // merge GA info
                             $node_server->resetHeartbeat(EtvaServerPeer::_GA_RUNNING_);
                             $node_server->setHbnrestarts(0);
                             // reset num of restarts
                             $node_server->save();
                             $message = sprintf('domains_gainfo guest agent info updated (id=%s name=%s type=%s hb=%s)', $node_server->getId(), $node_server->getName(), $obj->__name__, $node_server->getHeartbeat());
                             error_log($message);
                             /*$this->dispatcher->notify(
                               new sfEvent(sfConfig::get('config_acronym'), 'event.log',
                                   array('message' => $message,'priority'=>EtvaEventLogger::INFO)));*/
                         }
                     }
                 }
                 return array('success' => true);
                 break;
             case 'domains_sync':
                 $new_servers = array();
                 $vms = (array) $request->getParameter('vms');
                 $vms_uuids = array();
                 $vms = !empty($vms) ? (array) $vms : array();
                 $not_affected = 0;
                 foreach ($vms as $vm) {
                     if ($vm) {
                         $vms_uuids[$vm->uuid] = (array) $vm;
                     }
                 }
                 foreach ($node_servers as $node_server) {
                     error_log(sprintf('domains_sync server id=%s name=%s priority_ha=%s', $node_server->getId(), $node_server->getName(), $node_server->getPriorityHa()));
                     if (!$node_server->getUnassigned()) {
                         // ignore unassigned servers
                         $server_name = $node_server->getName();
                         $new_servers[$server_name] = $node_server->_VA();
                         $server_uuid = $node_server->getUuid();
                         if (isset($vms_uuids[$server_uuid])) {
                             if ($vms_uuids[$server_uuid]['state'] != EtvaServer::RUNNING && ($node_server->getVmState() == EtvaServer::RUNNING || $node_server->getAutostart())) {
                                 error_log(sprintf('domains_sync server id=%s name=%s should be running', $node_server->getId(), $node_server->getName()));
                                 $node_server->setHblaststart('NOW');
                                 // update hb last start
                                 $node_server->save();
                             }
                             unset($vms_uuids[$server_uuid]);
                         }
                     }
                 }
                 $servers_names = array_keys($new_servers);
                 $servers = implode(', ', $servers_names);
                 /*
                  * 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_VMS);
                 }
                 //notify system log
                 if ($new_servers) {
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_node->getName(), 'info' => $servers), EtvaServerPeer::_OK_SOAPUPDATE_), 'priority' => EtvaEventLogger::INFO)));
                 }
                 $load_servers = count($new_servers) ? array_values($new_servers) : array();
                 $destroy_servers = count($vms_uuids) ? array_values($vms_uuids) : array();
                 $return = array('success' => true, 'load_servers' => $load_servers, 'destroy_servers' => $destroy_servers);
                 return $return;
                 break;
             default:
                 $new_servers = array();
                 foreach ($node_servers as $node_server) {
                     if (!$node_server->getUnassigned()) {
                         // ignore unassigned servers
                         $server_name = $node_server->getName();
                         $new_servers[$server_name] = $node_server->_VA();
                     }
                 }
                 $servers_names = array_keys($new_servers);
                 $servers = implode(', ', $servers_names);
                 /*
                  * 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_VMS);
                 }
                 //notify system log
                 if ($new_servers) {
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_node->getName(), 'info' => $servers), EtvaServerPeer::_OK_SOAPUPDATE_), 'priority' => EtvaEventLogger::INFO)));
                 }
                 return $new_servers;
         }
     }
 }