Exemplo n.º 1
0
        public static async Task ProcessNotificationAsync(WorkerRequest request, ProcessNotificationRequest @event)
        {
            var jobProcessId        = @event.JobProcessId;
            var notification        = @event.Notification;
            var notificationJobData = notification.Content.ToMcmaObject <JobBase>();

            var table = new DynamoDbTable <JobProcess>(request.TableName());

            var jobProcess = await table.GetAsync(jobProcessId);

            // not updating job if it already was marked as completed or failed.
            if (jobProcess.Status == JobStatus.Completed || jobProcess.Status == JobStatus.Failed)
            {
                Logger.Warn("Ignoring update of job process that tried to change state from " + jobProcess.Status + " to " + notificationJobData.Status);
                return;
            }

            jobProcess.Status        = notificationJobData.Status;
            jobProcess.StatusMessage = notificationJobData.StatusMessage;
            jobProcess.Progress      = notificationJobData.Progress;
            jobProcess.JobOutput     = notificationJobData.JobOutput;
            jobProcess.DateModified  = DateTime.UtcNow;

            await table.PutAsync(jobProcessId, jobProcess);

            var resourceManager = request.GetAwsV4ResourceManager();

            await resourceManager.SendNotificationAsync(jobProcess, jobProcess.NotificationEndpoint);
        }
Exemplo n.º 2
0
        protected override async Task ExecuteAsync(WorkerRequest @event, ProcessNotificationRequest notificationRequest)
        {
            var jobAssignmentId        = notificationRequest.JobAssignmentId;
            var notification           = notificationRequest.Notification;
            var notificationJobPayload = notification.Content.ToMcmaObject <JobBase>();

            var table = new DynamoDbTable <JobAssignment>(@event.TableName());

            var jobAssignment = await table.GetAsync(jobAssignmentId);

            jobAssignment.Status        = notificationJobPayload.Status;
            jobAssignment.StatusMessage = notificationJobPayload.StatusMessage;
            if (notificationJobPayload.Progress != null)
            {
                jobAssignment.Progress = notificationJobPayload.Progress;
            }

            jobAssignment.JobOutput    = notificationJobPayload.JobOutput;
            jobAssignment.DateModified = DateTime.UtcNow;

            await table.PutAsync(jobAssignmentId, jobAssignment);

            var resourceManager = @event.GetAwsV4ResourceManager();

            await resourceManager.SendNotificationAsync(jobAssignment, jobAssignment.NotificationEndpoint);
        }
        public static async Task PutServiceAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(PutServiceAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var service = request.JsonBody?.ToMcmaObject <Service>();

            if (service == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing request body.";
                return;
            }

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var serviceId = request.StageVariables["PublicUrl"] + request.Path;

            service.Id           = serviceId;
            service.DateModified = DateTime.UtcNow;
            if (!service.DateCreated.HasValue)
            {
                service.DateCreated = service.DateModified;
            }

            await table.PutAsync <Service>(serviceId, service);

            response.JsonBody = service.ToMcmaJson();
        }
        internal static async Task ProcessNotificationAsync(WorkflowServiceWorkerRequest @event)
        {
            var jobAssignmentId        = @event.JobAssignmentId;
            var notification           = @event.Notification;
            var notificationJobPayload = notification.Content.ToMcmaObject <JobBase>();

            var table = new DynamoDbTable(@event.Request.StageVariables["TableName"]);

            var jobAssignment = await table.GetAsync <JobAssignment>(jobAssignmentId);

            jobAssignment.Status        = notificationJobPayload.Status;
            jobAssignment.StatusMessage = notificationJobPayload.StatusMessage;
            if (notificationJobPayload.Progress != null)
            {
                jobAssignment.Progress = notificationJobPayload.Progress;
            }

            jobAssignment.JobOutput    = notificationJobPayload.JobOutput;
            jobAssignment.DateModified = DateTime.UtcNow;

            await table.PutAsync <JobAssignment>(jobAssignmentId, jobAssignment);

            var resourceManager = @event.Request.GetAwsV4ResourceManager();

            await resourceManager.SendNotificationAsync(jobAssignment, jobAssignment.NotificationEndpoint);
        }
