Search in sources :

Example 1 with RoleConfigGroupsResourceApi

use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerClientActions method checkCmKnoxIDBrokerRoleConfigGroups.

public SdxInternalTestDto checkCmKnoxIDBrokerRoleConfigGroups(SdxInternalTestDto testDto, String user, String password) {
    String serverFqdn = testDto.getResponse().getStackV4Response().getCluster().getServerFqdn();
    ApiClient apiClient = getCmApiClient(serverFqdn, testDto.getName(), V_43, user, password);
    // CHECKSTYLE:OFF
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
    // CHECKSTYLE:ON
    try {
        ApiConfigList knoxConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "knox-IDBROKER-BASE", "knox", "full");
        knoxConfigs.getItems().stream().forEach(knoxConfig -> {
            String knoxConfigName = knoxConfig.getName();
            String mappingsFromKnoxConfig = knoxConfig.getValue();
            if (String.join("_", "idbroker", cloudProvider, "group", "mapping").equalsIgnoreCase(knoxConfigName)) {
                if (!mappingsFromKnoxConfig.contains("_c_cm_admins_")) {
                    LOGGER.error("{} does not contains the expected 'CM Admins' mapping!", knoxConfigName);
                    throw new TestFailException(String.format("%s does not contains the expected 'CM Admins' mapping!", knoxConfigName));
                } else {
                    Log.log(LOGGER, format(" '%s' contains the expected '%s' mapping. ", knoxConfigName, mappingsFromKnoxConfig));
                }
            } else if (String.join("_", "idbroker", cloudProvider, "user", "mapping").equalsIgnoreCase(knoxConfigName)) {
                if (!mappingsFromKnoxConfig.contains("hive")) {
                    LOGGER.error("{} does not contains the expected 'Hive' mapping!", knoxConfigName);
                    throw new TestFailException(String.format("%s does not contains the expected 'Hive' mapping!", knoxConfigName));
                } else {
                    Log.log(LOGGER, format(" '%s' contains the expected ['%s'] mappings. ", knoxConfigName, mappingsFromKnoxConfig));
                }
            }
        });
        if (knoxConfigs.getItems().isEmpty()) {
            LOGGER.error("IDBroker mappings are NOT exist!");
            throw new TestFailException("IDBroker mappings are NOT exist!");
        }
    } catch (ApiException e) {
        LOGGER.error("Exception when calling RoleConfigGroupsResourceApi#readConfig. Response: {}", e.getResponseBody(), e);
        String message = format("Exception when calling RoleConfigGroupsResourceApi#readConfig at %s. Response: %s", apiClient.getBasePath(), e.getResponseBody());
        throw new TestFailException(message, e);
    } catch (Exception e) {
        LOGGER.error("Can't get users' list at: '{}'!", apiClient.getBasePath());
        throw new TestFailException("Can't get users' list at: " + apiClient.getBasePath(), e);
    }
    return testDto;
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiException(com.cloudera.api.swagger.client.ApiException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 2 with RoleConfigGroupsResourceApi

use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerCommunicator method getRoleConfigPropertiesFromCM.

public Map<String, ApiConfig> getRoleConfigPropertiesFromCM(Cluster cluster, String serviceName, String roleGroupRef, Set roleConfigPropertyNames) {
    LOGGER.debug("Retrieving roleConfigProperties for cluster '{}', service '{}', roleGroupRef '{}'", cluster.getStackCrn(), serviceName, roleGroupRef);
    HttpClientConfig httpClientConfig = tlsHttpClientConfigurationService.buildTLSClientConfig(cluster.getStackCrn(), cluster.getClusterManager().getHost(), cluster.getTunnel());
    ClusterManager cm = cluster.getClusterManager();
    String user = secretService.get(cm.getUser());
    String pass = secretService.get(cm.getPass());
    Map<String, ApiConfig> roleConfigProperties = requestLogging.logResponseTime(() -> {
        try {
            ApiClient client = clouderaManagerApiClientProvider.getV31Client(Integer.valueOf(cm.getPort()), user, pass, httpClientConfig);
            client.getHttpClient().interceptors().add(cmOkHttpTracingInterceptor);
            client.getHttpClient().interceptors().add(cmRequestIdProviderInterceptor);
            RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(client);
            return roleConfigGroupsResourceApi.readConfig(cluster.getStackName(), roleGroupRef, serviceName, DataView.FULL.name()).getItems().stream().filter(apiConfig -> roleConfigPropertyNames.contains(apiConfig.getName())).collect(Collectors.toMap(ApiConfig::getName, apiConfig -> apiConfig));
        } catch (Exception ex) {
            throw new RuntimeException(String.format("Error retrieving roleConfigProperties for cluster '%s', service '%s', roleGroupRef '%s'", cluster.getStackCrn(), serviceName, roleGroupRef), ex);
        }
    }, String.format("getRoleConfigPropertiesFromCM for cluster crn '%s'", cluster.getStackCrn()));
    LOGGER.debug("Retrieved roleConfigPropertyValues for cluster '{}', service '{}', roleGroupRef '{}', roleConfigProperties '{}", cluster.getStackCrn(), serviceName, roleGroupRef, roleConfigProperties.values().stream().map(apiConfig -> String.format("ApiConfig Name '%s, Value '%s', Default '%s", apiConfig.getName(), apiConfig.getValue(), apiConfig.getDefault())).collect(Collectors.toSet()));
    return roleConfigProperties;
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) CmRequestIdProviderInterceptor(com.sequenceiq.cloudbreak.cm.client.tracing.CmRequestIdProviderInterceptor) CmOkHttpTracingInterceptor(com.sequenceiq.cloudbreak.cm.client.tracing.CmOkHttpTracingInterceptor) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) SecretService(com.sequenceiq.cloudbreak.service.secret.service.SecretService) Set(java.util.Set) DataView(com.sequenceiq.cloudbreak.cm.DataView) RequestLogging(com.sequenceiq.periscope.aspects.RequestLogging) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) ClusterManager(com.sequenceiq.periscope.domain.ClusterManager) Service(org.springframework.stereotype.Service) Map(java.util.Map) TlsHttpClientConfigurationService(com.sequenceiq.periscope.service.security.TlsHttpClientConfigurationService) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ClusterService(com.sequenceiq.periscope.service.ClusterService) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClusterManager(com.sequenceiq.periscope.domain.ClusterManager)

