Search in sources :

Example 1 with ClusterManagerCommand

use of com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand in project cloudbreak by hortonworks.

the class ClusterUpgradeExistingUpgradeCommandValidationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeExistingUpgradeCommandValidationEvent> event) {
    LOGGER.debug("Accepting Cluster upgrade existing upgradeCDH command validation event.");
    ClusterUpgradeExistingUpgradeCommandValidationEvent request = event.getData();
    Image targetImage = request.getImage();
    Long stackId = request.getResourceId();
    Stack stack = getStack(stackId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    Optional<ClusterManagerCommand> optionalUpgradeCommand = connector.clusterStatusService().findCommand(stack, ClusterCommandType.UPGRADE_CLUSTER);
    if (optionalUpgradeCommand.isEmpty()) {
        LOGGER.debug("There is no existing upgradeCDH command, validation passed successfully");
        return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
    } else {
        ClusterManagerCommand upgradeCommand = optionalUpgradeCommand.get();
        if (upgradeCommand.getActive() || (!upgradeCommand.getSuccess() && upgradeCommand.getRetryable())) {
            return validateIfExistingRuntimeMatchesTargetRuntime(stack, connector, targetImage);
        } else {
            LOGGER.debug("There is no retryable upgradeCDH command, validation passed successfully");
            return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
        }
    }
}
Also used : ClusterUpgradeExistingUpgradeCommandValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationEvent) ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with ClusterManagerCommand

use of com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand in project cloudbreak by hortonworks.

the class ClouderaManagerClusterStatusService method convertApiCommand.

private ClusterManagerCommand convertApiCommand(ApiCommand apiCommand) {
    if (Objects.isNull(apiCommand)) {
        return null;
    }
    ClusterManagerCommand command = new ClusterManagerCommand();
    command.setId(apiCommand.getId());
    command.setName(apiCommand.getName());
    command.setSuccess(apiCommand.getSuccess());
    command.setActive(apiCommand.getActive());
    command.setRetryable(apiCommand.getCanRetry());
    command.setEndTime(apiCommand.getEndTime());
    command.setResultMessage(apiCommand.getResultMessage());
    command.setStartTime(apiCommand.getStartTime());
    return command;
}
Also used : ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand)

Example 3 with ClusterManagerCommand

use of com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand in project cloudbreak by hortonworks.

the class ClusterUpgradeExistingUpgradeCommandValidationHandlerTest method testUpgradeCommandNotActiveNotSuccessfulRetryableAndEmptyactiveRuntimeParcelVersionThenValidationShouldPass.

@Test
public void testUpgradeCommandNotActiveNotSuccessfulRetryableAndEmptyactiveRuntimeParcelVersionThenValidationShouldPass() {
    ClusterManagerCommand command = new ClusterManagerCommand();
    command.setActive(false);
    command.setSuccess(false);
    command.setRetryable(true);
    when(clusterStatusService.findCommand(stack, ClusterCommandType.UPGRADE_CLUSTER)).thenReturn(Optional.of(command));
    Map<String, String> parcelNameToVersionMap = Map.of();
    when(connector.gatherInstalledParcels(STACK_NAME)).thenReturn(parcelNameToVersionMap);
    Selectable nextFlowStepSelector = underTest.doAccept(getHandlerEvent());
    assertEquals(FINISH_CLUSTER_UPGRADE_EXISTING_UPGRADE_COMMAND_VALIDATION_EVENT.selector(), nextFlowStepSelector.selector());
}
Also used : ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Test(org.junit.Test)

Example 4 with ClusterManagerCommand

use of com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand in project cloudbreak by hortonworks.

the class ClusterUpgradeExistingUpgradeCommandValidationHandlerTest method testUpgradeCommandNotActiveSuccessfulNotRetryableThenValidationShouldPass.

@Test
public void testUpgradeCommandNotActiveSuccessfulNotRetryableThenValidationShouldPass() {
    ClusterManagerCommand command = new ClusterManagerCommand();
    command.setActive(false);
    command.setSuccess(true);
    command.setRetryable(false);
    when(clusterStatusService.findCommand(stack, ClusterCommandType.UPGRADE_CLUSTER)).thenReturn(Optional.of(command));
    Selectable nextFlowStepSelector = underTest.doAccept(getHandlerEvent());
    assertEquals(FINISH_CLUSTER_UPGRADE_EXISTING_UPGRADE_COMMAND_VALIDATION_EVENT.selector(), nextFlowStepSelector.selector());
}
Also used : ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Test(org.junit.Test)

Example 5 with ClusterManagerCommand

use of com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand in project cloudbreak by hortonworks.

the class ClusterUpgradeExistingUpgradeCommandValidationHandlerTest method testUpgradeCommandNotActiveNotSuccessfulRetryableAndActiveRuntimeParcelVersionAndTargetBuildNotMatchThenValidationShouldFail.

@Test
public void testUpgradeCommandNotActiveNotSuccessfulRetryableAndActiveRuntimeParcelVersionAndTargetBuildNotMatchThenValidationShouldFail() {
    ClusterManagerCommand command = new ClusterManagerCommand();
    command.setActive(false);
    command.setSuccess(false);
    command.setRetryable(true);
    when(clusterStatusService.findCommand(stack, ClusterCommandType.UPGRADE_CLUSTER)).thenReturn(Optional.of(command));
    Map<String, String> parcelNameToVersionMap = Map.of(CDH, "7.2.7-1.cdh7.2.7.p7.12569826");
    when(connector.gatherInstalledParcels(STACK_NAME)).thenReturn(parcelNameToVersionMap);
    Selectable nextFlowStepSelector = underTest.doAccept(getHandlerEvent("23569826"));
    assertEquals(FAILED_CLUSTER_UPGRADE_VALIDATION_EVENT.selector(), nextFlowStepSelector.selector());
    String expectedMessage = "Existing upgrade command found for active runtime 7.2.7-1.cdh7.2.7.p7.12569826, upgrading to a different runtime version " + "(7.2.7-23569826) is not allowed! Possible solutions: " + "#1, retry the upgrade with the same target runtime. " + "#2, complete the upgrade manually in Cloudera Manager. " + "#3, recover the cluster";
    assertEquals(expectedMessage, ((ClusterUpgradeValidationFailureEvent) nextFlowStepSelector).getException().getMessage());
}
Also used : ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent) Test(org.junit.Test)

Aggregations

ClusterManagerCommand (com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand)7 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)5 Test (org.junit.Test)5 Image (com.sequenceiq.cloudbreak.cloud.model.Image)1 ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)1 ClusterUpgradeExistingUpgradeCommandValidationEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationEvent)1 ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent)1 ClusterUpgradeValidationFailureEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1