/** * Upload a file to the current upload token * @param file $fileData * @param bool $resume * @param bool $finalChunk * @param int $resumeAt */ public function uploadFileToToken($fileData, $resume = false, $finalChunk = true, $resumeAt = -1) { $allowedStatuses = array(UploadToken::UPLOAD_TOKEN_PENDING, UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD); if (!in_array($this->_uploadToken->getStatus(), $allowedStatuses, true)) { throw new kUploadTokenException("Invalid upload token status", kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS); } $this->updateFileName($fileData); try { $this->checkIfFileIsValid($fileData); } catch (kUploadTokenException $ex) { if (!$resume && $finalChunk) { kFlowHelper::handleUploadFailed($this->_uploadToken); } $this->tryMoveToErrors($fileData); throw $ex; } if ($resume) { $this->handleResume($fileData, $resumeAt); } else { $this->handleMoveFile($fileData); } $fileSize = kFile::fileSize($this->_uploadToken->getUploadTempPath()); if ($finalChunk) { $this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_FULL_UPLOAD); } else { $this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD); } $this->_uploadToken->setUploadedFileSize($fileSize); $this->_uploadToken->setDc(kDataCenterMgr::getCurrentDcId()); $this->_uploadToken->save(); $this->addTrackEntry(); }
public function toObject($object_to_fill = null, $props_to_skip = array()) { $this->validateForUsage($object_to_fill, $props_to_skip); $dbUploadToken = UploadTokenPeer::retrieveByPK($this->token); if (is_null($dbUploadToken)) { throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_NOT_FOUND); } if (!$object_to_fill) { $object_to_fill = new kUploadedFileTokenResource(); } $object_to_fill->setToken($this->token); if ($dbUploadToken->getStatus() != UploadToken::UPLOAD_TOKEN_FULL_UPLOAD) { $object_to_fill->setIsReady(false); return $object_to_fill; } try { $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($this->token); } catch (kCoreException $ex) { if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) { } throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY); throw $ex; } if (!file_exists($entryFullPath)) { $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($this->token, kDataCenterMgr::getCurrentDcId()); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } else { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } } $object_to_fill->setLocalFilePath($entryFullPath); return $object_to_fill; }
public function shouldConsumeAddedEvent(BaseObject $object) { if ($object instanceof FileSync && $object->getStatus() == FileSync::FILE_SYNC_STATUS_PENDING && $object->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_FILE && $object->getDc() != kDataCenterMgr::getCurrentDcId() && $this->shouldSyncFileObjectType($object->getObjectType(), $object->getObjectSubType())) { return true; } return false; }
/** * Creates perioding metadata sync-point events on a live stream * * @action createPeriodicSyncPoints * @actionAlias liveStream.createPeriodicSyncPoints * @param string $entryId Kaltura live-stream entry id * @param int $interval Events interval in seconds * @param int $duration Duration in seconds * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::NO_MEDIA_SERVER_FOUND * @throws KalturaErrors::MEDIA_SERVER_SERVICE_NOT_FOUND */ function createPeriodicSyncPoints($entryId, $interval, $duration) { $entryDc = substr($entryId, 0, 1); if ($entryDc != kDataCenterMgr::getCurrentDcId()) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($entryDc); kFileUtils::dumpApiRequest($remoteDCHost, true); } $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::LIVE_STREAM || !in_array($dbEntry->getSource(), array(KalturaSourceType::LIVE_STREAM, KalturaSourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } /* @var $dbEntry LiveStreamEntry */ $mediaServers = $dbEntry->getMediaServers(); if (!count($mediaServers)) { throw new KalturaAPIException(KalturaErrors::NO_MEDIA_SERVER_FOUND, $entryId); } foreach ($mediaServers as $key => $kMediaServer) { if ($kMediaServer && $kMediaServer instanceof kLiveMediaServer) { $mediaServer = $kMediaServer->getMediaServer(); $mediaServerCuePointsService = $mediaServer->getWebService(MediaServer::WEB_SERVICE_CUE_POINTS); KalturaLog::debug("Sending sync points for DC [" . $mediaServer->getDc() . "] "); if ($mediaServerCuePointsService && $mediaServerCuePointsService instanceof KalturaMediaServerCuePointsService) { KalturaLog::debug("Call createTimeCuePoints on DC [" . $mediaServer->getDc() . "] "); $mediaServerCuePointsService->createTimeCuePoints($entryId, $interval, $duration); } else { KalturaLog::debug("Media server service not found on DC: [" . $mediaServer->getDc() . "] "); } } } }
public function validateEntry(entry $dbEntry) { parent::validateEntry($dbEntry); $this->validatePropertyNotNull('resources'); $dc = null; foreach ($this->resources as $resource) { $resource->validateEntry($dbEntry); if (!$resource instanceof KalturaDataCenterContentResource) { continue; } $theDc = $resource->getDc(); if (is_null($theDc)) { continue; } if (is_null($dc)) { $dc = $theDc; } elseif ($dc != $theDc) { throw new KalturaAPIException(KalturaErrors::RESOURCES_MULTIPLE_DATA_CENTERS); } } if (!is_null($dc) && $dc != kDataCenterMgr::getCurrentDcId()) { $remoteHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($dc); kFileUtils::dumpApiRequest($remoteHost); } }
/** * @param BaseObject $object * @return bool true if should continue to the next consumer */ public function objectAdded(BaseObject $object) { if (!$object instanceof FileSync || $object->getStatus() != FileSync::FILE_SYNC_STATUS_PENDING || $object->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_FILE || $object->getDc() == kDataCenterMgr::getCurrentDcId()) { return true; } $c = new Criteria(); $c->addAnd(FileSyncPeer::OBJECT_ID, $object->getObjectId()); $c->addAnd(FileSyncPeer::VERSION, $object->getVersion()); $c->addAnd(FileSyncPeer::OBJECT_TYPE, $object->getObjectType()); $c->addAnd(FileSyncPeer::OBJECT_SUB_TYPE, $object->getObjectSubType()); $c->addAnd(FileSyncPeer::ORIGINAL, '1'); $original_filesync = FileSyncPeer::doSelectOne($c); if (!$original_filesync) { KalturaLog::err('Original filesync not found for object_id[' . $object->getObjectId() . '] version[' . $object->getVersion() . '] type[' . $object->getObjectType() . '] subtype[' . $object->getObjectSubType() . ']'); return true; } $sourceFileUrl = $original_filesync->getExternalUrl(); if (!$sourceFileUrl) { KalturaLog::err('External URL not found for filesync id [' . $object->getId() . ']'); return true; } $job = kMultiCentersManager::addFileSyncImportJob($this->getEntryId($object), $object->getPartnerId(), $object->getId(), $sourceFileUrl); $job->setDc($object->getDc()); $job->save(); return true; }
public function preInsert(PropelPDO $con = null) { if ($this->getPartnerId() === Partner::MEDIA_SERVER_PARTNER_ID) { $this->setDc(kDataCenterMgr::getCurrentDcId()); } return parent::preInsert($con); }
/** * Retrieve the server object of the current data center * * @param string $server server name * @param PropelPDO $con the connection to use * @return SphinxLogServer */ public static function retrieveByLocalServer($server, PropelPDO $con = null) { $criteria = new Criteria(); $criteria->add(SphinxLogServerPeer::SERVER, $server); $criteria->add(SphinxLogServerPeer::DC, kDataCenterMgr::getCurrentDcId()); return SphinxLogServerPeer::doSelectOne($criteria, $con); }
public function toObject($object_to_fill = null, $props_to_skip = array()) { if (!$this->isNull('currentDc')) { $this->dcEqual = kDataCenterMgr::getCurrentDcId(); } return parent::toObject($object_to_fill, $props_to_skip); }
/** * Entry point to job balancing. * - Move jobs from status '0' to status '11' in case there are too many pending jobs * - move jobs back from status '11' to status '0' in case the load is over. * */ public static function balanceJobsload() { $minPendingJobs = self::getSuspenderMinPendingJobs(); $maxPendingJobs = self::getSuspenderMaxPendingJobs(); $dcId = kDataCenterMgr::getCurrentDcId(); $loadedKeys = array(); // Suspend Jobs $c = self::createJobBalanceQuery($dcId, $minPendingJobs); $stmt = BatchJobLockPeer::doSelectStmt($c); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($rows as $row) { $partnerId = $row['PARTNER_ID']; $jobType = $row['JOB_TYPE']; $jobSubType = $row['JOB_SUB_TYPE']; $loadedKeys[] = $partnerId . "#" . $jobType . "#" . $jobSubType; $jobCount = $row[BatchJobLockPeer::COUNT]; if ($jobCount > $maxPendingJobs) { self::suspendJobs($jobCount - $maxPendingJobs, $dcId, $partnerId, $jobType, $jobSubType); } } // Unsuspend jobs $c = self::createReturnBalancedJobsQuery($dcId); $stmt = BatchJobLockSuspendPeer::doSelectStmt($c); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($rows as $row) { $partnerId = $row['PARTNER_ID']; $jobType = $row['JOB_TYPE']; $jobSubType = $row['JOB_SUB_TYPE']; $key = $partnerId . "#" . $jobType . "#" . $jobSubType; if (!in_array($key, $loadedKeys)) { self::unsuspendJobs($maxPendingJobs - $minPendingJobs, $dcId, $partnerId, $jobType, $jobSubType); } } }
public function save(PropelPDO $con = null) { KalturaLog::log("BatchJob [{$this->getJobType()}][{$this->getJobSubType()}]: save()"); $is_new = $this->isNew(); if ($this->isNew()) { $this->setDc(kDataCenterMgr::getCurrentDcId()); // if the status not set upon creation if (is_null($this->status) || !$this->isColumnModified(BatchJobPeer::STATUS)) { //echo "sets the status to " . self::BATCHJOB_STATUS_PENDING . "\n"; $this->setStatus(self::BATCHJOB_STATUS_PENDING); } } $res = parent::save($con); if ($is_new && !$this->root_job_id && $this->id) { // set the root to point to itself $this->setRootJobId($this->id); $res = parent::save($con); } /* * remove - no need to use file indicators any more // when new object or status is pending - add the indicator for the batch job to start running if ( $is_new || ( $this->getStatus() == self::BATCHJOB_STATUS_PENDING ) ) { self::addIndicator( $this->getId() , $this->getJobType() ); KalturaLog::log ( "BatchJob: Added indicator for BatchJob [" . $this->getId() . "] of type [{$this->getJobType() }]" ); //debugUtils::st(); } else { KalturaLog::log ( "BatchJob: Didn't add an indicator for BatchJob [" . $this->getId() . "]" ); } */ return $res; }
/** * * @param FileSyncKey $key * @return FileSync */ public static function retrieveByFileSyncKey(FileSyncKey $key, $current_dc_only = false) { $c = self::getCriteriaForFileSyncKey($key); if ($current_dc_only) { $c->add(self::DC, kDataCenterMgr::getCurrentDcId()); } return self::doSelectOne($c); }
function dumpApiRequest($entryId, $onlyIfAvailable = true) { $entryDc = substr($entryId, 0, 1); if ($entryDc != kDataCenterMgr::getCurrentDcId()) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($entryDc); kFileUtils::dumpApiRequest($remoteDCHost, $onlyIfAvailable); } }
public function save(PropelPDO $con = null) { if ($this->isNew()) { $this->setId($this->calculateId()); $this->setDc(kDataCenterMgr::getCurrentDcId()); } parent::save($con); }
public function toObject($object_to_fill = null, $props_to_skip = array()) { if (!$this->isNull('currentDc')) { if ($this->currentDc == KalturaNullableBoolean::TRUE_VALUE) { $this->dcEqual = kDataCenterMgr::getCurrentDcId(); } } return parent::toObject($object_to_fill, $props_to_skip); }
public function getDc() { $content = myContentStorage::getFSContentRootPath(); $entryFullPath = "{$content}/content/webcam/{$this->token}.flv"; if (file_exists($entryFullPath)) { return kDataCenterMgr::getCurrentDcId(); } return 1 - kDataCenterMgr::getCurrentDcId(); // other dc }
/** * Generic add entry using an uploaded file, should be used when the uploaded entry type is not known * * @action addFromUploadedFile * @param KalturaBaseEntry $entry * @param string $uploadTokenId * @param KalturaEntryType $type * @return KalturaBaseEntry */ function addFromUploadedFileAction(KalturaBaseEntry $entry, $uploadTokenId, $type = -1) { try { // check that the uploaded file exists $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId); } catch (kCoreException $ex) { if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) { } throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY); throw $ex; } if (!file_exists($entryFullPath)) { $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId()); if ($remoteDCHost) { kFile::dumpApiRequest($remoteDCHost); } else { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } } // validate the input object //$entry->validatePropertyMinLength("name", 1); if (!$entry->name) { $entry->name = $this->getPartnerId() . '_' . time(); } // first copy all the properties to the db entry, then we'll check for security stuff $dbEntry = $entry->toInsertableObject(new entry()); $dbEntry->setType($type); $dbEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_AUTOMATIC); $this->checkAndSetValidUser($entry, $dbEntry); $this->checkAdminOnlyInsertProperties($entry); $this->validateAccessControlId($entry); $this->validateEntryScheduleDates($entry); $dbEntry->setPartnerId($this->getPartnerId()); $dbEntry->setSubpId($this->getPartnerId() * 100); $dbEntry->setSourceId($uploadTokenId); $dbEntry->setSourceLink($entryFullPath); $dbEntry->setDefaultModerationStatus(); $dbEntry->save(); $kshow = $this->createDummyKShow(); $kshowId = $kshow->getId(); myEntryUtils::setEntryTypeAndMediaTypeFromFile($dbEntry, $entryFullPath); // setup the needed params for my insert entry helper $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags()); $token = $this->getKsUniqueString(); $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray); $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100); $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry); $dbEntry = $insert_entry_helper->getEntry(); kUploadTokenMgr::closeUploadTokenById($uploadTokenId); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry); $entry->fromObject($dbEntry); return $entry; }
public function getDc() { $content = myContentStorage::getFSContentRootPath(); $entryFullPaths = array("{$content}/content/webcam/{$this->token}.flv", "{$content}/content/webcam/{$this->token}.f4v", "{$content}/content/webcam/{$this->token}.f4v.mp4"); foreach ($entryFullPaths as $entryFullPath) { if (file_exists($entryFullPath)) { return kDataCenterMgr::getCurrentDcId(); } } return 1 - kDataCenterMgr::getCurrentDcId(); // other dc }
public function validateForUsage($sourceObject, $propertiesToSkip = array()) { parent::validateForUsage($sourceObject, $propertiesToSkip); $dc = $this->getDc(); if ($dc == kDataCenterMgr::getCurrentDcId()) { return; } $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($dc); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } throw new KalturaAPIException(KalturaErrors::REMOTE_DC_NOT_FOUND, $dc); }
public function validateEntry(entry $dbEntry) { parent::validateEntry($dbEntry); $dc = $this->getDc(); if ($dc == kDataCenterMgr::getCurrentDcId()) { return; } $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($dc); if ($remoteDCHost) { kFile::dumpApiRequest($remoteDCHost); } throw new KalturaAPIException(KalturaErrors::REMOTE_DC_NOT_FOUND, $dc); }
/** * Update media server status * * @action reportStatus * @param string $hostname * @param KalturaMediaServerStatus $mediaServerStatus * @return KalturaMediaServer */ function reportStatusAction($hostname, KalturaMediaServerStatus $mediaServerStatus) { $dbMediaServer = MediaServerPeer::retrieveByHostname($hostname); if (!$dbMediaServer) { $dbMediaServer = new MediaServer(); $dbMediaServer->setHostname($hostname); $dbMediaServer->setDc(kDataCenterMgr::getCurrentDcId()); } $mediaServerStatus->toUpdatableObject($dbMediaServer); $dbMediaServer->save(); $mediaServer = new KalturaMediaServer(); $mediaServer->fromObject($dbMediaServer, $this->getResponseProfile()); return $mediaServer; }
/** * generate unique string id for CuePoint */ private function calculateId() { $currentDcId = kDataCenterMgr::getCurrentDcId(); for ($i = 0; $i < 10; $i++) { $id = $currentDcId . '_' . kString::generateStringId(); $existingObject = CuePointPeer::retrieveByPKNoFilter($id); if ($existingObject) { KalturaLog::log(__METHOD__ . ": id [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for CuePoint"); }
/** * Add new document entry after the specific document file was uploaded and the upload token id exists * * @action addFromUploadedFile * @param KalturaDocumentEntry $documentEntry Document entry metadata * @param string $uploadTokenId Upload token id * @return KalturaDocumentEntry The new document entry * * @throws KalturaErrors::PROPERTY_VALIDATION_MIN_LENGTH * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN */ function addFromUploadedFileAction(KalturaDocumentEntry $documentEntry, $uploadTokenId) { try { // check that the uploaded file exists $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId); } catch (kCoreException $ex) { if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) { } throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY); throw $ex; } if (!file_exists($entryFullPath)) { $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId()); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } else { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } } $dbEntry = $this->prepareEntryForInsert($documentEntry); $dbEntry->setSource(KalturaSourceType::FILE); $dbEntry->setSourceLink("file:{$entryFullPath}"); $dbEntry->save(); $te = new TrackEntry(); $te->setEntryId($dbEntry->getId()); $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY); $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_FILE"); TrackEntry::addTrackEntry($te); $msg = null; $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId(), $msg); if (!$flavorAsset) { KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "] reason [{$msg}]"); $dbEntry->setStatus(entryStatus::ERROR_CONVERTING); $dbEntry->save(); } else { $ext = pathinfo($entryFullPath, PATHINFO_EXTENSION); KalturaLog::info("Uploaded file extension: {$ext}"); $flavorAsset->setFileExt($ext); $flavorAsset->save(); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($entryFullPath, $syncKey); kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset)); } kUploadTokenMgr::closeUploadTokenById($uploadTokenId); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry); $documentEntry->fromObject($dbEntry, $this->getResponseProfile()); return $documentEntry; }
public function setEntryBroadcastingUrls(LiveStreamEntry $dbEntry) { $currentDc = kDataCenterMgr::getCurrentDcId(); $hostname = $this->getHostname($currentDc, $dbEntry->getSource()); $dbEntry->setPrimaryBroadcastingUrl($this->getBroadcastUrl($dbEntry, kBroadcastUrlManager::PROTOCOL_RTMP, $hostname, kBroadcastUrlManager::PRIMARY_MEDIA_SERVER_INDEX)); $dbEntry->setPrimaryRtspBroadcastingUrl($this->getBroadcastUrl($dbEntry, kBroadcastUrlManager::PROTOCOL_RTSP, $hostname, kBroadcastUrlManager::PRIMARY_MEDIA_SERVER_INDEX, true)); $configuration = $this->getConfiguration(); foreach ($configuration as $dc => $config) { if (!is_numeric($dc) || $dc == $currentDc) { continue; } $hostname = $this->getHostname($dc, $dbEntry->getSource()); $dbEntry->setSecondaryBroadcastingUrl($this->getBroadcastUrl($dbEntry, kBroadcastUrlManager::PROTOCOL_RTMP, $hostname, kBroadcastUrlManager::SECONDARY_MEDIA_SERVER_INDEX)); $dbEntry->setSecondaryRtspBroadcastingUrl($this->getBroadcastUrl($dbEntry, kBroadcastUrlManager::PROTOCOL_RTSP, $hostname, kBroadcastUrlManager::SECONDARY_MEDIA_SERVER_INDEX, true)); } }
/** * @return int unique id per request */ public function getUniqueRequestId() { if (!is_null(self::$uniqueRequestId)) { return self::$uniqueRequestId; } $dcId = kDataCenterMgr::getCurrentDcId(); for ($i = 0; $i < 10; ++$i) { $requestId = $dcId . '_' . kString::generateStringId(); $exists = AuditTrailPeer::retrieveByRequestId($requestId); if (!$exists) { self::$uniqueRequestId = $requestId; return self::$uniqueRequestId; } } throw new kAuditTrailException('Unable to generate unique id', kAuditTrailException::UNIQUE_ID_NOT_GENERATED); }
private function reconvertEntry($entry_id, $conversion_profile_id, $job_priority) { $entry = entryPeer::retrieveByPK($entry_id); $this->error = ""; if (!$entry) { $error = "Cannot reconvert entry [{$entry_id}]. Might be a deleted entry"; return array($entry_id, null, null, $error); } $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id); if (!$flavorAsset) { $flavorAsset = assetPeer::retrieveReadyWebByEntryId($entry_id); if (!$flavorAsset) { $flavorAssets = assetPeer::retrieveFlavorsByEntryId($entry_id); if (!$flavorAssets) { $error = "Cannot find good enough flavor asset to re-convert from"; return array($entry_id, $entry, null, $error); } $flavorAsset = $flavorAssets[0]; // choose the first one } } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); if (!$filePath) { $error = "Cannot find a fileSync for the flavorAsset [" . $flavorAsset->getId() . "]"; return array($entry_id, $entry, null, $error); } $dbBatchJob = new BatchJob(); $dbBatchJob->setEntryId($entry_id); $dbBatchJob->setPartnerId($entry->getPartnerId()); $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_PENDING); $dbBatchJob->setDc(kDataCenterMgr::getCurrentDcId()); //$dbBatchJob->setPriority ( $job_priority ); Not supported anymore $dbBatchJob->setObjectId($entry_id); $dbBatchJob->setObjectType(BatchJobObjectType::ENTRY); $dbBatchJob->setJobType(BatchJobType::CONVERT_PROFILE); $dbBatchJob->save(); // creates a convert profile job $convertProfileData = new kConvertProfileJobData(); $convertProfileData->setFlavorAssetId($flavorAsset->getId()); $convertProfileData->setInputFileSyncLocalPath($filePath); kJobsManager::addJob($dbBatchJob, $convertProfileData, BatchJobType::CONVERT_PROFILE); // save again afget the addJob $dbBatchJob->save(); return array($entry_id, $entry, $dbBatchJob, $error); }
public function save(PropelPDO $con = null) { $is_new = $this->isNew(); if ($this->isNew()) { $this->setDc(kDataCenterMgr::getCurrentDcId()); } if (self::isEntryNotification($this->getType())) { $this->setObjectType(self::NOTIFICATION_OBJECT_TYPE_ENTRY); } else { $this->setObjectType(self::NOTIFICATION_OBJECT_TYPE_KSHOW); } $res = parent::save($con); // when new object or status is pending - add the indicator for the batch job to start running if ($is_new || ($this->getStatus() == self::NOTIFICATION_STATUS_PENDING || $this->getStatus() == self::NOTIFICATION_STATUS_SHOULD_RESEND)) { self::addIndicator($this->getId()); } return $res; }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { requestUtils::handleConditionalGet(); $file_sync_id = $this->getRequestParameter("id"); $hash = $this->getRequestParameter("hash"); $file_name = $this->getRequestParameter("fileName"); if ($file_name) { $file_name = base64_decode($file_name); } $file_sync = FileSyncPeer::retrieveByPk($file_sync_id); if (!$file_sync) { $current_dc_id = kDataCenterMgr::getCurrentDcId(); $error = "DC[{$current_dc_id}]: Cannot find FileSync with id [{$file_sync_id}]"; KalturaLog::err($error); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveFile', $file_sync->getPartnerId()); kDataCenterMgr::serveFileToRemoteDataCenter($file_sync, $hash, $file_name); die; }
public function preInsert(PropelPDO $con = null) { // set the dc ONLY if it wasnt initialized // this is required in the special case of file_sync import jobs which are created on one dc but run from the other // all other jobs run from the same datacenter they were created on. // setting the dc later results in a race condition were the job is picked up by the current datacenter before the dc value is changed if (is_null($this->dc) || !$this->isColumnModified(BatchJobPeer::DC)) { // by default set the dc to the current data center. However whenever a batch job is operating on an entry, we rather run it // in the DC where the file sync of the entry exists. Since the batch job doesnt refer to a flavor (we only have an entry id member) // we check the file sync of the source flavor asset (if one exists) $dc = kDataCenterMgr::getCurrentDcId(); $this->setDc($dc); } // if the status not set upon creation if (is_null($this->status) || !$this->isColumnModified(BatchJobPeer::STATUS)) { //echo "sets the status to " . self::BATCHJOB_STATUS_PENDING . "\n"; $this->setStatus(self::BATCHJOB_STATUS_PENDING); } return parent::preInsert($con); }
/** * will verify if each recipient should be getting this email */ public function save(PropelPDO $con = null) { // before saving - remove all the recipients that are in the blocked_email list $recipient_list = explode(self::RECIPIENT_SEPARATOR, $this->recipient_email); $new_recipient_email = ""; foreach ($recipient_list as $recipient) { if ($new_recipient_email != "") { $new_recipient_email .= self::RECIPIENT_SEPARATOR; } if (myBlockedEmailUtils::shouldSendEmail(trim($recipient))) { $new_recipient_email .= $recipient; } } $this->recipient_email = $new_recipient_email; if ($this->recipient_email != "") { if ($this->isNew()) { $this->setDc(kDataCenterMgr::getCurrentDcId()); } parent::save($con); } }