Search in sources :

Example 6 with ApiServiceConfig

use of com.cloudera.api.swagger.model.ApiServiceConfig in project knox by apache.

the class AbstractCMDiscoveryTest method createApiServiceConfigMock.

protected static ApiServiceConfig createApiServiceConfigMock(Map<String, String> configProps) {
    ApiServiceConfig serviceConfig = EasyMock.createNiceMock(ApiServiceConfig.class);
    EasyMock.expect(serviceConfig.getItems()).andReturn(createMockApiConfigs(configProps)).anyTimes();
    EasyMock.replay(serviceConfig);
    return serviceConfig;
}
Also used : ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig)

Example 7 with ApiServiceConfig

use of com.cloudera.api.swagger.model.ApiServiceConfig in project knox by apache.

the class ClouderaManagerServiceDiscovery method getServiceConfig.

private ApiServiceConfig getServiceConfig(ServiceDiscoveryConfig serviceDiscoveryConfig, ServicesResourceApi servicesResourceApi, ApiService service) {
    log.lookupServiceConfigsFromRepository();
    // first, try in the service discovery repository
    ApiServiceConfig serviceConfig = repository.getServiceConfig(serviceDiscoveryConfig, service);
    if (serviceConfig == null) {
        // no service config in the repository -> query CM
        try {
            log.lookupServiceConfigsFromCM();
            serviceConfig = servicesResourceApi.readServiceConfig(serviceDiscoveryConfig.getCluster(), service.getName(), VIEW_FULL);
            // make sure that service config is populated in the service discovery repository to avoid subsequent CM calls
            repository.addServiceConfig(serviceDiscoveryConfig, service, serviceConfig);
        } catch (Exception e) {
            log.failedToAccessServiceConfigs(serviceDiscoveryConfig.getCluster(), e);
        }
    }
    return serviceConfig;
}
Also used : ApiException(com.cloudera.api.swagger.client.ApiException) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig)

Example 8 with ApiServiceConfig

use of com.cloudera.api.swagger.model.ApiServiceConfig in project knox by apache.

the class ClouderaManagerServiceDiscoveryTest method createMockApiServiceConfig.

private static ApiServiceConfig createMockApiServiceConfig(Map<String, String> properties) {
    ApiServiceConfig serviceConfig = EasyMock.createNiceMock(ApiServiceConfig.class);
    List<ApiConfig> serviceConfigs = new ArrayList<>();
    int i = 0;
    for (Map.Entry<String, String> property : properties.entrySet()) {
        ApiConfig config = EasyMock.createNiceMock(ApiConfig.class);
        if (i++ % 2 == 0) {
            EasyMock.expect(config.getName()).andReturn(property.getKey()).anyTimes();
        } else {
            EasyMock.expect(config.getRelatedName()).andReturn(property.getKey()).anyTimes();
        }
        EasyMock.expect(config.getValue()).andReturn(property.getValue()).anyTimes();
        EasyMock.replay(config);
        serviceConfigs.add(config);
    }
    EasyMock.expect(serviceConfig.getItems()).andReturn(serviceConfigs).anyTimes();
    EasyMock.replay(serviceConfig);
    return serviceConfig;
}
Also used : ArrayList(java.util.ArrayList) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) Map(java.util.Map) HashMap(java.util.HashMap) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig)

Example 9 with ApiServiceConfig

use of com.cloudera.api.swagger.model.ApiServiceConfig in project knox by apache.

the class ClouderaManagerServiceDiscoveryRepositoryTest method testAddServiceConfig.

@Test
public void testAddServiceConfig() throws Exception {
    final String serviceName = "HDFS-1";
    final String serviceConfigName = "myServiceConfigName";
    final String serviceConfigValue = "myServiceConfigValue";
    repository.registerCluster(serviceDiscoveryConfig);
    final ApiService service = EasyMock.createNiceMock(ApiService.class);
    EasyMock.expect(service.getName()).andReturn(serviceName).anyTimes();
    final ApiConfig serviceConfig = EasyMock.createNiceMock(ApiConfig.class);
    EasyMock.expect(serviceConfig.getName()).andReturn(serviceConfigName).anyTimes();
    EasyMock.expect(serviceConfig.getValue()).andReturn(serviceConfigValue).anyTimes();
    final ApiServiceConfig serviceConfigs = EasyMock.createNiceMock(ApiServiceConfig.class);
    EasyMock.expect(serviceConfigs.getItems()).andReturn(Collections.singletonList(serviceConfig)).anyTimes();
    EasyMock.replay(service, serviceConfig, serviceConfigs);
    assertFalse(containsServiceConfig(service, serviceConfigName, serviceConfigValue));
    repository.addService(serviceDiscoveryConfig, service);
    repository.addServiceConfig(serviceDiscoveryConfig, service, serviceConfigs);
    assertTrue(containsServiceConfig(service, serviceConfigName, serviceConfigValue));
}
Also used : ApiService(com.cloudera.api.swagger.model.ApiService) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Test(org.junit.Test)

Aggregations

ApiServiceConfig (com.cloudera.api.swagger.model.ApiServiceConfig)9 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)4 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)3 ApiRole (com.cloudera.api.swagger.model.ApiRole)3 ApiRoleList (com.cloudera.api.swagger.model.ApiRoleList)3 ApiService (com.cloudera.api.swagger.model.ApiService)3 RolesResourceApi (com.cloudera.api.swagger.RolesResourceApi)2 ApiException (com.cloudera.api.swagger.client.ApiException)2 ApiConfig (com.cloudera.api.swagger.model.ApiConfig)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)1 ServiceDiscovery (org.apache.knox.gateway.topology.discovery.ServiceDiscovery)1 ServiceDiscoveryConfig (org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig)1 DiscoveryApiClient (org.apache.knox.gateway.topology.discovery.cm.DiscoveryApiClient)1