public function setJobData(StorageProfile $storage, FileSync $fileSync)
 {
     /* @var $storage KontikiStorageProfile */
     $this->setServerUrl($storage->getStorageUrl());
     $this->setServiceToken($storage->getServiceToken());
     if ($fileSync->getObjectType() != FileSyncObjectType::ASSET) {
         throw new kCoreException("Incompatible filesync type", kCoreException::INTERNAL_SERVER_ERROR);
     }
     $this->setContentMoid($fileSync->getFilePath());
 }
 public function setStorageExportJobData(StorageProfile $externalStorage, FileSync $fileSync, $srcFileSyncLocalPath, $force = false)
 {
     /* @var $externalStorage KontikiStorageProfile */
     $this->setServerUrl($externalStorage->getStorageUrl());
     $this->setServiceToken($externalStorage->getServiceToken());
     $this->setSrcFileSyncId($fileSync->getId());
     if ($fileSync->getObjectType() != FileSyncObjectType::ASSET) {
         throw new kCoreException("Incompatible filesync type", kCoreException::INTERNAL_SERVER_ERROR);
     }
     $this->setFlavorAssetId($fileSync->getObjectId());
 }
Пример #3
0
 public function setStorageExportJobData(StorageProfile $externalStorage, FileSync $fileSync, $srcFileSyncLocalPath, $force = false)
 {
     $this->setServerUrl($externalStorage->getStorageUrl());
     $this->setServerUsername($externalStorage->getStorageUsername());
     $this->setServerPassword($externalStorage->getStoragePassword());
     $this->setServerPrivateKey($externalStorage->getPrivateKey());
     $this->setServerPublicKey($externalStorage->getPublicKey());
     $this->setServerPassPhrase($externalStorage->getPassPhrase());
     $this->setFtpPassiveMode($externalStorage->getStorageFtpPassiveMode());
     $this->setSrcFileSyncLocalPath($srcFileSyncLocalPath);
     $this->setSrcFileSyncId($fileSync->getId());
     $this->setForce($force);
     $this->setDestFileSyncStoredPath($externalStorage->getStorageBaseDir() . '/' . $fileSync->getFilePath());
     $this->setCreateLink($externalStorage->getCreateFileLink());
 }
Пример #4
0
 /**
  * @var StorageProfile $storage
  * @var FileSync $fileSync
  */
 public function setJobData(StorageProfile $storage, FileSync $filesync)
 {
     $this->setServerUrl($storage->getStorageUrl());
     $this->setServerUsername($storage->getStorageUsername());
     $this->setServerPassword($storage->getStoragePassword());
     $this->setServerPrivateKey($storage->getPrivateKey());
     $this->setServerPublicKey($storage->getPublicKey());
     $this->setServerPassPhrase($storage->getPassPhrase());
     $this->setFtpPassiveMode($storage->getStorageFtpPassiveMode());
     $this->setSrcFileSyncId($filesync->getId());
     $this->setDestFileSyncStoredPath($storage->getStorageBaseDir() . '/' . $filesync->getFilePath());
 }
