Search in sources :

Example 16 with StructuredSyncEvent

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

the class StructuredEventToCDPClusterShapeConverterTest method testConversionWithIncorrectBlueprintDetails.

@Test
public void testConversionWithIncorrectBlueprintDetails() {
    String blueprintJson = "{ \"cdhVersion\": \"7.2.14\", \"displayName\": \"dataengineering ha\", \"wrongServices\": " + "[{ \"refName\": \"das\", \"serviceType\": \"DAS\" }] }";
    StructuredFlowEvent structuredFlowEvent = new StructuredFlowEvent();
    structuredFlowEvent.setStack(createStackDetails());
    BlueprintDetails flowBlueprintDetails = new BlueprintDetails();
    flowBlueprintDetails.setName("My Blueprint");
    flowBlueprintDetails.setBlueprintJson(blueprintJson);
    structuredFlowEvent.setBlueprintDetails(flowBlueprintDetails);
    UsageProto.CDPClusterShape flowClusterShape = underTest.convert(structuredFlowEvent);
    Assert.assertEquals("My Blueprint", flowClusterShape.getClusterTemplateName());
    Assert.assertEquals(10, flowClusterShape.getNodes());
    Assert.assertEquals("compute=3, gw=4, master=1, worker=2", flowClusterShape.getHostGroupNodeCount());
    Assert.assertTrue(flowClusterShape.getTemporaryStorageUsed());
    Assert.assertEquals("{\"services\":{}}", flowClusterShape.getClusterTemplateDetails());
    StructuredSyncEvent structuredSyncEvent = new StructuredSyncEvent();
    structuredSyncEvent.setStack(createStackDetails());
    BlueprintDetails syncBlueprintDetails = new BlueprintDetails();
    syncBlueprintDetails.setName("My Blueprint");
    syncBlueprintDetails.setBlueprintJson(blueprintJson);
    structuredSyncEvent.setBlueprintDetails(syncBlueprintDetails);
    UsageProto.CDPClusterShape syncClusterShape = underTest.convert(structuredSyncEvent);
    Assert.assertEquals("My Blueprint", syncClusterShape.getClusterTemplateName());
    Assert.assertEquals(10, syncClusterShape.getNodes());
    Assert.assertEquals("compute=3, gw=4, master=1, worker=2", syncClusterShape.getHostGroupNodeCount());
    Assert.assertTrue(syncClusterShape.getTemporaryStorageUsed());
    Assert.assertEquals("{\"services\":{}}", syncClusterShape.getClusterTemplateDetails());
}
Also used : BlueprintDetails(com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails) StructuredSyncEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent) StructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowEvent) UsageProto(com.cloudera.thunderhead.service.common.usage.UsageProto) Test(org.junit.jupiter.api.Test)

Example 17 with StructuredSyncEvent

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

the class StructuredEventToCDPDatalakeFeaturesConverterTest method testRazEnabled.

@Test
public void testRazEnabled() {
    ClusterDetails clusterDetails = new ClusterDetails();
    clusterDetails.setRazEnabled(true);
    StructuredFlowEvent flowEvent = new StructuredFlowEvent();
    flowEvent.setCluster(clusterDetails);
    UsageProto.CDPDatalakeFeatures features = underTest.convert(flowEvent);
    assertEquals("ENABLED", features.getRaz().getStatus());
    StructuredSyncEvent syncEvent = new StructuredSyncEvent();
    syncEvent.setCluster(clusterDetails);
    features = underTest.convert(syncEvent);
    assertEquals("ENABLED", features.getRaz().getStatus());
}
Also used : ClusterDetails(com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails) StructuredSyncEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent) StructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowEvent) UsageProto(com.cloudera.thunderhead.service.common.usage.UsageProto) Test(org.junit.jupiter.api.Test)

Example 18 with StructuredSyncEvent

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

the class StructuredSynchronizerJob method executeTracedJob.

