Search in sources :

Example 1 with CDPOperationDetails

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

the class FreeipaStructuredFlowEventFactory method createStructuredFlowEvent.

@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
    Stack stack = stackService.getStackById(resourceId);
    String resourceType = CloudbreakEventService.FREEIPA_RESOURCE_TYPE;
    CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, stack.getId(), stack.getName(), nodeConfig.getId(), serviceVersion, stack.getAccountId(), stack.getResourceCrn(), ThreadBasedUserCrnProvider.getUserCrn(), stack.getEnvironmentCrn(), null);
    StackStatus stackStatus = stack.getStackStatus();
    CDPStructuredFlowEvent event = new CDPStructuredFlowEvent(operationDetails, flowDetails, null, stackStatus.getDetailedStackStatus().name(), stackStatus.getStatusReason());
    if (exception != null) {
        event.setException(ExceptionUtils.getStackTrace(exception));
    }
    return event;
}
Also used : CDPStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent) StackStatus(com.sequenceiq.freeipa.entity.StackStatus) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 2 with CDPOperationDetails

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

the class DatalakeStructuredFlowEventFactory method createStructuredFlowEvent.

@Override
public CDPStructuredFlowEvent<SdxClusterDto> createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
    SdxCluster sdxCluster = sdxService.getById(resourceId);
    CDPOperationDetails operationDetails = makeCdpOperationDetails(resourceId, sdxCluster);
    SdxClusterDto sdxClusterDto = sdxClusterDtoConverter.sdxClusterToDto(sdxCluster);
    SdxStatusEntity sdxStatus = sdxStatusRepository.findFirstByDatalakeIsOrderByIdDesc(sdxCluster);
    String status = sdxStatus.getStatus().name();
    String statusReason = sdxStatus.getStatusReason();
    CDPStructuredFlowEvent<SdxClusterDto> event = new CDPStructuredFlowEvent<>(operationDetails, flowDetails, sdxClusterDto, status, statusReason);
    if (exception != null) {
        event.setException(ExceptionUtils.getStackTrace(exception));
    }
    return event;
}
Also used : SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) CDPStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Example 3 with CDPOperationDetails

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

the class ConsumptionStructuredFlowEventFactory method createStructuredFlowEvent.

@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Exception exception) {
    Consumption consumption = consumptionService.findConsumptionById(resourceId);
    CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, CloudbreakEventService.CONSUMPTION_RESOURCE_TYPE, consumption.getId(), consumption.getName(), nodeConfig.getId(), serviceVersion, consumption.getAccountId(), consumption.getResourceCrn(), ThreadBasedUserCrnProvider.getUserCrn(), null, null);
    CDPConsumptionStructuredFlowEvent event = new CDPConsumptionStructuredFlowEvent(operationDetails, flowDetails, null, null, null);
    if (exception != null) {
        event.setException(ExceptionUtils.getStackTrace(exception));
    }
    return event;
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) CDPConsumptionStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.consumption.CDPConsumptionStructuredFlowEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Example 4 with CDPOperationDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails 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 5 with CDPOperationDetails

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

the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider.

@Test
public void testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider() {
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    RestResponseDetails response = new RestResponseDetails();
    CDPOperationDetails operationDetails = new CDPOperationDetails();
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    Map<String, String> restParams = new HashMap<>();
    restParams.put(RESOURCE_TYPE, "mock");
    CustomCrnOrNameProvider customCrnOrNameProvider = mock(CustomCrnOrNameProvider.class);
    customCrnOrNameProviders.put("mockCustomCrnOrNameProvider", customCrnOrNameProvider);
    when(customCrnOrNameProvider.provide(restCallDetails, operationDetails, restParams, "names", "crns")).thenReturn(Map.of("crns", "pCrn", "names", "pName"));
    Map<String, Object> expected = new HashMap<>();
    expected.put("names", "pName");
    expected.put("crns", "pCrn");
    Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, operationDetails, restParams, "names", "crns");
    assertEquals(expected, actual);
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Aggregations

CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)31 Test (org.junit.jupiter.api.Test)8 CDPStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent)7 CDPStructuredNotificationEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredNotificationEvent)6 CDPStructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)5 FlowDetails (com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails)4 CDPStructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent)4 Json (com.sequenceiq.cloudbreak.common.json.Json)3 CDPStructuredEventEntity (com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity)3 CDPStructuredNotificationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredNotificationDetails)3 CDPEnvironmentStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.CDPEnvironmentStructuredFlowEvent)3 EnvironmentDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.EnvironmentDetails)3 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)3 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)2 CDPFreeIpaStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.freeipa.CDPFreeIpaStructuredFlowEvent)2 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)2 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 SdxStatusEntity (com.sequenceiq.datalake.entity.SdxStatusEntity)2 Environment (com.sequenceiq.environment.environment.domain.Environment)2