Esempio n. 1
0
 /**
  * This function calculates the priority of the job.
  * @param BatchJob $batchJob
  * @return integer the calculated priority
  */
 public function calculatePriority(BatchJob $batchJob)
 {
     $parentJob = $batchJob->getParentJob();
     if (!is_null($parentJob) && !is_null($parentJob->getLockInfo())) {
         return $parentJob->getLockInfo()->getPriority();
     }
     return self::BATCH_JOB_DEFAULT_PRIORITY;
 }
Esempio n. 2
0
 public function shouldConsumeJobStatusEvent(BatchJob $dbBatchJob)
 {
     $jobType = $dbBatchJob->getJobType();
     $data = $dbBatchJob->getData();
     // copy cue points only if it's the first file and this is the primary server
     if ($jobType == BatchJobType::CONVERT_LIVE_SEGMENT && $dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED && $data->getFileIndex() == 0 && $data->getMediaServerIndex() == MediaServerIndex::PRIMARY) {
         $asset = assetPeer::retrieveByIdNoFilter($data->getAssetId());
         if ($asset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) {
             return true;
         }
     } elseif ($jobType == BatchJobType::CONCAT && $dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) {
         $convertLiveSegmentJobData = $dbBatchJob->getParentJob()->getData();
         $asset = assetPeer::retrieveByIdNoFilter($convertLiveSegmentJobData->getAssetId());
         if ($asset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) {
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kPostConvertJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function handlePostConvertFailed(BatchJob $dbBatchJob, kPostConvertJobData $data, BatchJob $twinJob = null)
 {
     KalturaLog::debug("Post Convert failed for flavor params output: " . $data->getFlavorParamsOutputId());
     // get additional info from the parent job
     $engineType = null;
     $mediaInfoId = null;
     $parentJob = $dbBatchJob->getParentJob();
     if ($parentJob) {
         $engineType = $parentJob->getJobSubType();
         $convertJobData = $parentJob->getData();
         if ($convertJobData instanceof kConvertJobData) {
             $mediaInfoId = $convertJobData->getMediaInfoId();
         }
     }
     kBusinessPostConvertDL::handleConvertFailed($dbBatchJob, $engineType, $data->getFlavorAssetId(), $data->getFlavorParamsOutputId(), $mediaInfoId);
     return $dbBatchJob;
 }
Esempio n. 4
0
 public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId)
 {
     // verifies that flavor asset created
     if (!$flavorAssetId) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     $currentFlavorAsset = assetPeer::retrieveById($flavorAssetId);
     // verifies that flavor asset exists
     if (!$currentFlavorAsset) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     // if the flavor deleted then it shouldn't be taken into ready calculations
     if ($currentFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
         return $currentFlavorAsset;
     }
     //		Remarked because we want the original flavor ready behavior to work the same as other flavors
     //
     //		$rootBatchJob = $dbBatchJob->getRootJob();
     //
     //		// happens in case of post convert on the original (in case of bypass)
     //		if($rootBatchJob && $currentFlavorAsset->getIsOriginal())
     //		{
     //			kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
     //			return $dbBatchJob;
     //		}
     $sourceMediaInfo = mediaInfoPeer::retrieveOriginalByEntryId($dbBatchJob->getEntryId());
     /*
      * For intermediate source generation, both the source and the asset have the same asset id.
      * In this case sourceMediaInfo should be retrieved as the first version of source asset mediaInfo 
      */
     if (isset($sourceMediaInfo) && $sourceMediaInfo->getFlavorAssetId() == $flavorAssetId) {
         $productMediaInfo = $sourceMediaInfo;
         $entry = $dbBatchJob->getEntry();
         $operationAttributes = $entry->getOperationAttributes();
         // if in clipping operation - take the latest created mediainfo object
         $ascending = empty($operationAttributes) ? 1 : 0;
         $sourceMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAssetId, $ascending);
         KalturaLog::log("Intermediate source generation - assetId(" . $flavorAssetId . "),src MdInf id(" . $sourceMediaInfo->getId() . "),product MdInf id(" . $productMediaInfo->getId()) . ")";
     } else {
         $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     }
     $targetFlavor = assetParamsOutputPeer::retrieveByAssetId($currentFlavorAsset->getId());
     //Retrieve convert job executing engien
     $convertEngineType = null;
     if ($dbBatchJob->getParentJob()) {
         $dbParentBatchJob = $dbBatchJob->getParentJob();
         if ($dbParentBatchJob->getJobType() == BatchJobType::CONVERT) {
             $convertEngineType = $dbParentBatchJob->getJobSubType();
         }
     }
     $postConvertData = $dbBatchJob->getData();
     $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR;
     if ($postConvertData instanceof kPostConvertJobData) {
         $postConvertAssetType = $postConvertData->getPostConvertAssetType();
     }
     // don't validate in case of bypass, in case target flavor or media info are null
     // or ISM/ISMC manifest assets
     if ($postConvertAssetType != BatchJob::POSTCONVERT_ASSET_TYPE_BYPASS && $targetFlavor && $productMediaInfo && !$targetFlavor->hasTag(assetParams::TAG_ISM_MANIFEST)) {
         try {
             $productFlavor = KDLWrap::CDLValidateProduct($sourceMediaInfo, $targetFlavor, $productMediaInfo, $convertEngineType);
         } catch (Exception $e) {
             KalturaLog::err('KDL Error: ' . print_r($e, true));
         }
         $err = kBusinessConvertDL::parseFlavorDescription($productFlavor);
         KalturaLog::debug("BCDL: job id [" . $dbBatchJob->getId() . "] flavor params output id [" . $targetFlavor->getId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "] desc: {$err}");
         if (!$productFlavor->IsValid()) {
             $description = $currentFlavorAsset->getDescription() . "\n{$err}";
             // mark the asset as ready
             $currentFlavorAsset->setDescription($description);
             $currentFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $currentFlavorAsset->save();
             if (!kConf::get('ignore_cdl_failure')) {
                 kJobsManager::failBatchJob($dbBatchJob, $err);
                 return null;
             }
         }
     }
     // mark the asset as ready
     $currentFlavorAsset->setStatusLocalReady();
     $currentFlavorAsset->save();
     $waitingFlavorAssets = assetPeer::retrieveByEntryIdAndStatus($currentFlavorAsset->getEntryId(), flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT);
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($currentFlavorAsset->getEntryId());
     foreach ($waitingFlavorAssets as $waitingFlavorAsset) {
         $flavor = assetParamsOutputPeer::retrieveByAsset($waitingFlavorAsset);
         KalturaLog::debug('Check waiting flavor asset [' . $waitingFlavorAsset->getId() . ']');
         if ($dbBatchJob->getParentJob()) {
             $parentJob = $dbBatchJob->getParentJob();
         } else {
             $parentJob = $dbBatchJob;
         }
         kBusinessPreConvertDL::decideFlavorConvert($waitingFlavorAsset, $flavor, $originalFlavorAsset, null, null, $parentJob);
     }
     kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId());
     if ($currentFlavorAsset->getIsOriginal()) {
         $entry = $currentFlavorAsset->getentry();
         if ($entry) {
             kBusinessConvertDL::checkForPendingLiveClips($entry);
         }
     }
     return $currentFlavorAsset;
 }