AmbariImpl extends AbstractSoftwareManager implements SoftwareManager { @Override public boolean onDeleteCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reports) throws SoftwareManagementPluginException { try { String clusterName = clusterBlueprint.getName(); if (!echo()) { logger.warn("Ambari server is unavailable when deleting cluster " + clusterName + ". Will delete VMs forcely."); logger.warn("You may need to delete cluster resource on ambari server manually."); return true; } if (!isProvisioned(clusterName)) { return true; } AmClusterDef clusterDef = new AmClusterDef(clusterBlueprint, privateKey, getVersion()); if (!isClusterProvisionedByBDE(clusterDef)) { return true; } try { if (!onStopCluster(clusterBlueprint, reports)) { logger.error("Ambari failed to stop services"); } } catch (Exception e) { logger.error("Got exception when stop all services before delete cluster, try to delete cluster forcely", e); } List<String> serviceNames = apiManager.getClusterServicesNames(clusterName); if (serviceNames != null && !serviceNames.isEmpty()) { for (String serviceName : serviceNames) { apiManager.deleteService(clusterName, serviceName); } } if (apiManager.getHostsSummaryInfo(clusterName) != null) { List<ApiHost> hosts = apiManager.getHostsSummaryInfo(clusterName).getApiHosts(); if (hosts != null && !hosts.isEmpty()) { for (ApiHost host : hosts) { assert (host.getApiHostInfo() != null); String hostName = host.getApiHostInfo().getHostName(); apiManager.deleteHost(clusterName, hostName); } } } apiManager.deleteCluster(clusterName); if (isBlueprintCreated(clusterDef) && isBlueprintCreatedByBDE(clusterDef)) { apiManager.deleteBlueprint(clusterName); } ApiPersist persist = new ApiPersist(""); apiManager.updatePersist(persist); return true; } catch (Exception e) { logger.error("Ambari got an exception when deleting cluster", e); throw SoftwareManagementPluginException.DELETE_CLUSTER_FAILED(e, Constants.AMBARI_PLUGIN_NAME, clusterBlueprint.getName()); } } 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 testDeleteUnprovisionedCluster() { Assert.assertTrue(provider.onDeleteCluster(blueprint, reportQueue)); }