7474import org .apache .cloudstack .utils .CloudStackVersion ;
7575import org .apache .cloudstack .utils .identity .ManagementServerNode ;
7676import org .apache .cloudstack .utils .usage .UsageUtils ;
77+ import org .apache .commons .collections4 .CollectionUtils ;
7778import org .apache .commons .lang3 .ObjectUtils ;
7879import org .apache .commons .lang3 .StringUtils ;
7980import org .jetbrains .annotations .NotNull ;
@@ -811,9 +812,10 @@ protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> rout
811812 }
812813 final String privateIP = router .getPrivateIpAddress ();
813814 final HostVO host = _hostDao .findById (router .getHostId ());
814- if ( !(host == null || host .getState () != Status .Up )
815+ boolean hostAvailable = !(host == null || host .getState () != Status .Up )
815816 && (host .getManagementServerId () == ManagementServerNode .getManagementServerId ())
816- && (privateIP != null )) {
817+ && (privateIP != null );
818+ if (hostAvailable ) {
817819 final CheckS2SVpnConnectionsCommand command = new CheckS2SVpnConnectionsCommand (ipList );
818820 command .setAccessDetail (NetworkElementCommand .ROUTER_IP , _routerControlHelper .getRouterControlIp (router .getId ()));
819821 command .setAccessDetail (NetworkElementCommand .ROUTER_NAME , router .getInstanceName ());
@@ -1041,12 +1043,7 @@ protected void runInContext() {
10411043 continue ;
10421044 }
10431045
1044- DomainRouterVO router ;
1045- if (router0 .getId () < router1 .getId ()) {
1046- router = router0 ;
1047- } else {
1048- router = router1 ;
1049- }
1046+ DomainRouterVO router = (router0 .getId () < router1 .getId ()) ? router0 : router1 ;
10501047 // && router.getState() == VirtualMachine.State.Stopped
10511048 if (router .getHostId () == null && router .getState () == VirtualMachine .State .Running ) {
10521049 logger .debug ("Skip router pair (" + router0 .getInstanceName () + "," + router1 .getInstanceName () + ") due to can't find host" );
@@ -1156,7 +1153,7 @@ private List<String> getFailingChecks(DomainRouterVO router, GetRouterMonitorRes
11561153 }
11571154
11581155 private void handleFailingChecks (DomainRouterVO router , List <String > failingChecks ) {
1159- if (failingChecks == null || failingChecks .isEmpty ()) {
1156+ if (CollectionUtils .isEmpty (failingChecks )) {
11601157 return ;
11611158 }
11621159
@@ -1404,7 +1401,6 @@ private void updateDbHealthChecksFromRouterResponse(final DomainRouterVO router,
14041401 } catch (JsonSyntaxException ex ) {
14051402 logger .error ("Unable to parse the result of health checks due to " + ex .getLocalizedMessage (), ex );
14061403 }
1407- return ;
14081404 }
14091405
14101406 private GetRouterMonitorResultsAnswer fetchAndUpdateRouterHealthChecks (DomainRouterVO router , boolean performFreshChecks ) {
@@ -1420,7 +1416,7 @@ private GetRouterMonitorResultsAnswer fetchAndUpdateRouterHealthChecks(DomainRou
14201416 try {
14211417 final Answer answer = _agentMgr .easySend (router .getHostId (), command );
14221418
1423- logger .info ("Got health check results from router {}: {}" , router .getHostName (), answer != null ? answer .getDetails () : "null answer" );
1419+ logger .debug ("Got health check results from router {}: {}" , router .getHostName (), answer != null ? answer .getDetails () : "null answer" );
14241420 if (answer == null ) {
14251421 logger .warn ("Unable to fetch monitoring results data from router {}" , router .getHostName ());
14261422 return null ;
@@ -1484,7 +1480,7 @@ public Pair<Boolean, String> performRouterHealthChecks(long routerId) {
14841480 throw new CloudRuntimeException ("Router health checks are not enabled for router: " + router );
14851481 }
14861482
1487- logger .info ("Running health check results for router " + router .getUuid ());
1483+ logger .debug ("Running health check results for router " + router .getUuid ());
14881484
14891485 GetRouterMonitorResultsAnswer answer ;
14901486 String resultDetails = "" ;
@@ -1493,11 +1489,11 @@ public Pair<Boolean, String> performRouterHealthChecks(long routerId) {
14931489 // Step 1: Perform basic tests to check the connectivity and file system on router
14941490 answer = performBasicTestsOnRouter (router );
14951491 if (answer == null ) {
1496- logger .debug ("No results received for the basic tests on router: " + router );
1492+ logger .info ("No results received for the basic tests on router: " + router );
14971493 resultDetails = "Basic tests results unavailable" ;
14981494 success = false ;
14991495 } else if (!answer .getResult ()) {
1500- logger .debug ("Basic tests failed on router: " + router );
1496+ logger .warn ("Basic tests failed on router: " + router );
15011497 resultDetails = "Basic tests failed - " + answer .getMonitoringResults ();
15021498 success = false ;
15031499 } else {
@@ -1624,15 +1620,16 @@ private boolean updateRouterHealthChecksConfig(DomainRouterVO router) {
16241620 }
16251621
16261622 private String getSystemThresholdsHealthChecksData (final DomainRouterVO router ) {
1627- return "minDiskNeeded=" + RouterHealthChecksFreeDiskSpaceThreshold .valueIn (router .getDataCenterId ()) +
1628- ",maxCpuUsage=" + RouterHealthChecksMaxCpuUsageThreshold .valueIn (router .getDataCenterId ()) +
1629- ",maxMemoryUsage=" + RouterHealthChecksMaxMemoryUsageThreshold .valueIn (router .getDataCenterId ()) + ";" ;
1623+ return String .format ("minDiskNeeded=%s,maxCpuUsage=%s,maxMemoryUsage=%s;" ,
1624+ RouterHealthChecksFreeDiskSpaceThreshold .valueIn (router .getDataCenterId ()),
1625+ RouterHealthChecksMaxCpuUsageThreshold .valueIn (router .getDataCenterId ()),
1626+ RouterHealthChecksMaxMemoryUsageThreshold .valueIn (router .getDataCenterId ()));
16301627 }
16311628
16321629 private String getRouterVersionHealthChecksData (final DomainRouterVO router ) {
16331630 if (router .getTemplateVersion () != null && router .getScriptsVersion () != null ) {
1634- return "templateVersion=" + router .getTemplateVersion () +
1635- ",scriptsVersion=" + router .getScriptsVersion ();
1631+ return String . format ( "templateVersion=%s,scriptsVersion=%s" , router .getTemplateVersion (),
1632+ router .getScriptsVersion () );
16361633 }
16371634 return null ;
16381635 }
0 commit comments