Search in sources :

Example 1 with ServiceStatusResponse

use of com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse in project kylo by Teradata.

the class AmbariServicesStatusCheck method healthCheck.

/**
 * https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/host-component-resources.md
 *
 * State 	Description                                                                          <br>
 * INIT 	The initial clean state after the component is first created.                        <br>
 * INSTALLING 	In the process of installing the component.                                  <br>
 * INSTALL_FAILED 	The component install failed.                                                <br>
 * INSTALLED 	The component has been installed successfully but is not currently running.  <br>
 * STARTING 	In the process of starting the component.                                    <br>
 * STARTED 	The component has been installed and started.                                        <br>
 * STOPPING 	In the process of stopping the component.                                    <br>
 * UNINSTALLING 	In the process of uninstalling the component.                                <br>
 * UNINSTALLED 	The component has been successfully uninstalled.                             <br>
 * WIPING_OUT 	In the process of wiping out the installed component.                        <br>
 * UPGRADING 	In the process of upgrading the component.                                   <br>
 * MAINTENANCE 	The component has been marked for maintenance.                               <br>
 * UNKNOWN 	The component state can not be determined.                                           <br>
 */
@Override
public List<ServiceStatusResponse> healthCheck() {
    List<ServiceStatusResponse> serviceStatusResponseList = new ArrayList<>();
    // Get the Map of Services and optional Components we are tracking
    Map<String, List<String>> definedServiceComponentMap = ServiceMonitorCheckUtil.getMapOfServiceAndComponents(services);
    if (definedServiceComponentMap != null && !definedServiceComponentMap.isEmpty()) {
        try {
            AmbariClient client = ambariClient;
            // get the Clusers from ambari
            List<String> clusterNames = client.getAmbariClusterNames();
            // get the Service Status from Ambari
            ServiceComponentInfoSummary response = client.getServiceComponentInfo(clusterNames, services);
            // get alert info for these services as well
            AlertSummary alertSummary = client.getAlerts(clusterNames, services);
            // Convert the Ambari Alerts to the Pipeline Controller Alert
            List<ServiceAlert> serviceAlerts = transformAmbariAlert(alertSummary);
            // Convert the Ambari ServiceComponentInfo objects to Pipeline Controller ServiceComponents
            serviceStatusResponseList = transformAmbariServiceComponents(response, serviceAlerts, definedServiceComponentMap);
        } catch (RestClientException e) {
            Throwable cause;
            if (e.getCause() != null) {
                cause = e.getCause();
            } else {
                cause = e;
            }
            ServiceComponent ambariServiceComponent = new DefaultServiceComponent.Builder("Unknown", "Ambari", "Ambari REST_CLIENT", ServiceComponent.STATE.DOWN).exception(cause).build();
            List<ServiceComponent> ambariComponents = new ArrayList<>();
            ambariComponents.add(ambariServiceComponent);
            ServiceStatusResponse serviceStatusResponse = new DefaultServiceStatusResponse(ambariServiceComponent.getServiceName(), ambariComponents);
            serviceStatusResponseList.add(serviceStatusResponse);
            // add the other services as being Warnings
            addAmbariServiceErrors(cause.getMessage(), serviceStatusResponseList, definedServiceComponentMap);
        }
    }
    return serviceStatusResponseList;
}
Also used : ServiceComponentInfoSummary(com.thinkbiganalytics.servicemonitor.rest.model.ambari.ServiceComponentInfoSummary) DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) ServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) ServiceComponent(com.thinkbiganalytics.servicemonitor.model.ServiceComponent) ArrayList(java.util.ArrayList) DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) ServiceAlert(com.thinkbiganalytics.servicemonitor.model.ServiceAlert) DefaultServiceAlert(com.thinkbiganalytics.servicemonitor.model.DefaultServiceAlert) RestClientException(org.springframework.web.client.RestClientException) ArrayList(java.util.ArrayList) List(java.util.List) AlertSummary(com.thinkbiganalytics.servicemonitor.rest.model.ambari.AlertSummary) AmbariClient(com.thinkbiganalytics.servicemonitor.rest.client.ambari.AmbariClient)

