Repository: ambari Updated Branches: refs/heads/trunk b65b7c2dd -> a6dd447b0
AMBARI-15457. Topology host info is not cleared when a host is removed. (Daniel Gergely via stoader) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a6dd447b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a6dd447b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a6dd447b Branch: refs/heads/trunk Commit: a6dd447b0878029197f00b2f4cd34adba88e5d47 Parents: b65b7c2 Author: Toader, Sebastian <stoa...@hortonworks.com> Authored: Sat Mar 19 11:52:51 2016 +0100 Committer: Toader, Sebastian <stoa...@hortonworks.com> Committed: Sat Mar 19 11:52:51 2016 +0100 ---------------------------------------------------------------------- .../internal/HostResourceProvider.java | 30 ++++- .../server/orm/dao/TopologyHostInfoDAO.java | 116 +++++++++++++++++++ .../orm/entities/TopologyHostInfoEntity.java | 13 +++ .../server/state/cluster/ClustersImpl.java | 4 + .../ambari/server/topology/ClusterTopology.java | 48 ++++---- .../server/topology/ClusterTopologyImpl.java | 7 ++ .../ambari/server/topology/HostGroupInfo.java | 10 ++ .../ambari/server/topology/PersistedState.java | 4 + .../server/topology/PersistedStateImpl.java | 18 +++ .../ambari/server/topology/TopologyManager.java | 3 +- .../server/upgrade/UpgradeCatalog222.java | 6 +- .../main/resources/Ambari-DDL-MySQL-CREATE.sql | 2 + .../main/resources/Ambari-DDL-Oracle-CREATE.sql | 2 + .../resources/Ambari-DDL-Postgres-CREATE.sql | 2 + .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql | 2 + .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 2 + .../resources/Ambari-DDL-SQLServer-CREATE.sql | 2 + .../AmbariManagementControllerTest.java | 8 +- .../internal/HostResourceProviderTest.java | 1 + 19 files changed, 255 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/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 6251f07..1ffd3aa 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 @@ -64,6 +64,7 @@ import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.ServiceComponent; import org.apache.ambari.server.state.ServiceComponentHost; import org.apache.ambari.server.state.stack.OsFamily; +import org.apache.ambari.server.topology.ClusterTopology; import org.apache.ambari.server.topology.InvalidTopologyException; import org.apache.ambari.server.topology.InvalidTopologyTemplateException; import org.apache.ambari.server.topology.LogicalRequest; @@ -75,6 +76,7 @@ import org.slf4j.LoggerFactory; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; +import com.google.inject.persist.Transactional; /** @@ -821,7 +823,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider { } } - + @Transactional protected void deleteHosts(Set<HostRequest> requests) throws AmbariException { @@ -886,6 +888,8 @@ public class HostResourceProvider extends AbstractControllerResourceProvider { // Assume the user also wants to delete it entirely, including all clusters. clusters.deleteHost(hostRequest.getHostname()); + removeHostFromClusterTopology(clusters, hostRequest); + for (LogicalRequest logicalRequest: topologyManager.getRequests(Collections.<Long>emptyList())) { logicalRequest.removeHostRequestByHostName(hostRequest.getHostname()); } @@ -897,6 +901,30 @@ public class HostResourceProvider extends AbstractControllerResourceProvider { } /** + * Removes hostname from the stateful cluster topology + * @param clusters + * @param hostRequest + * @throws AmbariException + */ + private void removeHostFromClusterTopology(Clusters clusters, HostRequest hostRequest) throws AmbariException{ + if(hostRequest.getClusterName() == null) { + for( Cluster c : clusters.getClusters().values()) { + removeHostFromClusterTopology(c.getClusterId(), hostRequest.getHostname()); + } + } else { + long clusterId = clusters.getCluster(hostRequest.getClusterName()).getClusterId(); + removeHostFromClusterTopology(clusterId, hostRequest.getHostname()); + } + } + + private void removeHostFromClusterTopology(long clusterId, String hostname) { + ClusterTopology clusterTopology = topologyManager.getClusterTopology(clusterId); + if(clusterTopology != null) { + clusterTopology.removeHost(hostname); + } + } + + /** * Obtain the hostname from the request properties. The hostname property name may differ * depending on the request type. For the low level host resource creation calls, it is always * "Hosts/host_name". For multi host "add host from hostgroup", the hostname property is a top level http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostInfoDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostInfoDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostInfoDAO.java new file mode 100644 index 0000000..98979e5 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostInfoDAO.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.dao; + +import java.util.Collections; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.NoResultException; +import javax.persistence.TypedQuery; + +import org.apache.ambari.server.orm.RequiresSession; +import org.apache.ambari.server.orm.entities.HostEntity; +import org.apache.ambari.server.orm.entities.TopologyHostInfoEntity; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Singleton; +import com.google.inject.persist.Transactional; + +@Singleton +public class TopologyHostInfoDAO { + + @Inject + Provider<EntityManager> entityManagerProvider; + + /** + * Looks for TopologyHostInfo by ID + * @param hostInfoId ID of topology host info + * @return Found entity or NULL + */ + @RequiresSession + public TopologyHostInfoEntity findById(long hostInfoId) { + return entityManagerProvider.get().find(TopologyHostInfoEntity.class, hostInfoId); + } + + @RequiresSession + public List<TopologyHostInfoEntity> findByHost(HostEntity host) { + TypedQuery<TopologyHostInfoEntity> query = entityManagerProvider.get().createQuery( + "SELECT hostInfo FROM TopologyHostInfoEntity hostInfo where hostInfo.hostEntity=:host", TopologyHostInfoEntity.class); + query.setParameter("host", host); + try { + return query.getResultList(); + } catch (NoResultException ignored) { + return null; + } + } + + @RequiresSession + public List<TopologyHostInfoEntity> findAll() { + TypedQuery<TopologyHostInfoEntity> query = entityManagerProvider.get().createQuery("SELECT hostInfo FROM TopologyHostInfoEntity hostInfo", TopologyHostInfoEntity.class); + try { + return query.getResultList(); + } catch (NoResultException e) { + return Collections.emptyList(); + } + } + + /** + * Refreshes entity state from database + * @param topologyHostInfoEntity entity to refresh + */ + @Transactional + public void refresh(TopologyHostInfoEntity topologyHostInfoEntity) { + entityManagerProvider.get().refresh(topologyHostInfoEntity); + } + + @Transactional + public void create(TopologyHostInfoEntity topologyHostInfoEntity) { + entityManagerProvider.get().persist(topologyHostInfoEntity); + } + + @Transactional + public TopologyHostInfoEntity merge(TopologyHostInfoEntity topologyHostInfoEntity) { + return entityManagerProvider.get().merge(topologyHostInfoEntity); + } + + @Transactional + public void remove(TopologyHostInfoEntity topologyHostInfoEntity) { + entityManagerProvider.get().remove(merge(topologyHostInfoEntity)); + } + + @Transactional + public void removeByHost(HostEntity host) { + for(TopologyHostInfoEntity e : findByHost(host)) { + entityManagerProvider.get().remove(merge(e)); + } + } + + public TopologyHostInfoEntity findByHostname(String hostName) { + TypedQuery<TopologyHostInfoEntity> query = entityManagerProvider.get().createQuery( + "SELECT hostInfo FROM TopologyHostInfoEntity hostInfo where hostInfo.fqdn=:hostName", TopologyHostInfoEntity.class); + query.setParameter("hostName", hostName); + try { + return query.getSingleResult(); + } catch (NoResultException ignored) { + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java index a4f251a..acb86b4 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java @@ -24,6 +24,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.TableGenerator; @@ -41,6 +42,10 @@ public class TopologyHostInfoEntity { @Column(name = "fqdn", length = 255) private String fqdn; + @OneToOne + @JoinColumn(name="host_id") + private HostEntity hostEntity; + @Column(name = "host_count", length = 10) private Integer hostCount; @@ -106,6 +111,14 @@ public class TopologyHostInfoEntity { this.rackInfo = rackInfo; } + public HostEntity getHostEntity() { + return hostEntity; + } + + public void setHostEntity(HostEntity hostEntity) { + this.hostEntity = hostEntity; + } + @Override public boolean equals(Object o) { if (this == o) return true; http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/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 1d8bdbb..6c68d0e 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 @@ -45,6 +45,7 @@ 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.TopologyHostInfoDAO; import org.apache.ambari.server.orm.dao.TopologyHostRequestDAO; import org.apache.ambari.server.orm.dao.TopologyLogicalTaskDAO; import org.apache.ambari.server.orm.dao.TopologyRequestDAO; @@ -151,6 +152,8 @@ public class ClustersImpl implements Clusters { private TopologyHostRequestDAO topologyHostRequestDAO; @Inject private TopologyRequestDAO topologyRequestDAO; + @Inject + private TopologyHostInfoDAO topologyHostInfoDAO; /** * Data access object for stacks. @@ -900,6 +903,7 @@ public class ClustersImpl implements Clusters { hostConfigMappingDAO.removeByHostId(entity.getHostId()); serviceConfigDAO.removeHostFromServiceConfigs(entity.getHostId()); requestOperationLevelDAO.removeByHostId(entity.getHostId()); + topologyHostInfoDAO.removeByHost(entity); // Remove from dictionaries hosts.remove(hostname); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java index 4e178c0..3cdca4d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java @@ -35,21 +35,21 @@ public interface ClusterTopology { * * @return cluster id */ - public Long getClusterId(); + Long getClusterId(); /** * Set the id of the cluster. * * @param clusterId cluster id */ - public void setClusterId(Long clusterId); + void setClusterId(Long clusterId); /** * Get the blueprint associated with the cluster. * * @return assocaited blueprint */ - public Blueprint getBlueprint(); + Blueprint getBlueprint(); /** * Get the cluster scoped configuration for the cluster. @@ -58,14 +58,14 @@ public interface ClusterTopology { * * @return cluster scoped configuration */ - public Configuration getConfiguration(); + Configuration getConfiguration(); /** * Get host group information. * * @return map of host group name to host group information */ - public Map<String, HostGroupInfo> getHostGroupInfo(); + Map<String, HostGroupInfo> getHostGroupInfo(); /** * Get the names of all of host groups which contain the specified component. @@ -74,7 +74,7 @@ public interface ClusterTopology { * * @return collection of host group names which contain the specified component */ - public Collection<String> getHostGroupsForComponent(String component); + Collection<String> getHostGroupsForComponent(String component); /** * Get the name of the host group which is mapped to the specified host. @@ -84,7 +84,7 @@ public interface ClusterTopology { * @return name of the host group which is mapped to the specified host or null if * no group is mapped to the host */ - public String getHostGroupForHost(String hostname); + String getHostGroupForHost(String hostname); /** * Get all hosts which are mapped to a host group which contains the specified component. @@ -94,7 +94,7 @@ public interface ClusterTopology { * * @return collection of hosts for the specified component; will not return null */ - public Collection<String> getHostAssignmentsForComponent(String component); + Collection<String> getHostAssignmentsForComponent(String component); /** * Update the existing topology based on the provided topology request. @@ -104,7 +104,7 @@ public interface ClusterTopology { * @throws InvalidTopologyException if the request specified invalid topology information or if * making the requested changes would result in an invalid topology */ - public void update(TopologyRequest topologyRequest) throws InvalidTopologyException; + void update(TopologyRequest topologyRequest) throws InvalidTopologyException; /** * Add a new host to the topology. @@ -115,28 +115,28 @@ public interface ClusterTopology { * @throws InvalidTopologyException if the host being added is already registered to a different host group * @throws NoSuchHostGroupException if the specified host group is invalid */ - public void addHostToTopology(String hostGroupName, String host) throws InvalidTopologyException, NoSuchHostGroupException; + void addHostToTopology(String hostGroupName, String host) throws InvalidTopologyException, NoSuchHostGroupException; /** * Determine if NameNode HA is enabled. * * @return true if NameNode HA is enabled; false otherwise */ - public boolean isNameNodeHAEnabled(); + boolean isNameNodeHAEnabled(); /** * Determine if Yarn ResourceManager HA is enabled. * * @return true if Yarn ResourceManager HA is enabled; false otherwise */ - public boolean isYarnResourceManagerHAEnabled(); + boolean isYarnResourceManagerHAEnabled(); /** * Determine if the cluster is kerberos enabled. * * @return true if the cluster is kerberos enabled; false otherwise */ - public boolean isClusterKerberosEnabled(); + boolean isClusterKerberosEnabled(); /** * Install the specified host. @@ -144,7 +144,7 @@ public interface ClusterTopology { * @param hostName host name * @return install response */ - public RequestStatusResponse installHost(String hostName); + RequestStatusResponse installHost(String hostName); /** * Start the specified host. @@ -152,23 +152,29 @@ public interface ClusterTopology { * @param hostName host name * @return start response */ - public RequestStatusResponse startHost(String hostName); + RequestStatusResponse startHost(String hostName); - public void setConfigRecommendationStrategy(ConfigRecommendationStrategy strategy); + void setConfigRecommendationStrategy(ConfigRecommendationStrategy strategy); - public ConfigRecommendationStrategy getConfigRecommendationStrategy(); + ConfigRecommendationStrategy getConfigRecommendationStrategy(); /** * Set request provision action : INSTALL vs INSTALL_AND_START * @param provisionAction @ProvisionAction */ - public void setProvisionAction(ProvisionAction provisionAction); + void setProvisionAction(ProvisionAction provisionAction); - public ProvisionAction getProvisionAction(); + ProvisionAction getProvisionAction(); - public Map<String, AdvisedConfiguration> getAdvisedConfigurations(); + Map<String, AdvisedConfiguration> getAdvisedConfigurations(); //todo: don't expose ambari context from this class - public AmbariContext getAmbariContext(); + AmbariContext getAmbariContext(); + + /** + * Removes host from stateful ClusterTopology + * @param hostname + */ + void removeHost(String hostname); } http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java index 003539c..4f2f02d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java @@ -280,6 +280,13 @@ public class ClusterTopologyImpl implements ClusterTopology { return ambariContext; } + @Override + public void removeHost(String hostname) { + for(Map.Entry<String,HostGroupInfo> entry : hostGroupInfoMap.entrySet()) { + entry.getValue().removeHost(hostname); + } + } + private void registerHostGroupInfo(Map<String, HostGroupInfo> requestedHostGroupInfoMap) throws InvalidTopologyException { LOG.debug("Registering requested host group information for {} hostgroups", requestedHostGroupInfoMap.size()); checkForDuplicateHosts(requestedHostGroupInfoMap); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupInfo.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupInfo.java index 4847a11..c6704a0 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupInfo.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupInfo.java @@ -232,4 +232,14 @@ public class HostGroupInfo { } } + /** + * Removes hostname from group + * @param hostname + */ + public void removeHost(String hostname) { + synchronized (hostNames) { + hostNames.remove(hostname); + } + } + } http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java index dbf6735..1ccd527 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java @@ -21,6 +21,8 @@ package org.apache.ambari.server.topology; import java.util.List; import java.util.Map; +import org.apache.ambari.server.state.Host; + /** * Persistence abstraction. */ @@ -66,4 +68,6 @@ public interface PersistedState { * @return map of cluster topology to list of logical requests */ Map<ClusterTopology, List<LogicalRequest>> getAllRequests(); + + void registerInTopologyHostInfo(Host host); } http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java index b878955..324a397 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java @@ -23,8 +23,10 @@ import com.google.inject.Inject; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.actionmanager.HostRoleCommand; import org.apache.ambari.server.api.predicate.InvalidQueryException; +import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.orm.dao.HostRoleCommandDAO; import org.apache.ambari.server.orm.dao.TopologyHostGroupDAO; +import org.apache.ambari.server.orm.dao.TopologyHostInfoDAO; import org.apache.ambari.server.orm.dao.TopologyHostRequestDAO; import org.apache.ambari.server.orm.dao.TopologyLogicalTaskDAO; import org.apache.ambari.server.orm.dao.TopologyRequestDAO; @@ -37,6 +39,7 @@ 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.stack.NoSuchStackException; +import org.apache.ambari.server.state.Host; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +64,12 @@ public class PersistedStateImpl implements PersistedState { private TopologyRequestDAO topologyRequestDAO; @Inject + private TopologyHostInfoDAO topologyHostInfoDAO; + + @Inject + private HostDAO hostDAO; + + @Inject private TopologyHostGroupDAO hostGroupDAO; @Inject @@ -125,6 +134,15 @@ public class PersistedStateImpl implements PersistedState { } @Override + public void registerInTopologyHostInfo(Host host) { + TopologyHostInfoEntity entity = topologyHostInfoDAO.findByHostname(host.getHostName()); + if(entity != null && entity.getHostEntity() == null) { + entity.setHostEntity(hostDAO.findById(host.getHostId())); + topologyHostInfoDAO.merge(entity); + } + } + + @Override public Map<ClusterTopology, List<LogicalRequest>> getAllRequests() { //todo: we only currently support a single request per ambari instance so there should only //todo: be a single cluster topology http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/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 41f3150..c317162 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 @@ -581,7 +581,7 @@ public class TopologyManager { return logicalRequest; } - private void processAcceptedHostOffer(ClusterTopology topology, final HostOfferResponse response, HostImpl host) { + private void processAcceptedHostOffer(ClusterTopology topology, final HostOfferResponse response, final HostImpl host) { final String hostName = host.getHostName(); try { topology.addHostToTopology(response.getHostGroupName(), hostName); @@ -603,6 +603,7 @@ public class TopologyManager { @Override public Object call() throws Exception { persistedState.registerHostName(response.getHostRequestId(), hostName); + persistedState.registerInTopologyHostInfo(host); return null; } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java index 84bb9f3..e5a94cb 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java @@ -27,6 +27,7 @@ import com.google.inject.Injector; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.controller.AmbariManagementController; +import org.apache.ambari.server.orm.DBAccessor; import org.apache.ambari.server.orm.dao.AlertDefinitionDAO; import org.apache.ambari.server.orm.dao.DaoUtils; import org.apache.ambari.server.orm.dao.WidgetDAO; @@ -144,7 +145,10 @@ public class UpgradeCatalog222 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { - //To change body of implemented methods use File | Settings | File Templates. + DBAccessor.DBColumnInfo columnInfo = new DBAccessor.DBColumnInfo("host_id", Long.class); + dbAccessor.addColumn("topology_host_info", columnInfo); + dbAccessor.addFKConstraint("topology_host_info", "FK_hostinfo_host_id", "host_id", "hosts", "host_id", true); + dbAccessor.executeUpdate("update topology_host_info set host_id = (select hosts.host_id from hosts where hosts.host_name = topology_host_info.fqdn)"); } @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql index fb24c89..a07c6fc 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql @@ -636,6 +636,7 @@ CREATE TABLE topology_host_info ( id BIGINT NOT NULL, group_id BIGINT NOT NULL, fqdn VARCHAR(255), + host_id BIGINT, host_count INTEGER, predicate VARCHAR(2048), rack_info VARCHAR(255), @@ -827,6 +828,7 @@ ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY (w ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id); ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); +ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_host_id FOREIGN KEY (host_id) REFERENCES hosts(host_id); ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql index 2e092b2..b2b450a 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -625,6 +625,7 @@ CREATE TABLE topology_host_info ( id NUMBER(19) NOT NULL, group_id NUMBER(19) NOT NULL, fqdn VARCHAR(255), + host_id NUMBER(19), host_count INTEGER, predicate VARCHAR(2048), rack_info VARCHAR(255), @@ -817,6 +818,7 @@ ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY (w ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id); ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); +ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_host_id FOREIGN KEY (host_id) REFERENCES hosts(host_id); ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql index 5f5df3c..cec122e 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -629,6 +629,7 @@ CREATE TABLE topology_host_info ( id BIGINT NOT NULL, group_id BIGINT NOT NULL, fqdn VARCHAR(255), + host_id BIGINT, host_count INTEGER, predicate VARCHAR(2048), rack_info VARCHAR(255), @@ -821,6 +822,7 @@ ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY (w ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id); ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); +ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_host_id FOREIGN KEY (host_id) REFERENCES hosts(host_id); ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql index 3d71f1f..96fc720 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql @@ -705,6 +705,7 @@ CREATE TABLE ambari.topology_host_info ( id BIGINT NOT NULL, group_id BIGINT NOT NULL, fqdn VARCHAR(255), + host_id BIGINT, host_count INTEGER, predicate VARCHAR(2048), rack_info VARCHAR(255), @@ -904,6 +905,7 @@ ALTER TABLE ambari.widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN ALTER TABLE ambari.topology_request ADD CONSTRAINT FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters(cluster_id); ALTER TABLE ambari.topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY (request_id) REFERENCES ambari.topology_request(id); ALTER TABLE ambari.topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY (group_id) REFERENCES ambari.topology_hostgroup(id); +ALTER TABLE ambari.topology_host_info ADD CONSTRAINT FK_hostinfo_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts(host_id); ALTER TABLE ambari.topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES ambari.topology_request(id); ALTER TABLE ambari.topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES ambari.topology_logical_request(id); ALTER TABLE ambari.topology_host_request ADD CONSTRAINT FK_hostreq_group_id FOREIGN KEY (group_id) REFERENCES ambari.topology_hostgroup(id); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql index 9d70fbb..c425d6f 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql @@ -626,6 +626,7 @@ CREATE TABLE topology_host_info ( id NUMERIC(19) NOT NULL, group_id NUMERIC(19) NOT NULL, fqdn VARCHAR(255), + host_id NUMERIC(19), host_count INTEGER, predicate VARCHAR(2048), rack_info VARCHAR(255), @@ -816,6 +817,7 @@ ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY (w ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id); ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); +ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_host_id FOREIGN KEY (host_id) REFERENCES hosts(host_id); ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql index 715000e..2a89e26 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -733,6 +733,7 @@ CREATE TABLE topology_host_info ( id BIGINT NOT NULL, group_id BIGINT NOT NULL, fqdn VARCHAR(255), + host_id BIGINT, host_count INTEGER, predicate VARCHAR(2048), rack_info VARCHAR(255), @@ -927,6 +928,7 @@ ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY (w ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id); ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); +ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_host_id FOREIGN KEY (host_id) REFERENCES hosts(host_id); ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES topology_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id); ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_id FOREIGN KEY (group_id) REFERENCES topology_hostgroup(id); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java index c87e298..ca062c0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java @@ -93,6 +93,7 @@ import org.apache.ambari.server.orm.OrmTestHelper; import org.apache.ambari.server.orm.dao.ExecutionCommandDAO; import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.orm.dao.HostRoleCommandDAO; +import org.apache.ambari.server.orm.dao.TopologyHostInfoDAO; import org.apache.ambari.server.orm.dao.WidgetDAO; import org.apache.ambari.server.orm.dao.WidgetLayoutDAO; import org.apache.ambari.server.orm.entities.ExecutionCommandEntity; @@ -210,6 +211,7 @@ public class AmbariManagementControllerTest { private OrmTestHelper helper; private StageFactory stageFactory; private HostDAO hostDAO; + private TopologyHostInfoDAO topologyHostInfoDAO; private HostRoleCommandDAO hostRoleCommandDAO; private TopologyManager topologyManager; @@ -246,6 +248,7 @@ public class AmbariManagementControllerTest { helper = injector.getInstance(OrmTestHelper.class); stageFactory = injector.getInstance(StageFactory.class); hostDAO = injector.getInstance(HostDAO.class); + topologyHostInfoDAO = injector.getInstance(TopologyHostInfoDAO.class); hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class); topologyManager = injector.getInstance(TopologyManager.class); StageUtils.setTopologyManager(topologyManager); @@ -8619,6 +8622,8 @@ public class AmbariManagementControllerTest { Assert.assertEquals(0, cluster.getServiceComponentHosts(host1).size()); + Assert.assertNull(topologyHostInfoDAO.findByHostname(host1)); + // Deletion without specifying cluster should be successful requests.clear(); requests.add(new HostRequest(host1, null, null)); @@ -8630,7 +8635,7 @@ public class AmbariManagementControllerTest { // Verify host is no longer part of the cluster Assert.assertFalse(clusters.getHostsForCluster(clusterName).containsKey(host1)); Assert.assertFalse(clusters.getClustersForHost(host1).contains(cluster)); - + Assert.assertNull(topologyHostInfoDAO.findByHostname(host1)); // Case 3: Delete host that is still part of the cluster, and specify the cluster_name in the request requests.clear(); @@ -8643,6 +8648,7 @@ public class AmbariManagementControllerTest { // Verify host is no longer part of the cluster Assert.assertFalse(clusters.getHostsForCluster(clusterName).containsKey(host2)); Assert.assertFalse(clusters.getClustersForHost(host2).contains(cluster)); + Assert.assertNull(topologyHostInfoDAO.findByHostname(host2)); // Case 4: Attempt to delete a host that has already been deleted requests.clear(); http://git-wip-us.apache.org/repos/asf/ambari/blob/a6dd447b/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 4f4709e..23524d7 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 @@ -1075,6 +1075,7 @@ public class HostResourceProviderTest extends EasyMockSupport { expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes(); clusters.deleteHost("Host100"); expectLastCall().anyTimes(); + expect(clusters.getClusters()).andReturn(Collections.EMPTY_MAP); expect(host1.getHostName()).andReturn("Host100").anyTimes(); expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes(); expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();