Exemplo n.º 1
0
        public override void HandleFinishedJob(FinishedJobContext context)
        {
            var task = context.Job.Tasks.FirstOrDefault(x => x.Name == TaskName);

            if (task == null)
            {
                return;
            }

            // Delete existing thumbnail assets.
            var thumbnailAssets = context.CloudVideoPart.Assets.Where(x => x is ThumbnailAsset);

            _assetManager.RemoveAssets(thumbnailAssets);

            foreach (var asset in task.OutputAssets)
            {
                var closureAsset = asset;
                _assetManager.CreateAssetFor <ThumbnailAsset>(context.CloudVideoPart, a => {
                    a.UploadState.Status = AssetUploadStatus.Uploaded;
                    a.WamsAssetId        = closureAsset.Id;
                });
            }
        }
Exemplo n.º 2
0
        private void ProcessCreatedWamsAssets(CloudVideoPart part, CloudVideoPartViewModel viewModel)
        {
            if (viewModel.WamsVideo.AssetId == null && !String.IsNullOrWhiteSpace(viewModel.WamsVideo.WamsAssetId))
            {
                var asset = _assetManager.CreateAssetFor <MezzanineAsset>(part, a => {
                    a.Name               = "Mezzanine";
                    a.IncludeInPlayer    = false;
                    a.OriginalFileName   = viewModel.WamsVideo.FileName;
                    a.WamsAssetId        = viewModel.WamsVideo.WamsAssetId;
                    a.UploadState.Status = AssetUploadStatus.Uploaded;
                    CreatePrivateLocatorFor(a);
                });
                viewModel.WamsVideo.AssetId = asset.Record.Id;
            }

            if (viewModel.WamsThumbnail.AssetId == null && !String.IsNullOrWhiteSpace(viewModel.WamsThumbnail.WamsAssetId))
            {
                var asset = _assetManager.CreateAssetFor <ThumbnailAsset>(part, a => {
                    a.Name               = viewModel.WamsThumbnail.FileName;
                    a.IncludeInPlayer    = true;
                    a.OriginalFileName   = viewModel.WamsThumbnail.FileName;
                    a.WamsAssetId        = viewModel.WamsThumbnail.WamsAssetId;
                    a.UploadState.Status = AssetUploadStatus.Uploaded;
                    CreatePrivateLocatorFor(a);
                });
                viewModel.WamsThumbnail.AssetId = asset.Record.Id;
            }

            if (viewModel.WamsSubtitle.AssetId == null && !String.IsNullOrWhiteSpace(viewModel.WamsSubtitle.WamsAssetId))
            {
                var asset = _assetManager.CreateAssetFor <SubtitleAsset>(part, a => {
                    a.Name               = viewModel.AddedSubtitleLanguage;
                    a.IncludeInPlayer    = true;
                    a.OriginalFileName   = viewModel.WamsSubtitle.FileName;
                    a.Language           = viewModel.AddedSubtitleLanguage;
                    a.WamsAssetId        = viewModel.WamsSubtitle.WamsAssetId;
                    a.UploadState.Status = AssetUploadStatus.Uploaded;
                    CreatePrivateLocatorFor(a);
                });
                viewModel.WamsThumbnail.AssetId = asset.Record.Id;
            }
        }
