Search in sources :

Example 16 with UserProfile

use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.

the class StructuredFlowEventFactory method createStucturedFlowEvent.

public StructuredFlowEvent createStucturedFlowEvent(Long stackId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
    Stack stack = stackService.getById(stackId);
    UserProfile userProfile = userProfileService.get(stack.getAccount(), stack.getOwner());
    OperationDetails operationDetails = new OperationDetails("FLOW", "STACK", stackId, stack.getAccount(), stack.getOwner(), userProfile.getUserName(), cloudbreakNodeConfig.getId(), cbVersion);
    StackDetails stackDetails = null;
    ClusterDetails clusterDetails = null;
    BlueprintDetails blueprintDetails = null;
    if (detailed) {
        stackDetails = conversionService.convert(stack, StackDetails.class);
        Cluster cluster = stack.getCluster();
        if (cluster != null) {
            clusterDetails = conversionService.convert(cluster, ClusterDetails.class);
            blueprintDetails = conversionService.convert(cluster.getBlueprint(), BlueprintDetails.class);
        }
    }
    return exception != null ? new StructuredFlowErrorEvent(operationDetails, flowDetails, stackDetails, clusterDetails, blueprintDetails, ExceptionUtils.getStackTrace(exception)) : new StructuredFlowEvent(operationDetails, flowDetails, stackDetails, clusterDetails, blueprintDetails);
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.OperationDetails) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) BlueprintDetails(com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails) ClusterDetails(com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails) StructuredFlowErrorEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowErrorEvent) StackDetails(com.sequenceiq.cloudbreak.structuredevent.event.StackDetails) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) StructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowEvent) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 17 with UserProfile

use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.

the class StructuredFlowEventFactory method createStructuredNotificationEvent.

public StructuredNotificationEvent createStructuredNotificationEvent(Long stackId, String notificationType, String message, String instanceGroupName) {
    Stack stack = stackService.getById(stackId);
    UserProfile userProfile = userProfileService.get(stack.getAccount(), stack.getOwner());
    OperationDetails operationDetails = new OperationDetails("NOTIFICATION", "STACK", stackId, stack.getAccount(), stack.getOwner(), userProfile.getUserName(), cloudbreakNodeConfig.getInstanceUUID(), cbVersion);
    NotificationDetails notificationDetails = new NotificationDetails();
    notificationDetails.setNotificationType(notificationType);
    notificationDetails.setNotification(message);
    notificationDetails.setCloud(stack.cloudPlatform());
    notificationDetails.setRegion(stack.getRegion());
    notificationDetails.setAvailabiltyZone(stack.getAvailabilityZone());
    notificationDetails.setStackId(stackId);
    notificationDetails.setStackName(stack.getDisplayName());
    notificationDetails.setStackStatus(stack.getStatus().name());
    notificationDetails.setNodeCount(stack.getRunningInstanceMetaData().size());
    notificationDetails.setInstanceGroup(instanceGroupName);
    Cluster cluster = stack.getCluster();
    if (cluster != null) {
        notificationDetails.setClusterId(cluster.getId());
        notificationDetails.setClusterName(cluster.getName());
        notificationDetails.setClusterStatus(cluster.getStatus().name());
        Blueprint blueprint = cluster.getBlueprint();
        if (blueprint != null) {
            notificationDetails.setBlueprintId(blueprint.getId());
            notificationDetails.setBlueprintName(blueprint.getAmbariName());
        }
    }
    return new StructuredNotificationEvent(operationDetails, notificationDetails);
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.OperationDetails) NotificationDetails(com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)17 Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)6 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)2 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.OperationDetails)2 Before (org.junit.Before)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 Credential (com.sequenceiq.cloudbreak.domain.Credential)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1 BlueprintDetails (com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails)1 ClusterDetails (com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails)1 NotificationDetails (com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails)1 StackDetails (com.sequenceiq.cloudbreak.structuredevent.event.StackDetails)1 StructuredFlowErrorEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowErrorEvent)1