ServiceCommands implements CommandMarker { @CliCommand(value = "services stop", help = "Stops a service/all the running services") public String stopServices(@CliOption(key = "service", mandatory = false, help = "Name of the service to stop") Service service) { String message; try { if (service != null) { String serviceName = service.getName(); message = "Stopping " + serviceName; client.stopService(serviceName); } else { message = "Stopping all services.."; client.stopAllServices(); } } catch (Exception e) { message = "Cannot stop services"; } return String.format("%s\n\n%s", message, servicesList()); } @Autowired  ServiceCommands(AmbariClient client, AmbariContext context); @CliAvailabilityIndicator("services list") boolean isServiceListCommandAvailable(); @CliCommand(value = "services list", help = "Lists the available services") String servicesList(); @CliAvailabilityIndicator("services components") boolean isServiceComponentsCommandAvailable(); @CliCommand(value = "services components", help = "Lists all services with their components") String serviceComponents(); @CliAvailabilityIndicator("services stop") boolean isServiceStopCommandAvailable(); @CliCommand(value = "services stop", help = "Stops a service/all the running services") String stopServices(@CliOption(key = "service", mandatory = false, help = "Name of the service to stop") Service service); @CliAvailabilityIndicator("services start") boolean isServiceStartCommandAvailable(); @CliCommand(value = "services start", help = "Starts a service/all the services") String startServices(@CliOption(key = "service", mandatory = false, help = "Name of the service to start") Service service);  }
@Test public void testStopAllServices() { serviceCommands.stopServices(null); verify(client).stopAllServices(); }
@Test public void testStopService() { serviceCommands.stopServices(new Service("ZOOKEEPER")); verify(client).stopService("ZOOKEEPER"); }