Search in sources :

Example 6 with ServiceComponent

use of com.thinkbiganalytics.servicemonitor.model.ServiceComponent 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 7 with ServiceComponent

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

the class ClusterServiceStatusCheck method healthCheck.

public ServiceStatusResponse healthCheck() {
    String serviceName = "Kylo Cluster";
    String MEMBER_COUNT_PROPERTY = "member count";
    String MEMBERS_PROPERTY = "members";
    Map<String, Object> properties = new HashMap<>();
    boolean isClustered = clusterService.isClustered();
    boolean valid = true;
    List<ServiceComponent> components = new ArrayList<>();
    String serviceMessage = "";
    List<ServiceAlert> serviceAlerts = new ArrayList<>();
    if (isClustered) {
        int memberCount = clusterService.getMembersAsString().size();
        List<String> members = clusterService.getMembersAsString();
        if (StringUtils.isNotBlank(expectedNodes)) {
            try {
                int expectedNodeCount = Integer.valueOf(expectedNodes);
                if (expectedNodeCount != memberCount) {
                    valid = false;
                    serviceMessage = "Error.  Missing " + (expectedNodeCount - memberCount) + " nodes. ";
                } else {
                    serviceMessage = " All " + expectedNodeCount + " nodes are connected. ";
                }
            } catch (NumberFormatException e) {
                valid = false;
                serviceMessage = "  Unable to validate the expected kylo node count.  Ensure the 'kylo.cluster.nodeCount' property is set to a valid number.";
            }
        }
        final boolean isValid = valid;
        final String finalServiceMessage = serviceMessage;
        members.stream().forEach(member -> {
            String componentName = member;
            boolean currentlyConnected = member.equalsIgnoreCase(clusterService.getAddressAsString());
            properties.put(MEMBER_COUNT_PROPERTY, memberCount);
            properties.put(MEMBERS_PROPERTY, members.toString());
            String message = "There are " + memberCount + " members in the cluster. ";
            if (currentlyConnected) {
                message = "Currently connected to this node. " + message;
            }
            ServiceAlert alert = null;
            if (isValid) {
                message = finalServiceMessage + message;
            } else {
                alert = new DefaultServiceAlert();
                alert.setLabel(componentName);
                alert.setServiceName(serviceName);
                alert.setComponentName(componentName);
                alert.setMessage(finalServiceMessage);
                alert.setState(ServiceAlert.STATE.CRITICAL);
            }
            ServiceComponent component = new DefaultServiceComponent.Builder(componentName, isValid ? ServiceComponent.STATE.UP : ServiceComponent.STATE.DOWN).message(message).properties(properties).addAlert(alert).build();
            components.add(component);
        });
    } else {
        serviceMessage = "Kylo is not configured to be running as a cluster";
        ServiceComponent component = new DefaultServiceComponent.Builder(serviceName, ServiceComponent.STATE.UP).message(serviceMessage).properties(properties).build();
        components.add(component);
    }
    return new DefaultServiceStatusResponse(serviceName, components);
}
Also used : HashMap(java.util.HashMap) 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) DefaultServiceAlert(com.thinkbiganalytics.servicemonitor.model.DefaultServiceAlert) ServiceAlert(com.thinkbiganalytics.servicemonitor.model.ServiceAlert) DefaultServiceAlert(com.thinkbiganalytics.servicemonitor.model.DefaultServiceAlert)

Example 8 with ServiceComponent

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

the class AmbariServicesStatusCheck method transformAmbariServiceComponents.

/**
 * Convert Ambari ServiceComponentInfo into  ServiceComponent objects
 */
private List<ServiceStatusResponse> transformAmbariServiceComponents(ServiceComponentInfoSummary ambariServiceComponents, List<ServiceAlert> serviceAlerts, Map<String, List<String>> definedServiceComponentMap) {
    List<ServiceStatusResponse> list = new ArrayList<>();
    if (ambariServiceComponents != null) {
        Map<String, List<ServiceComponent>> serviceComponentMap = new HashMap<>();
        for (ServiceComponentInfoItem item : ambariServiceComponents.getItems()) {
            ServiceComponent.STATE state = getServiceComponentState(item);
            String message = item.getServiceComponentInfo().getState();
            String name = item.getServiceComponentInfo().getComponentName();
            String serviceName = item.getServiceComponentInfo().getServiceName();
            String clusterName = item.getServiceComponentInfo().getClusterName();
            ServiceComponent component = new DefaultServiceComponent.Builder(clusterName, serviceName, name, state).alerts(alertsForComponent(serviceAlerts, item.getServiceComponentInfo().getComponentName())).message(message).build();
            if (!serviceComponentMap.containsKey(component.getServiceName())) {
                serviceComponentMap.put(component.getServiceName(), new ArrayList<>());
            }
            if (definedServiceComponentMap.get(component.getServiceName()).contains(ServiceMonitorCheckUtil.ALL_COMPONENTS) || definedServiceComponentMap.get(component.getServiceName()).contains(component.getName())) {
                serviceComponentMap.get(component.getServiceName()).add(component);
            }
        }
        // build the response
        for (Map.Entry<String, List<ServiceComponent>> entry : serviceComponentMap.entrySet()) {
            List<ServiceAlert> alertsForService = alertsForService(serviceAlerts, entry.getKey());
            ServiceStatusResponse serviceStatusResponse = new DefaultServiceStatusResponse(entry.getKey(), entry.getValue(), alertsForService);
            if (ServiceStatusResponse.STATE.DOWN.equals(serviceStatusResponse.getState())) {
                notifyServiceDown(serviceStatusResponse);
            } else if (ServiceStatusResponse.STATE.UP.equals(serviceStatusResponse.getState())) {
                notifyServiceUp(serviceStatusResponse);
            }
            list.add(serviceStatusResponse);
        }
    }
    return list;
}
Also used : DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) ServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse) HashMap(java.util.HashMap) 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) ServiceComponentInfoItem(com.thinkbiganalytics.servicemonitor.rest.model.ambari.ServiceComponentInfoItem) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with ServiceComponent

use of com.thinkbiganalytics.servicemonitor.model.ServiceComponent 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

DefaultServiceComponent (com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent)9 ServiceComponent (com.thinkbiganalytics.servicemonitor.model.ServiceComponent)9 DefaultServiceStatusResponse (com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse)7 ArrayList (java.util.ArrayList)6 DefaultServiceAlert (com.thinkbiganalytics.servicemonitor.model.DefaultServiceAlert)5 ServiceAlert (com.thinkbiganalytics.servicemonitor.model.ServiceAlert)5 ServiceStatusResponse (com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse)5 List (java.util.List)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ApiClusterList (com.cloudera.api.model.ApiClusterList)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 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 ServiceComponentInfoItem (com.thinkbiganalytics.servicemonitor.rest.model.ambari.ServiceComponentInfoItem)1 ServiceComponentInfoSummary (com.thinkbiganalytics.servicemonitor.rest.model.ambari.ServiceComponentInfoSummary)1