Exemplo n.º 5
0
        private static async Task UpdateJobAssignmentWithOutputAsync(DynamoDbTable table, string jobAssignmentId, JobParameterBag jobOutput)
        {
            var jobAssignment = await GetJobAssignmentAsync(table, jobAssignmentId);

            jobAssignment.JobOutput = jobOutput;
            await PutJobAssignmentAsync(null, table, jobAssignmentId, jobAssignment);
        }
        public static async Task DeleteJobAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(DeleteJobAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobId = request.StageVariables["PublicUrl"] + request.Path;

            var job = await table.GetAsync <Job>(jobId);

            if (job == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'.";
                return;
            }

            await table.DeleteAsync <Job>(jobId);

            // invoking worker lambda function that will delete the JobProcess created for this Job
            if (!string.IsNullOrEmpty(job.JobProcess))
            {
                var lambdaClient  = new AmazonLambdaClient();
                var invokeRequest = new InvokeRequest
                {
                    FunctionName   = request.StageVariables["WorkerLambdaFunctionName"],
                    InvocationType = "Event",
                    LogType        = "None",
                    Payload        = new { action = "deleteJobProcess", request = request, jobProcessId = job.JobProcess }.ToMcmaJson().ToString()
                };

                await lambdaClient.InvokeAsync(invokeRequest);
            }
        }
        public static async Task ProcessNotificationAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobAssignmentId = request.StageVariables["PublicUrl"] + "/job-assignments/" + request.PathVariables["id"];

            var jobAssignment = await table.GetAsync <JobAssignment>(jobAssignmentId);

            if (jobAssignment == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'";
                return;
            }

            var notification = request.JsonBody?.ToMcmaObject <Notification>();

            if (notification == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing notification in request body";
                return;
            }

            var lambdaClient  = new AmazonLambdaClient();
            var invokeRequest = new InvokeRequest
            {
                FunctionName   = request.StageVariables["WorkerLambdaFunctionName"],
                InvocationType = "Event",
                LogType        = "None",
                Payload        = new { action = "ProcessNotification", request = request, jobAssignmentId = jobAssignmentId, notification = notification }.ToMcmaJson().ToString()
            };

            await lambdaClient.InvokeAsync(invokeRequest);
        }
        internal static async Task ProcessNotificationAsync(JobRepositoryWorkerRequest @event)
        {
            var jobId           = @event.JobId;
            var notification    = @event.Notification;
            var notificationJob = notification.Content.ToMcmaObject <JobBase>();

            var table = new DynamoDbTable(@event.Request.StageVariables["TableName"]);

            var job = await table.GetAsync <Job>(jobId);

            // not updating job if it already was marked as completed or failed.
            if (job.Status == "COMPLETED" || job.Status == "FAILED")
            {
                Logger.Warn("Ignoring update of job that tried to change state from " + job.Status + " to " + notificationJob.Status);
                return;
            }

            job.Status        = notificationJob.Status;
            job.StatusMessage = notificationJob.StatusMessage;
            job.Progress      = notificationJob.Progress;
            job.JobOutput     = notificationJob.JobOutput;
            job.DateModified  = DateTime.UtcNow;

            await table.PutAsync <Job>(jobId, job);

            var resourceManager = @event.Request.GetAwsV4ResourceManager();

            await resourceManager.SendNotificationAsync(job, job.NotificationEndpoint);
        }
        public static async Task AddServiceAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(AddServiceAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var service = request.JsonBody?.ToMcmaObject <Service>();

            if (service == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing request body.";
                return;
            }

            var serviceId = request.StageVariables["PublicUrl"] + "/services/" + Guid.NewGuid();

            service.Id           = serviceId;
            service.DateCreated  = DateTime.UtcNow;
            service.DateModified = service.DateCreated;

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            await table.PutAsync <Service>(serviceId, service);

            response.StatusCode          = (int)HttpStatusCode.Created;
            response.Headers["Location"] = service.Id;
            response.JsonBody            = service.ToMcmaJson();

            Logger.Debug(response.ToMcmaJson().ToString());
        }
