@Test public void testZKQuorumPropertiesSetCorrectly() throws Exception { final String zookeeperQuorum = "c6401.ambari.apache.org:2181,c6402.ambari.apache.org:2181"; PowerMockito.mockStatic(ZooKeeperQuorumCalculator.class); PowerMockito.when(ZooKeeperQuorumCalculator.getZooKeeperQuorumString(m_cluster)).thenReturn( zookeeperQuorum); Map<String, String> hiveSiteProperties = new HashMap<>(); EasyMock.expect(m_hiveSiteConfig.getProperties()).andReturn(hiveSiteProperties).atLeastOnce(); m_hiveSiteConfig.setProperties(EasyMock.<Map<String, String>>anyObject()); EasyMock.expectLastCall().once(); m_hiveSiteConfig.save(); EasyMock.expectLastCall().once(); EasyMock.expect(m_cluster.getDesiredConfigByType(HiveZKQuorumConfigAction.HIVE_SITE_CONFIG_TYPE)).andReturn(m_hiveSiteConfig).atLeastOnce(); EasyMock.replay(m_executionCommand, m_clusters, m_cluster, m_hiveSiteConfig); m_action.execute(null); EasyMock.verify(m_executionCommand, m_clusters, m_cluster, m_hiveSiteConfig); Assert.assertEquals(zookeeperQuorum, hiveSiteProperties.get(HiveZKQuorumConfigAction.HIVE_SITE_ZK_QUORUM)); Assert.assertEquals(zookeeperQuorum, hiveSiteProperties.get(HiveZKQuorumConfigAction.HIVE_SITE_ZK_CONNECT_STRING)); }
@Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); Config hiveSite = cluster.getDesiredConfigByType(HIVE_SITE_CONFIG_TYPE); if (hiveSite == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format( "The %s configuration type was not found; unable to set Hive configuration properties", HIVE_SITE_CONFIG_TYPE), ""); } String zookeeperQuorum = ZooKeeperQuorumCalculator.getZooKeeperQuorumString(cluster); Map<String, String> hiveSiteProperties = hiveSite.getProperties(); hiveSiteProperties.put(HIVE_SITE_ZK_QUORUM, zookeeperQuorum); hiveSiteProperties.put(HIVE_SITE_ZK_CONNECT_STRING, zookeeperQuorum); hiveSite.setProperties(hiveSiteProperties); hiveSite.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Successfully set %s and %s in %s", HIVE_SITE_ZK_QUORUM, HIVE_SITE_ZK_CONNECT_STRING, HIVE_SITE_CONFIG_TYPE), ""); }
HiveZKQuorumConfigAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); Config hiveSite = cluster.getDesiredConfigByType(HIVE_SITE_CONFIG_TYPE); if (hiveSite == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format( "The %s configuration type was not found; unable to set Hive configuration properties", HIVE_SITE_CONFIG_TYPE), ""); } String zookeeperQuorum = ZooKeeperQuorumCalculator.getZooKeeperQuorumString(cluster); Map<String, String> hiveSiteProperties = hiveSite.getProperties(); hiveSiteProperties.put(HIVE_SITE_ZK_QUORUM, zookeeperQuorum); hiveSiteProperties.put(HIVE_SITE_ZK_CONNECT_STRING, zookeeperQuorum); hiveSite.setProperties(hiveSiteProperties); hiveSite.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Successfully set %s and %s in %s", HIVE_SITE_ZK_QUORUM, HIVE_SITE_ZK_CONNECT_STRING, HIVE_SITE_CONFIG_TYPE), ""); } }
HiveZKQuorumConfigAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); Config hiveSite = cluster.getDesiredConfigByType(HIVE_SITE_CONFIG_TYPE); if (hiveSite == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format( "The %s configuration type was not found; unable to set Hive configuration properties", HIVE_SITE_CONFIG_TYPE), ""); } String zookeeperQuorum = ZooKeeperQuorumCalculator.getZooKeeperQuorumString(cluster); Map<String, String> hiveSiteProperties = hiveSite.getProperties(); hiveSiteProperties.put(HIVE_SITE_ZK_QUORUM, zookeeperQuorum); hiveSiteProperties.put(HIVE_SITE_ZK_CONNECT_STRING, zookeeperQuorum); hiveSite.setProperties(hiveSiteProperties); hiveSite.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Successfully set %s and %s in %s", HIVE_SITE_ZK_QUORUM, HIVE_SITE_ZK_CONNECT_STRING, HIVE_SITE_CONFIG_TYPE), ""); }  }
HiveZKQuorumConfigAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); Config hiveSite = cluster.getDesiredConfigByType(HIVE_SITE_CONFIG_TYPE); if (hiveSite == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format( "The %s configuration type was not found; unable to set Hive configuration properties", HIVE_SITE_CONFIG_TYPE), ""); } String zookeeperQuorum = ZooKeeperQuorumCalculator.getZooKeeperQuorumString(cluster); Map<String, String> hiveSiteProperties = hiveSite.getProperties(); hiveSiteProperties.put(HIVE_SITE_ZK_QUORUM, zookeeperQuorum); hiveSiteProperties.put(HIVE_SITE_ZK_CONNECT_STRING, zookeeperQuorum); hiveSite.setProperties(hiveSiteProperties); hiveSite.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Successfully set %s and %s in %s", HIVE_SITE_ZK_QUORUM, HIVE_SITE_ZK_CONNECT_STRING, HIVE_SITE_CONFIG_TYPE), ""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); }
HiveZKQuorumConfigAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); Config hiveSite = cluster.getDesiredConfigByType(HIVE_SITE_CONFIG_TYPE); if (hiveSite == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format( "The %s configuration type was not found; unable to set Hive configuration properties", HIVE_SITE_CONFIG_TYPE), ""); } String zookeeperQuorum = ZooKeeperQuorumCalculator.getZooKeeperQuorumString(cluster); Map<String, String> hiveSiteProperties = hiveSite.getProperties(); hiveSiteProperties.put(HIVE_SITE_ZK_QUORUM, zookeeperQuorum); hiveSiteProperties.put(HIVE_SITE_ZK_CONNECT_STRING, zookeeperQuorum); hiveSite.setProperties(hiveSiteProperties); hiveSite.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Successfully set %s and %s in %s", HIVE_SITE_ZK_QUORUM, HIVE_SITE_ZK_CONNECT_STRING, HIVE_SITE_CONFIG_TYPE), ""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext);  }