コード例 #1
0
 public static function getReadyBehavior(flavorAsset $flavorAsset)
 {
     if ($flavorAsset->getIsOriginal()) {
         try {
             $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
             if ($profile) {
                 $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavorAsset->getFlavorParamsId(), $profile->getId());
                 if ($flavorParamsConversionProfile) {
                     return $flavorParamsConversionProfile->getReadyBehavior();
                 }
             }
         } catch (Exception $e) {
             KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage());
         }
     }
     $targetFlavor = flavorParamsOutputPeer::retrieveByFlavorAssetId($flavorAsset->getId());
     if ($targetFlavor) {
         return $targetFlavor->getReadyBehavior();
     }
     return flavorParamsConversionProfile::READY_BEHAVIOR_INHERIT_FLAVOR_PARAMS;
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param flavorAsset $currentFlavorAsset
  * @return BatchJob
  */
 public static function handleConvertFinished(BatchJob $dbBatchJob = null, flavorAsset $currentFlavorAsset)
 {
     KalturaLog::debug("entry id [" . $currentFlavorAsset->getEntryId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "]");
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($currentFlavorAsset->getEntryId());
         KalturaLog::debug("profile [" . $profile->getId() . "]");
     } catch (Exception $e) {
         KalturaLog::err($e->getMessage());
     }
     $currentReadyBehavior = self::getReadyBehavior($currentFlavorAsset, $profile);
     KalturaLog::debug("Current ready behavior [{$currentReadyBehavior}]");
     if ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
         return $dbBatchJob;
     }
     $rootBatchJob = null;
     if ($dbBatchJob) {
         $rootBatchJob = $dbBatchJob->getRootJob();
     }
     if ($rootBatchJob) {
         KalturaLog::debug("root batch job id [" . $rootBatchJob->getId() . "] type [" . $rootBatchJob->getJobType() . "]");
     }
     // update the root job end exit
     if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
         $siblingJobs = $rootBatchJob->getChildJobs();
         foreach ($siblingJobs as $siblingJob) {
             // checking only conversion child jobs
             if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::CONVERT_COLLECTION && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) {
                 continue;
             }
             // if not complete leave function
             if (!in_array($siblingJob->getStatus(), BatchJobPeer::getClosedStatusList())) {
                 KalturaLog::debug("job id [" . $siblingJob->getId() . "] status [" . $siblingJob->getStatus() . "]");
                 return $dbBatchJob;
             }
         }
         KalturaLog::debug("finish bulk download root job");
         // all child jobs completed
         kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         return $dbBatchJob;
     }
     $inheritedFlavorParamsIds = array();
     $requiredFlavorParamsIds = array();
     $flavorParamsConversionProfileItems = array();
     if ($profile) {
         $flavorParamsConversionProfileItems = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     }
     foreach ($flavorParamsConversionProfileItems as $flavorParamsConversionProfile) {
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_NO_IMPACT) {
             $inheritedFlavorParamsIds[] = $flavorParamsConversionProfile->getFlavorParamsId();
         }
     }
     $flavorParamsItems = assetParamsPeer::retrieveByPKs($inheritedFlavorParamsIds);
     foreach ($flavorParamsItems as $flavorParams) {
         if ($flavorParams->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     // go over all the flavor assets of the entry
     $inCompleteFlavorIds = array();
     $origianlAssetFlavorId = null;
     $siblingFlavorAssets = assetPeer::retrieveFlavorsByEntryId($currentFlavorAsset->getEntryId());
     foreach ($siblingFlavorAssets as $siblingFlavorAsset) {
         KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] flavor params id [" . $siblingFlavorAsset->getFlavorParamsId() . "]");
         // don't mark any incomplete flag
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ready");
             if (isset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()])) {
                 unset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()]);
             }
             continue;
         }
         $readyBehavior = self::getReadyBehavior($siblingFlavorAsset, $profile);
         if ($siblingFlavorAsset->getStatus() == flavorAsset::ASSET_STATUS_EXPORTING) {
             if ($siblingFlavorAsset->getIsOriginal()) {
                 $origianlAssetFlavorId = $siblingFlavorAsset->getFlavorParamsId();
             } else {
                 if ($readyBehavior != flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
                     KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
                     $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
                 }
             }
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ignored");
             continue;
         }
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
             $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is required");
             $requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("left required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     KalturaLog::debug("left incomplete flavor ids [" . print_r($inCompleteFlavorIds, true) . "]");
     if (count($requiredFlavorParamsIds)) {
         $inCompleteRequiredFlavorParamsIds = array_keys($requiredFlavorParamsIds);
         foreach ($inCompleteRequiredFlavorParamsIds as $inCompleteFlavorId) {
             $inCompleteFlavorIds[] = $inCompleteFlavorId;
         }
         KalturaLog::debug('Convert Finished - has In-Complete Required flavors [[' . print_r($inCompleteRequiredFlavorParamsIds, true) . ']');
     } elseif ($currentFlavorAsset->getStatus() == asset::ASSET_STATUS_READY && ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL || $currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED)) {
         // mark the entry as ready if all required conversions completed or any of the optionals
         if ($currentFlavorAsset->getentry()->getReplacedEntryId()) {
             KalturaLog::debug('Entry is temporary replacement and requires all flavors to complete');
         } else {
             KalturaLog::debug('Mark the entry as ready');
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
         }
     }
     if ($origianlAssetFlavorId) {
         $inCompleteFlavorIds = array_diff($inCompleteFlavorIds, array($origianlAssetFlavorId));
     }
     if (!count($inCompleteFlavorIds)) {
         KalturaLog::debug('Convert Finished');
         if ($origianlAssetFlavorId && $rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
             kStorageExporter::exportSourceAssetFromJob($rootBatchJob);
         } else {
             // mark the context root job as finished only if all conversion jobs are completed
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
             if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
             }
         }
         return $dbBatchJob;
     }
     KalturaLog::debug('Convert Finished - has In-Complete flavors [' . print_r($inCompleteFlavorIds, true) . ']');
     if (!$rootBatchJob || $rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         return $dbBatchJob;
     }
     $childJobs = $rootBatchJob->getChildJobs();
     KalturaLog::debug('Child jobs found [' . count($childJobs) . ']');
     if (count($childJobs) > 1) {
         $allDone = true;
         foreach ($childJobs as $childJob) {
             if ($childJob->getId() != $rootBatchJob->getId() && $childJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED) {
                 KalturaLog::debug('Child job id [' . $childJob->getId() . '] status [' . $childJob->getStatus() . ']');
                 $allDone = false;
             }
         }
         if ($allDone) {
             KalturaLog::debug('All child jobs done, closing profile');
             kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         }
     }
     return $dbBatchJob;
 }