Example 3 with RoleConfigGroupsResourceApi

use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenRoleTypeNotFound.

@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenRoleTypeNotFound() throws ApiException {
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = Mockito.mock(RoleConfigGroupsResourceApi.class);
    ServicesResourceApi servicesResourceApi = Mockito.mock(ServicesResourceApi.class);
    when(clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(API_CLIENT)).thenReturn(roleConfigGroupsResourceApi);
    when(clouderaManagerApiFactory.getServicesResourceApi(API_CLIENT)).thenReturn(servicesResourceApi);
    List<ApiService> services = List.of(createApiService(NIFI_SERVICE, NIFI_SERVICE_TYPE), createApiService("SPARK", "SPARK-ROLE"));
    when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
    ApiRoleConfigGroupList configGroupList = createApiRoleConfigGroups(List.of(createConfigGroup("SPARK-GROUP", "SPARK-ROLE")));
    when(roleConfigGroupsResourceApi.readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE)).thenReturn(configGroupList);
    Optional<String> actual = underTest.getRoleConfigValueByServiceType(API_CLIENT, TEST_CLUSTER_NAME, NIFI_ROLE, NIFI_SERVICE_TYPE, CONFIG_NAME);
    assertEquals(Optional.empty(), actual);
    verify(clouderaManagerApiFactory).getRoleConfigGroupsResourceApi(API_CLIENT);
    verify(clouderaManagerApiFactory).getServicesResourceApi(API_CLIENT);
    verify(servicesResourceApi).readServices(eq(TEST_CLUSTER_NAME), any());
    verify(roleConfigGroupsResourceApi, times(1)).readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE);
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ApiRoleConfigGroupList(com.cloudera.api.swagger.model.ApiRoleConfigGroupList) ApiService(com.cloudera.api.swagger.model.ApiService) Test(org.junit.Test)

Example 4 with RoleConfigGroupsResourceApi

use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenTheConfigNotFound.

