Search in sources :

Example 1 with OperationDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.

the class BaseLegacyStructuredFlowEventFactory method createStructuredNotificationEvent.

public StructuredNotificationEvent createStructuredNotificationEvent(Stack stack, String notificationType, String message, String instanceGroupName) {
    Long stackId = stack.getId();
    NotificationDetails notificationDetails = new NotificationDetails();
    notificationDetails.setNotificationType(notificationType);
    notificationDetails.setNotification(message);
    notificationDetails.setStackId(stackId);
    String stackName = stack.getName();
    String userName = stack.getCreator().getUserName();
    String userId = stack.getCreator().getUserId();
    try {
        notificationDetails.setCloud(stack.cloudPlatform());
        notificationDetails.setRegion(stack.getRegion());
        notificationDetails.setAvailabiltyZone(stack.getAvailabilityZone());
        notificationDetails.setStackName(stack.getDisplayName());
        notificationDetails.setStackStatus(stack.getStatus().name());
        notificationDetails.setNodeCount(stack.getNotDeletedInstanceMetaDataSet().size());
        Cluster cluster = stack.getCluster();
        notificationDetails.setInstanceGroup(instanceGroupName);
        if (cluster != null) {
            notificationDetails.setClusterId(cluster.getId());
            notificationDetails.setClusterName(cluster.getName());
            notificationDetails.setClusterStatus(stack.getStatus().name());
            Blueprint blueprint = cluster.getBlueprint();
            if (blueprint != null) {
                notificationDetails.setBlueprintId(blueprint.getId());
                notificationDetails.setBlueprintName(blueprint.getStackName());
            }
        }
    } catch (AccessDeniedException e) {
        LOGGER.info("Access denied in structured notification event creation, user: {}, stack: {}", userName, stackId, e);
    }
    String resourceType = (stack.getType() == null || stack.getType().equals(StackType.WORKLOAD)) ? CloudbreakEventService.DATAHUB_RESOURCE_TYPE : CloudbreakEventService.DATALAKE_RESOURCE_TYPE;
    OperationDetails operationDetails = new OperationDetails(clock.getCurrentTimeMillis(), NOTIFICATION, resourceType, stackId, stackName, nodeConfig.getInstanceUUID(), cbVersion, stack.getWorkspace().getId(), userId, userName, stack.getTenant().getName(), stack.getResourceCrn(), stack.getCreator().getUserCrn(), stack.getEnvironmentCrn(), null);
    return new StructuredNotificationEvent(operationDetails, notificationDetails);
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) NotificationDetails(com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent)

Example 2 with OperationDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.

the class BaseLegacyStructuredFlowEventFactory method createStucturedFlowEvent.

@Override
public StructuredFlowEvent createStucturedFlowEvent(Long stackId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
    Stack stack = stackService.getByIdWithTransaction(stackId);
    String resourceType = (stack.getType() == null || stack.getType().equals(StackType.WORKLOAD)) ? CloudbreakEventService.DATAHUB_RESOURCE_TYPE : CloudbreakEventService.DATALAKE_RESOURCE_TYPE;
    OperationDetails operationDetails = new OperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, stackId, stack.getName(), nodeConfig.getId(), cbVersion, stack.getWorkspace().getId(), stack.getCreator().getUserId(), stack.getCreator().getUserName(), stack.getTenant().getName(), stack.getResourceCrn(), stack.getCreator().getUserCrn(), stack.getEnvironmentCrn(), null);
    StackDetails stackDetails = null;
    ClusterDetails clusterDetails = null;
    BlueprintDetails blueprintDetails = null;
    if (detailed) {
        stackDetails = stackToStackDetailsConverter.convert(stack);
        Cluster cluster = stack.getCluster();
        if (cluster != null) {
            clusterDetails = clusterToClusterDetailsConverter.convert(cluster);
            blueprintDetails = getIfNotNull(cluster.getBlueprint(), blueprintToBlueprintDetailsConverter::convert);
        }
    }
    StructuredFlowEvent event = new StructuredFlowEvent(operationDetails, flowDetails, stackDetails, clusterDetails, blueprintDetails);
    if (exception != null) {
        event.setException(ExceptionUtils.getStackTrace(exception));
    }
    return event;
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) BlueprintDetails(com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails) ClusterDetails(com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails) StackDetails(com.sequenceiq.cloudbreak.structuredevent.event.StackDetails) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 3 with OperationDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.

the class DistroxStopStartScaleDurationAssertions method getTimestampForEvent.

private long getTimestampForEvent(List<StructuredNotificationEvent> structuredNotificationEvents, String message) {
    OperationDetails latestEvent = structuredNotificationEvents.stream().filter(events -> StringUtils.containsIgnoreCase(events.getNotificationDetails().getNotification(), message)).map(StructuredEvent::getOperation).max(Comparator.comparing(OperationDetails::getTimestamp)).orElseThrow(() -> new TestFailException(String.format("Cannot find Structured Event for '%s' message!", message)));
    long latestEventTimestamp = latestEvent.getTimestamp();
    LOGGER.info(String.format("[%s] event time '%s'.", message, LocalDateTime.ofInstant(Instant.ofEpochMilli(latestEventTimestamp), ZoneId.systemDefault())));
    return latestEventTimestamp;
}
Also used : Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) Instant(java.time.Instant) StringUtils(org.apache.commons.lang3.StringUtils) ZoneId(java.time.ZoneId) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) TimeUnit(java.util.concurrent.TimeUnit) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) Assertion(com.sequenceiq.it.cloudbreak.assertion.Assertion) List(java.util.List) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent) StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) Comparator(java.util.Comparator) CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 4 with OperationDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.

the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackNotFound.

@Test
public void testRequestParametersWhenStackNotFound() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceName("name");
    operation.setWorkspaceId(123L);
    event.setOperation(operation);
    RestCallDetails restCall = new RestCallDetails();
    event.setRestCall(restCall);
    RestRequestDetails restRequest = new RestRequestDetails();
    restCall.setRestRequest(restRequest);
    Map<String, Object> params = new HashMap<>();
    when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
    when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.empty());
    Map<String, Object> actual = underTest.requestParameters(event);
    Assertions.assertEquals(0, actual.size());
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Test(org.junit.jupiter.api.Test)

Example 5 with OperationDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.

the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundButNotScaling.

@Test
public void testRequestParametersWhenStackFoundButNotScaling() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceName("name");
    operation.setWorkspaceId(123L);
    event.setOperation(operation);
    RestCallDetails restCall = new RestCallDetails();
    event.setRestCall(restCall);
    RestRequestDetails restRequest = new RestRequestDetails();
    restRequest.setMethod("POST");
    restCall.setRestRequest(restRequest);
    Stack stack = new Stack();
    Map<String, Object> params = new HashMap<>();
    when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
    when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
    Map<String, Object> actual = underTest.requestParameters(event);
    Assertions.assertEquals(0, actual.size());
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)19 Test (org.junit.jupiter.api.Test)10 StructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent)8 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)8 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)8 Json (com.sequenceiq.cloudbreak.common.json.Json)7 HashMap (java.util.HashMap)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)5 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)4 StructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowEvent)3 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)2 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)2 BlueprintDetails (com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails)2 ClusterDetails (com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails)2 NotificationDetails (com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails)2 StackDetails (com.sequenceiq.cloudbreak.structuredevent.event.StackDetails)2 StructuredNotificationEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent)2 StructuredSyncEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent)2 CloudbreakEventV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Response)1