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());
}
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());
}
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);
}
}
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);
}
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);
}
Aggregations