Search in sources :

Example 1 with DefaultServiceStatusResponse

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

the class DatabaseServiceCheckDao method healthCheck.

public ServiceStatusResponse healthCheck() {
    String serviceName = "database";
    String componentName = "Kylo Database";
    ServiceComponent component = null;
    Map<String, Object> properties = new HashMap<>();
    try {
        properties = (Map<String, Object>) JdbcUtils.extractDatabaseMetaData(jdbcTemplate.getDataSource(), new DatabaseMetaDataCallback() {

            public Object processMetaData(DatabaseMetaData metadata) throws SQLException, MetaDataAccessException {
                Map<String, Object> properties = new HashMap<>();
                properties.put("database", metadata.getDatabaseProductName());
                properties.put("databaseVersion", metadata.getDatabaseMajorVersion() + "." + metadata.getDatabaseMinorVersion());
                properties.put("url", metadata.getURL());
                return properties;
            }
        });
        String dbVersion = properties.get("database") + " " + properties.get("databaseVersion");
        component = new DefaultServiceComponent.Builder(dbVersion, ServiceComponent.STATE.UP).message(properties.get("database") + " is up.").properties(properties).build();
    } catch (MetaDataAccessException e) {
        component = new DefaultServiceComponent.Builder(componentName, ServiceComponent.STATE.DOWN).exception(e).build();
    }
    return new DefaultServiceStatusResponse(serviceName, Arrays.asList(component));
}
Also used : DatabaseMetaDataCallback(org.springframework.jdbc.support.DatabaseMetaDataCallback) DefaultServiceComponent(com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent) ServiceComponent(com.thinkbiganalytics.servicemonitor.model.ServiceComponent) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) DefaultServiceStatusResponse(com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse) DatabaseMetaData(java.sql.DatabaseMetaData) MetaDataAccessException(org.springframework.jdbc.support.MetaDataAccessException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with DefaultServiceStatusResponse

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

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

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

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

Aggregations

DefaultServiceComponent (com.thinkbiganalytics.servicemonitor.model.DefaultServiceComponent)7 DefaultServiceStatusResponse (com.thinkbiganalytics.servicemonitor.model.DefaultServiceStatusResponse)7 ServiceComponent (com.thinkbiganalytics.servicemonitor.model.ServiceComponent)7 ArrayList (java.util.ArrayList)6 ServiceStatusResponse (com.thinkbiganalytics.servicemonitor.model.ServiceStatusResponse)5 List (java.util.List)5 DefaultServiceAlert (com.thinkbiganalytics.servicemonitor.model.DefaultServiceAlert)4 ServiceAlert (com.thinkbiganalytics.servicemonitor.model.ServiceAlert)4 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