/** * batch updateExclusiveFileSyncImportJob action updates a BatchJob of type FILESYNC_IMPORT that was claimed using the getExclusiveFileSyncImportJobs * * @action updateExclusiveFileSyncImportJob * @param int $id The id of the job to free * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param KalturaBatchJob $job * @return KalturaBatchJob */ function updateExclusiveFileSyncImportJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job) { $dbBatchJob = BatchJobPeer::retrieveByPK($id); // verifies that the job is of the right type if ($dbBatchJob->getJobType() != KalturaBatchJobType::FILESYNC_IMPORT) { throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job)); } $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob)); $batchJob = new KalturaBatchJob(); // start from blank return $batchJob->fromObject($dbBatchJob); }
/** * batch updateExclusiveVirusScanJob action updates a BatchJob of type VIRUS_SCAN that was claimed using the getExclusiveVirusScanJobs * * @action updateExclusiveVirusScanJob * @param int $id The id of the job to free * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param KalturaBatchJob $job * @return KalturaBatchJob */ function updateExclusiveVirusScanJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job) { $dbBatchJob = BatchJobPeer::retrieveByPK($id); // verifies that the job is of the right type $jobType = VirusScanPlugin::getBatchJobTypeCoreValue(VirusScanBatchJobType::VIRUS_SCAN); if ($dbBatchJob->getJobType() != $jobType) { throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job)); } $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob)); $batchJob = new KalturaBatchJob(); // start from blank return $batchJob->fromObject($dbBatchJob); }
protected function updatedImport(BatchJob $dbBatchJob, kImportJobData $data, BatchJob $twinJob = null) { switch ($dbBatchJob->getStatus()) { case BatchJob::BATCHJOB_STATUS_FINISHED: return kFlowHelper::handleImportFinished($dbBatchJob, $data, $twinJob); case BatchJob::BATCHJOB_STATUS_FAILED: case BatchJob::BATCHJOB_STATUS_FATAL: kBatchManager::updateEntry($dbBatchJob, entryStatus::ERROR_IMPORTING); return $dbBatchJob; default: return $dbBatchJob; } }
/** * will return BatchJob objects. * * @param kExclusiveLockKey $lockKey * @param int $max_execution_time * @param int $number_of_objects * @param int $jobType * @param BatchJobFilter $filter */ public static function getExclusiveJobs(kExclusiveLockKey $lockKey, $max_execution_time, $number_of_objects, $jobType, BatchJobFilter $filter) { $priority = kBatchManager::getNextJobPriority($jobType); $c = new Criteria(); // added to support nfs delay if ($jobType == BatchJobType::EXTRACT_MEDIA || $jobType == BatchJobType::POSTCONVERT || $jobType == BatchJobType::STORAGE_EXPORT) { $c->add(BatchJobPeer::CREATED_AT, time() - 30, Criteria::LESS_THAN); } $c->add(BatchJobPeer::JOB_TYPE, $jobType); $c->add(BatchJobPeer::PRIORITY, $priority, Criteria::GREATER_EQUAL); $filter->attachToCriteria($c); $c->addAscendingOrderByColumn(BatchJobPeer::PRIORITY); $max_exe_attempts = BatchJobPeer::getMaxExecutionAttempts($jobType); return self::getExclusive($c, $lockKey, $max_execution_time, $number_of_objects, $max_exe_attempts); }
/** * batch updateExclusiveDistributionFetchReportJob action updates a BatchJob of type DISTRIBUTION_FETCH_REPORT that was claimed using the getExclusiveDistributionFetchReportJobs * * @action updateExclusiveDistributionFetchReportJob * @param int $id The id of the job to free * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param KalturaBatchJob $job * @return KalturaBatchJob */ function updateExclusiveDistributionFetchReportJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job) { $dbBatchJob = BatchJobPeer::retrieveByPK($id); // verifies that the job is of the right type $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_FETCH_REPORT); if ($dbBatchJob->getJobType() != $jobType) { throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job)); } $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob)); $batchJob = new KalturaBatchJob(); // start from blank return $batchJob->fromObject($dbBatchJob); }
/** * batch reportStatus action saves the a status attribute from a remote scheduler and returns pending commands for the scheduler * * @action reportStatus * @param KalturaScheduler $scheduler The scheduler * @param KalturaSchedulerStatusArray $schedulerStatuses A scheduler status array * @param KalturaWorkerQueueFilterArray $workerQueueFilters Filters list to get queues * @return KalturaSchedulerStatusResponse */ function reportStatusAction(KalturaScheduler $scheduler, KalturaSchedulerStatusArray $schedulerStatuses, KalturaWorkerQueueFilterArray $workerQueueFilters) { $schedulerDb = $this->getOrCreateScheduler($scheduler); $schedulerChanged = false; // saves the statuses to the DB foreach ($schedulerStatuses as $schedulerStatus) { $schedulerStatus->schedulerId = $schedulerDb->getId(); $schedulerStatus->schedulerConfiguredId = $scheduler->configuredId; if ($schedulerStatus->workerConfiguredId) { $worker = $this->getOrCreateWorker($schedulerDb, $schedulerStatus->workerConfiguredId, $schedulerStatus->workerType); $worker->setStatus($schedulerStatus->type, $schedulerStatus->value); $worker->save(); $schedulerStatus->workerId = $worker->getId(); } else { $schedulerChanged = true; $schedulerDb->setStatus($schedulerStatus->type, $schedulerStatus->value); } $schedulerStatusDb = new SchedulerStatus(); $schedulerStatus->toObject($schedulerStatusDb); $schedulerStatusDb->save(); } if ($schedulerChanged) { $schedulerDb->save(); } // creates a response $schedulerStatusResponse = new KalturaSchedulerStatusResponse(); if (kConf::hasParam('batch_enable_control_panel') && kConf::get('batch_enable_control_panel')) { // gets the control pannel commands $c = new Criteria(); $c->add(ControlPanelCommandPeer::SCHEDULER_ID, $schedulerDb->getId()); $c->add(ControlPanelCommandPeer::TYPE, KalturaControlPanelCommandType::CONFIG, Criteria::NOT_EQUAL); $c->add(ControlPanelCommandPeer::STATUS, KalturaControlPanelCommandStatus::PENDING); $commandsList = ControlPanelCommandPeer::doSelect($c); foreach ($commandsList as $command) { $command->setStatus(KalturaControlPanelCommandStatus::HANDLED); $command->save(); } $schedulerStatusResponse->controlPanelCommands = KalturaControlPanelCommandArray::fromDbArray($commandsList, $this->getResponseProfile()); // gets new configs $c = new Criteria(); $c->add(SchedulerConfigPeer::SCHEDULER_ID, $schedulerDb->getId()); $c->add(SchedulerConfigPeer::COMMAND_STATUS, KalturaControlPanelCommandStatus::PENDING); $configList = SchedulerConfigPeer::doSelect($c); foreach ($configList as $config) { $config->setCommandStatus(KalturaControlPanelCommandStatus::HANDLED); $config->save(); } $schedulerStatusResponse->schedulerConfigs = KalturaSchedulerConfigArray::fromDbArray($configList, $this->getResponseProfile()); } else { $schedulerStatusResponse->controlPanelCommands = new KalturaControlPanelCommandArray(); $schedulerStatusResponse->schedulerConfigs = new KalturaSchedulerConfigArray(); } // gets queues length $schedulerStatusResponse->queuesStatus = new KalturaBatchQueuesStatusArray(); foreach ($workerQueueFilters as $workerQueueFilter) { $dbJobType = kPluginableEnumsManager::apiToCore('BatchJobType', $workerQueueFilter->jobType); $filter = $workerQueueFilter->filter->toFilter($dbJobType); $batchQueuesStatus = new KalturaBatchQueuesStatus(); $batchQueuesStatus->jobType = $workerQueueFilter->jobType; $batchQueuesStatus->workerId = $workerQueueFilter->workerId; $batchQueuesStatus->size = kBatchManager::getQueueSize($workerQueueFilter->schedulerId, $workerQueueFilter->workerId, $dbJobType, $filter); $schedulerStatusResponse->queuesStatus[] = $batchQueuesStatus; } return $schedulerStatusResponse; }
public static function decideProfileFlavorsConvert(BatchJob $parentJob, BatchJob $convertProfileJob, array $flavors, array $conversionProfileFlavorParams, mediaInfo $mediaInfo = null) { $entryId = $convertProfileJob->getEntryId(); $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); return false; } $errDescription = null; $finalFlavors = self::validateConversionProfile($convertProfileJob->getPartnerId(), $entryId, $mediaInfo, $flavors, $conversionProfileFlavorParams, $errDescription); KalturaLog::log(count($finalFlavors) . " flavors returned from the decision layer"); if (is_null($finalFlavors)) { $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription); KalturaLog::log("No flavors created"); throw new Exception($errDescription); } if (strlen($errDescription)) { $err = $convertProfileJob->getDescription() . $errDescription; $convertProfileJob->setDescription($err); $convertProfileJob->save(); } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $conversionsCreated = 0; $entry = $convertProfileJob->getEntry(); if (!$entry) { throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId); } $flavorsCollections = array(); // create a convert job per each flavor foreach ($finalFlavors as $flavor) { $flavorAsset = kBatchManager::createFlavorAsset($flavor, $entry->getPartnerId(), $entry->getId()); if (!$flavorAsset) { KalturaLog::log("Flavor asset could not be created, flavor conversion won't be created"); continue; } $collectionTag = $flavor->getCollectionTag(); if ($collectionTag) { $flavorsCollections[$collectionTag][] = $flavor; continue; } KalturaLog::log("Adding flavor conversion with flavor params output id [" . $flavor->getId() . "] and flavor params asset id [" . $flavorAsset->getId() . "]"); $madiaInfoId = $mediaInfo ? $mediaInfo->getId() : null; $createdJob = kJobsManager::addFlavorConvertJob($srcSyncKey, $flavor, $flavorAsset->getId(), $madiaInfoId, $parentJob); if ($createdJob) { $conversionsCreated++; } } foreach ($flavorsCollections as $tag => $flavors) { switch ($tag) { case flavorParams::TAG_ISM: $createdJob = kJobsManager::addConvertIsmCollectionJob($tag, $srcSyncKey, $entry, $parentJob, $flavors); if ($createdJob) { $conversionsCreated++; } break; default: KalturaLog::log("Error: Invalid collection tag [{$tag}]"); break; } } if (!$conversionsCreated) { $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription); KalturaLog::log("No flavors created: {$errDescription}"); return false; } return true; }
public static function handleProvisionProvideFailed(BatchJob $dbBatchJob, kProvisionJobData $data, BatchJob $twinJob = null) { kBatchManager::updateEntry($dbBatchJob, entryStatus::ERROR_CONVERTING); return $dbBatchJob; }
/** * batch cleanExclusiveJobs action mark as fatal error all expired jobs * @action cleanExclusiveJobs * @return int the count of jobs that cleaned */ function cleanExclusiveJobsAction() { return kBatchManager::cleanExclusiveJobs(); }
public static function handleConvertFailed(BatchJob $dbBatchJob, $engineType, $flavorAssetId, $flavorParamsOutputId, $mediaInfoId) { $flavorAsset = assetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); // try to create a convert job with the next engine if (!is_null($engineType)) { $data = $dbBatchJob->getData(); if ($data instanceof kConvartableJobData) { $data->incrementOperationSet(); $dbBatchJob->setData($data); $dbBatchJob->save(); } $newDbBatchJob = kBusinessPreConvertDL::redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, $dbBatchJob, $engineType); if ($newDbBatchJob) { return true; } } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); if (!$rootBatchJob) { return false; } // the root is already failed if ($rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) { return false; } // bulk download root job no need to handle if ($rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } if (is_null($flavorParamsOutputId)) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } $readyBehavior = $dbBatchJob->getData()->getReadyBehavior(); if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } // failing the root profile job if all child jobs failed if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } $siblingJobs = $rootBatchJob->getChildJobs(); foreach ($siblingJobs as $siblingJob) { /* @var $siblingJob BatchJob */ // not conversion job and should be ignored if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) { continue; } $jobData = $siblingJob->getData(); if (!$jobData || !$jobData instanceof kConvertJobData && !$jobData instanceof kPostConvertJobData) { KalturaLog::err("Job id [" . $siblingJob->getId() . "] has no valid job data"); continue; } // found child flavor asset that hasn't failed, no need to fail the root job $siblingFlavorAssetId = $jobData->getFlavorAssetId(); $siblingFlavorAsset = assetPeer::retrieveById($siblingFlavorAssetId); if ($siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_ERROR && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return false; } } // all conversions failed, should fail the root job kJobsManager::failBatchJob($rootBatchJob, "All conversions failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; }
private static function setError($errDescription, BatchJob $batchJob, $batchJobType, $entryId) { $batchJob = kJobsManager::failBatchJob($batchJob, $errDescription, $batchJobType); kBatchManager::updateEntry($entryId, entryStatus::ERROR_CONVERTING); KalturaLog::err($errDescription); }
/** * @param BatchJob $batchJob * @param $data * @param int $type * @param int $subType * @return BatchJob */ public static function addJob(BatchJob $batchJob, kJobData $data, $type, $subType = null) { $batchJob->setJobType($type); $batchJob->setJobSubType($subType); $batchJob->setData($data); if (!$batchJob->getParentJobId() && $batchJob->getEntryId()) { $currentJob = kBatchManager::getCurrentUpdatingJob(); if ($currentJob && $currentJob->getEntryId() == $batchJob->getEntryId()) { $batchJob->setParentJobId($currentJob->getId()); $batchJob->setBulkJobId($currentJob->getBulkJobId()); $batchJob->setRootJobId($currentJob->getRootJobId()); } else { $entry = entryPeer::retrieveByPKNoFilter($batchJob->getEntryId()); // some jobs could be on deleted entry if ($entry) { $batchJob->setRootJobId($entry->getBulkUploadId()); $batchJob->setBulkJobId($entry->getBulkUploadId()); } } } $lockInfo = new kLockInfoData($batchJob); $lockInfo->setEstimatedEffort($data->calculateEstimatedEffort($batchJob)); $lockInfo->setPriority($data->calculatePriority($batchJob)); $lockInfo->setUrgency($data->calculateUrgency($batchJob)); $batchJob->setLockInfo($lockInfo); if (is_null($batchJob->getStatus())) { $batchJob = self::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING); } else { $batchJob = self::updateBatchJob($batchJob, $batchJob->getStatus()); } return $batchJob; }
public static function handleConvertFailed(BatchJob $dbBatchJob, $engineType, $flavorAssetId, $flavorParamsOutputId, $mediaInfoId) { $flavorAsset = assetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } /* * On Webex error, roll back the inter-src asset version in order to allow the retry to get ARF as a source, * rather than the invlaid WMV file (product of bad nbrplayer session) */ if ($dbBatchJob->getErrNumber() == BatchJobAppErrors::BLACK_OR_SILENT_CONTENT) { $prevVer = $flavorAsset->getPreviousVersion(); $currVer = $flavorAsset->getVersion(); KalturaLog::log("Webex conversion - Garbled Audio or Black frame or Silence. Rolling back asset/file-sync version - curr({$currVer}), prev({$prevVer})"); if (isset($prevVer)) { $syncKey = $flavorAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $currVer); if (isset($syncKey)) { kFileSyncUtils::deleteSyncFileForKey($syncKey, false, true); $flavorAsset->setVersion($prevVer); $flavorAsset->setPreviousVersion(null); KalturaLog::log("Webex conversion - Rolled back"); } } } $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); // try to create a convert job with the next engine if (!is_null($engineType)) { $data = $dbBatchJob->getData(); if ($data instanceof kConvartableJobData) { $data->incrementOperationSet(); $dbBatchJob->setData($data); $dbBatchJob->save(); } $newDbBatchJob = kBusinessPreConvertDL::redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, $dbBatchJob, $engineType); if ($newDbBatchJob) { return true; } } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); if (!$rootBatchJob) { return false; } // the root is already failed if ($rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) { return false; } // bulk download root job no need to handle if ($rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } if (is_null($flavorParamsOutputId)) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } $readyBehavior = $dbBatchJob->getData()->getReadyBehavior(); if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } // failing the root profile job if all child jobs failed if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } $siblingJobs = $rootBatchJob->getChildJobs(); foreach ($siblingJobs as $siblingJob) { /* @var $siblingJob BatchJob */ // not conversion job and should be ignored if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) { continue; } $jobData = $siblingJob->getData(); if (!$jobData || !$jobData instanceof kConvertJobData && !$jobData instanceof kPostConvertJobData) { KalturaLog::err("Job id [" . $siblingJob->getId() . "] has no valid job data"); continue; } // found child flavor asset that hasn't failed, no need to fail the root job $siblingFlavorAssetId = $jobData->getFlavorAssetId(); $siblingFlavorAsset = assetPeer::retrieveById($siblingFlavorAssetId); if ($siblingFlavorAsset && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_ERROR && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return false; } } // all conversions failed, should fail the root job kJobsManager::failBatchJob($rootBatchJob, "All conversions failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; }
/** * Common to all the jobs using the BatchJob table * * @param unknown_type $id * @param kExclusiveLockKey $lockKey * @param BatchJob $dbBatchJob * @return Ambigous <BatchJob, NULL, unknown, multitype:> */ public static function updateExclusiveBatchJob($id, kExclusiveLockKey $lockKey, BatchJob $dbBatchJob) { self::$currentUpdatingJob = $dbBatchJob; $dbBatchJob = kBatchExclusiveLock::updateExclusive($id, $lockKey, $dbBatchJob); $event = new kBatchJobStatusEvent($dbBatchJob); kEventsManager::raiseEvent($event); $dbBatchJob->reload(); return $dbBatchJob; }
/** * @param UploadToken $uploadToken */ public static function handleUploadFinished(UploadToken $uploadToken) { if (!is_subclass_of($uploadToken->getObjectType(), assetPeer::OM_CLASS) && $uploadToken->getObjectType() != FileAssetPeer::OM_CLASS && $uploadToken->getObjectType() != entryPeer::OM_CLASS) { KalturaLog::info("Class [" . $uploadToken->getObjectType() . "] not supported"); return; } $fullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadToken->getId()); if (!file_exists($fullPath)) { KalturaLog::info("File path [{$fullPath}] not found"); $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadToken->getId(), kDataCenterMgr::getCurrentDcId()); if (!$remoteDCHost) { KalturaLog::err("File path [{$fullPath}] could not be redirected"); return; } kFileUtils::dumpApiRequest($remoteDCHost); } if ($uploadToken->getObjectType() == FileAssetPeer::OM_CLASS) { $dbFileAsset = FileAssetPeer::retrieveByPK($uploadToken->getObjectId()); if (!$dbFileAsset) { KalturaLog::err("File asset id [" . $uploadToken->getObjectId() . "] not found"); return; } if (!$dbFileAsset->getFileExt()) { $dbFileAsset->setFileExt(pathinfo($fullPath, PATHINFO_EXTENSION)); } $dbFileAsset->incrementVersion(); $dbFileAsset->save(); $syncKey = $dbFileAsset->getSyncKey(FileAsset::FILE_SYNC_ASSET); try { kFileSyncUtils::moveFromFile($fullPath, $syncKey, true); } catch (Exception $e) { $dbFileAsset->setStatus(FileAssetStatus::ERROR); $dbFileAsset->save(); throw $e; } if ($dbFileAsset->getStatus() == FileAssetStatus::UPLOADING) { $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); $dbFileAsset->setSize(kFile::fileSize($finalPath)); $dbFileAsset->setStatus(FileAssetStatus::READY); $dbFileAsset->save(); } $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED); $uploadToken->save(); KalturaLog::info("File asset [" . $dbFileAsset->getId() . "] handled"); return; } if (is_subclass_of($uploadToken->getObjectType(), assetPeer::OM_CLASS)) { $dbAsset = assetPeer::retrieveById($uploadToken->getObjectId()); if (!$dbAsset) { KalturaLog::err("Asset id [" . $uploadToken->getObjectId() . "] not found"); return; } $ext = pathinfo($fullPath, PATHINFO_EXTENSION); $dbAsset->setFileExt($ext); $dbAsset->incrementVersion(); $dbAsset->save(); $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); try { kFileSyncUtils::moveFromFile($fullPath, $syncKey, true); } catch (Exception $e) { if ($dbAsset instanceof flavorAsset) { kBatchManager::updateEntry($dbAsset->getEntryId(), entryStatus::ERROR_IMPORTING); } $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $dbAsset->save(); throw $e; } if ($dbAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING) { $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); $dbAsset->setSize(kFile::fileSize($finalPath)); if ($dbAsset instanceof flavorAsset) { if ($dbAsset->getIsOriginal()) { $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED); } else { $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING); } } else { $dbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY); } if ($dbAsset instanceof thumbAsset) { list($width, $height, $type, $attr) = getimagesize($finalPath); $dbAsset->setWidth($width); $dbAsset->setHeight($height); } $dbAsset->save(); kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset)); } $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED); $uploadToken->save(); } if ($uploadToken->getObjectType() == entryPeer::OM_CLASS) { $dbEntry = entryPeer::retrieveByPK($uploadToken->getObjectId()); if (!$dbEntry) { KalturaLog::err("Entry id [" . $uploadToken->getObjectId() . "] not found"); return; } //Keep original extention $ext = pathinfo($fullPath, PATHINFO_EXTENSION); // increments version $dbEntry->setData('100000.' . $ext); $dbEntry->save(); $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); try { kFileSyncUtils::moveFromFile($fullPath, $syncKey, true); } catch (Exception $e) { if ($dbAsset instanceof flavorAsset) { kBatchManager::updateEntry($dbEntry->getId(), entryStatus::ERROR_IMPORTING); } throw $e; } $dbEntry->setStatus(entryStatus::READY); $dbEntry->save(); $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED); $uploadToken->save(); } }
/** * @param BatchJob $batchJob * @param $data * @param int $type * @param int $subType * @return BatchJob */ public static function addJob(BatchJob $batchJob, $data, $type, $subType = null) { $batchJob->setJobType($type); $batchJob->setJobSubType($subType); $batchJob->setData($data); if (!$batchJob->getParentJobId() && $batchJob->getEntryId()) { $currentJob = kBatchManager::getCurrentUpdatingJob(); if ($currentJob && $currentJob->getEntryId() == $batchJob->getEntryId()) { $batchJob->setParentJobId($currentJob->getId()); $batchJob->setBulkJobId($currentJob->getBulkJobId()); $batchJob->setRootJobId($currentJob->getRootJobId()); } else { $entry = entryPeer::retrieveByPKNoFilter($batchJob->getEntryId()); // some jobs could be on deleted entry if ($entry) { $batchJob->setRootJobId($entry->getBulkUploadId()); $batchJob->setBulkJobId($entry->getBulkUploadId()); } } } // validate partner id $partnerId = $batchJob->getPartnerId(); // if(!$partnerId) // throw new APIException(APIErrors::PARTNER_NOT_SET); // validate that partner exists $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { KalturaLog::err("Invalid partner id [{$partnerId}]"); throw new APIException(APIErrors::INVALID_PARTNER_ID, $partnerId); } // set the priority and work group $batchJob->setPriority($partner->getPriority($batchJob->getBulkJobId())); $batchJob = self::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING); // look for identical jobs $twinJobs = BatchJobPeer::retrieveDuplicated($type, $data); $twinJob = null; if (count($twinJobs)) { foreach ($twinJobs as $currentTwinJob) { if ($currentTwinJob->getId() != $batchJob->getId()) { $twinJob = reset($twinJobs); } } } if (!is_null($twinJob)) { $batchJob->setTwinJobId($twinJob->getId()); if (!kConf::get("batch_ignore_duplication")) { $batchJob = self::updateBatchJob($batchJob, $twinJob->getStatus(), $twinJob); } else { $batchJob->save(); } } return $batchJob; }