Exemplo n.º 1
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         KalturaLog::err("No flavors created: {$errDescription}");
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     $dynamicFlavorAttributes = $entry->getDynamicFlavorAttributes();
     // gets the flavor params by the id
     $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds);
     foreach ($flavors as $index => $flavor) {
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             unset($flavors[$index]);
             continue;
         }
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
Exemplo n.º 2
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kPullJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function handlePullFailed(BatchJob $dbBatchJob, kPullJobData $data, BatchJob $twinJob = null)
 {
     $rootBatchJob = $dbBatchJob->getRootJob();
     if ($rootBatchJob) {
         $rootBatchJob = kJobsManager::failBatchJob($rootBatchJob, "Pull job " . $dbBatchJob->getId() . " failed");
     }
     return $dbBatchJob;
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param kConvertCollectionJobData $data
  * @param int $engineType
  * @return boolean
  */
 public static function handleConvertCollectionFailed(BatchJob $dbBatchJob, kConvertCollectionJobData $data, $engineType)
 {
     $collectionFlavors = array();
     foreach ($data->getFlavors() as $flavor) {
         $collectionFlavors[$flavor->getFlavorAssetId()] = $flavor;
     }
     // find the root job
     $rootBatchJob = $dbBatchJob->getRootJob();
     $hasIncomplete = false;
     $shouldFailProfile = false;
     $flavorAssets = assetPeer::retrieveFlavorsByEntryId($dbBatchJob->getEntryId());
     foreach ($flavorAssets as $flavorAsset) {
         if (isset($collectionFlavors[$flavorAsset->getId()])) {
             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $flavorAsset->save();
             if (!$rootBatchJob) {
                 continue;
             }
             $flavorData = $collectionFlavors[$flavorAsset->getId()];
             if ($flavorData->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
                 $shouldFailProfile = true;
             }
             continue;
         }
         if ($flavorAsset->getIsOriginal()) {
             continue;
         }
         if ($flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING || $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING || $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) {
             $hasIncomplete = true;
         }
     }
     if (!$rootBatchJob) {
         return false;
     }
     if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         return false;
     }
     if ($shouldFailProfile || !$hasIncomplete) {
         kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed");
     }
     return false;
 }
Exemplo n.º 4
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     // gets the flavor params by the id
     $flavors = assetParamsPeer::retrieveFlavorsByPKs($flavorsIds);
     self::checkConvertProfileParams($flavors, $conversionProfileFlavorParams, $entry);
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     try {
         return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $profile->getId(), $mediaInfo);
     } catch (Exception $e) {
         KalturaLog::err('decideProfileFlavorsConvert - ' . $e->getMessage());
     }
 }
Exemplo n.º 5
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kConvertJobData $data
  * @return BatchJob
  */
 public static function handleConvertQueued(BatchJob $dbBatchJob, kConvertJobData $data)
 {
     $rootBatchJob = $dbBatchJob->getRootJob();
     if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
         $entry = $dbBatchJob->getEntry();
         if (!$entry) {
             return $dbBatchJob;
         }
         $notificationData = array("puserId" => $entry->getPuserId(), "entryId" => $entry->getId(), "entryIntId" => $entry->getIntId(), "entryVersion" => $entry->getVersion(), "conversionQuality" => $entry->getConversionQuality());
         $extraData = array("data" => json_encode($notificationData), "partner_id" => $entry->getPartnerId(), "puser_id" => $entry->getPuserId(), "entry_id" => $entry->getId(), "entry_int_id" => $entry->getIntId(), "entry_version" => $entry->getVersion(), "conversion_quality" => $entry->getConversionQuality(), "status" => $entry->getStatus(), "abort" => $dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED, "message" => $dbBatchJob->getMessage(), "description" => $dbBatchJob->getDescription(), "job_type" => BatchJobType::DOWNLOAD, "status" => BatchJob::BATCHJOB_STATUS_QUEUED, "progress" => 0, "debug" => __LINE__);
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_BATCH_JOB_STARTED, $dbBatchJob, $dbBatchJob->getPartnerId(), null, null, $extraData, $dbBatchJob->getEntryId());
     }
     return $dbBatchJob;
 }
Exemplo n.º 6
0
 /**
  * @param BatchJob $parentJob
  * @param int $jobSubType
  * @param string $srcFileSyncLocalPath
  * @param int $flavorAssetId
  * @param int $flavorParamsOutputId
  * @param bool $createThumb
  * @param int $thumbOffset
  * @return BatchJob
  */
 public static function addPostConvertJob(BatchJob $parentJob, $jobSubType, $srcFileSyncLocalPath, $flavorAssetId, $flavorParamsOutputId, $createThumb = false, $thumbOffset = 3)
 {
     $postConvertData = new kPostConvertJobData();
     $postConvertData->setSrcFileSyncLocalPath($srcFileSyncLocalPath);
     $postConvertData->setFlavorParamsOutputId($flavorParamsOutputId);
     $postConvertData->setFlavorAssetId($flavorAssetId);
     $postConvertData->setThumbOffset($thumbOffset);
     $postConvertData->setCreateThumb($createThumb);
     $parentData = $parentJob->getData();
     if ($parentData instanceof kConvartableJobData) {
         $postConvertData->setCurrentOperationSet($parentData->getCurrentOperationSet());
         $postConvertData->setCurrentOperationIndex($parentData->getCurrentOperationIndex());
     }
     if ($createThumb) {
         $flavorParamsOutput = flavorParamsOutputPeer::retrieveByPK($flavorParamsOutputId);
         if (!$flavorParamsOutput) {
             $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId);
             if ($flavorAsset) {
                 $postConvertData->setThumbHeight($flavorAsset->getHeight());
                 $postConvertData->setThumbBitrate($flavorAsset->getBitrate());
             } else {
                 $postConvertData->setCreateThumb(false);
             }
         } elseif (!$flavorParamsOutput->getVideoBitrate()) {
             $postConvertData->setCreateThumb(false);
         } else {
             $entry = $parentJob->getEntry();
             $rootBatchJob = $parentJob->getRootJob();
             if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 $thisFlavorHeight = $flavorParamsOutput->getHeight();
                 $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate();
                 $rootBatchJobData = $rootBatchJob->getData();
                 $createThumb = false;
                 if ($rootBatchJobData->getThumbBitrate() < $thisFlavorBitrate) {
                     $createThumb = true;
                 } elseif ($rootBatchJobData->getThumbBitrate() == $thisFlavorBitrate && $rootBatchJobData->getThumbHeight() < $thisFlavorHeight) {
                     $createThumb = true;
                 }
                 if ($createThumb) {
                     $postConvertData->setCreateThumb(true);
                     $postConvertData->setThumbHeight($thisFlavorHeight);
                     $postConvertData->setThumbBitrate($thisFlavorBitrate);
                 }
             } elseif (!$entry->getThumbnailVersion()) {
                 $thisFlavorHeight = $flavorParamsOutput->getHeight();
                 $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate();
                 $postConvertData->setCreateThumb(true);
                 $postConvertData->setThumbHeight($thisFlavorHeight);
                 $postConvertData->setThumbBitrate($thisFlavorBitrate);
             }
         }
     }
     KalturaLog::log("Post Convert created with file: " . $postConvertData->getSrcFileSyncLocalPath());
     return kJobsManager::addJob($parentJob->createChild(), $postConvertData, BatchJobType::POSTCONVERT, $jobSubType);
 }