use of com.cloudera.api.swagger.model.ApiService in project tbd-studio-se by Talend.
the class HadoopCMCluster method getHostedServices.
/*
* (non-Javadoc)
*
* @see org.talend.repository.hadoopcluster.configurator.HadoopCluster#getHostedServices()
*/
@Override
public Map<HadoopHostedService, HadoopClusterService> getHostedServices() {
Map<HadoopHostedService, HadoopClusterService> servicesMapping = new HashMap<HadoopHostedService, HadoopClusterService>();
ApiServiceList services;
try {
services = this.serviceAPI.readServices(this.clusterName, DEFAULT_VIEW_NAME);
for (ApiService service : services.getItems()) {
if (HadoopHostedService.isSupport(service.getType())) {
HadoopCMClusterService clusterService = new HadoopCMClusterService(this.clusterName, service.getName(), this.serviceAPI, blacklistParams);
if (clusterService.hasConfigurations()) {
servicesMapping.put(HadoopHostedService.fromString(service.getType()), clusterService);
}
}
}
} catch (ApiException e) {
throw new RuntimeException(e);
}
return servicesMapping;
}
use of com.cloudera.api.swagger.model.ApiService in project knox by apache.
the class ClouderaManagerServiceDiscovery method discoverCluster.
private ClouderaManagerCluster discoverCluster(DiscoveryApiClient client, String clusterName, Collection<String> includedServices) throws ApiException {
ServicesResourceApi servicesResourceApi = new ServicesResourceApi(client);
RolesResourceApi rolesResourceApi = new RolesResourceApi(client);
log.discoveringCluster(clusterName);
repository.registerCluster(client.getConfig());
Set<ServiceModel> serviceModels = new HashSet<>();
List<ApiService> serviceList = getClusterServices(client.getConfig(), servicesResourceApi);
if (serviceList != null) {
/*
Since Cloudera Manager does not have a service for itself, we will add a skeleton CM
service so that we can add CM service to topology when auto-discovery is
turned on and CM service is selected in the descriptor
*/
final ApiService cmService = new ApiService();
cmService.setName(CM_SERVICE_TYPE.toLowerCase(Locale.ROOT));
cmService.setType(CM_SERVICE_TYPE);
serviceList.add(cmService);
for (ApiService service : serviceList) {
final List<ServiceModelGenerator> modelGenerators = serviceModelGenerators.get(service.getType());
if (shouldSkipServiceDiscovery(modelGenerators, includedServices)) {
log.skipServiceDiscovery(service.getName(), service.getType());
continue;
}
log.discoveringService(service.getName(), service.getType());
ApiServiceConfig serviceConfig = null;
/* no reason to check service config for CM service */
if (!CM_SERVICE_TYPE.equals(service.getType())) {
serviceConfig = getServiceConfig(client.getConfig(), servicesResourceApi, service);
}
ApiRoleList roleList = getRoles(client.getConfig(), rolesResourceApi, clusterName, service);
if (roleList != null) {
for (ApiRole role : roleList.getItems()) {
String roleName = role.getName();
log.discoveringServiceRole(roleName, role.getType());
ApiConfigList roleConfig = null;
/* no reason to check role config for CM service */
if (!CM_SERVICE_TYPE.equals(service.getType())) {
roleConfig = getRoleConfig(client.getConfig(), rolesResourceApi, service, role);
}
if (modelGenerators != null) {
for (ServiceModelGenerator serviceModelGenerator : modelGenerators) {
ServiceModelGeneratorHandleResponse response = serviceModelGenerator.handles(service, serviceConfig, role, roleConfig);
if (response.handled()) {
serviceModelGenerator.setApiClient(client);
ServiceModel serviceModel = serviceModelGenerator.generateService(service, serviceConfig, role, roleConfig);
serviceModels.add(serviceModel);
} else if (!response.getConfigurationIssues().isEmpty()) {
log.serviceRoleHasConfigurationIssues(roleName, String.join(";", response.getConfigurationIssues()));
}
}
}
log.discoveredServiceRole(roleName, role.getType());
}
}
log.discoveredService(service.getName(), service.getType());
}
ClouderaManagerCluster cluster = new ClouderaManagerCluster(clusterName);
cluster.addServiceModels(serviceModels);
return cluster;
}
return null;
}
use of com.cloudera.api.swagger.model.ApiService in project knox by apache.
the class ClouderaManagerServiceDiscoveryTest method doTestDiscovery.
private ServiceDiscovery.Cluster doTestDiscovery(final String hostName, final String serviceName, final String serviceType, final String roleName, final String roleType, final Map<String, String> serviceProperties, final Map<String, String> roleProperties) {
final String clusterName = "cluster-1";
GatewayConfig gwConf = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.replay(gwConf);
ServiceDiscoveryConfig sdConfig = createMockDiscoveryConfig(clusterName);
// Create the test client for providing test response content
TestDiscoveryApiClient mockClient = new TestDiscoveryApiClient(sdConfig, null, null);
// Prepare the service list response for the cluster
ApiServiceList serviceList = EasyMock.createNiceMock(ApiServiceList.class);
final List<ApiService> apiServiceList = new ArrayList<>();
apiServiceList.add(createMockApiService(serviceName, serviceType, clusterName));
EasyMock.expect(serviceList.getItems()).andReturn(apiServiceList).anyTimes();
EasyMock.replay(serviceList);
mockClient.addResponse(ApiServiceList.class, new TestApiServiceListResponse(serviceList));
// Prepare the service config response for the cluster
ApiServiceConfig serviceConfig = createMockApiServiceConfig(serviceProperties);
mockClient.addResponse(ApiServiceConfig.class, new TestApiServiceConfigResponse(serviceConfig));
// Prepare the role
ApiRole role = createMockApiRole(roleName, roleType, hostName);
ApiRoleList roleList = EasyMock.createNiceMock(ApiRoleList.class);
EasyMock.expect(roleList.getItems()).andReturn(Collections.singletonList(role)).anyTimes();
EasyMock.replay(roleList);
mockClient.addResponse(ApiRoleList.class, new TestApiRoleListResponse(roleList));
// Configure the role
ApiConfigList roleConfigList = createMockApiConfigList(roleProperties);
mockClient.addResponse(ApiConfigList.class, new TestApiConfigListResponse(roleConfigList));
// Invoke the service discovery
ClouderaManagerServiceDiscovery cmsd = new ClouderaManagerServiceDiscovery(true, gwConf);
// to clear the repo
cmsd.onConfigurationChange(null, null);
ServiceDiscovery.Cluster cluster = cmsd.discover(gwConf, sdConfig, clusterName, Collections.emptySet(), mockClient);
assertNotNull(cluster);
assertEquals(clusterName, cluster.getName());
return cluster;
}
use of com.cloudera.api.swagger.model.ApiService in project knox by apache.
the class ClouderaManagerServiceDiscoveryTest method createMockApiService.
private static ApiService createMockApiService(String name, String type, String clusterName) {
ApiService s = EasyMock.createNiceMock(ApiService.class);
EasyMock.expect(s.getName()).andReturn(name).anyTimes();
EasyMock.expect(s.getType()).andReturn(type).anyTimes();
ApiClusterRef clusterRef = EasyMock.createNiceMock(ApiClusterRef.class);
EasyMock.expect(clusterRef.getClusterName()).andReturn(clusterName).anyTimes();
EasyMock.replay(clusterRef);
EasyMock.expect(s.getClusterRef()).andReturn(clusterRef).anyTimes();
EasyMock.replay(s);
return s;
}
use of com.cloudera.api.swagger.model.ApiService in project knox by apache.
the class AbstractCMDiscoveryTest method createApiServiceMock.
protected static ApiService createApiServiceMock(final String serviceName, final String serviceType) {
ApiService service = EasyMock.createNiceMock(ApiService.class);
EasyMock.expect(service.getName()).andReturn(serviceName).anyTimes();
EasyMock.expect(service.getType()).andReturn(serviceType).anyTimes();
EasyMock.replay(service);
return service;
}
Aggregations