Skip to content

Commit 59bf355

Browse files
karuturiJayapal
authored andcommitted
CLOUDSTACK-6531: stopping the router in case of command failures. Also added alerts for failures.
Signed-off-by: Jayapal <jayapal@apache.org>
1 parent 4083634 commit 59bf355

1 file changed

Lines changed: 20 additions & 32 deletions

File tree

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import org.apache.log4j.Logger;
4848

49+
import org.apache.cloudstack.alert.AlertService;
4950
import org.apache.cloudstack.alert.AlertService.AlertType;
5051
import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd;
5152
import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
@@ -81,7 +82,6 @@
8182
import com.cloud.agent.api.NetworkUsageCommand;
8283
import com.cloud.agent.api.PvlanSetupCommand;
8384
import com.cloud.agent.api.StartupCommand;
84-
import com.cloud.agent.api.check.CheckSshAnswer;
8585
import com.cloud.agent.api.check.CheckSshCommand;
8686
import com.cloud.agent.api.routing.AggregationControlCommand;
8787
import com.cloud.agent.api.routing.AggregationControlCommand.Action;
@@ -2811,22 +2811,23 @@ protected ArrayList<? extends PublicIpAddress> getPublicIpsToApply(final Virtual
28112811
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
28122812
DomainRouterVO router = _routerDao.findById(profile.getId());
28132813

2814-
boolean result = true;
2815-
2816-
Answer answer = cmds.getAnswer("checkSsh");
2817-
if (answer != null && answer instanceof CheckSshAnswer) {
2818-
final CheckSshAnswer sshAnswer = (CheckSshAnswer)answer;
2819-
if (sshAnswer == null || !sshAnswer.getResult()) {
2820-
s_logger.warn("Unable to ssh to the VM: " + sshAnswer.getDetails());
2821-
result = false;
2814+
//process all the answers
2815+
for (Answer answer : cmds.getAnswers()) {
2816+
// handle any command failures
2817+
if (!answer.getResult()) {
2818+
String cmdClassName = answer.getClass().getCanonicalName().replace("Answer", "Command");
2819+
String errorMessage = "Command: " + cmdClassName + " failed while starting virtual router";
2820+
String errorDetails = "Details: " + answer.getDetails() + " " + answer.toString();
2821+
//add alerts for the failed commands
2822+
_alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), errorMessage, errorDetails);
2823+
s_logger.warn(errorMessage);
2824+
//Stop the router if any of the commands failed
2825+
return false;
28222826
}
2823-
} else {
2824-
result = false;
2825-
}
2826-
if (result == false) {
2827-
return result;
28282827
}
28292828

2829+
// at this point, all the router command are successful.
2830+
boolean result = true;
28302831
//Get guest networks info
28312832
final List<Network> guestNetworks = new ArrayList<Network>();
28322833

@@ -2841,24 +2842,11 @@ public boolean finalizeStart(final VirtualMachineProfile profile, final long hos
28412842
}
28422843
}
28432844
}
2844-
2845-
if (!result) {
2846-
return result;
2847-
}
2848-
2849-
answer = cmds.getAnswer("getDomRVersion");
2850-
if (answer != null && answer instanceof GetDomRVersionAnswer) {
2851-
final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer;
2852-
if (answer == null || !answer.getResult()) {
2853-
s_logger.warn("Unable to get the template/scripts version of router " + router.getInstanceName() + " due to: " + versionAnswer.getDetails());
2854-
result = false;
2855-
} else {
2856-
router.setTemplateVersion(versionAnswer.getTemplateVersion());
2857-
router.setScriptsVersion(versionAnswer.getScriptsVersion());
2858-
router = _routerDao.persist(router, guestNetworks);
2859-
}
2860-
} else {
2861-
result = false;
2845+
if (result) {
2846+
GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)cmds.getAnswer("getDomRVersion");
2847+
router.setTemplateVersion(versionAnswer.getTemplateVersion());
2848+
router.setScriptsVersion(versionAnswer.getScriptsVersion());
2849+
router = _routerDao.persist(router, guestNetworks);
28622850
}
28632851

28642852
return result;

0 commit comments

Comments
 (0)