use of com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs 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.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs 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.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs in project cloudbreak by hortonworks.
the class StackToTemplatePreparationObjectConverter method calculateGeneralClusterConfigs.
private GeneralClusterConfigs calculateGeneralClusterConfigs(Stack source, Cluster cluster) {
GeneralClusterConfigs generalClusterConfigs = generalClusterConfigsProvider.generalClusterConfigs(source, cluster);
boolean allInstanceGroupsHaveMultiAz = source.getInstanceGroups().stream().allMatch(this::isInstanceGroupsHaveMultiAz);
generalClusterConfigs.setMultiAzEnabled(allInstanceGroupsHaveMultiAz);
if (source.getPrimaryGatewayInstance() != null) {
if (StringUtils.isBlank(generalClusterConfigs.getClusterManagerIp())) {
String primaryGatewayIp = gatewayConfigService.getPrimaryGatewayIp(source);
generalClusterConfigs.setClusterManagerIp(primaryGatewayIp);
}
Optional<String> instanceDiscoveryFQDN = generalClusterConfigs.getPrimaryGatewayInstanceDiscoveryFQDN();
if (instanceDiscoveryFQDN.isEmpty()) {
generalClusterConfigs.setPrimaryGatewayInstanceDiscoveryFQDN(Optional.of(source.getPrimaryGatewayInstance().getDiscoveryFQDN()));
}
}
generalClusterConfigs.setLoadBalancerGatewayFqdn(Optional.ofNullable(loadBalancerConfigService.getLoadBalancerUserFacingFQDN(source.getId())));
generalClusterConfigs.setAccountId(Optional.ofNullable(Crn.safeFromString(source.getResourceCrn()).getAccountId()));
return generalClusterConfigs;
}
use of com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs in project cloudbreak by hortonworks.
the class StackToTemplatePreparationObjectConverterTest method setUp.
@BeforeEach
public void setUp() throws IOException, TransactionService.TransactionExecutionException {
MockitoAnnotations.initMocks(this);
doAnswer(invocation -> {
invocation.getArgument(0, Runnable.class).run();
return null;
}).when(transactionService).required(any(Runnable.class));
User user = new User();
user.setUserName("applebob@apple.com");
user.setUserCrn("user-crn");
Tenant tenant = new Tenant();
tenant.setId(1L);
tenant.setName("account");
user.setTenant(tenant);
when(stackMock.getCreator()).thenReturn(user);
when(stackMock.getEnvironmentCrn()).thenReturn("env");
when(stackMock.getCloudPlatform()).thenReturn(TEST_CLOUD_PLATFORM);
when(stackMock.cloudPlatform()).thenReturn(TEST_CLOUD_PLATFORM);
when(stackMock.getType()).thenReturn(StackType.DATALAKE);
when(stackMock.getRegion()).thenReturn(REGION);
when(stackMock.getAvailabilityZone()).thenReturn(AVAILABILITY_ZONE);
when(stackMock.getName()).thenReturn("stackname");
when(sourceCluster.getId()).thenReturn(TEST_CLUSTER_ID);
when(cluster.getId()).thenReturn(TEST_CLUSTER_ID);
when(instanceGroupMetadataCollector.collectMetadata(stackMock)).thenReturn(groupInstances);
when(cluster.getBlueprint()).thenReturn(blueprint);
when(blueprint.getBlueprintText()).thenReturn(TEST_BLUEPRINT_TEXT);
when(blueprint.getStackVersion()).thenReturn("7.2.11");
when(stackMock.getInputs()).thenReturn(stackInputs);
when(stackInputs.get(StackInputs.class)).thenReturn(null);
when(stackMock.getEnvironmentCrn()).thenReturn(TestConstants.CRN);
when(stackMock.getCluster()).thenReturn(sourceCluster);
when(sourceCluster.getCustomConfigurations()).thenReturn(customConfigurations);
when(customConfigurations.getCrn()).thenReturn("test-custom-configs-crn");
when(stackMock.getResourceCrn()).thenReturn("crn:cdp:datahub:us-west-1:account:cluster:cluster");
when(clusterService.findOneWithCustomConfigurations(anyLong())).thenReturn(sourceCluster);
when(accountTagClientService.list()).thenReturn(new HashMap<>());
when(entitlementService.internalTenant(anyString())).thenReturn(true);
when(loadBalancerConfigService.getLoadBalancerUserFacingFQDN(anyLong())).thenReturn(null);
Credential credential = Credential.builder().crn("aCredentialCRN").attributes(new Json("")).build();
DetailedEnvironmentResponse environmentResponse = DetailedEnvironmentResponse.builder().withIdBrokerMappingSource(IdBrokerMappingSource.MOCK).withCredential(new CredentialResponse()).withAdminGroupName(ADMIN_GROUP_NAME).withCrn(TestConstants.CRN).build();
when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
when(credentialConverter.convert(any(CredentialResponse.class))).thenReturn(credential);
when(awsMockAccountMappingService.getGroupMappings(REGION, cloudCredential, ADMIN_GROUP_NAME)).thenReturn(MOCK_GROUP_MAPPINGS);
when(awsMockAccountMappingService.getUserMappings(REGION, cloudCredential)).thenReturn(MOCK_USER_MAPPINGS);
when(ldapConfigService.get(anyString(), anyString())).thenReturn(Optional.empty());
when(clusterService.getById(anyLong())).thenReturn(cluster);
when(customConfigurationsService.getByNameOrCrn(any(NameOrCrn.class))).thenReturn(customConfigurations);
when(exposedServiceCollector.getAllKnoxExposed(any())).thenReturn(Set.of());
when(resourceService.getAllByStackId(anyLong())).thenReturn(Collections.EMPTY_LIST);
IdBroker idbroker = idBrokerConverterUtil.generateIdBrokerSignKeys(cluster);
when(idBrokerService.getByCluster(any(Cluster.class))).thenReturn(idbroker);
when(idBrokerService.save(any(IdBroker.class))).thenReturn(idbroker);
when(grpcUmsClient.listServicePrincipalCloudIdentities(anyString(), anyString(), any(Optional.class))).thenReturn(Collections.EMPTY_LIST);
when(dbCertificateProvider.getSslCertsFilePath()).thenReturn(SSL_CERTS_FILE_PATH);
when(stackMock.getId()).thenReturn(1L);
when(generalClusterConfigsProvider.generalClusterConfigs(any(Stack.class), any(Cluster.class))).thenReturn(new GeneralClusterConfigs());
}
use of com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs in project cloudbreak by hortonworks.
the class StackToTemplatePreparationObjectConverterTest method testMissingClouderaManagerIp.
@Test
public void testMissingClouderaManagerIp() {
GeneralClusterConfigs configs = new GeneralClusterConfigs();
Optional<String> primaryGatewayFqdn = Optional.of("primaryFqdn");
configs.setPrimaryGatewayInstanceDiscoveryFQDN(primaryGatewayFqdn);
when(generalClusterConfigsProvider.generalClusterConfigs(any(Stack.class), any(Cluster.class))).thenReturn(configs);
when(gatewayConfigService.getPrimaryGatewayIp(any(Stack.class))).thenReturn("10.0.0.1");
InstanceMetaData dummyMetadata = new InstanceMetaData();
when(stackMock.getPrimaryGatewayInstance()).thenReturn(dummyMetadata);
when(blueprintViewProvider.getBlueprintView(any())).thenReturn(getBlueprintView());
TemplatePreparationObject result = underTest.convert(stackMock);
assertThat(result.getGeneralClusterConfigs().getClusterManagerIp()).isEqualTo("10.0.0.1");
verify(gatewayConfigService, times(1)).getPrimaryGatewayIp(any(Stack.class));
}
Aggregations