示例#1
0
$iStatLog = ReadMandatoryParam($oP, 'log');
$iChange = ReadMandatoryParam($oP, 'change');
$sLastFullLoad = ReadMandatoryParam($oP, 'last_full_load', 'raw_data');
$iChunkSize = ReadMandatoryParam($oP, 'chunk');
$oP->p('Last full load: ' . $sLastFullLoad);
$oP->p('Chunk size: ' . $iChunkSize);
$oP->p('Source: ' . $iSource);
try {
    $oSynchroDataSource = MetaModel::GetObject('SynchroDataSource', $iSource);
    $oLog = MetaModel::GetObject('SynchroLog', $iStatLog);
    $oChange = MetaModel::GetObject('CMDBChange', $iChange);
    if (strlen($sLastFullLoad) > 0) {
        $oLastFullLoad = new DateTime($sLastFullLoad);
        $oSynchroExec = new SynchroExecution($oSynchroDataSource, $oLastFullLoad);
    } else {
        $oSynchroExec = new SynchroExecution($oSynchroDataSource);
    }
    if ($oSynchroExec->DoSynchronizeChunk($oLog, $oChange, $iChunkSize)) {
        // The last line MUST follow this convention
        $oP->p("continue");
    } else {
        // The last line MUST follow this convention
        $oP->p("finished");
    }
    $oP->output();
} catch (Exception $e) {
    $oP->p("Error: " . $e->GetMessage());
    $oP->add($e->getTraceAsString());
    $oP->output();
    exit(28);
}
 /**
  * Do the synchronization job, limited to some amount of work
  * This verb has been designed to be called from within a separate process	 
  * @return true if the process has to be continued
  */
 public function DoSynchronizeChunk($oLog, $oChange, $iMaxChunkSize)
 {
     // Initialize the structures...
     self::$m_oCurrentTask = $this->m_oDataSource;
     $this->m_oStatLog = $oLog;
     $this->m_oChange = $oChange;
     // Prepare internal structures (not the first pass)
     $this->PrepareProcessing(false);
     $iCurrJob = $this->m_oStatLog->Get('status_curr_job');
     $iCurrPos = $this->m_oStatLog->Get('status_curr_pos');
     $this->m_oStatLog->AddTrace("Synchronizing chunk - curr_job:{$iCurrJob}, curr_pos:{$iCurrPos}, max_chunk_size:{$iMaxChunkSize}");
     $bContinue = false;
     switch ($iCurrJob) {
         case 1:
         default:
             $this->DoJob1($iMaxChunkSize, $iCurrPos);
             $bContinue = true;
             break;
         case 2:
             $this->DoJob2($iMaxChunkSize, $iCurrPos);
             $bContinue = true;
             break;
         case 3:
             $bContinue = $this->DoJob3($iMaxChunkSize, $iCurrPos);
             break;
     }
     $this->m_oStatLog->DBUpdate($this->m_oChange);
     self::$m_oCurrentTask = null;
     return $bContinue;
 }
示例#3
0
 public function GetSynchroReplicaFlags($sAttCode, &$aReason)
 {
     $iFlags = OPT_ATT_NORMAL;
     $oSet = $this->GetMasterReplica();
     while ($aData = $oSet->FetchAssoc()) {
         if ($aData['datasource']->GetKey() == SynchroExecution::GetCurrentTaskId()) {
             // Ignore the current task (check to write => ok)
             continue;
         }
         // Assumption: $aData['datasource'] will not be null because the data source id is always set...
         $oReplica = $aData['replica'];
         $oSource = $aData['datasource'];
         $oAttrSet = $oSource->Get('attribute_list');
         while ($oSyncAttr = $oAttrSet->Fetch()) {
             if ($oSyncAttr->Get('attcode') == $sAttCode && $oSyncAttr->Get('update') == 1 && $oSyncAttr->Get('update_policy') == 'master_locked') {
                 $iFlags |= OPT_ATT_SLAVE;
                 $sUrl = $oSource->GetApplicationUrl($this, $oReplica);
                 $aReason[] = array('name' => $oSource->GetName(), 'description' => $oSource->Get('description'), 'url_application' => $sUrl);
             }
         }
     }
     return $iFlags;
 }
示例#4
0
     $oP->add_comment("Columns: " . implode(', ', $aInputColumns));
     $oP->add_comment("Output format: " . $sOutput);
     //		$oP->add_comment("Report level: ".$sReportLevel);
     $oP->add_comment("Simulate: " . ($bSimulate ? '1' : '0'));
     $oP->add_comment("Change tracking comment: " . $sComment);
     $oP->add_comment("Issues (before synchro): " . $iCountErrors);
     //		$oP->add_comment("Warnings: ".$iCountWarnings);
     $oP->add_comment("Created (before synchro): " . $iCountCreations);
     $oP->add_comment("Updated (before synchro): " . $iCountUpdates);
 }
 //////////////////////////////////////////////////
 //
 // Synchronize
 //
 if ($bSynchronize) {
     $oSynchroExec = new SynchroExecution($oDataSource, $oLoadStartDate);
     $oStatLog = $oSynchroExec->Process();
     $oP->add_comment('Synchronization---');
     $oP->add_comment('------------------');
     if ($sOutput == 'details') {
         foreach ($oStatLog->GetTraces() as $sMessage) {
             $oP->add_comment($sMessage);
         }
     }
     if ($oStatLog->Get('status') == 'error') {
         $oP->p("ERROR: " . $oStatLog->Get('last_error'));
     }
     $oP->add_comment("Replicas: " . $oStatLog->Get('stats_nb_replica_total'));
     $oP->add_comment("Replicas touched since last synchro: " . $oStatLog->Get('stats_nb_replica_seen'));
     $oP->add_comment("Objects deleted: " . $oStatLog->Get('stats_nb_obj_deleted'));
     $oP->add_comment("Objects deletion errors: " . $oStatLog->Get('stats_nb_obj_deleted_errors'));
示例#5
0
 public function GetSynchroReplicaFlags($sAttCode, &$aReason)
 {
     $iFlags = OPT_ATT_NORMAL;
     foreach ($this->GetSynchroData() as $iSourceId => $aSourceData) {
         if ($iSourceId == SynchroExecution::GetCurrentTaskId()) {
             // Ignore the current task (check to write => ok)
             continue;
         }
         // Assumption: one replica - take the first one!
         $oReplica = reset($aSourceData['replica']);
         $oSource = $aSourceData['source'];
         if (array_key_exists($sAttCode, $aSourceData['attributes'])) {
             $oSyncAttr = $aSourceData['attributes'][$sAttCode];
             if ($oSyncAttr->Get('update') == 1 && $oSyncAttr->Get('update_policy') == 'master_locked') {
                 $iFlags |= OPT_ATT_SLAVE;
                 $sUrl = $oSource->GetApplicationUrl($this, $oReplica);
                 $aReason[] = array('name' => $oSource->GetName(), 'description' => $oSource->Get('description'), 'url_application' => $sUrl);
             }
         }
     }
     return $iFlags;
 }