protected static function getStorageProfile($storageProfileId = null) { if (is_null($storageProfileId)) { return kDataCenterMgr::getCurrentStorageProfile(); } return StorageProfilePeer::retrieveByPK($storageProfileId); }
/** * @return kUrlTokenizer */ public function getTokenizer() { $secret = null; switch ($this->protocol) { case StorageProfile::PLAY_FORMAT_HTTP: if (@$this->params['http_auth_salt']) { $storageProfile = StorageProfilePeer::retrieveByPK($this->storageProfileId); if ($storageProfile) { // get parameters $window = $this->params['http_auth_seconds']; $secret = $this->params['http_auth_salt']; $useDummyHost = false; $httpBaseUrl = rtrim($storageProfile->getDeliveryHttpBaseUrl(), '/'); } } break; case StorageProfile::PLAY_FORMAT_RTMP: if (@$this->params['rtmp_auth_salt']) { $window = $this->params['rtmp_auth_seconds']; $secret = $this->params['rtmp_auth_salt']; $useDummyHost = true; $httpBaseUrl = ''; } break; } if ($secret) { if (is_null($window) || !is_int($window)) { $window = self::DEFAULT_ACCESS_WINDOW_SECONDS; } return new kMirrorImageUrlTokenizer($window, $secret, $useDummyHost, $httpBaseUrl); } return null; }
/** * @return StorageProfile */ public static function getCurrentStorageProfile() { if (self::$currentStorageProfile) { return self::$currentStorageProfile; } self::$currentStorageProfile = StorageProfilePeer::retrieveByPK(self::getCurrentDcId()); return self::$currentStorageProfile; }
public function validateForUsage($sourceObject, $propertiesToSkip = array()) { parent::validateForUsage($sourceObject, $propertiesToSkip); $this->validatePropertyNotNull('storageProfileId'); $storageProfile = StorageProfilePeer::retrieveByPK($this->storageProfileId); if (!$storageProfile) { throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $this->storageProfileId); } }
public function validateEntry(entry $dbEntry) { parent::validateEntry($dbEntry); $this->validatePropertyNotNull('storageProfileId'); $storageProfile = StorageProfilePeer::retrieveByPK($this->storageProfileId); if (!$storageProfile) { throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $this->storageProfileId); } }
/** * @param int $storageProfileId * @return kUrlManager */ public static function getUrlManagerByStorageProfile($storageProfileId) { $class = 'kUrlManager'; $storageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if ($storageProfile && $storageProfile->getUrlManagerClass() && class_exists($storageProfile->getUrlManagerClass())) { $class = $storageProfile->getUrlManagerClass(); } KalturaLog::log("Uses url manager [{$class}]"); return new $class($storageProfileId); }
protected function doGetFileSyncUrl(FileSync $fileSync) { $storageProfile = StorageProfilePeer::retrieveByPK($this->params->getStorageId()); /* @var $storageProfile KontikiStorageProfile */ $kontikiAPIWrapper = new KontikiAPIWrapper($storageProfile->getStorageUrl()); $playbackResource = $kontikiAPIWrapper->getPlaybackResource(KontikiPlugin::SERVICE_TOKEN_PREFIX . base64_encode($storageProfile->getServiceToken()), $fileSync->getFilePath()); if (!$playbackResource) { return null; } return strval($playbackResource->urn) . ";realmId:" . strval($playbackResource->realmId) . ";realmTicket:" . strval($playbackResource->realmTicket); }
/** * Update storage profile by id * * @action update * @param int $storageProfileId * @param KalturaStorageProfile $storageProfile * @return KalturaStorageProfile */ function updateAction($storageProfileId, KalturaStorageProfile $storageProfile) { $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$dbStorageProfile) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $storageProfileId); } $dbStorageProfile = $storageProfile->toUpdatableObject($dbStorageProfile); $dbStorageProfile->save(); $storageProfile->fromObject($dbStorageProfile); return $storageProfile; }
/** * Update storage profile by id * * @action update * @param int $storageProfileId * @param KalturaStorageProfile $storageProfile * @return KalturaStorageProfile */ function updateAction($storageProfileId, KalturaStorageProfile $storageProfile) { $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$dbStorageProfile) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $storageProfileId); } $dbStorageProfile = $storageProfile->toUpdatableObject($dbStorageProfile); $dbStorageProfile->save(); $protocol = $dbStorageProfile->getProtocol(); $storageProfile = KalturaStorageProfile::getInstanceByType($protocol); $storageProfile->fromObject($dbStorageProfile, $this->getResponseProfile()); return $storageProfile; }
public function getExternalUrl($entryId, $format = PlaybackProtocol::HTTP) { $storage = StorageProfilePeer::retrieveByPK($this->getDc()); if (!$storage || $storage->getProtocol() == StorageProfile::STORAGE_KALTURA_DC) { return kDataCenterMgr::getInternalRemoteUrl($this); } $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($this->getDc(), $entryId, PlaybackProtocol::HTTP, infraRequestUtils::getProtocol())); if (is_null($urlManager) && infraRequestUtils::getProtocol() != 'http') { $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($this->getDc(), $entryId)); } if (is_null($urlManager)) { return null; } $url = $urlManager->getFileSyncUrl($this); $baseUrl = $urlManager->getUrl(); $url = ltrim($url, "/"); if (strpos($url, "://") === false) { $url = rtrim($baseUrl, "/") . "/" . $url; } return $url; }
protected function doGetFileSyncUrl(FileSync $fileSync) { $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return parent::doGetFileSyncUrl($fileSync); } $partnerPath = myPartnerUtils::getUrlForPartner($fileSync->getPartnerId(), $fileSync->getPartnerId() * 100); $objectSubType = $fileSync->getObjectSubType(); if ($fileSync->getObjectType() == FileSyncObjectType::ENTRY && $objectSubType == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM) { return $this->doGetServeIsmUrl($fileSync, $partnerPath, $storage); } //To Remove - Until the migration process from asset sub type 3 to asset sub type 1 will be completed we need to support both formats if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET && $objectSubType == flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISM) { return $this->doGetServeIsmUrl($fileSync, $partnerPath, $storage); } if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET && $objectSubType == flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET) { $asset = assetPeer::retrieveById($fileSync->getObjectId()); if ($asset->hasTag(assetParams::TAG_ISM_MANIFEST)) { return $this->doGetServeIsmUrl($fileSync, $partnerPath, $storage); } } return parent::doGetFileSyncUrl($fileSync); }
/** * Parameters * -------------- */ function setDeliveryId($partnerId, $storageId, $deliveryIds) { // don't add to database if one of the parameters is missing or is an empty string if (!$partnerId && !$storageId || !$deliveryIds) { die('Missing parameter'); } if ($partnerId) { $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { die("No such partner with id [{$partnerId}]." . PHP_EOL); } $partner->setDeliveryProfileIds($deliveryIds); $partner->save(); } if ($storageId) { $storage = StorageProfilePeer::retrieveByPK($storageId); if (!$storageId) { die("No such storage profile with id [{$storageId}]." . PHP_EOL); } $storage->setDeliveryProfileIds($deliveryIds); $storage->save(); } }
public function initStorageProfile() { if (!$this->deliveryAttributes->getStorageId()) { return; } $storageProfile = StorageProfilePeer::retrieveByPK($this->deliveryAttributes->getStorageId()); if (!$storageProfile) { KExternalErrors::dieGracefully(); } // TODO use a dieError // storage doesn't belong to the partner if ($storageProfile->getPartnerId() != $this->entry->getPartnerId()) { KExternalErrors::dieGracefully(); } // TODO use a dieError }
/** * * Allows to create additional files in the conversion process in addition to flavor asset */ private static function handleAdditionalFilesConvertFinished(flavorAsset $flavorAsset, BatchJob $dbBatchJob, kConvertJobData $data) { if (!$flavorAsset->getVersion() || !kFileSyncUtils::fileSync_exists($flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET))) { $flavorAsset->incrementVersion(); $flavorAsset->save(); } foreach ($data->getExtraDestFileSyncs() as $destFileSyncDesc) { $syncKey = $flavorAsset->getSyncKey($destFileSyncDesc->getFileSyncObjectSubType()); $flavorParamsOutput = $data->getFlavorParamsOutput(); $storageProfileId = $flavorParamsOutput->getSourceRemoteStorageProfileId(); if ($storageProfileId == StorageProfile::STORAGE_KALTURA_DC) { kFileSyncUtils::moveFromFile($destFileSyncDesc->getFileSyncLocalPath(), $syncKey, false); } elseif ($flavorParamsOutput->getRemoteStorageProfileIds()) { $remoteStorageProfileIds = explode(',', $flavorParamsOutput->getRemoteStorageProfileIds()); foreach ($remoteStorageProfileIds as $remoteStorageProfileId) { $storageProfile = StorageProfilePeer::retrieveByPK($remoteStorageProfileId); kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $destFileSyncDesc->getFileSyncLocalPath(), $storageProfile); } } } }
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; }
/** * @param FileSync $fileSync * @return string */ protected function doGetFileSyncUrl(FileSync $fileSync) { $fileSync = kFileSyncUtils::resolve($fileSync); if ($fileSync->getObjectSubType() == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM) { return $fileSync->getSmoothStreamUrl(); } $url = $fileSync->getFilePath(); $url = str_replace('\\', '/', $url); if ($this->protocol == StorageProfile::PLAY_FORMAT_RTMP) { $storageProfile = StorageProfilePeer::retrieveByPK($this->storageProfileId); if ($storageProfile->getRTMPPrefix()) { if (strpos($url, '/') !== 0) { $url = '/' . $url; } $url = $storageProfile->getRTMPPrefix() . $url; } if ($this->extention && strtolower($this->extention) != 'flv' || $this->containerFormat && strtolower($this->containerFormat) != 'flash video') { $url = "mp4:{$url}"; } // when serving files directly via RTMP fms doesnt expect to get the file extension $url = str_replace('.mp4', '', str_replace('.flv', '', $url)); } return $url; }
/** * @action export * Action for manually exporting an entry * @param string $entryId * @param int $storageProfileId * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND * @return KalturaBaseEntry The exported entry */ public function exportAction($entryId, $storageProfileId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$dbStorageProfile) { throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $storageProfileId); } kStorageExporter::exportEntry($dbEntry, $dbStorageProfile); //TODO: implement export errors $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType()); $entry->fromObject($dbEntry); return $entry; }
/** * @param AttachmentAsset $attachmentAsset * @param IRemoteStorageResource $contentResource * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND */ protected function attachRemoteStorageResource(AttachmentAsset $attachmentAsset, IRemoteStorageResource $contentResource) { $resources = $contentResource->getResources(); $attachmentAsset->setFileExt($contentResource->getFileExt()); $attachmentAsset->incrementVersion(); $attachmentAsset->setStatus(AttachmentAsset::ASSET_STATUS_READY); $attachmentAsset->save(); $syncKey = $attachmentAsset->getSyncKey(AttachmentAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } }
/** * @param FileSync $fileSync * @return string */ protected function doGetFileSyncUrl(FileSync $fileSync) { $fileSync = kFileSyncUtils::resolve($fileSync); $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return parent::doGetFileSyncUrl($fileSync); } $serverUrl = $storage->getDeliveryIisBaseUrl(); $partnerPath = myPartnerUtils::getUrlForPartner($fileSync->getPartnerId(), $fileSync->getPartnerId() * 100); if ($this->protocol == StorageProfile::PLAY_FORMAT_APPLE_HTTP && isset($this->params["hd_ios"])) { $path = $fileSync->getFilePath(); $urlSuffix = str_replace('\\', '/', $path) . "/index_0_av.m3u8"; $urlPrefix = "http://" . $this->params["hd_ios"] . '/i/'; return $urlPrefix . ltrim($urlSuffix, '/'); } if ($this->protocol == "hdnetworksmil" && isset($this->params["hd_flash"])) { $path = $fileSync->getFilePath(); $urlSuffix = str_replace('\\', '/', $path); $urlPrefix = "http://" . $this->params["hd_flash"]; return $urlPrefix . '/' . ltrim($urlSuffix, '/'); } if ($fileSync->getObjectSubType() != entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM) { return parent::doGetFileSyncUrl($fileSync); } $serverUrl = myPartnerUtils::getIisHost($fileSync->getPartnerId(), "http"); $path = $partnerPath . '/serveIsm/objectId/' . $fileSync->getObjectId() . '_' . $fileSync->getObjectSubType() . '_' . $fileSync->getVersion() . '.' . pathinfo(kFileSyncUtils::resolve($fileSync)->getFilePath(), PATHINFO_EXTENSION) . '/manifest'; $matches = null; if (preg_match('/(https?:\\/\\/[^\\/]+)(.*)/', $serverUrl, $matches)) { $path = $matches[2] . $path; } $path = str_replace('//', '/', $path); return $path; }
private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $servePlayManifest = false, $playManifestClientTag = null, $storageId = null) { if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { return null; } if (is_null($storageId) && $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, $storageId); if (!$fileSync) { return null; } $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return null; } if ($servePlayManifest) { // in case of an https request, if a delivery profile which supports https doesn't exist use an http cdn api host if (infraRequestUtils::getProtocol() == infraRequestUtils::PROTOCOL_HTTPS && DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId(), PlaybackProtocol::HTTP, "https"))) { $url = requestUtils::getApiCdnHost(); } else { $url = infraRequestUtils::PROTOCOL_HTTP . "://" . kConf::get("cdn_api_host"); } $url .= $asset->getPlayManifestUrl($playManifestClientTag, $storageId); } else { $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId())); if ($urlManager) { $dynamicAttrs = new DeliveryProfileDynamicAttributes(); $dynamicAttrs->setFileExtension($asset->getFileExt()); $dynamicAttrs->setStorageId($fileSync->getDc()); $urlManager->setDynamicAttributes($dynamicAttrs); $url = ltrim($urlManager->getFileSyncUrl($fileSync), '/'); if (strpos($url, "://") === false) { $url = rtrim($urlManager->getUrl(), "/") . "/" . $url; } } else { KalturaLog::debug("Couldn't determine delivery profile for storage id"); $url = null; } } return $url; }
public function getExternalUrl($storageId, $fileName = null) { $key = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId); if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) { return null; } $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return null; } $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $this->getEntryId()), $fileSync, $this); if (is_null($urlManager)) { return null; } $url = ltrim($urlManager->getFileSyncUrl($fileSync), "/"); if (strpos($url, "://") === false) { $url = rtrim($urlManager->getUrl(), "/") . "/" . $url; } $url = $this->finalizeDownloadUrl($fileSync, $url, $fileName, true); return $url; }
/** * Action for manually exporting an asset * @param string $assetId * @param int $storageProfileId * @throws KalturaErrors::INVALID_FLAVOR_ASSET_ID * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND * @throws KalturaErrors::INTERNAL_SERVERL_ERROR * @return KalturaFlavorAsset The exported asset */ protected function exportAction($assetId, $storageProfileId) { $dbAsset = assetPeer::retrieveById($assetId); if (!$dbAsset) { throw new KalturaAPIException(KalturaErrors::INVALID_FLAVOR_ASSET_ID, $assetId); } $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$dbStorageProfile) { throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $storageProfileId); } $scope = $dbStorageProfile->getScope(); $scope->setEntryId($dbAsset->getEntryId()); if (!$dbStorageProfile->fulfillsRules($scope)) { throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_RULES_NOT_FULFILLED, $storageProfileId); } $exported = kStorageExporter::exportFlavorAsset($dbAsset, $dbStorageProfile); if ($exported !== true) { //TODO: implement export errors throw new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR); } return $this->getAction($assetId); }
public function validateStorageId() { if (!$this->storageId) { return true; } $storage = StorageProfilePeer::retrieveByPK($this->storageId); // no storage found if (!$storage) { die; } $partner = $this->entry->getPartner(); // partner configured to use kaltura data centers only if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { die; } // storage doesn't belong to the partner if ($storage->getPartnerId() != $partner->getId()) { die; } }
private function setContextDataStorageProfilesXml() { if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_REMOTE_STORAGE_DELIVERY_PRIORITY, $this->entry->getPartnerId()) && $this->partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { $asset = reset($this->allowedFlavorAssets); if (!$asset) { return; } $assetSyncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $fileSyncs = kFileSyncUtils::getAllReadyExternalFileSyncsForKey($assetSyncKey); $storageProfilesXML = new SimpleXMLElement("<StorageProfiles/>"); foreach ($fileSyncs as $fileSync) { $storageProfileId = $fileSync->getDc(); $storageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); $deliveryProfileRtmp = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($storageProfileId, $this->entry, PlaybackProtocol::RTMP)); if (is_null($deliveryProfileRtmp) && (!$this->streamerType || $this->streamerType == PlaybackProtocol::AUTO)) { $this->streamerType = PlaybackProtocol::HTTP; $this->mediaProtocol = PlaybackProtocol::HTTP; } $storageProfileXML = $storageProfilesXML->addChild("StorageProfile"); $storageProfileXML->addAttribute("storageProfileId", $storageProfileId); $storageProfileXML->addChild("Name", $storageProfile->getName()); $storageProfileXML->addChild("SystemName", $storageProfile->getSystemName()); } $this->storageProfilesXML = $storageProfilesXML->saveXML(); } }
public function validateStorageId($partnerId) { if (is_null($this->storageId) || $this->storageId instanceof KalturaNullField) { return; } $storage = StorageProfilePeer::retrieveByPK($this->storageId); if (!$storage) { throw new KalturaAPIException(KalturaErrors::SYNDICATION_FEED_INVALID_STORAGE_ID); } $partner = PartnerPeer::retrieveByPK($partnerId); // storage doesn't belong to the partner if ($storage->getPartnerId() != $partner->getId()) { throw new KalturaAPIException(KalturaErrors::SYNDICATION_FEED_INVALID_STORAGE_ID); } // partner configured to use kaltura data centers only if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { throw new KalturaAPIException(KalturaErrors::SYNDICATION_FEED_KALTURA_DC_ONLY); } }
/** * This function returns the delivery object that matches a given storage profile and format * If one not found - returns null * @param DeliveryProfileDynamicAttributes $deliveryAttributes - containing requested storageId, entryId, format and media protocol * @return DeliveryProfile */ public static function getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes $deliveryAttributes, FileSync $fileSync = null, asset $asset = null) { $storageId = $deliveryAttributes->getStorageId(); $storageProfile = StorageProfilePeer::retrieveByPK($storageId); if (!$storageProfile) { KalturaLog::err('Couldn\'t retrieve storageId: ' . $storageId); return null; } $streamerType = $deliveryAttributes->getFormat(); $deliveryIds = $storageProfile->getDeliveryProfileIds(); if (!array_key_exists($streamerType, $deliveryIds)) { KalturaLog::err("Delivery ID can't be determined for storageId [{$storageId}] ( PartnerId [" . $storageProfile->getPartnerId() . "] ) and streamer type [ {$streamerType} ]"); return null; } self::filterDeliveryProfilesArray($deliveryIds, $deliveryAttributes); $deliveries = DeliveryProfilePeer::retrieveByPKs($deliveryIds[$streamerType]); $delivery = self::selectByDeliveryAttributes($deliveries, $deliveryAttributes); if ($delivery) { KalturaLog::info("Delivery ID for storageId [{$storageId}] ( PartnerId [" . $storageProfile->getPartnerId() . "] ) and streamer type [{$streamerType}] is " . $delivery->getId()); $delivery->setEntryId($deliveryAttributes->getEntryId()); $delivery->setStorageId($storageId); $delivery->initDeliveryDynamicAttributes($fileSync, $asset); } else { KalturaLog::err("Delivery ID can't be determined for storageId [{$storageId}] ( PartnerId [" . $storageProfile->getPartnerId() . "] ) streamer type [{$streamerType}] and media protocol [" . $deliveryAttributes->getMediaProtocol() . "]"); } return $delivery; }
/** * @param IRemoteStorageResource $resource * @param entry $dbEntry * @param asset $dbAsset * @return asset * @throws KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND */ protected function attachRemoteStorageResource(IRemoteStorageResource $resource, entry $dbEntry, asset $dbAsset = null) { $resources = $resource->getResources(); $fileExt = $resource->getFileExt(); $dbEntry->setSource(KalturaSourceType::URL); // TODO - move image handling to media service if ($dbEntry->getMediaType() == KalturaMediaType::IMAGE) { $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } $dbEntry->setStatus(entryStatus::READY); $dbEntry->save(); return null; } $dbEntry->save(); $isNewAsset = false; if (!$dbAsset) { $isNewAsset = true; $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId()); } if (!$dbAsset) { KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "]"); if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) { $dbEntry->setStatus(entryStatus::ERROR_CONVERTING); $dbEntry->save(); } throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED); } $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } $dbAsset->setFileExt($fileExt); if ($dbAsset instanceof flavorAsset && !$dbAsset->getIsOriginal()) { $dbAsset->setStatus(asset::FLAVOR_ASSET_STATUS_READY); } $dbAsset->save(); if ($isNewAsset) { kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset)); } kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset)); if ($dbAsset instanceof flavorAsset && !$dbAsset->getIsOriginal()) { kBusinessPostConvertDL::handleConvertFinished(null, $dbAsset); } return $dbAsset; }
/** * @action export * Action for manually exporting an entry * @param string $entryId * @param int $storageProfileId * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND * @return KalturaBaseEntry The exported entry */ public function exportAction($entryId, $storageProfileId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$dbStorageProfile) { throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $storageProfileId); } $scope = $dbStorageProfile->getScope(); $scope->setEntryId($entryId); if (!$dbStorageProfile->fulfillsRules($scope)) { throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_RULES_NOT_FULFILLED, $storageProfileId); } try { kStorageExporter::exportEntry($dbEntry, $dbStorageProfile); } catch (kCoreException $e) { if ($e->getCode() == kCoreException::PROFILE_STATUS_DISABLED) { throw new KalturaAPIException(APIErrors::PROFILE_STATUS_DISABLED, $entryId); } } //TODO: implement export errors $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType()); $entry->fromObject($dbEntry, $this->getResponseProfile()); return $entry; }
<?php require_once dirname(__FILE__) . '/../bootstrap.php'; if ($argc < 3) { echo "Arguments missing.\n\n"; echo "Usage: php exportToNetStorage.php {partner id} {storage profile id} {max number of entries}(optional)\n"; exit; } $partnerId = $argv[1]; $storageProfileId = $argv[2]; $maxEntriesToExport = isset($argv[3]) ? $argv[3] : -1; if (empty($maxEntriesToExport) || $maxEntriesToExport <= 0) { $maxEntriesToExport = -1; } $storageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$storageProfile) { echo "Invalid storage profile id [{$storageProfileId}].\n\n"; echo "Usage: php exportToNetStorage.php {partner id} {storage profile id}\n"; exit; } $flavorParamsIds = $storageProfile->getFlavorParamsIds(); KalturaLog::log("flavorParamsIds [{$flavorParamsIds}]"); $flavorParamsArr = null; if (!is_null($flavorParamsIds) && strlen(trim($flavorParamsIds))) { $flavorParamsArr = explode(',', $flavorParamsIds); } $moreEntries = true; $maxConcurrentJobs = 20; $totalExported = 0; $lastCreatedAt = null; $processedIds = array();
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; }