Skip to content

Commit 645516e

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 a642fa1 commit 645516e

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;
@@ -2807,22 +2807,23 @@ protected ArrayList<? extends PublicIpAddress> getPublicIpsToApply(final Virtual
28072807
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
28082808
DomainRouterVO router = _routerDao.findById(profile.getId());
28092809

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

2825+
// at this point, all the router command are successful.
2826+
boolean result = true;
28262827
//Get guest networks info
28272828
final List<Network> guestNetworks = new ArrayList<Network>();
28282829

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

28602848
return result;

0 commit comments

Comments
 (0)