Пример #5
0
 /**
  * @param FileSyncKey $key
  * @param string $url
  * @param StorageProfile $externalStorage
  * @return SyncFile
  */
 public static function createReadyExternalSyncFileForKey(FileSyncKey $key, $url, StorageProfile $externalStorage)
 {
     $externalStorageId = $externalStorage->getId();
     KalturaLog::debug("key [{$key}], externalStorage [{$externalStorageId}]");
     $fileRoot = '';
     $deliveryProfile = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($externalStorageId, ''));
     if ($deliveryProfile) {
         $fileRoot = $deliveryProfile->getUrl();
     }
     $filePath = str_replace($fileRoot, '', $url);
     $c = FileSyncPeer::getCriteriaForFileSyncKey($key);
     $c->add(FileSyncPeer::DC, $externalStorageId);
     $fileSync = FileSyncPeer::doSelectOne($c);
     if (!$fileSync) {
         $fileSync = FileSync::createForFileSyncKey($key);
     }
     $fileSync->setDc($externalStorageId);
     $fileSync->setFileRoot($fileRoot);
     $fileSync->setFilePath($filePath);
     $fileSync->setFileSize(-1);
     $fileSync->setStatus(FileSync::FILE_SYNC_STATUS_READY);
     $fileSync->setOriginal(false);
     $fileSync->setFileType(FileSync::FILE_SYNC_FILE_TYPE_URL);
     $fileSync->save();
     kEventsManager::raiseEvent(new kObjectAddedEvent($fileSync));
     return $fileSync;
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      StorageProfile $value A StorageProfile object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(StorageProfile $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Пример #7
0
 public static function addStorageDeleteJob(BatchJob $parentJob = null, $entryId = null, StorageProfile $storage, FileSync $fileSync)
 {
     $netStorageDeleteData = kStorageDeleteJobData::getInstance($storage->getProtocol());
     $netStorageDeleteData->setJobData($storage, $fileSync);
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::STORAGE_DELETE, $storage->getProtocol(), false);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entryId);
         $batchJob->setPartnerId($storage->getPartnerId());
     }
     $batchJob->setObjectId($fileSync->getId());
     $batchJob->setObjectType(BatchJobObjectType::FILE_SYNC);
     $batchJob->setJobSubType($storage->getProtocol());
     KalturaLog::log("Creating Net-Storage Delete job, with source file: " . $netStorageDeleteData->getSrcFileSyncLocalPath());
     return self::addJob($batchJob, $netStorageDeleteData, BatchJobType::STORAGE_DELETE, $storage->getProtocol());
 }
Пример #8
0
 private function requiredToExportFlavor(StorageProfile $storage)
 {
     // check if storage profile should affect the asset ready status
     if ($storage->getReadyBehavior() != StorageProfileReadyBehavior::REQUIRED) {
         // current storage profile is not required for asset readiness - skipping
         return false;
     }
     // check if export should happen now or wait for another trigger
     if (!$storage->triggerFitsReadyAsset($this->getEntryId())) {
         KalturaLog::info('Asset id [' . $this->getId() . '] is not ready to export to profile [' . $storage->getId() . ']');
         return false;
     }
     // check if asset needs to be exported to the remote storage
     if (!$storage->shouldExportFlavorAsset($this, true)) {
         KalturaLog::info('Should not export asset id [' . $this->getId() . '] to profile [' . $storage->getId() . ']');
         return false;
     }
     $keys = array($this->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET), $this->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISM), $this->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISMC));
     foreach ($keys as $key) {
         if ($storage->shoudlExportFileSync($key)) {
             return true;
         }
     }
     foreach ($keys as $key) {
         // check if asset is currently being exported to the remote storage
         if ($storage->isPendingExport($key)) {
             KalturaLog::info('Asset id [' . $this->getId() . '] is currently being exported to profile [' . $storage->getId() . ']');
             return true;
         }
     }
     return false;
 }
