use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method testCannotRepairBaseImageGateway.
@Test
public void testCannotRepairBaseImageGateway() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("hostGroup1");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_HEALTHY, InstanceGroupType.GATEWAY);
hostGroup1.setInstanceGroup(host1.getInstanceGroup());
when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(componentConfigProviderService.getImage(stack.getId())).thenReturn(mock(Image.class));
com.sequenceiq.cloudbreak.cloud.model.catalog.Image image = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
when(image.isPrewarmed()).thenReturn(false);
when(imageCatalogService.getImage(any(), any(), any())).thenReturn(StatedImage.statedImage(image, "catalogUrl", "catalogName"));
when(clusterDBValidationService.isGatewayRepairEnabled(cluster)).thenReturn(true);
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
Result result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairWithDryRun(stack.getId()));
assertFalse(result.isSuccess());
verifyNoInteractions(stackUpdater, flowManager, resourceService);
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method repairValidationShouldFailWhenStackUsesCCMAndHasMultipleGatewayInstances.
@Test
public void repairValidationShouldFailWhenStackUsesCCMAndHasMultipleGatewayInstances() {
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("hostGroup1");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_UNHEALTHY, InstanceGroupType.GATEWAY);
InstanceMetaData host2 = getHost("host2", hostGroup1.getName(), InstanceStatus.SERVICES_UNHEALTHY, InstanceGroupType.GATEWAY);
host2.setInstanceGroup(host1.getInstanceGroup());
host1.getInstanceGroup().getAllInstanceMetaData().add(host2);
hostGroup1.setInstanceGroup(host1.getInstanceGroup());
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(stack.getInstanceMetaDataAsList()).thenReturn(List.of(host1));
when(stack.getInstanceGroups()).thenReturn(Set.of(host1.getInstanceGroup()));
when(stack.getTunnel()).thenReturn(Tunnel.CLUSTER_PROXY);
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
BadRequestException exception = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairHostGroups(1L, Set.of("hostGroup1"), false)));
assertEquals("Repair is not supported when the cluster uses cluster proxy and has multiple gateway nodes. This will be fixed in future releases.", exception.getMessage());
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method shouldNotUpdateStackStateWhenThereAreNoNodesToRepair.
@Test
public void shouldNotUpdateStackStateWhenThereAreNoNodesToRepair() {
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("hostGroup1");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_HEALTHY, InstanceGroupType.CORE);
hostGroup1.setInstanceGroup(host1.getInstanceGroup());
when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(stack.getInstanceMetaDataAsList()).thenReturn(List.of(host1));
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
BadRequestException exception = assertThrows(BadRequestException.class, () -> {
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairHostGroups(1L, Set.of("hostGroup1"), false));
});
assertEquals("Repairable node list is empty. Please check node statuses and try again.", exception.getMessage());
verifyEventArguments(CLUSTER_MANUALRECOVERY_COULD_NOT_START, "Repairable node list is empty. Please check node statuses and try again.");
verifyNoInteractions(stackUpdater);
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method shouldNotAllowRepairWhenNodeIsStoppedInNotSelectedInstanceGroup.
@Test
public void shouldNotAllowRepairWhenNodeIsStoppedInNotSelectedInstanceGroup() {
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("hostGroup1");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_UNHEALTHY, InstanceGroupType.CORE);
hostGroup1.setInstanceGroup(host1.getInstanceGroup());
HostGroup hostGroup2 = new HostGroup();
hostGroup2.setName("hostGroup2");
hostGroup2.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host2 = getHost("host2", hostGroup2.getName(), InstanceStatus.STOPPED, InstanceGroupType.CORE);
hostGroup2.setInstanceGroup(host2.getInstanceGroup());
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(stack.getInstanceMetaDataAsList()).thenReturn(List.of(host1, host2));
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
BadRequestException exception = assertThrows(BadRequestException.class, () -> {
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairHostGroups(1L, Set.of("hostGroup1"), false));
});
String expectedErrorMessage = "Action cannot be performed because there are stopped nodes in the cluster. " + "Stopped nodes: [host2]. " + "Please select them for repair or start the stopped nodes.";
assertEquals(expectedErrorMessage, exception.getMessage());
verifyEventArguments(CLUSTER_MANUALRECOVERY_COULD_NOT_START, expectedErrorMessage);
verifyNoInteractions(stackUpdater);
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method testValidateRepairWhenReattachSupported.
@Test
public void testValidateRepairWhenReattachSupported() {
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
String idbrokerGroupName = "idbroker";
HostGroup idbrokerHg = new HostGroup();
idbrokerHg.setName(idbrokerGroupName);
idbrokerHg.setRecoveryMode(RecoveryMode.MANUAL);
Set<VolumeTemplate> volumeTemplateSet = Set.of(createVolumeTemplate(AwsDiskType.Standard), createVolumeTemplate(AwsDiskType.Ephemeral));
InstanceGroup idbrokerIg = createUnhealthyInstanceGroup(idbrokerGroupName, volumeTemplateSet);
idbrokerHg.setInstanceGroup(idbrokerIg);
stack.setInstanceGroups(Set.of(idbrokerIg));
when(hostGroupService.getByCluster(CLUSTER_ID)).thenReturn(Set.of(idbrokerHg));
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> actual = underTest.validateRepair(ManualClusterRepairMode.HOST_GROUP, STACK_ID, Set.of(idbrokerGroupName), false);
assertEquals(1, actual.getSuccess().size());
assertNotNull(actual.getSuccess().get(hostGroupName(idbrokerGroupName)));
});
}
Aggregations