Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
package org.apache.ambari.server.api.services.stackadvisor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest.StackAdvisorRequestType;
Expand All @@ -47,6 +45,7 @@
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Singleton;

/**
Expand All @@ -66,10 +65,10 @@ public static void init(StackAdvisorHelper instance) {
stackAdvisorHelper = instance;
}

private static final SortedMap<String, String> userContext;
private static final Map<String, String> userContext;
static
{
userContext = new TreeMap<>();
userContext = new HashMap<>();
userContext.put("operation", "ClusterCreate");
}

Expand All @@ -92,10 +91,10 @@ public void adviseConfiguration(ClusterTopology clusterTopology, Map<String, Map

private StackAdvisorRequest createStackAdvisorRequest(ClusterTopology clusterTopology, StackAdvisorRequestType requestType) {
Stack stack = clusterTopology.getBlueprint().getStack();
SortedMap<String, SortedSet<String>> hgComponentsMap = gatherHostGroupComponents(clusterTopology);
SortedMap<String, SortedSet<String>> hgHostsMap = gatherHostGroupBindings(clusterTopology);
SortedMap<String, SortedSet<String>> componentHostsMap = gatherComponentsHostsMap(hgComponentsMap,
hgHostsMap);
Map<String, Set<String>> hgComponentsMap = gatherHostGroupComponents(clusterTopology);
Map<String, Set<String>> hgHostsMap = gatherHostGroupBindings(clusterTopology);
Map<String, Set<String>> componentHostsMap = gatherComponentsHostsMap(hgComponentsMap,
hgHostsMap);
return StackAdvisorRequest.StackAdvisorRequestBuilder
.forStack(stack.getName(), stack.getVersion())
.forServices(new ArrayList<>(clusterTopology.getBlueprint().getServices()))
Expand All @@ -109,47 +108,46 @@ private StackAdvisorRequest createStackAdvisorRequest(ClusterTopology clusterTop
.build();
}

private SortedMap<String, SortedSet<String>> gatherHostGroupBindings(ClusterTopology clusterTopology) {
SortedMap<String, SortedSet<String>> hgBindngs = Maps.newTreeMap();
private Map<String, Set<String>> gatherHostGroupBindings(ClusterTopology clusterTopology) {
Map<String, Set<String>> hgBindngs = Maps.newHashMap();
for (Map.Entry<String, HostGroupInfo> hgEnrty: clusterTopology.getHostGroupInfo().entrySet()) {
hgBindngs.put(hgEnrty.getKey(), new TreeSet<>(hgEnrty.getValue().getHostNames()));
hgBindngs.put(hgEnrty.getKey(), Sets.newCopyOnWriteArraySet(hgEnrty.getValue().getHostNames()));
}
return hgBindngs;
}

private SortedMap<String, SortedSet<String>> gatherHostGroupComponents(ClusterTopology clusterTopology) {
SortedMap<String, SortedSet<String>> hgComponentsMap = Maps.newTreeMap();
private Map<String, Set<String>> gatherHostGroupComponents(ClusterTopology clusterTopology) {
Map<String, Set<String>> hgComponentsMap = Maps.newHashMap();
for (Map.Entry<String, HostGroup> hgEnrty: clusterTopology.getBlueprint().getHostGroups().entrySet()) {
hgComponentsMap.put(hgEnrty.getKey(), new TreeSet<>(hgEnrty.getValue().getComponentNames()));
hgComponentsMap.put(hgEnrty.getKey(), Sets.newCopyOnWriteArraySet(hgEnrty.getValue().getComponentNames()));
}
return hgComponentsMap;
}

private SortedMap<String, SortedMap<String, SortedMap<String, String>>> calculateConfigs(ClusterTopology clusterTopology) {
SortedMap<String, SortedMap<String, SortedMap<String, String>>> result = Maps.newTreeMap();
private Map<String, Map<String, Map<String, String>>> calculateConfigs(ClusterTopology clusterTopology) {
Map<String, Map<String, Map<String, String>>> result = Maps.newHashMap();
Map<String, Map<String, String>> fullProperties = clusterTopology.getConfiguration().getFullProperties();
for (Map.Entry<String, Map<String, String>> siteEntry : fullProperties.entrySet()) {
SortedMap<String, SortedMap<String, String>> propsMap = Maps.newTreeMap();
propsMap.put("properties", new TreeMap<>(siteEntry.getValue()));
Map<String, Map<String, String>> propsMap = Maps.newHashMap();
propsMap.put("properties", siteEntry.getValue());
result.put(siteEntry.getKey(), propsMap);
}
return result;
}

private SortedMap<String, SortedSet<String>> gatherComponentsHostsMap(SortedMap<String, SortedSet<String>> hostGroups,
SortedMap<String, SortedSet<String>> bindingHostGroups) {
SortedMap<String, SortedSet<String>> componentHostsMap = new TreeMap<>();
private Map<String, Set<String>> gatherComponentsHostsMap(Map<String, Set<String>> hostGroups, Map<String, Set<String>> bindingHostGroups) {
Map<String, Set<String>> componentHostsMap = new HashMap<>();
if (null != bindingHostGroups && null != hostGroups) {
for (Map.Entry<String, SortedSet<String>> hgComponents : hostGroups.entrySet()) {
for (Map.Entry<String, Set<String>> hgComponents : hostGroups.entrySet()) {
String hgName = hgComponents.getKey();
Set<String> components = hgComponents.getValue();

Set<String> hosts = bindingHostGroups.get(hgName);
if (hosts != null) {
for (String component : components) {
SortedSet<String> componentHosts = componentHostsMap.get(component);
Set<String> componentHosts = componentHostsMap.get(component);
if (componentHosts == null) { // if was not initialized
componentHosts = new TreeSet<>();
componentHosts = new HashSet<>();
componentHostsMap.put(component, componentHosts);
}
componentHosts.addAll(hosts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.Map;
import java.util.Set;

import org.apache.ambari.server.api.services.stackadvisor.recommendations.RecommendationResponse;
import org.apache.ambari.server.state.ChangedConfigInfo;
Expand All @@ -45,14 +45,14 @@ public class StackAdvisorRequest {
private StackAdvisorRequestType requestType;
private List<String> hosts = new ArrayList<>();
private Collection<String> services = new ArrayList<>();
private SortedMap<String, SortedSet<String>> componentHostsMap = new TreeMap<>();
private SortedMap<String, SortedSet<String>> hostComponents = new TreeMap<>();
private SortedMap<String, SortedSet<String>> hostGroupBindings = new TreeMap<>();
private SortedMap<String, SortedMap<String, SortedMap<String, String>>> configurations = new TreeMap<>();
private Map<String, Set<String>> componentHostsMap = new HashMap<>();
private Map<String, Set<String>> hostComponents = new HashMap<>();
private Map<String, Set<String>> hostGroupBindings = new HashMap<>();
private Map<String, Map<String, Map<String, String>>> configurations = new HashMap<>();
private List<ChangedConfigInfo> changedConfigurations = new LinkedList<>();
private SortedSet<RecommendationResponse.ConfigGroup> configGroups;
private SortedMap<String, String> userContext = new TreeMap<>();
private SortedMap<String, Object> ldapConfig = new TreeMap<>();
private Set<RecommendationResponse.ConfigGroup> configGroups;
private Map<String, String> userContext = new HashMap<>();
private Map<String, Object> ldapConfig = new HashMap<>();
private Boolean gplLicenseAccepted;
private Boolean configsResponse = false;

Expand All @@ -76,7 +76,7 @@ public Collection<String> getServices() {
return services;
}

public SortedMap<String, SortedSet<String>> getComponentHostsMap() {
public Map<String, Set<String>> getComponentHostsMap() {
return componentHostsMap;
}

Expand All @@ -88,19 +88,19 @@ public String getServicesCommaSeparated() {
return StringUtils.join(services, ",");
}

public SortedMap<String, SortedSet<String>> getHostComponents() {
public Map<String, Set<String>> getHostComponents() {
return hostComponents;
}

public SortedMap<String, SortedSet<String>> getHostGroupBindings() {
public Map<String, Set<String>> getHostGroupBindings() {
return hostGroupBindings;
}

public SortedMap<String, SortedMap<String, SortedMap<String, String>>> getConfigurations() {
public Map<String, Map<String, Map<String, String>>> getConfigurations() {
return configurations;
}

public SortedMap<String, Object> getLdapConfig() { return ldapConfig; }
public Map<String, Object> getLdapConfig() { return ldapConfig; }

public List<ChangedConfigInfo> getChangedConfigurations() {
return changedConfigurations;
Expand All @@ -110,19 +110,19 @@ public void setChangedConfigurations(List<ChangedConfigInfo> changedConfiguratio
this.changedConfigurations = changedConfigurations;
}

public SortedMap<String, String> getUserContext() {
public Map<String, String> getUserContext() {
return this.userContext;
}

public void setUserContext(SortedMap<String, String> userContext) {
public void setUserContext(Map<String, String> userContext) {
this.userContext = userContext;
}

public SortedSet<RecommendationResponse.ConfigGroup> getConfigGroups() {
public Set<RecommendationResponse.ConfigGroup> getConfigGroups() {
return configGroups;
}

public void setConfigGroups(SortedSet<RecommendationResponse.ConfigGroup> configGroups) {
public void setConfigGroups(Set<RecommendationResponse.ConfigGroup> configGroups) {
this.configGroups = configGroups;
}

Expand Down Expand Up @@ -177,24 +177,24 @@ public StackAdvisorRequestBuilder forServices(Collection<String> services) {
}

public StackAdvisorRequestBuilder withComponentHostsMap(
SortedMap<String, SortedSet<String>> componentHostsMap) {
Map<String, Set<String>> componentHostsMap) {
this.instance.componentHostsMap = componentHostsMap;
return this;
}

public StackAdvisorRequestBuilder forHostComponents(SortedMap<String, SortedSet<String>> hostComponents) {
public StackAdvisorRequestBuilder forHostComponents(Map<String, Set<String>> hostComponents) {
this.instance.hostComponents = hostComponents;
return this;
}

public StackAdvisorRequestBuilder forHostsGroupBindings(
SortedMap<String, SortedSet<String>> hostGroupBindings) {
Map<String, Set<String>> hostGroupBindings) {
this.instance.hostGroupBindings = hostGroupBindings;
return this;
}

public StackAdvisorRequestBuilder withConfigurations(
SortedMap<String, SortedMap<String, SortedMap<String, String>>> configurations) {
Map<String, Map<String, Map<String, String>>> configurations) {
this.instance.configurations = configurations;
return this;
}
Expand All @@ -206,13 +206,13 @@ public StackAdvisorRequestBuilder withChangedConfigurations(
}

public StackAdvisorRequestBuilder withUserContext(
SortedMap<String, String> userContext) {
Map<String, String> userContext) {
this.instance.userContext = userContext;
return this;
}

public StackAdvisorRequestBuilder withConfigGroups(
SortedSet<RecommendationResponse.ConfigGroup> configGroups) {
Set<RecommendationResponse.ConfigGroup> configGroups) {
this.instance.configGroups = configGroups;
return this;
}
Expand All @@ -228,7 +228,7 @@ public StackAdvisorRequestBuilder withGPLLicenseAccepted(
return this;
}

public StackAdvisorRequestBuilder withLdapConfig(SortedMap<String, Object> ldapConfig) {
public StackAdvisorRequestBuilder withLdapConfig(Map<String, Object> ldapConfig) {
Preconditions.checkNotNull(ldapConfig);
this.instance.ldapConfig = ldapConfig;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;

import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorException;
Expand Down Expand Up @@ -78,7 +77,7 @@ protected RecommendationResponse updateResponse(StackAdvisorRequest request,

protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) {
Set<HostGroup> resultSet = new HashSet<>();
for (Map.Entry<String, SortedSet<String>> componentHost : request.getHostComponents().entrySet()) {
for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) {
String hostGroupName = componentHost.getKey();
Set<String> components = componentHost.getValue();
if (hostGroupName != null && components != null) {
Expand All @@ -99,7 +98,7 @@ protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) {

private Set<BindingHostGroup> processHostGroupBindings(StackAdvisorRequest request) {
Set<BindingHostGroup> resultSet = new HashSet<>();
for (Map.Entry<String, SortedSet<String>> hostBinding : request.getHostGroupBindings().entrySet()) {
for (Map.Entry<String, Set<String>> hostBinding : request.getHostGroupBindings().entrySet()) {
String hostGroupName = hostBinding.getKey();
Set<String> hosts = hostBinding.getValue();
if (hostGroupName != null && hosts != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;

import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorException;
Expand Down Expand Up @@ -86,7 +85,7 @@ protected RecommendationResponse updateResponse(StackAdvisorRequest request, Rec

protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) {
Set<HostGroup> resultSet = new HashSet<>();
for (Map.Entry<String, SortedSet<String>> componentHost : request.getHostComponents().entrySet()) {
for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) {
String hostGroupName = componentHost.getKey();
Set<String> components = componentHost.getValue();
if (hostGroupName != null && components != null) {
Expand All @@ -107,7 +106,7 @@ protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) {

private Set<BindingHostGroup> processHostGroupBindings(StackAdvisorRequest request) {
Set<BindingHostGroup> resultSet = new HashSet<>();
for (Map.Entry<String, SortedSet<String>> hostBinding : request.getHostGroupBindings().entrySet()) {
for (Map.Entry<String, Set<String>> hostBinding : request.getHostGroupBindings().entrySet()) {
String hostGroupName = hostBinding.getKey();
Set<String> hosts = hostBinding.getValue();
if (hostGroupName != null && hosts != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -214,13 +212,13 @@ protected void populateAmbariServerInfo(ObjectNode root) {

private void populateConfigurations(ObjectNode root,
StackAdvisorRequest request) {
SortedMap<String, SortedMap<String, SortedMap<String, String>>> configurations =
Map<String, Map<String, Map<String, String>>> configurations =
request.getConfigurations();
ObjectNode configurationsNode = root.putObject(CONFIGURATIONS_PROPERTY);
for (String siteName : configurations.keySet()) {
ObjectNode siteNode = configurationsNode.putObject(siteName);

SortedMap<String, SortedMap<String, String>> siteMap = configurations.get(siteName);
Map<String, Map<String, String>> siteMap = configurations.get(siteName);
for (String properties : siteMap.keySet()) {
ObjectNode propertiesNode = siteNode.putObject(properties);

Expand Down Expand Up @@ -261,7 +259,7 @@ protected void populateStackHierarchy(ObjectNode root) {
}
}

private void populateComponentHostsMap(ObjectNode root, SortedMap<String, SortedSet<String>> componentHostsMap) {
private void populateComponentHostsMap(ObjectNode root, Map<String, Set<String>> componentHostsMap) {
ArrayNode services = (ArrayNode) root.get(SERVICES_PROPERTY);
Iterator<JsonNode> servicesIter = services.getElements();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorResponse;
Expand Down Expand Up @@ -163,6 +164,20 @@ public Map<String, ValueAttributesInfo> getPropertyAttributes() {
public void setPropertyAttributes(Map<String, ValueAttributesInfo> propertyAttributes) {
this.propertyAttributes = propertyAttributes;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlueprintConfigurations that = (BlueprintConfigurations) o;
return Objects.equals(properties, that.properties) &&
Objects.equals(propertyAttributes, that.propertyAttributes);
}

@Override
public int hashCode() {
return Objects.hash(properties, propertyAttributes);
}
}

public static class HostGroup {
Expand Down Expand Up @@ -268,6 +283,21 @@ public Map<String, BlueprintConfigurations> getDependentConfigurations() {
public void setDependentConfigurations(Map<String, BlueprintConfigurations> dependentConfigurations) {
this.dependentConfigurations = dependentConfigurations;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConfigGroup that = (ConfigGroup) o;
return Objects.equals(hosts, that.hosts) &&
Objects.equals(configurations, that.configurations) &&
Objects.equals(dependentConfigurations, that.dependentConfigurations);
}

@Override
public int hashCode() {
return Objects.hash(hosts, configurations, dependentConfigurations);
}
}

}
Loading