Search in sources :

Example 6 with ApiException

use of com.cloudera.api.swagger.client.ApiException 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)

Example 7 with ApiException

use of com.cloudera.api.swagger.client.ApiException in project knox by apache.

the class PollingConfigurationAnalyzer method queryEvents.

/**
 * Query the ClouderaManager instance associated with the specified client for any service start events in the
 * specified cluster since the specified time.
 *
 * @param client      A ClouderaManager API client.
 * @param clusterName The name of the cluster for which events should be queried.
 * @param since       The ISO8601 timestamp indicating from which time to query.
 *
 * @return A List of ApiEvent objects representing the relevant events since the specified time.
 */
protected List<ApiEvent> queryEvents(final ApiClient client, final String clusterName, final String since) {
    List<ApiEvent> events = new ArrayList<>();
    // Setup the query for events
    String timeFilter = (since != null) ? String.format(Locale.ROOT, EVENTS_QUERY_TIMESTAMP_FORMAT, since) : "";
    String queryString = String.format(Locale.ROOT, EVENTS_QUERY_FORMAT, clusterName, timeFilter);
    try {
        // giving 'null' as maximum result size results in fetching all events from CM within the given time interval
        ApiEventQueryResult eventsResult = (new EventsResourceApi(client)).readEvents(null, queryString, 0);
        events.addAll(eventsResult.getItems());
    } catch (ApiException e) {
        log.clouderaManagerEventsAPIError(e);
    }
    return events;
}
Also used : ApiEvent(com.cloudera.api.swagger.model.ApiEvent) ArrayList(java.util.ArrayList) ApiEventQueryResult(com.cloudera.api.swagger.model.ApiEventQueryResult) EventsResourceApi(com.cloudera.api.swagger.EventsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

ApiException (com.cloudera.api.swagger.client.ApiException)7 ArrayList (java.util.ArrayList)3 ApiService (com.cloudera.api.swagger.model.ApiService)2 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)2 HashMap (java.util.HashMap)2 EventsResourceApi (com.cloudera.api.swagger.EventsResourceApi)1 RolesResourceApi (com.cloudera.api.swagger.RolesResourceApi)1 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiCluster (com.cloudera.api.swagger.model.ApiCluster)1 ApiClusterList (com.cloudera.api.swagger.model.ApiClusterList)1 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)1 ApiEvent (com.cloudera.api.swagger.model.ApiEvent)1 ApiEventQueryResult (com.cloudera.api.swagger.model.ApiEventQueryResult)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 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1