Search in sources :

Example 66 with HostGroup

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);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Result(com.sequenceiq.cloudbreak.service.cluster.model.Result) Test(org.junit.jupiter.api.Test)

Example 67 with HostGroup

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());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 68 with HostGroup

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);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 69 with HostGroup

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);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 70 with HostGroup

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)));
    });
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Map(java.util.Map) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)132 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)66 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)60 HashSet (java.util.HashSet)55 Test (org.junit.jupiter.api.Test)52 List (java.util.List)50 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)43 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)37 Map (java.util.Map)37 Set (java.util.Set)37 Collectors (java.util.stream.Collectors)35 HostGroupService (com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService)25 Optional (java.util.Optional)25 ArrayList (java.util.ArrayList)24 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)22 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)21 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)21 HashMap (java.util.HashMap)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19