Search in sources :

Example 16 with SdxStatusEntity

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

the class SdxStatusService method updateInMemoryStateStore.

public void updateInMemoryStateStore(SdxCluster sdxCluster) {
    SdxStatusEntity actualStatusForSdx = getActualStatusForSdx(sdxCluster);
    if (actualStatusForSdx != null && (actualStatusForSdx.getStatus().isDeleteInProgressOrCompleted() || DELETED_ON_PROVIDER_SIDE.equals(actualStatusForSdx.getStatus()))) {
        DatalakeInMemoryStateStore.put(sdxCluster.getId(), PollGroup.CANCELLED);
        LOGGER.info("Update {} datalake status in inmemory store to {}", sdxCluster.getClusterName(), PollGroup.CANCELLED.name());
    } else {
        DatalakeInMemoryStateStore.put(sdxCluster.getId(), PollGroup.POLLABLE);
        LOGGER.info("Update {} datalake status in inmemory store to {}", sdxCluster.getClusterName(), PollGroup.POLLABLE.name());
    }
}
Also used : SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity)

Example 17 with SdxStatusEntity

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

the class SdxStatusService method createStatusEntity.

private SdxStatusEntity createStatusEntity(DatalakeStatusEnum status, String statusReason, SdxCluster sdxCluster) {
    SdxStatusEntity sdxStatusEntity = new SdxStatusEntity();
    sdxStatusEntity.setCreated(new Date().getTime());
    sdxStatusEntity.setStatus(status);
    sdxStatusEntity.setStatusReason(statusReason);
    sdxStatusEntity.setDatalake(sdxCluster);
    return sdxStatusEntity;
}
Also used : SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) Date(java.util.Date)

Example 18 with SdxStatusEntity

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

the class SdxStatusService method setStatusForDatalake.

public void setStatusForDatalake(DatalakeStatusEnum status, String statusReason, SdxCluster sdxCluster) {
    try {
        transactionService.required(() -> {
            SdxStatusEntity previous = getActualStatusForSdx(sdxCluster);
            if (statusChangeIsValid(previous, status)) {
                SdxStatusEntity sdxStatusEntity = createStatusEntity(status, statusReason, sdxCluster);
                if (DELETED.equals(status)) {
                    setDeletedTime(sdxCluster);
                }
                sdxStatusRepository.save(sdxStatusEntity);
                updateInMemoryStateStore(sdxCluster);
                LOGGER.info("Updated status of Datalake with name: {} from {} to {} with statusReason {}", sdxCluster.getClusterName(), getPreviousStatusText(previous), status, statusReason);
            } else if (DELETED.equals(previous.getStatus())) {
                if (sdxCluster.getDeleted() == null) {
                    setDeletedTime(sdxCluster);
                } else {
                    throw notFoundException("SDX cluster", sdxCluster.getClusterName());
                }
            } else {
                throw new DatalakeStatusUpdateException(getActualStatusForSdx(sdxCluster).getStatus(), status);
            }
        });
    } catch (TransactionService.TransactionExecutionException e) {
        LOGGER.error("Exception happened while transaction was executed", e);
        throw e.getCause();
    }
}
Also used : TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity)

Example 19 with SdxStatusEntity

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

the class SdxControllerTest method createTest.

@Test
void createTest() {
    SdxCluster sdxCluster = getValidSdxCluster();
    when(sdxService.createSdx(anyString(), anyString(), any(SdxClusterRequest.class), nullable(StackV4Request.class))).thenReturn(Pair.of(sdxCluster, new FlowIdentifier(FlowType.FLOW, "FLOW_ID")));
    SdxClusterRequest createSdxClusterRequest = new SdxClusterRequest();
    createSdxClusterRequest.setClusterShape(SdxClusterShape.MEDIUM_DUTY_HA);
    createSdxClusterRequest.setEnvironment("test-env");
    Map<String, String> tags = new HashMap<>();
    tags.put("tag1", "value1");
    createSdxClusterRequest.addTags(tags);
    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.create(SDX_CLUSTER_NAME, createSdxClusterRequest));
    verify(sdxService).createSdx(eq(USER_CRN), eq(SDX_CLUSTER_NAME), eq(createSdxClusterRequest), nullable(StackV4Request.class));
    verify(sdxStatusService, times(1)).getActualStatusForSdx(sdxCluster);
    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 : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) HashMap(java.util.HashMap) SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) Test(org.junit.jupiter.api.Test)

Example 20 with SdxStatusEntity

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

the class RangerCloudIdentityService method isDatalakeRunning.

private boolean isDatalakeRunning(SdxCluster sdxCluster) {
    SdxStatusEntity sdxStatusEntity = sdxStatusService.getActualStatusForSdx(sdxCluster);
    LOGGER.debug("SDX status = {}", sdxStatusEntity.getStatus());
    return sdxStatusEntity.getStatus().equals(DatalakeStatusEnum.RUNNING);
}
Also used : SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity)

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