Search in sources :

Example 1 with CDPStructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.

the class StructuredEventFilterUtil method sendStructuredEvent.

public void sendStructuredEvent(RestRequestDetails restRequest, RestResponseDetails restResponse, Map<String, String> restParams, Long requestTime, String responseBody) {
    boolean valid = checkRestParams(restParams);
    try {
        if (!valid) {
            LOGGER.debug("Cannot create structured event, because rest params are invalid.");
            return;
        }
        restResponse.setBody(responseBody);
        RestCallDetails restCall = new RestCallDetails();
        restCall.setRestRequest(restRequest);
        restCall.setRestResponse(restResponse);
        restCall.setDuration(System.currentTimeMillis() - requestTime);
        Map<String, String> params = restCommonService.collectCrnAndNameIfPresent(restCall, null, restParams, RESOURCE_NAME, RESOURCE_CRN);
        dataCollector.fetchDataFromDbIfNeed(params);
        restParams.putAll(params);
        CDPOperationDetails cdpOperationDetails = restEventFilterRelatedObjectFactory.createCDPOperationDetails(restParams, requestTime);
        CDPStructuredRestCallEvent structuredEvent = new CDPStructuredRestCallEvent(cdpOperationDetails, restCall, null, null);
        structuredEventClient.sendStructuredEvent(structuredEvent);
    } catch (UnsupportedOperationException e) {
        LOGGER.debug("Audit log is unnecessary: {}", e.getMessage());
    } catch (Exception ex) {
        LOGGER.warn("Failed to send structured event: " + ex.getMessage(), ex);
    }
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) IOException(java.io.IOException)

Example 2 with CDPStructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.

the class CDPStructuredEventDBServiceTest method testCreateWhenResourceCrnIsNotEmpty.

@Test
public void testCreateWhenResourceCrnIsNotEmpty() {
    CDPStructuredEvent event = new CDPStructuredRestCallEvent();
    CDPOperationDetails operation = new CDPOperationDetails();
    operation.setResourceCrn("crn:cdp:cloudbreak:us-west-1:someone:stack:12345");
    event.setOperation(operation);
    CDPStructuredEventEntity entity = new CDPStructuredEventEntity();
    when(cdpStructuredEventToCDPStructuredEventEntityConverter.convert(event)).thenReturn(entity);
    underTest.create(event);
    verify(cdpStructuredEventToCDPStructuredEventEntityConverter, Mockito.times(1)).convert(event);
    verify(structuredEventRepository, Mockito.times(1)).save(entity);
}
Also used : CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) Test(org.junit.jupiter.api.Test)

Example 3 with CDPStructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.

the class CDPStructuredEventDBServiceTest method testCreateWhenResourceCrnIsEmpty.

@Test
public void testCreateWhenResourceCrnIsEmpty() {
    CDPStructuredEvent event = new CDPStructuredRestCallEvent();
    CDPOperationDetails operation = new CDPOperationDetails();
    operation.setResourceCrn("");
    event.setOperation(operation);
    underTest.create(event);
    verify(cdpStructuredEventToCDPStructuredEventEntityConverter, never()).convert(event);
}
Also used : CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) Test(org.junit.jupiter.api.Test)

Example 4 with CDPStructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.

the class CDPStructuredEventDBServiceTest method testCreateWhenResourceCrnIsNull.

@Test
public void testCreateWhenResourceCrnIsNull() {
    CDPStructuredEvent event = new CDPStructuredRestCallEvent();
    CDPOperationDetails operation = new CDPOperationDetails();
    operation.setResourceCrn(null);
    event.setOperation(operation);
    underTest.create(event);
    verify(cdpStructuredEventToCDPStructuredEventEntityConverter, never()).convert(event);
}
Also used : CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) Test(org.junit.jupiter.api.Test)

Example 5 with CDPStructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.

the class RestCDPEventDataExtractor method shouldAudit.

@Override
public boolean shouldAudit(CDPStructuredEvent structuredEvent) {
    CDPStructuredRestCallEvent event = (CDPStructuredRestCallEvent) structuredEvent;
    String resourceType = event.getOperation().getResourceType();
    if (resourceType != null) {
        CDPRestResourceAuditEventConverter restResourceAuditEventConverter = getConverter(resourceType);
        return restResourceAuditEventConverter != null && restResourceAuditEventConverter.shouldAudit(event);
    }
    return false;
}
Also used : CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) CDPRestResourceAuditEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.audit.auditeventname.rest.CDPRestResourceAuditEventConverter)

Aggregations

CDPStructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent)6 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)4 CDPStructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)3 Test (org.junit.jupiter.api.Test)3 CDPStructuredEventEntity (com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity)1 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)1 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)1 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)1 CDPRestResourceAuditEventConverter (com.sequenceiq.cloudbreak.structuredevent.service.audit.auditeventname.rest.CDPRestResourceAuditEventConverter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1