Example 2 with ServiceStatusResponse

use of com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse in project kylo by Teradata.

the class AmbariServicesStatusCheck method addAmbariServiceErrors.

/**
 * add ambari Service errors to the supplied list
 */
private void addAmbariServiceErrors(String exceptionMessage, List<ServiceStatusResponse> list, Map<String, List<String>> definedServiceComponentMap) {
    if (definedServiceComponentMap != null && !definedServiceComponentMap.isEmpty()) {
        String message = "Status Unknown. Unable to check service.  Ambari connection error: " + exceptionMessage;
        for (Map.Entry<String, List<String>> entry : definedServiceComponentMap.entrySet()) {
            String serviceName = entry.getKey();
            List<String> componentNames = entry.getValue();
            List<ServiceComponent> components = new ArrayList<>();
            if (componentNames != null && !componentNames.isEmpty()) {
                for (String componentName : componentNames) {
                    if (ServiceMonitorCheckUtil.ALL_COMPONENTS.equals(componentName)) {
                        componentName = serviceName;
                    }
                    ServiceComponent serviceComponent = new DefaultServiceComponent.Builder("Unknown", serviceName, componentName, ServiceComponent.STATE.UNKNOWN).message(message).build();
                    components.add(serviceComponent);
                }
            } else {
                // add the component based uppon the Service Name
                ServiceComponent serviceComponent = new DefaultServiceComponent.Builder("Unknown", serviceName, serviceName, ServiceComponent.STATE.UNKNOWN).message(message).build();
                components.add(serviceComponent);
            }
            ServiceStatusResponse serviceStatusResponse = new DefaultServiceStatusResponse(serviceName, components);
            list.add(serviceStatusResponse);
        }
    }
}
Also used : DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) ServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) ServiceComponent(com.thinkbiganalytics.servicemonitor.model.ServiceComponent) ArrayList(java.util.ArrayList) DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ServiceStatusResponse

use of com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse in project kylo by Teradata.

the class ClouderaServicesStatusCheck method addClouderaServiceErrors.

private void addClouderaServiceErrors(String exceptionMessage, List<ServiceStatusResponse> list, Map<String, List<String>> definedServiceComponentMap) {
    if (definedServiceComponentMap != null && !definedServiceComponentMap.isEmpty()) {
        String message = "Status Unknown. Unable to check service.  Cloudera connection error: " + exceptionMessage;
        for (Map.Entry<String, List<String>> entry : definedServiceComponentMap.entrySet()) {
            String serviceName = entry.getKey();
            List<String> componentNames = entry.getValue();
            List<ServiceComponent> components = new ArrayList<>();
            if (componentNames != null && !componentNames.isEmpty()) {
                for (String componentName : componentNames) {
                    if (ServiceMonitorCheckUtil.ALL_COMPONENTS.equals(componentName)) {
                        componentName = serviceName;
                    }
                    ServiceComponent serviceComponent = new DefaultServiceComponent.Builder(componentName, ServiceComponent.STATE.UNKNOWN).clusterName("UNKNOWN").message(message).build();
                    components.add(serviceComponent);
                }
            } else {
                // add the component based uppon the Service Name
                ServiceComponent serviceComponent = new DefaultServiceComponent.Builder(serviceName, ServiceComponent.STATE.UNKNOWN).clusterName("UNKNOWN").message(message).build();
                components.add(serviceComponent);
            }
            ServiceStatusResponse serviceStatusResponse = new DefaultServiceStatusResponse(serviceName, components);
            list.add(serviceStatusResponse);
        }
    }
}
Also used : DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) ServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) ServiceComponent(com.thinkbiganalytics.servicemonitor.model.ServiceComponent) ArrayList(java.util.ArrayList) DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) ApiClusterList(com.cloudera.api.model.ApiClusterList) ArrayList(java.util.ArrayList) List(java.util.List) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) Map(java.util.Map)

Example 4 with ServiceStatusResponse

use of com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse in project kylo by Teradata.

