4343import javax .inject .Inject ;
4444import javax .naming .ConfigurationException ;
4545
46+ import org .apache .log4j .Logger ;
47+
48+ import org .apache .cloudstack .alert .AlertService ;
49+ import org .apache .cloudstack .alert .AlertService .AlertType ;
4650import org .apache .cloudstack .api .command .admin .router .RebootRouterCmd ;
4751import org .apache .cloudstack .api .command .admin .router .UpgradeRouterCmd ;
4852import org .apache .cloudstack .api .command .admin .router .UpgradeRouterTemplateCmd ;
7680import com .cloud .agent .api .NetworkUsageCommand ;
7781import com .cloud .agent .api .PvlanSetupCommand ;
7882import com .cloud .agent .api .StartupCommand ;
79- import com .cloud .agent .api .check .CheckSshAnswer ;
8083import com .cloud .agent .api .check .CheckSshCommand ;
8184import com .cloud .agent .api .routing .CreateIpAliasCommand ;
8285import com .cloud .agent .api .routing .DeleteIpAliasCommand ;
@@ -2682,23 +2685,24 @@ protected ArrayList<? extends PublicIpAddress> getPublicIpsToApply(VirtualRouter
26822685 public boolean finalizeStart (VirtualMachineProfile profile , long hostId , Commands cmds ,
26832686 ReservationContext context ) {
26842687 DomainRouterVO router = _routerDao .findById (profile .getId ());
2685-
2686- boolean result = true ;
26872688
2688- Answer answer = cmds .getAnswer ("checkSsh" );
2689- if (answer != null && answer instanceof CheckSshAnswer ) {
2690- CheckSshAnswer sshAnswer = (CheckSshAnswer ) answer ;
2691- if (sshAnswer == null || !sshAnswer .getResult ()) {
2692- s_logger .warn ("Unable to ssh to the VM: " + sshAnswer .getDetails ());
2693- result = false ;
2689+ //process all the answers
2690+ for (Answer answer : cmds .getAnswers ()) {
2691+ // handle any command failures
2692+ if (!answer .getResult ()) {
2693+ String cmdClassName = answer .getClass ().getCanonicalName ().replace ("Answer" , "Command" );
2694+ String errorMessage = "Command: " + cmdClassName + " failed while starting virtual router" ;
2695+ String errorDetails = "Details: " + answer .getDetails () + " " + answer .toString ();
2696+ //add alerts for the failed commands
2697+ _alertMgr .sendAlert (AlertService .AlertType .ALERT_TYPE_DOMAIN_ROUTER , router .getDataCenterId (), router .getPodIdToDeployIn (), errorMessage , errorDetails );
2698+ s_logger .warn (errorMessage );
2699+ //Stop the router if any of the commands failed
2700+ return false ;
26942701 }
2695- } else {
2696- result = false ;
26972702 }
2698- if (result == false ) {
2699- return result ;
2700- }
2701-
2703+
2704+ // at this point, all the router command are successful.
2705+ boolean result = true ;
27022706 //Get guest networks info
27032707 List <Network > guestNetworks = new ArrayList <Network >();
27042708
@@ -2713,25 +2717,11 @@ public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Command
27132717 }
27142718 }
27152719 }
2716-
2717- if (!result ) {
2718- return result ;
2719- }
2720-
2721- answer = cmds .getAnswer ("getDomRVersion" );
2722- if (answer != null && answer instanceof GetDomRVersionAnswer ) {
2723- GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer )answer ;
2724- if (answer == null || !answer .getResult ()) {
2725- s_logger .warn ("Unable to get the template/scripts version of router " + router .getInstanceName () +
2726- " due to: " + versionAnswer .getDetails ());
2727- result = false ;
2728- } else {
2729- router .setTemplateVersion (versionAnswer .getTemplateVersion ());
2730- router .setScriptsVersion (versionAnswer .getScriptsVersion ());
2731- router = _routerDao .persist (router , guestNetworks );
2732- }
2733- } else {
2734- result = false ;
2720+ if (result ) {
2721+ GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer )cmds .getAnswer ("getDomRVersion" );
2722+ router .setTemplateVersion (versionAnswer .getTemplateVersion ());
2723+ router .setScriptsVersion (versionAnswer .getScriptsVersion ());
2724+ router = _routerDao .persist (router , guestNetworks );
27352725 }
27362726
27372727 return result ;
0 commit comments