use of com.cloudera.api.swagger.model.ApiRemoteDataContext 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.model.ApiRemoteDataContext 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.model.ApiRemoteDataContext 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));
}
use of com.cloudera.api.swagger.model.ApiRemoteDataContext 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));
}
use of com.cloudera.api.swagger.model.ApiRemoteDataContext in project cloudbreak by hortonworks.
the class ClouderaManagerSetupService method setupRemoteDataContext.
@Override
public String setupRemoteDataContext(String sdxContext) {
Cluster cluster = stack.getCluster();
String user = cluster.getCloudbreakAmbariUser();
String password = cluster.getCloudbreakAmbariPassword();
try {
ApiClient rootClient = clouderaManagerApiClientProvider.getRootClient(stack.getGatewayPort(), user, password, clientConfig);
CdpResourceApi cdpResourceApi = clouderaManagerApiFactory.getCdpResourceApi(rootClient);
ApiRemoteDataContext apiRemoteDataContext = JsonUtil.readValue(sdxContext, ApiRemoteDataContext.class);
LOGGER.debug("Posting remote context to workload. EndpointId: {}", apiRemoteDataContext.getEndPointId());
return cdpResourceApi.postRemoteContext(apiRemoteDataContext).getEndPointId();
} catch (ApiException | ClouderaManagerClientInitException e) {
LOGGER.info("Error while creating data context using: {}", sdxContext, e);
throw new ClouderaManagerOperationFailedException(String.format("Error while creating data context: %s", e.getMessage()), e);
} catch (IOException e) {
LOGGER.info("Failed to parse SDX context to CM API object.", e);
throw new ClouderaManagerOperationFailedException(String.format("Failed to parse SDX context to CM API object: %s", e.getMessage()), e);
}
}
Aggregations