コード例 #3
0
 private static function getSourceFlavorAssets(flavorAsset $flavorAsset, flavorParamsOutput $flavor)
 {
     $srcFlavorParamsIds = explode(',', trim($flavor->getSourceAssetParamsIds()));
     $c = new Criteria();
     $c->add(assetPeer::ENTRY_ID, $flavorAsset->getEntryId());
     $c->add(assetPeer::STATUS, array(flavorAsset::ASSET_STATUS_READY, flavorAsset::ASSET_STATUS_NOT_APPLICABLE, flavorAsset::ASSET_STATUS_EXPORTING), Criteria::IN);
     $c->add(assetPeer::FLAVOR_PARAMS_ID, $srcFlavorParamsIds, Criteria::IN);
     $readyAndNonApplicableAssetsCount = assetPeer::doCount($c);
     KalturaLog::info('Verify source flavors are ready: number of ready and NA assets [' . $readyAndNonApplicableAssetsCount . '], number of source params ids [' . count($srcFlavorParamsIds) . ']');
     if ($readyAndNonApplicableAssetsCount < count($srcFlavorParamsIds)) {
         KalturaLog::info('Not all source flavors are ready, changing status to WAIT_FOR_CONVERT');
         $flavorAsset->setStatus(flavorAsset::ASSET_STATUS_WAIT_FOR_CONVERT);
         $flavorAsset->setDescription("Source flavor assets are not ready");
         $flavorAsset->save();
         return false;
     }
     $srcFlavors = assetPeer::retrieveLocalReadyByEntryIdAndFlavorParams($flavorAsset->getEntryId(), $srcFlavorParamsIds);
     if (!count($srcFlavors)) {
         //assuming all source flavors are Not Applicable
         KalturaLog::log("Flavor [" . $flavorAsset->getFlavorParamsId() . "] is set to N/A since all it's sources are N/A");
         $flavorAsset->setStatus(flavorAsset::ASSET_STATUS_NOT_APPLICABLE);
         $flavorAsset->save();
         return false;
     }
     return $srcFlavors;
 }
