@Test public void testIsTopologyResolved_True() throws Exception { DesiredConfig testHdfsDesiredConfig1 = new DesiredConfig(); testHdfsDesiredConfig1.setTag(TopologyManager.INITIAL_CONFIG_TAG); testHdfsDesiredConfig1.setVersion(1L); DesiredConfig testHdfsDesiredConfig2 = new DesiredConfig(); testHdfsDesiredConfig2.setTag(TopologyManager.TOPOLOGY_RESOLVED_TAG); testHdfsDesiredConfig2.setVersion(2L); DesiredConfig testHdfsDesiredConfig3 = new DesiredConfig(); testHdfsDesiredConfig3.setTag("ver123"); testHdfsDesiredConfig3.setVersion(3L); DesiredConfig testCoreSiteDesiredConfig = new DesiredConfig(); testCoreSiteDesiredConfig.setTag("ver123"); testCoreSiteDesiredConfig.setVersion(1L); Map<String, Set<DesiredConfig>> testDesiredConfigs = ImmutableMap.<String, Set<DesiredConfig>>builder() .put("hdfs-site", ImmutableSet.of(testHdfsDesiredConfig2, testHdfsDesiredConfig3, testHdfsDesiredConfig1)) .put("core-site", ImmutableSet.of(testCoreSiteDesiredConfig)) .build(); expect(cluster.getAllDesiredConfigVersions()).andReturn(testDesiredConfigs).atLeastOnce(); replayAll(); boolean topologyResolved = context.isTopologyResolved(CLUSTER_ID); assertTrue(topologyResolved); }
public boolean isTopologyResolved(long clusterId) { boolean isTopologyResolved = false; try { Cluster cluster = getController().getClusters().getClusterById(clusterId); Map<String, Set<DesiredConfig>> allDesiredConfigsByType = cluster.getAllDesiredConfigVersions(); for (String configType: allDesiredConfigsByType.keySet()) { Set<DesiredConfig> desiredConfigVersions = allDesiredConfigsByType.get(configType); SortedSet<DesiredConfig> desiredConfigsOrderedByVersion = new TreeSet<>(new Comparator<DesiredConfig>() { @Override public int compare(DesiredConfig o1, DesiredConfig o2) { if (o1.getVersion() < o2.getVersion()) { return -1; } if (o1.getVersion() > o2.getVersion()) { return 1; } return 0; } }); desiredConfigsOrderedByVersion.addAll(desiredConfigVersions); int tagMatchState = 0; for (DesiredConfig config: desiredConfigsOrderedByVersion) { if (config.getTag().equals(TopologyManager.INITIAL_CONFIG_TAG) && tagMatchState == 0) { tagMatchState = 1; } else if (config.getTag().equals(TopologyManager.TOPOLOGY_RESOLVED_TAG) && tagMatchState == 1) { tagMatchState = 2; break; } } if (tagMatchState == 2) { isTopologyResolved = true; break; } } } catch (ClusterNotFoundException e) { LOG.info("Attempted to determine if configuration is topology resolved for a non-existent cluster: {}", clusterId); } catch (AmbariException e) { throw new RuntimeException( "Unable to determine if cluster config is topology resolved due to unknown error: " + e, e); } return isTopologyResolved; }
AmbariContext { public boolean isTopologyResolved(long clusterId) { boolean isTopologyResolved = false; try { Cluster cluster = getController().getClusters().getClusterById(clusterId); Map<String, Set<DesiredConfig>> allDesiredConfigsByType = cluster.getAllDesiredConfigVersions(); for (String configType: allDesiredConfigsByType.keySet()) { Set<DesiredConfig> desiredConfigVersions = allDesiredConfigsByType.get(configType); SortedSet<DesiredConfig> desiredConfigsOrderedByVersion = new TreeSet<>(new Comparator<DesiredConfig>() { @Override public int compare(DesiredConfig o1, DesiredConfig o2) { if (o1.getVersion() < o2.getVersion()) { return -1; } if (o1.getVersion() > o2.getVersion()) { return 1; } return 0; } }); desiredConfigsOrderedByVersion.addAll(desiredConfigVersions); int tagMatchState = 0; for (DesiredConfig config: desiredConfigsOrderedByVersion) { if (config.getTag().equals(TopologyManager.INITIAL_CONFIG_TAG) && tagMatchState == 0) { tagMatchState = 1; } else if (config.getTag().equals(TopologyManager.TOPOLOGY_RESOLVED_TAG) && tagMatchState == 1) { tagMatchState = 2; break; } } if (tagMatchState == 2) { isTopologyResolved = true; break; } } } catch (ClusterNotFoundException e) { LOG.info("Attempted to determine if configuration is topology resolved for a non-existent cluster: {}", clusterId); } catch (AmbariException e) { throw new RuntimeException( "Unable to determine if cluster config is topology resolved due to unknown error: " + e, e); } return isTopologyResolved; } }
AmbariContext { public boolean isTopologyResolved(long clusterId) { boolean isTopologyResolved = false; try { Cluster cluster = getController().getClusters().getClusterById(clusterId); Map<String, Set<DesiredConfig>> allDesiredConfigsByType = cluster.getAllDesiredConfigVersions(); for (String configType: allDesiredConfigsByType.keySet()) { Set<DesiredConfig> desiredConfigVersions = allDesiredConfigsByType.get(configType); SortedSet<DesiredConfig> desiredConfigsOrderedByVersion = new TreeSet<>(new Comparator<DesiredConfig>() { @Override public int compare(DesiredConfig o1, DesiredConfig o2) { if (o1.getVersion() < o2.getVersion()) { return -1; } if (o1.getVersion() > o2.getVersion()) { return 1; } return 0; } }); desiredConfigsOrderedByVersion.addAll(desiredConfigVersions); int tagMatchState = 0; for (DesiredConfig config: desiredConfigsOrderedByVersion) { if (config.getTag().equals(TopologyManager.INITIAL_CONFIG_TAG) && tagMatchState == 0) { tagMatchState = 1; } else if (config.getTag().equals(TopologyManager.TOPOLOGY_RESOLVED_TAG) && tagMatchState == 1) { tagMatchState = 2; break; } } if (tagMatchState == 2) { isTopologyResolved = true; break; } } } catch (ClusterNotFoundException e) { LOG.info("Attempted to determine if configuration is topology resolved for a non-existent cluster: {}", clusterId); } catch (AmbariException e) { throw new RuntimeException( "Unable to determine if cluster config is topology resolved due to unknown error: " + e, e); } return isTopologyResolved; }  }
AmbariContext { public boolean isTopologyResolved(long clusterId) { boolean isTopologyResolved = false; try { Cluster cluster = getController().getClusters().getClusterById(clusterId); Map<String, Set<DesiredConfig>> allDesiredConfigsByType = cluster.getAllDesiredConfigVersions(); for (String configType: allDesiredConfigsByType.keySet()) { Set<DesiredConfig> desiredConfigVersions = allDesiredConfigsByType.get(configType); SortedSet<DesiredConfig> desiredConfigsOrderedByVersion = new TreeSet<>(new Comparator<DesiredConfig>() { @Override public int compare(DesiredConfig o1, DesiredConfig o2) { if (o1.getVersion() < o2.getVersion()) { return -1; } if (o1.getVersion() > o2.getVersion()) { return 1; } return 0; } }); desiredConfigsOrderedByVersion.addAll(desiredConfigVersions); int tagMatchState = 0; for (DesiredConfig config: desiredConfigsOrderedByVersion) { if (config.getTag().equals(TopologyManager.INITIAL_CONFIG_TAG) && tagMatchState == 0) { tagMatchState = 1; } else if (config.getTag().equals(TopologyManager.TOPOLOGY_RESOLVED_TAG) && tagMatchState == 1) { tagMatchState = 2; break; } } if (tagMatchState == 2) { isTopologyResolved = true; break; } } } catch (ClusterNotFoundException e) { LOG.info("Attempted to determine if configuration is topology resolved for a non-existent cluster: {}", clusterId); } catch (AmbariException e) { throw new RuntimeException( "Unable to determine if cluster config is topology resolved due to unknown error: " + e, e); } return isTopologyResolved; }  boolean isClusterKerberosEnabled(long clusterId); HostRoleCommand createAmbariTask(long requestId, long stageId, String component, String host,
                                          TaskType type, boolean skipFailure); HostRoleCommand createAmbariTask(long taskId, long requestId, long stageId,
                                          String component, String host, TaskType type, boolean skipFailure); HostRoleCommand getPhysicalTask(long id); Collection<HostRoleCommand> getPhysicalTasks(Collection<Long> ids); void createAmbariResources(ClusterTopology topology, String clusterName, SecurityType securityType, String repoVersion); void createAmbariClusterResource(String clusterName, String stackName, String stackVersion, SecurityType securityType, String repoVersion); void createAmbariServiceAndComponentResources(ClusterTopology topology, String clusterName); void createAmbariHostResources(long  clusterId, String hostName, Map<String, Collection<String>> components); Long getNextRequestId(); synchronized static AmbariManagementController getController(); synchronized static ClusterController getClusterController(); static void init(HostRoleCommandFactory factory); void registerHostWithConfigGroup(final String hostName, final ClusterTopology topology, final String groupName); RequestStatusResponse installHost(String hostName, String clusterName, Collection<String> skipInstallForComponents, Collection<String> dontSkipInstallForComponents, boolean skipFailure); RequestStatusResponse startHost(String hostName, String clusterName, Collection<String> installOnlyComponents, boolean skipFailure); void persistInstallStateForUI(String clusterName, String stackName, String stackVersion); List<ConfigurationRequest> createConfigurationRequests(Map<String, Object> clusterProperties); void setConfigurationOnCluster(final ClusterRequest clusterRequest); void waitForConfigurationResolution(String clusterName, Set<String> updatedConfigTypes); boolean isTopologyResolved(long clusterId); PersistedState getPersistedTopologyState(); boolean isHostRegisteredWithCluster(long clusterId, String host); long getClusterId(String clusterName); String getClusterName(long clusterId); }
