ApiManager implements IApiManager { @Override public ApiRequest restartRequiredService(String clusterName, ApiRestartRequiredService apiRestartRequiredService) throws AmbariApiException { String serviceName = apiRestartRequiredService.getName(); ApiPostRequestInfo requestInfo = new ApiPostRequestInfo(); requestInfo.setContext("Restart all components with Stale Configs for " + serviceName); requestInfo.setCommand(Constants.OPERATION_COMMAND_RESTART); if (!isAmbari_1_6_0()) { ApiOperationLevel operationLevel = new ApiOperationLevel(Constants.OPERATION_SERVICE_LEVEL, clusterName, serviceName); requestInfo.setOperationLevel(operationLevel); } List<ApiRequestsPostResourceFilter> apiRequestsResourceFilters = new ArrayList<ApiRequestsPostResourceFilter>(); for (ApiRestartRequiredCompent apiRestartRequiredCompent : apiRestartRequiredService.getApiRestartRequiredCompents()) { ApiRequestsPostResourceFilter apiRequestResourceFilter = new ApiRequestsPostResourceFilter(serviceName, apiRestartRequiredCompent.getName(), apiRestartRequiredCompent.getStringHosts()); apiRequestsResourceFilters.add(apiRequestResourceFilter); } ApiPostRequest restartServiceRequest = new ApiPostRequest(requestInfo, apiRequestsResourceFilters); String request = ApiUtils.objectToJson(restartServiceRequest); logger.info("The request in restarting service is :" + request); Response response = null; try { response = apiResourceRootV1.getClustersResource().getRequestsResource(clusterName).postRequest(request); } catch (Exception e) { throw AmbariApiException.CANNOT_CONNECT_AMBARI_SERVER(e); } String responseJson = handleAmbariResponse(response); logger.info("in restarting service, reponse is :" + responseJson); return ApiUtils.jsonToObject(ApiRequest.class, responseJson); } ApiManager(String amServerHost, int port, String user, String password);  ApiManager(URL baseUrl, String user, String password);  ApiManager(AmbariManagerClientbuilder clientbuilder); @Override ApiStackList getStackList(); @Override ApiStack getStack(String stackName); @Override ApiService readService(String clusterName, String serviceName); @Override boolean isServiceStarted(String clusterName, String serviceName); @Override ApiStackVersionList getStackVersionList(String stackName); @Override ApiStackVersion getStackVersion(String stackName, String stackVersion); @Override ApiStackServiceList getStackServiceList(String stackName,
         String stackVersion); @Override ApiStackServiceList getStackServiceListWithComponents(
         String stackName, String stackVersion); @Override ApiStackServiceList getStackServiceListWithConfigurations(
         String stackName, String stackVersion); @Override ApiStackService getStackServiceWithComponents(String stackName,
         String stackVersion, String serviceName); List<ApiConfiguration> getServiceConfiguration(String stackName,
         String stackVersion, String serviceName); @Override ApiStackService getStackService(String stackName,
         String stackVersion, String stackServiceName); @Override ApiStackComponentList getStackComponentList(String stackName,
         String stackVersion, String stackServiceName); @Override ApiStackComponent getStackComponent(String stackName,
         String stackVersion, String stackServiceName, String stackComponentName); @Override ApiClusterList getClusterList(); @Override ApiCluster getCluster(String clusterName); @Override List<ApiService> getClusterServices(String clusterName); @Override ApiRequest stopAllServicesInCluster(String clusterName); @Override ApiRequest startAllServicesInCluster(String clusterName); ApiRequest decommissionComponent(String clusterName, String host, String serviceName, String managementRoleName, String slaveRoleName); @Override List<String> getClusterServicesNames(String clusterName); @Override ApiRequest provisionCluster(String clusterName,
         ApiClusterBlueprint apiClusterBlueprint); @Override ApiBlueprintList getBlueprintList(); @Override ApiBlueprint getBlueprint(String blueprintName); @Override ApiBlueprint createBlueprint(String blueprintName,
         ApiBlueprint apiBlueprint); boolean updatePersist(ApiPersist persist); @Override ApiRequest deleteHost(String clusterName, String fqdn); @Override boolean deleteBlueprint(String blueprintName); @Override boolean deleteCluster(String clusterName); @Override ApiRequestList getRequestList(String clusterName); @Override ApiRequest getRequest(String clusterName, Long requestId); @Override ApiBootstrap createBootstrap(ApiBootstrap bootstrap); @Override ApiBootstrapStatus getBootstrapStatus(Long bootstrapId); @Override ApiRequest getRequestWithTasks(String clusterName, Long requestId); @Override ServiceStatus getClusterStatus(String clusterName, HadoopStack stack); @Override Map<String, ServiceStatus> getHostStatus(String clusterName); @Override ApiHostList getHostsSummaryInfo(String clusterName); List<ApiHostComponent> getHostComponents(String clusterName, String hostName); @Override String healthCheck(); @Override String getVersion(); @Override boolean deleteService(String clusterName, String serviceName); @Override List<String> getExistingHosts(String clusterName,
         List<String> hostNames); @Override void addHostsToCluster(String clusterName, List<String> hostNames); @Override ApiHostList getClusterHostsList(String clusterName); @Override ApiRequest stopAllComponentsInHosts(String clusterName,
         List<String> hostNames); @Override void deleteAllComponents(String clusterName, String hostName); @Override List<String> getAssociatedConfigGroups(String clusterName,
         String hostName); ApiConfigGroupList getConfigGroupsList(String clusterName); @Override void deleteConfigGroup(String clusterName, String groupId); ApiClusterConfigurations getClusterConfigurationsWithTypeAndTag(String clusterName, String type, String tag); @Override ApiRequest startComponents(String clusterName,
         List<String> hostNames, List<String> components); @Override void createConfigGroups(String clusterName,
         List<ApiConfigGroup> configGroups); ApiConfigGroup readConfigGroup(String clusterName, String configGroupId); void updateConfigGroup(String clusterName, String groupId,
         ApiConfigGroup configGroup); @Override void addComponents(String clusterName, List<String> hostNames,
         ApiHostComponentsRequest components); @Override ApiRequest installComponents(String clusterName); @Override ApiStackServiceList getStackWithCompAndConfigs(String stackName,
         String stackVersion); @Override ApiHostList getRegisteredHosts(); @Override ApiStackServiceList getServicesWithFilter(String stackName,
         String stackVersion, String filter); @Override List<ApiRequest> restartRequiredServices(String clusterName); @Override ApiRequest restartRequiredService(String clusterName, ApiRestartRequiredService apiRestartRequiredService); @Override List<ApiRestartRequiredService> getRestartRequiredServices(String clusterName); @Override void setClusterHostsRackInfo(String clusterName, String rackInfo, Set<String> hosts);  }