コード例 #4
0
ファイル: kJobsManager.php プロジェクト: ace3535/server
 /**
  * @param BatchJob $parentJob
  * @param flavorAsset $asset
  * @param array $files
  * @return BatchJob
  */
 public static function addConcatJob(BatchJob $parentJob = null, flavorAsset $asset, array $files, $offset = null, $duration = null)
 {
     $jobData = new kConcatJobData();
     $jobData->setSrcFiles($files);
     $jobData->setFlavorAssetId($asset->getId());
     $jobData->setOffset($offset);
     $jobData->setDuration($duration);
     $entry = $asset->getentry();
     if ($entry && $entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
         $entry->save();
     }
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONCAT);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setPartnerId($asset->getPartnerId());
     }
     $batchJob->setEntryId($asset->getEntryId());
     $batchJob->setObjectId($jobData->getFlavorAssetId());
     $batchJob->setObjectType(BatchJobObjectType::ASSET);
     return self::addJob($batchJob, $jobData, BatchJobType::CONCAT);
 }
コード例 #5
0
 private function getExternalStorageUrl(Partner $partner, flavorAsset $flavorAsset, FileSyncKey $key)
 {
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
             // check if having file sync on kaltura dcs
             return null;
         }
     }
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key);
     if (!$fileSync) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     if ($this->syndicationFeedDb->getServePlayManifest()) {
         $deliveryProfile = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($storage->getId(), $flavorAsset->getEntryId(), PlaybackProtocol::HTTP, "https"));
         $clientTag = 'feed:' . $this->syndicationFeedDb->getId();
         if (is_null($deliveryProfile)) {
             $url = infraRequestUtils::PROTOCOL_HTTP . "://" . kConf::get("cdn_api_host");
         } else {
             $url = requestUtils::getApiCdnHost();
         }
         $url .= $flavorAsset->getPlayManifestUrl($clientTag, $storage->getId());
     } else {
         $dpda = new DeliveryProfileDynamicAttributes();
         $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $flavorAsset->getEntryId()), null, $flavorAsset);
         $url = ltrim($urlManager->getFileSyncUrl($fileSync), '/');
         if (strpos($url, "://") === false) {
             $url = rtrim($urlManager->getUrl(), "/") . "/" . $url;
         }
     }
     return $url;
 }
 private function getExternalStorageUrl(Partner $partner, flavorAsset $flavorAsset, FileSyncKey $key)
 {
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
             // check if having file sync on kaltura dcs
             return null;
         }
     }
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key);
     if (!$fileSync) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc(), $flavorAsset->getEntryId());
     $urlManager->setFileExtension($flavorAsset->getFileExt());
     $url = $storage->getDeliveryHttpBaseUrl() . '/' . $urlManager->getFileSyncUrl($fileSync);
     return $url;
 }