Exemplo n.º 10
0
        public static async Task ProcessNotificationAsync(McmaApiRequestContext requestContext)
        {
            var request  = requestContext.Request;
            var response = requestContext.Response;

            var table = new DynamoDbTable <JobProcess>(requestContext.TableName());

            var jobProcess = await table.GetAsync(requestContext.PublicUrl() + "/job-processes/" + request.PathVariables["id"]);

            if (!requestContext.ResourceIfFound(jobProcess, false) ||
                requestContext.IsBadRequestDueToMissingBody <Notification>(out var notification))
            {
                return;
            }

            if (jobProcess.JobAssignment != notification.Source)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Unexpected notification from '" + notification.Source + "'.";
                return;
            }

            await WorkerInvoker.RunAsync(
                requestContext.WorkerFunctionName(),
                new
            {
                operationName    = "processNotification",
                contextVariables = requestContext.GetAllContextVariables(),
                input            = new
                {
                    jobProcessId = jobProcess.Id,
                    notification = notification
                }
            });
        }
        public static async Task PutBmContentAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(PutBmContentAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var bmContent = request.JsonBody?.ToMcmaObject <BMContent>();

            if (bmContent == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing request body.";
                return;
            }

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var bmContentId = request.StageVariables["PublicUrl"] + request.Path;

            bmContent.Id           = bmContentId;
            bmContent.DateModified = DateTime.UtcNow;
            if (!bmContent.DateCreated.HasValue)
            {
                bmContent.DateCreated = bmContent.DateModified;
            }

            await table.PutAsync <BMContent>(bmContentId, bmContent);

            response.JsonBody = bmContent.ToMcmaJson();
        }
        public static async Task AddBmContentAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(AddBmContentAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var bmContent = request.JsonBody?.ToMcmaObject <BMContent>();

            if (bmContent == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing request body.";
                return;
            }

            var bmContentId = request.StageVariables["PublicUrl"] + "/bm-contents/" + Guid.NewGuid();

            bmContent.Id           = bmContentId;
            bmContent.Status       = "NEW";
            bmContent.DateCreated  = DateTime.UtcNow;
            bmContent.DateModified = bmContent.DateCreated;

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            await table.PutAsync <BMContent>(bmContentId, bmContent);

            response.StatusCode          = (int)HttpStatusCode.Created;
            response.Headers["Location"] = bmContent.Id;
            response.JsonBody            = bmContent.ToMcmaJson();

            Logger.Debug(response.ToMcmaJson().ToString());
        }
        public static async Task ProcessNotificationAsync(McmaApiRequestContext requestContext)
        {
            var table = new DynamoDbTable <JobAssignment>(requestContext.TableName());

            var jobAssignment =
                await table.GetAsync(requestContext.PublicUrl() + "/job-assignments/" + requestContext.Request.PathVariables["id"]);

            if (!requestContext.ResourceIfFound(jobAssignment, false) || requestContext.IsBadRequestDueToMissingBody(out Notification notification))
            {
                return;
            }

            await WorkerInvoker.RunAsync(
                requestContext.WorkerFunctionName(),
                new
            {
                operationName    = "ProcessNotification",
                contextVariables = requestContext.GetAllContextVariables(),
                input            = new
                {
                    jobAssignmentId = jobAssignment.Id,
                    notification    = notification
                }
            });
        }
