Search in sources :

Example 1 with ProxyConfig

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

the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigCouldBeFetched.

@Test
void testGetWhenProxyConfigCouldBeFetched() {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    String decryptedSecretValue = "decrypted-secret-value";
    String noProxyList = "noproxy.com";
    SecretResponse secretResponse = new SecretResponse();
    ProxyResponse proxyResponse = new ProxyResponse();
    proxyResponse.setName(name);
    proxyResponse.setHost(host);
    proxyResponse.setPort(port);
    proxyResponse.setUserName(secretResponse);
    proxyResponse.setPassword(secretResponse);
    proxyResponse.setNoProxyHosts(noProxyList);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
    when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
    when(secretService.getByResponse(any(SecretResponse.class))).thenReturn(decryptedSecretValue);
    ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
    verify(secretService, times(2)).getByResponse(secretResponse);
    assertEquals(proxyConfig.getName(), name);
    assertEquals(proxyConfig.getServerHost(), host);
    assertEquals(proxyConfig.getServerPort(), port);
    assertTrue(proxyConfig.getProxyAuthentication().isPresent());
    assertEquals(proxyConfig.getProxyAuthentication().get().getUserName(), decryptedSecretValue);
    assertEquals(proxyConfig.getProxyAuthentication().get().getPassword(), decryptedSecretValue);
    assertEquals(proxyConfig.getNoProxyHosts(), noProxyList);
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ProxyConfig

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

the class UserDataService method createUserData.

private void createUserData(Stack stack, Supplier<CcmConnectivityParameters> ccmParametersSupplier) {
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    Future<PlatformParameters> platformParametersFuture = intermediateBuilderExecutor.submit(() -> platformParameterService.getPlatformParameters(stack, credential));
    SecurityConfig securityConfig = stack.getSecurityConfig();
    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 = ccmParametersSupplier.get();
        Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByEnvironmentCrn(stack.getEnvironmentCrn());
        String userData = userDataBuilder.buildUserData(stack.getAccountId(), environment, 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 parameters", e);
        throw new GetCloudParameterException("Failed to get Platform parameters", e);
    }
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltSecurityConfig(com.sequenceiq.freeipa.entity.SaltSecurityConfig) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) SaltSecurityConfig(com.sequenceiq.freeipa.entity.SaltSecurityConfig) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with ProxyConfig

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

the class ClouderaManagerMgmtTelemetryServiceTest method testBuildTelemetryConfigListWithProxyConfig.

@Test
public void testBuildTelemetryConfigListWithProxyConfig() {
    // GIVEN
    Stack stack = new Stack();
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setName("cl1");
    stack.setCluster(cluster);
    WorkloadAnalytics wa = new WorkloadAnalytics();
    ProxyConfig proxyConfig = ProxyConfig.builder().withProtocol("https").withServerHost("proxyServer").withServerPort(80).withProxyAuthentication(ProxyAuthentication.builder().withUserName("proxyUser").withPassword("proxyPassword").build()).withNoProxyHosts("noproxy.com").build();
    // WHEN
    ApiConfigList result = underTest.buildTelemetryConfigList(stack, wa, null, null, proxyConfig);
    // THEN
    assertTrue(containsConfigWithValue(result, "telemetrypublisher_proxy_server", "proxyServer"));
    assertTrue(containsConfigWithValue(result, "telemetrypublisher_proxy_port", "80"));
    assertTrue(containsConfigWithValue(result, "telemetrypublisher_proxy_enabled", "true"));
    assertTrue(containsConfigWithValue(result, "telemetrypublisher_proxy_user", "proxyUser"));
    assertTrue(containsConfigWithValue(result, "telemetrypublisher_proxy_password", "proxyPassword"));
// TODO: check no_proxy configkey
}
Also used : ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) WorkloadAnalytics(com.sequenceiq.common.api.telemetry.model.WorkloadAnalytics) Test(org.junit.Test)

Example 4 with ProxyConfig

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

use of com.sequenceiq.cloudbreak.dto.ProxyConfig 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));
}
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) ApiException(com.cloudera.api.swagger.client.ApiException) Test(org.junit.jupiter.api.Test)

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