Search in sources :

Example 16 with HostsResourceApi

use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSetupServiceTest method testConfigureSupportTagsWhenThrowCManagerOperationFailedExceptionShouldThrowCManagerOperationFailedException.

@Test
public void testConfigureSupportTagsWhenThrowCManagerOperationFailedExceptionShouldThrowCManagerOperationFailedException() throws ApiException {
    HostsResourceApi mockHostsResourceApi = mock(HostsResourceApi.class);
    ApiHostList apiHostList = mock(ApiHostList.class);
    TemplatePreparationObject mockTemplatePreparationObject = mock(TemplatePreparationObject.class);
    GeneralClusterConfigs generalClusterConfigs = mock(GeneralClusterConfigs.class);
    when(mockTemplatePreparationObject.getGeneralClusterConfigs()).thenReturn(generalClusterConfigs);
    when(generalClusterConfigs.getPrimaryGatewayInstanceDiscoveryFQDN()).thenReturn(Optional.of("fqdn"));
    when(apiHostList.getItems()).thenReturn(List.of(apiHost("fqdn")));
    when(mockHostsResourceApi.readHosts(null, null, DataView.SUMMARY.name())).thenReturn(apiHostList);
    when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(mockHostsResourceApi);
    doThrow(new ClouderaManagerOperationFailedException("error")).when(clouderaManagerSupportSetupService).prepareSupportRole(any(ApiClient.class), any(StackType.class));
    ClouderaManagerOperationFailedException actual = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.configureSupportTags(mockTemplatePreparationObject));
    verify(clouderaManagerSupportSetupService, times(1)).prepareSupportRole(any(ApiClient.class), any(StackType.class));
    assertEquals(ClouderaManagerOperationFailedException.class, actual.getClass());
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiClient(com.cloudera.api.swagger.client.ApiClient) Test(org.junit.jupiter.api.Test)

Example 17 with HostsResourceApi

use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN.

