use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenPollingCancelled.
@Test
public void testRotateHostCertificatesWhenPollingCancelled() 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);
ApiHostList hostList = createApiHostList();
when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenReturn(hostList);
ArgumentCaptor<ApiBatchRequest> batchRequestArgumentCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
when(batchResourceApi.execute(batchRequestArgumentCaptor.capture())).thenReturn(createApiBatchResponse(hostList, true));
when(clouderaManagerPollingServiceProvider.startPollingCommandList(eq(stack), eq(apiClient), any(List.class), eq("Rotate host certificates"))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().exit().build());
// WHEN
CancellationException exception = assertThrows(CancellationException.class, () -> underTest.rotateHostCertificates(null, null, null));
// THEN exception
assertThat(exception).hasMessage("Cluster was terminated during rotation of host certificates");
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenBatchExecuteFailed.
@ParameterizedTest(name = "{0}")
@MethodSource("testRotateHostCertificatesWhenBatchExecuteFailedDataProvider")
public void testRotateHostCertificatesWhenBatchExecuteFailed(String testCaseName, Function<ApiHostList, ApiBatchResponse> batchResponseFactory) 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);
ApiHostList hostList = createApiHostList();
when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenReturn(hostList);
ArgumentCaptor<ApiBatchRequest> batchRequestArgumentCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
when(batchResourceApi.execute(batchRequestArgumentCaptor.capture())).thenReturn(batchResponseFactory.apply(hostList));
// WHEN
ClouderaManagerOperationFailedException exception = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.rotateHostCertificates(null, null, null));
// THEN exception
assertThat(exception).hasMessageStartingWith("Host certificates rotation batch operation failed: ");
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSetupServiceTest method testConfigureManagementServicesWhenThePrimaryGatewayInstanceDiscoveryFQDNIsPresentedOnCMSideShoudCallSetupMgmtServices.
@Test
public void testConfigureManagementServicesWhenThePrimaryGatewayInstanceDiscoveryFQDNIsPresentedOnCMSideShoudCallSetupMgmtServices() 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");
doNothing().when(mgmtSetupService).setupMgmtServices(any(Stack.class), any(ApiClient.class), any(ApiHostRef.class), any(Telemetry.class), anyString(), anyString(), any(ProxyConfig.class));
underTest.configureManagementServices(mockTemplatePreparationObject, mockSdxContext, mockSdxStackCrn, telemetry, proxyConfig);
verify(mgmtSetupService, times(1)).setupMgmtServices(any(Stack.class), any(ApiClient.class), any(ApiHostRef.class), any(Telemetry.class), anyString(), anyString(), any(ProxyConfig.class));
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSetupServiceTest method testConfigureManagementServicesWhenApiExceptionHappensThenShouldThrowClouderaManagerOperationFailedException.
@Test
public void testConfigureManagementServicesWhenApiExceptionHappensThenShouldThrowClouderaManagerOperationFailedException() throws Exception {
ApiException error = mock(ApiException.class);
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(error.getResponseBody()).thenReturn(null);
when(error.getMessage()).thenReturn("error");
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(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));
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSetupServiceTest method testConfigureSupportTagsWhenCmHostPresentedShouldEverythingWorks.
@Test
public void testConfigureSupportTagsWhenCmHostPresentedShouldEverythingWorks() 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);
doNothing().when(clouderaManagerSupportSetupService).prepareSupportRole(any(ApiClient.class), any(StackType.class));
underTest.configureSupportTags(mockTemplatePreparationObject);
verify(clouderaManagerSupportSetupService, times(1)).prepareSupportRole(any(ApiClient.class), any(StackType.class));
}
Aggregations