AmbariContext { public boolean isTopologyResolved(long clusterId) { boolean isTopologyResolved = false; try { Cluster cluster = getController().getClusters().getClusterById(clusterId); Map<String, Set<DesiredConfig>> allDesiredConfigsByType = cluster.getAllDesiredConfigVersions(); for (String configType: allDesiredConfigsByType.keySet()) { Set<DesiredConfig> desiredConfigVersions = allDesiredConfigsByType.get(configType); SortedSet<DesiredConfig> desiredConfigsOrderedByVersion = new TreeSet<>(new Comparator<DesiredConfig>() { @Override public int compare(DesiredConfig o1, DesiredConfig o2) { if (o1.getVersion() < o2.getVersion()) { return -1; } if (o1.getVersion() > o2.getVersion()) { return 1; } return 0; } }); desiredConfigsOrderedByVersion.addAll(desiredConfigVersions); int tagMatchState = 0; for (DesiredConfig config: desiredConfigsOrderedByVersion) { if (config.getTag().equals(TopologyManager.INITIAL_CONFIG_TAG) && tagMatchState == 0) { tagMatchState = 1; } else if (config.getTag().equals(TopologyManager.TOPOLOGY_RESOLVED_TAG) && tagMatchState == 1) { tagMatchState = 2; break; } } if (tagMatchState == 2) { isTopologyResolved = true; break; } } } catch (ClusterNotFoundException e) { LOG.info("Attempted to determine if configuration is topology resolved for a non-existent cluster: {}", clusterId); } catch (AmbariException e) { throw new RuntimeException( "Unable to determine if cluster config is topology resolved due to unknown error: " + e, e); } return isTopologyResolved; }  boolean isClusterKerberosEnabled(long clusterId); HostRoleCommand createAmbariTask(long requestId, long stageId, String component, String host,
                                          TaskType type, boolean skipFailure); HostRoleCommand createAmbariTask(long taskId, long requestId, long stageId,
                                          String component, String host, TaskType type, boolean skipFailure); HostRoleCommand getPhysicalTask(long id); Collection<HostRoleCommand> getPhysicalTasks(Collection<Long> ids); void createAmbariResources(ClusterTopology topology, String clusterName, SecurityType securityType, String repoVersion); void createAmbariClusterResource(String clusterName, String stackName, String stackVersion, SecurityType securityType, String repoVersion); void createAmbariServiceAndComponentResources(ClusterTopology topology, String clusterName); void createAmbariHostResources(long  clusterId, String hostName, Map<String, Collection<String>> components); Long getNextRequestId(); synchronized static AmbariManagementController getController(); synchronized static ClusterController getClusterController(); static void init(HostRoleCommandFactory factory); void registerHostWithConfigGroup(final String hostName, final ClusterTopology topology, final String groupName); RequestStatusResponse installHost(String hostName, String clusterName, Collection<String> skipInstallForComponents, Collection<String> dontSkipInstallForComponents, boolean skipFailure); RequestStatusResponse startHost(String hostName, String clusterName, Collection<String> installOnlyComponents, boolean skipFailure); void persistInstallStateForUI(String clusterName, String stackName, String stackVersion); List<ConfigurationRequest> createConfigurationRequests(Map<String, Object> clusterProperties); void setConfigurationOnCluster(final ClusterRequest clusterRequest); void waitForConfigurationResolution(String clusterName, Set<String> updatedConfigTypes); boolean isTopologyResolved(long clusterId); PersistedState getPersistedTopologyState(); boolean isHostRegisteredWithCluster(long clusterId, String host); long getClusterId(String clusterName); String getClusterName(long clusterId);  }