ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject ambari git commit: AMBARI-16145. Add dryrun API for host delete (ajit)
Date Wed, 27 Apr 2016 23:14:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 80f1beaac -> 237a5d692


AMBARI-16145. Add dryrun API for host delete (ajit)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/237a5d69
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/237a5d69
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/237a5d69

Branch: refs/heads/trunk
Commit: 237a5d6926ddf841859695b4fcc469ab1cc04fcf
Parents: 80f1bea
Author: Ajit Kumar <ajit@apache.org>
Authored: Wed Apr 27 16:12:42 2016 -0700
Committer: Ajit Kumar <ajit@apache.org>
Committed: Wed Apr 27 16:12:42 2016 -0700

----------------------------------------------------------------------
 .../api/resources/HostResourceDefinition.java   | 10 +++-
 .../internal/HostResourceProvider.java          | 48 ++++++++++++--------
 .../internal/HostResourceProviderTest.java      |  2 +-
 3 files changed, 39 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/237a5d69/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java
index c9b0878..10828bb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java
@@ -19,9 +19,12 @@
 package org.apache.ambari.server.api.resources;
 
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 
 /**
@@ -47,8 +50,13 @@ public class HostResourceDefinition extends BaseResourceDefinition {
   }
 
   @Override
+  public Collection<String> getDeleteDirectives() {
+    return Collections.singleton(Request.DIRECTIVE_DRY_RUN);
+  }
+
+  @Override
   public Set<SubResourceDefinition> getSubResourceDefinitions() {
-    Set<SubResourceDefinition> subs = new HashSet<SubResourceDefinition>();
+    Set<SubResourceDefinition> subs = new HashSet<>();
     subs.add(new SubResourceDefinition(Resource.Type.HostComponent));
     subs.add(new SubResourceDefinition(Resource.Type.Alert));
     subs.add(new SubResourceDefinition(Resource.Type.HostStackVersion));

http://git-wip-us.apache.org/repos/asf/ambari/blob/237a5d69/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index 4dc47be..56ef28b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
@@ -330,7 +330,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
   }
 
   @Override
-  protected RequestStatus deleteResourcesAuthorized(Request request, Predicate predicate)
+  protected RequestStatus deleteResourcesAuthorized(final Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException
{
 
     final Set<HostRequest> requests = new HashSet<>();
@@ -341,7 +341,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
     DeleteStatusMetaData deleteStatusMetaData = modifyResources(new Command<DeleteStatusMetaData>()
{
       @Override
       public DeleteStatusMetaData invoke() throws AmbariException {
-        return deleteHosts(requests);
+        return deleteHosts(requests, request.isDryRunRequest());
       }
     });
 
@@ -827,13 +827,12 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
   }
 
   @Transactional
-  protected DeleteStatusMetaData deleteHosts(Set<HostRequest> requests)
+  protected DeleteStatusMetaData deleteHosts(Set<HostRequest> requests, boolean dryRun)
       throws AmbariException {
 
     AmbariManagementController controller = getManagementController();
     Clusters                   clusters   = controller.getClusters();
     DeleteStatusMetaData deleteStatusMetaData = new DeleteStatusMetaData();
-
     List<HostRequest> okToRemove = new ArrayList<>();
 
     for (HostRequest hostRequest : requests) {
@@ -850,22 +849,13 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
       }
     }
 
-    for (HostRequest hostRequest : okToRemove) {
-      // Assume the user also wants to delete it entirely, including all clusters.
-      String hostname = hostRequest.getHostname();
-      try {
-        clusters.deleteHost(hostname);
-        deleteStatusMetaData.addDeletedKey(hostname);
-      } catch (Exception ex) {
-        deleteStatusMetaData.addException(hostname, ex);
-      }
-      for (LogicalRequest logicalRequest: topologyManager.getRequests(Collections.<Long>emptyList()))
{
-        logicalRequest.removeHostRequestByHostName(hostname);
-      }
-
-      if (null != hostRequest.getClusterName()) {
-        clusters.getCluster(hostRequest.getClusterName()).recalculateAllClusterVersionStates();
+    //If dry run, don't delete. just assume it can be successfully deleted.
+    if (dryRun) {
+      for (HostRequest request : okToRemove) {
+        deleteStatusMetaData.addDeletedKey(request.getHostname());
       }
+    } else {
+      processDeleteHostRequests(okToRemove, clusters, deleteStatusMetaData);
     }
 
     //Do not break behavior for existing clients where delete request contains only 1 host.
@@ -887,6 +877,26 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
     return deleteStatusMetaData;
   }
 
+  private void processDeleteHostRequests(List<HostRequest> requests,  Clusters clusters,
DeleteStatusMetaData deleteStatusMetaData) throws AmbariException {
+    for (HostRequest hostRequest : requests) {
+      // Assume the user also wants to delete it entirely, including all clusters.
+      String hostname = hostRequest.getHostname();
+      try {
+        clusters.deleteHost(hostname);
+        deleteStatusMetaData.addDeletedKey(hostname);
+      } catch (Exception ex) {
+        deleteStatusMetaData.addException(hostname, ex);
+      }
+      for (LogicalRequest logicalRequest: topologyManager.getRequests(Collections.<Long>emptyList()))
{
+        logicalRequest.removeHostRequestByHostName(hostname);
+      }
+
+      if (null != hostRequest.getClusterName()) {
+        clusters.getCluster(hostRequest.getClusterName()).recalculateAllClusterVersionStates();
+      }
+    }
+  }
+
   private void validateHostInDeleteFriendlyState(HostRequest hostRequest, Clusters clusters
) throws AmbariException {
     Set<String> clusterNamesForHost = new HashSet<>();
     String hostName = hostRequest.getHostname();

http://git-wip-us.apache.org/repos/asf/ambari/blob/237a5d69/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
index 1c91477..3a2fdb2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
@@ -1361,7 +1361,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     HostResourceProvider provider = getHostProvider(controller);
     HostResourceProvider.setTopologyManager(topologyManager);
-    provider.deleteHosts(requests);
+    provider.deleteHosts(requests, false);
   }
 
   public static void updateHosts(AmbariManagementController controller, Set<HostRequest>
requests)


Mime
View raw message