Repository: ambari Updated Branches: refs/heads/trunk f5b797c16 -> fa0893684
AMBARI-18005. Clean cached resources on host removal. (Laszlo Puskas via stoader) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fa089368 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fa089368 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fa089368 Branch: refs/heads/trunk Commit: fa0893684006ce083735552008770a6b62dc7a6c Parents: f5b797c Author: Laszlo Puskas <[email protected]> Authored: Fri Aug 5 15:05:30 2016 +0200 Committer: Toader, Sebastian <[email protected]> Committed: Fri Aug 5 16:35:10 2016 +0200 ---------------------------------------------------------------------- .../ambari/server/state/host/HostImpl.java | 9 +++--- .../ambari/server/topology/TopologyManager.java | 34 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/fa089368/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java index a757010..91b6360 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java @@ -65,8 +65,8 @@ import org.apache.ambari.server.state.fsm.SingleArcTransition; import org.apache.ambari.server.state.fsm.StateMachine; import org.apache.ambari.server.state.fsm.StateMachineFactory; import org.apache.ambari.server.topology.TopologyManager; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -77,7 +77,7 @@ import com.google.inject.persist.Transactional; public class HostImpl implements Host { - private static final Log LOG = LogFactory.getLog(HostImpl.class); + private static final Logger LOG = LoggerFactory.getLogger(HostImpl.class); private static final String HARDWAREISA = "hardware_isa"; private static final String HARDWAREMODEL = "hardware_model"; private static final String INTERFACES = "interfaces"; @@ -1217,7 +1217,7 @@ public class HostImpl implements Host { try { clusters.getClusterById(clusterEntity.getClusterId()).refresh(); } catch (AmbariException e) { - LOG.error(e); + LOG.error("Error while looking up the cluster", e); throw new RuntimeException("Cluster '" + clusterEntity.getClusterId() + "' was removed", e); } } @@ -1475,6 +1475,7 @@ public class HostImpl implements Host { } return hostStateEntity; } + } http://git-wip-us.apache.org/repos/asf/ambari/blob/fa089368/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 0190478..9a6ee94 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 @@ -34,7 +34,6 @@ import java.util.concurrent.Executors; import javax.inject.Inject; -import com.google.common.eventbus.Subscribe; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.actionmanager.HostRoleCommand; import org.apache.ambari.server.actionmanager.HostRoleStatus; @@ -57,6 +56,7 @@ import org.apache.ambari.server.controller.spi.ResourceProvider; import org.apache.ambari.server.controller.spi.SystemException; import org.apache.ambari.server.controller.spi.UnsupportedPropertyException; import org.apache.ambari.server.events.AmbariEvent; +import org.apache.ambari.server.events.HostRemovedEvent; import org.apache.ambari.server.events.RequestFinishedEvent; import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.orm.dao.HostRoleCommandStatusSummaryDTO; @@ -68,6 +68,7 @@ import org.apache.ambari.server.utils.RetryHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.eventbus.Subscribe; import com.google.inject.Singleton; /** @@ -337,7 +338,7 @@ public class TopologyManager { Map<String, String> requestInfoProps = new HashMap<>(); requestInfoProps.put(org.apache.ambari.server.controller.spi.Request.REQUEST_INFO_BODY_PROPERTY, - "{\"" + ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY + "\": " + descriptor + "}"); + "{\"" + ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY + "\": " + descriptor + "}"); org.apache.ambari.server.controller.spi.Request request = new RequestImpl(Collections.<String>emptySet(), Collections.singleton(properties), requestInfoProps, null); @@ -968,4 +969,33 @@ public class TopologyManager { return configTopologyResolved; } } + + /** + * + * Removes a host from the available hosts when the host gets deleted. + * @param hostRemovedEvent the event containing the hostname + */ + @Subscribe + public void processHostRemovedEvent(HostRemovedEvent hostRemovedEvent) { + LOG.info("Cleaning up caches on host removed event: {}", hostRemovedEvent.getHostName()); + + HostImpl toBeRemoved = null; + + // synchronization is required here as the list may be modified concurrently. See comments in this whole class. + synchronized (availableHosts) { + for (HostImpl hostImpl : availableHosts) { + if (hostRemovedEvent.getHostName().equals(hostImpl.getHostName())) { + toBeRemoved = hostImpl; + break; + } + } + + if (null != toBeRemoved) { + availableHosts.remove(toBeRemoved); + LOG.info("Removed host: [{}] from available hosts", toBeRemoved.getHostName()); + } else { + LOG.info("Host [{}] not found in available hosts", toBeRemoved.getHostName()); + } + } + } }
