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);
}
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;
}
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;
}
Aggregations