ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject ambari git commit: AMBARI-14551. Rest API returns incorrect cluster creation request status using Blueprints until nodes join the cluster (Sebastian Toader via smohanty)
Date Sat, 09 Jan 2016 23:40:56 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk c7476d8a3 -> 5549bd485


AMBARI-14551. Rest API returns incorrect cluster creation request status using Blueprints
until nodes join the cluster (Sebastian Toader via smohanty)


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

Branch: refs/heads/trunk
Commit: 5549bd48565ae6d7acc67fc8bf63aee4c4b068ae
Parents: c7476d8
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Sat Jan 9 15:40:39 2016 -0800
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Sat Jan 9 15:40:39 2016 -0800

----------------------------------------------------------------------
 .../internal/HostResourceProvider.java          |  5 ++
 .../internal/RequestResourceProvider.java       | 14 ++++--
 .../server/state/cluster/ClustersImpl.java      | 36 +++++++++++++-
 .../ambari/server/topology/LogicalRequest.java  | 31 ++++++++++++
 .../ambari/server/topology/TopologyManager.java |  2 +-
 .../internal/HostResourceProviderTest.java      | 19 +++++++-
 .../server/state/cluster/ClusterImplTest.java   | 50 ++++++++++++++++++++
 7 files changed, 148 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5549bd48/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 f0d9fde..9bc4ab3 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
@@ -66,6 +66,7 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.apache.ambari.server.topology.InvalidTopologyException;
 import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
+import org.apache.ambari.server.topology.LogicalRequest;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
@@ -875,6 +876,10 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
       // Assume the user also wants to delete it entirely, including all clusters.
       clusters.deleteHost(hostRequest.getHostname());
 
