use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class FreeIpaCustomCrnOrNameProviderTest method testProviderWhenHasQueryParamsButNotContainsEnvironmentCrn.
@Test
public void testProviderWhenHasQueryParamsButNotContainsEnvironmentCrn() {
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails restRequestDetails = new RestRequestDetails();
restCallDetails.setRestRequest(restRequestDetails);
restRequestDetails.setRequestUri("http://localhost/any/path?asdda=asdasd");
Map<String, String> restParams = new HashMap<>();
underTest.provide(restCallDetails, null, restParams, "name", "crn");
Assertions.assertFalse(restParams.containsKey("name"));
Assertions.assertFalse(restParams.containsKey("crn"));
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class LegacyRestCommonService method addClusterCrnAndNameIfPresent.
public Map<String, Object> addClusterCrnAndNameIfPresent(StructuredRestCallEvent structuredEvent) {
Map<String, Object> params = new HashMap<>();
RestRequestDetails restRequest = structuredEvent.getRestCall().getRestRequest();
Json requestJson = getJson(restRequest.getBody());
Json responseJson = getJson(structuredEvent.getRestCall().getRestResponse().getBody());
String resourceCrn = getCrn(requestJson, responseJson, restRequest, structuredEvent.getOperation());
String name = getName(requestJson, responseJson, restRequest, structuredEvent.getOperation());
checkNameOrCrnProvided(restRequest, resourceCrn, name);
if (StringUtils.isNotEmpty(name)) {
params.put(CLUSTER_NAME, name);
}
if (StringUtils.isNotEmpty(resourceCrn)) {
params.put(CLUSTER_CRN, resourceCrn);
}
return params;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class LegacyStructuredEventFilter method createRequestDetails.
private RestRequestDetails createRequestDetails(ContainerRequestContext requestContext, String body) {
LOGGER.debug("Request body length: {}", body.length());
RestRequestDetails restRequest = new RestRequestDetails();
restRequest.setRequestUri(requestContext.getUriInfo().getRequestUri().toString());
restRequest.setBody(body);
restRequest.setCookies(requestContext.getCookies().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().toString())));
restRequest.setHeaders(requestContext.getHeaders().entrySet().stream().filter(e -> !skippedHeadersList.contains(e.getKey())).collect(Collectors.toMap(Entry::getKey, e -> StringUtils.join(e.getValue(), ","))));
MediaType mediaType = requestContext.getMediaType();
restRequest.setMediaType(mediaType != null ? mediaType.toString() : "");
restRequest.setMethod(requestContext.getMethod());
return restRequest;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class LegacyStructuredEventFilter method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
context.proceed();
if (BooleanUtils.isTrue((Boolean) context.getProperty(LOGGING_ENABLED_PROPERTY))) {
Long requestTime = (Long) context.getProperty(REQUEST_TIME);
RestRequestDetails restRequest = (RestRequestDetails) context.getProperty(REQUEST_DETAILS);
RestResponseDetails restResponse = (RestResponseDetails) context.getProperty(RESPONSE_DETAILS);
String responseBody = ((LoggingStream) context.getProperty(LOGGINGSTREAM_PROPERTY)).getStringBuilder(MessageUtils.getCharset(context.getMediaType())).toString();
Map<String, String> restParams = (Map<String, String>) context.getProperty(REST_PARAMS);
if (restParams == null) {
restParams = new HashMap<>();
}
extendRestParamsFromResponse(restParams, responseBody);
sendStructuredEvent(restRequest, restResponse, restParams, requestTime, responseBody);
}
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class RestLegacyEventDataExtractor method eventData.
@Override
public EventData eventData(StructuredRestCallEvent structuredEvent) {
RestRequestDetails restRequest = structuredEvent.getRestCall().getRestRequest();
boolean mutating = Set.of("POST", "PUT", "DELETE").contains(restRequest.getMethod());
String userAgent = restRequest.getHeaders().get("user-agent");
Map<String, Object> requestParameters = new HashMap<>();
requestParameters.put("uri", restRequest.getRequestUri());
String resourceType = structuredEvent.getOperation().getResourceType();
RestResourceAuditEventConverter restResourceAuditEventConverter = getConverter(resourceType);
if (restResourceAuditEventConverter != null) {
LOGGER.info("Determine request params with {}", restResourceAuditEventConverter);
Map<String, Object> params = restResourceAuditEventConverter.requestParameters(structuredEvent);
requestParameters.putAll(params);
}
return ApiRequestData.builder().withApiVersion(cbVersion).withMutating(mutating).withRequestParameters(new Json(requestParameters).getValue()).withUserAgent(userAgent).build();
}
Aggregations