protected function handleResults(array $results, array $items) { //Added to support cases where the resource is entry resource $conversionProfileId = null; try { KBatchBase::impersonate($this->xmlBulkUploadEngine->getCurrentPartnerId()); $entry = KBatchBase::$kClient->baseEntry->get($this->entryId); KBatchBase::unimpersonate(); if ($entry && $entry->conversionProfileId) { $conversionProfileId = $entry->conversionProfileId; } } catch (Exception $ex) { KBatchBase::unimpersonate(); KalturaLog::info("Entry ID [" . $this->entryId . "] not found, continuing with no conversion profile"); } foreach ($results as $index => $cuePoint) { if ($cuePoint instanceof KalturaThumbCuePoint) { if (!isset($items[$index]->slide) || empty($items[$index]->slide)) { continue; } $timedThumbResource = $this->xmlBulkUploadEngine->getResource($items[$index]->slide, $conversionProfileId); $thumbAsset = new KalturaTimedThumbAsset(); $thumbAsset->cuePointId = $cuePoint->id; KBatchBase::impersonate($this->xmlBulkUploadEngine->getCurrentPartnerId()); KBatchBase::$kClient->startMultiRequest(); KBatchBase::$kClient->thumbAsset->add($cuePoint->entryId, $thumbAsset); KBatchBase::$kClient->thumbAsset->setContent(KBatchBase::$kClient->getMultiRequestResult()->id, $timedThumbResource); KBatchBase::$kClient->doMultiRequest(); KBatchBase::unimpersonate(); } } return parent::handleResults($results, $items); }
/** * @param KalturaFilter $filter The filter should return the list of objects that need to be reindexed * @param bool $shouldUpdate Indicates that the object columns and attributes values should be recalculated before reindexed * @return int the number of indexed objects */ public function run(KalturaFilter $filter) { KBatchBase::impersonate($this->partnerId); $ret = $this->delete($filter); KBatchBase::unimpersonate(); return $ret; }
public function run($jobs = null) { if (KBatchBase::$taskConfig->isInitOnly()) { return $this->init(); } if (is_null($jobs)) { $jobs = KBatchBase::$kClient->batch->getExclusiveAlmostDone($this->getExclusiveLockKey(), KBatchBase::$taskConfig->maximumExecutionTime, $this->getMaxJobsEachRun(), $this->getFilter(), static::getType()); } KalturaLog::info(count($jobs) . " jobs to close"); if (!count($jobs) > 0) { KalturaLog::info("Queue size: 0 sent to scheduler"); $this->saveSchedulerQueue(static::getType()); return null; } foreach ($jobs as &$job) { try { self::setCurrentJob($job); $job = $this->exec($job); } catch (KalturaException $kex) { KBatchBase::unimpersonate(); $job = $this->closeJob($job, KalturaBatchJobErrorTypes::KALTURA_API, $kex->getCode(), "Error: " . $kex->getMessage(), KalturaBatchJobStatus::FAILED); } catch (KalturaClientException $kcex) { KBatchBase::unimpersonate(); $job = $this->closeJob($job, KalturaBatchJobErrorTypes::KALTURA_CLIENT, $kcex->getCode(), "Error: " . $kcex->getMessage(), KalturaBatchJobStatus::RETRY); } catch (Exception $ex) { KBatchBase::unimpersonate(); $job = $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED); } self::unsetCurrentJob(); } return $jobs; }
private function syncCategoryPrivacyContext(KalturaBatchJob $job, KalturaSyncCategoryPrivacyContextJobData $data, $categoryId) { $categoryEntryPager = $this->getFilterPager(); $categoryEntryFilter = new KalturaCategoryEntryFilter(); $categoryEntryFilter->orderBy = KalturaCategoryEntryOrderBy::CREATED_AT_ASC; $categoryEntryFilter->categoryIdEqual = $categoryId; if ($data->lastUpdatedCategoryEntryCreatedAt) { $categoryEntryFilter->createdAtGreaterThanOrEqual = $data->lastUpdatedCategoryEntryCreatedAt; } $categoryEntryList = KBatchBase::$kClient->categoryEntry->listAction($categoryEntryFilter, $categoryEntryPager); while (count($categoryEntryList->objects)) { KBatchBase::$kClient->startMultiRequest(); foreach ($categoryEntryList->objects as $categoryEntry) { KalturaLog::debug('entryId ' . $categoryEntry->entryId . ' categoryId ' . $categoryEntry->categoryId); KBatchBase::$kClient->categoryEntry->syncPrivacyContext($categoryEntry->entryId, $categoryEntry->categoryId); } KBatchBase::$kClient->doMultiRequest(); $data->lastUpdatedCategoryEntryCreatedAt = $categoryEntry->createdAt; $categoryEntryPager->pageIndex++; KBatchBase::unimpersonate(); $this->updateJob($job, null, KalturaBatchJobStatus::PROCESSING, $data); KBatchBase::impersonate($job->partnerId); $categoryEntryList = KBatchBase::$kClient->categoryEntry->listAction($categoryEntryFilter, $categoryEntryPager); } }
protected function getCmdLine() { $cmdLine = parent::getCmdLine(); $cmdLine = KConversionEngineFfmpeg::experimentalFixing($cmdLine, $this->data->flavorParamsOutput, $this->cmd, $this->inFilePath, $this->outFilePath); $cmdLine = KConversionEngineFfmpeg::expandForcedKeyframesParams($cmdLine); $wmStr = strstr($this->operator->params, "watermark:"); if ($wmStr == false) { return $cmdLine; } $wmStr = trim(substr($this->operator->params, strlen("watermark:"))); /* * If no watermarkData, carry on */ if ($wmStr == null) { return $cmdLine; } KalturaLog::log("Watermark string({$wmStr})"); $wmData = json_decode($wmStr); if (!isset($wmData)) { KalturaLog::err("Bad watermark JSON string({$wmStr}), carry on without watermark"); } KalturaLog::log("Watermark data:\n" . print_r($wmData, 1)); // impersonite KBatchBase::impersonate($this->data->flavorParamsOutput->partnerId); // !!!!!!!!!!!$this->job->partnerId); $wmCmdLine = KConversionEngineFfmpeg::buildWatermarkedCommandLine($wmData, $this->data->destFileSyncLocalPath, $cmdLine, KBatchBase::$taskConfig->params->ffmpegCmd, KBatchBase::$taskConfig->params->mediaInfoCmd); // un-impersonite KBatchBase::unimpersonate(); if (isset($wmCmdLine)) { $cmdLine = $wmCmdLine; } return $cmdLine; }
/** * @param KalturaFilter $filter The filter should return the list of objects that need to be reindexed * @param bool $shouldUpdate Indicates that the object columns and attributes values should be recalculated before reindexed * @return int the number of indexed objects */ public function run(KalturaFilter $filter, $shouldUpdate) { KBatchBase::impersonate($this->partnerId); $ret = $this->index($filter, $shouldUpdate); KBatchBase::unimpersonate(); return $ret; }
/** * @param KalturaFilter $filter The filter should return the list of objects that need to be copied * @param KalturaObjectBase $templateObject Template object to overwrite attributes on the copied object * @return int the number of copied objects */ public function run(KalturaFilter $filter, KalturaObjectBase $templateObject) { KBatchBase::impersonate($this->partnerId); $ret = $this->copy($filter, $templateObject); KBatchBase::unimpersonate(); return $ret; }
protected function getCmdLine() { $exeCmd = parent::getCmdLine(); if (strstr($exeCmd, KDLOperatorMp4box::ACTION_EMBED_SUBTITLES) !== FALSE) { $captionsStr = null; // impersonite KBatchBase::impersonate($this->job->partnerId); $captionsStr = $this->buildSubTitleCommandParam($this->data); // un-impersonite KBatchBase::unimpersonate(); if (isset($captionsStr)) { $exeCmd = str_replace(array(KDLOperatorMp4box::ACTION_EMBED_SUBTITLES, KDLOperatorMp4box::SUBTITLE_PLACEHOLDER), array("", $captionsStr), $exeCmd); } else { if (!(isset($this->operator) && isset($this->operator->isOptional) && $this->operator->isOptional > 0)) { $this->message .= "." . print_r($this->operator, 1); throw new KOperationEngineException($this->message); } } } else { if (strstr($exeCmd, KDLOperatorMp4box::ACTION_HINT) !== FALSE) { $exeCmd = str_replace(KDLOperatorMp4box::ACTION_HINT, "", $exeCmd); } } return $exeCmd; }
protected function doOperation() { KalturaLog::debug("starting"); KBatchBase::impersonate($this->job->partnerId); $drmPlugin = KalturaDrmClientPlugin::get(KBatchBase::$kClient); $profile = $drmPlugin->drmProfile->getByProvider(KalturaDrmProviderType::CENC); KBatchBase::unimpersonate(); $udrmData = $this->getUDRMdata($profile->licenseServerUrl, $profile->signingKey); if (!isset($this->data->srcFileSyncs) || !isset($this->data->srcFileSyncs[0])) { $logMsg = "Did not get input file"; KalturaLog::err($logMsg); throw new KOperationEngineException($logMsg); } $encryptResult = $this->encryptWithEdash($udrmData); $mpdResult = $this->createMPD(); $mpdOutPath = $this->data->destFileSyncLocalPath . ".mpd"; $fsDescArr = array(); $fsDesc = new KalturaDestFileSyncDescriptor(); $fsDesc->fileSyncLocalPath = $mpdOutPath; $fsDesc->fileSyncObjectSubType = 7; //FILE_SYNC_ASSET_SUB_TYPE_MPD; $fsDescArr[] = $fsDesc; $this->data->extraDestFileSyncs = $fsDescArr; return true; }
/** * Execute register asset with new details to update exisiting asset * * @param int $assetId * @param string $licenseStartDate * @param string $licenseEndDate * @throws kApplicativeException */ private function updateWidevineAsset($assetId, $licenseStartDate, $licenseEndDate, $profile) { KalturaLog::debug("Update asset [" . $assetId . "] license start date [" . $licenseStartDate . '] license end date [' . $licenseEndDate . ']'); $errorMessage = ''; $wvAssetId = KWidevineBatchHelper::sendRegisterAssetRequest($profile->regServerHost, null, $assetId, $profile->portal, null, $licenseStartDate, $licenseEndDate, $profile->iv, $profile->key, $errorMessage); if (!$wvAssetId) { KBatchBase::unimpersonate(); $logMessage = 'Asset update failed, asset id: ' . $assetId . ' error: ' . $errorMessage; KalturaLog::err($logMessage); throw new kApplicativeException(null, $logMessage); } }
protected function getFilter() { $filter = parent::getFilter(); $filter->jobSubTypeIn = $this->getSupportedProtocols(); if ($this->taskConfig->params->minFileSize && is_numeric($this->taskConfig->params->minFileSize)) { $filter->fileSizeGreaterThan = $this->taskConfig->params->minFileSize; } if ($this->taskConfig->params->maxFileSize && is_numeric($this->taskConfig->params->maxFileSize)) { $filter->fileSizeLessThan = $this->taskConfig->params->maxFileSize; } return $filter; }
/** * */ protected function getExecutionCommandAndConversionString(KalturaConvertJobData $data) { $wmData = null; if (isset($data->flavorParamsOutput->watermarkData)) { $wmData = json_decode($data->flavorParamsOutput->watermarkData); if (!isset($wmData)) { KalturaLog::err("Bad watermark JSON string({$data->flavorParamsOutput}->watermarkData), carry on without watermark"); } } $cmdLines = parent::getExecutionCommandAndConversionString($data); KalturaLog::log("cmdLines==>" . print_r($cmdLines, 1)); /* * The code below handles the ffmpeg 0.10 and higher option to set up 'forced_key_frame'. * The ffmpeg cmd-line should contain list of all forced kf's, this list might be up to 40Kb for 2hr videos. * Since the cmd-lines are stored in db records (flavor_params_output), it would blow it up. * The solution is to setup a placeholer w/duration and step, the full cmd-line is generated over here * just before the activation. * Sample: * __forceKeyframes__462_2 * stands for duration of 462 seconds, gop size 2 seconds */ foreach ($cmdLines as $k => $cmdLine) { $exec_cmd = self::experimentalFixing($cmdLine->exec_cmd, $data->flavorParamsOutput, $this->getCmd(), $this->inFilePath, $this->outFilePath); $exec_cmd = self::expandForcedKeyframesParams($exec_cmd); if (strstr($exec_cmd, "ffmpeg") == false) { $cmdLines[$k]->exec_cmd = $exec_cmd; continue; } // impersonite KBatchBase::impersonate($data->flavorParamsOutput->partnerId); $wmCmdLine = null; if (isset($wmData)) { $wmCmdLine = self::buildWatermarkedCommandLine($wmData, $data->destFileSyncLocalPath, $exec_cmd, KBatchBase::$taskConfig->params->ffmpegCmd, KBatchBase::$taskConfig->params->mediaInfoCmd); } /* * 'watermark_pair_'/TAG_VARIANT_PAIR_ID tag for NGS digital signature watermarking flow */ if (isset($data->flavorParamsOutput->tags) && strstr($data->flavorParamsOutput->tags, KConversionEngineFfmpeg::TAG_VARIANT_PAIR_ID) != false) { $wmCmdLine = self::buildNGSPairedDigitalWatermarkingCommandLine(isset($wmCmdLine) ? $wmCmdLine : $exec_cmd, $data); } // un-impersonite KBatchBase::unimpersonate(); if (isset($wmCmdLine)) { $cmdLines[$k]->exec_cmd = $wmCmdLine; } else { $cmdLines[$k]->exec_cmd = $exec_cmd; } } return $cmdLines; }
protected function createCsv(KalturaBatchJob $job, KalturaLiveReportExportJobData $data) { $partnerId = $job->partnerId; $type = $job->jobSubType; // Create local path for report generation $data->outputPath = self::$taskConfig->params->localTempPath . DIRECTORY_SEPARATOR . $partnerId; KBatchBase::createDir($data->outputPath); // Generate report KBatchBase::impersonate($job->partnerId); $exporter = LiveReportFactory::getExporter($type, $data); $reportFile = $exporter->run(); $this->setFilePermissions($reportFile); KBatchBase::unimpersonate(); // Copy the report to shared location. $this->moveFile($job, $data, $partnerId); return $job; }
public function processFolder(KalturaBatchJob $job, KalturaDropFolderContentProcessorJobData $data) { KBatchBase::impersonate($job->partnerId); /* @var $data KalturaWebexDropFolderContentProcessorJobData */ $dropFolder = $this->dropFolderPlugin->dropFolder->get($data->dropFolderId); //In the case of the webex drop folder engine, the only possible contentMatch policy is ADD_AS_NEW. //Any other policy should cause an error. switch ($data->contentMatchPolicy) { case KalturaDropFolderContentFileHandlerMatchPolicy::ADD_AS_NEW: $this->addAsNewContent($job, $data, $dropFolder); break; default: throw new kApplicativeException(KalturaDropFolderErrorCode::DROP_FOLDER_APP_ERROR, 'Content match policy not allowed for Webex drop folders'); break; } KBatchBase::unimpersonate(); }
public function doRecalculate(KalturaRecalculateResponseProfileCacheJobData $data) { $job = KJobHandlerWorker::getCurrentJob(); KBatchBase::impersonate($job->partnerId); $partner = KBatchBase::$kClient->partner->get($job->partnerId); KBatchBase::unimpersonate(); $role = reset($data->userRoles); /* @var $role KalturaIntegerValue */ $privileges = array('setrole:' . $role->value, 'disableentitlement'); $privileges = implode(',', $privileges); $client = new KalturaClient(KBatchBase::$kClientConfig); $ks = $client->generateSession($partner->adminSecret, 'batchUser', $data->ksType, $job->partnerId, 86400, $privileges); $client->setKs($ks); $options = new KalturaResponseProfileCacheRecalculateOptions(); $options->limit = $this->maxCacheObjectsPerRequest; $options->cachedObjectType = $data->cachedObjectType; $options->objectId = $data->objectId; $options->startObjectKey = $data->startObjectKey; $options->endObjectKey = $data->endObjectKey; $options->jobCreatedAt = $job->createdAt; $options->isFirstLoop = true; $recalculated = 0; try { do { $results = $client->responseProfile->recalculate($options); $recalculated += $results->recalculated; $options->startObjectKey = $results->lastObjectKey; $options->isFirstLoop = false; } while ($results->lastObjectKey); } catch (KalturaException $e) { if ($e->getCode() != self::RESPONSE_PROFILE_CACHE_ALREADY_RECALCULATED && $e->getCode() != self::RESPONSE_PROFILE_CACHE_RECALCULATE_RESTARTED) { throw $e; } KalturaLog::err($e); } return $recalculated; }
public function processFolder(KalturaBatchJob $job, KalturaDropFolderContentProcessorJobData $data) { KBatchBase::impersonate($job->partnerId); /* @var $data KalturaWebexDropFolderContentProcessorJobData */ $dropFolder = $this->dropFolderPlugin->dropFolder->get($data->dropFolderId); switch ($data->contentMatchPolicy) { case KalturaDropFolderContentFileHandlerMatchPolicy::ADD_AS_NEW: $this->addAsNewContent($job, $data, $dropFolder); break; case KalturaDropFolderContentFileHandlerMatchPolicy::MATCH_EXISTING_OR_KEEP_IN_FOLDER: $this->addAsExistingContent($job, $data, null, $dropFolder); break; case KalturaDropFolderContentFileHandlerMatchPolicy::MATCH_EXISTING_OR_ADD_AS_NEW: $matchedEntry = $this->isEntryMatch($data); if ($matchedEntry) { $this->addAsExistingContent($job, $data, $matchedEntry, $dropFolder); } else { $this->addAsNewContent($job, $data, $dropFolder); } break; default: throw new kApplicativeException(KalturaDropFolderErrorCode::CONTENT_MATCH_POLICY_UNDEFINED, 'No content match policy is defined for drop folder'); break; } KBatchBase::unimpersonate(); }
/** * Inits the array of storage profile to Id (with all given flavor params) */ protected function initStorageProfileNameToId() { $pager = new KalturaFilterPager(); $pager->pageSize = 500; KBatchBase::impersonate($this->currentPartnerId); $allStorageProfiles = KBatchBase::$kClient->storageProfile->listAction(null, $pager); KBatchBase::unimpersonate(); $allStorageProfiles = $allStorageProfiles->objects; // KalturaLog::debug("allStorageProfiles [" . print_r($allStorageProfiles,true) ." ]"); foreach ($allStorageProfiles as $storageProfile) { if ($storageProfile->systemName) { $this->storageProfileNameToId["{$storageProfile->systemName}"] = $storageProfile->id; } else { //NO system name so we add them to a default name $this->storageProfileNameToId["No system name " . "{$storageProfile->id}"] = $storageProfile->id; } } // KalturaLog::debug("new storageProfileNameToId [" . print_r($this->storageProfileNameToId, true). "]"); }
/** * @param int $partnerId * @param string $entryId * @param string $assetIds comma seperated * @return array<KalturaCaptionAsset> */ protected function getCaptionAssets($partnerId, $entryId, $assetIds) { KBatchBase::impersonate($partnerId); $filter = new KalturaCaptionAssetFilter(); $filter->entryIdEqual = $entryId; $filter->idIn = $assetIds; $captionPlugin = KalturaCaptionClientPlugin::get(KBatchBase::$kClient); $assetsList = $captionPlugin->captionAsset->listAction($filter); KBatchBase::unimpersonate(); return $assetsList->objects; }
function export() { if (!KBatchBase::pollingFileExists($this->srcFile)) { throw new kTemporaryException("Source file {$this->srcFile} does not exist"); } $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $engineOptions['passiveMode'] = $this->data->ftpPassiveMode; $engineOptions['createLink'] = $this->data->createLink; if ($this->data instanceof KalturaAmazonS3StorageExportJobData) { $engineOptions['filesAcl'] = $this->data->filesPermissionInS3; $engineOptions['s3Region'] = $this->data->s3Region; } $engine = kFileTransferMgr::getInstance($this->protocol, $engineOptions); try { $keyPairLogin = false; if ($this->protocol == KalturaStorageProfileProtocol::SFTP) { $keyPairLogin = $this->data->serverPrivateKey || $this->data->serverPublicKey; } if ($keyPairLogin) { $privateKeyFile = self::getTempFileWithContent($this->data->serverPrivateKey, 'privateKey'); $publicKeyFile = self::getTempFileWithContent($this->data->serverPublicKey, 'publicKey'); $engine->loginPubKey($this->data->serverUrl, $this->data->serverUsername, $publicKeyFile, $privateKeyFile, $this->data->serverPassPhrase); } else { $engine->login($this->data->serverUrl, $this->data->serverUsername, $this->data->serverPassword); } } catch (Exception $e) { throw new kTemporaryException($e->getMessage()); } try { if (is_file($this->srcFile)) { $engine->putFile($this->destFile, $this->srcFile, $this->data->force); if (KBatchBase::$taskConfig->params->chmod) { try { $engine->chmod($this->destFile, KBatchBase::$taskConfig->params->chmod); } catch (Exception $e) { } } } else { if (is_dir($this->srcFile)) { $filesPaths = kFile::dirList($this->srcFile); $destDir = $this->destFile; foreach ($filesPaths as $filePath) { $destFile = $destDir . '/' . basename($filePath); $engine->putFile($destFile, $filePath, $this->data->force); if (KBatchBase::$taskConfig->params->chmod) { try { $engine->chmod($destFile, KBatchBase::$taskConfig->params->chmod); } catch (Exception $e) { } } } } } } catch (kFileTransferMgrException $e) { if ($e->getCode() == kFileTransferMgrException::remoteFileExists) { throw new kApplicativeException(KalturaBatchJobAppErrors::FILE_ALREADY_EXISTS, $e->getMessage()); } throw new Exception($e->getMessage(), $e->getCode()); } return true; }
/** * @param KalturaDistributionJobData $data * @param KalturaExampleDistributionProfile $distributionProfile * @param KalturaExampleDistributionJobProviderData $providerData */ protected function handleUpdate(KalturaDistributionJobData $data, KalturaExampleDistributionProfile $distributionProfile, KalturaExampleDistributionJobProviderData $providerData) { $entryId = $data->entryDistribution->entryId; $partnerId = $distributionProfile->partnerId; $entry = $this->getEntry($partnerId, $entryId); $feed = new KDOMDocument(); $feed->load($this->updateXmlTemplate); $feed->documentElement->setAttribute('mediaId', $data->remoteId); $nodes = array('title' => 'name', 'description' => 'description', 'width' => 'width', 'height' => 'height'); foreach ($nodes as $nodeName => $entryAttribute) { $nodeElements = $feed->getElementsByTagName($nodeName); foreach ($nodeElements as $nodeElement) { $nodeElement->textContent = $entry->{$entryAttribute}; } } // get the first asset id $thumbAssetIds = explode(',', $data->entryDistribution->thumbAssetIds); $thumbAssetId = reset($thumbAssetIds); $thumbElements = $feed->getElementsByTagName('thumb'); $thumbElement = reset($thumbElements); $thumbElement->textContent = $this->getThumbAssetUrl($thumbAssetId); $videosElements = $feed->getElementsByTagName('videos'); $videosElement = reset($videosElements); $flavorAssets = $this->getFlavorAssets($partnerId, $data->entryDistribution->flavorAssetIds); KBatchBase::impersonate($partnerId); foreach ($flavorAssets as $flavorAsset) { $url = $this->getFlavorAssetUrl($flavorAsset->id); $videoElement = $feed->createElement('video'); $videoElement->textContent = $url; $videosElement->appendChild($videoElement); } KBatchBase::unimpersonate(); $localFile = tempnam(sys_get_temp_dir(), 'example-update-'); $feed->save($localFile); // loads ftp manager $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $ftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP, $engineOptions); $ftpManager->login(self::FTP_SERVER_URL, $distributionProfile->username, $distributionProfile->password); // put the XML file on the FTP $remoteFile = $entryId . '.xml'; $ftpManager->putFile($remoteFile, $localFile); return true; }
protected function validateKs() { //Retrieve the KS from within the XML $xdoc = new SimpleXMLElement($this->xslTransformedContent); $xmlKs = $xdoc->ks; //Get session info KBatchBase::impersonate($this->currentPartnerId); try { $this->ksInfo = KBatchBase::$kClient->session->get($xmlKs); } catch (Exception $e) { KBatchBase::unimpersonate(); throw new KalturaBatchException("KS [{$xmlKs}] validation failed for [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED); } KBatchBase::unimpersonate(); //validate ks is still valid $currentTime = time(); if ($currentTime > $this->ksInfo->expiry) { throw new KalturaBatchException("KS validation failed for [{$this->job->id}], ks provided in XML Expired", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED); } }
private function getLicenseParamsStr() { // impersonite KBatchBase::impersonate($this->job->partnerId); $drmPlugin = KalturaDrmClientPlugin::get(KBatchBase::$kClient); if (!isset($drmPlugin)) { KalturaLog::err("FAILED to get drmPlugin"); return false; } $profile = $drmPlugin->drmProfile->getByProvider(KalturaDrmProviderType::PLAY_READY); if (!isset($profile)) { KalturaLog::err("FAILED to get profile"); return false; } $playReadyPlugin = KalturaPlayReadyClientPlugin::get(KBatchBase::$kClient); if (!isset($playReadyPlugin)) { KalturaLog::err("FAILED to get playReadyPlugin"); return false; } $playReadyData = $playReadyPlugin->playReadyDrm->getEntryContentKey($this->job->entryId, true); if (!isset($playReadyData)) { KalturaLog::err("FAILED to get playReadyData"); return false; } // un-impersonite KBatchBase::unimpersonate(); $paramsStr = " -keyId {$playReadyData->keyId} -contentKey {$playReadyData->contentKey} -laUrl {$profile->licenseServerUrl}"; KalturaLog::info($paramsStr); return $paramsStr; /* $keyId = "b6e16839-eebd-4ff6-ab76-8d482d8d2b6a"; $keySeed = "XVBovsmzhP9gRIZxWfFta3VVRPzVEWmJsazEJ46I"; $laSrv = "http://playready.directtaps.net/pr/svc/rightsmanager.asmx?"; $paramsStr = " -keyId $keyId -keySeed $keySeed -laUrl $laSrv"; return $paramsStr; */ }
/** * @param string $file * @param int $size * @return bool */ protected function checkFileExists($file, $size = null, $directorySync = null) { $this->setFilePermissions($file); if ($this->isUnitTest) { KalturaLog::debug("Is in unit test"); return true; } // If this is not a file but a directory, certain operations should be done diffrently: // - size calcultions // - the response from the client (to check the client size beaviour) if (is_null($directorySync)) { $directorySync = is_dir($file); } KalturaLog::info("Check File Exists[{$file}] size[{$size}] isDir[{$directorySync}]"); if (is_null($size)) { clearstatcache(); if ($directorySync) { $size = KBatchBase::foldersize($file); } else { $size = kFile::fileSize($file); } if ($size === false) { KalturaLog::debug("Size not found on file [{$file}]"); return false; } } $retries = self::$taskConfig->fileExistReties ? self::$taskConfig->fileExistReties : 1; $interval = self::$taskConfig->fileExistInterval ? self::$taskConfig->fileExistInterval : 5; while ($retries > 0) { $check = self::$kClient->batch->checkFileExists($file, $size); // In case of directorySync - do not check client sizeOk - to be revised if ($check->exists && ($check->sizeOk || $directorySync)) { $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_EXISTS); return true; } $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_DOESNT_EXIST); sleep($interval); $retries--; } KalturaLog::log("Passed max retries"); return false; }
public function handleItemAdded(KalturaObjectBase $object, SimpleXMLElement $item) { if (!$object instanceof $this->objectClass) { return; } $metadataItems = $item; if ($this->containerName) { $containerName = $this->containerName; if (empty($item->{$containerName})) { return; } $metadataItems = $item->{$containerName}; } $nodeName = $this->nodeName; if (empty($metadataItems->{$nodeName})) { // if there is no costum data then we exit return; } KalturaLog::debug("Handles custom metadata for object type [{$this->objectType}] class [{$this->objectClass}] id [{$object->id}] partner id [{$object->partnerId}]"); KBatchBase::impersonate($this->xmlBulkUploadEngine->getCurrentPartnerId()); $pluginsErrorResults = array(); foreach ($metadataItems->{$nodeName} as $customData) { try { $this->handleCustomData($object->id, $customData); } catch (Exception $e) { KalturaLog::err($this->getContainerName() . ' failed: ' . $e->getMessage()); $pluginsErrorResults[] = $e->getMessage(); } } if (count($pluginsErrorResults)) { throw new Exception(implode(', ', $pluginsErrorResults)); } KBatchBase::unimpersonate(); }
public function handleItemUpdated(KalturaObjectBase $object, SimpleXMLElement $item) { if (!$object instanceof KalturaBaseEntry) { return; } if (empty($item->scenes)) { return; } $action = KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::UPDATE]; if (isset($item->scenes->action)) { $action = strtolower($item->scenes->action); } switch ($action) { case KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::UPDATE]: break; default: throw new KalturaBatchException("scenes->action: {$action} is not supported", KalturaBatchJobAppErrors::BULK_ACTION_NOT_SUPPORTED); } $this->entryId = $object->id; $this->cuePointPlugin = KalturaCuePointClientPlugin::get(KBatchBase::$kClient); KBatchBase::impersonate($this->xmlBulkUploadEngine->getCurrentPartnerId()); $this->getExistingCuePointsBySystemName($this->entryId); KBatchBase::$kClient->startMultiRequest(); $items = array(); foreach ($item->scenes->children() as $scene) { if ($this->updateCuePoint($scene)) { $items[] = $scene; } } $results = KBatchBase::$kClient->doMultiRequest(); KBatchBase::unimpersonate(); if (is_array($results) && is_array($items)) { $this->handleResults($results, $items); } }
protected function getEntryDuration(KalturaEntryDistribution $entryDistribution) { try { KBatchBase::impersonate($entryDistribution->partnerId); $entry = KBatchBase::$kClient->baseEntry->get($entryDistribution->entryId); KBatchBase::unimpersonate(); } catch (Exception $e) { KBatchBase::unimpersonate(); throw $e; } return $entry->duration; }
/** * * Create the entries from the given bulk upload results */ protected function createObjects() { // start a multi request for add entries KBatchBase::$kClient->startMultiRequest(); KalturaLog::info("job[{$this->job->id}] start creating users"); $bulkUploadResultChunk = array(); // store the results of the created entries foreach ($this->bulkUploadResults as $bulkUploadResult) { /* @var $bulkUploadResult KalturaBulkUploadResultUser */ KalturaLog::info("Handling bulk upload result: [" . $bulkUploadResult->userId . "]"); switch ($bulkUploadResult->action) { case KalturaBulkUploadAction::ADD: $user = $this->createUserFromResultAndJobData($bulkUploadResult); $bulkUploadResultChunk[] = $bulkUploadResult; KBatchBase::impersonate($this->currentPartnerId); KBatchBase::$kClient->user->add($user); KBatchBase::unimpersonate(); break; case KalturaBulkUploadAction::UPDATE: $category = $this->createUserFromResultAndJobData($bulkUploadResult); $bulkUploadResultChunk[] = $bulkUploadResult; KBatchBase::impersonate($this->currentPartnerId); KBatchBase::$kClient->user->update($bulkUploadResult->userId, $category); KBatchBase::unimpersonate(); break; case KalturaBulkUploadAction::DELETE: $bulkUploadResultChunk[] = $bulkUploadResult; KBatchBase::impersonate($this->currentPartnerId); KBatchBase::$kClient->user->delete($bulkUploadResult->userId); KBatchBase::unimpersonate(); break; default: $bulkUploadResult->status = KalturaBulkUploadResultStatus::ERROR; $bulkUploadResult->errorDescription = "Unknown action passed: [" . $bulkUploadResult->action . "]"; break; } if (KBatchBase::$kClient->getMultiRequestQueueSize() >= $this->multiRequestSize) { // make all the media->add as the partner $requestResults = KBatchBase::$kClient->doMultiRequest(); $this->updateObjectsResults($requestResults, $bulkUploadResultChunk); $this->checkAborted(); KBatchBase::$kClient->startMultiRequest(); $bulkUploadResultChunk = array(); } } // make all the category actions as the partner $requestResults = KBatchBase::$kClient->doMultiRequest(); if (count($requestResults)) { $this->updateObjectsResults($requestResults, $bulkUploadResultChunk); } KalturaLog::info("job[{$this->job->id}] finish modifying users"); }
private function moveExtraFiles(KalturaConvertJobData &$data, $sharedFile) { $i = 0; foreach ($data->extraDestFileSyncs as $destFileSync) { $i++; clearstatcache(); $directorySync = is_dir($destFileSync->fileSyncLocalPath); if ($directorySync) { $fileSize = KBatchBase::foldersize($destFileSync->fileSyncLocalPath); } else { $fileSize = kFile::fileSize($destFileSync->fileSyncLocalPath); } $ext = pathinfo($destFileSync->fileSyncLocalPath, PATHINFO_EXTENSION); if ($ext) { $newName = $sharedFile . '.' . $ext; } else { $newName = $sharedFile . '.' . $i; } kFile::moveFile($destFileSync->fileSyncLocalPath, $newName); // directory sizes may differ on different devices if (!file_exists($newName) || is_file($newName) && kFile::fileSize($newName) != $fileSize) { KalturaLog::err("Error: moving file failed"); die; } $destFileSync->fileSyncLocalPath = $this->translateLocalPath2Shared($newName); if (self::$taskConfig->params->isRemoteOutput) { $destFileSync->fileSyncRemoteUrl = $this->distributedFileManager->getRemoteUrl($destFileSync->fileSyncLocalPath); } } }
protected function generateAmfData(KalturaBatchJob $job, KalturaConvertLiveSegmentJobData $data, $localTempFilePath) { $mediaInfoBin = isset(KBatchBase::$taskConfig->params->mediaInfoCmd) ? KBatchBase::$taskConfig->params->mediaInfoCmd : "mediainfo"; // only extract the data if it's the primary server since we don't use this data in the secondary if ($data->mediaServerIndex == KalturaMediaServerIndex::PRIMARY) { try { // get the asset to check if it has a assetParams::TAG_RECORDING_ANCHOR tag. // note that assetParams::TAG_RECORDING_ANCHOR is not exposed in the API so I use it's string value. KBatchBase::impersonate($job->partnerId); $asset = KBatchBase::$kClient->flavorAsset->get($data->assetId); KBatchBase::unimpersonate(); if (strpos($asset->tags, self::TAG_RECORDING_ANCHOR) == false) { return; } // Extract AMF data from all data frames in the segment $amfParser = new KAMFMediaInfoParser($data->srcFilePath); $amfArray = $amfParser->getAMFInfo(); // run mediaInfo on $localTempFilePath to get it's duration, and store it in the job data $mediaInfoParser = new KMediaInfoMediaParser($localTempFilePath, $mediaInfoBin); $duration = $mediaInfoParser->getMediaInfo()->videoDuration; array_unshift($amfArray, $duration); $amfFileName = "{$data->entryId}_{$data->assetId}_{$data->mediaServerIndex}_{$data->fileIndex}.data"; $localTempAmfFilePath = $this->localTempPath . DIRECTORY_SEPARATOR . $amfFileName; $sharedTempAmfFilePath = $this->sharedTempPath . DIRECTORY_SEPARATOR . $amfFileName; file_put_contents($localTempAmfFilePath, serialize($amfArray)); self::moveDataFile($data, $localTempAmfFilePath, $sharedTempAmfFilePath); } catch (Exception $ex) { KBatchBase::unimpersonate(); KalturaLog::warning('failed to extract AMF data or duration data ' . print_r($ex)); } } }
/** * @param KalturaDistributionJobData $data * @return CrossKalturaEntryObjectsContainer */ protected function getSourceObjects(KalturaDistributionJobData $data) { $sourceEntryId = $data->entryDistribution->entryId; KBatchBase::impersonate($this->distributionProfile->partnerId); $sourceObjects = $this->getEntryObjects(KBatchBase::$kClient, $sourceEntryId, $data); KBatchBase::unimpersonate(); return $sourceObjects; }