Пример #1
0
 public function executeFile(sfWebRequest $request)
 {
     $file = $request->getParameter('filename');
     $type = $request->getParameter('type');
     switch ($type) {
         case 'backup':
             $apl = new Appliance();
             $base_dir = $apl->get_archive_base_dir();
             break;
         default:
             break;
     }
     if (!$base_dir) {
         return sfView::NONE;
     }
     $path = realpath($base_dir . '/' . $file);
     // if base_dir isn't at the front 0==strpos, most likely hacking attempt
     if (strpos($path, $base_dir)) {
         die('Invalid Path');
     } elseif (file_exists($path)) {
         $this->prepareDownload($file);
         readfile($path);
     } else {
         die('Invalid Path');
     }
     return sfView::NONE;
 }
Пример #2
0
 public function load_by_id($id)
 {
     parent::load_by_id($id);
     $details = explode(",", $this->description);
     $this->name = $details[0];
     $this->lightID = $details[1];
 }
 /**
  * @param string           $name
  * @param string           $overview
  * @param ICompany         $company
  * @param bool             $active
  * @param IMarketPlaceType $marketplace_type
  * @param null|string      $call_2_action_url
  * @return ICompanyService
  */
 public function buildCompanyService($name, $overview, ICompany $company, $active, IMarketPlaceType $marketplace_type, $call_2_action_url = null, $live_service = null, $published = null)
 {
     $appliance = new Appliance();
     $appliance->setName($name);
     $appliance->setOverview($overview);
     $appliance->setCompany($company);
     if ($active) {
         $appliance->activate();
     } else {
         $appliance->deactivate();
     }
     $appliance->setMarketplace($marketplace_type);
     $appliance->setCall2ActionUri($call_2_action_url);
     return $appliance;
 }
Пример #4
0
 public function __construct($id = null)
 {
     parent::__construct($id);
     $details = explode(",", $this->description);
     $this->name = $details[0];
     $this->handler = $details[1];
     if (isset($details[2])) {
         $this->lock_img = $details[2];
     }
     if (isset($details[3])) {
         $this->unlock_img = $details[3];
     }
 }
Пример #5
0
 protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $apli = new Appliance();
     $serial = $apli->get_serial_number();
     $this->log('[INFO] Appliance backup...' . "\n");
     if ($serial) {
         $result = $apli->backup(true);
         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...';
             }
             $reason = $result['info'];
             if ($result['txt']) {
                 $reason = $result['txt'];
             }
             $message = 'The backup failed, reason: ' . $reason;
             $context->getEventDispatcher()->notify(new sfEvent($this->name, 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             $this->log('[ERR] ' . $message . "\n");
         } else {
             $message = 'The backup process run with success.';
             $context->getEventDispatcher()->notify(new sfEvent($this->name, 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::INFO)));
             $this->log('[INFO] ' . $message . "\n");
         }
     } else {
         $this->log('[INFO] Could not be possible to do the backup because the appliance is not registered!' . "\n");
     }
 }
Пример #6
0
 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);
     }
 }
 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);
     }
 }
