Search in sources :

Example 1 with RouterHealthCheckResult

use of com.cloud.network.RouterHealthCheckResult in project cloudstack by apache.

the class QueryManagerImpl method listRouterHealthChecks.

@Override
public List<RouterHealthCheckResultResponse> listRouterHealthChecks(GetRouterHealthCheckResultsCmd cmd) {
    s_logger.info("Executing health check command " + cmd);
    long routerId = cmd.getRouterId();
    if (!VirtualNetworkApplianceManager.RouterHealthChecksEnabled.value()) {
        throw new CloudRuntimeException("Router health checks are not enabled for router " + routerId);
    }
    if (cmd.shouldPerformFreshChecks()) {
        Pair<Boolean, String> healthChecksresult = routerService.performRouterHealthChecks(routerId);
        if (healthChecksresult == null) {
            throw new CloudRuntimeException("Failed to initiate fresh checks on router.");
        } else if (!healthChecksresult.first()) {
            throw new CloudRuntimeException("Unable to perform fresh checks on router - " + healthChecksresult.second());
        }
    }
    List<RouterHealthCheckResult> result = new ArrayList<>(routerHealthCheckResultDao.getHealthCheckResults(routerId));
    if (result == null || result.size() == 0) {
        throw new CloudRuntimeException("No health check results found for the router. This could happen for " + "a newly created router. Please wait for periodic results to populate or manually call for checks to execute.");
    }
    return responseGenerator.createHealthCheckResponse(_routerDao.findById(routerId), result);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) RouterHealthCheckResult(com.cloud.network.RouterHealthCheckResult)

Example 2 with RouterHealthCheckResult

use of com.cloud.network.RouterHealthCheckResult in project cloudstack by apache.

the class ApiResponseHelper method createHealthCheckResponse.

@Override
public List<RouterHealthCheckResultResponse> createHealthCheckResponse(VirtualMachine router, List<RouterHealthCheckResult> healthCheckResults) {
    List<RouterHealthCheckResultResponse> responses = new ArrayList<>(healthCheckResults.size());
    for (RouterHealthCheckResult hcResult : healthCheckResults) {
        RouterHealthCheckResultResponse healthCheckResponse = new RouterHealthCheckResultResponse();
        healthCheckResponse.setObjectName("routerhealthchecks");
        healthCheckResponse.setCheckName(hcResult.getCheckName());
        healthCheckResponse.setCheckType(hcResult.getCheckType());
        healthCheckResponse.setResult(hcResult.getCheckResult());
        healthCheckResponse.setLastUpdated(hcResult.getLastUpdateTime());
        healthCheckResponse.setDetails(hcResult.getParsedCheckDetails());
        responses.add(healthCheckResponse);
    }
    return responses;
}
Also used : ArrayList(java.util.ArrayList) RouterHealthCheckResultResponse(org.apache.cloudstack.api.response.RouterHealthCheckResultResponse) RouterHealthCheckResult(com.cloud.network.RouterHealthCheckResult)

Example 3 with RouterHealthCheckResult

use of com.cloud.network.RouterHealthCheckResult in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method parseHealthCheckResults.

/**
 * @param checksJson JSON expected is
 *                   {
 *                      checkType1: {
 *                          checkName1: {
 *                              success: true/false,
 *                              lastUpdate: date string,
 *                              lastRunDuration: ms spent on test,
 *                              message: detailed message from check execution
 *                          },
 *                          checkType2: .....
 *                      },
 *                      checkType2: ......
 *                   }
 * @return converts the above JSON into list of RouterHealthCheckResult.
 */
private List<RouterHealthCheckResult> parseHealthCheckResults(final Map<String, Map<String, Map<String, String>>> checksJson, final long routerId) {
    final Map<String, Map<String, RouterHealthCheckResultVO>> checksInDb = getHealthChecksFromDb(routerId);
    List<RouterHealthCheckResult> healthChecks = new ArrayList<>();
    final String lastRunKey = "lastRun";
    for (String checkType : checksJson.keySet()) {
        if (checksJson.get(checkType).containsKey(lastRunKey)) {
            // Log last run of this check type run info
            Map<String, String> lastRun = checksJson.get(checkType).get(lastRunKey);
            s_logger.info("Found check types executed on VR " + checkType + ", start: " + lastRun.get("start") + ", end: " + lastRun.get("end") + ", duration: " + lastRun.get("duration"));
        }
        for (String checkName : checksJson.get(checkType).keySet()) {
            if (lastRunKey.equals(checkName)) {
                continue;
            }
            try {
                final RouterHealthCheckResultVO hcVo = parseHealthCheckVOFromJson(routerId, checkName, checkType, checksJson.get(checkType).get(checkName), checksInDb);
                healthChecks.add(hcVo);
            } catch (Exception ex) {
                s_logger.error("Skipping health check: Exception while parsing check result data for router id " + routerId + ", check type: " + checkType + ", check name: " + checkName + ":" + ex.getLocalizedMessage(), ex);
            }
        }
    }
    return healthChecks;
}
Also used : ArrayList(java.util.ArrayList) RouterHealthCheckResultVO(com.cloud.network.dao.RouterHealthCheckResultVO) Map(java.util.Map) HashMap(java.util.HashMap) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) JsonSyntaxException(com.google.gson.JsonSyntaxException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ParseException(java.text.ParseException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) RouterHealthCheckResult(com.cloud.network.RouterHealthCheckResult)

Aggregations

RouterHealthCheckResult (com.cloud.network.RouterHealthCheckResult)3 ArrayList (java.util.ArrayList)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ConnectionException (com.cloud.exception.ConnectionException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 RouterHealthCheckResultVO (com.cloud.network.dao.RouterHealthCheckResultVO)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigurationException (javax.naming.ConfigurationException)1 RouterHealthCheckResultResponse (org.apache.cloudstack.api.response.RouterHealthCheckResultResponse)1