diff --git a/MB-ForensicWatermark/ActionsProvider/AMS/AMSProvider.cs b/MB-ForensicWatermark/ActionsProvider/AMS/AMSProvider.cs index f546ea5..805f01a 100644 --- a/MB-ForensicWatermark/ActionsProvider/AMS/AMSProvider.cs +++ b/MB-ForensicWatermark/ActionsProvider/AMS/AMSProvider.cs @@ -20,6 +20,7 @@ namespace ActionsProvider.AMS class AMSProvider : IAMSProvider { string _WaterMarkStorageConStr; + string _WatermarkedStorageName; CloudMediaContext _mediaContext; CloudStorageAccount _WaterMArkStorageAccount; CloudBlobClient _WaterMArkStorageBlobClient; @@ -42,7 +43,7 @@ private string GetBlobSasUri(CloudBlobClient stClient, string containerName, str string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints); return blob.Uri + sasBlobToken; } - public AMSProvider(string TenantId, string ClientId, string ClientSecret, Uri AMSApiUri, string WaterMarkStorageConStr, string AMSStorageConStr,string PUBLISHWATERKEDCOPY, int sasTtl) + public AMSProvider(string TenantId, string ClientId, string ClientSecret, Uri AMSApiUri, string WaterMarkStorageConStr, string WatermarkedStorageName, string AMSStorageConStr,string PUBLISHWATERKEDCOPY, int sasTtl) { AzureAdClientSymmetricKey clientSymmetricKey = new AzureAdClientSymmetricKey(ClientId, ClientSecret); var tokenCredentials = new AzureAdTokenCredentials(TenantId, clientSymmetricKey, AzureEnvironments.AzureCloudEnvironment); @@ -53,6 +54,7 @@ public AMSProvider(string TenantId, string ClientId, string ClientSecret, Uri AM _WaterMArkStorageAccount = CloudStorageAccount.Parse(WaterMarkStorageConStr); _WaterMArkStorageBlobClient = _WaterMArkStorageAccount.CreateCloudBlobClient(); _WaterMarkStorageConStr = WaterMarkStorageConStr; + _WatermarkedStorageName = WatermarkedStorageName; //AMS Stoarge _AMSStorageAccount = CloudStorageAccount.Parse(AMSStorageConStr); _AMSStorageBlobClient = _AMSStorageAccount.CreateCloudBlobClient(); @@ -123,13 +125,13 @@ private ManifestInfo GetManifest5Jobs(ManifestInfo manifestInfo,IAsset theAsset, VideoInformation video = CreateVideoInformationK28JobNode(file.Name, theAsset, AssetLocatorPath); manifestInfo.VideoInformation.Add(video); //Watermarked - foreach (var code in manifestInfo.EnbebedCodes) + foreach (var code in manifestInfo.EmbeddedCodes) { var wmp4Name = System.Web.HttpUtility.UrlPathEncode(video.FileName); code.MP4WatermarkedURL.Add(new MP4WatermarkedURL() { FileName = video.FileName, - WaterMarkedMp4 = GetBlobSasUri(_AMSStorageBlobClient,"watermarked", $"{theAsset.Id}/{code.EmbebedCode}/{wmp4Name}", allAccess, _SASTTL) + WaterMarkedMp4 = GetBlobSasUri(_WaterMArkStorageBlobClient,"watermarked", $"{theAsset.Id}/{code.Code}/{wmp4Name}", allAccess, _SASTTL) }); } } @@ -155,27 +157,27 @@ private async Task CreateSharedAccessPolicyAsync(string queueName, strin return accessSignature; } - public async Task GetK8SJobManifestAsync(string AssetID, string JobID, List codes) + public async Task GetK8SJobManifestAsync(string AssetId, string JobId, List codes) { string AssetLocatorPath = ""; - string EmbedderNotificationQueue = await CreateSharedAccessPolicyAsync("embeddernotification", JobID); - string PreprocessorNotificationQueue = await CreateSharedAccessPolicyAsync("preprocessorout", JobID); + string EmbedderNotificationQueue = await CreateSharedAccessPolicyAsync("embeddernotification", JobId); + string PreprocessorNotificationQueue = await CreateSharedAccessPolicyAsync("preprocessorout", JobId); ManifestInfo myData = new ManifestInfo { - JobID = JobID, - AssetID = AssetID, + JobId = JobId, + AssetId = AssetId, EmbedderNotificationQueue = EmbedderNotificationQueue, PreprocessorNotificationQueue = PreprocessorNotificationQueue, //Video information VideoInformation = new List(), - //Enbebedcodes - EnbebedCodes = new List() + //EmbeddedCodes + EmbeddedCodes = new List() }; foreach (var code in codes) { - myData.EnbebedCodes.Add(new EnbebedCode() + myData.EmbeddedCodes.Add(new EmbeddedCode() { - EmbebedCode = code, + Code = code, MP4WatermarkedURL = new List() }); } @@ -183,11 +185,11 @@ public async Task GetK8SJobManifestAsync(string AssetID, string Jo IAsset currentAsset = null; try { - currentAsset = _mediaContext.Assets.Where(a => a.Id == AssetID).FirstOrDefault(); + currentAsset = _mediaContext.Assets.Where(a => a.Id == AssetId).FirstOrDefault(); } catch (Exception X) { - throw new Exception($"AssetID {AssetID} not found. Error: {X.Message}"); + throw new Exception($"AssetId {AssetId} not found. Error: {X.Message}"); } var AssetLocator = currentAsset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin).FirstOrDefault(); @@ -203,7 +205,7 @@ public async Task GetK8SJobManifestAsync(string AssetID, string Jo IEnumerable mp4AssetFiles = currentAsset.AssetFiles.ToList().Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)).OrderBy(f => f.ContentFileSize); - myData = GetManifest5Jobs(myData, /*AssetID*/ currentAsset, mp4AssetFiles, AssetLocatorPath); + myData = GetManifest5Jobs(myData, /*AssetId*/ currentAsset, mp4AssetFiles, AssetLocatorPath); return myData; @@ -218,7 +220,7 @@ public void DeleteAsset(string AssetId) } public void DeleteWatermakedBlobRenders(string AssetId) { - CloudBlobContainer container = _AMSStorageBlobClient.GetContainerReference("watermarked"); + CloudBlobContainer container = _WaterMArkStorageBlobClient.GetContainerReference("watermarked"); foreach (IListBlobItem item in container.ListBlobs(AssetId, true)) { @@ -274,12 +276,12 @@ string ConvertMediaAssetIdToStorageContainerName(String AssetId) int startIndex = AssetPrefix.Length - 1; // return AssetBlobContainerNamePrefix + AssetId.Substring(startIndex, AssetId.Length - startIndex); } - IAsset GetMediaAssetFromAssetId(string assetId) + IAsset GetMediaAssetFromAssetId(string AssetId) { // Use a LINQ Select query to get an asset. var assetInstance = from a in _mediaContext.Assets - where a.Id == assetId + where a.Id == AssetId select a; // Reference the asset as an IAsset. IAsset asset = assetInstance.FirstOrDefault(); @@ -302,7 +304,7 @@ public async Task CreateEmptyWatermarkedAsset(string Proce IAsset SourceMediaAsset = GetMediaAssetFromAssetId(SourceAssetId); string NewAssetName = $"{SourceMediaAsset.Name}-{ProcessId}-{DateTime.Now.Ticks.ToString()}"; CancellationToken myToken = new CancellationToken(); - IAsset newWatermarkedAsset = await _mediaContext.Assets.CreateAsync(NewAssetName, AssetCreationOptions.None, myToken); + IAsset newWatermarkedAsset = await _mediaContext.Assets.CreateAsync(NewAssetName,_WatermarkedStorageName , AssetCreationOptions.None, myToken); newWatermarkedAsset.AlternateId = $"{SourceAssetId}-{WMEmbedCode}"; await newWatermarkedAsset.UpdateAsync(); result.Status = result.Status = "Finished"; ; @@ -389,7 +391,7 @@ public async Task AddWatermarkedMediaFiletoAsset(string Wa string containerName = ConvertMediaAssetIdToStorageContainerName(Asset.Id); - CloudBlobContainer DestinationBlobContainer = _AMSStorageBlobClient.ListContainers().Where(n => n.Name == containerName).FirstOrDefault(); + CloudBlobContainer DestinationBlobContainer = _WaterMArkStorageBlobClient.ListContainers().Where(n => n.Name == containerName).FirstOrDefault(); CloudBlockBlob sourceBlob = new CloudBlockBlob(new Uri(MMRKURL)); diff --git a/MB-ForensicWatermark/ActionsProvider/AMS/AMSProviderFactory.cs b/MB-ForensicWatermark/ActionsProvider/AMS/AMSProviderFactory.cs index abee217..f30aaf7 100644 --- a/MB-ForensicWatermark/ActionsProvider/AMS/AMSProviderFactory.cs +++ b/MB-ForensicWatermark/ActionsProvider/AMS/AMSProviderFactory.cs @@ -17,12 +17,13 @@ public static IAMSProvider CreateAMSProvider() string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"]; string ClientSecret = System.Configuration.ConfigurationManager.AppSettings["ClientSecret"]; Uri AMSApiUri = new Uri( System.Configuration.ConfigurationManager.AppSettings["AMSApiUri"]); - string Storageconn = System.Configuration.ConfigurationManager.AppSettings["Storageconn"]; + string WatermarkedStorageConn = System.Configuration.ConfigurationManager.AppSettings["WatermarkedStorageConn"]; + string WatermarkedStorageName = System.Configuration.ConfigurationManager.AppSettings["WatermarkedStorageName"]; string AMSStorageConStr= System.Configuration.ConfigurationManager.AppSettings["AMSStorageConStr"]; string PUBLISHWATERKEDCOPY= System.Configuration.ConfigurationManager.AppSettings["PUBLISHWATERKEDCOPY"] ?? "false"; //SAS URL TTL int SASTTL = int.Parse(System.Configuration.ConfigurationManager.AppSettings["SASTTL"] ?? "24"); - return new AMSProvider(TenantId,ClientId,ClientSecret,AMSApiUri, Storageconn, AMSStorageConStr, PUBLISHWATERKEDCOPY, SASTTL); + return new AMSProvider(TenantId,ClientId,ClientSecret,AMSApiUri, WatermarkedStorageConn, WatermarkedStorageName, AMSStorageConStr, PUBLISHWATERKEDCOPY, SASTTL); } } } diff --git a/MB-ForensicWatermark/ActionsProvider/AMS/IAMSProvider.cs b/MB-ForensicWatermark/ActionsProvider/AMS/IAMSProvider.cs index df017c6..733641d 100644 --- a/MB-ForensicWatermark/ActionsProvider/AMS/IAMSProvider.cs +++ b/MB-ForensicWatermark/ActionsProvider/AMS/IAMSProvider.cs @@ -10,7 +10,7 @@ public interface IAMSProvider { void DeleteAsset(string AssetId); - Task GetK8SJobManifestAsync(string AssetID, string JobID, List codes); + Task GetK8SJobManifestAsync(string AssetId, string JobId, List codes); Task AddWatermarkedMediaFiletoAsset(string WatermarkedAssetId, string WMEmbedCode, string MMRKURL); Task CreateEmptyWatermarkedAsset(string ProcessId,string SourceAssetId, string WMEmbedCode); void DeleteWatermakedBlobRenders(string AssetId); diff --git a/MB-ForensicWatermark/ActionsProvider/ActionProvider.cs b/MB-ForensicWatermark/ActionsProvider/ActionProvider.cs index 3e84863..37b406c 100644 --- a/MB-ForensicWatermark/ActionsProvider/ActionProvider.cs +++ b/MB-ForensicWatermark/ActionsProvider/ActionProvider.cs @@ -57,7 +57,7 @@ public UnifiedResponse.WaterMarkedRender UpdateWaterMarkedRender(UnifiedResponse myTable.Execute(InsertOrReplace); return renderData; } - public List GetWaterMarkedRenders(string ParentAssetID, string EmbebedCodeValue) + public List GetWaterMarkedRenders(string ParentAssetId, string EmbeddedCodeValue) { List myList = new List(); var wmrTable = tableClient.GetTableReference(ReferenceNames.WaterMarkedRender); @@ -65,7 +65,7 @@ public UnifiedResponse.WaterMarkedRender UpdateWaterMarkedRender(UnifiedResponse TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition( - "PartitionKey", QueryComparisons.Equal, $"{ParentAssetID}-{EmbebedCodeValue}")); + "PartitionKey", QueryComparisons.Equal, $"{ParentAssetId}-{EmbeddedCodeValue}")); var wmrTList = wmrTable.ExecuteQuery(query); @@ -77,17 +77,17 @@ public UnifiedResponse.WaterMarkedRender UpdateWaterMarkedRender(UnifiedResponse return myList; } - public UnifiedResponse.WaterMarkedRender GetWaterMarkedRender(string ParentAssetID, string EmbebedCodeValue, string RenderName) + public UnifiedResponse.WaterMarkedRender GetWaterMarkedRender(string ParentAssetId, string EmbeddedCodeValue, string RenderName) { UnifiedResponse.WaterMarkedRender x = null; UnifiedResponse.WaterMarkedAssetInfo wai = new UnifiedResponse.WaterMarkedAssetInfo() { - AssetID = ParentAssetID, + AssetId = ParentAssetId, }; var myTable = tableClient.GetTableReference(ReferenceNames.WaterMarkedRender); myTable.CreateIfNotExists(); - TableOperation retrieveOperation = TableOperation.Retrieve($"{ParentAssetID}-{EmbebedCodeValue}", RenderName); + TableOperation retrieveOperation = TableOperation.Retrieve($"{ParentAssetId}-{EmbeddedCodeValue}", RenderName); TableResult retrievedResult = myTable.Execute(retrieveOperation); if (retrievedResult.Result != null) { @@ -107,7 +107,7 @@ public async Task EvalPEmbeddedNotifications() try { NotificationEmbedder rawdata = Newtonsoft.Json.JsonConvert.DeserializeObject(message.AsString); - WaterMarkedRender data = GetWaterMarkedRender(rawdata.AssetID, rawdata.EmbebedCode, rawdata.FileName); + WaterMarkedRender data = GetWaterMarkedRender(rawdata.AssetId, rawdata.EmbeddedCode, rawdata.FileName); string url = data.MP4URL; data = new WaterMarkedRender(rawdata, url); var outputData = UpdateWaterMarkedRender(data); @@ -204,16 +204,16 @@ public void UpdateUnifiedProcessStatus(UnifiedResponse.UnifiedProcessStatus curr TableOperation InsertOrReplace = TableOperation.InsertOrReplace(new UnifiedResponse.TJobStatus(curretnData.JobStatus, curretnData.AssetStatus.AssetId)); _ProcessStatusTable.Execute(InsertOrReplace); //Update all Enbebed - foreach (var data in curretnData.EmbebedCodesList) + foreach (var data in curretnData.EmbeddedCodesList) { UpdateWaterMarkedAssetInfo(data, curretnData.AssetStatus.AssetId); } } - private UnifiedResponse.JobStatus GetJobStatus(string AssetId, string JobID) + private UnifiedResponse.JobStatus GetJobStatus(string AssetId, string JobId) { UnifiedResponse.JobStatus data = null; - TableOperation retrieveOperation = TableOperation.Retrieve(AssetId, JobID); + TableOperation retrieveOperation = TableOperation.Retrieve(AssetId, JobId); TableResult retrievedResult = _ProcessStatusTable.Execute(retrieveOperation); if (retrievedResult.Result != null) { @@ -221,44 +221,44 @@ private UnifiedResponse.JobStatus GetJobStatus(string AssetId, string JobID) } return data; } - public UnifiedResponse.UnifiedProcessStatus GetUnifiedProcessStatus(string AssetId, string JobID) + public UnifiedResponse.UnifiedProcessStatus GetUnifiedProcessStatus(string AssetId, string JobId) { UnifiedResponse.UnifiedProcessStatus Manifest = new UnifiedResponse.UnifiedProcessStatus { AssetStatus = GetAssetStatus(AssetId), - JobStatus = GetJobStatus(AssetId, JobID), - EmbebedCodesList = new List() + JobStatus = GetJobStatus(AssetId, JobId), + EmbeddedCodesList = new List() }; - foreach (var ecode in Manifest.JobStatus.EmbebedCodeList) + foreach (var ecode in Manifest.JobStatus.EmbeddedCodeList) { - Manifest.EmbebedCodesList.Add(GetWaterMarkedAssetInfo(AssetId, ecode)); + Manifest.EmbeddedCodesList.Add(GetWaterMarkedAssetInfo(AssetId, ecode)); } return Manifest; } - public UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, string JobId, string[] EmbebedCodeList) + public UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, string JobId, string[] EmbeddedCodeList) { //NEW Process UnifiedResponse.UnifiedProcessStatus newProcess = new UnifiedResponse.UnifiedProcessStatus { - EmbebedCodesList = new List(), + EmbeddedCodesList = new List(), //2. JobStatus JobStatus = new UnifiedResponse.JobStatus() { Details = "Queue", Duration = null, FinishTime = null, - JobID = JobId, + JobId = JobId, StartTime = DateTime.Now, State = ExecutionStatus.Running, - EmbebedCodeList = EmbebedCodeList + EmbeddedCodeList = EmbeddedCodeList }, AssetStatus = GetAssetStatus(AssetId) ?? new UnifiedResponse.AssetStatus() { AssetId = AssetId, State = ExecutionStatus.New } }; //Status - ExecutionStatus EmbebedStatus = ExecutionStatus.New; + ExecutionStatus EmbeddedStatus = ExecutionStatus.New; switch (newProcess.AssetStatus.State) { @@ -267,7 +267,7 @@ public UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, stri newProcess.JobStatus.Details = "MMRK Files Generation Error"; newProcess.JobStatus.FinishTime = DateTime.Now; newProcess.JobStatus.Duration = DateTime.Now.Subtract(newProcess.JobStatus.StartTime); - EmbebedStatus = ExecutionStatus.Aborted; + EmbeddedStatus = ExecutionStatus.Aborted; break; case ExecutionStatus.Running: @@ -275,7 +275,7 @@ public UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, stri newProcess.JobStatus.State = ExecutionStatus.Error; newProcess.JobStatus.FinishTime = DateTime.Now; newProcess.JobStatus.Duration = DateTime.Now.Subtract(newProcess.JobStatus.StartTime); - EmbebedStatus = ExecutionStatus.Aborted; + EmbeddedStatus = ExecutionStatus.Aborted; break; @@ -287,7 +287,7 @@ public UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, stri //New Asset //Asset has not oter process running newProcess.AssetStatus.State = ExecutionStatus.Running; - EmbebedStatus = ExecutionStatus.Running; + EmbeddedStatus = ExecutionStatus.Running; newProcess.JobStatus.State = ExecutionStatus.Running; } else @@ -301,12 +301,12 @@ public UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, stri newProcess.JobStatus.State = ExecutionStatus.Error; newProcess.JobStatus.FinishTime = DateTime.Now; newProcess.JobStatus.Duration = DateTime.Now.Subtract(newProcess.JobStatus.StartTime); - EmbebedStatus = ExecutionStatus.Aborted; + EmbeddedStatus = ExecutionStatus.Aborted; } else { //Asset has not other process running - EmbebedStatus = ExecutionStatus.Running; + EmbeddedStatus = ExecutionStatus.Running; newProcess.JobStatus.State = ExecutionStatus.Running; } } @@ -314,16 +314,16 @@ public UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, stri default: break; } - //Embebedecodes - foreach (var code in EmbebedCodeList) + //Embeddedecodes + foreach (var code in EmbeddedCodeList) { - newProcess.EmbebedCodesList.Add( + newProcess.EmbeddedCodesList.Add( new UnifiedResponse.WaterMarkedAssetInfo() { - ParentAssetID = AssetId, - State = EmbebedStatus, - EmbebedCodeValue = code, - AssetID = "", + ParentAssetId = AssetId, + State = EmbeddedStatus, + EmbeddedCodeValue = code, + AssetId = "", Details = "Just Start" }); } @@ -349,7 +349,7 @@ public UnifiedProcessStatus UpdateJob(UnifiedResponse.UnifiedProcessStatus proce break; } - foreach (var watermaekAssetInfo in processState.EmbebedCodesList) + foreach (var watermaekAssetInfo in processState.EmbeddedCodesList) { watermaekAssetInfo.State = watermarkState; watermaekAssetInfo.Details = WaterMarkCopiesStatusDetails; @@ -374,10 +374,10 @@ public MMRKStatus GetMMRKStatus(string AsssetId, string JobRender) } return myData; } - public List GetMMRKStatusList(string AssetID) + public List GetMMRKStatusList(string AssetId) { List ret = new List(); - TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, AssetID)); + TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, AssetId)); var mmrkList = _MMRKSttausTable.ExecuteQuery(query); foreach (var item in mmrkList) { @@ -392,10 +392,10 @@ private UnifiedResponse.WaterMarkedAssetInfo UpdateWaterMarkedAssetInfo(UnifiedR _WaterMarkedAssetInfo.Execute(InsertOrReplace); return data; } - private UnifiedResponse.WaterMarkedAssetInfo GetWaterMarkedAssetInfo(string AssetId, string EmbebedCodeValue) + private UnifiedResponse.WaterMarkedAssetInfo GetWaterMarkedAssetInfo(string AssetId, string EmbeddedCodeValue) { UnifiedResponse.WaterMarkedAssetInfo z = null; - TableOperation retrieveOperation = TableOperation.Retrieve(AssetId, EmbebedCodeValue); + TableOperation retrieveOperation = TableOperation.Retrieve(AssetId, EmbeddedCodeValue); TableResult retrievedResult = _WaterMarkedAssetInfo.Execute(retrieveOperation); if (retrievedResult.Result != null) { @@ -404,9 +404,9 @@ private UnifiedResponse.WaterMarkedAssetInfo GetWaterMarkedAssetInfo(string Asse return z; } - public UnifiedResponse.WaterMarkedAssetInfo EvalWaterMarkedAssetInfo(string ParentAssetID, string EmbebedCodeValue) + public UnifiedResponse.WaterMarkedAssetInfo EvalWaterMarkedAssetInfo(string ParentAssetId, string EmbeddedCodeValue) { - UnifiedResponse.WaterMarkedAssetInfo currentWaterMarkInfo = GetWaterMarkedAssetInfo(ParentAssetID, EmbebedCodeValue); + UnifiedResponse.WaterMarkedAssetInfo currentWaterMarkInfo = GetWaterMarkedAssetInfo(ParentAssetId, EmbeddedCodeValue); if (currentWaterMarkInfo.State == ExecutionStatus.Running) { @@ -415,7 +415,7 @@ public UnifiedResponse.WaterMarkedAssetInfo EvalWaterMarkedAssetInfo(string Pare TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition( - "PartitionKey", QueryComparisons.Equal, $"{ParentAssetID}-{EmbebedCodeValue}")); + "PartitionKey", QueryComparisons.Equal, $"{ParentAssetId}-{EmbeddedCodeValue}")); var wmrList = wmrTable.ExecuteQuery(query); if (wmrList != null) @@ -424,7 +424,7 @@ public UnifiedResponse.WaterMarkedAssetInfo EvalWaterMarkedAssetInfo(string Pare { //Error currentWaterMarkInfo.State = ExecutionStatus.Error; - //Update EmbebedCode + //Update EmbeddedCode currentWaterMarkInfo.State = ExecutionStatus.Error; currentWaterMarkInfo.Details = $"Render with errors"; } @@ -441,7 +441,7 @@ public UnifiedResponse.WaterMarkedAssetInfo EvalWaterMarkedAssetInfo(string Pare currentWaterMarkInfo.Details = $"Ready {finishcount} of {wmrList.Count()}"; } } - UpdateWaterMarkedAssetInfo(currentWaterMarkInfo, ParentAssetID); + UpdateWaterMarkedAssetInfo(currentWaterMarkInfo, ParentAssetId); } return currentWaterMarkInfo; @@ -466,8 +466,8 @@ public async Task EvalPreprocessorNotifications() { var jNotification = Newtonsoft.Json.Linq.JObject.Parse(message.AsString); // Retrive - string jobRender = $"[{(string)jNotification["JobID"]}]{(string)jNotification["FileName"]}"; - var MMRK = GetMMRKStatus((string)jNotification["AssetID"], jobRender); + string jobRender = $"[{(string)jNotification["JobId"]}]{(string)jNotification["FileName"]}"; + var MMRK = GetMMRKStatus((string)jNotification["AssetId"], jobRender); //Update MMRK Status MMRK.Details = (string)jNotification["JobOutput"]; MMRK.State = (ExecutionStatus)Enum.Parse(typeof(ExecutionStatus), (string)jNotification["Status"]); @@ -488,7 +488,7 @@ public async Task EvalPreprocessorNotifications() #endregion #region K8S JOBS - private string GetJobYmal(string JobID, string JOBBASE64, string imagename) + private string GetJobYmal(string JobId, string JOBBASE64, string imagename) { string path; if (Environment.GetEnvironmentVariable("HOME") != null) @@ -501,24 +501,24 @@ private string GetJobYmal(string JobID, string JOBBASE64, string imagename) } string ymal = System.IO.File.ReadAllText(path); - ymal = ymal.Replace("[JOBNAME]", "allinone-job-" + JobID); + ymal = ymal.Replace("[JOBNAME]", "allinone-job-" + JobId); ymal = ymal.Replace("[IMAGENAME]", imagename); return ymal.Replace("[JOBBASE64]", JOBBASE64); } - public async Task SubmiteJobK8S(ManifestInfo manifest, int subId) + public async Task SubmitJobK8S(ManifestInfo manifest, int subId) { //Create Yamal Job definition string manifesttxt = Newtonsoft.Json.JsonConvert.SerializeObject(manifest); string jobbase64 = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(manifesttxt), Base64FormattingOptions.None); string imageName = System.Configuration.ConfigurationManager.AppSettings["imageName"]; - string jobtxt = GetJobYmal(manifest.JobID + "-" + subId.ToString(), jobbase64, imageName); + string jobtxt = GetJobYmal(manifest.JobId + "-" + subId.ToString(), jobbase64, imageName); HttpContent ymal = new StringContent(jobtxt, Encoding.UTF8, "application/yaml"); - // Submite JOB + // Submit JOB IK8SClient k8sClient = K8SClientFactory.Create(); - var rs = await k8sClient.SubmiteK8SJob(ymal); + var rs = await k8sClient.SubmitK8SJob(ymal); return rs; } @@ -526,20 +526,20 @@ private ManifestInfo GetManifestInfo(int skip, int take, ManifestInfo manifest) { ManifestInfo aggregateJobManifest = new ManifestInfo() { - AssetID = manifest.AssetID, + AssetId = manifest.AssetId, EmbedderNotificationQueue = manifest.EmbedderNotificationQueue, - EnbebedCodes = new List(), - JobID = manifest.JobID, + EmbeddedCodes = new List(), + JobId = manifest.JobId, PreprocessorNotificationQueue = manifest.PreprocessorNotificationQueue, VideoInformation = new List() }; //Add aggregated video info nodes aggregateJobManifest.VideoInformation.AddRange(manifest.VideoInformation.Skip(skip).Take(take)); - foreach (var emc in manifest.EnbebedCodes) + foreach (var emc in manifest.EmbeddedCodes) { - EnbebedCode jobemc = new EnbebedCode() + EmbeddedCode jobemc = new EmbeddedCode() { - EmbebedCode = emc.EmbebedCode, + Code = emc.Code, MP4WatermarkedURL = new List() }; foreach (var vi in aggregateJobManifest.VideoInformation) @@ -548,7 +548,7 @@ private ManifestInfo GetManifestInfo(int skip, int take, ManifestInfo manifest) //add to the list jobemc.MP4WatermarkedURL.Add(myMMP4WatermarkeInfo); } - aggregateJobManifest.EnbebedCodes.Add(jobemc); + aggregateJobManifest.EmbeddedCodes.Add(jobemc); } return aggregateJobManifest; diff --git a/MB-ForensicWatermark/ActionsProvider/ActionProviderFactory.cs b/MB-ForensicWatermark/ActionsProvider/ActionProviderFactory.cs index f767ac0..cafcb05 100644 --- a/MB-ForensicWatermark/ActionsProvider/ActionProviderFactory.cs +++ b/MB-ForensicWatermark/ActionsProvider/ActionProviderFactory.cs @@ -9,7 +9,7 @@ public class ActionProviderFactory { public static IActionsProvider GetActionProvider() { - string Storageconn = System.Configuration.ConfigurationManager.AppSettings["Storageconn"]; + string Storageconn = System.Configuration.ConfigurationManager.AppSettings["WatermarkedStorageConn"]; return new ActionProvider(Storageconn); } } diff --git a/MB-ForensicWatermark/ActionsProvider/ActionsProvider.csproj b/MB-ForensicWatermark/ActionsProvider/ActionsProvider.csproj index c35663c..eb5a80c 100644 --- a/MB-ForensicWatermark/ActionsProvider/ActionsProvider.csproj +++ b/MB-ForensicWatermark/ActionsProvider/ActionsProvider.csproj @@ -75,8 +75,8 @@ ..\packages\windowsazure.mediaservices.4.1.0.1\lib\net45\Microsoft.WindowsAzure.MediaServices.Client.Common.FileEncryption.dll - - ..\packages\WindowsAzure.Storage.8.6.0\lib\net45\Microsoft.WindowsAzure.Storage.dll + + ..\packages\WindowsAzure.Storage.8.7.0\lib\net45\Microsoft.WindowsAzure.Storage.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -131,8 +131,10 @@ + + diff --git a/MB-ForensicWatermark/ActionsProvider/Entities/JobSubmitData.cs b/MB-ForensicWatermark/ActionsProvider/Entities/JobSubmitData.cs index 4a39e77..5e2bd68 100644 --- a/MB-ForensicWatermark/ActionsProvider/Entities/JobSubmitData.cs +++ b/MB-ForensicWatermark/ActionsProvider/Entities/JobSubmitData.cs @@ -26,20 +26,20 @@ public class MP4WatermarkedURL public string WaterMarkedMp4 { get; set; } } - public class EnbebedCode + public class EmbeddedCode { - public string EmbebedCode { get; set; } + public string Code { get; set; } public List MP4WatermarkedURL { get; set; } } public class ManifestInfo { - public string JobID { get; set; } - public string AssetID { get; set; } + public string JobId { get; set; } + public string AssetId { get; set; } public string PreprocessorNotificationQueue { get; set; } public string EmbedderNotificationQueue { get; set; } public List VideoInformation { get; set; } - public List EnbebedCodes { get; set; } + public List EmbeddedCodes { get; set; } } diff --git a/MB-ForensicWatermark/ActionsProvider/Entities/MMRKStatus.cs b/MB-ForensicWatermark/ActionsProvider/Entities/MMRKStatus.cs index 109e596..683f19e 100644 --- a/MB-ForensicWatermark/ActionsProvider/Entities/MMRKStatus.cs +++ b/MB-ForensicWatermark/ActionsProvider/Entities/MMRKStatus.cs @@ -24,19 +24,19 @@ public class TMMRKStatus: TableEntity public string FileName { get; set; } public string Details { get; set; } - public string JobID { get; set; } + public string JobId { get; set; } public string FileURL { get; set; } public TMMRKStatus() { } public TMMRKStatus(MMRKStatus data) { - this.PartitionKey = data.AssetID; - //this.RowKey =$"[{data.JobID}]{data.FileName}"; - this.RowKey = $"[{data.JobID}]{data.FileName}"; + this.PartitionKey = data.AssetId; + //this.RowKey =$"[{data.JobId}]{data.FileName}"; + this.RowKey = $"[{data.JobId}]{data.FileName}"; FileName = data.FileName; State = data.State.ToString(); - JobID = data.JobID; + JobId = data.JobId; Details = data.Details; FileURL = data.FileURL; } @@ -45,8 +45,8 @@ public MMRKStatus GetMMRKStatus() { return new MMRKStatus { - AssetID = PartitionKey, - JobID = JobID, + AssetId = PartitionKey, + JobId = JobId, FileName = FileName, Details = Details, FileURL = FileURL, @@ -56,8 +56,8 @@ public MMRKStatus GetMMRKStatus() } public class MMRKStatus { - public string JobID { get; set; } - public string AssetID { get; set; } + public string JobId { get; set; } + public string AssetId { get; set; } public string FileName { get; set; } public ExecutionStatus State { get; set; } public string Details { get; set; } diff --git a/MB-ForensicWatermark/ActionsProvider/Entities/RequestData.cs b/MB-ForensicWatermark/ActionsProvider/Entities/RequestData.cs new file mode 100644 index 0000000..2c8e004 --- /dev/null +++ b/MB-ForensicWatermark/ActionsProvider/Entities/RequestData.cs @@ -0,0 +1,51 @@ +using ActionsProvider.UnifiedResponse; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ActionsProvider.Entities +{ + public class RequestData + { + public class AssetRequest + { + public string AssetId { get; set; } + } + public class JobRequest + { + public string JobId { get; set; } + } + public class CheckAssetStatus: AssetRequest{ } + public class BaseStatusData + { + public string AssetId { get; set; } + public string JobId { get; set; } + } + public class StartNewJob: BaseStatusData + { + public string[] EmbeddedCodes { get; set; } + } + public class GetPreprocessorJobData: BaseStatusData + { + public List EmbeddedCodes { get; set; } + } + public class UpdateWaterMarkCode + { + public EmbeddedCode EmbeddedCode { get; set; } + public string ParentAssetId { get; set; } + } + public class UpdateJob + { + public UnifiedProcessStatus Manifest { get; set; } + public ExecutionStatus AssetStatus { get; set; } + public ExecutionStatus JobState { get; set; } + public string JobStateDetails { get; set; } + public string WaterMarkCopiesStatusDetails { get; set; } + public ExecutionStatus WaterMarkCopiesStatus { get; set; } + } + public class GetUnifiedProcessStatus : BaseStatusData { } + + } +} diff --git a/MB-ForensicWatermark/ActionsProvider/Entities/UnifiedResponse.cs b/MB-ForensicWatermark/ActionsProvider/Entities/UnifiedResponse.cs index 0c39d6b..2d0088a 100644 --- a/MB-ForensicWatermark/ActionsProvider/Entities/UnifiedResponse.cs +++ b/MB-ForensicWatermark/ActionsProvider/Entities/UnifiedResponse.cs @@ -41,31 +41,31 @@ public AssetStatus GetAssetStatus() } public class JobStatus { - public string JobID { get; set; } + public string JobId { get; set; } public ExecutionStatus State { get; set; } public string Details { get; set; } public DateTime StartTime { get; set; } public DateTime? FinishTime { get; set; } public TimeSpan? Duration { get; set; } - public string[] EmbebedCodeList { get; set; } + public string[] EmbeddedCodeList { get; set; } } public class TJobStatus : TableEntity { public TJobStatus() { } - public TJobStatus(JobStatus Data, string AssetID) + public TJobStatus(JobStatus Data, string AssetId) { - PartitionKey = AssetID; - RowKey = Data.JobID; + PartitionKey = AssetId; + RowKey = Data.JobId; State = Data.State.ToString(); Details = Data.Details; StartTime = Data.StartTime; FinishTime = Data.FinishTime; Duration = Data.Duration.ToString(); - EmbebedCodeList =string.Join(";", Data.EmbebedCodeList); + EmbeddedCodeList =string.Join(";", Data.EmbeddedCodeList); } - public string EmbebedCodeList { get; set; } + public string EmbeddedCodeList { get; set; } public string State { get; set; } public string Details { get; set; } @@ -81,9 +81,9 @@ public JobStatus GetJobStatus() //Duration = TimeSpan.Parse( Duration.ToString() ?? "", FinishTime = FinishTime, StartTime = StartTime, - JobID = RowKey, + JobId = RowKey, State = (ExecutionStatus)Enum.Parse(typeof(ExecutionStatus), this.State), - EmbebedCodeList = EmbebedCodeList.Split(';') + EmbeddedCodeList = EmbeddedCodeList.Split(';') }; if (!string.IsNullOrEmpty( Duration)) { @@ -94,37 +94,37 @@ public JobStatus GetJobStatus() } public class WaterMarkedAssetInfo { - public string EmbebedCodeValue { get; set; } + public string EmbeddedCodeValue { get; set; } public ExecutionStatus State { get; set; } - public string ParentAssetID { get; set; } - public string AssetID { get; set; } + public string ParentAssetId { get; set; } + public string AssetId { get; set; } public string Details { get; set; } } public class TWaterMarkedAssetInfo :TableEntity { public TWaterMarkedAssetInfo () { } - public TWaterMarkedAssetInfo (WaterMarkedAssetInfo Data, string ParentAssetID) + public TWaterMarkedAssetInfo (WaterMarkedAssetInfo Data, string ParentAssetId) { - this.PartitionKey = ParentAssetID; + this.PartitionKey = ParentAssetId; this.State = Data.State.ToString(); - this.RowKey = Data.EmbebedCodeValue; - this.AssetID = Data.AssetID; + this.RowKey = Data.EmbeddedCodeValue; + this.AssetId = Data.AssetId; this.Details = Data.Details; - this.EmbebedCode = Data.EmbebedCodeValue; + this.EmbeddedCode = Data.EmbeddedCodeValue; } public string Details { get; set; } - public string EmbebedCode { get; set; } + public string EmbeddedCode { get; set; } public string State { get; set; } - public string AssetID { get; set; } + public string AssetId { get; set; } public WaterMarkedAssetInfo GetWaterMarkedAsssetInfo() { return new WaterMarkedAssetInfo() { - ParentAssetID = PartitionKey, - EmbebedCodeValue = RowKey, + ParentAssetId = PartitionKey, + EmbeddedCodeValue = RowKey, State= (ExecutionStatus)Enum.Parse(typeof(ExecutionStatus), this.State), - AssetID =AssetID, + AssetId =AssetId, Details=Details }; } @@ -132,8 +132,8 @@ public WaterMarkedAssetInfo GetWaterMarkedAsssetInfo() } public class WaterMarkedRender { - public string EmbebedCodeValue { get; set; } - public string ParentAssetID { get; set; } + public string EmbeddedCodeValue { get; set; } + public string ParentAssetId { get; set; } public string RenderName { get; set; } public string MP4URL{ get; set; } public string Details { get; set; } @@ -144,10 +144,10 @@ public WaterMarkedRender() { } public WaterMarkedRender(NotificationEmbedder textData,string MP4URL) { - this.Details = $"[{textData.JobID}] {textData.JobOutput}"; - this.EmbebedCodeValue = textData.EmbebedCode; + this.Details = $"[{textData.JobId}] {textData.JobOutput}"; + this.EmbeddedCodeValue = textData.EmbeddedCode; this.MP4URL = MP4URL; - this.ParentAssetID = textData.AssetID; + this.ParentAssetId = textData.AssetId; this.RenderName = textData.FileName; this.State = (ExecutionStatus)Enum.Parse(typeof(ExecutionStatus), textData.Status); @@ -156,9 +156,9 @@ public WaterMarkedRender(NotificationEmbedder textData,string MP4URL) public class TWaterMarkedRender:TableEntity { - public string EmbebedCodeValue { get; set; } + public string EmbeddedCodeValue { get; set; } public string State { get; set; } - public string ParentAssetID { get; set; } + public string ParentAssetId { get; set; } public string MP4URL { get; set; } public string Details { get; set; } @@ -166,12 +166,12 @@ public TWaterMarkedRender() { } public TWaterMarkedRender(WaterMarkedRender Data) { - PartitionKey = $"{Data.ParentAssetID}-{Data.EmbebedCodeValue}"; + PartitionKey = $"{Data.ParentAssetId}-{Data.EmbeddedCodeValue}"; RowKey = Data.RenderName; //Properties - EmbebedCodeValue = Data.EmbebedCodeValue; + EmbeddedCodeValue = Data.EmbeddedCodeValue; State = Data.State.ToString(); - ParentAssetID = Data.ParentAssetID; + ParentAssetId = Data.ParentAssetId; MP4URL = Data.MP4URL; Details = Data.Details; } @@ -179,9 +179,9 @@ public WaterMarkedRender GetWaterMarkedRender() { return new WaterMarkedRender() { - EmbebedCodeValue=this.EmbebedCodeValue, + EmbeddedCodeValue=this.EmbeddedCodeValue, MP4URL=this.MP4URL, - ParentAssetID=ParentAssetID, + ParentAssetId=ParentAssetId, RenderName=RowKey, State= (ExecutionStatus)Enum.Parse(typeof(ExecutionStatus), this.State), Details=Details @@ -191,10 +191,10 @@ public WaterMarkedRender GetWaterMarkedRender() } public class NotificationEmbedder { - public string JobID { get; set; } - public string AssetID { get; set; } + public string JobId { get; set; } + public string AssetId { get; set; } public string FileName { get; set; } - public string EmbebedCode { get; set; } + public string EmbeddedCode { get; set; } public string Status { get; set; } public string JobOutput { get; set; } @@ -203,6 +203,6 @@ public class UnifiedProcessStatus { public AssetStatus AssetStatus { get; set; } public JobStatus JobStatus { get; set; } - public List EmbebedCodesList { get; set; } + public List EmbeddedCodesList { get; set; } } } diff --git a/MB-ForensicWatermark/ActionsProvider/Extensions.cs b/MB-ForensicWatermark/ActionsProvider/Extensions.cs new file mode 100644 index 0000000..f1a2fd6 --- /dev/null +++ b/MB-ForensicWatermark/ActionsProvider/Extensions.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace ActionsProvider +{ + public static class HttpRequestMessageExtensions + { + public static T GetBodyData(this string payload) where T : class, new() + { + T result = default(T); + + if (payload != null) + { + result = JsonConvert.DeserializeObject(payload, + new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }); + } + + + return result; + } + } +} diff --git a/MB-ForensicWatermark/ActionsProvider/IActionsProvider.cs b/MB-ForensicWatermark/ActionsProvider/IActionsProvider.cs index 177a658..0dbcd2c 100644 --- a/MB-ForensicWatermark/ActionsProvider/IActionsProvider.cs +++ b/MB-ForensicWatermark/ActionsProvider/IActionsProvider.cs @@ -16,20 +16,20 @@ public interface IActionsProvider { MMRKStatus UpdateMMRKStatus(MMRKStatus mmrkStatus); - UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, string JobId, string[] EmbebedCodeList); + UnifiedResponse.UnifiedProcessStatus StartNewProcess(string AssetId, string JobId, string[] EmbeddedCodeList); MMRKStatus GetMMRKStatus(string AsssetId, string JobRender); - List GetMMRKStatusList(string AssetID); + List GetMMRKStatusList(string AssetId); UnifiedResponse.AssetStatus GetAssetStatus(string AssetId); Task EvalPreprocessorNotifications(); Task EvalPEmbeddedNotifications(); UnifiedResponse.AssetStatus EvalAssetStatus(string AssetId); UnifiedResponse.WaterMarkedRender UpdateWaterMarkedRender(UnifiedResponse.WaterMarkedRender renderData); - UnifiedResponse.WaterMarkedRender GetWaterMarkedRender(string ParentAssetID, string EmbebedCodeValue, string RenderName); - List GetWaterMarkedRenders(string ParentAssetID, string EmbebedCodeValue); - UnifiedResponse.WaterMarkedAssetInfo EvalWaterMarkedAssetInfo(string ParentAssetID, string EmbebedCodeValue); + UnifiedResponse.WaterMarkedRender GetWaterMarkedRender(string ParentAssetId, string EmbeddedCodeValue, string RenderName); + List GetWaterMarkedRenders(string ParentAssetId, string EmbeddedCodeValue); + UnifiedResponse.WaterMarkedAssetInfo EvalWaterMarkedAssetInfo(string ParentAssetId, string EmbeddedCodeValue); void UpdateUnifiedProcessStatus(UnifiedResponse.UnifiedProcessStatus curretnData); - UnifiedResponse.UnifiedProcessStatus GetUnifiedProcessStatus(string AssetId, string JobID); - Task SubmiteJobK8S(ManifestInfo manifest, int subId); + UnifiedResponse.UnifiedProcessStatus GetUnifiedProcessStatus(string AssetId, string JobId); + Task SubmitJobK8S(ManifestInfo manifest, int subId); UnifiedResponse.UnifiedProcessStatus UpdateJob(UnifiedResponse.UnifiedProcessStatus currentData, ExecutionStatus AssetState, ExecutionStatus JobState, string JobStateDetails, ExecutionStatus watermarkState, string WaterMarkCopiesStatusDetails); List GetK8SManifestInfo(int aggregationLevel, int aggregationLevelOnlyEmb, ManifestInfo manifest); diff --git a/MB-ForensicWatermark/ActionsProvider/K8S/IK8SClient.cs b/MB-ForensicWatermark/ActionsProvider/K8S/IK8SClient.cs index 613b1f1..45ad091 100644 --- a/MB-ForensicWatermark/ActionsProvider/K8S/IK8SClient.cs +++ b/MB-ForensicWatermark/ActionsProvider/K8S/IK8SClient.cs @@ -11,6 +11,6 @@ public interface IK8SClient { Task>> GetK8SJobLog(string JobNamePrefix); Task DeletePods(string JobName,string status = "All"); - Task SubmiteK8SJob(HttpContent yamalJob); + Task SubmitK8SJob(HttpContent yamalJob); } } diff --git a/MB-ForensicWatermark/ActionsProvider/K8S/K8SClient.cs b/MB-ForensicWatermark/ActionsProvider/K8S/K8SClient.cs index d9f8b89..4acbfdf 100644 --- a/MB-ForensicWatermark/ActionsProvider/K8S/K8SClient.cs +++ b/MB-ForensicWatermark/ActionsProvider/K8S/K8SClient.cs @@ -237,7 +237,7 @@ public async Task DeletePods(string jobname, string status = "All") r.Content = Newtonsoft.Json.JsonConvert.SerializeObject(deleteLog); return r; } - public async Task SubmiteK8SJob(HttpContent yamalJob) + public async Task SubmitK8SJob(HttpContent yamalJob) { K8SResult r = new K8SResult(); var rs = await CallK8SPostAsync(yamalJob, K8SURLTOKEN, CREATEJOBAPIPATH); diff --git a/MB-ForensicWatermark/ActionsProvider/app.config b/MB-ForensicWatermark/ActionsProvider/app.config index 956b37a..09619dc 100644 --- a/MB-ForensicWatermark/ActionsProvider/app.config +++ b/MB-ForensicWatermark/ActionsProvider/app.config @@ -20,7 +20,7 @@ - + diff --git a/MB-ForensicWatermark/ActionsProvider/packages.config b/MB-ForensicWatermark/ActionsProvider/packages.config index f6856d8..7322c6c 100644 --- a/MB-ForensicWatermark/ActionsProvider/packages.config +++ b/MB-ForensicWatermark/ActionsProvider/packages.config @@ -45,5 +45,5 @@ - + \ No newline at end of file diff --git a/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.json b/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.json index 80fc592..bbd28f0 100644 --- a/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.json +++ b/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.json @@ -38,6 +38,19 @@ "description": "Azure Media Services Storage connection string" } }, + + "WatermarkedStorageConn": { + "type": "string", + "metadata": { + "description": "Watermarked Azure Media Services Storage connection string" + } + }, + "WatermarkedStorageName": { + "type": "string", + "metadata": { + "description": "Watermarked Azure Media Services Storage connection name" + } + }, "K8SURL": { "type": "string", "metadata": { @@ -72,7 +85,7 @@ } }, "variables": { - + "PUBLISHWATERKEDCOPY": "false", "branch": "master", "KeepWatermakedBlobs": "false", "gopsize": "3", @@ -171,6 +184,14 @@ "name": "AMSStorageConStr", "value": "[parameters('AMSStorageConStr')]" }, + { + "name": "WatermarkedStorageConn", + "value": "[parameters('WatermarkedStorageConn')]" + }, + { + "name": "WatermarkedStorageName", + "value": "[parameters('WatermarkedStorageName')]" + }, { "name": "K8SURL", "value": "[parameters('K8SURL')]" @@ -195,6 +216,14 @@ "name": "KeepWatermakedBlobs", "value": "[variables('KeepWatermakedBlobs')]" }, + { + "name": "PUBLISHWATERKEDCOPY", + "value": "[variables('PUBLISHWATERKEDCOPY')]" + }, + { + "name": "K8SJobAggregationOnlyEmb", + "value": "[variables('K8SJobAggregationOnlyEmb')]" + }, { "name": "K8SJobAggregationOnlyEmb", "value": "[variables('K8SJobAggregationOnlyEmb')]" diff --git a/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.parameters.json b/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.parameters.json index 7e447d6..43f1cc2 100644 --- a/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.parameters.json +++ b/MB-ForensicWatermark/WaterMarking/AzureFunctionActions.parameters.json @@ -20,6 +20,9 @@ "AMSStorageConStr": { "value": "" }, + "WatermarkedStorageConn": { + "value": "" + }, "K8SURL": { "value": "" }, diff --git a/MB-ForensicWatermark/WaterMarking/UnifiedProcess.json b/MB-ForensicWatermark/WaterMarking/UnifiedProcess.json index b2203cf..d28ac48 100644 --- a/MB-ForensicWatermark/WaterMarking/UnifiedProcess.json +++ b/MB-ForensicWatermark/WaterMarking/UnifiedProcess.json @@ -13,7 +13,7 @@ }, "logicAppLocation": { "type": "string", - "defaultValue": "[resourceGroup().location]", + "defaultValue": "westeurope", "allowedValues": [ "eastasia", "southeastasia", @@ -66,10 +66,10 @@ "GetPreprocessorJobData": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','GetPreprocessorJobData','?code=',parameters('HostKeys'))]", "EvalAssetStatusURL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','EvalAssetStatus','?code=',parameters('HostKeys'))]", "UpdateWaterMarkCodeURL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','UpdateWaterMarkCode','?code=',parameters('HostKeys'))]", - "Eval_Renders_URL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','EvalEnbebedCodes','?code=',parameters('HostKeys'))]", + "Eval_Renders_URL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','EvalEmbeddedCodes','?code=',parameters('HostKeys'))]", "Create_Asset_CopiesURL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','CreateWaterMArkedAssets','?code=',parameters('HostKeys'))]", - "Evaluate_Job_StausURL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','EvalJobProgress','?code=',parameters('HostKeys'))]", - "SubmitK8S_URL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','SubmiteWaterMarkJob','?code=',parameters('HostKeys'))]", + "Evaluate_Job_StatusURL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','EvalJobProgress','?code=',parameters('HostKeys'))]", + "SubmitK8S_URL": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','SubmitWaterMarkJob','?code=',parameters('HostKeys'))]", "Error_Asset_MMRK_URI": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','UpdateJob','?code=',parameters('HostKeys'))]", "Delete_Watermarked_Renders_URI": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','DeleteWatermarkedRenders','?code=',parameters('HostKeys'))]", "DeleteSucceededPods_URI": "[concat('https://',parameters('yourapp'),'.azurewebsites.net/api/','DeleteSucceededPods','?code=',parameters('HostKeys'))]" @@ -87,12 +87,12 @@ "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { - "SetJobID": { + "SetJobId": { "type": "InitializeVariable", "inputs": { "variables": [ { - "name": "JobID", + "name": "JobId", "type": "String", "value": "@{workflow()['run']['name']}" } @@ -100,7 +100,7 @@ }, "runAfter": {} }, - "SetSwitchChec": { + "SetSwitchCheck": { "type": "InitializeVariable", "inputs": { "variables": [ @@ -112,19 +112,19 @@ ] }, "runAfter": { - "SetJobID": [ + "SetJobId": [ "Succeeded" ] } }, - "CheckJobStaus": { + "CheckJobStatus": { "type": "If", - "expression": "@equals(body('ParseJobStaus')?['JobStatus']?['State'], 'Running')", + "expression": "@equals(body('ParseJobStatus')?['JobStatus']?['State'], 'Running')", "actions": { "Resonsw200": { "type": "SetVariable", "inputs": { - "name": "ResponeCode", + "name": "ResponseCode", "value": 200 }, "runAfter": {} @@ -140,7 +140,7 @@ "Response409": { "type": "SetVariable", "inputs": { - "name": "ResponeCode", + "name": "ResponseCode", "value": 409 }, "runAfter": {} @@ -151,11 +151,11 @@ "Response": { "type": "Response", "inputs": { - "statusCode": "@variables('ResponeCode')", - "body": "@body('StatProcessCAll')" + "statusCode": "@variables('ResponseCode')", + "body": "@body('StatProcessCall')" }, "runAfter": { - "CheckJobStaus": [ + "CheckJobStatus": [ "Succeeded" ] } @@ -165,19 +165,19 @@ "inputs": { "variables": [ { - "name": "ResponeCode", + "name": "ResponseCode", "type": "Integer", "value": 200 } ] }, "runAfter": { - "SetSwitchChec": [ + "SetSwitchCheck": [ "Succeeded" ] } }, - "StatProcessCAll": { + "StatProcessCall": { "type": "Http", "inputs": { "method": "POST", @@ -186,9 +186,9 @@ "Content-Type": "application/json" }, "body": { - "AssetID": "@{triggerBody()?['AssetId']}", - "JobID": "@{variables('JobID')}", - "EmbebedCodes": "@triggerBody()?['EmbebedCodes']" + "AssetId": "@{triggerBody()?['AssetId']}", + "JobId": "@{variables('JobId')}", + "EmbeddedCodes": "@triggerBody()?['EmbeddedCodes']" }, "retryPolicy": { "type": "none" @@ -200,10 +200,10 @@ ] } }, - "ParseJobStaus": { + "ParseJobStatus": { "type": "ParseJson", "inputs": { - "content": "@body('StatProcessCAll')", + "content": "@body('StatProcessCall')", "schema": { "type": "object", "properties": { @@ -221,7 +221,7 @@ "JobStatus": { "type": "object", "properties": { - "JobID": { + "JobId": { "type": "string" }, "State": { @@ -241,21 +241,21 @@ } } }, - "EmbebedCodesList": { + "EmbeddedCodesList": { "type": "array", "items": { "type": "object", "properties": { - "EmbebedCodeValue": { + "EmbeddedCodeValue": { "type": "string" }, "State": { "type": "string" }, - "ParentAssetID": { + "ParentAssetId": { "type": "string" }, - "AssetID": { + "AssetId": { "type": "any" }, "Details": { @@ -263,10 +263,10 @@ } }, "required": [ - "EmbebedCodeValue", + "EmbeddedCodeValue", "State", - "ParentAssetID", - "AssetID", + "ParentAssetId", + "AssetId", "Details" ] } @@ -275,14 +275,14 @@ } }, "runAfter": { - "Initialize_CurrentManifest": [ + "Initialize_CurrentManifestt": [ "Succeeded" ] } }, "CheckProcessStart": { "type": "If", - "expression": "@equals(variables('ResponeCode'), 200)", + "expression": "@equals(variables('ResponseCode'), 200)", "actions": { "GetJobSubmitData": { "type": "Http", @@ -294,8 +294,8 @@ }, "body": { "AssetId": "@{triggerBody()?['AssetId']}", - "JobID": "@{variables('JobID')}", - "Codes": "@triggerBody()?['EmbebedCodes']" + "JobId": "@{variables('JobId')}", + "Codes": "@triggerBody()?['EmbeddedCodes']" }, "retryPolicy": { "type": "none" @@ -313,10 +313,10 @@ "schema": { "type": "object", "properties": { - "JobID": { + "JobId": { "type": "string" }, - "AssetID": { + "AssetId": { "type": "string" }, "PreprocessorNotificationQueue": { @@ -359,12 +359,12 @@ ] } }, - "EnbebedCodes": { + "EmbeddedCodes": { "type": "array", "items": { "type": "object", "properties": { - "EmbebedCode": { + "Code": { "type": "string" }, "MP4WatermarkedURL": { @@ -387,7 +387,7 @@ } }, "required": [ - "EmbebedCode", + "Code", "MP4WatermarkedURL" ] } @@ -429,7 +429,7 @@ "actions": { "CheckCreateNewMMRK": { "type": "If", - "expression": "@equals(body('ParseJobStaus')?['AssetStatus']?['State'], 'Running')", + "expression": "@equals(body('ParseJobStatus')?['AssetStatus']?['State'], 'Running')", "actions": { "WaitAsseReady": { "type": "Until", @@ -447,7 +447,7 @@ "headers": { "Content-Type": "application/json" }, - "body": "@variables('CurrentManifes')" + "body": "@variables('CurrentManifest')" }, "runAfter": {} }, @@ -492,7 +492,7 @@ "Update_Current_Manifest_Asset_Status": { "type": "SetVariable", "inputs": { - "name": "CurrentManifes", + "name": "CurrentManifest", "value": "@{body('Update_JOB_Staus_bseon_Asset_Status')}" }, "runAfter": { @@ -505,7 +505,7 @@ "type": "Http", "inputs": { "method": "POST", - "uri": "[variables('Evaluate_Job_StausURL')]", + "uri": "[variables('Evaluate_Job_StatusURL')]", "headers": { "Content-Type": "application/json" }, @@ -545,8 +545,8 @@ "Content-Type": "application/json" }, "body": { - "JobID": "@{variables('JobID')}", - "AssetID": "@{body('K8SJobData')?['AssetID']}", + "JobId": "@{variables('JobId')}", + "AssetId": "@{body('K8SJobData')?['AssetId']}", "FileName": "@{items('CreateAssetMMRKEntry')?['FileName']}", "State": "Running", "Details": "Just sumbited", @@ -562,9 +562,9 @@ ] } }, - "Create_Embededd_Codes": { + "Create_Embeddedd_Codes": { "type": "Foreach", - "foreach": "@body('K8SJobData')?['EnbebedCodes']", + "foreach": "@body('K8SJobData')?['EmbeddedCodes']", "actions": { "Create_Watermark_Code": { "type": "Http", @@ -575,8 +575,8 @@ "Content-Type": "application/json" }, "body": { - "ParentAssetID": "@{triggerBody()?['AssetId']}", - "EnbebedCode": "@items('Create_Embededd_Codes')" + "ParentAssetId": "@{triggerBody()?['AssetId']}", + "EmbeddedCode": "@items('Create_Embeddedd_Codes')" }, "retryPolicy": { "type": "none" @@ -597,7 +597,7 @@ "actions": { "Create_Embedded_Code_on_MMRK_finished": { "type": "Foreach", - "foreach": "@body('K8SJobData')?['EnbebedCodes']", + "foreach": "@body('K8SJobData')?['EmbeddedCodes']", "actions": { "Create_Embedded_Registers": { "type": "Http", @@ -608,8 +608,8 @@ "Content-Type": "application/json" }, "body": { - "ParentAssetID": "@{triggerBody()?['AssetId']}", - "EnbebedCode": "@items('Create_Embedded_Code_on_MMRK_finished')" + "ParentAssetId": "@{triggerBody()?['AssetId']}", + "EmbeddedCode": "@items('Create_Embedded_Code_on_MMRK_finished')" } }, "runAfter": {} @@ -639,9 +639,9 @@ "Manifest": "@body('EvalAssetStatus')", "AssetStatus": "Error", "JobState": "Error", - "JobStateDetails": "Fail creating MMKR files", + "JobStateDetails": "MMKR files creation failed", "WaterMarkCopiesStatus": "Aborted", - "WaterMarkCopiesStatusDetails": "Watermark copies aborted becouse MMRK fialed" + "WaterMarkCopiesStatusDetails": "Watermark copies aborted because MMRK failed" }, "retryPolicy": { "type": "none" @@ -670,7 +670,7 @@ "headers": { "Content-Type": "application/json" }, - "body": "@variables('CurrentManifes')", + "body": "@variables('CurrentManifest')", "retryPolicy": { "type": "none" } @@ -696,11 +696,11 @@ ] } }, - "Evaluate_Job_Staus": { + "Evaluate_Job_Status": { "type": "Http", "inputs": { "method": "POST", - "uri": "[variables('Evaluate_Job_StausURL')]", + "uri": "[variables('Evaluate_Job_StatusURL')]", "headers": { "Content-Type": "application/json" }, @@ -718,11 +718,11 @@ "Update_Manifest": { "type": "SetVariable", "inputs": { - "name": "CurrentManifes", - "value": "@{body('Evaluate_Job_Staus')}" + "name": "CurrentManifest", + "value": "@{body('Evaluate_Job_Status')}" }, "runAfter": { - "Evaluate_Job_Staus": [ + "Evaluate_Job_Status": [ "Succeeded" ] } @@ -731,7 +731,7 @@ "type": "SetVariable", "inputs": { "name": "switchCheck", - "value": "@equals(body('Evaluate_Job_Staus')?['JobStatus']?['State'], 'Running')" + "value": "@equals(body('Evaluate_Job_Status')?['JobStatus']?['State'], 'Running')" }, "runAfter": { "Update_Manifest": [ @@ -739,7 +739,7 @@ ] } }, - "Delay_for_Check_Job_Staus": { + "Delay_for_Check_Job_Status": { "type": "Wait", "inputs": { "interval": { @@ -755,12 +755,12 @@ } }, "runAfter": { - "Set_Switch_Waait_For_Renders": [ + "Set_Switch_Wait_For_Renders": [ "Succeeded" ] } }, - "Set_Switch_Waait_For_Renders": { + "Set_Switch_Wait_For_Renders": { "type": "SetVariable", "inputs": { "name": "switchCheck", @@ -777,7 +777,7 @@ "Content-Type": "application/json" }, "body": { - "AssetId": "@{body('ParseJobStaus')?['AssetStatus']?['AssetId']}" + "AssetId": "@{body('ParseJobStatus')?['AssetStatus']?['AssetId']}" }, "retryPolicy": { "type": "none" @@ -798,7 +798,7 @@ "Content-Type": "application/json" }, "body": { - "JobId": "@{variables('JobID')}" + "JobId": "@{variables('JobId')}" }, "retryPolicy": { "type": "none" @@ -835,12 +835,12 @@ "Content-Type": "application/json" }, "body": { - "Manifest": "@body('StatProcessCAll')", + "Manifest": "@body('StatProcessCall')", "AssetStatus": "Error", "JobState": "Error", - "JobStateDetails": "Error Submite K8S JOB", + "JobStateDetails": "Error Submit K8S JOB", "WaterMarkCopiesStatus": "Aborted", - "WaterMarkCopiesStatusDetails": "Error submite JOB K8S" + "WaterMarkCopiesStatusDetails": "Error Submit JOB K8S" }, "retryPolicy": { "type": "none" @@ -863,7 +863,7 @@ "Content-Type": "application/json" }, "body": { - "Manifest": "@body('StatProcessCAll')", + "Manifest": "@body('StatProcessCall')", "AssetStatus": "Error", "JobState": "Error", "JobStateDetails": "Error on Get Sumit Job Data", @@ -892,7 +892,7 @@ "Content-Type": "application/json" }, "body": { - "Manifest": "@body('StatProcessCAll')", + "Manifest": "@body('StatProcessCall')", "AssetStatus": "Error", "JobState": "Error", "JobStateDetails": "K8S submit error :@{body('SubmitK8S')}", @@ -923,29 +923,29 @@ { "name": "AssetStatusState", "type": "String", - "value": "@body('ParseJobStaus')?['AssetStatus']?['State']" + "value": "@body('ParseJobStatus')?['AssetStatus']?['State']" } ] }, "runAfter": { - "ParseJobStaus": [ + "ParseJobStatus": [ "Succeeded" ] } }, - "Initialize_CurrentManifest": { + "Initialize_CurrentManifestt": { "type": "InitializeVariable", "inputs": { "variables": [ { - "name": "CurrentManifes", + "name": "CurrentManifest", "type": "String", - "value": "@{body('StatProcessCAll')}" + "value": "@{body('StatProcessCall')}" } ] }, "runAfter": { - "StatProcessCAll": [ + "StatProcessCall": [ "Succeeded" ] } @@ -963,7 +963,7 @@ "AssetId": { "type": "string" }, - "EmbebedCodes": { + "EmbeddedCodes": { "type": "array", "items": { "type": "string" diff --git a/MB-ForensicWatermark/WaterMarkingActions/WaterMArkActions.cs b/MB-ForensicWatermark/WaterMarkingActions/WaterMArkActions.cs index 48d22b2..2c7de54 100644 --- a/MB-ForensicWatermark/WaterMarkingActions/WaterMArkActions.cs +++ b/MB-ForensicWatermark/WaterMarkingActions/WaterMArkActions.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. + using ActionsProvider; using ActionsProvider.AMS; using ActionsProvider.Entities; @@ -20,54 +21,87 @@ namespace WaterMarkingActions { - public static class WaterMArkActions + public static class WaterMarkActions { + /// + /// Check the status of an asset + /// + /// + /// + /// + [FunctionName("CheckAssetStatus")] + public static async Task CheckAssetStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + string AssetId = BodyData.AssetId; + //Save Status + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + var status = myActions.GetAssetStatus(AssetId); + if (status == null) + { + return req.CreateResponse(HttpStatusCode.NotFound, $"Asset with id '{AssetId}' was not watermarked yet.", JsonMediaTypeFormatter.DefaultMediaType); + } + return req.CreateResponse(HttpStatusCode.OK, status, JsonMediaTypeFormatter.DefaultMediaType); + } [FunctionName("StartNewJob")] public static async Task StartNewJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { - dynamic BodyData = await req.Content.ReadAsAsync(); - string AssetID = BodyData.AssetID; - string JobID = BodyData.JobID; - string[] EmbebedCodes = BodyData.EmbebedCodes.ToObject(); + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + string AssetId = BodyData.AssetId; + string JobId = BodyData.JobId; + string[] EmbeddedCodes = BodyData.EmbeddedCodes; + if (string.IsNullOrWhiteSpace(JobId) || + string.IsNullOrWhiteSpace(AssetId) || + (EmbeddedCodes == null || EmbeddedCodes.Length == 0)) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } //Save Status IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); - var status = myActions.StartNewProcess(AssetID, JobID, EmbebedCodes); + var status = myActions.StartNewProcess(AssetId, JobId, EmbeddedCodes); return req.CreateResponse(HttpStatusCode.OK, status, JsonMediaTypeFormatter.DefaultMediaType); } [FunctionName("GetPreprocessorJobData")] public static async Task GetJobManifest([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { - dynamic BodyData = await req.Content.ReadAsAsync(); + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); string AssetId = BodyData.AssetId; - string JobID = BodyData.JobID; - List codes = BodyData.Codes.ToObject>(); + string JobId = BodyData.JobId; + List codes = BodyData.EmbeddedCodes; IAMSProvider myAMS = AMSProviderFactory.CreateAMSProvider(); try { - ManifestInfo jobdata = await myAMS.GetK8SJobManifestAsync(AssetId, JobID, codes); + ManifestInfo jobdata = await myAMS.GetK8SJobManifestAsync(AssetId, JobId, codes); return req.CreateResponse(HttpStatusCode.OK, jobdata, JsonMediaTypeFormatter.DefaultMediaType); } catch (Exception X) { - return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); + return req.CreateResponse(HttpStatusCode.InternalServerError, X.Message, JsonMediaTypeFormatter.DefaultMediaType); } } [FunctionName("UpdateMMRKStatus")] public static async Task UpdateMMRKStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { - dynamic BodyData = await req.Content.ReadAsAsync(); - //Create JobStatus from body data - MMRKStatus MMRK = BodyData.ToObject(); + string content = await req.Content.ReadAsStringAsync(); + //Create JobStatus from body data + MMRKStatus MMRK = content.GetBodyData(); + if (MMRK == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, MMRK, JsonMediaTypeFormatter.DefaultMediaType); + } //Save Status IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); if (MMRK.FileURL == "{NO UPDATE}") { - string jobRender = $"[{MMRK.JobID}]{MMRK.FileName}"; - var currentMMRKStatus = myActions.GetMMRKStatus(MMRK.AssetID, jobRender); + string jobRender = $"[{MMRK.JobId}]{MMRK.FileName}"; + var currentMMRKStatus = myActions.GetMMRKStatus(MMRK.AssetId, jobRender); string url = currentMMRKStatus.FileURL; MMRK.FileURL = url; } @@ -78,8 +112,12 @@ public static async Task UpdateMMRKStatus([HttpTrigger(Auth [FunctionName("EvalAssetStatus")] public static async Task EvalAssetStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { - dynamic BodyData = await req.Content.ReadAsAsync(); - UnifiedProcessStatus manifest = BodyData.ToObject(); + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus manifest = content.GetBodyData(); + if (manifest == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); //1. Update EvalPreprocessorNotifications @@ -90,7 +128,7 @@ public static async Task EvalAssetStatus([HttpTrigger(Autho //3. Update Manifest/ all process myActions.UpdateUnifiedProcessStatus(manifest); //4. Log and replay - log.Info($"Updated Actions AssetId {manifest.AssetStatus.AssetId} staus {manifest.AssetStatus.ToString()}"); + log.Info($"Updated Actions AssetId {manifest.AssetStatus.AssetId} status {manifest.AssetStatus.ToString()}"); return req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType); } @@ -98,103 +136,116 @@ public static async Task EvalAssetStatus([HttpTrigger(Autho public static async Task UpdateWaterMarkCode([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); - dynamic BodyData = await req.Content.ReadAsAsync(); - EnbebedCode myCode = BodyData.EnbebedCode.ToObject(); - string ParentAssetID = BodyData.ParentAssetID; + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } + EmbeddedCode myCode = BodyData.EmbeddedCode; + string ParentAssetId = BodyData.ParentAssetId; foreach (var info in myCode.MP4WatermarkedURL) { WaterMarkedRender data = new WaterMarkedRender() { - Details = "Submited", - EmbebedCodeValue = myCode.EmbebedCode, + Details = "Submitted", + EmbeddedCodeValue = myCode.Code, MP4URL = info.WaterMarkedMp4, RenderName = info.FileName, - ParentAssetID = ParentAssetID, + ParentAssetId = ParentAssetId, State = ExecutionStatus.Running }; myActions.UpdateWaterMarkedRender(data); - var outputData = myActions.UpdateWaterMarkedRender(data); + // var outputData = myActions.UpdateWaterMarkedRender(data); } return req.CreateResponse(HttpStatusCode.OK, new { Status = ExecutionStatus.Finished.ToString() }, JsonMediaTypeFormatter.DefaultMediaType); } - [FunctionName("EvalEnbebedCodes")] - public static async Task EvalEnbebedCodes([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + [FunctionName("EvalEmbeddedCodes")] + public static async Task EvalEmbeddedCodes([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); - dynamic BodyData = await req.Content.ReadAsAsync(); - UnifiedProcessStatus manifest = BodyData.ToObject(); - string ParentAssetID = manifest.AssetStatus.AssetId; + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus manifest = content.GetBodyData(); + if (manifest == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + string ParentAssetId = manifest.AssetStatus.AssetId; //1. Process Embbeded Notifications int nNotification = await myActions.EvalPEmbeddedNotifications(); log.Info($"Embedded Notifications processed {nNotification}"); //2. Eval Each Watermark Render status List UpdatedInfo = new List(); - foreach (var item in manifest.EmbebedCodesList) + foreach (var item in manifest.EmbeddedCodesList) { - UpdatedInfo.Add(myActions.EvalWaterMarkedAssetInfo(ParentAssetID, item.EmbebedCodeValue)); + UpdatedInfo.Add(myActions.EvalWaterMarkedAssetInfo(ParentAssetId, item.EmbeddedCodeValue)); } //Replace New WaterMarkAssetInfo - manifest.EmbebedCodesList = UpdatedInfo; + manifest.EmbeddedCodesList = UpdatedInfo; // myActions.UpdateUnifiedProcessStatus(manifest); return req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType); } - [FunctionName("CreateWaterMArkedAssets")] - public static async Task CreateWaterMArkedAssets([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + [FunctionName("CreateWaterMarkedAssets")] + public static async Task CreateWaterMarkedAssets([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); - dynamic BodyData = await req.Content.ReadAsAsync(); - UnifiedProcessStatus manifest = BodyData.ToObject(); - string ParentAssetID = manifest.AssetStatus.AssetId; + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus manifest = content.GetBodyData(); + if (manifest == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + string ParentAssetId = manifest.AssetStatus.AssetId; List UpdatedInfo = new List(); try { - - //List only Finished without AsstID - foreach (var watermarkedInfo in manifest.EmbebedCodesList) - { - if ((watermarkedInfo.State == ExecutionStatus.Finished) && (string.IsNullOrEmpty(watermarkedInfo.AssetID))) - { - //Create new asset per embbeded code - IAMSProvider help = AMSProviderFactory.CreateAMSProvider(); - var xx = await help.CreateEmptyWatermarkedAsset(manifest.JobStatus.JobID, ParentAssetID, watermarkedInfo.EmbebedCodeValue); - watermarkedInfo.AssetID = xx.WMAssetId; - ////Inject all Renders on New asset - foreach (var render in myActions.GetWaterMarkedRenders(ParentAssetID, watermarkedInfo.EmbebedCodeValue)) + //List only Finished without AssetId + foreach (var watermarkedInfo in manifest.EmbeddedCodesList) + { + if ((watermarkedInfo.State == ExecutionStatus.Finished) && (string.IsNullOrEmpty(watermarkedInfo.AssetId))) { - string url = render.MP4URL; - var r = await help.AddWatermarkedMediaFiletoAsset(watermarkedInfo.AssetID, watermarkedInfo.EmbebedCodeValue, url); - if (r.Status != "MMRK File Added") + //Create new asset per embbeded code + IAMSProvider help = AMSProviderFactory.CreateAMSProvider(); + var xx = await help.CreateEmptyWatermarkedAsset(manifest.JobStatus.JobId, ParentAssetId, watermarkedInfo.EmbeddedCodeValue); + + watermarkedInfo.AssetId = xx.WMAssetId; + ////Inject all Renders on New asset + foreach (var render in myActions.GetWaterMarkedRenders(ParentAssetId, watermarkedInfo.EmbeddedCodeValue)) { - //Error - watermarkedInfo.State = ExecutionStatus.Error; - watermarkedInfo.Details = $"Error adding {render.RenderName} deatils: {r.StatusMessage}"; - //Delete Asset - help.DeleteAsset(watermarkedInfo.AssetID); - watermarkedInfo.AssetID = ""; - //Abort - break; + string url = render.MP4URL; + var r = await help.AddWatermarkedMediaFiletoAsset(watermarkedInfo.AssetId, watermarkedInfo.EmbeddedCodeValue, url); + if (r.Status != "MMRK File Added") + { + //Error + watermarkedInfo.State = ExecutionStatus.Error; + watermarkedInfo.Details = $"Error adding {render.RenderName} details: {r.StatusMessage}"; + //Delete Asset + help.DeleteAsset(watermarkedInfo.AssetId); + watermarkedInfo.AssetId = ""; + //Abort + break; + } } + //Create New Manifest and set it as primary file. + await help.GenerateManifest(watermarkedInfo.AssetId); } - //Create New Manifest and set it as primary file. - await help.GenerateManifest(watermarkedInfo.AssetID); + UpdatedInfo.Add(watermarkedInfo); } - UpdatedInfo.Add(watermarkedInfo); - } - //Replace New WaterMarkAssetInfo - manifest.EmbebedCodesList = UpdatedInfo; + //Replace New WaterMarkAssetInfo + manifest.EmbeddedCodesList = UpdatedInfo; - myActions.UpdateUnifiedProcessStatus(manifest); + myActions.UpdateUnifiedProcessStatus(manifest); } catch (Exception X) { @@ -208,8 +259,13 @@ public static async Task CreateWaterMArkedAssets([HttpTrigg public static async Task EvalJobProgress([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { - dynamic BodyData = await req.Content.ReadAsAsync(); - UnifiedProcessStatus myProcessStatus = BodyData.ToObject(); + + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus myProcessStatus = content.GetBodyData(); + if (myProcessStatus == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType); + } IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); //Check AssetStatus @@ -234,13 +290,13 @@ public static async Task EvalJobProgress([HttpTrigger(Autho myProcessStatus.JobStatus.Details = $"Generating MMRK files {mmrkFinished} of {mmrkTotal}, last update {DateTime.Now.ToString()}"; - //var jobinfo = myActions.GetJobK8SDetail(myProcessStatus.JobStatus.JobID + "-1"); + //var jobinfo = myActions.GetJobK8SDetail(myProcessStatus.JobStatus.JobId + "-1"); //myProcessStatus.JobStatus.Details += Newtonsoft.Json.JsonConvert.SerializeObject(jobinfo, Newtonsoft.Json.Formatting.Indented); break; case ExecutionStatus.Finished: - //Check EmbebedCodeList - int nRunning = myProcessStatus.EmbebedCodesList.Where(emc => emc.State == ExecutionStatus.Running).Count(); + //Check EmbeddedCodeList + int nRunning = myProcessStatus.EmbeddedCodesList.Where(emc => emc.State == ExecutionStatus.Running).Count(); log.Info($"Current EMC Running {nRunning}"); if (nRunning == 0) { @@ -251,9 +307,9 @@ public static async Task EvalJobProgress([HttpTrigger(Autho } else { - int total = myProcessStatus.EmbebedCodesList.Count(); + int total = myProcessStatus.EmbeddedCodesList.Count(); myProcessStatus.JobStatus.State = ExecutionStatus.Running; - myProcessStatus.JobStatus.Details = $"Watermaerked copies {(total - nRunning)} of {total}"; + myProcessStatus.JobStatus.Details = $"Watermarked copies {(total - nRunning)} of {total}"; } myActions.UpdateUnifiedProcessStatus(myProcessStatus); @@ -266,14 +322,19 @@ public static async Task EvalJobProgress([HttpTrigger(Autho [FunctionName("GetUnifiedProcessStatus")] public static async Task GetUnifiedProcessStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) { - dynamic BodyData = await req.Content.ReadAsAsync(); + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); string AssetId = BodyData.AssetId; - string JobID = BodyData.JobID; - + string JobId = BodyData.JobId; + try { - var myProcessStatus = myActions.GetUnifiedProcessStatus(AssetId, JobID); + var myProcessStatus = myActions.GetUnifiedProcessStatus(AssetId, JobId); return req.CreateResponse(HttpStatusCode.OK, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType); } catch (Exception X) @@ -282,12 +343,13 @@ public static async Task GetUnifiedProcessStatus([HttpTrigg return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); } } - [FunctionName("SubmiteWaterMarkJob")] - public static async Task SubmiteWaterMarkJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) + [FunctionName("SubmitWaterMarkJob")] + public static async Task SubmitWaterMarkJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) { IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); - dynamic BodyData = await req.Content.ReadAsAsync(); - ManifestInfo manifest = BodyData.ToObject(); + string content = await req.Content.ReadAsStringAsync(); + ManifestInfo manifest = content.GetBodyData(); + int K8SJobAggregation = int.Parse(System.Configuration.ConfigurationManager.AppSettings["K8SJobAggregation"]); int K8SJobAggregationOnlyEmb = int.Parse(System.Configuration.ConfigurationManager.AppSettings["K8SJobAggregationOnlyEmb"] ?? "1"); try @@ -298,7 +360,7 @@ public static async Task SubmiteWaterMarkJob([HttpTrigger(A int jobSubId = 1; foreach (var job in jobList) { - var ret = await myActions.SubmiteJobK8S(job, jobSubId); + var ret = await myActions.SubmitJobK8S(job, jobSubId); log.Info($"{job.VideoInformation.FirstOrDefault().FileName} CODE {ret.Code.ToString()}"); jobSubId += 1; if (!ret.IsSuccessStatusCode) @@ -312,24 +374,29 @@ public static async Task SubmiteWaterMarkJob([HttpTrigger(A catch (Exception X) { - return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); + return req.CreateResponse(HttpStatusCode.InternalServerError, X.Message, JsonMediaTypeFormatter.DefaultMediaType); } } [FunctionName("UpdateJob")] public static async Task UpdateJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) { - dynamic BodyData = await req.Content.ReadAsAsync(); - IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); - UnifiedProcessStatus Manifest = BodyData.Manifest.ToObject(); + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); - ExecutionStatus AssetStatus = BodyData.AssetStatus.ToObject(); + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } - ExecutionStatus JobState = BodyData.JobState.ToObject(); + ExecutionStatus AssetStatus = BodyData.AssetStatus; + UnifiedProcessStatus Manifest = BodyData.Manifest; + ExecutionStatus JobState = BodyData.JobState; string JobStateDetails = BodyData.JobStateDetails; - ExecutionStatus WaterMarkCopiesStatus = BodyData.WaterMarkCopiesStatus.ToObject(); + ExecutionStatus WaterMarkCopiesStatus = BodyData.WaterMarkCopiesStatus; string WaterMarkCopiesStatusDetails = BodyData.WaterMarkCopiesStatusDetails; switch (Manifest.AssetStatus.State) { @@ -355,7 +422,12 @@ public static async Task UpdateJob([HttpTrigger(Authorizati [FunctionName("DeleteWatermarkedRenders")] public static async Task DeleteWatermarkedRenders([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) { - dynamic BodyData = await req.Content.ReadAsAsync(); + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } IAMSProvider myAMShelp = AMSProviderFactory.CreateAMSProvider(); string AssetId = BodyData.AssetId; @@ -377,20 +449,24 @@ public static async Task DeleteWatermarkedRenders([HttpTrig return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); } - - + + } [FunctionName("DeleteSucceededPods")] public static async Task DeleteSucceededPods([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) { - dynamic BodyData = await req.Content.ReadAsAsync(); - string JobId = BodyData.JobId; + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } IK8SClient k = K8SClientFactory.Create(); - string prefixName = $"allinone-job-{JobId}"; + string prefixName = $"allinone-job-{BodyData.JobId}"; try { var r = await k.DeletePods(prefixName, "Succeeded"); @@ -406,7 +482,7 @@ public static async Task DeleteSucceededPods([HttpTrigger(A [FunctionName("GetK8SProcessLog")] public static async Task GetK8SProcessLog([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) { - string JobId = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "JobId", true) == 0).Value; + string JobId = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "JobId", true) == 0).Value; if (string.IsNullOrEmpty(JobId)) { return req.CreateResponse(HttpStatusCode.InternalServerError, new { Error = "Parameter JobId is null" }, JsonMediaTypeFormatter.DefaultMediaType); @@ -417,7 +493,7 @@ public static async Task GetK8SProcessLog([HttpTrigger(Auth { string jobName = $"allinone-job-{JobId}"; var ResultList = await K8S.GetK8SJobLog(jobName); - + if (ResultList.Count == 0) { //Not Found @@ -434,7 +510,7 @@ public static async Task GetK8SProcessLog([HttpTrigger(Auth log.Error(X.Message); return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); } - + } } diff --git a/MB-ForensicWatermark/WaterMarkingActions/WaterMarkActions.cs b/MB-ForensicWatermark/WaterMarkingActions/WaterMarkActions.cs new file mode 100644 index 0000000..2c7de54 --- /dev/null +++ b/MB-ForensicWatermark/WaterMarkingActions/WaterMarkActions.cs @@ -0,0 +1,517 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + + +using ActionsProvider; +using ActionsProvider.AMS; +using ActionsProvider.Entities; +using ActionsProvider.K8S; +using ActionsProvider.UnifiedResponse; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.Azure.WebJobs.Host; +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Formatting; +using System.Threading.Tasks; + +namespace WaterMarkingActions +{ + public static class WaterMarkActions + { + /// + /// Check the status of an asset + /// + /// + /// + /// + [FunctionName("CheckAssetStatus")] + public static async Task CheckAssetStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + string AssetId = BodyData.AssetId; + //Save Status + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + var status = myActions.GetAssetStatus(AssetId); + if (status == null) + { + return req.CreateResponse(HttpStatusCode.NotFound, $"Asset with id '{AssetId}' was not watermarked yet.", JsonMediaTypeFormatter.DefaultMediaType); + } + return req.CreateResponse(HttpStatusCode.OK, status, JsonMediaTypeFormatter.DefaultMediaType); + } + [FunctionName("StartNewJob")] + public static async Task StartNewJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + string AssetId = BodyData.AssetId; + string JobId = BodyData.JobId; + string[] EmbeddedCodes = BodyData.EmbeddedCodes; + if (string.IsNullOrWhiteSpace(JobId) || + string.IsNullOrWhiteSpace(AssetId) || + (EmbeddedCodes == null || EmbeddedCodes.Length == 0)) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } + //Save Status + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + var status = myActions.StartNewProcess(AssetId, JobId, EmbeddedCodes); + return req.CreateResponse(HttpStatusCode.OK, status, JsonMediaTypeFormatter.DefaultMediaType); + } + + [FunctionName("GetPreprocessorJobData")] + public static async Task GetJobManifest([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + string AssetId = BodyData.AssetId; + string JobId = BodyData.JobId; + List codes = BodyData.EmbeddedCodes; + IAMSProvider myAMS = AMSProviderFactory.CreateAMSProvider(); + try + { + ManifestInfo jobdata = await myAMS.GetK8SJobManifestAsync(AssetId, JobId, codes); + return req.CreateResponse(HttpStatusCode.OK, jobdata, JsonMediaTypeFormatter.DefaultMediaType); + } + catch (Exception X) + { + + return req.CreateResponse(HttpStatusCode.InternalServerError, X.Message, JsonMediaTypeFormatter.DefaultMediaType); + } + } + + [FunctionName("UpdateMMRKStatus")] + public static async Task UpdateMMRKStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + string content = await req.Content.ReadAsStringAsync(); + + //Create JobStatus from body data + MMRKStatus MMRK = content.GetBodyData(); + if (MMRK == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, MMRK, JsonMediaTypeFormatter.DefaultMediaType); + } + //Save Status + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + if (MMRK.FileURL == "{NO UPDATE}") + { + string jobRender = $"[{MMRK.JobId}]{MMRK.FileName}"; + var currentMMRKStatus = myActions.GetMMRKStatus(MMRK.AssetId, jobRender); + string url = currentMMRKStatus.FileURL; + MMRK.FileURL = url; + } + myActions.UpdateMMRKStatus(MMRK); + return req.CreateResponse(HttpStatusCode.OK, MMRK, JsonMediaTypeFormatter.DefaultMediaType); + } + + [FunctionName("EvalAssetStatus")] + public static async Task EvalAssetStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus manifest = content.GetBodyData(); + if (manifest == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + //1. Update EvalPreprocessorNotifications + int nNotification = await myActions.EvalPreprocessorNotifications(); + log.Info($"Preprocessor Notifications processed {nNotification}"); + //2. Eval Asset Status + manifest.AssetStatus = myActions.EvalAssetStatus(manifest.AssetStatus.AssetId); + //3. Update Manifest/ all process + myActions.UpdateUnifiedProcessStatus(manifest); + //4. Log and replay + log.Info($"Updated Actions AssetId {manifest.AssetStatus.AssetId} status {manifest.AssetStatus.ToString()}"); + return req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + + [FunctionName("UpdateWaterMarkCode")] + public static async Task UpdateWaterMarkCode([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } + EmbeddedCode myCode = BodyData.EmbeddedCode; + string ParentAssetId = BodyData.ParentAssetId; + + foreach (var info in myCode.MP4WatermarkedURL) + { + WaterMarkedRender data = new WaterMarkedRender() + { + Details = "Submitted", + EmbeddedCodeValue = myCode.Code, + MP4URL = info.WaterMarkedMp4, + RenderName = info.FileName, + ParentAssetId = ParentAssetId, + State = ExecutionStatus.Running + + }; + myActions.UpdateWaterMarkedRender(data); + // var outputData = myActions.UpdateWaterMarkedRender(data); + } + return req.CreateResponse(HttpStatusCode.OK, new { Status = ExecutionStatus.Finished.ToString() }, JsonMediaTypeFormatter.DefaultMediaType); + } + [FunctionName("EvalEmbeddedCodes")] + public static async Task EvalEmbeddedCodes([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus manifest = content.GetBodyData(); + if (manifest == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + string ParentAssetId = manifest.AssetStatus.AssetId; + //1. Process Embbeded Notifications + int nNotification = await myActions.EvalPEmbeddedNotifications(); + log.Info($"Embedded Notifications processed {nNotification}"); + //2. Eval Each Watermark Render status + List UpdatedInfo = new List(); + foreach (var item in manifest.EmbeddedCodesList) + { + + UpdatedInfo.Add(myActions.EvalWaterMarkedAssetInfo(ParentAssetId, item.EmbeddedCodeValue)); + + } + //Replace New WaterMarkAssetInfo + manifest.EmbeddedCodesList = UpdatedInfo; + // + myActions.UpdateUnifiedProcessStatus(manifest); + + return req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + [FunctionName("CreateWaterMarkedAssets")] + public static async Task CreateWaterMarkedAssets([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus manifest = content.GetBodyData(); + if (manifest == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + string ParentAssetId = manifest.AssetStatus.AssetId; + + List UpdatedInfo = new List(); + + try + { + + + //List only Finished without AssetId + foreach (var watermarkedInfo in manifest.EmbeddedCodesList) + { + if ((watermarkedInfo.State == ExecutionStatus.Finished) && (string.IsNullOrEmpty(watermarkedInfo.AssetId))) + { + //Create new asset per embbeded code + IAMSProvider help = AMSProviderFactory.CreateAMSProvider(); + var xx = await help.CreateEmptyWatermarkedAsset(manifest.JobStatus.JobId, ParentAssetId, watermarkedInfo.EmbeddedCodeValue); + + watermarkedInfo.AssetId = xx.WMAssetId; + ////Inject all Renders on New asset + foreach (var render in myActions.GetWaterMarkedRenders(ParentAssetId, watermarkedInfo.EmbeddedCodeValue)) + { + string url = render.MP4URL; + var r = await help.AddWatermarkedMediaFiletoAsset(watermarkedInfo.AssetId, watermarkedInfo.EmbeddedCodeValue, url); + if (r.Status != "MMRK File Added") + { + //Error + watermarkedInfo.State = ExecutionStatus.Error; + watermarkedInfo.Details = $"Error adding {render.RenderName} details: {r.StatusMessage}"; + //Delete Asset + help.DeleteAsset(watermarkedInfo.AssetId); + watermarkedInfo.AssetId = ""; + //Abort + break; + } + } + //Create New Manifest and set it as primary file. + await help.GenerateManifest(watermarkedInfo.AssetId); + } + UpdatedInfo.Add(watermarkedInfo); + } + //Replace New WaterMarkAssetInfo + manifest.EmbeddedCodesList = UpdatedInfo; + + myActions.UpdateUnifiedProcessStatus(manifest); + } + catch (Exception X) + { + + return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); + } + return req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + + [FunctionName("EvalJobProgress")] + public static async Task EvalJobProgress([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + + + string content = await req.Content.ReadAsStringAsync(); + UnifiedProcessStatus myProcessStatus = content.GetBodyData(); + if (myProcessStatus == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType); + } + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + //Check AssetStatus + + switch (myProcessStatus.AssetStatus.State) + { + case ExecutionStatus.Error: + //Finished with error + myProcessStatus.JobStatus.State = ExecutionStatus.Error; + myProcessStatus.JobStatus.FinishTime = DateTime.Now; + myProcessStatus.JobStatus.Duration = DateTime.Now.Subtract(myProcessStatus.JobStatus.StartTime); + myActions.UpdateUnifiedProcessStatus(myProcessStatus); + break; + case ExecutionStatus.Running: + //Same status for JOB + //No Action + myProcessStatus.JobStatus.State = ExecutionStatus.Running; + + var mmrklist = myActions.GetMMRKStatusList(myProcessStatus.AssetStatus.AssetId); + + int mmrkTotal = mmrklist.Count(); + int mmrkFinished = mmrklist.Where(m => m.State == ExecutionStatus.Finished).Count(); + + myProcessStatus.JobStatus.Details = $"Generating MMRK files {mmrkFinished} of {mmrkTotal}, last update {DateTime.Now.ToString()}"; + + //var jobinfo = myActions.GetJobK8SDetail(myProcessStatus.JobStatus.JobId + "-1"); + //myProcessStatus.JobStatus.Details += Newtonsoft.Json.JsonConvert.SerializeObject(jobinfo, Newtonsoft.Json.Formatting.Indented); + + break; + case ExecutionStatus.Finished: + //Check EmbeddedCodeList + int nRunning = myProcessStatus.EmbeddedCodesList.Where(emc => emc.State == ExecutionStatus.Running).Count(); + log.Info($"Current EMC Running {nRunning}"); + if (nRunning == 0) + { + myProcessStatus.JobStatus.State = ExecutionStatus.Finished; + myProcessStatus.JobStatus.FinishTime = DateTime.Now; + myProcessStatus.JobStatus.Duration = DateTime.Now.Subtract(myProcessStatus.JobStatus.StartTime); + myProcessStatus.JobStatus.Details = "Finished"; + } + else + { + int total = myProcessStatus.EmbeddedCodesList.Count(); + myProcessStatus.JobStatus.State = ExecutionStatus.Running; + myProcessStatus.JobStatus.Details = $"Watermarked copies {(total - nRunning)} of {total}"; + + } + myActions.UpdateUnifiedProcessStatus(myProcessStatus); + log.Info($"Updated Manifest JOB Status {myProcessStatus.JobStatus.State.ToString()}"); + break; + } + + return req.CreateResponse(HttpStatusCode.OK, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType); + } + [FunctionName("GetUnifiedProcessStatus")] + public static async Task GetUnifiedProcessStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log) + { + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + string AssetId = BodyData.AssetId; + string JobId = BodyData.JobId; + + try + { + var myProcessStatus = myActions.GetUnifiedProcessStatus(AssetId, JobId); + return req.CreateResponse(HttpStatusCode.OK, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType); + } + catch (Exception X) + { + log.Error(X.Message); + return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); + } + } + [FunctionName("SubmitWaterMarkJob")] + public static async Task SubmitWaterMarkJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) + { + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + string content = await req.Content.ReadAsStringAsync(); + ManifestInfo manifest = content.GetBodyData(); + + int K8SJobAggregation = int.Parse(System.Configuration.ConfigurationManager.AppSettings["K8SJobAggregation"]); + int K8SJobAggregationOnlyEmb = int.Parse(System.Configuration.ConfigurationManager.AppSettings["K8SJobAggregationOnlyEmb"] ?? "1"); + try + { + //Get JOBList to Send to K8S cluster + List jobList = myActions.GetK8SManifestInfo(K8SJobAggregation, K8SJobAggregationOnlyEmb, manifest); + //Sumbite to K8S cluster + int jobSubId = 1; + foreach (var job in jobList) + { + var ret = await myActions.SubmitJobK8S(job, jobSubId); + log.Info($"{job.VideoInformation.FirstOrDefault().FileName} CODE {ret.Code.ToString()}"); + jobSubId += 1; + if (!ret.IsSuccessStatusCode) + { + log.Error($"K8S Summition Error {ret.Code.ToString()} {ret.Content}"); + throw new Exception($"K8S Summition Error {ret.Code.ToString()} {ret.Content}"); + } + } + return req.CreateResponse(HttpStatusCode.OK, jobList, JsonMediaTypeFormatter.DefaultMediaType); + } + catch (Exception X) + { + + return req.CreateResponse(HttpStatusCode.InternalServerError, X.Message, JsonMediaTypeFormatter.DefaultMediaType); + } + + } + [FunctionName("UpdateJob")] + public static async Task UpdateJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) + { + + IActionsProvider myActions = ActionProviderFactory.GetActionProvider(); + + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } + + ExecutionStatus AssetStatus = BodyData.AssetStatus; + UnifiedProcessStatus Manifest = BodyData.Manifest; + ExecutionStatus JobState = BodyData.JobState; + string JobStateDetails = BodyData.JobStateDetails; + + ExecutionStatus WaterMarkCopiesStatus = BodyData.WaterMarkCopiesStatus; + string WaterMarkCopiesStatusDetails = BodyData.WaterMarkCopiesStatusDetails; + switch (Manifest.AssetStatus.State) + { + case ExecutionStatus.Finished: + AssetStatus = ExecutionStatus.Finished; + break; + case ExecutionStatus.Error: + break; + case ExecutionStatus.Running: + break; + case ExecutionStatus.New: + break; + case ExecutionStatus.Aborted: + break; + default: + break; + } + var updatedManifest = myActions.UpdateJob(Manifest, AssetStatus, JobState, JobStateDetails, WaterMarkCopiesStatus, WaterMarkCopiesStatusDetails); + + return req.CreateResponse(HttpStatusCode.OK, Manifest, JsonMediaTypeFormatter.DefaultMediaType); + } + + [FunctionName("DeleteWatermarkedRenders")] + public static async Task DeleteWatermarkedRenders([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) + { + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } + IAMSProvider myAMShelp = AMSProviderFactory.CreateAMSProvider(); + + string AssetId = BodyData.AssetId; + try + { + string KeepWatermakedBlobs = System.Configuration.ConfigurationManager.AppSettings["KeepWatermakedBlobs"] ?? "false"; + + if (!(KeepWatermakedBlobs != "false")) + { + myAMShelp.DeleteWatermakedBlobRenders(AssetId); + + } + else + log.Info($"Blob not deleted {AssetId}"); + return req.CreateResponse(HttpStatusCode.OK, new { result = "ok" }, JsonMediaTypeFormatter.DefaultMediaType); + } + catch (Exception X) + { + + return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); + } + + + + + } + + [FunctionName("DeleteSucceededPods")] + public static async Task DeleteSucceededPods([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) + { + string content = await req.Content.ReadAsStringAsync(); + var BodyData = content.GetBodyData(); + if (BodyData == null) + { + return req.CreateResponse(HttpStatusCode.BadRequest, BodyData, JsonMediaTypeFormatter.DefaultMediaType); + } + + IK8SClient k = K8SClientFactory.Create(); + string prefixName = $"allinone-job-{BodyData.JobId}"; + try + { + var r = await k.DeletePods(prefixName, "Succeeded"); + //var r = await k.DeletePods(JobId, prefixName, new List()); + + return req.CreateResponse(r.Code, r, JsonMediaTypeFormatter.DefaultMediaType); + } + catch (Exception X) + { + return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); + } + } + [FunctionName("GetK8SProcessLog")] + public static async Task GetK8SProcessLog([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context) + { + string JobId = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "JobId", true) == 0).Value; + if (string.IsNullOrEmpty(JobId)) + { + return req.CreateResponse(HttpStatusCode.InternalServerError, new { Error = "Parameter JobId is null" }, JsonMediaTypeFormatter.DefaultMediaType); + } + + var K8S = K8SClientFactory.Create(); + try + { + string jobName = $"allinone-job-{JobId}"; + var ResultList = await K8S.GetK8SJobLog(jobName); + + if (ResultList.Count == 0) + { + //Not Found + return req.CreateResponse(HttpStatusCode.NotFound, ResultList, JsonMediaTypeFormatter.DefaultMediaType); + } + else + { + //LOG + return req.CreateResponse(HttpStatusCode.OK, ResultList, JsonMediaTypeFormatter.DefaultMediaType); + } + } + catch (Exception X) + { + log.Error(X.Message); + return req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType); + } + + } + + } +} \ No newline at end of file diff --git a/MB-ForensicWatermark/WaterMarkingActions/WaterMarkingActions.csproj b/MB-ForensicWatermark/WaterMarkingActions/WaterMarkingActions.csproj index b642bee..b89c30f 100644 --- a/MB-ForensicWatermark/WaterMarkingActions/WaterMarkingActions.csproj +++ b/MB-ForensicWatermark/WaterMarkingActions/WaterMarkingActions.csproj @@ -3,10 +3,10 @@ net461 - + - + diff --git a/MB-ForensicWatermark/readme.md b/MB-ForensicWatermark/readme.md index 39ec02b..16c7a59 100644 --- a/MB-ForensicWatermark/readme.md +++ b/MB-ForensicWatermark/readme.md @@ -74,7 +74,7 @@ After you finish deployment process you will have on the same resource group 4. UnifiedProcess Logic App -So, to test **UnifiedProcess** you need to execute a POST CALL to CallBack URL specifying **AssetId** of original Assset and **EmbebedCodes** list. Each code on the list will produce a new Asset copy on AMS. +So, to test **UnifiedProcess** you need to execute a POST CALL to CallBack URL specifying **AssetId** of original Assset and **EmbeddedCodes** list. Each code on the list will produce a new Asset copy on AMS. ```json POST /workflows/[** your workflowwid here ***]/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=[** your sig **] HTTP/1.1 @@ -85,7 +85,7 @@ Postman-Token: abd40c58-d30d-c34c-6165-08161868e0de { "AssetId": "nb:cid:UUID:ecda4e79-f800-44de-9fd5-562de140c7c7", - "EmbebedCodes": + "EmbeddedCodes": [ "0x1ADE29" ] @@ -101,29 +101,29 @@ As response you will receive JOB status information. "State": "Running" }, "JobStatus": { - "JobID": "08586993026535557503409978660", + "JobId": "08586993026535557503409978660", "State": "Running", "Details": "Queue", "StartTime": "2017-08-09T18:43:54.0835878+00:00", "FinishTime": null, "Duration": null, - "EmbebedCodeList": [ + "EmbeddedCodeList": [ "0x1ADE29" ] }, - "EmbebedCodesList": [ + "EmbeddedCodesList": [ { - "EmbebedCodeValue": "0x1ADE29", + "EmbeddedCodeValue": "0x1ADE29", "State": "Running", - "ParentAssetID": "nb:cid:UUID:ecda4e79-f800-44de-9fd5-562de140c7c7", - "AssetID": "", + "ParentAssetId": "nb:cid:UUID:ecda4e79-f800-44de-9fd5-562de140c7c7", + "AssetId": "", "Details": "Just Start" } ] } ``` -After you trigger the JOB, you could check JOB status calling Azure Function **GetUnifiedProcessStatus** endpoint using same **AssetId** and **JobID** from preview response. +After you trigger the JOB, you could check JOB status calling Azure Function **GetUnifiedProcessStatus** endpoint using same **AssetId** and **JobId** from preview response. ```json POST /api/GetUnifiedProcessStatus?code=[** your code here **] HTTP/1.1 Host: [*** your HOST HERE ***] @@ -133,6 +133,6 @@ Postman-Token: b9994858-53f0-c98d-02a0-370059a56a03 { "AssetId": "nb:cid:UUID:ecda4e79-f800-44de-9fd5-562de140c7c7", - "JobID": "08586993026535557503409978660" + "JobId": "08586993026535557503409978660" } ``` diff --git a/k8s/embedder.src/DataTransferObjects.cs b/k8s/embedder.src/DataTransferObjects.cs index 2c775a2..d7fa7f4 100644 --- a/k8s/embedder.src/DataTransferObjects.cs +++ b/k8s/embedder.src/DataTransferObjects.cs @@ -11,11 +11,11 @@ namespace embedder public class EmbedderJobDTO { - [JsonProperty(propertyName: "JobID")] - public string JobID { get; set; } + [JsonProperty(propertyName: "JobId")] + public string JobId { get; set; } - [JsonProperty(propertyName: "AssetID")] - public string AssetID { get; set; } + [JsonProperty(propertyName: "AssetId")] + public string AssetId { get; set; } [JsonProperty(propertyName: "PreprocessorNotificationQueue")] public string PreprocessorNotificationQueue { get; set; } @@ -26,7 +26,7 @@ public class EmbedderJobDTO [JsonProperty(propertyName: "VideoInformation")] public VideoInformation[] PreprocessorItems { get; set; } - [JsonProperty(propertyName: "EnbebedCodes")] + [JsonProperty(propertyName: "EmbeddedCodes")] public EmbedderJobs[] EmbedderJobs { get; set; } } @@ -62,8 +62,8 @@ public class VideoInformation public class EmbedderJobs { - [JsonProperty(propertyName: "EmbebedCode")] - public string UserID { get; set; } + [JsonProperty(propertyName: "EmbeddedCode")] + public string UserId { get; set; } [JsonProperty(propertyName: "MP4WatermarkedURL")] public EmbedderItems[] EmbedderItems { get; set; } @@ -105,11 +105,11 @@ public enum PreprocessorStage public class NotificationPreprocessor : INotificationMessage { - [JsonProperty(propertyName: "JobID")] - public string JobID { get; set; } + [JsonProperty(propertyName: "JobId")] + public string JobId { get; set; } - [JsonProperty(propertyName: "AssetID")] - public string AssetID { get; set; } + [JsonProperty(propertyName: "AssetId")] + public string AssetId { get; set; } [JsonProperty(propertyName: "FileName")] public string FileName { get; set; } @@ -136,17 +136,17 @@ public enum EmbedderStage public class NotificationEmbedder : INotificationMessage { - [JsonProperty(propertyName: "JobID")] - public string JobID { get; set; } + [JsonProperty(propertyName: "JobId")] + public string JobId { get; set; } - [JsonProperty(propertyName: "AssetID")] - public string AssetID { get; set; } + [JsonProperty(propertyName: "AssetId")] + public string AssetId { get; set; } [JsonProperty(propertyName: "FileName")] public string FileName { get; set; } - [JsonProperty(propertyName: "EmbebedCode")] - public string UserID { get; set; } + [JsonProperty(propertyName: "EmbeddedCode")] + public string UserId { get; set; } [JsonProperty(propertyName: "Status")] public JobStatus Status { get; set; } diff --git a/k8s/embedder.src/Program.cs b/k8s/embedder.src/Program.cs index 5db908a..aa66194 100644 --- a/k8s/embedder.src/Program.cs +++ b/k8s/embedder.src/Program.cs @@ -38,7 +38,7 @@ internal class EmbedderJob { internal EmbedderJobDTO Job { get; set; } public string Name { get; set; } - public string UserID { get; set; } + public string UserId { get; set; } public Uri MmrkURL { get; set; } public FileInfo MmrkFile { get; set; } public Uri WatermarkedURL { get; set; } @@ -48,7 +48,7 @@ internal class EmbedderJob #endregion - public static int Main(string[] args) { return MainAsync(args).Result; } + public static int Main(string[] args) { return MainAsync(args).GetAwaiter().GetResult(); } static async Task MainAsync(string[] args) { @@ -115,9 +115,9 @@ static async Task MainAsync(string[] args) foreach (var pd in preprocessorData) { - Policy + Policy .Handle() - .WaitAndRetryAsync(retryCount: 5, sleepDurationProvider: attempt => TimeSpan.FromSeconds(1)) + .WaitAndRetry(retryCount: 5, sleepDurationProvider: attempt => TimeSpan.FromSeconds(1)) .Execute(() => { if (pd.LocalFile.Exists) @@ -135,7 +135,7 @@ static async Task MainAsync(string[] args) { Policy .Handle() - .WaitAndRetryAsync(retryCount: 5, sleepDurationProvider: attempt => TimeSpan.FromSeconds(1)) + .WaitAndRetry(retryCount: 5, sleepDurationProvider: attempt => TimeSpan.FromSeconds(1)) .Execute(() => { if (ed.WatermarkedFile.Exists) @@ -191,8 +191,8 @@ private static async Task RunPreprocessorAsync(PreprocessorJob _, Action stderr(output.Output); var queueOutput = await _.Queue.DispatchMessage(new NotificationPreprocessor { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, Status = JobStatus.Error, JobOutput = output.Output, @@ -268,8 +268,8 @@ private static async Task RunPreprocessorAsync(PreprocessorJob _, Action stderr(output.Output); var queueOutput = await _.Queue.DispatchMessage(new NotificationPreprocessor { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, Status = JobStatus.Error, JobOutput = output.Output, @@ -345,8 +345,8 @@ private static async Task RunPreprocessorAsync(PreprocessorJob _, Action stdout($"***Start PREPROCESSOR Error Notification Message {DateTime.Now.ToString()}"); var queueOutput = await _.Queue.DispatchMessage(new NotificationPreprocessor { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, Status = JobStatus.Error, JobOutput = output.Output, @@ -375,8 +375,8 @@ private static async Task RunPreprocessorAsync(PreprocessorJob _, Action stdout(output.Output); var queueOutput = await _.Queue.DispatchMessage(new NotificationPreprocessor { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, Status = JobStatus.Finished, JobOutput = output.Output, @@ -392,8 +392,8 @@ private static async Task RunPreprocessorAsync(PreprocessorJob _, Action stderr(output.Output); var queueOutput = await _.Queue.DispatchMessage(new NotificationPreprocessor { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, Status = JobStatus.Error, JobOutput = output.Output, @@ -425,8 +425,8 @@ private static async Task RunPreprocessorAsync(PreprocessorJob _, Action stderr(output.Output); var queueOutput = await _.Queue.DispatchMessage(new NotificationEmbedder { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, Status = JobStatus.Error, JobOutput = output.Output, @@ -455,10 +455,10 @@ private static IEnumerable DetermineEmbedderJobs(EmbedderJobDTO job { Job = job, Name = b.FileName, - UserID = a.UserID, + UserId = a.UserId, MmrkURL = job.PreprocessorItems.FirstOrDefault(_ => _.FileName == b.FileName)?.MmrkUrl.AsUri(), MmrkFile = b.FileName.AsMmrkFile(), - WatermarkedFile = b.FileName.AsWatermarkFileForUser(a.UserID), + WatermarkedFile = b.FileName.AsWatermarkFileForUser(a.UserId), WatermarkedURL = b.WaterMarkedMp4.AsUri(), Queue = embedderQueue @@ -477,7 +477,7 @@ private static async Task RunEmbedderAsync(EmbedderJob _, Action stdout, fileName: "/usr/bin/NGS_SmartEmbedderCLI", arguments: new[] { _.MmrkFile.FullName, - _.UserID, + _.UserId, _.WatermarkedFile.FullName } ); if (embedderOutput.Success) @@ -489,10 +489,10 @@ private static async Task RunEmbedderAsync(EmbedderJob _, Action stdout, stderr(embedderOutput.Output); var queueOutput = await _.Queue.DispatchMessage(new NotificationEmbedder { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, - UserID = _.UserID, + UserId = _.UserId, Status = JobStatus.Error, JobOutput = embedderOutput.Output }); @@ -513,10 +513,10 @@ private static async Task RunEmbedderAsync(EmbedderJob _, Action stdout, { var queueOutput = await _.Queue.DispatchMessage(new NotificationEmbedder { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, - UserID = _.UserID, + UserId = _.UserId, Status = JobStatus.Finished, JobOutput = uploadResult.Output }); @@ -529,10 +529,10 @@ private static async Task RunEmbedderAsync(EmbedderJob _, Action stdout, { var queueOutput = await _.Queue.DispatchMessage(new NotificationEmbedder { - AssetID = _.Job.AssetID, - JobID = _.Job.JobID, + AssetId = _.Job.AssetId, + JobId = _.Job.JobId, FileName = _.Name, - UserID = _.UserID, + UserId = _.UserId, Status = JobStatus.Error, JobOutput = uploadResult.Output }); @@ -545,4 +545,4 @@ private static async Task RunEmbedderAsync(EmbedderJob _, Action stdout, #endregion } } -} \ No newline at end of file +} diff --git a/k8s/embedder.src/SampleData.cs b/k8s/embedder.src/SampleData.cs index 5b38b47..286537b 100644 --- a/k8s/embedder.src/SampleData.cs +++ b/k8s/embedder.src/SampleData.cs @@ -32,14 +32,14 @@ public static class SampleData var embedDetails = new[] { - new { UserID = "0x123456", WatermarkURL = "https://mediahack.blob.core.windows.net/asset-80dcf6de-33bb-4ddc-89b7-1500afdd9736-0x123456?st=2017-06-29T15%3A29%3A00Z&se=2017-09-30T15%3A29%3A00Z&sp=rw&sv=2015-12-11&sr=c&sig=6gOwBCNG3xRnbJ%2F1OpNmg48MkuO0GsvPdg84HnHCPGU%3D" }, - new { UserID = "0x654321", WatermarkURL = "https://mediahack.blob.core.windows.net/asset-80dcf6de-33bb-4ddc-89b7-1500afdd9736-0x654321?st=2017-06-29T15%3A29%3A00Z&se=2017-07-30T15%3A29%3A00Z&sp=rw&sv=2015-12-11&sr=c&sig=t78%2FAWclQpw9%2F2RqF3v8%2Bp2g%2BFr4sL0s%2FsrWB8gjMOw%3D" } + new { UserId = "0x123456", WatermarkURL = "https://mediahack.blob.core.windows.net/asset-80dcf6de-33bb-4ddc-89b7-1500afdd9736-0x123456?st=2017-06-29T15%3A29%3A00Z&se=2017-09-30T15%3A29%3A00Z&sp=rw&sv=2015-12-11&sr=c&sig=6gOwBCNG3xRnbJ%2F1OpNmg48MkuO0GsvPdg84HnHCPGU%3D" }, + new { UserId = "0x654321", WatermarkURL = "https://mediahack.blob.core.windows.net/asset-80dcf6de-33bb-4ddc-89b7-1500afdd9736-0x654321?st=2017-06-29T15%3A29%3A00Z&se=2017-07-30T15%3A29%3A00Z&sp=rw&sv=2015-12-11&sr=c&sig=t78%2FAWclQpw9%2F2RqF3v8%2Bp2g%2BFr4sL0s%2FsrWB8gjMOw%3D" } }; var preprocessorAndEmbedderJob = new EmbedderJobDTO { - JobID = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736-full", - AssetID = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736", + JobId = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736-full", + AssetId = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736", PreprocessorNotificationQueue = queue, EmbedderNotificationQueue = queue, PreprocessorItems = bs.Select(b => new VideoInformation @@ -53,7 +53,7 @@ public static class SampleData }).ToArray(), EmbedderJobs = embedDetails.Select(_ => new EmbedderJobs { - UserID = _.UserID, + UserId = _.UserId, EmbedderItems = bs.Select(b => new EmbedderItems { WaterMarkedMp4 = _.WatermarkURL.Replace("?", $"/{b.filename}?"), @@ -64,8 +64,8 @@ public static class SampleData var preprocessorJob = new EmbedderJobDTO { - JobID = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736-full", - AssetID = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736", + JobId = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736-full", + AssetId = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736", PreprocessorNotificationQueue = queue, EmbedderNotificationQueue = queue, PreprocessorItems = bs.Select(b => new VideoInformation @@ -81,8 +81,8 @@ public static class SampleData var embedderJob = new EmbedderJobDTO { - JobID = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736-full", - AssetID = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736", + JobId = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736-full", + AssetId = "nb:cid:UUID:80dcf6de-33bb-4ddc-89b7-1500afdd9736", PreprocessorNotificationQueue = queue, EmbedderNotificationQueue = queue, PreprocessorItems = bs.Select(b => new VideoInformation @@ -92,7 +92,7 @@ public static class SampleData }).ToArray(), EmbedderJobs = embedDetails.Select(_ => new EmbedderJobs { - UserID = _.UserID, + UserId = _.UserId, EmbedderItems = bs.Select(b => new EmbedderItems { WaterMarkedMp4 = _.WatermarkURL.Replace("?", $"/{b.filename}?"), diff --git a/k8s/embedder.src/Utils.cs b/k8s/embedder.src/Utils.cs index da896e3..f7b5f35 100644 --- a/k8s/embedder.src/Utils.cs +++ b/k8s/embedder.src/Utils.cs @@ -104,7 +104,7 @@ public static FileInfo AsSafeFileName(this string x) public static FileInfo AsLocalFile(this string filename) { return (filename).AsSafeFileName(); } public static FileInfo AsStatsFile(this string filename) { return filename.Replace(".mp4", ".stats").AsSafeFileName(); } public static FileInfo AsMmrkFile(this string filename) { return filename.Replace(".mp4", ".mmrk").AsSafeFileName(); } - public static FileInfo AsWatermarkFileForUser(this string filename, string userid) { return (filename.Replace(".mp4", $"-{userid}.mp4")).AsSafeFileName(); } + public static FileInfo AsWatermarkFileForUser(this string filename, string UserId) { return (filename.Replace(".mp4", $"-{UserId}.mp4")).AsSafeFileName(); } public static Uri AsUri(this string uri) { return string.IsNullOrEmpty(uri) ? null : new Uri(uri); } diff --git a/k8s/embedder.src/embedder.csproj b/k8s/embedder.src/embedder.csproj index c5a2701..a28df37 100644 --- a/k8s/embedder.src/embedder.csproj +++ b/k8s/embedder.src/embedder.csproj @@ -1,11 +1,11 @@  - netcoreapp1.1 + netcoreapp2.0 Exe - - + + \ No newline at end of file