/// <summary> /// This API updates an existing incident /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> public async Task <UpdateIncidentResponse> UpdateIncident(UpdateIncidentRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called updateIncident"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/v2/incidents/{incidentKey}".Trim('/'))); HttpMethod method = new HttpMethod("Put"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken); } else { responseMessage = await this.restClient.HttpSend(requestMessage); } return(Converter.FromHttpResponseMessage <UpdateIncidentResponse>(responseMessage)); } catch (Exception e) { logger.Error($"UpdateIncident failed with error: {e.Message}"); throw; } }
protected override void ProcessRecord() { base.ProcessRecord(); UpdateIncidentRequest request; try { request = new UpdateIncidentRequest { IncidentKey = IncidentKey, Csi = Csi, UpdateIncidentDetails = UpdateIncidentDetails, Ocid = Ocid, OpcRequestId = OpcRequestId, IfMatch = IfMatch, Homeregion = Homeregion }; response = client.UpdateIncident(request).GetAwaiter().GetResult(); WriteOutput(response, response.Incident); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public IActionResult UpdateIncident([FromRoute] int id, [FromBody] UpdateIncidentRequest requestBody) { var incident = _incidentsManager.GetIncident(id); if (incident == null) { return(NotFound(new { message = "An incident with this ID does not exist." })); } if (incident.State == IncidentState.Resolved) { return(BadRequest(new { message = "You may not edit a resolved incident." })); } incident.Title = requestBody?.Title ?? incident.Title;; incident.CausedStatus = requestBody?.CausedStatus ?? incident.CausedStatus; _incidentsManager.UpdateIncident(incident); var service = _servicesManager.GetService(incident.ServiceId); if (service.Status < incident.CausedStatus) { service.Status = incident.CausedStatus; _servicesManager.Update(service); } return(Ok(incident)); }