Search in sources :

Example 1 with UpgradeCcmFailedEvent

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

the class UpgradeCcmOnFreeIpaHandlerTest method testFreeIpaMissingAvailabilityStatus.

@ParameterizedTest
@EnumSource(Status.class)
void testFreeIpaMissingAvailabilityStatus(Status status) {
    DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
    freeipa.setStatus(status);
    freeipa.setAvailabilityStatus(null);
    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 2 with UpgradeCcmFailedEvent

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

the class UpgradeCcmActionsTest method failureAction.

@Test
void failureAction() {
    EnvironmentDto environmentDto = mock(EnvironmentDto.class);
    IllegalStateException failureException = new IllegalStateException(MESSAGE);
    UpgradeCcmFailedEvent failedActionPayload = new UpgradeCcmFailedEvent(environmentDto, failureException, EnvironmentStatus.UPGRADE_CCM_FAILED);
    when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(failedActionPayload);
    testUpgradeActionHappyPath(underTest::failedAction, HANDLED_FAILED_UPGRADE_CCM_EVENT.selector());
    verify(environmentStatusUpdateService).updateFailedEnvironmentStatusAndNotify(any(), any(), eq(EnvironmentStatus.UPGRADE_CCM_FAILED), eq(ResourceEvent.ENVIRONMENT_UPGRADE_CCM_FAILED), any());
    verify(metricService).incrementMetricCounter(eq(MetricType.ENV_UPGRADE_CCM_FAILED), (EnvironmentDto) any(), eq(failureException));
}
Also used : UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Test(org.junit.jupiter.api.Test)

Example 3 with UpgradeCcmFailedEvent

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

the class UpgradeCcmOnDatahubHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("In UpgradeCcmOnDatahubHandler.accept");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        // TODO action here
        UpgradeCcmEvent upgradeCcmEvent = UpgradeCcmEvent.builder().withSelector(UpgradeCcmStateSelectors.FINISH_UPGRADE_CCM_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(upgradeCcmEvent, environmentDtoEvent.getHeaders());
        LOGGER.debug("FINISH_UPGRADE_CCM_EVENT event sent");
    } catch (Exception e) {
        UpgradeCcmFailedEvent failedEvent = new UpgradeCcmFailedEvent(environmentDto, e, EnvironmentStatus.UPGRADE_CCM_ON_DATAHUB_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
        LOGGER.debug("UPGRADE_CCM_ON_DATAHUB_FAILED event sent");
    }
}
Also used : UpgradeCcmEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto)

Example 4 with UpgradeCcmFailedEvent

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

the class UpgradeCcmOnFreeIpaHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("In UpgradeCcmOnFreeIpaHandler.accept");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        freeIpaService.describe(environmentDto.getResourceCrn()).ifPresentOrElse(freeIpa -> {
            if (freeIpa.getStatus() == null || freeIpa.getAvailabilityStatus() == null) {
                throw new FreeIpaOperationFailedException("FreeIPA status is unpredictable, upgrading of Cluster Connectivity Manager will be interrupted.");
            } else if (!freeIpa.getStatus().isCcmUpgradeablePhase()) {
                throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to upgrade Cluster Connectivity Manager. Current state is: " + freeIpa.getStatus().name());
            } else {
                LOGGER.info("CCM on FreeIPA will be upgraded.");
                freeIpaPollerService.waitForCcmUpgrade(environmentDto.getId(), environmentDto.getResourceCrn());
            }
            UpgradeCcmEvent upgradeCcmEvent = UpgradeCcmEvent.builder().withSelector(UpgradeCcmStateSelectors.UPGRADE_CCM_TUNNEL_UPDATE_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
            eventSender().sendEvent(upgradeCcmEvent, environmentDtoEvent.getHeaders());
            LOGGER.debug("UPGRADE_CCM_TUNNEL_UPDATE_EVENT event sent");
        }, () -> {
            throw new FreeIpaOperationFailedException(String.format("FreeIPA cannot be found for environment %s", environmentDto.getName()));
        });
    } catch (Exception e) {
        UpgradeCcmFailedEvent failedEvent = new UpgradeCcmFailedEvent(environmentDto, e, EnvironmentStatus.UPGRADE_CCM_ON_FREEIPA_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
        LOGGER.debug("UPGRADE_CCM_ON_FREEIPA_FAILED event sent");
    }
}
Also used : UpgradeCcmEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException)

Example 5 with UpgradeCcmFailedEvent

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

the class ValidateUpgradeCcmHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("In ValidateUpgradeCcmHandler.accept");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        UpgradeCcmEvent upgradeCcmEvent = UpgradeCcmEvent.builder().withSelector(UpgradeCcmStateSelectors.UPGRADE_CCM_FREEIPA_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(upgradeCcmEvent, environmentDtoEvent.getHeaders());
        LOGGER.debug("UPGRADE_CCM_FREEIPA_EVENT event sent");
    } catch (Exception e) {
        UpgradeCcmFailedEvent failedEvent = new UpgradeCcmFailedEvent(environmentDto, e, EnvironmentStatus.UPGRADE_CCM_VALIDATION_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
        LOGGER.debug("UPGRADE_CCM_VALIDATION_FAILED event sent");
    }
}
Also used : UpgradeCcmEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto)

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