Search in sources :

Example 1 with SdxStatusEntity

use of com.sequenceiq.datalake.entity.SdxStatusEntity 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 2 with SdxStatusEntity

use of com.sequenceiq.datalake.entity.SdxStatusEntity in project cloudbreak by hortonworks.

the class SdxStatusServiceTest method setStatusForDatalakeAndNotify.

@Test
void setStatusForDatalakeAndNotify() throws TransactionService.TransactionExecutionException {
    doAnswer(invocation -> {
        invocation.getArgument(0, Runnable.class).run();
        return null;
    }).when(transactionService).required(any(Runnable.class));
    long deletedTimeStamp = 100L;
    when(clock.getCurrentTimeMillis()).thenReturn(deletedTimeStamp);
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setRuntime("7.0.2");
    sdxCluster.setClusterName("datalake-cluster");
    sdxCluster.setId(2L);
    SdxStatusEntity oldStatus = new SdxStatusEntity();
    oldStatus.setStatus(DatalakeStatusEnum.STACK_DELETED);
    oldStatus.setCreated(1L);
    oldStatus.setStatusReason("stack deleted");
    oldStatus.setId(1L);
    oldStatus.setDatalake(sdxCluster);
    when(sdxStatusRepository.findFirstByDatalakeIsOrderByIdDesc(any(SdxCluster.class))).thenReturn(oldStatus);
    when(sdxClusterRepository.findById(eq(2L))).thenReturn(Optional.of(sdxCluster));
    ArgumentCaptor<SdxStatusEntity> statusEntityCaptor = ArgumentCaptor.forClass(SdxStatusEntity.class);
    when(sdxStatusRepository.save(statusEntityCaptor.capture())).thenReturn(null);
    ArgumentCaptor<SdxCluster> sdxClusterCaptor = ArgumentCaptor.forClass(SdxCluster.class);
    when(sdxClusterRepository.save(sdxClusterCaptor.capture())).thenReturn(sdxCluster);
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETED, ResourceEvent.SDX_RDS_DELETION_FINISHED, "deleted", sdxCluster);
    verify(sdxStatusRepository, times(1)).save(any(SdxStatusEntity.class));
    assertEquals(DatalakeStatusEnum.DELETED, statusEntityCaptor.getValue().getStatus());
    assertEquals(Long.valueOf(deletedTimeStamp), sdxClusterCaptor.getValue().getDeleted());
    verify(transactionService, times(1)).required(any(Runnable.class));
}
Also used : SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Test(org.junit.jupiter.api.Test)

Example 3 with SdxStatusEntity

use of com.sequenceiq.datalake.entity.SdxStatusEntity in project cloudbreak by hortonworks.

the class SdxClusterStatusCheckerJobTest method setUp.

@BeforeEach
void setUp() {
    underTest.setLocalId(SDX_ID.toString());
    underTest.setRemoteResourceCrn(STACK_ID.toString());
    sdxCluster = new SdxCluster();
    sdxCluster.setClusterName("data-lake-cluster");
    when(sdxClusterRepository.findById(SDX_ID)).thenReturn(Optional.of(sdxCluster));
    stack = new StackStatusV4Response();
    when(cloudbreakInternalCrnClient.withInternalCrn()).thenReturn(cloudbreakServiceCrnEndpoints);
    when(cloudbreakServiceCrnEndpoints.autoscaleEndpoint()).thenReturn(autoscaleV4Endpoint);
    when(autoscaleV4Endpoint.getStatusByCrn(STACK_ID.toString())).thenReturn(stack);
    status = new SdxStatusEntity();
    status.setDatalake(sdxCluster);
    when(sdxStatusService.getActualStatusForSdx(sdxCluster)).thenReturn(status);
    jobDataMap = new JobDataMap();
    when(jobExecutionContext.getMergedJobDataMap()).thenReturn(jobDataMap);
    when(flowLogService.isOtherFlowRunning(any())).thenReturn(false);
}
Also used : JobDataMap(org.quartz.JobDataMap) SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with SdxStatusEntity

use of com.sequenceiq.datalake.entity.SdxStatusEntity in project cloudbreak by hortonworks.

the class SdxControllerTest method getTest.

@Test
void getTest() {
    SdxCluster sdxCluster = getValidSdxCluster();
    when(sdxService.getByNameInAccount(anyString(), anyString())).thenReturn(sdxCluster);
    SdxStatusEntity sdxStatusEntity = new SdxStatusEntity();
    sdxStatusEntity.setStatus(DatalakeStatusEnum.REQUESTED);
    sdxStatusEntity.setStatusReason("statusreason");
    sdxStatusEntity.setCreated(1L);
    when(sdxStatusService.getActualStatusForSdx(sdxCluster)).thenReturn(sdxStatusEntity);
    ReflectionTestUtils.setField(sdxClusterConverter, "sdxStatusService", sdxStatusService);
    SdxClusterResponse sdxClusterResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> sdxController.get(SDX_CLUSTER_NAME));
    assertEquals(SDX_CLUSTER_NAME, sdxClusterResponse.getName());
    assertEquals("test-env", sdxClusterResponse.getEnvironmentName());
    assertEquals("crn:sdxcluster", sdxClusterResponse.getCrn());
    assertEquals(SdxClusterStatusResponse.REQUESTED, sdxClusterResponse.getStatus());
    assertEquals("statusreason", sdxClusterResponse.getStatusReason());
}
Also used : SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) Test(org.junit.jupiter.api.Test)

Example 5 with SdxStatusEntity

use of com.sequenceiq.datalake.entity.SdxStatusEntity in project cloudbreak by hortonworks.

the class SdxService method syncComponentVersionsFromCm.

public FlowIdentifier syncComponentVersionsFromCm(String userCrn, NameOrCrn clusterNameOrCrn) {
    SdxCluster cluster = getByNameOrCrn(userCrn, clusterNameOrCrn);
    MDCBuilder.buildMdcContext(cluster);
    SdxStatusEntity sdxStatus = sdxStatusService.getActualStatusForSdx(cluster);
    if (sdxStatus.getStatus().isStopState()) {
        String message = String.format("Reading CM and parcel versions from CM cannot be initiated as the datalake is in %s state", sdxStatus.getStatus());
        LOGGER.info(message);
        throw new BadRequestException(message);
    } else {
        LOGGER.info("Syncing CM and parcel versions from CM initiated");
        return sdxReactorFlowManager.triggerDatalakeSyncComponentVersionsFromCmFlow(cluster);
    }
}
Also used : SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Aggregations

SdxStatusEntity (com.sequenceiq.datalake.entity.SdxStatusEntity)23 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)9 Test (org.junit.jupiter.api.Test)9 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)3 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)3 StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)2 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)2 CDPStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent)2 DatalakeStatusEnum (com.sequenceiq.datalake.entity.DatalakeStatusEnum)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 SdxRecoverableResponse (com.sequenceiq.sdx.api.model.SdxRecoverableResponse)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)1 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 AllocateDatabaseServerV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request)1 SslConfigV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.SslConfigV4Request)1