AmbariImpl extends AbstractSoftwareManager implements SoftwareManager { protected boolean doSoftwareOperation(String clusterName, ApiRequest apiRequestSummary, ClusterReport clusterReport, ClusterReportQueue reports) throws Exception{ if (apiRequestSummary == null) { return true; } ClusterOperationPoller poller = new ClusterOperationPoller(apiManager, apiRequestSummary, clusterName, clusterReport, reports, ProgressSplit.OPERATION_FINISHED.getProgress()); poller.waitForComplete(); boolean success = false; ApiRequest apiRequest = apiManager.getRequestWithTasks(clusterName, apiRequestSummary .getApiRequestInfo().getRequestId()); ClusterRequestStatus clusterRequestStatus = ClusterRequestStatus.valueOf(apiRequest.getApiRequestInfo() .getRequestStatus()); if (!clusterRequestStatus.isFailedState()) { success = true; } else { logger.error("Failed to do request: " + ApiUtils.objectToJson(apiRequest.getApiRequestInfo())); List<ApiTask> apiTasks = apiRequest.getApiTasks(); Map<String, NodeReport> nodeReports = clusterReport.getNodeReports(); HashMap<String, List<String>> errMsg = new HashMap<>(); for (ApiTask apiTask : apiTasks) { ApiTaskInfo taskInfo = apiTask.getApiTaskInfo(); if (TaskStatus.valueOf(taskInfo.getStatus()).isFailedState()) { if (!errMsg.containsKey(taskInfo.getHostName())) { List<String> errs = new ArrayList<>(); errMsg.put(taskInfo.getHostName(), errs); } String taskErrMsg = taskInfo.getCommandDetail() + " " + taskInfo.getStatus(); errMsg.get(taskInfo.getHostName()).add(taskErrMsg); logger.error("command: " + taskInfo.getCommandDetail() + "role: " + taskInfo.getRole() + "stderr: " + taskInfo.getStderr() + "status: " + taskInfo.getStatus()); } } for (NodeReport nodeReport: nodeReports.values()) { if (errMsg.containsKey(nodeReport.getHostname())) { nodeReport.setErrMsg(errMsg.get(nodeReport.getHostname()).toString()); } } String requestErrorMsg = "Failed to execute request: " + apiRequest.getApiRequestInfo().getRequestStatus() + ". Refer to each node for details."; clusterReport.setErrMsg(requestErrorMsg); reportStatus(clusterReport.clone(), reports); throw new RuntimeException(requestErrorMsg); } return success; } AmbariImpl(String amServerHost, int port, String username,
         String password, String privateKey);  AmbariImpl(URL url, String username, String password, String privateKey); protected  AmbariImpl(AmbariManagerClientbuilder clientbuilder, String privateKey); @Override String getName(); @Override String getDescription(); @Override String getType(); @Override boolean echo(); @Override boolean validateServerVersion(); @Override HealthStatus getStatus(); @Override List<HadoopStack> getSupportedStacks(); @SuppressWarnings("unchecked") @Override String getSupportedConfigs(HadoopStack stack); @Override boolean createCluster(ClusterBlueprint blueprint,
         ClusterReportQueue reportQueue); @Override String exportBlueprint(String clusterName); @Override List<String> validateRolesForScaleOut(NodeGroupInfo group); @Override void validateRolesForShrink(NodeGroupInfo groupInfo); @Override void updateInfrastructure(ClusterBlueprint blueprint); @Override boolean reconfigCluster(ClusterBlueprint blueprint,
         ClusterReportQueue reports); @Override boolean scaleOutCluster(ClusterBlueprint blueprint, List<String> addedNodeNames,
         ClusterReportQueue reports, boolean forceScaleOut); boolean scaleOutCluster(ClusterBlueprint blueprint, List<String> addedNodeNames,
         ClusterReportQueue reports); boolean startCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reportQueue); @Override boolean startCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reports, boolean forceStart); @Override boolean deleteCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reports); @Override boolean onStopCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reports); @Override boolean onDeleteCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reports); @Override boolean onDeleteNodes(ClusterBlueprint blueprint, List<String> nodeNames); @Override boolean decomissionNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override void decommissionNode(ClusterBlueprint blueprint, String nodeGroupName, String nodeName, ClusterReportQueue reportQueue); @Override boolean recomissionNode(String clusterName, NodeInfo node, ClusterReportQueue reportQueue); @Override boolean comissionNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override boolean startNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override boolean stopNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override ClusterReport queryClusterStatus(ClusterBlueprint blueprint); @Override boolean validateBlueprint(ClusterBlueprint blueprint); @Override boolean hasHbase(ClusterBlueprint blueprint); @Override boolean hasMgmtRole(List<String> roles); @Override boolean isComputeOnlyRoles(List<String> roles); @Override boolean twoDataDisksRequired(NodeGroupInfo group); @Override boolean hasComputeMasterGroup(ClusterBlueprint blueprint); @Override String getVersion(); @Override HadoopStack getDefaultStack(); ApiManager getApiManager(); void setApiManager(ApiManager apiManager); int getRequestMaxRetryTimes(); @Override boolean hasMountPointStartwithDatax(String clusterName); @Override void restartClusterRequiredServices(ClusterBlueprint blueprint, ClusterReportQueue reports); static final String MIN_SUPPORTED_VERSION; }
@Test(groups = { "TestAmbariImpl" }) public void testDoSoftwareOperation() { ClusterReport clusterReport = new ClusterReport(blueprint); AmbariImpl spy = Mockito.spy(provider); ApiManager apiManager = new FakeApiManager(makeClientBuilder()); ApiManager backup = spy.getApiManager(); spy.setApiManager(apiManager); ApiRequest request = new ApiRequest(); ApiGetRequestInfo requestInfo = new ApiGetRequestInfo(); request.setApiRequestInfo(requestInfo); try { spy.doSoftwareOperation(blueprint.getName(), request, clusterReport, reportQueue); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(e.getMessage().contains("Failed to execute request: ")); } spy.setApiManager(backup); }