Search in sources :

Example 1 with RepairValidation

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

the class ClusterRepairService method validateRepair.

public Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> validateRepair(ManualClusterRepairMode repairMode, Long stackId, Set<String> selectedParts, boolean deleteVolumes) {
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    boolean reattach = !deleteVolumes;
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult;
    List<String> stoppedInstanceIds = getStoppedNotSelectedInstanceIds(stack, repairMode, selectedParts);
    if (!freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())) {
        repairStartResult = Result.error(RepairValidation.of("Action cannot be performed because the FreeIPA isn't available. Please check the FreeIPA state."));
    } else if (!environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))) {
        repairStartResult = Result.error(RepairValidation.of("Action cannot be performed because the Environment isn't available. Please check the Environment state."));
    } else if (!stoppedInstanceIds.isEmpty()) {
        repairStartResult = Result.error(RepairValidation.of("Action cannot be performed because there are stopped nodes in the cluster. " + "Stopped nodes: [" + String.join(", ", stoppedInstanceIds) + "]. " + "Please select them for repair or start the stopped nodes."));
    } else if (!isReattachSupportedOnProvider(stack, reattach)) {
        repairStartResult = Result.error(RepairValidation.of(String.format("Volume reattach currently not supported on %s platform!", stack.getPlatformVariant())));
    } else if (hasNotAvailableDatabase(stack)) {
        repairStartResult = Result.error(RepairValidation.of(String.format("Database %s is not in AVAILABLE status, could not start repair.", stack.getCluster().getDatabaseServerCrn())));
    } else if (isHAClusterAndRepairNotAllowed(stack)) {
        repairStartResult = Result.error(RepairValidation.of("Repair is not supported when the cluster uses cluster proxy and has multiple gateway nodes. This will be fixed in future releases."));
    } else if (isAnyGWUnhealthyAndItIsNotSelected(repairMode, selectedParts, stack)) {
        repairStartResult = Result.error(RepairValidation.of("Gateway node is unhealthy, it must be repaired first."));
    } else {
        Map<HostGroupName, Set<InstanceMetaData>> repairableNodes = selectRepairableNodes(getInstanceSelectors(repairMode, selectedParts), stack);
        if (repairableNodes.isEmpty()) {
            repairStartResult = Result.error(RepairValidation.of("Repairable node list is empty. Please check node statuses and try again."));
        } else {
            RepairValidation validationBySelectedNodes = validateSelectedNodes(stack, repairableNodes, reattach);
            if (!validationBySelectedNodes.getValidationErrors().isEmpty()) {
                repairStartResult = Result.error(validationBySelectedNodes);
            } else {
                setStackStatusAndMarkDeletableVolumes(repairMode, deleteVolumes, stack, repairableNodes);
                repairStartResult = Result.success(repairableNodes);
            }
        }
    }
    return repairStartResult;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) HostGroupName(com.sequenceiq.cloudbreak.service.cluster.model.HostGroupName) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with RepairValidation

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

the class ClusterUpgradeAvailabilityService method checkForUpgradesByName.

public UpgradeV4Response checkForUpgradesByName(Stack stack, boolean lockComponents, boolean replaceVms, InternalUpgradeSettings internalUpgradeSettings) {
    UpgradeV4Response upgradeOptions = checkForUpgrades(stack, lockComponents, internalUpgradeSettings);
    upgradeOptions.setReplaceVms(replaceVms);
    if (StringUtils.isEmpty(upgradeOptions.getReason())) {
        if (!stack.getStatus().isAvailable()) {
            upgradeOptions.setReason(String.format("Cannot upgrade cluster because it is in %s state.", stack.getStatus()));
            LOGGER.warn(upgradeOptions.getReason());
        } else if (instanceMetaDataService.anyInstanceStopped(stack.getId())) {
            upgradeOptions.setReason("Cannot upgrade cluster because there is stopped instance.");
            LOGGER.warn(upgradeOptions.getReason());
        } else if (shouldValidateForRepair(lockComponents, replaceVms)) {
            LOGGER.debug("Validate for repair");
            Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> validationResult = clusterRepairService.repairWithDryRun(stack.getId());
            if (validationResult.isError()) {
                upgradeOptions.setReason(String.join(",", validationResult.getError().getValidationErrors()));
                LOGGER.warn(String.format("Cannot upgrade cluster because: %s", upgradeOptions.getReason()));
            }
        }
    }
    return upgradeOptions;
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) Map(java.util.Map)

Example 3 with RepairValidation

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

the class UpgradeServiceTest method upgradeAllowedWhenConnectedDataHubStackAndClusterStoppedOrDeleted.

