use of bio.terra.cloudres.azure.resourcemanager.common.Defaults.CLOUD_RESOURCE_REQUEST_DATA_KEY in project terra-cloud-resource-lib by DataBiosphere.
the class AzureResourceCleanupRecorder method logRequest.
@Override
public Mono<Void> logRequest(ClientLogger logger, HttpRequestLoggingContext loggingOptions) {
final Context context = loggingOptions.getContext();
Optional.ofNullable(context).flatMap(c -> c.getData(CLOUD_RESOURCE_REQUEST_DATA_KEY)).ifPresent(data -> {
ResourceManagerRequestData requestData = (ResourceManagerRequestData) data;
requestData.resourceUidCreation().ifPresent(resourceUid -> CleanupRecorder.record(resourceUid, requestData.resourceCreationMetadata().orElse(null), clientConfig));
});
return Mono.empty();
}
use of bio.terra.cloudres.azure.resourcemanager.common.Defaults.CLOUD_RESOURCE_REQUEST_DATA_KEY in project terra-cloud-resource-lib by DataBiosphere.
the class AzureResponseLogger method logResponse.
@Override
public Mono<HttpResponse> logResponse(ClientLogger clientLogger, HttpResponseLoggingContext loggingOptions) {
final HttpResponse response = loggingOptions.getHttpResponse();
final HttpRequest request = response.getRequest();
// Always add request method and request URL
JsonObject requestDataJson = new JsonObject();
requestDataJson.addProperty("requestMethod", request.getHttpMethod().toString());
requestDataJson.addProperty("requestUrl", request.getUrl().toString());
// Optionally add rich request data if provided in the logging context
Optional<ResourceManagerRequestData> requestData = Optional.ofNullable(loggingOptions.getContext()).flatMap(c -> c.getData(CLOUD_RESOURCE_REQUEST_DATA_KEY)).map(o -> (ResourceManagerRequestData) o);
requestData.ifPresent(d -> requestDataJson.add("requestBody", d.serialize()));
// verbose.
if (logger.isDebugEnabled()) {
logBody(request.getHeaders(), request.getBody(), s -> requestDataJson.addProperty("rawRequestBody", s));
logBody(response.getHeaders(), response.buffer().getBody(), s -> requestDataJson.addProperty("rawResponseBody", s));
}
// Build OperationData object.
OperationData operationData = OperationData.builder().setDuration(Optional.ofNullable(loggingOptions.getResponseDuration()).orElse(Duration.ZERO)).setTryCount(OptionalInt.of(loggingOptions.getTryCount())).setExecutionException(Optional.empty()).setHttpStatusCode(OptionalInt.of(response.getStatusCode())).setCloudOperation(requestData.map(ResourceManagerRequestData::cloudOperation).orElse(ResourceManagerOperation.AZURE_RESOURCE_MANAGER_UNKNOWN_OPERATION)).setRequestData(requestDataJson).build();
// Invoke OperationAnnotator to record the operation.
operationAnnotator.recordOperation(operationData);
return Mono.justOrEmpty(response);
}
Aggregations