@Test
public void testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN() throws ApiException {
    // GIVEN
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 50, "vt");
    Stack stack = createTestStack(volumeSetAttributes);
    Cluster cluster = new Cluster();
    stack.setCluster(cluster);
    Set<HostGroup> hostGroups = createTestHostGroups(1, 6);
    cluster.setHostGroups(hostGroups);
    HostGroup downscaledHostGroup = hostGroups.iterator().next();
    Optional<InstanceMetaData> hgHost2 = downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData().stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN().equals("hg0-host-2")).findFirst();
    hgHost2.ifPresent(instanceMetaData -> instanceMetaData.setDiscoveryFQDN(null));
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(hostsResourceApi);
    HostTemplatesResourceApi hostTemplatesResourceApi = mock(HostTemplatesResourceApi.class);
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
    ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
    when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
    ApiHostList apiHostRefList = new ApiHostList();
    List<ApiHost> apiHosts = new ArrayList<>();
    hostGroups.stream().flatMap(hostGroup -> hostGroup.getInstanceGroup().getAllInstanceMetaData().stream()).map(InstanceMetaData::getDiscoveryFQDN).forEach(hostName -> {
        ApiHost apiHostRef = new ApiHost();
        apiHostRef.setHostname(hostName);
        apiHostRef.setHostId(hostName);
        apiHostRef.setHealthSummary(ApiHealthSummary.GOOD);
        apiHosts.add(apiHostRef);
    });
    apiHostRefList.setItems(apiHosts);
    when(hostsResourceApi.readHosts(any(), any(), any())).thenReturn(apiHostRefList);
    Set<InstanceMetaData> downscaleCandidates = underTest.collectDownscaleCandidates(mock(ApiClient.class), stack, downscaledHostGroup, -2, downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData());
    assertEquals(2, downscaleCandidates.size());
    assertTrue("Assert if downscaleCandidates contains hg0-host-2, because FQDN is missing", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-2".equals(instanceMetaData.getInstanceId())));
    assertTrue("Assert if downscaleCandidates contains hg0-host-5", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-host-5".equals(instanceMetaData.getDiscoveryFQDN())));
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ApiException(com.cloudera.api.swagger.client.ApiException) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) NotEnoughNodeException(com.sequenceiq.cloudbreak.cluster.service.NotEnoughNodeException) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) ApiClient(com.cloudera.api.swagger.client.ApiClient) RunWith(org.junit.runner.RunWith) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ApiHost(com.cloudera.api.swagger.model.ApiHost) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) CloudConstants(com.sequenceiq.cloudbreak.common.type.CloudConstants) InjectMocks(org.mockito.InjectMocks) ApiRoleConfigGroupRef(com.cloudera.api.swagger.model.ApiRoleConfigGroupRef) ResourceType(com.sequenceiq.common.api.type.ResourceType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito(org.mockito.Mockito) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Assertions(org.junit.jupiter.api.Assertions) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ApiClient(com.cloudera.api.swagger.client.ApiClient) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 18 with HostsResourceApi

use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSetupServiceTest method testConfigureManagementServicesWhenCManagerOperationFailedExceptionHappensThenShouldThrowCManagerOperationFailedException.

@Test
public void testConfigureManagementServicesWhenCManagerOperationFailedExceptionHappensThenShouldThrowCManagerOperationFailedException() throws Exception {
    HostsResourceApi mockHostsResourceApi = mock(HostsResourceApi.class);
    TemplatePreparationObject mockTemplatePreparationObject = mock(TemplatePreparationObject.class);
    String mockSdxContext = JsonUtil.writeValueAsString(new ApiRemoteDataContext());
    String mockSdxStackCrn = "mockSdxStackCrn";
    Telemetry telemetry = mock(Telemetry.class);
    ProxyConfig proxyConfig = mock(ProxyConfig.class);
    ApiClient apiClient = mock(ApiClient.class);
    ApiHostList apiHostList = mock(ApiHostList.class);
    GeneralClusterConfigs generalClusterConfigs = mock(GeneralClusterConfigs.class);
    CdpResourceApi cdpResourceApi = mock(CdpResourceApi.class);
    ApiRemoteDataContext mockApiRemoteDataContext = mock(ApiRemoteDataContext.class);
    when(mockHostsResourceApi.readHosts(null, null, DataView.SUMMARY.name())).thenReturn(apiHostList);
    when(mockTemplatePreparationObject.getGeneralClusterConfigs()).thenReturn(generalClusterConfigs);
    when(generalClusterConfigs.getPrimaryGatewayInstanceDiscoveryFQDN()).thenReturn(Optional.of("fqdn"));
    when(apiHostList.getItems()).thenReturn(List.of(apiHost("fqdn")));
    when(clouderaManagerApiClientProvider.getRootClient(any(Integer.class), anyString(), anyString(), any(HttpClientConfig.class))).thenReturn(apiClient);
    when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(mockHostsResourceApi);
    when(clouderaManagerApiFactory.getCdpResourceApi(any(ApiClient.class))).thenReturn(cdpResourceApi);
    when(cdpResourceApi.postRemoteContext(any(ApiRemoteDataContext.class))).thenReturn(mockApiRemoteDataContext);
    when(mockApiRemoteDataContext.getEndPointId()).thenReturn("endpoint");
    doThrow(new ClouderaManagerOperationFailedException("error")).when(mgmtSetupService).setupMgmtServices(any(Stack.class), any(ApiClient.class), any(ApiHostRef.class), any(Telemetry.class), anyString(), anyString(), any(ProxyConfig.class));
    ClouderaManagerOperationFailedException actual = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.configureManagementServices(mockTemplatePreparationObject, mockSdxContext, mockSdxStackCrn, telemetry, proxyConfig));
    assertEquals(ClouderaManagerOperationFailedException.class, actual.getClass());
    verify(mgmtSetupService, times(1)).setupMgmtServices(any(Stack.class), any(ApiClient.class), any(ApiHostRef.class), any(Telemetry.class), anyString(), anyString(), any(ProxyConfig.class));
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) ApiClient(com.cloudera.api.swagger.client.ApiClient) CdpResourceApi(com.cloudera.api.swagger.CdpResourceApi) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) ApiRemoteDataContext(com.cloudera.api.swagger.model.ApiRemoteDataContext) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef) Test(org.junit.jupiter.api.Test)

Example 19 with HostsResourceApi

use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSetupServiceTest method testConfigureManagementServicesWhenThePrimaryGatewayInstanceDiscoveryFQDNIsNOTPresentedOnCMSideShoudNOTCallSetupMgmtServices.