the class ServiceMonitorManager method doServiceCheck.

/**
 * Run a service check on the system.
 * Each service will run in a separate thread and return status back
 *
 * @return a list of service status objects
 */
public List<ServiceStatusResponse> doServiceCheck() {
    List<ServiceStatusResponse> serviceHealthResponseList = new ArrayList<ServiceStatusResponse>();
    if (totalServices > 0) {
        ExecutorService pool = Executors.newFixedThreadPool(totalServices);
        List<Callable<List<ServiceStatusResponse>>> tasks = new ArrayList<>();
        for (ServiceStatusCheck serviceHealth : services) {
            tasks.add(serviceCheckAsCallable(serviceHealth));
        }
        for (ServicesStatusCheck serviceHealth : servicesHealth) {
            tasks.add(servicesCheckAsCallable(serviceHealth));
        }
        try {
            List<Future<List<ServiceStatusResponse>>> results = pool.invokeAll(tasks);
            for (Future<List<ServiceStatusResponse>> result : results) {
                try {
                    List<ServiceStatusResponse> responses = result.get();
                    if (responses != null) {
                        for (ServiceStatusResponse response : responses) {
                            if (response != null) {
                                serviceHealthResponseList.add(response);
                            }
                        }
                    }
                } catch (Exception e) {
                }
            }
        } catch (Exception e) {
        }
        pool.shutdown();
    }
    notifyAlerts(serviceHealthResponseList);
    return serviceHealthResponseList;
}
Also used : ServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) BeansException(org.springframework.beans.BeansException) ServicesStatusCheck(com.thinkbiganalytics.servicemonitor.check.ServicesStatusCheck) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) ServiceStatusCheck(com.thinkbiganalytics.servicemonitor.check.ServiceStatusCheck)

Example 5 with ServiceStatusResponse

use of com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse in project kylo by Teradata.

the class ClouderaServicesStatusCheck method healthCheck.

