@Test public void testOnServiceComponentEvent() throws AmbariException { String INSTALLED_VERSION = "2.2.0-1000"; String INSTALLED_VERSION_2 = "2.1.1-2000"; StackId stackId = new StackId(this.stackId); StackId yaStackId = new StackId(yetAnotherStackId); createClusterAndHosts(INSTALLED_VERSION, stackId); addRepoVersion(INSTALLED_VERSION_2, yaStackId); List<String> hostList = new ArrayList<String>(); hostList.add("h1"); hostList.add("h2"); hostList.add("h3"); addServiceComponent(c1, hostList, "ZOOKEEPER", "ZOOKEEPER_CLIENT"); Set<String> changedHosts = new HashSet<String>(); changedHosts.add("h1"); changedHosts.add("h2"); changedHosts.add("h3"); assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION, RepositoryVersionState.INSTALLED); List<HostVersionEntity> hostVersions = hostVersionDAO.findAll(); for (HostVersionEntity hostVersionEntity : hostVersions) { RepositoryVersionEntity repoVersion = hostVersionEntity.getRepositoryVersion(); if (repoVersion.getVersion().equals(INSTALLED_VERSION) || repoVersion.getVersion().equals(INSTALLED_VERSION_2)) { if (changedHosts.contains(hostVersionEntity.getHostName())) { assertEquals(hostVersionEntity.getState(), RepositoryVersionState.OUT_OF_SYNC); } else { assertEquals(hostVersionEntity.getState(), RepositoryVersionState.INSTALLED); } } } }
@Subscribe @Transactional public void onServiceComponentEvent(ServiceComponentInstalledEvent event) { if (LOG.isDebugEnabled()) { LOG.debug(event.toString()); } m_lock.lock(); try { Cluster cluster = clusters.get().getClusterById(event.getClusterId()); List<HostVersionEntity> hostVersionEntities = hostVersionDAO.get().findByClusterAndHost(cluster.getClusterName(), event.getHostName()); for (HostVersionEntity hostVersionEntity : hostVersionEntities) { StackEntity hostStackEntity = hostVersionEntity.getRepositoryVersion().getStack(); StackId hostStackId = new StackId(hostStackEntity); String serviceName = event.getServiceName(); String componentName = event.getComponentName(); ComponentInfo component = ami.get().getComponent(hostStackId.getStackName(), hostStackId.getStackVersion(), serviceName, componentName); if (!component.isVersionAdvertised()) { RepositoryVersionState state = checkAllHostComponents(hostStackId, hostVersionEntity.getHostEntity()); if (null != state) { hostVersionEntity.setState(state); hostVersionDAO.get().merge(hostVersionEntity); } continue; } switch (hostVersionEntity.getState()) { case INSTALLED: case NOT_REQUIRED: hostVersionEntity.setState(RepositoryVersionState.OUT_OF_SYNC); hostVersionDAO.get().merge(hostVersionEntity); cluster.recalculateClusterVersionState(hostVersionEntity.getRepositoryVersion()); break; default: break; } } } catch (AmbariException e) { LOG.error("Can not update hosts about out of sync", e); } finally { m_lock.unlock(); } }
HostVersionOutOfSyncListener { @Subscribe @Transactional public void onServiceComponentEvent(ServiceComponentInstalledEvent event) { if (LOG.isDebugEnabled()) { LOG.debug(event.toString()); } m_lock.lock(); try { Cluster cluster = clusters.get().getClusterById(event.getClusterId()); List<HostVersionEntity> hostVersionEntities = hostVersionDAO.get().findByClusterAndHost(cluster.getClusterName(), event.getHostName()); for (HostVersionEntity hostVersionEntity : hostVersionEntities) { StackEntity hostStackEntity = hostVersionEntity.getRepositoryVersion().getStack(); StackId hostStackId = new StackId(hostStackEntity); String serviceName = event.getServiceName(); String componentName = event.getComponentName(); ComponentInfo component = ami.get().getComponent(hostStackId.getStackName(), hostStackId.getStackVersion(), serviceName, componentName); if (!component.isVersionAdvertised()) { RepositoryVersionState state = checkAllHostComponents(hostStackId, hostVersionEntity.getHostEntity()); if (null != state) { hostVersionEntity.setState(state); hostVersionDAO.get().merge(hostVersionEntity); } continue; } switch (hostVersionEntity.getState()) { case INSTALLED: case NOT_REQUIRED: hostVersionEntity.setState(RepositoryVersionState.OUT_OF_SYNC); hostVersionDAO.get().merge(hostVersionEntity); cluster.recalculateClusterVersionState(hostVersionEntity.getRepositoryVersion()); break; default: break; } } } catch (AmbariException e) { LOG.error("Can not update hosts about out of sync", e); } finally { m_lock.unlock(); } } }
HostVersionOutOfSyncListener { @Subscribe @Transactional public void onServiceComponentEvent(ServiceComponentInstalledEvent event) { if (LOG.isDebugEnabled()) { LOG.debug(event.toString()); } m_lock.lock(); try { Cluster cluster = clusters.get().getClusterById(event.getClusterId()); List<HostVersionEntity> hostVersionEntities = hostVersionDAO.get().findByClusterAndHost(cluster.getClusterName(), event.getHostName()); for (HostVersionEntity hostVersionEntity : hostVersionEntities) { StackEntity hostStackEntity = hostVersionEntity.getRepositoryVersion().getStack(); StackId hostStackId = new StackId(hostStackEntity); String serviceName = event.getServiceName(); String componentName = event.getComponentName(); ComponentInfo component = ami.get().getComponent(hostStackId.getStackName(), hostStackId.getStackVersion(), serviceName, componentName); if (!component.isVersionAdvertised()) { RepositoryVersionState state = checkAllHostComponents(hostStackId, hostVersionEntity.getHostEntity()); if (null != state) { hostVersionEntity.setState(state); hostVersionDAO.get().merge(hostVersionEntity); } continue; } switch (hostVersionEntity.getState()) { case INSTALLED: case NOT_REQUIRED: hostVersionEntity.setState(RepositoryVersionState.OUT_OF_SYNC); hostVersionDAO.get().merge(hostVersionEntity); cluster.recalculateClusterVersionState(hostVersionEntity.getRepositoryVersion()); break; default: break; } } } catch (AmbariException e) { LOG.error("Can not update hosts about out of sync", e); } finally { m_lock.unlock(); } } @Inject  HostVersionOutOfSyncListener(AmbariEventPublisher ambariEventPublisher, LockFactory lockFactory); }
HostVersionOutOfSyncListener { @Subscribe @Transactional public void onServiceComponentEvent(ServiceComponentInstalledEvent event) { if (LOG.isDebugEnabled()) { LOG.debug(event.toString()); } m_lock.lock(); try { Cluster cluster = clusters.get().getClusterById(event.getClusterId()); List<HostVersionEntity> hostVersionEntities = hostVersionDAO.get().findByClusterAndHost(cluster.getClusterName(), event.getHostName()); for (HostVersionEntity hostVersionEntity : hostVersionEntities) { StackEntity hostStackEntity = hostVersionEntity.getRepositoryVersion().getStack(); StackId hostStackId = new StackId(hostStackEntity); String serviceName = event.getServiceName(); String componentName = event.getComponentName(); ComponentInfo component = ami.get().getComponent(hostStackId.getStackName(), hostStackId.getStackVersion(), serviceName, componentName); if (!component.isVersionAdvertised()) { RepositoryVersionState state = checkAllHostComponents(hostStackId, hostVersionEntity.getHostEntity()); if (null != state) { hostVersionEntity.setState(state); hostVersionDAO.get().merge(hostVersionEntity); } continue; } switch (hostVersionEntity.getState()) { case INSTALLED: case NOT_REQUIRED: hostVersionEntity.setState(RepositoryVersionState.OUT_OF_SYNC); hostVersionDAO.get().merge(hostVersionEntity); cluster.recalculateClusterVersionState(hostVersionEntity.getRepositoryVersion()); break; default: break; } } } catch (AmbariException e) { LOG.error("Can not update hosts about out of sync", e); } finally { m_lock.unlock(); } } @Inject  HostVersionOutOfSyncListener(AmbariEventPublisher ambariEventPublisher, LockFactory lockFactory); @Subscribe @Transactional void onServiceComponentEvent(ServiceComponentInstalledEvent event); @Subscribe @Transactional void onServiceComponentHostEvent(ServiceComponentUninstalledEvent event); @Subscribe @Transactional void onServiceEvent(ServiceInstalledEvent event); @Subscribe @Transactional void onHostEvent(HostsAddedEvent event); @Subscribe @Transactional void onHostEvent(HostsRemovedEvent event); }
HostVersionOutOfSyncListener { @Subscribe @Transactional public void onServiceComponentEvent(ServiceComponentInstalledEvent event) { if (LOG.isDebugEnabled()) { LOG.debug(event.toString()); } m_lock.lock(); try { Cluster cluster = clusters.get().getClusterById(event.getClusterId()); List<HostVersionEntity> hostVersionEntities = hostVersionDAO.get().findByClusterAndHost(cluster.getClusterName(), event.getHostName()); for (HostVersionEntity hostVersionEntity : hostVersionEntities) { StackEntity hostStackEntity = hostVersionEntity.getRepositoryVersion().getStack(); StackId hostStackId = new StackId(hostStackEntity); String serviceName = event.getServiceName(); String componentName = event.getComponentName(); ComponentInfo component = ami.get().getComponent(hostStackId.getStackName(), hostStackId.getStackVersion(), serviceName, componentName); if (!component.isVersionAdvertised()) { RepositoryVersionState state = checkAllHostComponents(hostStackId, hostVersionEntity.getHostEntity()); if (null != state) { hostVersionEntity.setState(state); hostVersionDAO.get().merge(hostVersionEntity); } continue; } switch (hostVersionEntity.getState()) { case INSTALLED: case NOT_REQUIRED: hostVersionEntity.setState(RepositoryVersionState.OUT_OF_SYNC); hostVersionDAO.get().merge(hostVersionEntity); cluster.recalculateClusterVersionState(hostVersionEntity.getRepositoryVersion()); break; default: break; } } } catch (AmbariException e) { LOG.error("Can not update hosts about out of sync", e); } finally { m_lock.unlock(); } } @Inject  HostVersionOutOfSyncListener(AmbariEventPublisher ambariEventPublisher, LockFactory lockFactory); @Subscribe @Transactional void onServiceComponentEvent(ServiceComponentInstalledEvent event); @Subscribe @Transactional void onServiceComponentHostEvent(ServiceComponentUninstalledEvent event); @Subscribe @Transactional void onServiceEvent(ServiceInstalledEvent event); @Subscribe @Transactional void onHostEvent(HostsAddedEvent event); @Subscribe @Transactional void onHostEvent(HostsRemovedEvent event);  }