Пример #8
0
 public function updateLastMessage($response)
 {
     $node_name = $this->etva_node->getName();
     if (!$response['success']) {
         $message = Etva::getLogMessage(array('name' => $node_name, 'info' => $response['message']), EtvaNodePeer::_ERR_CHECK_MDSTAT_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($node_name, 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         $msg_i18n = sfContext::getInstance()->getI18N()->__(EtvaNodePeer::_ERR_CHECK_MDSTAT_, array('%name%' => $node_name, '%info%' => $response['message']));
         error_log($message);
         // send status to mastersite
         $apli = new Appliance();
         $apli->updateStatusMessage($message);
         // mark node with fail
         $this->etva_node->setErrorMessage(self::CHECK_MDSTAT, $msg_i18n);
     } else {
         $this->clearLastMessage($response);
     }
 }
Пример #9
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     if ($this->ID) {
         Session::set("FamilyID", $this->ID);
     }
     $nameField = TextField::create('Name', 'Family Name');
     $fields->replaceField('Name', $nameField);
     $houseNoField = TextField::create('HouseNo', 'House No (govt)');
     $fields->replaceField('HouseNo', $houseNoField);
     $parishes = Parish::get()->map('ID', 'NameWithLocation')->toArray();
     $parishField = DropdownField::create('ParishID', 'Parish')->setSource($parishes);
     $parishField->setEmptyString('select...');
     $fields->replaceField('ParishID', $parishField);
     //remove FamilyMembers tab
     $fields->removeByName('FamilyMembers');
     $memberGridFieldConfig = GridFieldConfig_RecordEditor::create();
     $familyMemberList = FamilyMember::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     $familyMemberGridField = new GridField('Members', 'Family members', $familyMemberList, $memberGridFieldConfig);
     $fields->addFieldsToTab('Root.Members', array($familyMemberGridField));
     //house gridfield
     $houseGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $houseList = House::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($houseList->count()) {
         $houseGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $houseGridField = new GridField('House', 'House', $houseList, $houseGridFeildConfig);
     $fields->addFieldsToTab('Root.Housing', array($houseGridField));
     //land gridfield
     $landGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $landList = Land::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($landList->count()) {
         $landGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $landGridField = new GridField('Land', 'Land', $landList, $landGridFeildConfig);
     $fields->addFieldsToTab('Root.Housing', array($landGridField));
     //ShiftedFrom gridfield
     $shiftedFromGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $shiftedFromList = ShiftedFrom::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($shiftedFromList->count()) {
         $shiftedFromGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $shiftedFromGridField = new GridField('Shifted', 'Shifted', $shiftedFromList, $shiftedFromGridFeildConfig);
     $fields->addFieldsToTab('Root.Housing', array($shiftedFromGridField));
     //Agriculture gridfield
     $agricultureGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $agricultureList = Agriculture::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($agricultureList->count()) {
         $agricultureGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $agricultureGridField = new GridField('Agriculture', 'Agriculture', $agricultureList, $agricultureGridFeildConfig);
     $fields->addFieldsToTab('Root.Occupation', array($agricultureGridField));
     //Business gridfield
     $businessGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $businessList = Business::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($businessList->count()) {
         $businessGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $businessGridField = new GridField('Business', 'Business', $businessList, $businessGridFeildConfig);
     $fields->addFieldsToTab('Root.Occupation', array($businessGridField));
     //MonthlyIncome gridfield
     $monthlyIncomeGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $monthlyIncomeList = MonthlyIncome::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($monthlyIncomeList->count()) {
         $monthlyIncomeGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $monthlyIncomeGridField = new GridField('MonthlyIncome', 'MonthlyIncome', $monthlyIncomeList, $monthlyIncomeGridFeildConfig);
     $fields->addFieldsToTab('Root.Monthly', array($monthlyIncomeGridField));
     //MonthlyExpense gridfield
     $monthlyExpenseGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $monthlyExpenseList = MonthlyExpense::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($monthlyExpenseList->count()) {
         $monthlyExpenseGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $monthlyExpenseGridField = new GridField('MonthlyExpense', 'MonthlyExpense', $monthlyExpenseList, $monthlyExpenseGridFeildConfig);
     $fields->addFieldsToTab('Root.Monthly', array($monthlyExpenseGridField));
     //Vehicle gridfield
     $vehicleGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $vehicleList = Vehicle::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($vehicleList->count()) {
         $vehicleGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $vehicleGridField = new GridField('Vehicle', 'Vehicle', $vehicleList, $vehicleGridFeildConfig);
     $fields->addFieldsToTab('Root.OtherDetails', array($vehicleGridField));
     //Appliance gridfield
     $applianceGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $applianceList = Appliance::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($applianceList->count()) {
         $applianceGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $applianceGridField = new GridField('Appliance', 'Appliance', $applianceList, $applianceGridFeildConfig);
     $fields->addFieldsToTab('Root.OtherDetails', array($applianceGridField));
     //OtherFacility gridfield
     $otherFacilityGridFeildConfig = GridFieldConfig_RecordEditor::create();
     $otherFacilityList = OtherFacility::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($otherFacilityList->count()) {
         $otherFacilityGridFeildConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $otherFacilityGridField = new GridField('OtherFacility', 'Other Facility', $otherFacilityList, $otherFacilityGridFeildConfig);
     $fields->addFieldsToTab('Root.OtherDetails', array($otherFacilityGridField));
     //Media gridfield
     $mediaGridFieldConfig = GridFieldConfig_RecordEditor::create();
     $mediaList = Media::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($mediaList->count()) {
         $mediaGridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $mediaGridField = new GridField('Media', 'Media', $mediaList, $mediaGridFieldConfig);
     $fields->addFieldsToTab('Root.OtherDetails', array($mediaGridField));
     //CatholicMagazine gridfield
     $catholicMagazineGridFieldConfig = GridFieldConfig_RecordEditor::create();
     $catholicMagazineList = CatholicMagazine::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($catholicMagazineList->count()) {
         $catholicMagazineGridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $catholicMagazineGridField = new GridField('CatholicMagazine', 'Catholic Magazine', $catholicMagazineList, $catholicMagazineGridFieldConfig);
     $fields->addFieldsToTab('Root.OtherDetails', array($catholicMagazineGridField));
     //Loan gridfield
     $loanGridFieldConfig = GridFieldConfig_RecordEditor::create();
     $loanList = Loan::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($loanList->count()) {
         $loanGridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $loanGridField = new GridField('Loan', 'Loan', $loanList, $loanGridFieldConfig);
     $fields->addFieldsToTab('Root.Financial', array($loanGridField));
     //Saving gridfield
     $savingGridFieldConfig = GridFieldConfig_RecordEditor::create();
     $savingList = Saving::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($savingList->count()) {
         $savingGridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $savingGridField = new GridField('Saving', 'Saving', $savingList, $savingGridFieldConfig);
     $fields->addFieldsToTab('Root.Financial', array($savingGridField));
     //Talent gridfield
     $talentGridFieldConfig = GridFieldConfig_RecordEditor::create();
     $talentList = Talent::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($talentList->count()) {
         $talentGridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $talentGridField = new GridField('Talent', 'Talent', $talentList, $talentGridFieldConfig);
     $fields->addFieldsToTab('Root.Members', array($talentGridField));
     //Contact gridfield
     $contactGridFieldConfig = GridFieldConfig_RecordEditor::create();
     $contactList = Contact::get()->filter(array('FamilyID' => $this->ID))->sort('ID ASC');
     // remove add button if record already exists
     if ($contactList->count()) {
         $contactGridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
     }
     $contactGridField = new GridField('Contact', 'Contact', $contactList, $contactGridFieldConfig);
     $fields->addFieldsToTab('Root.Contact', array($contactGridField));
     return $fields;
 }
Пример #10
0
 public function executeJsonRestore(sfWebRequest $request)
 {
     $backup_id = $request->getParameter('backup');
     $backup_size = $request->getParameter('backup_size');
     $apli = new Appliance();
     $method = $request->getParameter('method');
     switch ($method) {
         case 'restore':
             $serial = $apli->get_serial_number();
             if (!$serial) {
                 $msg = 'Need to register first!';
                 $result = array('success' => false, 'agent' => 'MASTERSITE', 'action' => 'need_register', 'info' => $msg, 'error' => $msg);
                 $error = $this->setJsonError($result);
                 return $this->renderText($error);
             }
             $result = $apli->restore($backup_id);
             if (!$result['success']) {
                 if ($result['action'] == 'check_nodes') {
                     $result['txt'] = 'VA error...';
                 }
             }
             break;
         default:
             $result = array('success' => true, 'data' => array());
             break;
     }
     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);
 }
Пример #11
0
 public function executeSoapInit(sfWebRequest $request)
 {
     if (sfConfig::get('sf_environment') == 'soap') {
         $agent_tmpl = $request->getParameter('name');
         $ip = $request->getParameter('ip');
         $port = $request->getParameter('port');
         $services = $request->getParameter('services');
         $macaddr = $request->getParameter('macaddr');
         $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;
         }
         // print_r($agent_tmpl);
         $etva_server = $etva_network->getEtvaServer();
         $etva_server->setIp($ip);
         $etva_server->setAgentTmpl($agent_tmpl);
         $etva_server->setAgentPort($port);
         $etva_server->setState(1);
         $etva_server->save();
         if ($services) {
             foreach ($services as $service) {
                 $c = new Criteria();
                 $c->add(EtvaServicePeer::NAME_TMPL, $service->name);
                 $c->add(EtvaServicePeer::SERVER_ID, $etva_server->getId());
                 $etva_service = EtvaServicePeer::doSelectOne($c);
                 if (!$etva_service) {
                     $etva_service = new EtvaService();
                     $etva_service->setNameTmpl($service->name);
                     $etva_service->setEtvaServer($etva_server);
                 }
                 if (isset($service->description)) {
                     $etva_service->setDescription($service->description);
                 }
                 if (isset($service->params)) {
                     $params = $service->params;
                     $encoded_json = json_encode($params);
                     $etva_service->setParams($encoded_json);
                 }
                 $etva_service->save();
             }
         }
         /*
          *
          * check if has restore to perform....
          */
         $apli = new Appliance();
         $backup_url = $apli->get_backupconf_url(Appliance::MA_ARCHIVE_FILE, $etva_server->getUuid(), $etva_server->getAgentTmpl());
         $result = array('success' => true);
         if ($backup_url) {
             $result['reset'] = 1;
             $result['backup_url'] = $backup_url;
         }
         return $result;
     }
 }
Пример #12
0
 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);
     }
 }
Пример #13
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;
 }
Пример #14
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;
         }
     }
 }