@Subscribe
  @Transactional
  public void onHostEvent(HostsAddedEvent event) {
    if (LOG.isDebugEnabled()) {
      LOG.debug(event.toString());
    }

    // create host version entries for every repository
    @Experimental(feature=ExperimentalFeature.PATCH_UPGRADES, comment="Eventually take into account deleted repositories")
    List<RepositoryVersionEntity> repos = repositoryVersionDAO.get().findAll();

    for (String hostName : event.getHostNames()) {
      HostEntity hostEntity = hostDAO.get().findByName(hostName);

      for (RepositoryVersionEntity repositoryVersion : repos) {

        // we don't have the knowledge yet to know if we need the record
        HostVersionEntity missingHostVersion = new HostVersionEntity(hostEntity,
            repositoryVersion, RepositoryVersionState.NOT_REQUIRED);

        LOG.info("Creating host version for {}, state={}, repo={} (repo_id={})",
          missingHostVersion.getHostName(), missingHostVersion.getState(),
          missingHostVersion.getRepositoryVersion().getVersion(), missingHostVersion.getRepositoryVersion().getId());

        hostVersionDAO.get().create(missingHostVersion);
        hostDAO.get().merge(hostEntity);

        hostEntity.getHostVersionEntities().add(missingHostVersion);
        hostEntity = hostDAO.get().merge(hostEntity);
      }
    }
  }
When hosts are added, add a host_version record for every repo_version in the database.

@param event the add event
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java