Search in sources :

Example 6 with UpgradeCcmFailedEvent

use of com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent in project cloudbreak by hortonworks.

the class UpgradeCcmOnDatalakeHandlerTest method testAcceptWhenUpgradeError.

@Test
void testAcceptWhenUpgradeError() {
    SdxCcmUpgradeResponse response = new SdxCcmUpgradeResponse(CcmUpgradeResponseType.ERROR, new FlowIdentifier(FlowType.FLOW, "flowId"), "reason", "datalakeCrn");
    when(sdxService.upgradeCcm(TEST_ENV_CRN)).thenReturn(response);
    underTest.accept(mockEnvironmentDtoEvent);
    verify(sdxUpgradeCcmPollerService, never()).waitForUpgradeCcm(any(), any());
    UpgradeCcmFailedEvent capturedUpgradeCcmEvent = (UpgradeCcmFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedUpgradeCcmEvent.getResourceName()).isEqualTo(TEST_ENV_NAME);
    assertThat(capturedUpgradeCcmEvent.getResourceId()).isEqualTo(TEST_ENV_ID);
    assertThat(capturedUpgradeCcmEvent.getResourceCrn()).isEqualTo(TEST_ENV_CRN);
    assertThat(capturedUpgradeCcmEvent.selector()).isEqualTo("FAILED_UPGRADE_CCM_EVENT");
    assertThat(capturedUpgradeCcmEvent.getEnvironmentStatus()).isEqualTo(UPGRADE_CCM_ON_DATALAKE_FAILED);
}
Also used : SdxCcmUpgradeResponse(com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 7 with UpgradeCcmFailedEvent

use of com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent in project cloudbreak by hortonworks.

the class UpgradeCcmOnFreeIpaHandlerTest method testFreeIpaWrongStatuses.

@ParameterizedTest
@EnumSource(value = Status.class, names = { "AVAILABLE", "UPGRADE_CCM_FAILED" }, mode = EnumSource.Mode.EXCLUDE)
void testFreeIpaWrongStatuses(Status status) {
    DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
    freeipa.setStatus(status);
    freeipa.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
    Optional<DescribeFreeIpaResponse> freeipaOpt = Optional.of(freeipa);
    when(freeIpaService.describe(any())).thenReturn(freeipaOpt);
    underTest.accept(mockEnvironmentDtoEvent);
    verify(freeIpaPollerService, never()).waitForCcmUpgrade(any(), any());
    UpgradeCcmFailedEvent capturedUpgradeCcmEvent = (UpgradeCcmFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedUpgradeCcmEvent.getResourceName()).isEqualTo(TEST_ENV_NAME);
    assertThat(capturedUpgradeCcmEvent.getResourceId()).isEqualTo(TEST_ENV_ID);
    assertThat(capturedUpgradeCcmEvent.getResourceCrn()).isEqualTo(TEST_ENV_CRN);
    assertThat(capturedUpgradeCcmEvent.selector()).isEqualTo("FAILED_UPGRADE_CCM_EVENT");
    assertThat(capturedUpgradeCcmEvent.getEnvironmentStatus()).isEqualTo(UPGRADE_CCM_ON_FREEIPA_FAILED);
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with UpgradeCcmFailedEvent

use of com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent in project cloudbreak by hortonworks.

the class UpgradeCcmOnFreeIpaHandlerTest method testFreeIpaDoesNotExist.

@Test
void testFreeIpaDoesNotExist() {
    when(freeIpaService.describe(any())).thenReturn(Optional.empty());
    underTest.accept(mockEnvironmentDtoEvent);
    verify(freeIpaPollerService, never()).waitForCcmUpgrade(any(), any());
    UpgradeCcmFailedEvent capturedUpgradeCcmEvent = (UpgradeCcmFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedUpgradeCcmEvent.getResourceName()).isEqualTo(TEST_ENV_NAME);
    assertThat(capturedUpgradeCcmEvent.getResourceId()).isEqualTo(TEST_ENV_ID);
    assertThat(capturedUpgradeCcmEvent.getResourceCrn()).isEqualTo(TEST_ENV_CRN);
    assertThat(capturedUpgradeCcmEvent.selector()).isEqualTo("FAILED_UPGRADE_CCM_EVENT");
    assertThat(capturedUpgradeCcmEvent.getEnvironmentStatus()).isEqualTo(UPGRADE_CCM_ON_FREEIPA_FAILED);
}
Also used : UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with UpgradeCcmFailedEvent

use of com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent in project cloudbreak by hortonworks.

the class UpgradeCcmTunnelUpdateHandlerTest method acceptFailure.

@Test
void acceptFailure() {
    when(environmentService.updateTunnelByEnvironmentId(any(), any())).thenThrow(new RuntimeException("internal error"));
    underTest.accept(mockEnvironmentDtoEvent);
    verify(environmentService).updateTunnelByEnvironmentId(TEST_ENV_ID, Tunnel.latestUpgradeTarget());
    UpgradeCcmFailedEvent capturedUpgradeCcmEvent = (UpgradeCcmFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedUpgradeCcmEvent.getResourceName()).isEqualTo(TEST_ENV_NAME);
    assertThat(capturedUpgradeCcmEvent.getResourceId()).isEqualTo(TEST_ENV_ID);
    assertThat(capturedUpgradeCcmEvent.getResourceCrn()).isEqualTo(TEST_ENV_CRN);
    assertThat(capturedUpgradeCcmEvent.selector()).isEqualTo("FAILED_UPGRADE_CCM_EVENT");
    assertThat(capturedUpgradeCcmEvent.getEnvironmentStatus()).isEqualTo(UPGRADE_CCM_TUNNEL_UPDATE_FAILED);
}
Also used : UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) Test(org.junit.jupiter.api.Test)

Example 10 with UpgradeCcmFailedEvent

use of com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent in project cloudbreak by hortonworks.

the class UpgradeCcmActions method failedAction.

@Bean(name = "UPGRADE_CCM_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractUpgradeCcmAction<>(UpgradeCcmFailedEvent.class) {

        @Override
        protected void doExecute(CommonContext context, UpgradeCcmFailedEvent payload, Map<Object, Object> variables) {
            LOGGER.error(String.format("Failed to upgrade CCM in environment '%s'. Status: '%s'.", payload.getEnvironmentDto(), payload.getEnvironmentStatus()), payload.getException());
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateFailedEnvironmentStatusAndNotify(context, payload, payload.getEnvironmentStatus(), convertStatus(payload.getEnvironmentStatus()), UpgradeCcmState.UPGRADE_CCM_FAILED_STATE);
            metricService.incrementMetricCounter(MetricType.ENV_UPGRADE_CCM_FAILED, environmentDto, payload.getException());
            sendEvent(context, HANDLED_FAILED_UPGRADE_CCM_EVENT.event(), payload);
        }

        private ResourceEvent convertStatus(EnvironmentStatus status) {
            switch(status) {
                case UPGRADE_CCM_VALIDATION_FAILED:
                    return ResourceEvent.ENVIRONMENT_UPGRADE_CCM_VALIDATION_FAILED;
                case UPGRADE_CCM_TUNNEL_UPDATE_FAILED:
                    return ResourceEvent.ENVIRONMENT_UPGRADE_CCM_TUNNEL_UPDATE_FAILED;
                case UPGRADE_CCM_ON_FREEIPA_FAILED:
                    return ResourceEvent.ENVIRONMENT_UPGRADE_CCM_ON_FREEIPA_FAILED;
                case UPGRADE_CCM_ON_DATALAKE_FAILED:
                    return ResourceEvent.ENVIRONMENT_UPGRADE_CCM_ON_DATALAKE_FAILED;
                case UPGRADE_CCM_ON_DATAHUB_FAILED:
                    return ResourceEvent.ENVIRONMENT_UPGRADE_CCM_ON_DATAHUB_FAILED;
                default:
                    return ResourceEvent.ENVIRONMENT_UPGRADE_CCM_FAILED;
            }
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

UpgradeCcmFailedEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent)12 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)6 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)1 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)1 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1 CommonContext (com.sequenceiq.flow.core.CommonContext)1 SdxCcmUpgradeResponse (com.sequenceiq.sdx.api.model.SdxCcmUpgradeResponse)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1