Search in sources :

Example 1 with FailureReport

use of com.sequenceiq.cloudbreak.api.model.FailureReport in project cloudbreak by hortonworks.

the class AmbariAgentHealthEvaluator method run.

@Override
public void run() {
    Cluster cluster = clusterService.find(clusterId);
    MDCBuilder.buildMdcContext(cluster);
    LOGGER.info("Checking '{}' alerts.", AMBARI_AGENT_HEARTBEAT);
    try {
        AmbariClient ambariClient = ambariClientProvider.createAmbariClient(cluster);
        List<Map<String, Object>> alertHistory = ambariClient.getAlert(AMBARI_AGENT_HEARTBEAT_DEF_NAME);
        if (!alertHistory.isEmpty()) {
            List<String> hostNamesToRecover = new ArrayList<>();
            for (Map<String, Object> history : alertHistory) {
                String currentState = (String) history.get(ALERT_STATE);
                if (isAlertStateMet(currentState)) {
                    String hostName = (String) history.get(HOST_NAME);
                    hostNamesToRecover.add(hostName);
                    LOGGER.info("Alert: {} is in '{}' state for host '{}'.", AMBARI_AGENT_HEARTBEAT, currentState, hostName);
                }
            }
            if (!hostNamesToRecover.isEmpty()) {
                hostNamesToRecover.forEach(hn -> LOGGER.info("Host to recover: {}", hn));
                CloudbreakClient cbClient = cloudbreakClientConfiguration.cloudbreakClient();
                FailureReport failureReport = new FailureReport();
                failureReport.setFailedNodes(hostNamesToRecover);
                cbClient.clusterEndpoint().failureReport(cluster.getStackId(), failureReport);
            }
        }
    } catch (Exception e) {
        LOGGER.warn(String.format("Failed to retrieve '%s' alerts.", AMBARI_AGENT_HEARTBEAT), e);
        publishEvent(new UpdateFailedEvent(clusterId));
    }
}
Also used : CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.periscope.domain.Cluster) Map(java.util.Map) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 2 with FailureReport

use of com.sequenceiq.cloudbreak.api.model.FailureReport in project cloudbreak by hortonworks.

the class UpdateFailedHandler method reportAmbariServerFailure.

private void reportAmbariServerFailure(Cluster cluster, StackResponse stackResponse, CloudbreakClient cbClient) {
    Optional<InstanceMetaDataJson> pgw = stackResponse.getInstanceGroups().stream().flatMap(ig -> ig.getMetadata().stream()).filter(im -> im.getInstanceType() == InstanceMetadataType.GATEWAY_PRIMARY && im.getInstanceStatus() != InstanceStatus.TERMINATED).findFirst();
    if (pgw.isPresent()) {
        FailureReport failureReport = new FailureReport();
        failureReport.setFailedNodes(Collections.singletonList(pgw.get().getDiscoveryFQDN()));
        try {
            cbClient.clusterEndpoint().failureReport(cluster.getStackId(), failureReport);
        } catch (Exception e) {
            LOGGER.warn("Exception during failure report", e);
        }
    }
}
Also used : Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ApplicationListener(org.springframework.context.ApplicationListener) UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InstanceMetadataType(com.sequenceiq.cloudbreak.api.model.InstanceMetadataType) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) Component(org.springframework.stereotype.Component) Map(java.util.Map) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) MDCBuilder(com.sequenceiq.periscope.log.MDCBuilder) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) ClusterState(com.sequenceiq.periscope.api.model.ClusterState) Optional(java.util.Optional) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) Collections(java.util.Collections) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)

Aggregations

FailureReport (com.sequenceiq.cloudbreak.api.model.FailureReport)2 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)2 Cluster (com.sequenceiq.periscope.domain.Cluster)2 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)2 Map (java.util.Map)2 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)1 InstanceMetaDataJson (com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)1 InstanceMetadataType (com.sequenceiq.cloudbreak.api.model.InstanceMetadataType)1 InstanceStatus (com.sequenceiq.cloudbreak.api.model.InstanceStatus)1 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)1 ClusterState (com.sequenceiq.periscope.api.model.ClusterState)1 MDCBuilder (com.sequenceiq.periscope.log.MDCBuilder)1 ClusterService (com.sequenceiq.periscope.service.ClusterService)1 CloudbreakClientConfiguration (com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Inject (javax.inject.Inject)1