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 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(); }
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()); }
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 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()); }
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()); }
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); }
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 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 + "'."; } }
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); }
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()); }