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;
}
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;
}
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;
}
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));
}
Aggregations