Search in sources :

Example 6 with RoleConfigGroupsResourceApi

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

the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenServiceTypeNotFound.

@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenServiceTypeNotFound() 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("SPARK", "SPARK-ROLE"));
    when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
    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());
    verifyNoInteractions(roleConfigGroupsResourceApi);
    verifyNoInteractions(roleConfigGroupsResourceApi);
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ApiService(com.cloudera.api.swagger.model.ApiService) Test(org.junit.Test)

Example 7 with RoleConfigGroupsResourceApi

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

the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValue.

@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValue() 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(CONFIG_VALUE, null)));
    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(CONFIG_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)

Example 8 with RoleConfigGroupsResourceApi

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

the class ClouderaManagerConfigService method getRoleConfigValueByServiceType.

public Optional<String> getRoleConfigValueByServiceType(ApiClient apiClient, String clusterName, String roleType, String serviceType, String configName) {
    LOGGER.debug("Looking for configuration: {} for cluster {}, roleType {}, and serviceType {}", configName, clusterName, roleType, serviceType);
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(apiClient);
    ServicesResourceApi servicesResourceApi = clouderaManagerApiFactory.getServicesResourceApi(apiClient);
    try {
        String serviceName = getServiceNameValue(clusterName, serviceType, servicesResourceApi);
        String roleConfigGroupName = getRoleConfigGroupNameByTypeAndServiceName(roleType, clusterName, serviceName, roleConfigGroupsResourceApi);
        ApiConfigList roleConfig = roleConfigGroupsResourceApi.readConfig(clusterName, roleConfigGroupName, serviceName, "full");
        return roleConfig.getItems().stream().filter(apiConfig -> configName.equals(apiConfig.getName())).map(apiConfig -> Optional.ofNullable(apiConfig.getValue()).orElse(apiConfig.getDefault())).findFirst();
    } catch (ApiException | NotFoundException e) {
        LOGGER.debug("Failed to get configuration: {} for cluster {}, roleType {}, and serviceType {}", configName, clusterName, roleType, serviceType, e);
        return Optional.empty();
    }
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Arrays(java.util.Arrays) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException) Inject(javax.inject.Inject) RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) Service(org.springframework.stereotype.Service) Map(java.util.Map) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ApiRoleConfigGroupList(com.cloudera.api.swagger.model.ApiRoleConfigGroupList) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) Logger(org.slf4j.Logger) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ApiVersionInfo(com.cloudera.api.swagger.model.ApiVersionInfo) Objects(java.util.Objects) Consumer(java.util.function.Consumer) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Optional(java.util.Optional) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 9 with RoleConfigGroupsResourceApi

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

the class ClouderaManagerClientActions method checkCmHdfsNamenodeRoleConfigGroups.

public DistroXTestDto checkCmHdfsNamenodeRoleConfigGroups(DistroXTestDto testDto, String user, String password, Set<String> mountPoints) {
    String serverIp = testDto.getResponse().getCluster().getServerIp();
    ApiClient apiClient = getCmApiClientWithTimeoutDisabled(serverIp, testDto.getName(), V_43, user, password);
    // CHECKSTYLE:OFF
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
    // CHECKSTYLE:ON
    try {
        ApiConfigList hdfsConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "hdfs-NAMENODE-BASE", "hdfs", "summary");
        hdfsConfigs.getItems().forEach(config -> {
            String hdfsConfigName = config.getName();
            String mappingsFromHdfsConfig = config.getValue();
            if ("dfs_name_dir_list".equalsIgnoreCase(hdfsConfigName)) {
                if (mountPoints.stream().anyMatch(mappingsFromHdfsConfig::startsWith)) {
                    LOGGER.error("{} contains ephemeral volume mapping '{}'!", hdfsConfigName, mappingsFromHdfsConfig);
                    throw new TestFailException(String.format("%s contains ephemeral volume mapping '%s'!", hdfsConfigName, mappingsFromHdfsConfig));
                } else {
                    Log.log(LOGGER, format(" '%s' does not contain the ephemeral mapping '%s', as expected. ", hdfsConfigName, mappingsFromHdfsConfig));
                }
            }
        });
        if (hdfsConfigs.getItems().isEmpty()) {
            LOGGER.error("Namenode mappings are NOT exist!");
            throw new TestFailException("Namenode 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 read config at: '{}'!", apiClient.getBasePath());
        throw new TestFailException("Can't read config 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 10 with RoleConfigGroupsResourceApi

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

the class ClouderaManagerClientActions method checkCmYarnNodemanagerRoleConfigGroups.

private DistroXTestDto checkCmYarnNodemanagerRoleConfigGroups(ApiClient apiClient, DistroXTestDto testDto, String user, String password) {
    // CHECKSTYLE:OFF
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
    // CHECKSTYLE:ON
    try {
        ApiConfigList knoxConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "yarn-NODEMANAGER-BASE", "yarn", "full");
        knoxConfigs.getItems().stream().forEach(knoxConfig -> {
            String knoxConfigName = knoxConfig.getName();
            String mappingsFromKnoxConfig = knoxConfig.getValue();
            if ("yarn_nodemanager_local_dirs".equalsIgnoreCase(knoxConfigName)) {
                if (!mappingsFromKnoxConfig.startsWith("/hadoopfs/ephfs")) {
                    LOGGER.error("{} does not contains the expected '/hadoopfs/ephfs...' mapping!", knoxConfigName);
                    throw new TestFailException(String.format("%s does not contains the expected '/hadoopfs/ephfs...' mapping!", knoxConfigName));
                } else {
                    Log.log(LOGGER, format(" '%s' contains the expected '%s' mapping. ", knoxConfigName, mappingsFromKnoxConfig));
                }
            }
        });
        if (knoxConfigs.getItems().isEmpty()) {
            LOGGER.error("Nodemanager mappings are NOT exist!");
            throw new TestFailException("Nodemanager 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 role configs at: '{}'!", apiClient.getBasePath());
        throw new TestFailException("Can't get role configs 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) ApiException(com.cloudera.api.swagger.client.ApiException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiException(com.cloudera.api.swagger.client.ApiException)

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