@Override
public List<ServiceStatusResponse> healthCheck() {
    List<ServiceStatusResponse> serviceStatusResponseList = new ArrayList<>();
    // Get the Map of Services and optional Components we are tracking
    Map<String, List<String>> definedServiceComponentMap = ServiceMonitorCheckUtil.getMapOfServiceAndComponents(services);
    if (definedServiceComponentMap != null && !definedServiceComponentMap.isEmpty()) {
        ClouderaRootResource rootResource;
        try {
            rootResource = clouderaClient.getClouderaResource();
            if (rootResource == null) {
                throw new Exception("The Cloudera Resource is null... It may still be trying to initialize the Rest Client.");
            }
            ApiClusterList clusters = rootResource.getPopulatedClusterList();
            for (ApiCluster cluster : clusters.getClusters()) {
                String clusterName = cluster.getName();
                List<ApiService> services = cluster.getServices();
                for (ApiService service : services) {
                    List<ServiceComponent> serviceComponents = new ArrayList<>();
                    List<ServiceAlert> alerts = new ArrayList<>();
                    String serviceName = service.getType();
                    if (definedServiceComponentMap.containsKey(serviceName)) {
                        service.getHealthSummary();
                        List<ApiHealthCheck> healthChecks = service.getHealthChecks();
                        for (ApiHealthCheck healthCheck : healthChecks) {
                            alerts.add(apiHealthCheckToServiceAlert(null, healthCheck));
                        }
                        List<ApiRole> roles = service.getRoles();
                        for (ApiRole role : roles) {
                            String roleName = role.getType();
                            role.getHealthSummary();
                            List<ApiHealthCheck> roleHealthChecks = role.getHealthChecks();
                            ServiceComponent.STATE roleState = apiRoleStateToServiceComponentState(role.getRoleState());
                            List<ServiceAlert> componentAlerts = new ArrayList<>();
                            for (ApiHealthCheck healthCheck : roleHealthChecks) {
                                ServiceAlert alert = apiHealthCheckToServiceAlert(roleName, healthCheck);
                                alerts.add(alert);
                                componentAlerts.add(alert);
                            }
                            ServiceComponent component = new DefaultServiceComponent.Builder(roleName, roleState).clusterName(clusterName).message(role.getRoleState().name()).alerts(componentAlerts).build();
                            if (definedServiceComponentMap.containsKey(serviceName) && (definedServiceComponentMap.get(serviceName).contains(ServiceMonitorCheckUtil.ALL_COMPONENTS) || definedServiceComponentMap.get(serviceName).contains(component.getName()))) {
                                serviceComponents.add(component);
                            }
                        }
                        ServiceStatusResponse serviceStatusResponse = new DefaultServiceStatusResponse(serviceName, serviceComponents, alerts);
                        serviceStatusResponseList.add(serviceStatusResponse);
                    }
                }
            }
        } catch (Exception e) {
            Throwable cause;
            if (e.getCause() != null) {
                cause = e.getCause();
            } else {
                cause = e;
            }
            ServiceComponent clouderaServiceComponent = new DefaultServiceComponent.Builder("Cloudera REST_CLIENT", ServiceComponent.STATE.DOWN).serviceName("Cloudera").clusterName("UNKNOWN").exception(cause).build();
            List<ServiceComponent> clouderaComponents = new ArrayList<>();
            clouderaComponents.add(clouderaServiceComponent);
            ServiceStatusResponse serviceStatusResponse = new DefaultServiceStatusResponse(clouderaServiceComponent.getServiceName(), clouderaComponents);
            serviceStatusResponseList.add(serviceStatusResponse);
            // add the other services as being Warnings
            addClouderaServiceErrors(cause.getMessage(), serviceStatusResponseList, definedServiceComponentMap);
        }
    }
    return serviceStatusResponseList;
}
Also used : DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) ServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse) ApiClusterList(com.cloudera.api.model.ApiClusterList) ApiCluster(com.cloudera.api.model.ApiCluster) ArrayList(java.util.ArrayList) ClouderaRootResource(com.thinkbiganalytics.servicemonitor.rest.client.cdh.ClouderaRootResource) DefaultServiceAlert(com.thinkbiganalytics.servicemonitor.model.DefaultServiceAlert) ServiceAlert(com.thinkbiganalytics.servicemonitor.model.ServiceAlert) ApiRole(com.cloudera.api.model.ApiRole) ApiHealthCheck(com.cloudera.api.model.ApiHealthCheck) ApiClusterList(com.cloudera.api.model.ApiClusterList) ArrayList(java.util.ArrayList) List(java.util.List) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) ServiceComponent(com.thinkbiganalytics.servicemonitor.model.ServiceComponent) DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) ApiService(com.cloudera.api.model.ApiService)

Aggregations

ServiceStatusResponse (com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 DefaultServiceComponent (com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent)5 DefaultServiceStatusResponse (com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse)5 ServiceComponent (com.thinkbiganalytics.servicemonitor.model.ServiceComponent)5 DefaultServiceAlert (com.thinkbiganalytics.servicemonitor.model.DefaultServiceAlert)3 ServiceAlert (com.thinkbiganalytics.servicemonitor.model.ServiceAlert)3 Map (java.util.Map)3 ApiClusterList (com.cloudera.api.model.ApiClusterList)2 HashMap (java.util.HashMap)2 ApiCluster (com.cloudera.api.model.ApiCluster)1 ApiHealthCheck (com.cloudera.api.model.ApiHealthCheck)1 ApiRole (com.cloudera.api.model.ApiRole)1 ApiService (com.cloudera.api.model.ApiService)1 ServiceStatusCheck (com.thinkbiganalytics.servicemonitor.check.ServiceStatusCheck)1 ServicesStatusCheck (com.thinkbiganalytics.servicemonitor.check.ServicesStatusCheck)1 AmbariClient (com.thinkbiganalytics.servicemonitor.rest.client.ambari.AmbariClient)1 ClouderaRootResource (com.thinkbiganalytics.servicemonitor.rest.client.cdh.ClouderaRootResource)1 AlertSummary (com.thinkbiganalytics.servicemonitor.rest.model.ambari.AlertSummary)1