@Test public void testrestartRequiredService() throws Exception { ApiRestartRequiredService apiRestartRequiredService = new ApiRestartRequiredService(); apiRestartRequiredService.setName(clusterName); List<ApiRestartRequiredCompent> apiRestartRequiredCompents = new ArrayList<ApiRestartRequiredCompent>(); ApiRestartRequiredCompent apiRestartRequiredCompent_1 = new ApiRestartRequiredCompent(); apiRestartRequiredCompent_1.setName("DATANODE"); Set<String> hosts_1 = new HashSet<String>(); hosts_1.add("127.0.0.1"); hosts_1.add("127.0.0.2"); apiRestartRequiredCompent_1.setHosts(hosts_1); apiRestartRequiredCompents.add(apiRestartRequiredCompent_1); ApiRestartRequiredCompent apiRestartRequiredCompent_2 = new ApiRestartRequiredCompent(); apiRestartRequiredCompent_2.setName("NODEMANAGER"); Set<String> hosts_2 = new HashSet<String>(); hosts_2.add("127.0.0.1"); hosts_2.add("127.0.0.2"); apiRestartRequiredCompent_1.setHosts(hosts_2); apiRestartRequiredCompents.add(apiRestartRequiredCompent_2); apiRestartRequiredService.setApiRestartRequiredCompents(apiRestartRequiredCompents); System.out.println(ApiUtils.objectToJson(apiRestartRequiredService)); ApiRequest apiRequest = apiManager.restartRequiredService(clusterName, apiRestartRequiredService); Assert.assertNotNull(apiRequest); }