Search in sources :

Example 6 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig 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 7 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig 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 8 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class UserDataService method createUserData.

public void createUserData(Long stackId) throws CloudbreakImageNotFoundException {
    Stack stack = stackService.getByIdWithLists(stackId);
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    Future<PlatformParameters> platformParametersFuture = intermediateBuilderExecutor.submit(() -> connector.getPlatformParameters(stack, userCrn));
    SecurityConfig securityConfig = securityConfigService.generateAndSaveSecurityConfig(stack);
    stack.setSecurityConfig(securityConfig);
    stackService.save(stack);
    SaltSecurityConfig saltSecurityConfig = securityConfig.getSaltSecurityConfig();
    String cbPrivKey = saltSecurityConfig.getSaltBootSignPrivateKey();
    byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(new String(Base64.decodeBase64(cbPrivKey)));
    String sshUser = stack.getStackAuthentication().getLoginUserName();
    String cbCert = securityConfig.getClientCert();
    String saltBootPassword = saltSecurityConfig.getSaltBootPassword();
    try {
        PlatformParameters platformParameters = platformParametersFuture.get();
        CcmConnectivityParameters ccmParameters = ccmUserDataService.fetchAndSaveCcmParameters(stack);
        Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByEnvironmentCrn(stack.getEnvironmentCrn());
        Map<InstanceGroupType, String> userData = userDataBuilder.buildUserData(Platform.platform(stack.getCloudPlatform()), cbSshKeyDer, sshUser, platformParameters, saltBootPassword, cbCert, ccmParameters, proxyConfig.orElse(null));
        imageService.decorateImageWithUserDataForStack(stack, userData);
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.error("Failed to get Platform parmaters", e);
        throw new GetCloudParameterException("Failed to get Platform parmaters", e);
    }
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class ClusterBuilderService method configureManagementServices.

public void configureManagementServices(Long stackId) {
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByCrnWithEnvironmentFallback(stack.getCluster().getProxyConfigCrn(), stack.getCluster().getEnvironmentCrn());
    getClusterSetupService(stack).configureManagementServices(stackToTemplatePreparationObjectConverter.convert(stack), getSdxContextOptional(stack.getDatalakeCrn()).orElse(null), stack.getDatalakeCrn(), componentConfigProviderService.getTelemetry(stackId), proxyConfig.orElse(null));
}
Also used : ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 10 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class ClusterBuilderService method prepareProxyConfig.

public void prepareProxyConfig(Long stackId) {
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByCrnWithEnvironmentFallback(stack.getCluster().getProxyConfigCrn(), stack.getCluster().getEnvironmentCrn());
    if (proxyConfig.isPresent()) {
        LOGGER.info("proxyConfig is not null, setup proxy for cluster: {}", proxyConfig);
        getClusterSetupService(stack).setupProxy(proxyConfig.orElse(null));
    } else {
        LOGGER.info("proxyConfig was not found by proxyConfigCrn");
    }
}
Also used : ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)18 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Test (org.junit.jupiter.api.Test)6 CcmConnectivityParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters)5 CdpResourceApi (com.cloudera.api.swagger.CdpResourceApi)4 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)4 ApiClient (com.cloudera.api.swagger.client.ApiClient)4 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)4 ApiHostRef (com.cloudera.api.swagger.model.ApiHostRef)4 ApiRemoteDataContext (com.cloudera.api.swagger.model.ApiRemoteDataContext)4 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)4 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)4 GeneralClusterConfigs (com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)4 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)3 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)3 ProxyResponse (com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse)3 Test (org.junit.Test)3