Exemple #1
0
        private async Task <WorkflowJob> CreateWorkflowJobAsync(string inputURL, string jobName, RequestCloudPortEncodeCreateDTO cloudPortEncodeCreateDTO)
        {
            var workflow = await GetWorkflowByNameAsync(cloudPortEncodeCreateDTO.WorkflowName).ConfigureAwait(false);

            var store = await _telestreamCloudStorageProvider.GetStoreByNameAsync(new Uri(cloudPortEncodeCreateDTO.OutputContainer)).ConfigureAwait(false);

            var workflowJob = new WorkflowJob
            {
                Name = jobName
            };

            // We need to pass all source files
            var workflowJobSources = new Dictionary <string, string>();

            foreach (var source in workflow.Input.Sources)
            {
                workflowJobSources[source.Key] = inputURL;
            }

            var variables = ProcessWorkflowVariables(workflow, cloudPortEncodeCreateDTO);

            workflowJob.Inputs = new WorkflowJobInputs(sources: workflowJobSources, variables: variables);

            // Configure the encode payload for OpContext and other data that needs to be tunneled thru the payload.
            // Pass the OutputContainer in the Payload, so we can get it back from CloudPort.
            var payload = new CloudPortPayload()
            {
                OperationContext = cloudPortEncodeCreateDTO.OperationContext,
                OutputContainer  = cloudPortEncodeCreateDTO.OutputContainer
            };

            workflowJob.Payload = JsonConvert.SerializeObject(payload);

            // The Storage Reference section of the Input is where the workflow will advertise which Actions (denoted by the Identifier associated with those actions) which have been configured to emit outputs.
            // Additionally, this information will indicate which outputs are TRANSIENT (or temporary) and which outputs are PERMANENT (or intended to exist beyond the lifetime of the job)
            // The intent of the Storage Reference section is to provide the entity which is submitting to this workflow the requisite information necessary to specify the desired STORAGE that the action should utilize when running.
            workflowJob.StorageReferences = new Dictionary <string, WorkflowJobStorageReferences>();

            foreach (var workflowStorageReference in workflow.Input.StorageReferences)
            {
                workflowJob.StorageReferences[workflowStorageReference.Key] = new WorkflowJobStorageReferences(
                    storeId: store.Id,
                    folderOffset: ":id");  // use the job id as a blob name prefix.
            }

            try
            {
                var job = await _telestreamCloudClientProvider.CloudPortApi.CreateWorkflowJobAsync(workflow.Id, workflowJob).ConfigureAwait(false);

                return(job);
            }
            catch (ApiException ae)
            {
                throw new GridwichCloudPortApiException("Error calling CreateWorkflowJobAsync.", cloudPortEncodeCreateDTO.OperationContext, ae);
            }
        }
        public async Task HandleAsyncShouldReturnTrueAndNotLogWhenNoErrors()
        {
            // Arrange
            var payload = new CloudPortPayload()
            {
                OperationContext = testOpCtx,
                OutputContainer  = "https://someaccount.blob.core.windows.net/somecontainer"
            };
            var cloudPortStatusData = new CloudPortStatusData()
            {
                Name       = "Dave",
                Id         = "242",
                Progress   = 42,
                State      = "Completed",
                Status     = "Succeded",
                WorkflowId = "222",
                Payload    = payload,
                ActionJobs = new object[] { new object(), new object() }
            };

            var eventToPublish = new EventGridEvent()
            {
                Id          = Guid.NewGuid().ToString(),
                Data        = JObject.FromObject(cloudPortStatusData),
                EventTime   = DateTime.Now,
                EventType   = ExternalEventTypes.CloudPortWorkflowJobProgress,
                Subject     = $"/EncodeCompleted/sagaid",
                DataVersion = "1.0",
            };

            // Arrange Mocks
            Mock.Get(_eventGridPublisher)
            .Setup(x => x.PublishEventToTopic(It.IsAny <EventGridEvent>()))
            .ReturnsAsync(true);

            // Act
            var handleAsyncResult = await _handler.HandleAsync(eventToPublish).ConfigureAwait(false);

            // Assert
            handleAsyncResult.ShouldBe(true, "handleAsync should always return true");
        }