Search in sources :

Example 31 with GeneralClusterConfigs

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));
}
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 32 with GeneralClusterConfigs

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));
}
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 33 with GeneralClusterConfigs

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;
}
Also used : GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)

Example 34 with 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());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Optional(java.util.Optional) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Json(com.sequenceiq.cloudbreak.common.json.Json) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) IdBroker(com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with 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));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

GeneralClusterConfigs (com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)67 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)52 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)28 HostgroupView (com.sequenceiq.cloudbreak.template.views.HostgroupView)21 Test (org.junit.jupiter.api.Test)20 BlueprintView (com.sequenceiq.cloudbreak.template.views.BlueprintView)19 Test (org.junit.Test)18 ApiClusterTemplateService (com.cloudera.api.swagger.model.ApiClusterTemplateService)16 DisplayName (org.junit.jupiter.api.DisplayName)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)15 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 DatalakeView (com.sequenceiq.cloudbreak.template.views.DatalakeView)12 BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)11 Gateway (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 HashSet (java.util.HashSet)8 VirtualGroupRequest (com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest)7 ArrayList (java.util.ArrayList)7 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)6