Exemplo n.º 3
0
        public void Sweep()
        {
            Logger.Debug("Beginning sweep.");

            try {
                if (!_orchardServices.WorkContext.CurrentSite.As <CloudMediaSettingsPart>().IsValid())
                {
                    Logger.Debug("Settings are invalid; going back to sleep.");
                    return;
                }

                // Only allow this task to run on one farm node at a time.
                IDistributedLock @lock;
                if (_distributedLockService.TryAcquireLock(GetType().FullName, TimeSpan.FromHours(1), out @lock))
                {
                    using (@lock) {
                        var jobs = _jobManager.GetActiveJobs().ToDictionary(job => job.WamsJobId);

                        if (!jobs.Any())
                        {
                            Logger.Debug("No open jobs were found; going back to sleep.");
                            return;
                        }

                        Logger.Information("Beginning processing of {0} open jobs.", jobs.Count());

                        var wamsJobs = _wamsClient.GetJobsById(jobs.Keys);

                        foreach (var wamsJob in wamsJobs)
                        {
                            Logger.Information("Processing job '{0}'...", wamsJob.Name);

                            var job       = jobs[wamsJob.Id];
                            var tasks     = job.Tasks.ToDictionary(task => task.WamsTaskId);
                            var wamsTasks = wamsJob.Tasks.ToArray();

                            foreach (var wamsTask in wamsTasks)
                            {
                                var task = tasks[wamsTask.Id];
                                task.Status          = MapWamsJobState(wamsTask.State);
                                task.PercentComplete = (int)wamsTask.Progress;
                            }

                            var previousStatus = job.Status;
                            var wamsJobErrors  = HarvestWamsJobErrors(wamsJob).ToArray();

                            job.CreatedUtc   = wamsJob.Created;
                            job.StartedUtc   = wamsJob.StartTime;
                            job.FinishedUtc  = wamsJob.EndTime;
                            job.Status       = MapWamsJobState(wamsJob.State);
                            job.ErrorMessage = GetAggregateErrorMessage(wamsJobErrors);

                            LogWamsJobErrors(wamsJobErrors);

                            if (job.Status != previousStatus)
                            {
                                if (job.Status == JobStatus.Finished)
                                {
                                    Logger.Information("Job '{0}' was finished in WAMS; creating locators.", wamsJob.Name);

                                    var lastTask               = job.Tasks.Last();
                                    var lastWamsTask           = wamsTasks.Single(task => task.Id == lastTask.WamsTaskId);
                                    var outputAsset            = lastWamsTask.OutputAssets.First();
                                    var outputAssetName        = !String.IsNullOrWhiteSpace(job.OutputAssetName) ? job.OutputAssetName : lastWamsTask.Name;
                                    var outputAssetDescription = job.OutputAssetDescription.TrimSafe();
                                    var encoderMetadataXml     = _wamsClient.GetEncoderMetadataXml(outputAsset).Result;
                                    var cloudVideoPart         = job.CloudVideoPart;
                                    var wamsLocators           = _wamsClient.CreateLocatorsAsync(outputAsset, WamsLocatorCategory.Private).Result;

                                    // HACK: Temporary workaround to disable dynamic packaging for VC1-based assets. In future versions
                                    // this will be implemented more robustly by testing all the dynamic URLs to see which ones work
                                    // and only store and use the working ones.
                                    var forceNonDynamicAsset = lastWamsTask.Configuration.StartsWith("VC1");

                                    if (wamsLocators.OnDemandLocator != null && !forceNonDynamicAsset)
                                    {
                                        _assetManager.CreateAssetFor <DynamicVideoAsset>(cloudVideoPart, asset => {
                                            asset.IncludeInPlayer               = true;
                                            asset.Name                          = outputAssetName;
                                            asset.Description                   = outputAssetDescription;
                                            asset.EncodingPreset                = lastTask.HarvestAssetName;
                                            asset.WamsPrivateLocatorId          = wamsLocators.SasLocator.Id;
                                            asset.WamsPrivateLocatorUrl         = wamsLocators.SasLocator.Url;
                                            asset.WamsPrivateOnDemandLocatorId  = wamsLocators.OnDemandLocator.Id;
                                            asset.WamsPrivateOnDemandLocatorUrl = wamsLocators.OnDemandLocator.Url;
                                            asset.WamsManifestFilename          = wamsLocators.OnDemandManifestFilename;
                                            asset.WamsAssetId                   = outputAsset.Id;
                                            asset.WamsEncoderMetadataXml        = encoderMetadataXml;
                                            asset.UploadState.Status            = AssetUploadStatus.Uploaded;
                                            asset.PublishState.Status           = AssetPublishStatus.None;
                                        });
                                    }
                                    else
                                    {
                                        _assetManager.CreateAssetFor <VideoAsset>(cloudVideoPart, asset => {
                                            asset.IncludeInPlayer        = true;
                                            asset.Name                   = outputAssetName;
                                            asset.Description            = outputAssetDescription;
                                            asset.EncodingPreset         = lastTask.HarvestAssetName;
                                            asset.WamsPrivateLocatorId   = wamsLocators.SasLocator.Id;
                                            asset.WamsPrivateLocatorUrl  = wamsLocators.SasLocator.Url;
                                            asset.WamsAssetId            = outputAsset.Id;
                                            asset.WamsEncoderMetadataXml = encoderMetadataXml;
                                            asset.UploadState.Status     = AssetUploadStatus.Uploaded;
                                            asset.PublishState.Status    = AssetPublishStatus.None;
                                        });
                                    }

                                    try {
                                        if (cloudVideoPart.IsPublished())
                                        {
                                            _assetManager.PublishAssetsFor(cloudVideoPart);
                                        }
                                    }
                                    catch (Exception ex) {
                                        Logger.Warning(ex, "Processing of job '{0}' was completed but an error occurred while publishing the cloud video item with ID {1} after processing.", wamsJob.Name, cloudVideoPart.Id);
                                    }
                                }
                            }

                            Logger.Information("Processing of job '{0}' was successfully completed.", wamsJob.Name);
                        }
                    }
                }
                else
                {
                    Logger.Debug("Distributed lock could not be acquired; going back to sleep.");
                }
            }
            catch (Exception ex) {
                Logger.Error(ex, "Error during sweep.");
            }
            finally {
                Logger.Debug("Ending sweep.");
            }
        }