@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
    Long stackId = getLocalIdAsLong();
    try {
        Stack stack = stackService.get(stackId);
        if (stack == null) {
            LOGGER.debug("Stack not found with id {}, StructuredSynchronizerJob will be unscheduled.", stackId);
            syncJobService.unschedule(getLocalId());
        } else if (stack.getStatus() == null) {
            LOGGER.debug("Stack state is null for stack {}. The event won't be stored!", stackId);
        } else if (unschedulableStates().contains(stack.getStatus())) {
            LOGGER.debug("StructuredSynchronizerJob will be unscheduled for stack {}, stack state is {}", stackId, stack.getStatus());
            syncJobService.unschedule(getLocalId());
        } else {
            LOGGER.debug("StructuredSynchronizerJob is running for stack: '{}'", stackId);
            StructuredSyncEvent structuredEvent = structuredSyncEventFactory.createStructuredSyncEvent(stackId);
            legacyDefaultStructuredEventClient.sendStructuredEvent(structuredEvent);
        }
    } catch (NotFoundException ex) {
        LOGGER.debug("Stack not found with id {}, StructuredSynchronizerJob will be unscheduled.", stackId);
        syncJobService.unschedule(getLocalId());
    } catch (Exception ex) {
        LOGGER.error("Error happened during StructuredSyncEvent generation! The event won't be stored!", ex);
    }
}
Also used : StructuredSyncEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 19 with StructuredSyncEvent

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

the class StructuredSyncEventFactory method createStructuredSyncEvent.

public StructuredSyncEvent createStructuredSyncEvent(Long resourceId) {
    Stack stack = stackService.getByIdWithTransaction(resourceId);
    String resourceType = (stack.getType() == null || stack.getType().equals(StackType.WORKLOAD)) ? CloudbreakEventService.DATAHUB_RESOURCE_TYPE : CloudbreakEventService.DATALAKE_RESOURCE_TYPE;
    OperationDetails operationDetails = new OperationDetails(clock.getCurrentTimeMillis(), SYNC, resourceType, resourceId, stack.getName(), nodeConfig.getId(), serviceVersion, stack.getWorkspace().getId(), stack.getCreator().getUserId(), stack.getCreator().getUserName(), stack.getTenant().getName(), stack.getResourceCrn(), stack.getCreator().getUserCrn(), stack.getEnvironmentCrn(), null);
    StackDetails stackDetails = stackToStackDetailsConverter.convert(stack);
    ClusterDetails clusterDetails = null;
    BlueprintDetails blueprintDetails = null;
    Cluster cluster = stack.getCluster();
    if (cluster != null) {
        clusterDetails = clusterToClusterDetailsConverter.convert(cluster);
        blueprintDetails = blueprintToBlueprintDetailsConverter.convert(cluster.getBlueprint());
    }
    return new StructuredSyncEvent(operationDetails, stackDetails, clusterDetails, blueprintDetails);
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) BlueprintDetails(com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails) ClusterDetails(com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails) StructuredSyncEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent) StackDetails(com.sequenceiq.cloudbreak.structuredevent.event.StackDetails) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 20 with StructuredSyncEvent

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

the class StructuredSynchronizerJobTest method testJobRunsWhenStackIsInCorrectState.

@Test
public void testJobRunsWhenStackIsInCorrectState() throws JobExecutionException {
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.AVAILABLE));
    when(stackService.get(anyLong())).thenReturn(stack);
    StructuredSyncEvent structuredSyncEvent = new StructuredSyncEvent();
    when(structuredSyncEventFactory.createStructuredSyncEvent(1L)).thenReturn(structuredSyncEvent);
    underTest.executeTracedJob(jobExecutionContext);
    verify(syncJobService, times(0)).unschedule(any());
    verify(structuredSyncEventFactory, times(1)).createStructuredSyncEvent(1L);
    verify(legacyDefaultStructuredEventClient, times(1)).sendStructuredEvent(structuredSyncEvent);
}
Also used : StructuredSyncEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Test(org.junit.jupiter.api.Test)

Aggregations

StructuredSyncEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent)32 Test (org.junit.jupiter.api.Test)30 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)28 StructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowEvent)22 StackDetails (com.sequenceiq.cloudbreak.structuredevent.event.StackDetails)10 BlueprintDetails (com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails)5 ClusterDetails (com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 Json (com.sequenceiq.cloudbreak.common.json.Json)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 InstanceGroupDetails (com.sequenceiq.cloudbreak.structuredevent.event.InstanceGroupDetails)2 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)1 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 HashMap (java.util.HashMap)1 JobExecutionException (org.quartz.JobExecutionException)1