Search in sources :

Example 1 with ApiServiceList

use of com.cloudera.api.swagger.model.ApiServiceList 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;
}
Also used : HadoopHostedService(org.talend.repository.hadoopcluster.configurator.HadoopHostedService) HashMap(java.util.HashMap) ApiService(com.cloudera.api.swagger.model.ApiService) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) HadoopClusterService(org.talend.repository.hadoopcluster.configurator.HadoopClusterService) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 2 with ApiServiceList

use of com.cloudera.api.swagger.model.ApiServiceList 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;
}
Also used : ArrayList(java.util.ArrayList) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig) ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRoleList(com.cloudera.api.swagger.model.ApiRoleList) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) ServiceDiscovery(org.apache.knox.gateway.topology.discovery.ServiceDiscovery)

Example 3 with ApiServiceList

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

the class ClouderaManagerServiceDiscovery method getClusterServices.

private List<ApiService> getClusterServices(ServiceDiscoveryConfig serviceDiscoveryConfig, ServicesResourceApi servicesResourceApi) {
    log.lookupClusterServicesFromRepository();
    List<ApiService> services = repository.getServices(serviceDiscoveryConfig);
    if (services == null || services.isEmpty()) {
        try {
            log.lookupClusterServicesFromCM();
            final ApiServiceList serviceList = servicesResourceApi.readServices(serviceDiscoveryConfig.getCluster(), VIEW_SUMMARY);
            services = serviceList == null ? new ArrayList<>() : serviceList.getItems();
            // make sure that services are populated in the repository
            services.forEach(service -> repository.addService(serviceDiscoveryConfig, service));
        } catch (ApiException e) {
            log.failedToAccessServiceConfigs(serviceDiscoveryConfig.getCluster(), e);
        }
    }
    return services;
}
Also used : ApiService(com.cloudera.api.swagger.model.ApiService) ArrayList(java.util.ArrayList) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

ApiService (com.cloudera.api.swagger.model.ApiService)3 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)3 ApiException (com.cloudera.api.swagger.client.ApiException)2 ArrayList (java.util.ArrayList)2 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)1 ApiRole (com.cloudera.api.swagger.model.ApiRole)1 ApiRoleList (com.cloudera.api.swagger.model.ApiRoleList)1 ApiServiceConfig (com.cloudera.api.swagger.model.ApiServiceConfig)1 HashMap (java.util.HashMap)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 HadoopClusterService (org.talend.repository.hadoopcluster.configurator.HadoopClusterService)1 HadoopHostedService (org.talend.repository.hadoopcluster.configurator.HadoopHostedService)1