Search in sources :

Example 21 with HostGroup

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.

the class InstanceGroupV4RequestToHostGroupConverterTest method testConvertWhenHostNameUpperCase.

@Test
public void testConvertWhenHostNameUpperCase() {
    InstanceGroupV4Request source = new InstanceGroupV4Request();
    source.setName("MixEdName");
    source.setTemplate(new InstanceTemplateV4Request());
    HostGroup actual = underTest.convert(source);
    assertEquals(actual.getName(), "mixedname");
}
Also used : InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Test(org.junit.jupiter.api.Test)

Example 22 with HostGroup

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.

the class ClusterUpscaleServiceTest method testInstallServicesWithoutRepairAndServiceRestart.

@Test
public void testInstallServicesWithoutRepairAndServiceRestart() throws CloudbreakException {
    HostGroup hostGroup = newHostGroup("master", newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.DELETED_BY_PROVIDER));
    stack.setInstanceGroups(Set.of(hostGroup.getInstanceGroup()));
    when(hostGroupService.getByClusterWithRecipes(any())).thenReturn(Set.of(hostGroup));
    when(hostGroupService.getByCluster(any())).thenReturn(Set.of(hostGroup));
    when(parcelService.removeUnusedParcelComponents(stack)).thenReturn(new ParcelOperationStatus(Map.of(), Map.of()));
    when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
    underTest.installServicesOnNewHosts(1L, Set.of("master"), false, false, Map.of("master", Set.of("master-1", "master-2", "master-3")));
    inOrder.verify(parcelService).removeUnusedParcelComponents(stack);
    inOrder.verify(recipeEngine, times(1)).executePostAmbariStartRecipes(stack, Set.of(hostGroup));
    inOrder.verify(clusterApi, times(1)).upscaleCluster(any());
    inOrder.verify(clusterApi, times(0)).restartAll(false);
    inOrder.verify(clusterStatusService, times(0)).getDecommissionedHostsFromCM();
    inOrder.verify(clusterCommissionService, times(0)).recommissionHosts(any());
}
Also used : ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 23 with HostGroup

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.

the class ClusterUpscaleServiceTest method newHostGroup.

private HostGroup newHostGroup(String name, InstanceMetaData... instances) {
    HostGroup hostGroup = new HostGroup();
    hostGroup.setName(name);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceMetaData(Set.of(instances));
    hostGroup.setInstanceGroup(instanceGroup);
    return hostGroup;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 24 with HostGroup

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.

the class ClusterUpscaleServiceTest method testInstallServicesWithRepairAndServiceRestartWhenOneHostIsUnhealthy.

@Test
public void testInstallServicesWithRepairAndServiceRestartWhenOneHostIsUnhealthy() throws CloudbreakException {
    HostGroup hostGroup = newHostGroup("master", newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.DELETED_BY_PROVIDER));
    stack.setInstanceGroups(Set.of(hostGroup.getInstanceGroup()));
    when(hostGroupService.getByClusterWithRecipes(any())).thenReturn(Set.of(hostGroup));
    when(hostGroupService.getByCluster(any())).thenReturn(Set.of(hostGroup));
    when(parcelService.removeUnusedParcelComponents(stack)).thenReturn(new ParcelOperationStatus(Map.of(), Map.of()));
    when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
    when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
    when(clusterStatusService.getDecommissionedHostsFromCM()).thenReturn(List.of());
    underTest.installServicesOnNewHosts(1L, Set.of("master"), true, true, Map.of("master", Set.of("master-1", "master-2", "master-3")));
    inOrder.verify(parcelService).removeUnusedParcelComponents(stack);
    inOrder.verify(recipeEngine, times(1)).executePostAmbariStartRecipes(stack, Set.of(hostGroup));
    inOrder.verify(clusterApi, times(1)).upscaleCluster(any());
    inOrder.verify(clusterApi, times(0)).restartAll(false);
    inOrder.verify(clusterCommissionService, times(0)).recommissionHosts(any());
}
Also used : ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 25 with HostGroup

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.

the class StopStartDownscaleDecommissionViaCMHandlerTest method testErrorFromCmHostCollection.

@Test
void testErrorFromCmHostCollection() {
    int instancesToDecommissionCount = 5;
    int expcetedInstanceToCollectCount = 5;
    int expectedInstancesDecommissionedCount = 5;
    List<InstanceMetaData> instancesToDecommission = getInstancesToDecommission(instancesToDecommissionCount);
    HostGroup hostGroup = createHostGroup(instancesToDecommission);
    Map<String, InstanceMetaData> collected = instancesToDecommission.stream().limit(expcetedInstanceToCollectCount).collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
    List<InstanceMetaData> decommissionedMetadataList = collected.values().stream().limit(expectedInstancesDecommissionedCount).collect(Collectors.toList());
    Set<String> fqdnsDecommissioned = decommissionedMetadataList.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toUnmodifiableSet());
    Set<Long> instanceIdsToDecommission = instancesToDecommission.stream().map(InstanceMetaData::getPrivateId).collect(Collectors.toUnmodifiableSet());
    Set<String> hostnamesToDecommission = instancesToDecommission.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toUnmodifiableSet());
    setupAdditionalMocks(hostGroup, instancesToDecommission, collected, fqdnsDecommissioned);
    when(clusterDecomissionService.collectHostsToRemove(eq(hostGroup), eq(hostnamesToDecommission))).thenThrow(new RuntimeException("collectHostsToDecommissionError"));
    StopStartDownscaleDecommissionViaCMRequest request = new StopStartDownscaleDecommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instanceIdsToDecommission);
    HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
    Selectable selectable = underTest.doAccept(handlerEvent);
    verify(clusterDecomissionService).collectHostsToRemove(eq(hostGroup), eq(hostnamesToDecommission));
    assertThat(selectable).isInstanceOf(StopStartDownscaleDecommissionViaCMResult.class);
    StopStartDownscaleDecommissionViaCMResult result = (StopStartDownscaleDecommissionViaCMResult) selectable;
    assertThat(result.getNotDecommissionedHostFqdns()).hasSize(0);
    assertThat(result.getDecommissionedHostFqdns()).hasSize(0);
    assertThat(result.getErrorDetails().getMessage()).isEqualTo("collectHostsToDecommissionError");
    assertThat(result.getStatus()).isEqualTo(EventStatus.FAILED);
    assertThat(result.selector()).isEqualTo("STOPSTARTDOWNSCALEDECOMMISSIONVIACMRESULT_ERROR");
    verifyNoMoreInteractions(instanceMetaDataService);
    verifyNoMoreInteractions(flowMessageService);
    verifyNoMoreInteractions(clusterDecomissionService);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BeforeEach(org.junit.jupiter.api.BeforeEach) ClusterDecomissionService(com.sequenceiq.cloudbreak.cluster.api.ClusterDecomissionService) StopStartDownscaleDecommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartDownscaleDecommissionViaCMResult) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTEREDCMMAINTMODE(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTEREDCMMAINTMODE) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) Mockito.lenient(org.mockito.Mockito.lenient) ArrayList(java.util.ArrayList) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) HashSet(java.util.HashSet) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTERINGCMMAINTMODE(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTERINGCMMAINTMODE) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Event(reactor.bus.Event) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Mockito.when(org.mockito.Mockito.when) EventStatus(com.sequenceiq.cloudbreak.cloud.event.model.EventStatus) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) StopStartDownscaleDecommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest) List(java.util.List) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StopStartDownscaleDecommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartDownscaleDecommissionViaCMResult) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) StopStartDownscaleDecommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) 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