ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject ambari git commit: AMBARI-15862. NPE when deleting a host (Daniel Gergely via oleewere)
Date Thu, 14 Apr 2016 15:58:07 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 32f7ec368 -> d63147ff0


AMBARI-15862. NPE when deleting a host (Daniel Gergely via oleewere)


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

Branch: refs/heads/trunk
Commit: d63147ff0dc8c949a060330a3c593f9f60ad5385
Parents: 32f7ec3
Author: dgergely <dgergely@hortonworks.com>
Authored: Thu Apr 14 17:55:28 2016 +0200
Committer: oleewere <oleewere@gmail.com>
Committed: Thu Apr 14 17:56:24 2016 +0200

----------------------------------------------------------------------
 .../orm/entities/TopologyHostGroupEntity.java   |   2 -
 .../server/state/cluster/ClustersImpl.java      |   2 +-
 .../server/state/cluster/ClustersTest.java      | 111 +++++++++++++++++++
 3 files changed, 112 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d63147ff/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
index 0a81286..a795552 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
@@ -51,8 +51,6 @@ public class TopologyHostGroupEntity {
   private Long id;
 
   @Column(name = "name", nullable = false, updatable = false)
-  @Basic(fetch = FetchType.LAZY)
-  @Lob
   private String name;
 
   @Column(name = "group_properties")

http://git-wip-us.apache.org/repos/asf/ambari/blob/d63147ff/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 caab7df..3dd3beb 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
@@ -911,7 +911,7 @@ public class ClustersImpl implements Clusters {
           TopologyLogicalRequestEntity topologyLogicalRequestEntity = topologyRequestEntity.getTopologyLogicalRequestEntity();
 
           for (TopologyHostRequestEntity topologyHostRequestEntity: topologyLogicalRequestEntity.getTopologyHostRequestEntities())
{
-            if (topologyHostRequestEntity.getHostName().equals(hostname)) {
+            if (hostname.equals(topologyHostRequestEntity.getHostName())) {
               topologyHostRequestDAO.remove(topologyHostRequestEntity);
             }
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/d63147ff/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
index 1b0cf8e..b563268 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
@@ -56,14 +56,20 @@ import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.topology.Blueprint;
 import org.apache.ambari.server.topology.Configuration;
 import org.apache.ambari.server.topology.HostGroupInfo;
+import org.apache.ambari.server.topology.HostRequest;
+import org.apache.ambari.server.topology.LogicalRequest;
 import org.apache.ambari.server.topology.PersistedState;
 import org.apache.ambari.server.topology.TopologyRequest;
+import org.apache.ambari.server.topology.TopologyTask;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 import javax.persistence.EntityManager;
+
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -566,4 +572,109 @@ public class ClustersTest {
     Assert.assertTrue(
         clusters.getCluster(c1).getCurrentStackVersion().getStackVersion().equals(stackId.getStackVersion()));
   }
+
+
+  @Test
+  public void testNullHostNamesInTopologyRequests() throws AmbariException {
+    final String hostName = "myhost";
+    final String clusterName = "mycluster";
+
+    Cluster cluster = createCluster(clusterName);
+    addHostToCluster(hostName, clusterName);
+    addHostToCluster(hostName + "2", clusterName);
+    addHostToCluster(hostName + "3", clusterName);
+
+    createTopologyRequest(cluster, hostName);
+    clusters.deleteHost(hostName);
+    for(Host h : cluster.getHosts()) {
+      if(hostName.equals(h.getHostName())) {
+        Assert.fail("Host is expected to be deleted");
+      }
+    }
+  }
+
+  private void createTopologyRequest(Cluster cluster, String hostName) {
+    final String groupName = "MyHostGroup";
+
+    // add topology request
+    Blueprint bp = createNiceMock(Blueprint.class);
+    expect(bp.getName()).andReturn("TestBluePrint").anyTimes();
+
+    Configuration clusterConfig = new Configuration(
+      Maps.<String, Map<String, String>>newHashMap(),
+      Maps.<String, Map<String, Map<String, String>>>newHashMap()
+    );
+
+    Map<String, HostGroupInfo> hostGroups = new HashMap<>();
+    HostGroupInfo hostGroupInfo = new HostGroupInfo(groupName);
+    hostGroupInfo.setConfiguration(clusterConfig);
+    hostGroupInfo.addHost(hostName);
+    hostGroupInfo.addHost(hostName + "2");
+    hostGroupInfo.addHost(hostName + "3");
+    hostGroups.put(groupName, hostGroupInfo);
+
+    TopologyRequest topologyRequest = createNiceMock(TopologyRequest.class);
+    expect(topologyRequest.getType()).andReturn(TopologyRequest.Type.PROVISION).anyTimes();
+    expect(topologyRequest.getBlueprint()).andReturn(bp).anyTimes();
+    expect(topologyRequest.getClusterId()).andReturn(cluster.getClusterId()).anyTimes();
+    expect(topologyRequest.getConfiguration()).andReturn(clusterConfig).anyTimes();
+    expect(topologyRequest.getDescription()).andReturn("Test description").anyTimes();
+    expect(topologyRequest.getHostGroupInfo()).andReturn(hostGroups).anyTimes();
+
+    replay(bp, topologyRequest);
+
+    persistedState.persistTopologyRequest(topologyRequest);
+
+    createTopologyLogicalRequest(cluster, hostName);
+  }
+
+  private HostRequest createHostRequest(long hrId, String hostName) {
+    HostRequest hr = createNiceMock(HostRequest.class);
+    expect(hr.getId()).andReturn(hrId).anyTimes();
+    expect(hr.getHostgroupName()).andReturn("MyHostGroup").anyTimes();
+    expect(hr.getHostName()).andReturn(hostName).anyTimes();
+    expect(hr.getStageId()).andReturn(1L);
+    expect(hr.getTopologyTasks()).andReturn(Collections.<TopologyTask>emptyList());
+
+    replay(hr);
+    return hr;
+  }
+
+  private void createTopologyLogicalRequest(Cluster cluster, String hostName) {
+    Collection<HostRequest> hostRequests = new ArrayList<>();
+    hostRequests.add(createHostRequest(1L, null));
+    hostRequests.add(createHostRequest(2L, hostName));
+    hostRequests.add(createHostRequest(3L, null));
+    hostRequests.add(createHostRequest(4L, hostName + "2"));
+    hostRequests.add(createHostRequest(5L, null));
+    hostRequests.add(createHostRequest(6L, hostName + "3"));
+
+    Long requestId = topologyRequestDAO.findByClusterId(cluster.getClusterId()).get(0).getId();
+    LogicalRequest logicalRequest = createNiceMock(LogicalRequest.class);
+    expect(logicalRequest.getHostRequests()).andReturn(hostRequests).anyTimes();
+    expect(logicalRequest.getRequestContext()).andReturn("Description").anyTimes();
+    expect(logicalRequest.getRequestId()).andReturn(1L).anyTimes();
+    replay(logicalRequest);
+
+    persistedState.persistLogicalRequest(logicalRequest, requestId);
+  }
+
+  private void addHostToCluster(String hostName, String clusterName) throws AmbariException
{
+    clusters.addHost(hostName);
+
+    Host host = clusters.getHost(hostName);
+    setOsFamily(clusters.getHost(hostName), "centos", "5.9");
+    host.persist();
+
+    Set<String> hostnames = new HashSet<>();
+    hostnames.add(hostName);
+    clusters.mapHostsToCluster(hostnames, clusterName);
+  }
+
+  private Cluster createCluster(String clusterName) throws AmbariException {
+    StackId stackId = new StackId("HDP-0.1");
+    clusters.addCluster(clusterName, stackId);
+
+    return clusters.getCluster(clusterName);
+  }
 }


Mime
View raw message