Search in sources :

Example 6 with ClusterClientInitException

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

the class ClouderaManagerSetupService method createApiClient.

private ApiClient createApiClient() throws ClusterClientInitException {
    ApiClient client = null;
    try {
        client = clouderaManagerApiClientProvider.getDefaultClient(stack.getGatewayPort(), clientConfig, ClouderaManagerApiClientProvider.API_V_31);
        ToolsResourceApi toolsResourceApi = clouderaManagerApiFactory.getToolsResourceApi(client);
        toolsResourceApi.echo("TEST");
        LOGGER.debug("Cloudera Manager already running, old admin user's password has not been changed yet.");
        return client;
    } catch (ClouderaManagerClientInitException e) {
        throw new ClusterClientInitException(e);
    } catch (ApiException e) {
        return returnClientBasedOnApiError(client, e);
    }
}
Also used : ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 7 with ClusterClientInitException

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

the class StopStartUpscaleCommissionViaCMHandlerTest method testAllCommissioned.

@Test
void testAllCommissioned() throws ClusterClientInitException {
    int commissionInstanceCount = 5;
    List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
    HostGroup hostGroup = createHostGroup(instancesToCommission);
    Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
    Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
    Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().collect(Collectors.toUnmodifiableSet());
    setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
    StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
    HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
    Selectable selectable = underTest.doAccept(handlerEvent);
    assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
    StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
    assertThat(result.getNotRecommissionedFqdns()).hasSize(0);
    assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(commissionInstanceCount);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) BeforeEach(org.junit.jupiter.api.BeforeEach) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) 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) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Event(reactor.bus.Event) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) ClusterSetupService(com.sequenceiq.cloudbreak.cluster.api.ClusterSetupService) 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) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Collectors(java.util.stream.Collectors) ClusterCommissionService(com.sequenceiq.cloudbreak.cluster.api.ClusterCommissionService) Test(org.junit.jupiter.api.Test) 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) Collections(java.util.Collections) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Test(org.junit.jupiter.api.Test)

Example 8 with ClusterClientInitException

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

the class StopStartUpscaleCommissionViaCMHandlerTest method testFewerNodesOnBothCmInvocations.

@Test
void testFewerNodesOnBothCmInvocations() throws ClusterClientInitException {
    int commissionInstanceCount = 5;
    List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
    HostGroup hostGroup = createHostGroup(instancesToCommission);
    Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
    Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().limit(commissionInstanceCount - 1).collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
    Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().limit(commissionInstanceCount - 2).collect(Collectors.toUnmodifiableSet());
    setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
    StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
    HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
    Selectable selectable = underTest.doAccept(handlerEvent);
    assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
    StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
    assertThat(result.getNotRecommissionedFqdns()).hasSize(2);
    assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(commissionInstanceCount - 2);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) BeforeEach(org.junit.jupiter.api.BeforeEach) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) 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) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Event(reactor.bus.Event) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) ClusterSetupService(com.sequenceiq.cloudbreak.cluster.api.ClusterSetupService) 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) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Collectors(java.util.stream.Collectors) ClusterCommissionService(com.sequenceiq.cloudbreak.cluster.api.ClusterCommissionService) Test(org.junit.jupiter.api.Test) 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) Collections(java.util.Collections) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Test(org.junit.jupiter.api.Test)

Example 9 with ClusterClientInitException

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

the class StopStartUpscaleCommissionViaCMHandlerTest method testErrorFromCmHostCollection.

@Test
void testErrorFromCmHostCollection() throws ClusterClientInitException {
    int commissionInstanceCount = 5;
    List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
    HostGroup hostGroup = createHostGroup(instancesToCommission);
    Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
    Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
    Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().collect(Collectors.toUnmodifiableSet());
    setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
    when(clusterCommissionService.collectHostsToCommission(eq(hostGroup), eq(hostNames))).thenThrow(new RuntimeException("collectHostsToCommissionError"));
    StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
    HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
    Selectable selectable = underTest.doAccept(handlerEvent);
    assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
    StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
    assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(0);
    assertThat(result.getNotRecommissionedFqdns()).hasSize(0);
    assertThat(result.getErrorDetails().getMessage()).isEqualTo("collectHostsToCommissionError");
    assertThat(result.getStatus()).isEqualTo(EventStatus.FAILED);
    assertThat(result.selector()).isEqualTo("STOPSTARTUPSCALECOMMISSIONVIACMRESULT_ERROR");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) BeforeEach(org.junit.jupiter.api.BeforeEach) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) 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) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Event(reactor.bus.Event) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) ClusterSetupService(com.sequenceiq.cloudbreak.cluster.api.ClusterSetupService) 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) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Collectors(java.util.stream.Collectors) ClusterCommissionService(com.sequenceiq.cloudbreak.cluster.api.ClusterCommissionService) Test(org.junit.jupiter.api.Test) 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) Collections(java.util.Collections) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Test(org.junit.jupiter.api.Test)

Example 10 with ClusterClientInitException

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

the class ClouderaManagerClusterDecommissionServiceTest method testRemoveHostsFromClusterFailsWhenNoV45ClientAvailable.

@Test
public void testRemoveHostsFromClusterFailsWhenNoV45ClientAvailable() {
    ReflectionTestUtils.setField(underTest, "v45Client", null);
    ClusterClientInitException cloudbreakException = assertThrows(ClusterClientInitException.class, () -> underTest.removeHostsFromCluster(List.of(new InstanceMetaData())));
    assertEquals("V45 client is not initialized, bulk host removal is not supported", cloudbreakException.getMessage());
    verify(clouderaManagerDecomissioner, never()).removeHostsFromCluster(any(), anyList(), any());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) Test(org.junit.Test)

Aggregations

ClusterClientInitException (com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException)24 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)17 ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)12 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)8 ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)8 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)8 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)8 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)8 Map (java.util.Map)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 Test (org.junit.jupiter.api.Test)8 EventStatus (com.sequenceiq.cloudbreak.cloud.event.model.EventStatus)7 ClusterCommissionService (com.sequenceiq.cloudbreak.cluster.api.ClusterCommissionService)7 ClusterSetupService (com.sequenceiq.cloudbreak.cluster.api.ClusterSetupService)7 CloudbreakFlowMessageService (com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService)7 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)7 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)7