@Test
public void upgradeAllowedWhenConnectedDataHubStackAndClusterStoppedOrDeleted() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Stack stack = getStack();
    Image image = getImage("id-1");
    setUpMocks(stack, image, true, "id-1", "id-2");
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.success(new HashMap<>());
    when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult);
    StackViewV4Response datahubStack1 = new StackViewV4Response();
    datahubStack1.setStatus(Status.STOPPED);
    ClusterViewV4Response datahubCluster1 = new ClusterViewV4Response();
    datahubCluster1.setStatus(Status.STOPPED);
    datahubStack1.setCluster(datahubCluster1);
    StackViewV4Response datahubStack2 = new StackViewV4Response();
    datahubStack2.setStatus(Status.DELETE_COMPLETED);
    ClusterViewV4Response datahubCluster2 = new ClusterViewV4Response();
    datahubCluster2.setStatus(Status.DELETE_COMPLETED);
    datahubStack2.setCluster(datahubCluster2);
    StackViewV4Response datahubStack3 = new StackViewV4Response();
    datahubStack3.setStatus(Status.STOPPED);
    when(distroXV1Endpoint.list(any(), anyString())).thenReturn(new StackViewV4Responses(Set.of(datahubStack1, datahubStack2, datahubStack3)));
    when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack);
    UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user);
    verify(clusterRepairService).repairWithDryRun(eq(stack.getId()));
    verify(distroXV1Endpoint).list(eq(null), eq("env-crn"));
    verify(componentConfigProviderService).getImage(1L);
    verify(imageService).determineImageFromCatalog(eq(WORKSPACE_ID), captor.capture(), eq("aws"), eq("AWS"), eq(stack.getCluster().getBlueprint()), eq(false), eq(false), eq(user), any());
    assertThat(result.getUpgrade().getImageName()).isEqualTo("id-2");
    assertThat(result.getReason()).isEqualTo(null);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) ClusterViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.views.ClusterViewV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) Map(java.util.Map) HashMap(java.util.HashMap) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with RepairValidation

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

the class UpgradeServiceTest method shouldNotAllowUpgradeIfDryRunFails.

@Test
public void shouldNotAllowUpgradeIfDryRunFails() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Stack stack = getStack();
    Image image = getImage("id-1");
    when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack);
    when(componentConfigProviderService.getImage(anyLong())).thenReturn(image);
    StatedImage currentImageFromCatalog = imageFromCatalog(true, image.getImageId());
    when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(currentImageFromCatalog);
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.error(RepairValidation.of(List.of("Repair cannot be performed because there is an active flow running.", "No external Database")));
    when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult);
    UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user);
    verify(clusterRepairService).repairWithDryRun(eq(stack.getId()));
    verifyNoMoreInteractions(distroXV1Endpoint);
    verifyNoMoreInteractions(componentConfigProviderService);
    verifyNoMoreInteractions(imageService);
    assertThat(result.getUpgrade()).isEqualTo(null);
    assertThat(result.getReason()).isEqualTo("Repair cannot be performed because there is an active flow running.; No external Database");
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) HashMap(java.util.HashMap) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with RepairValidation

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

the class ClusterRepairServiceTest method testValidateRepairWhenOneGWUnhealthyAndNotSelected.

@Test
public void testValidateRepairWhenOneGWUnhealthyAndNotSelected() {
    when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
    when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
    when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
    InstanceMetaData primaryGW = new InstanceMetaData();
    primaryGW.setInstanceStatus(InstanceStatus.DELETED_ON_PROVIDER_SIDE);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName("gateway");
    primaryGW.setInstanceGroup(instanceGroup);
    InstanceMetaData secondaryGW = new InstanceMetaData();
    secondaryGW.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    secondaryGW.setInstanceGroup(instanceGroup);
    ArrayList<InstanceMetaData> gatewayInstances = new ArrayList<>();
    gatewayInstances.add(primaryGW);
    gatewayInstances.add(secondaryGW);
    when(stack.getNotTerminatedGatewayInstanceMetadata()).thenReturn(gatewayInstances);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> actual = underTest.validateRepair(ManualClusterRepairMode.HOST_GROUP, STACK_ID, Set.of("idbroker"), false);
        assertEquals(1, actual.getError().getValidationErrors().size());
        assertEquals("Gateway node is unhealthy, it must be repaired first.", actual.getError().getValidationErrors().get(0));
    });
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) ArrayList(java.util.ArrayList) Map(java.util.Map) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 RepairValidation (com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation)16 Map (java.util.Map)16 Test (org.junit.jupiter.api.Test)12 HashMap (java.util.HashMap)9 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)8 UpgradeOptionV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response)7 Image (com.sequenceiq.cloudbreak.cloud.model.Image)7 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)7 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)5 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)3 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)3 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)3 ArrayList (java.util.ArrayList)3 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)2 ClusterViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.views.ClusterViewV4Response)2 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)1 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)1 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)1 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1