Exemplo n.º 14
0
        private static async Task <JobAssignment> GetJobAssignmentAsync(DynamoDbTable table, string jobAssignmentId)
        {
            var jobAssignment = await table.GetAsync <JobAssignment>(jobAssignmentId);

            if (jobAssignment == null)
            {
                throw new Exception("JobAssignment with id '" + jobAssignmentId + "' not found");
            }
            return(jobAssignment);
        }
        internal static async Task ProcessJobAssignmentAsync(AmeServiceWorkerRequest @event)
        {
            var resourceManager = @event.Request.GetAwsV4ResourceManager();

            var table           = new DynamoDbTable(@event.Request.StageVariables["TableName"]);
            var jobAssignmentId = @event.JobAssignmentId;

            try
            {
                // 1. Setting job assignment status to RUNNING
                await UpdateJobAssignmentStatusAsync(resourceManager, table, jobAssignmentId, "RUNNING", null);

                // 2. Retrieving WorkflowJob
                var ameJob = await RetrieveAmeJobAsync(resourceManager, table, jobAssignmentId);

                // 3. Retrieve JobProfile
                var jobProfile = await RetrieveJobProfileAsync(resourceManager, ameJob);

                // 4. Retrieve job inputParameters
                var jobInput = ameJob.JobInput;

                // 5. Check if we support jobProfile and if we have required parameters in jobInput
                ValidateJobProfile(jobProfile, jobInput);

                S3Locator inputFile;
                if (!jobInput.TryGet <S3Locator>(nameof(inputFile), out inputFile))
                {
                    throw new Exception("Invalid or missing input file.");
                }

                S3Locator outputLocation;
                if (!jobInput.TryGet <S3Locator>(nameof(outputLocation), out outputLocation))
                {
                    throw new Exception("Invalid or missing output location.");
                }

                MediaInfoProcess mediaInfoProcess;
                if (inputFile is HttpEndpointLocator httpEndpointLocator && !string.IsNullOrWhiteSpace(httpEndpointLocator.HttpEndpoint))
                {
                    Logger.Debug("Running MediaInfo against " + httpEndpointLocator.HttpEndpoint);
                    mediaInfoProcess = await MediaInfoProcess.RunAsync("--Output=EBUCore_JSON", httpEndpointLocator.HttpEndpoint);
                }
                else if (inputFile is S3Locator s3Locator && !string.IsNullOrWhiteSpace(s3Locator.AwsS3Bucket) && !string.IsNullOrWhiteSpace(s3Locator.AwsS3Key))
                {
                    var s3GetResponse = await(await s3Locator.GetClientAsync()).GetObjectAsync(s3Locator.AwsS3Bucket, s3Locator.AwsS3Key);

                    var localFileName = "/tmp/" + Guid.NewGuid().ToString();
                    await s3GetResponse.WriteResponseStreamToFileAsync(localFileName, false, CancellationToken.None);

                    Logger.Debug("Running MediaInfo against " + localFileName);
                    mediaInfoProcess = await MediaInfoProcess.RunAsync("--Output=EBUCore_JSON", localFileName);

                    File.Delete(localFileName);
                }
Exemplo n.º 16
0
        public static async Task GetJobAssignmentsAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(GetJobAssignmentsAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            response.JsonBody = (await table.GetAllAsync <JobAssignment>()).ToMcmaJson();

            Logger.Debug(response.ToMcmaJson().ToString());
        }
Exemplo n.º 17
0
        public static async Task ProcessNotificationAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(ProcessNotificationAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobAssignmentId = request.StageVariables["PublicUrl"] + "/job-assignments/" + request.PathVariables["id"];

            var jobAssignment = await table.GetAsync <JobAssignment>(jobAssignmentId);

            Logger.Debug("jobAssignment = {0}", jobAssignment);

            if (jobAssignment == null)
            {
                Logger.Debug("jobAssignment not found", jobAssignment);
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'.";
                return;
            }

            var notification = request.QueryStringParameters;

            Logger.Debug("notification = {0}", notification);
            if (notification == null || !notification.Any())
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing notification in request Query String";
                return;
            }

            // invoking worker lambda function that will process the notification
            var lambdaClient  = new AmazonLambdaClient();
            var invokeRequest = new InvokeRequest
            {
                FunctionName   = request.StageVariables["WorkerLambdaFunctionName"],
                InvocationType = "Event",
                LogType        = "None",
                Payload        =
                    new
                {
                    action         = "ProcessNotification",
                    stageVariables = request.StageVariables,
                    jobAssignmentId,
                    notification
                }.ToMcmaJson().ToString()
            };

            Logger.Debug("Invoking Lambda with payload: {0}", invokeRequest.Payload);

            await lambdaClient.InvokeAsync(invokeRequest);
        }
        public static async Task GetBmEssencesAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(GetBmEssencesAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var essences = await table.GetAllAsync <BMEssence>();

            response.JsonBody = essences.ToMcmaJson();

            Logger.Debug(response.ToMcmaJson().ToString());
        }
Exemplo n.º 19
0
        public static async Task CancelJobAsync(McmaApiRequestContext requestContext)
        {
            var table = new DynamoDbTable <Job>(requestContext.TableName());

            var jobId = requestContext.PublicUrl() + "/jobs/" + requestContext.Request.PathVariables["id"];

            if (!requestContext.ResourceIfFound(await table.GetAsync(jobId), false))
            {
                return;
            }

            requestContext.Response.StatusCode    = (int)HttpStatusCode.NotImplemented;
            requestContext.Response.StatusMessage = "Stopping job is not implemented";
        }
        public static async Task AddJobAssignmentAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(AddJobAssignmentAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var jobAssignment = request.JsonBody?.ToMcmaObject <JobAssignment>();

            if (jobAssignment == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing request body.";
                return;
            }

            var jobAssignmentId = request.StageVariables["PublicUrl"] + "/job-assignments/" + Guid.NewGuid();

            jobAssignment.Id           = jobAssignmentId;
            jobAssignment.Status       = "NEW";
            jobAssignment.DateCreated  = DateTime.UtcNow;
            jobAssignment.DateModified = jobAssignment.DateCreated;

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            await table.PutAsync <JobAssignment>(jobAssignmentId, jobAssignment);

            response.StatusCode          = (int)HttpStatusCode.Created;
            response.Headers["Location"] = jobAssignment.Id;
            response.JsonBody            = jobAssignment.ToMcmaJson();

            Logger.Debug(response.ToMcmaJson().ToString());

            // invoking worker lambda function that will create a jobAssignment assignment for this new jobAssignment
            var lambdaClient  = new AmazonLambdaClient();
            var invokeRequest = new InvokeRequest
            {
                FunctionName   = request.StageVariables["WorkerLambdaFunctionName"],
                InvocationType = "Event",
                LogType        = "None",
                Payload        = new
                {
                    action          = "ProcessJobAssignment",
                    stageVariables  = request.StageVariables,
                    jobAssignmentId = jobAssignmentId
                }.ToMcmaJson().ToString()
            };

            await lambdaClient.InvokeAsync(invokeRequest);
        }
Exemplo n.º 21
0
        public static async Task DeleteJobAssignmentsAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(DeleteJobAssignmentsAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobAssignments = await table.GetAllAsync <JobAssignment>();

            foreach (var jobAssignment in jobAssignments)
            {
                await table.DeleteAsync <JobAssignment>(jobAssignment.Id);
            }

            Logger.Debug(response.ToMcmaJson().ToString());
        }
        public static async Task GetServiceAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(GetServiceAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var serviceId = request.StageVariables["PublicUrl"] + request.Path;

            response.JsonBody = (await table.GetAsync <Service>(serviceId))?.ToMcmaJson();

            if (response.JsonBody == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'.";
            }
        }
        public static async Task GetServicesAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(GetServicesAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var services = await table.GetAllAsync <Service>();

            if (request.QueryStringParameters.Any())
            {
                services.Filter(request.QueryStringParameters);
            }

            response.JsonBody = services.ToMcmaJson();

            Logger.Debug(response.ToMcmaJson().ToString());
        }
        public static async Task CancelJobAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobId = request.StageVariables["PublicUrl"] + "/jobs/" + request.PathVariables["id"];

            var job = await table.GetAsync <Job>(jobId);

            if (job == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'";
                return;
            }

            response.StatusCode    = (int)HttpStatusCode.NotImplemented;
            response.StatusMessage = "Canceling job is not implemented";
        }