Пример #9
0
 /**
  * Returns an associative array of variables to be passed to the XSLT.
  * This function can be extended by specific managers to add additonal variables to their XSLT transformations.
  * @param StorageProfile $storageProfile
  * @param ISyncableFile $object
  * @param $subType
  * @param $version
  * @param entry $entry
  * @return array associative array of variables to be passed to the XSLT
  */
 protected function getXslVariables(StorageProfile $storageProfile, ISyncableFile $object, $subType, $version, entry $entry)
 {
     return array('currentTime' => time(), 'storageProfileId' => $storageProfile->getId(), 'objectClass' => get_class($object), 'objectId' => $object->getId(), 'objectSubType' => $subType, 'objectVersion' => $version, 'entryId' => $entry->getId(), 'partnerId' => $entry->getPartnerId(), 'defaultFileName' => $object->generateFileName($subType, $version));
 }
 /**
  * @param FileSyncKey $key
  * @param string $url
  * @param StorageProfile $externalStorage
  * @return SyncFile
  */
 public static function createReadyExternalSyncFileForKey(FileSyncKey $key, $url, StorageProfile $externalStorage)
 {
     $externalStorageId = $externalStorage->getId();
     KalturaLog::log(__METHOD__ . " - key [{$key}], externalStorage [{$externalStorageId}]");
     $fileRoot = $externalStorage->getDeliveryHttpBaseUrl();
     $filePath = str_replace($fileRoot, '', $url);
     $c = FileSyncPeer::getCriteriaForFileSyncKey($key);
     $c->add(FileSyncPeer::DC, $externalStorageId);
     $fileSync = FileSyncPeer::doSelectOne($c);
     if (!$fileSync) {
         $fileSync = FileSync::createForFileSyncKey($key);
     }
     $fileSync->setDc($externalStorageId);
     $fileSync->setFileRoot($fileRoot);
     $fileSync->setFilePath($filePath);
     $fileSync->setFileSize(-1);
     $fileSync->setStatus(FileSync::FILE_SYNC_STATUS_READY);
     $fileSync->setOriginal(false);
     $fileSync->setFileType(FileSync::FILE_SYNC_FILE_TYPE_URL);
     $fileSync->save();
     kEventsManager::raiseEvent(new kObjectAddedEvent($fileSync));
     return $fileSync;
 }
 public static function addStorageDeleteJob(BatchJob $parentJob = null, $entryId = null, StorageProfile $storage, FileSync $fileSync)
 {
     $netStorageDeleteData = new kStorageDeleteJobData();
     $netStorageDeleteData->setServerUrl($storage->getStorageUrl());
     $netStorageDeleteData->setServerUsername($storage->getStorageUsername());
     $netStorageDeleteData->setServerPassword($storage->getStoragePassword());
     $netStorageDeleteData->setFtpPassiveMode($storage->getStorageFtpPassiveMode());
     $netStorageDeleteData->setSrcFileSyncId($fileSync->getId());
     $netStorageDeleteData->setDestFileSyncStoredPath($storage->getStorageBaseDir() . '/' . $fileSync->getFilePath());
     if ($parentJob) {
         $batchJob = $parentJob->createChild(false);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entryId);
         $batchJob->setPartnerId($storage->getPartnerId());
     }
     KalturaLog::log("Creating Net-Storage Delete job, with source file: " . $netStorageDeleteData->getSrcFileSyncLocalPath());
     return self::addJob($batchJob, $netStorageDeleteData, BatchJobType::STORAGE_DELETE, $storage->getProtocol());
 }
 /**
  * @param FileSyncKey $key
  * @return bool
  */
 public static function shouldExport(FileSyncKey $key, StorageProfile $externalStorage)
 {
     KalturaLog::log(__METHOD__ . " - key [{$key}], externalStorage id[" . $externalStorage->getId() . "]");
     list($kalturaFileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, false, false);
     if (!$kalturaFileSync) {
         KalturaLog::log(__METHOD__ . " key [{$key}] not found localy");
         return false;
     }
     KalturaLog::log(__METHOD__ . " validating file size [" . $kalturaFileSync->getFileSize() . "] is between min [" . $externalStorage->getMinFileSize() . "] and max [" . $externalStorage->getMaxFileSize() . "]");
     if ($externalStorage->getMaxFileSize() && $kalturaFileSync->getFileSize() > $externalStorage->getMaxFileSize()) {
         KalturaLog::log(__METHOD__ . " key [{$key}] file too big");
         return false;
     }
     if ($externalStorage->getMinFileSize() && $kalturaFileSync->getFileSize() < $externalStorage->getMinFileSize()) {
         KalturaLog::log(__METHOD__ . " key [{$key}] file too small");
         return false;
     }
     $storageFileSync = kFileSyncUtils::getReadyPendingExternalFileSyncForKey($key, $externalStorage->getId());
     if ($storageFileSync) {
         KalturaLog::log(__METHOD__ . " key [{$key}] already exported or being exported");
         return false;
     }
     return true;
 }
Пример #13
0
 /**
  * 
  * for each one of the assets and additional entry files check if it was exported to the external storage
  * and add DeleteStorage job
  * 
  * @param entry $entry
  * @param StorageProfile $profile
  */
 public static function deleteExportedEntry(entry $entry, StorageProfile $profile)
 {
     $flavorAssets = assetPeer::retrieveFlavorsByEntryIdAndStatus($entry->getId(), null, array(asset::ASSET_STATUS_READY, asset::ASSET_STATUS_EXPORTING));
     foreach ($flavorAssets as $flavorAsset) {
         $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if ($profile->isExported($key)) {
             self::delete($entry, $profile, $key);
         }
         $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISM);
         if ($profile->isExported($key)) {
             self::delete($entry, $profile, $key);
         }
         $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
         if ($profile->isExported($key)) {
             self::delete($entry, $profile, $key);
         }
     }
     self::deleteAdditionalEntryFilesFromStorage($entry, $profile);
 }
