use of com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method performRouterHealthChecks.
@Override
public Pair<Boolean, String> performRouterHealthChecks(long routerId) {
DomainRouterVO router = _routerDao.findById(routerId);
if (router == null) {
throw new CloudRuntimeException("Unable to find router with id " + routerId);
}
if (!RouterHealthChecksEnabled.value()) {
throw new CloudRuntimeException("Router health checks are not enabled for router: " + router);
}
s_logger.info("Running health check results for router " + router.getUuid());
GetRouterMonitorResultsAnswer answer = null;
String resultDetails = "";
boolean success = true;
// Step 1: Perform basic tests to check the connectivity and file system on router
answer = performBasicTestsOnRouter(router);
if (answer == null) {
s_logger.debug("No results received for the basic tests on router: " + router);
resultDetails = "Basic tests results unavailable";
success = false;
} else if (!answer.getResult()) {
s_logger.debug("Basic tests failed on router: " + router);
resultDetails = "Basic tests failed - " + answer.getMonitoringResults();
success = false;
} else {
// Step 2: Update health check data on router and perform and retrieve health checks on router
if (!updateRouterHealthChecksConfig(router)) {
s_logger.warn("Unable to update health check config for fresh run successfully for router: " + router + ", so trying to fetch last result.");
success = false;
answer = fetchAndUpdateRouterHealthChecks(router, false);
} else {
s_logger.info("Successfully updated health check config for fresh run successfully for router: " + router);
answer = fetchAndUpdateRouterHealthChecks(router, true);
}
if (answer == null) {
resultDetails = "Failed to fetch and update health checks";
success = false;
} else if (!answer.getResult()) {
resultDetails = "Get health checks failed - " + answer.getMonitoringResults();
success = false;
}
}
// Step 3: Update health checks values in database. We do this irrespective of new health check config.
List<String> failingChecks = getFailingChecks(router, answer);
handleFailingChecks(router, failingChecks);
return new Pair<Boolean, String>(success, resultDetails);
}
use of com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer in project cloudstack by apache.
the class VirtualRoutingResource method execute.
private GetRouterMonitorResultsAnswer execute(GetRouterMonitorResultsCommand cmd) {
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
Pair<Boolean, String> fileSystemTestResult = checkRouterFileSystem(routerIp);
if (!fileSystemTestResult.first()) {
return new GetRouterMonitorResultsAnswer(cmd, false, null, fileSystemTestResult.second());
}
if (cmd.shouldValidateBasicTestsOnly()) {
// Basic tests (connectivity and file system checks) are already validated
return new GetRouterMonitorResultsAnswer(cmd, true, null, "success");
}
String args = cmd.shouldPerformFreshChecks() ? "true" : "false";
s_logger.info("Fetching health check result for " + routerIp + " and executing fresh checks: " + args);
ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.ROUTER_MONITOR_RESULTS, args);
if (!result.isSuccess()) {
s_logger.warn("Result of " + cmd + " failed with details: " + result.getDetails());
return new GetRouterMonitorResultsAnswer(cmd, false, null, result.getDetails());
}
if (result.getDetails().isEmpty()) {
s_logger.warn("Result of " + cmd + " received no details.");
return new GetRouterMonitorResultsAnswer(cmd, false, null, "No results available.");
}
return parseLinesForHealthChecks(cmd, result.getDetails());
}
use of com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method performBasicTestsOnRouter.
private GetRouterMonitorResultsAnswer performBasicTestsOnRouter(DomainRouterVO router) {
if (!RouterHealthChecksEnabled.value()) {
return null;
}
String controlIP = _routerControlHelper.getRouterControlIp(router.getId());
if (StringUtils.isNotBlank(controlIP) && !controlIP.equals("0.0.0.0")) {
final GetRouterMonitorResultsCommand command = new GetRouterMonitorResultsCommand(false, true);
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlIP);
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
try {
final Answer answer = _agentMgr.easySend(router.getHostId(), command);
if (answer == null) {
s_logger.warn("Unable to fetch basic router test results data from router " + router.getHostName());
return null;
}
if (answer instanceof GetRouterMonitorResultsAnswer) {
return (GetRouterMonitorResultsAnswer) answer;
} else {
s_logger.warn("Unable to fetch basic router test results from router " + router.getHostName() + " Received answer " + answer.getDetails());
return new GetRouterMonitorResultsAnswer(command, false, null, answer.getDetails());
}
} catch (final Exception e) {
s_logger.warn("Error while performing basic tests on router: " + router.getInstanceName(), e);
return null;
}
}
return null;
}
use of com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method fetchAndUpdateRouterHealthChecks.
private GetRouterMonitorResultsAnswer fetchAndUpdateRouterHealthChecks(DomainRouterVO router, boolean performFreshChecks) {
if (!RouterHealthChecksEnabled.value()) {
return null;
}
String controlIP = _routerControlHelper.getRouterControlIp(router.getId());
if (StringUtils.isNotBlank(controlIP) && !controlIP.equals("0.0.0.0")) {
final GetRouterMonitorResultsCommand command = new GetRouterMonitorResultsCommand(performFreshChecks, false);
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlIP);
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
try {
final Answer answer = _agentMgr.easySend(router.getHostId(), command);
if (answer == null) {
s_logger.warn("Unable to fetch monitoring results data from router " + router.getHostName());
return null;
}
if (answer instanceof GetRouterMonitorResultsAnswer) {
return (GetRouterMonitorResultsAnswer) answer;
} else {
s_logger.warn("Unable to fetch health checks results to router " + router.getHostName() + " Received answer " + answer.getDetails());
return new GetRouterMonitorResultsAnswer(command, false, null, answer.getDetails());
}
} catch (final Exception e) {
s_logger.warn("Error while collecting alerts from router: " + router.getInstanceName(), e);
return null;
}
}
return null;
}
Aggregations