@Test
public void testConfigureManagementServicesWhenThePrimaryGatewayInstanceDiscoveryFQDNIsNOTPresentedOnCMSideShoudNOTCallSetupMgmtServices() throws Exception {
    HostsResourceApi mockHostsResourceApi = mock(HostsResourceApi.class);
    TemplatePreparationObject mockTemplatePreparationObject = mock(TemplatePreparationObject.class);
    String mockSdxContext = JsonUtil.writeValueAsString(new ApiRemoteDataContext());
    String mockSdxStackCrn = "mockSdxStackCrn";
    Telemetry telemetry = mock(Telemetry.class);
    ProxyConfig proxyConfig = mock(ProxyConfig.class);
    ApiClient apiClient = mock(ApiClient.class);
    ApiHostList apiHostList = mock(ApiHostList.class);
    GeneralClusterConfigs generalClusterConfigs = mock(GeneralClusterConfigs.class);
    CdpResourceApi cdpResourceApi = mock(CdpResourceApi.class);
    ApiRemoteDataContext mockApiRemoteDataContext = mock(ApiRemoteDataContext.class);
    when(mockHostsResourceApi.readHosts(null, null, DataView.SUMMARY.name())).thenReturn(apiHostList);
    when(mockTemplatePreparationObject.getGeneralClusterConfigs()).thenReturn(generalClusterConfigs);
    when(generalClusterConfigs.getPrimaryGatewayInstanceDiscoveryFQDN()).thenReturn(Optional.of("fqdn1"));
    when(apiHostList.getItems()).thenReturn(List.of(apiHost("fqdn")));
    when(clouderaManagerApiClientProvider.getRootClient(any(Integer.class), anyString(), anyString(), any(HttpClientConfig.class))).thenReturn(apiClient);
    when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(mockHostsResourceApi);
    when(clouderaManagerApiFactory.getCdpResourceApi(any(ApiClient.class))).thenReturn(cdpResourceApi);
    when(cdpResourceApi.postRemoteContext(any(ApiRemoteDataContext.class))).thenReturn(mockApiRemoteDataContext);
    when(mockApiRemoteDataContext.getEndPointId()).thenReturn("endpoint");
    underTest.configureManagementServices(mockTemplatePreparationObject, mockSdxContext, mockSdxStackCrn, telemetry, proxyConfig);
    verify(mgmtSetupService, times(0)).setupMgmtServices(any(Stack.class), any(ApiClient.class), any(ApiHostRef.class), any(Telemetry.class), anyString(), anyString(), any(ProxyConfig.class));
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) ApiClient(com.cloudera.api.swagger.client.ApiClient) CdpResourceApi(com.cloudera.api.swagger.CdpResourceApi) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) ApiRemoteDataContext(com.cloudera.api.swagger.model.ApiRemoteDataContext) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef) Test(org.junit.jupiter.api.Test)

Example 20 with HostsResourceApi

use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenCMApiCallFailed.

@Test
public void testRotateHostCertificatesWhenCMApiCallFailed() throws Exception {
    // GIVEN
    initTestInput("user");
    when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    BatchResourceApi batchResourceApi = mock(BatchResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(apiClient)).thenReturn(hostsResourceApi);
    when(clouderaManagerApiFactory.getBatchResourceApi(apiClient)).thenReturn(batchResourceApi);
    when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenThrow(new ApiException("Serious problem"));
    // WHEN
    CloudbreakException exception = assertThrows(CloudbreakException.class, () -> underTest.rotateHostCertificates(null, null, null));
    // THEN exception
    assertThat(exception).hasMessage("Can't rotate the host certificates due to: Serious problem");
}
Also used : BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiException(com.cloudera.api.swagger.client.ApiException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)34 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)29 ApiClient (com.cloudera.api.swagger.client.ApiClient)19 ApiException (com.cloudera.api.swagger.client.ApiException)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)15 ApiHost (com.cloudera.api.swagger.model.ApiHost)13 List (java.util.List)13 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)11 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)11 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Test (org.junit.jupiter.api.Test)10 HostTemplatesResourceApi (com.cloudera.api.swagger.HostTemplatesResourceApi)9 ApiHostTemplateList (com.cloudera.api.swagger.model.ApiHostTemplateList)9 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)9 ClouderaManagerApiFactory (com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory)9 ClouderaManagerPollingServiceProvider (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider)9 HashSet (java.util.HashSet)9