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;
}
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;
}
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);
}
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");
}
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));
});
}
Aggregations