+      for (LogicalRequest logicalRequest: topologyManager.getRequests(Collections.EMPTY_LIST))
{
+        logicalRequest.removeHostRequestByHostName(hostRequest.getHostname());
+      }
+
       if (null != hostRequest.getClusterName()) {
         clusters.getCluster(hostRequest.getClusterName()).recalculateAllClusterVersionStates();
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5549bd48/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
index 1a71afa..2cebbb4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
@@ -52,6 +52,7 @@ import org.apache.ambari.server.security.authorization.RoleAuthorization;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.topology.TopologyManager;
+import org.apache.ambari.server.topology.LogicalRequest;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -673,12 +674,15 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
     // get summaries from TopologyManager for logical requests
     summary.putAll(topologyManager.getStageSummaries(entity.getRequestId()));
 
-    CalculatedStatus status;
-    if (summary.isEmpty()) {
-      // Delete host might have cleared all HostRoleCommands
+    LogicalRequest logicalRequest = topologyManager.getRequest(entity.getRequestId());
+
+    CalculatedStatus status = CalculatedStatus.statusFromStageSummary(summary, summary.keySet());
+    if (summary.isEmpty() && (logicalRequest == null || logicalRequest.hasCompleted()))
{
+
+      // summary might be empty due to delete host have cleared all HostRoleCommands
+      // or due to hosts haven't registered yet with the cluster when the cluster is provisioned
+      // with a Blueprint
       status = CalculatedStatus.getCompletedStatus();
-    } else {
-      status = CalculatedStatus.statusFromStageSummary(summary, summary.keySet());
     }
 
     setResourceProperty(resource, REQUEST_STATUS_PROPERTY_ID, status.getStatus().toString(),
requestedPropertyIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/5549bd48/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index ca09ab8..0eabb3a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -55,7 +55,10 @@ import org.apache.ambari.server.orm.dao.RequestOperationLevelDAO;
 import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
 import org.apache.ambari.server.orm.dao.ServiceConfigDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.dao.TopologyHostRequestDAO;
+import org.apache.ambari.server.orm.dao.TopologyHostTaskDAO;
 import org.apache.ambari.server.orm.dao.TopologyLogicalTaskDAO;
+import org.apache.ambari.server.orm.dao.TopologyRequestDAO;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
@@ -65,6 +68,10 @@ import org.apache.ambari.server.orm.entities.PrivilegeEntity;
 import org.apache.ambari.server.orm.entities.ResourceEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.orm.entities.TopologyHostRequestEntity;
+import org.apache.ambari.server.orm.entities.TopologyLogicalRequestEntity;
+import org.apache.ambari.server.orm.entities.TopologyLogicalTaskEntity;
+import org.apache.ambari.server.orm.entities.TopologyRequestEntity;
 import org.apache.ambari.server.security.SecurityHelper;
 import org.apache.ambari.server.security.authorization.AmbariGrantedAuthority;
 import org.apache.ambari.server.security.authorization.ResourceType;
@@ -85,6 +92,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.security.core.GrantedAuthority;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
@@ -142,6 +150,10 @@ public class ClustersImpl implements Clusters {
   private SecurityHelper securityHelper;
   @Inject
   private TopologyLogicalTaskDAO topologyLogicalTaskDAO;
+  @Inject
+  private TopologyHostRequestDAO topologyHostRequestDAO;
+  @Inject
+  private TopologyRequestDAO topologyRequestDAO;
 
   /**
    * Data access object for stacks.
@@ -850,6 +862,12 @@ public class ClustersImpl implements Clusters {
       // Remove from all clusters in the cluster_host_mapping table.
       // This will also remove from kerberos_principal_hosts, hostconfigmapping, and configgrouphostmapping
       Set<Cluster> clusters = hostClusterMap.get(hostname);
+      Set<Long> clusterIds = Sets.newHashSet();
+      for (Cluster cluster: clusters)
+        clusterIds.add(cluster.getClusterId());
+
+
+
 
       unmapHostFromClusters(hostname, clusters);
       hostDAO.refresh(entity);
@@ -860,12 +878,26 @@ public class ClustersImpl implements Clusters {
       // TopologyLogicalTask owns the OneToOne relationship but Cascade is on HostRoleCommandEntity
       if (entity.getHostRoleCommandEntities() != null) {
         for (HostRoleCommandEntity hrcEntity : entity.getHostRoleCommandEntities()) {
-          if (hrcEntity.getTopologyLogicalTaskEntity() != null) {
-            topologyLogicalTaskDAO.remove(hrcEntity.getTopologyLogicalTaskEntity());
+          TopologyLogicalTaskEntity topologyLogicalTaskEnity = hrcEntity.getTopologyLogicalTaskEntity();
+          if (topologyLogicalTaskEnity != null) {
+            topologyLogicalTaskDAO.remove(topologyLogicalTaskEnity);
             hrcEntity.setTopologyLogicalTaskEntity(null);
           }
         }
       }
+      for (Long clusterId: clusterIds) {
+        for (TopologyRequestEntity topologyRequestEntity: topologyRequestDAO.findByClusterId(clusterId))
{
+          TopologyLogicalRequestEntity topologyLogicalRequestEntity = topologyRequestEntity.getTopologyLogicalRequestEntity();
+
+          for (TopologyHostRequestEntity topologyHostRequestEntity: topologyLogicalRequestEntity.getTopologyHostRequestEntities())
{
+            if (topologyHostRequestEntity.getHostName().equals(hostname)) {
+              topologyHostRequestDAO.remove(topologyHostRequestEntity);
+            }
+          }
+        }
+      }
+
+
       entity.setHostRoleCommandEntities(null);
       hostRoleCommandDAO.removeByHostId(entity.getHostId());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/5549bd48/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
index ad7c8fd..82edbcf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
@@ -327,6 +327,37 @@ public class LogicalRequest extends Request {
     return summaryMap;
   }
 
+  /**
+   * Removes all HostRequest associated with the passed host name from internal collections
+   * @param hostName name of the host
+   */
+  public void removeHostRequestByHostName(String hostName) {
+    synchronized (requestsWithReservedHosts) {
+      synchronized (outstandingHostRequests) {
+        requestsWithReservedHosts.remove(hostName);
+
+        Iterator<HostRequest> hostRequestIterator = outstandingHostRequests.iterator();
+        while (hostRequestIterator.hasNext()) {
+          if (hostRequestIterator.next().getHostName().equals(hostName)) {
+            hostRequestIterator.remove();
+            break;
+          }
+        }
+
+        //todo: synchronization
+        Iterator<HostRequest> allHostRequesIterator = allHostRequests.iterator();
+        while (allHostRequesIterator.hasNext()) {
+          if (allHostRequesIterator.next().getHostName().equals(hostName)) {
+            allHostRequesIterator.remove();
+            break;
+          }
+        }
+      }
+    }
+
+
+  }
+
   private void createHostRequests(TopologyRequest request, ClusterTopology topology) {
     Map<String, HostGroupInfo> hostGroupInfoMap = request.getHostGroupInfo();
     Blueprint blueprint = topology.getBlueprint();

http://git-wip-us.apache.org/repos/asf/ambari/blob/5549bd48/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
index 80d19d2..5b2cf8b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
@@ -380,7 +380,7 @@ public class TopologyManager {
     }
   }
 
-  public Request getRequest(long requestId) {
+  public LogicalRequest getRequest(long requestId) {
     ensureInitialized();
     return allRequests.get(requestId);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5549bd48/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 03ef06d..c480156 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
@@ -58,6 +58,7 @@ import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
 import org.junit.After;
+import org.apache.ambari.server.topology.TopologyManager;
 import org.junit.Assert;
 import org.junit.Test;
 import org.springframework.security.core.Authentication;
@@ -76,7 +77,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.replay;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -1079,7 +1084,13 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     SecurityContextHolder.getContext().setAuthentication(authentication);
 
+    TopologyManager topologyManager = EasyMock.createNiceMock(TopologyManager.class);
+    expect(topologyManager.getRequests(Collections.EMPTY_LIST)).andReturn(Collections.EMPTY_LIST).anyTimes();
+
+    replay(topologyManager);
+
     ResourceProvider provider = getHostProvider(injector);
+    HostResourceProvider.setTopologyManager(topologyManager);
 
     AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
 
@@ -1340,7 +1351,13 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
   public static void deleteHosts(AmbariManagementController controller, Set<HostRequest>
requests)
       throws AmbariException {
+    TopologyManager topologyManager = EasyMock.createNiceMock(TopologyManager.class);
+    expect(topologyManager.getRequests(Collections.EMPTY_LIST)).andReturn(Collections.EMPTY_LIST).anyTimes();
+
+    replay(topologyManager);
+
     HostResourceProvider provider = getHostProvider(controller);
+    HostResourceProvider.setTopologyManager(topologyManager);
     provider.deleteHosts(requests);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/5549bd48/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
index 178adc5..627ade9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
@@ -23,6 +23,8 @@ import com.google.common.collect.Sets;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
+
+import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.controller.AmbariSessionManager;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -40,6 +42,7 @@ import org.junit.Test;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createMockBuilder;
@@ -51,6 +54,7 @@ import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 public class ClusterImplTest {
 
@@ -256,4 +260,50 @@ public class ClusterImplTest {
     assertTrue("All components of the deleted service should be removed from all hosts",
checkHost1 && checkHost2);
 
   }
+
+  @Test
+  public void testDeleteHost() throws Exception {
+    // Given
+
+
+    String clusterName = "TEST_DELETE_HOST";
+    String hostName1 = "HOSTNAME1", hostName2 = "HOSTNAME2";
+    String hostToDelete = hostName2;
+
+    clusters.addCluster(clusterName, new StackId("HDP-2.1.1"));
+
+    Cluster cluster = clusters.getCluster(clusterName);
+
+    clusters.addHost(hostName1);
+    clusters.addHost(hostName2);
+
+    Host host1 = clusters.getHost(hostName1);
+    host1.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version",
"6.0"));
+    host1.persist();
+
+    Host host2 = clusters.getHost(hostName2);
+    host2.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version",
"6.0"));
+    host2.persist();
+
+    clusters.mapHostsToCluster(Sets.newHashSet(hostName1, hostName2), clusterName);
+
+    // When
+    clusters.deleteHost(hostToDelete);
+
+    // Then
+    assertTrue(clusters.getClustersForHost(hostToDelete).isEmpty());
+    assertFalse(clusters.getHostsForCluster(clusterName).containsKey(hostToDelete));
+
+    assertFalse(cluster.getHosts().contains(hostToDelete));
+
+    try {
+      clusters.getHost(hostToDelete);
+      fail("getHost(hostName) should throw Exception when invoked for deleted host !");
+    }
+    catch(HostNotFoundException e){
+
+    }
+
+
+  }
 }
\ No newline at end of file


Mime
View raw message