use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method updateRouterHealthChecksConfig.
/**
* Updates router health check config to the virtual router that it uses for health checks.
* @param router - the router ID that data needs to be sent to.
* @return success of whether data was sent or not
*/
private boolean updateRouterHealthChecksConfig(DomainRouterVO router) {
if (!RouterHealthChecksEnabled.value()) {
return false;
}
String controlIP = _routerControlHelper.getRouterControlIp(router.getId());
if (StringUtils.isBlank(controlIP) || controlIP.equals("0.0.0.0")) {
s_logger.debug("Skipping update data on router " + router.getUuid() + " because controlIp is not correct.");
return false;
}
s_logger.info("Updating data for router health checks for router " + router.getUuid());
Answer origAnswer = null;
try {
SetMonitorServiceCommand command = createMonitorServiceCommand(router, null, true, true);
origAnswer = _agentMgr.easySend(router.getHostId(), command);
} catch (final Exception e) {
s_logger.error("Error while sending update data for health check to router: " + router.getInstanceName(), e);
return false;
}
if (origAnswer == null) {
s_logger.error("Unable to update health checks data to router " + router.getHostName());
return false;
}
GroupAnswer answer = null;
if (origAnswer instanceof GroupAnswer) {
answer = (GroupAnswer) origAnswer;
} else {
s_logger.error("Unable to update health checks data to router " + router.getHostName() + " Received answer " + origAnswer.getDetails());
return false;
}
if (!answer.getResult()) {
s_logger.error("Unable to update health checks data to router " + router.getHostName() + ", details : " + answer.getDetails());
}
return answer.getResult();
}
use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.
the class VirtualRoutingResourceTest method testSetPortForwardingRulesCommand.
@Test
public void testSetPortForwardingRulesCommand() {
final SetPortForwardingRulesCommand cmd = generateSetPortForwardingRulesCommand();
// Reset rule check count
_count = 0;
final Answer answer = _resource.executeRequest(cmd);
assertTrue(answer instanceof GroupAnswer);
assertEquals(((GroupAnswer) answer).getResults().length, 2);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.
the class VirtualRoutingResourceTest method testIpAssocCommand.
@Test
public void testIpAssocCommand() {
final IpAssocCommand cmd = generateIpAssocCommand();
_count = 0;
final Answer answer = _resource.executeRequest(cmd);
assertTrue(answer instanceof GroupAnswer);
assertEquals(2, ((GroupAnswer) answer).getResults().length);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.routing.GroupAnswer in project cosmic by MissionCriticalCloud.
the class VirtualRoutingResource method applyConfig.
private Answer applyConfig(final NetworkElementCommand cmd, final List<ConfigItem> cfg) {
if (cfg.isEmpty()) {
return new Answer(cmd, true, "Nothing to do");
}
final List<ExecutionResult> results = new ArrayList<>();
final List<String> details = new ArrayList<>();
boolean finalResult = false;
for (final ConfigItem configItem : cfg) {
final long startTimestamp = System.currentTimeMillis();
ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), configItem);
if (s_logger.isDebugEnabled()) {
final long elapsed = System.currentTimeMillis() - startTimestamp;
s_logger.debug("Processing " + configItem + " took " + elapsed + "ms");
}
if (result == null) {
result = new ExecutionResult(false, "null execution result");
}
results.add(result);
details.add(configItem.getInfo() + (result.isSuccess() ? " - success: " : " - failed: ") + result.getDetails());
finalResult = result.isSuccess();
}
// Not sure why this matters, but log it anyway
if (cmd.getAnswersCount() != results.size()) {
s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size());
}
if (results.size() == 1) {
return new Answer(cmd, finalResult, results.get(0).getDetails());
} else {
return new GroupAnswer(cmd, finalResult, results.size(), details.toArray(new String[details.size()]));
}
}
use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.
the class VirtualRoutingResource method applyConfig.
private Answer applyConfig(NetworkElementCommand cmd, List<ConfigItem> cfg) {
if (cfg.isEmpty()) {
return new Answer(cmd, true, "Nothing to do");
}
List<ExecutionResult> results = new ArrayList<ExecutionResult>();
List<String> details = new ArrayList<String>();
boolean finalResult = false;
for (ConfigItem configItem : cfg) {
long startTimestamp = System.currentTimeMillis();
ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), configItem, VRScripts.VR_SCRIPT_EXEC_TIMEOUT);
if (s_logger.isDebugEnabled()) {
long elapsed = System.currentTimeMillis() - startTimestamp;
s_logger.debug("Processing " + configItem + " took " + elapsed + "ms");
}
if (result == null) {
result = new ExecutionResult(false, "null execution result");
}
results.add(result);
details.add(configItem.getInfo() + (result.isSuccess() ? " - success: " : " - failed: ") + result.getDetails());
finalResult = result.isSuccess();
}
// Not sure why this matters, but log it anyway
if (cmd.getAnswersCount() != results.size()) {
s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size());
}
if (results.size() == 1) {
return new Answer(cmd, finalResult, results.get(0).getDetails());
} else {
return new GroupAnswer(cmd, finalResult, results.size(), details.toArray(new String[details.size()]));
}
}
Aggregations