|
@@ -18,7 +18,6 @@
|
|
|
package org.apache.ambari.server.controller.internal;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -36,15 +35,17 @@ import org.apache.ambari.server.topology.Credential;
|
|
|
import org.apache.ambari.server.topology.HostGroupInfo;
|
|
|
import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
|
|
|
import org.apache.ambari.server.topology.NoSuchBlueprintException;
|
|
|
-import org.apache.ambari.server.topology.RequiredPasswordValidator;
|
|
|
import org.apache.ambari.server.topology.SecurityConfiguration;
|
|
|
import org.apache.ambari.server.topology.TopologyValidator;
|
|
|
+import org.apache.ambari.server.topology.validators.ClusterConfigTypeValidator;
|
|
|
+import org.apache.ambari.server.topology.validators.RequiredPasswordValidator;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import com.google.common.base.Enums;
|
|
|
import com.google.common.base.Optional;
|
|
|
import com.google.common.base.Strings;
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
/**
|
|
|
* Request for provisioning a cluster.
|
|
@@ -118,7 +119,6 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
public static final String QUICKLINKS_PROFILE_SERVICES_PROPERTY = "quicklinks_profile/services";
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* configuration factory
|
|
|
*/
|
|
@@ -145,6 +145,8 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
|
|
|
private final String quickLinksProfileJson;
|
|
|
|
|
|
+ private final List<TopologyValidator> topologyValidators;
|
|
|
+
|
|
|
private final static Logger LOG = LoggerFactory.getLogger(ProvisionClusterRequest.class);
|
|
|
|
|
|
/**
|
|
@@ -177,7 +179,7 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
this.securityConfiguration = securityConfiguration;
|
|
|
|
|
|
Configuration configuration = configurationFactory.getConfiguration(
|
|
|
- (Collection<Map<String, String>>) properties.get(CONFIGURATIONS_PROPERTY));
|
|
|
+ (Collection<Map<String, String>>) properties.get(CONFIGURATIONS_PROPERTY));
|
|
|
configuration.setParentConfiguration(blueprint.getConfiguration());
|
|
|
setConfiguration(configuration);
|
|
|
|
|
@@ -191,10 +193,11 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
|
|
|
try {
|
|
|
this.quickLinksProfileJson = processQuickLinksProfile(properties);
|
|
|
- }
|
|
|
- catch (QuickLinksProfileEvaluationException ex) {
|
|
|
+ } catch (QuickLinksProfileEvaluationException ex) {
|
|
|
throw new InvalidTopologyTemplateException("Invalid quick links profile", ex);
|
|
|
}
|
|
|
+
|
|
|
+ topologyValidators = ImmutableList.of(new RequiredPasswordValidator(defaultPassword), new ClusterConfigTypeValidator());
|
|
|
}
|
|
|
|
|
|
private String processQuickLinksProfile(Map<String, Object> properties) throws QuickLinksProfileEvaluationException {
|
|
@@ -269,7 +272,7 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
|
|
|
@Override
|
|
|
public List<TopologyValidator> getTopologyValidators() {
|
|
|
- return Collections.<TopologyValidator>singletonList(new RequiredPasswordValidator(defaultPassword));
|
|
|
+ return topologyValidators;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -304,7 +307,7 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
*/
|
|
|
private void parseHostGroupInfo(Map<String, Object> properties) throws InvalidTopologyTemplateException {
|
|
|
Collection<Map<String, Object>> hostGroups =
|
|
|
- (Collection<Map<String, Object>>) properties.get(HOSTGROUPS_PROPERTY);
|
|
|
+ (Collection<Map<String, Object>>) properties.get(HOSTGROUPS_PROPERTY);
|
|
|
|
|
|
if (hostGroups == null || hostGroups.isEmpty()) {
|
|
|
throw new InvalidTopologyTemplateException("'host_groups' element must be included in cluster create body");
|
|
@@ -334,11 +337,11 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
|
|
|
processHostCountAndPredicate(hostGroupProperties, hostGroupInfo);
|
|
|
processGroupHosts(name, (Collection<Map<String, String>>)
|
|
|
- hostGroupProperties.get(HOSTGROUP_HOSTS_PROPERTY), hostGroupInfo);
|
|
|
+ hostGroupProperties.get(HOSTGROUP_HOSTS_PROPERTY), hostGroupInfo);
|
|
|
|
|
|
// don't set the parent configuration
|
|
|
hostGroupInfo.setConfiguration(configurationFactory.getConfiguration(
|
|
|
- (Collection<Map<String, String>>) hostGroupProperties.get(CONFIGURATIONS_PROPERTY)));
|
|
|
+ (Collection<Map<String, String>>) hostGroupProperties.get(CONFIGURATIONS_PROPERTY)));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -350,20 +353,20 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
* @throws InvalidTopologyTemplateException specified host group properties fail validation
|
|
|
*/
|
|
|
private void processHostCountAndPredicate(Map<String, Object> hostGroupProperties, HostGroupInfo hostGroupInfo)
|
|
|
- throws InvalidTopologyTemplateException {
|
|
|
+ throws InvalidTopologyTemplateException {
|
|
|
|
|
|
if (hostGroupProperties.containsKey(HOSTGROUP_HOST_COUNT_PROPERTY)) {
|
|
|
hostGroupInfo.setRequestedCount(Integer.valueOf(String.valueOf(
|
|
|
- hostGroupProperties.get(HOSTGROUP_HOST_COUNT_PROPERTY))));
|
|
|
+ hostGroupProperties.get(HOSTGROUP_HOST_COUNT_PROPERTY))));
|
|
|
LOG.info("Stored expected hosts count {} for group {}",
|
|
|
- hostGroupInfo.getRequestedHostCount(), hostGroupInfo.getHostGroupName());
|
|
|
+ hostGroupInfo.getRequestedHostCount(), hostGroupInfo.getHostGroupName());
|
|
|
}
|
|
|
|
|
|
if (hostGroupProperties.containsKey(HOSTGROUP_HOST_PREDICATE_PROPERTY)) {
|
|
|
if (hostGroupInfo.getRequestedHostCount() == 0) {
|
|
|
throw new InvalidTopologyTemplateException(String.format(
|
|
|
- "Host group '%s' must not specify 'host_predicate' without 'host_count'",
|
|
|
- hostGroupInfo.getHostGroupName()));
|
|
|
+ "Host group '%s' must not specify 'host_predicate' without 'host_count'",
|
|
|
+ hostGroupInfo.getHostGroupName()));
|
|
|
}
|
|
|
|
|
|
String hostPredicate = String.valueOf(hostGroupProperties.get(HOSTGROUP_HOST_PREDICATE_PROPERTY));
|
|
@@ -373,7 +376,7 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
LOG.info("Compiled host predicate {} for group {}", hostPredicate, hostGroupInfo.getHostGroupName());
|
|
|
} catch (InvalidQueryException e) {
|
|
|
throw new InvalidTopologyTemplateException(
|
|
|
- String.format("Unable to compile host predicate '%s': %s", hostPredicate, e), e);
|
|
|
+ String.format("Unable to compile host predicate '%s': %s", hostPredicate, e), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -388,17 +391,17 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
* @throws InvalidTopologyTemplateException specified host group properties fail validation
|
|
|
*/
|
|
|
private void processGroupHosts(String name, Collection<Map<String, String>> hosts, HostGroupInfo hostGroupInfo)
|
|
|
- throws InvalidTopologyTemplateException {
|
|
|
+ throws InvalidTopologyTemplateException {
|
|
|
|
|
|
if (hosts != null) {
|
|
|
if (hostGroupInfo.getRequestedHostCount() != 0) {
|
|
|
throw new InvalidTopologyTemplateException(String.format(
|
|
|
- "Host group '%s' must not contain both a 'hosts' element and a 'host_count' value", name));
|
|
|
+ "Host group '%s' must not contain both a 'hosts' element and a 'host_count' value", name));
|
|
|
}
|
|
|
|
|
|
if (hostGroupInfo.getPredicate() != null) {
|
|
|
throw new InvalidTopologyTemplateException(String.format(
|
|
|
- "Host group '%s' must not contain both a 'hosts' element and a 'host_predicate' value", name));
|
|
|
+ "Host group '%s' must not contain both a 'hosts' element and a 'host_predicate' value", name));
|
|
|
}
|
|
|
|
|
|
for (Map<String, String> hostProperties : hosts) {
|
|
@@ -408,15 +411,15 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
|
|
|
|
|
|
if (hostProperties.containsKey(HOSTGROUP_HOST_RACK_INFO_PROPERTY)) {
|
|
|
hostGroupInfo.addHostRackInfo(
|
|
|
- hostProperties.get(HOSTGROUP_HOST_FQDN_PROPERTY),
|
|
|
- hostProperties.get(HOSTGROUP_HOST_RACK_INFO_PROPERTY));
|
|
|
+ hostProperties.get(HOSTGROUP_HOST_FQDN_PROPERTY),
|
|
|
+ hostProperties.get(HOSTGROUP_HOST_RACK_INFO_PROPERTY));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (hostGroupInfo.getRequestedHostCount() == 0) {
|
|
|
throw new InvalidTopologyTemplateException(String.format(
|
|
|
- "Host group '%s' must contain at least one 'hosts/fqdn' or a 'host_count' value", name));
|
|
|
+ "Host group '%s' must contain at least one 'hosts/fqdn' or a 'host_count' value", name));
|
|
|
}
|
|
|
}
|
|
|
|