Пример #14
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      StorageProfile $value A StorageProfile object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(StorageProfile $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('StorageProfilePeer');
         }
     }
 }
Пример #15
0
 /**
  * @param BatchJob $parentJob
  * @param string $entryId
  * @param int $partnerId
  * @param StorageProfile $externalStorage
  * @param SyncFile $fileSync
  * @param string $srcFileSyncLocalPath
  * @param bool $force
  * 
  * @return BatchJob
  */
 public static function addStorageExportJob(BatchJob $parentJob = null, $entryId, $partnerId, StorageProfile $externalStorage, FileSync $fileSync, $srcFileSyncLocalPath, $force = false)
 {
     KalturaLog::log(__METHOD__ . " entryId[{$entryId}], partnerId[{$partnerId}], externalStorage id[" . $externalStorage->getId() . "], fileSync id[" . $fileSync->getId() . "], srcFileSyncLocalPath[{$srcFileSyncLocalPath}]");
     $netStorageExportData = new kStorageExportJobData();
     $netStorageExportData->setServerUrl($externalStorage->getStorageUrl());
     $netStorageExportData->setServerUsername($externalStorage->getStorageUsername());
     $netStorageExportData->setServerPassword($externalStorage->getStoragePassword());
     $netStorageExportData->setFtpPassiveMode($externalStorage->getStorageFtpPassiveMode());
     $netStorageExportData->setSrcFileSyncLocalPath($srcFileSyncLocalPath);
     $netStorageExportData->setSrcFileSyncId($fileSync->getId());
     $netStorageExportData->setForce($force);
     $netStorageExportData->setDestFileSyncStoredPath($externalStorage->getStorageBaseDir() . '/' . $fileSync->getFilePath());
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(false);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entryId);
         $batchJob->setPartnerId($partnerId);
     }
     KalturaLog::log("Creating Storage export job, with source file: " . $netStorageExportData->getSrcFileSyncLocalPath());
     return self::addJob($batchJob, $netStorageExportData, BatchJobType::STORAGE_EXPORT, $externalStorage->getProtocol());
 }
Пример #16
0
 /**
  * @param FileSyncKey $key
  * @param StorageProfile $externalStorage
  * @return SyncFile
  */
 public static function createPendingExternalSyncFileForKey(FileSyncKey $key, StorageProfile $externalStorage)
 {
     $externalStorageId = $externalStorage->getId();
     KalturaLog::log(__METHOD__ . " - key [{$key}], externalStorage [{$externalStorageId}]");
     list($fileRoot, $realPath) = kPathManager::getFilePathArr($key, $externalStorageId);
     $c = FileSyncPeer::getCriteriaForFileSyncKey($key);
     $c->add(FileSyncPeer::DC, $externalStorageId);
     $fileSync = FileSyncPeer::doSelectOne($c);
     if (!$fileSync) {
         $fileSync = FileSync::createForFileSyncKey($key);
     }
     $fileSync->setDc($externalStorageId);
     $fileSync->setFileRoot($fileRoot);
     $fileSync->setFilePath($realPath);
     $fileSync->setFileSize(-1);
     $fileSync->setStatus(FileSync::FILE_SYNC_STATUS_PENDING);
     $fileSync->setOriginal(false);
     if ($externalStorage->getProtocol() == StorageProfile::STORAGE_KALTURA_DC) {
         $fileSync->setFileType(FileSync::FILE_SYNC_FILE_TYPE_FILE);
     } else {
         $fileSync->setFileType(FileSync::FILE_SYNC_FILE_TYPE_URL);
     }
     $fileSync->save();
     kEventsManager::raiseEvent(new kObjectAddedEvent($fileSync));
     return $fileSync;
 }