Search in sources :

Example 6 with SdxCcmUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse in project cloudbreak by hortonworks.

the class UpgradeCcmOnDatalakeHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("In UpgradeCcmOnDatalakeHandler.accept");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        LOGGER.debug("Calling Upgrade CCM endpoint on data lake service");
        SdxCcmUpgradeResponse ccmUpgradeResponse = sdxService.upgradeCcm(environmentDto.getResourceCrn());
        switch(ccmUpgradeResponse.getResponseType()) {
            case ERROR:
                String message = String.format("Upgrade CCM returned with reason: %s", ccmUpgradeResponse.getReason());
                LOGGER.warn(message);
                sendFailedEvent(environmentDtoEvent, environmentDto, new OperationException(message));
                return;
            case TRIGGERED:
                LOGGER.debug("Waiting for data lake Upgrade CCM flow to finish.");
                pollerService.waitForUpgradeCcm(environmentDto.getId(), ccmUpgradeResponse.getResourceCrn());
                break;
            case SKIP:
                LOGGER.debug("Upgrade CCM is skipped due to {}", ccmUpgradeResponse.getReason());
                break;
            default:
                message = String.format("Unknown response type: %s", ccmUpgradeResponse.getResponseType());
                LOGGER.warn(message);
                sendFailedEvent(environmentDtoEvent, environmentDto, new OperationException(message));
                return;
        }
        UpgradeCcmEvent upgradeCcmEvent = UpgradeCcmEvent.builder().withSelector(UpgradeCcmStateSelectors.UPGRADE_CCM_DATAHUB_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(upgradeCcmEvent, environmentDtoEvent.getHeaders());
        LOGGER.debug("UPGRADE_CCM_DATAHUB_EVENT event sent");
    } catch (Exception e) {
        sendFailedEvent(environmentDtoEvent, environmentDto, e);
    }
}
Also used : SdxCcmUpgradeResponse(com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse) UpgradeCcmEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) OperationException(com.sequenceiq.cloudbreak.service.OperationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 7 with SdxCcmUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse in project cloudbreak by hortonworks.

the class SdxUpgradeControllerTest method testUpgradeCcm.

@Test
void testUpgradeCcm() {
    SdxCcmUpgradeResponse response = new SdxCcmUpgradeResponse(CcmUpgradeResponseType.TRIGGERED, new FlowIdentifier(FlowType.FLOW, "FlowId"), "OK", "crn");
    when(sdxCcmUpgradeService.upgradeCcm(ENV_CRN)).thenReturn(response);
    SdxCcmUpgradeResponse sdxCcmUpgradeResponse = underTest.upgradeCcm(ENV_CRN, USER_CRN);
    assertThat(sdxCcmUpgradeResponse).isEqualTo(response);
}
Also used : SdxCcmUpgradeResponse(com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 8 with SdxCcmUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse in project cloudbreak by hortonworks.

the class SdxCcmUpgradeService method triggerCcmUpgradeFlow.

private SdxCcmUpgradeResponse triggerCcmUpgradeFlow(SdxCluster cluster) {
    MDCBuilder.buildMdcContext(cluster);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerCcmUpgradeFlow(cluster);
    return new SdxCcmUpgradeResponse(CcmUpgradeResponseType.TRIGGERED, flowIdentifier, getMessage(DATALAKE_UPGRADE_CCM, null), cluster.getResourceCrn());
}
Also used : SdxCcmUpgradeResponse(com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 9 with SdxCcmUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse in project cloudbreak by hortonworks.

the class SdxCcmUpgradeServiceTest method testTriggerUpgrade.

@Test
void testTriggerUpgrade() {
    SdxCluster sdxCluster = getSdxCluster();
    when(sdxService.listSdxByEnvCrn(anyString())).thenReturn(List.of(sdxCluster));
    when(sdxService.getAccountIdFromCrn(any())).thenReturn(ACCOUNT_ID);
    when(sdxService.getDetail(CLUSTER_NAME, null, ACCOUNT_ID)).thenReturn(getStack(Tunnel.CCM, Status.AVAILABLE));
    when(messagesService.getMessage(any(), any())).thenReturn("success");
    FlowIdentifier flowId = new FlowIdentifier(FlowType.FLOW, "flowId");
    when(sdxReactorFlowManager.triggerCcmUpgradeFlow(sdxCluster)).thenReturn(flowId);
    SdxCcmUpgradeResponse response = underTest.upgradeCcm(ENV_CRN);
    assertThat(response.getReason()).isEqualTo("success");
    assertThat(response.getFlowIdentifier()).isEqualTo(flowId);
}
Also used : SdxCcmUpgradeResponse(com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with SdxCcmUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse in project cloudbreak by hortonworks.

the class SdxCcmUpgradeServiceTest method testNotUpgradable.

@ParameterizedTest
@EnumSource(value = Tunnel.class, names = { "DIRECT", "CLUSTER_PROXY" }, mode = Mode.INCLUDE)
void testNotUpgradable(Tunnel tunnel) {
    SdxCluster sdxCluster = getSdxCluster();
    when(sdxService.listSdxByEnvCrn(anyString())).thenReturn(List.of(sdxCluster));
    when(sdxService.getAccountIdFromCrn(any())).thenReturn(ACCOUNT_ID);
    when(sdxService.getDetail(CLUSTER_NAME, null, ACCOUNT_ID)).thenReturn(getStack(tunnel, Status.AVAILABLE));
    when(messagesService.getMessage(any())).thenReturn("not upgradeable");
    SdxCcmUpgradeResponse response = underTest.upgradeCcm(ENV_CRN);
    assertThat(response.getReason()).isEqualTo("not upgradeable");
    assertThat(response.getFlowIdentifier()).isEqualTo(FlowIdentifier.notTriggered());
}
Also used : SdxCcmUpgradeResponse(com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SdxCcmUpgradeResponse (com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse)11 Test (org.junit.jupiter.api.Test)8 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)4 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)3 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 UpgradeCcmFailedEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1