@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenTheConfigNotFound() throws ApiException {
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = Mockito.mock(RoleConfigGroupsResourceApi.class);
    ServicesResourceApi servicesResourceApi = Mockito.mock(ServicesResourceApi.class);
    when(clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(API_CLIENT)).thenReturn(roleConfigGroupsResourceApi);
    when(clouderaManagerApiFactory.getServicesResourceApi(API_CLIENT)).thenReturn(servicesResourceApi);
    List<ApiService> services = List.of(createApiService(NIFI_SERVICE, NIFI_SERVICE_TYPE), createApiService("SPARK", "SPARK-ROLE"));
    when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
    ApiRoleConfigGroupList configGroupList = createApiRoleConfigGroups(List.of(createConfigGroup(NIFI_CONFIG_GROUP, NIFI_ROLE), createConfigGroup("SPARK-GROUP", "SPARK-ROLE")));
    when(roleConfigGroupsResourceApi.readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE)).thenReturn(configGroupList);
    ApiConfigList roleConfig = createApiConfigList(Collections.emptyList());
    when(roleConfigGroupsResourceApi.readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW)).thenReturn(roleConfig);
    Optional<String> actual = underTest.getRoleConfigValueByServiceType(API_CLIENT, TEST_CLUSTER_NAME, NIFI_ROLE, NIFI_SERVICE_TYPE, CONFIG_NAME);
    assertEquals(Optional.empty(), actual);
    verify(clouderaManagerApiFactory).getRoleConfigGroupsResourceApi(API_CLIENT);
    verify(clouderaManagerApiFactory).getServicesResourceApi(API_CLIENT);
    verify(servicesResourceApi).readServices(eq(TEST_CLUSTER_NAME), any());
    verify(roleConfigGroupsResourceApi).readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE);
    verify(roleConfigGroupsResourceApi).readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW);
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ApiRoleConfigGroupList(com.cloudera.api.swagger.model.ApiRoleConfigGroupList) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ApiService(com.cloudera.api.swagger.model.ApiService) Test(org.junit.Test)

Example 5 with RoleConfigGroupsResourceApi

use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValueWhenTheValueIsNullAndDefaultValuePresent.

@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValueWhenTheValueIsNullAndDefaultValuePresent() throws ApiException {
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = Mockito.mock(RoleConfigGroupsResourceApi.class);
    ServicesResourceApi servicesResourceApi = Mockito.mock(ServicesResourceApi.class);
    when(clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(API_CLIENT)).thenReturn(roleConfigGroupsResourceApi);
    when(clouderaManagerApiFactory.getServicesResourceApi(API_CLIENT)).thenReturn(servicesResourceApi);
    List<ApiService> services = List.of(createApiService(NIFI_SERVICE, NIFI_SERVICE_TYPE), createApiService("SPARK", "SPARK-ROLE"));
    when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
    ApiRoleConfigGroupList configGroupList = createApiRoleConfigGroups(List.of(createConfigGroup(NIFI_CONFIG_GROUP, NIFI_ROLE), createConfigGroup("SPARK-GROUP", "SPARK-ROLE")));
    when(roleConfigGroupsResourceApi.readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE)).thenReturn(configGroupList);
    ApiConfigList roleConfig = createApiConfigList(List.of(createConfig(null, DEFAULT_VALUE)));
    when(roleConfigGroupsResourceApi.readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW)).thenReturn(roleConfig);
    Optional<String> actual = underTest.getRoleConfigValueByServiceType(API_CLIENT, TEST_CLUSTER_NAME, NIFI_ROLE, NIFI_SERVICE_TYPE, CONFIG_NAME);
    assertEquals(Optional.of(DEFAULT_VALUE), actual);
    verify(clouderaManagerApiFactory).getRoleConfigGroupsResourceApi(API_CLIENT);
    verify(clouderaManagerApiFactory).getServicesResourceApi(API_CLIENT);
    verify(servicesResourceApi).readServices(eq(TEST_CLUSTER_NAME), any());
    verify(roleConfigGroupsResourceApi).readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE);
    verify(roleConfigGroupsResourceApi).readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW);
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ApiRoleConfigGroupList(com.cloudera.api.swagger.model.ApiRoleConfigGroupList) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ApiService(com.cloudera.api.swagger.model.ApiService) Test(org.junit.Test)

Aggregations

RoleConfigGroupsResourceApi (com.cloudera.api.swagger.RoleConfigGroupsResourceApi)11 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)8 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)6 ApiService (com.cloudera.api.swagger.model.ApiService)6 ApiClient (com.cloudera.api.swagger.client.ApiClient)5 ApiException (com.cloudera.api.swagger.client.ApiException)5 ApiRoleConfigGroupList (com.cloudera.api.swagger.model.ApiRoleConfigGroupList)5 Test (org.junit.Test)5 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)4 ApiConfig (com.cloudera.api.swagger.model.ApiConfig)2 ClouderaManagerApiFactory (com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Service (org.springframework.stereotype.Service)2 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)1 ApiServiceConfig (com.cloudera.api.swagger.model.ApiServiceConfig)1 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)1 ApiVersionInfo (com.cloudera.api.swagger.model.ApiVersionInfo)1