Exemplo n.º 25
0
        public static async Task GetJobAssignmentAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(GetJobAssignmentAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobAssignmentId = request.StageVariables["PublicUrl"] + request.Path;

            var jobAssignment = await table.GetAsync <JobAssignment>(jobAssignmentId);

            response.JsonBody = jobAssignment != null?jobAssignment.ToMcmaJson() : null;

            if (response.JsonBody == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'.";
            }
        }
Exemplo n.º 26
0
        public static async Task ProcessNotificationAsync(McmaApiRequestContext requestContext)
        {
            Logger.Debug(nameof(ProcessNotificationAsync));
            Logger.Debug(requestContext.Request.ToMcmaJson().ToString());

            var table = new DynamoDbTable <JobAssignment>(requestContext.TableName());

            var jobAssignmentId = requestContext.PublicUrl() + "/job-assignments/" + requestContext.Request.PathVariables["id"];

            var jobAssignment = await table.GetAsync(jobAssignmentId);

            Logger.Debug("jobAssignment = {0}", jobAssignment);

            if (!requestContext.ResourceIfFound(jobAssignment, false))
            {
                return;
            }

            var notification = requestContext.Request.QueryStringParameters;

            Logger.Debug("notification = {0}", notification);
            if (notification == null || !notification.Any())
            {
                requestContext.Response.StatusCode    = (int)HttpStatusCode.BadRequest;
                requestContext.Response.StatusMessage = "Missing notification in request Query String";
                return;
            }

            var lambdaWorkerInvoker = new LambdaWorkerInvoker();
            await lambdaWorkerInvoker.RunAsync(
                requestContext.WorkerFunctionName(),
                new
            {
                operationName    = "ProcessNotification",
                contextVariables = requestContext.GetAllContextVariables(),
                input            = new
                {
                    jobAssignmentId,
                    notification
                }
            });
        }
        public static async Task GetJobProfilesAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(GetJobProfilesAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobProfiles = await table.GetAllAsync <JobProfile>();

            if (request.QueryStringParameters.Any())
            {
                Logger.Debug(
                    "Applying job profile filter from query string: " + string.Join(", ", request.QueryStringParameters.Select(kvp => $"{kvp.Key}={kvp.Value}")));
                jobProfiles.Filter(request.QueryStringParameters);
            }

            response.JsonBody = jobProfiles.ToMcmaJson();

            Logger.Debug(response.ToMcmaJson().ToString());
        }
        public static async Task DeleteBmEssenceAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(DeleteBmEssenceAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var bmEssenceId = request.StageVariables["PublicUrl"] + request.Path;

            var bmEssence = await table.GetAsync <BMEssence>(bmEssenceId);

            if (bmEssence == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'.";
                return;
            }

            await table.DeleteAsync <BMEssence>(bmEssenceId);
        }
        internal static async Task CreateJobProcessAsync(JobRepositoryWorkerRequest @event)
        {
            var jobId = @event.JobId;

            var table = new DynamoDbTable(@event.Request.StageVariables["TableName"]);
            var job   = await table.GetAsync <Job>(jobId);

            var resourceManager = @event.Request.GetAwsV4ResourceManager();

            try
            {
                var jobProcess = new JobProcess {
                    Job = jobId, NotificationEndpoint = new NotificationEndpoint {
                        HttpEndpoint = jobId + "/notifications"
                    }
                };
                jobProcess = await resourceManager.CreateAsync(jobProcess);

                job.Status     = "QUEUED";
                job.JobProcess = jobProcess.Id;
            }
            catch (Exception error)
            {
                Logger.Error("Failed to create JobProcess.");
                Logger.Exception(error);

                job.Status        = "FAILED";
                job.StatusMessage = $"Failed to create JobProcess due to error '{error}'";
            }

            job.DateModified = DateTime.UtcNow;

            await table.PutAsync <Job>(jobId, job);

            await resourceManager.SendNotificationAsync(job, job.NotificationEndpoint);
        }
Exemplo n.º 30
0
        private static async Task PutJobAssignmentAsync(ResourceManager resourceManager, DynamoDbTable table, string jobAssignmentId, JobAssignment jobAssignment)
        {
            jobAssignment.DateModified = DateTime.UtcNow;
            await table.PutAsync <JobAssignment>(jobAssignmentId, jobAssignment);

            if (resourceManager != null)
            {
                await resourceManager.SendNotificationAsync(jobAssignment, jobAssignment.NotificationEndpoint);
            }
        }