@Test public void testFindByClusterStackVersionAndHost() { HostEntity host1 = hostDAO.findByName("test_host1"); HostEntity host2 = hostDAO.findByName("test_host2"); HostEntity host3 = hostDAO.findByName("test_host3"); HostVersionEntity hostVersionEntity1 = new HostVersionEntity(host1, helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2200), RepositoryVersionState.CURRENT); hostVersionEntity1.setId(1L); HostVersionEntity hostVersionEntity2 = new HostVersionEntity(host2, helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2200), RepositoryVersionState.INSTALLED); hostVersionEntity2.setId(2L); HostVersionEntity hostVersionEntity3 = new HostVersionEntity(host3, helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2200), RepositoryVersionState.INSTALLED); hostVersionEntity3.setId(3L); Assert.assertEquals(hostVersionEntity1, hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, repoVersion_2200, "test_host1")); Assert.assertEquals(hostVersionEntity2, hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, repoVersion_2200, "test_host2")); Assert.assertEquals(hostVersionEntity3, hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, repoVersion_2200, "test_host3")); Assert.assertEquals(null, hostVersionDAO.findByClusterStackVersionAndHost("non_existent_cluster", HDP_22_STACK, repoVersion_2200, "test_host3")); Assert.assertEquals(null, hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", BAD_STACK, repoVersion_2200, "test_host3")); Assert.assertEquals(null, hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, "non_existent_version", "test_host3")); Assert.assertEquals(null, hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, "non_existent_version", "non_existent_host")); addMoreVersions(); HostVersionEntity hostVersionEntity1LastExpected = new HostVersionEntity(host1, helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2202), RepositoryVersionState.INSTALLED); HostVersionEntity hostVersionEntity2LastExpected = new HostVersionEntity(host2, helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2202), RepositoryVersionState.INSTALLING); HostVersionEntity hostVersionEntity3LastExpected = new HostVersionEntity(host3, helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2202), RepositoryVersionState.INSTALL_FAILED); HostVersionEntity hostVersionEntity1LastActual = hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, repoVersion_2202, "test_host1"); HostVersionEntity hostVersionEntity2LastActual = hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, repoVersion_2202, "test_host2"); HostVersionEntity hostVersionEntity3LastActual = hostVersionDAO.findByClusterStackVersionAndHost("test_cluster1", HDP_22_STACK, repoVersion_2202, "test_host3"); Assert.assertEquals(hostVersionEntity1LastExpected, new HostVersionEntity(hostVersionEntity1LastActual)); Assert.assertEquals(hostVersionEntity2LastExpected, new HostVersionEntity(hostVersionEntity2LastActual)); Assert.assertEquals(hostVersionEntity3LastExpected, new HostVersionEntity(hostVersionEntity3LastActual)); }
@RequiresSession public HostVersionEntity findByClusterStackVersionAndHost(String clusterName, StackId stackId, String version, String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterStackVersionAndHostname", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("stackName", stackId.getStackName()); query.setParameter("stackVersion", stackId.getStackVersion()); query.setParameter("version", version); query.setParameter("hostName", hostName); return daoUtils.selectSingle(query); }
HostVersionDAO extends CrudDAO<HostVersionEntity, Long> { @RequiresSession public HostVersionEntity findByClusterStackVersionAndHost(String clusterName, StackId stackId, String version, String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterStackVersionAndHostname", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("stackName", stackId.getStackName()); query.setParameter("stackVersion", stackId.getStackVersion()); query.setParameter("version", version); query.setParameter("hostName", hostName); return daoUtils.selectSingle(query); } }
HostVersionDAO extends CrudDAO<HostVersionEntity, Long> { @RequiresSession public HostVersionEntity findByClusterStackVersionAndHost(String clusterName, StackId stackId, String version, String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterStackVersionAndHostname", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("stackName", stackId.getStackName()); query.setParameter("stackVersion", stackId.getStackVersion()); query.setParameter("version", version); query.setParameter("hostName", hostName); return daoUtils.selectSingle(query); } HostVersionDAO(); }
HostVersionDAO extends CrudDAO<HostVersionEntity, Long> { @RequiresSession public HostVersionEntity findByClusterStackVersionAndHost(String clusterName, StackId stackId, String version, String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterStackVersionAndHostname", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("stackName", stackId.getStackName()); query.setParameter("stackVersion", stackId.getStackVersion()); query.setParameter("version", version); query.setParameter("hostName", hostName); return daoUtils.selectSingle(query); } HostVersionDAO(); @Override @Transactional void create(HostVersionEntity entity); @RequiresSession List<HostVersionEntity> findByClusterStackAndVersion(
      String clusterName, StackId stackId, String version); @RequiresSession List<HostVersionEntity> findByHost(String hostName); @RequiresSession List<HostVersionEntity> findByClusterAndHost(String  clusterName, String hostName); @RequiresSession List<HostVersionEntity> findByClusterHostAndState(String  clusterName, String hostName, RepositoryVersionState state); @RequiresSession List<HostVersionEntity> findByClusterHostAndState(long clusterId, long hostId, RepositoryVersionState state); @RequiresSession HostVersionEntity findByHostAndStateCurrent(String clusterName, String hostName); @RequiresSession HostVersionEntity findByHostAndStateCurrent(long clusterId, long hostId); @RequiresSession HostVersionEntity findByClusterStackVersionAndHost(String clusterName,
      StackId stackId, String version, String hostName); @RequiresSession HostVersionEntity findByClusterStackVersionAndHost(long clusterId, StackId stackId, String version,
                                                            long hostId); @Transactional void removeByHostName(String hostName); @Transactional void updateVersions(RepositoryVersionEntity target, RepositoryVersionEntity current); }
HostVersionDAO extends CrudDAO<HostVersionEntity, Long> { @RequiresSession public HostVersionEntity findByClusterStackVersionAndHost(String clusterName, StackId stackId, String version, String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterStackVersionAndHostname", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("stackName", stackId.getStackName()); query.setParameter("stackVersion", stackId.getStackVersion()); query.setParameter("version", version); query.setParameter("hostName", hostName); return daoUtils.selectSingle(query); } HostVersionDAO(); @Override @Transactional void create(HostVersionEntity entity); @RequiresSession List<HostVersionEntity> findByClusterStackAndVersion(
      String clusterName, StackId stackId, String version); @RequiresSession List<HostVersionEntity> findByHost(String hostName); @RequiresSession List<HostVersionEntity> findByClusterAndHost(String  clusterName, String hostName); @RequiresSession List<HostVersionEntity> findByClusterHostAndState(String  clusterName, String hostName, RepositoryVersionState state); @RequiresSession List<HostVersionEntity> findByClusterHostAndState(long clusterId, long hostId, RepositoryVersionState state); @RequiresSession HostVersionEntity findByHostAndStateCurrent(String clusterName, String hostName); @RequiresSession HostVersionEntity findByHostAndStateCurrent(long clusterId, long hostId); @RequiresSession HostVersionEntity findByClusterStackVersionAndHost(String clusterName,
      StackId stackId, String version, String hostName); @RequiresSession HostVersionEntity findByClusterStackVersionAndHost(long clusterId, StackId stackId, String version,
                                                            long hostId); @Transactional void removeByHostName(String hostName); @Transactional void updateVersions(RepositoryVersionEntity target, RepositoryVersionEntity current);  }