[AMBARI-24756] Fix Restart All services on host function (#2435)

* Fix Restart All services on host function

* Fix indentation
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index 7717939..066aaff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -1453,35 +1453,35 @@
       Cluster cluster = clusters.getCluster(clusterName);
       StackId stackId = null;
       String serviceType = null;
-//      TODO add service group null checks when the UI is updated
-//      if (serviceGroupName != null) {
-      if (serviceName != null) {
+
+      if (serviceGroupName != null && serviceName != null) {
         Service service = cluster.getService(serviceGroupName, serviceName);
         stackId = service.getStackId();
         serviceType = service.getServiceType();
-      }
 
-      if (stackId == null) {
-        throw new AmbariException("StackId should not be null. Service " + serviceName + " should have a desiredStackId");
-      }
+        if (stackId == null) {
+          throw new AmbariException("StackId should not be null. Service " + serviceName + " should have a desiredStackId");
+        }
 
-      AmbariMetaInfo ambariMetaInfo = managementController.getAmbariMetaInfo();
+        AmbariMetaInfo ambariMetaInfo = managementController.getAmbariMetaInfo();
 
-      StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion());
-      if (stack != null) {
-        ServiceInfo serviceInfo = stack.getService(serviceType);
+        StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion());
+        if (stack != null) {
+          ServiceInfo serviceInfo = stack.getService(serviceType);
 
-        if (serviceInfo != null) {
-          // if there is a chance that this action was triggered by a change in rack info then we want to
-          // force a topology refresh
-          // TODO : we may be able to be smarter about this and only refresh when the rack info has definitely changed
-          Boolean restartRequiredAfterRackChange = serviceInfo.isRestartRequiredAfterRackChange();
-          if (restartRequiredAfterRackChange != null && restartRequiredAfterRackChange) {
-            return true;
+          if (serviceInfo != null) {
+            // if there is a chance that this action was triggered by a change in rack info then we want to
+            // force a topology refresh
+            // TODO : we may be able to be smarter about this and only refresh when the rack info has definitely changed
+            Boolean restartRequiredAfterRackChange = serviceInfo.isRestartRequiredAfterRackChange();
+            if (restartRequiredAfterRackChange != null && restartRequiredAfterRackChange) {
+              return true;
+            }
           }
         }
       }
     }
+      
     return false;
   }
 
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index 171c7ad..8bcf7b3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -625,6 +625,7 @@
     Assert.assertTrue(helper.isTopologyRefreshRequired("START", "c2", "CORE", "HDFS"));
     Assert.assertTrue(helper.isTopologyRefreshRequired("RESTART", "c2", "CORE", "HDFS"));
     Assert.assertFalse(helper.isTopologyRefreshRequired("STOP", "c2", "CORE", "HDFS"));
+    Assert.assertFalse(helper.isTopologyRefreshRequired("RESTART", "c2", null, null));
   }
 
   @Test