You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2017/10/06 16:22:27 UTC
ambari git commit: AMBARI-14714. add new v2 interfaces for blueprint
Repository: ambari
Updated Branches:
refs/heads/branch-feature-AMBARI-14714 9306544e5 -> 9c8ed58d1
AMBARI-14714. add new v2 interfaces for blueprint
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9c8ed58d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9c8ed58d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9c8ed58d
Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 9c8ed58d11a904392bebb89b42049eed10932a17
Parents: 9306544
Author: Sandor Magyari <sm...@hortonworks.com>
Authored: Fri Oct 6 18:20:28 2017 +0200
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Fri Oct 6 18:21:47 2017 +0200
----------------------------------------------------------------------
.../ambari/server/controller/StackV2.java | 816 +++++++++++++++++++
.../ambari/server/topology/BlueprintImplV2.java | 134 +++
.../ambari/server/topology/BlueprintV2.java | 179 ++++
.../ambari/server/topology/ComponentV2.java | 72 ++
.../ambari/server/topology/HostGroupV2.java | 124 +++
5 files changed, 1325 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9c8ed58d/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
new file mode 100644
index 0000000..3e34951
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
@@ -0,0 +1,816 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.state.*;
+import org.apache.ambari.server.topology.Cardinality;
+import org.apache.ambari.server.topology.Configuration;
+
+import java.util.*;
+
+/**
+ * Encapsulates stack information.
+ */
+public class StackV2 {
+ /**
+ * Stack name
+ */
+ private String name;
+
+ /**
+ * Stack version
+ */
+ private String version;
+
+ /**
+ * Repo version
+ */
+ private String repoVersion;
+
+ /**
+ * Map of service name to components
+ */
+ private Map<String, Collection<String>> serviceComponents =
+ new HashMap<>();
+
+ /**
+ * Map of component to service
+ */
+ private Map<String, String> componentService = new HashMap<>();
+
+ /**
+ * Map of component to dependencies
+ */
+ private Map<String, Collection<DependencyInfo>> dependencies =
+ new HashMap<>();
+
+ /**
+ * Map of dependency to conditional service
+ */
+ private Map<DependencyInfo, String> dependencyConditionalServiceMap =
+ new HashMap<>();
+
+ /**
+ * Map of database component name to configuration property which indicates whether
+ * the database in to be managed or if it is an external non-managed instance.
+ * If the value of the config property starts with 'New', the database is determined
+ * to be managed, otherwise it is non-managed.
+ */
+ private Map<String, String> dbDependencyInfo = new HashMap<>();
+
+ /**
+ * Map of component to required cardinality
+ */
+ private Map<String, String> cardinalityRequirements = new HashMap<>();
+
+ //todo: instead of all these maps from component -> * ,
+ //todo: we should use a Component object with all of these attributes
+ private Set<String> masterComponents = new HashSet<>();
+
+ /**
+ * Map of component to auto-deploy information
+ */
+ private Map<String, AutoDeployInfo> componentAutoDeployInfo =
+ new HashMap<>();
+
+ /**
+ * Map of service to config type properties
+ */
+ private Map<String, Map<String, Map<String, ConfigProperty>>> serviceConfigurations =
+ new HashMap<>();
+
+ /**
+ * Map of service to required type properties
+ */
+ private Map<String, Map<String, Map<String, ConfigProperty>>> requiredServiceConfigurations =
+ new HashMap<>();
+
+ /**
+ * Map of service to config type properties
+ */
+ private Map<String, Map<String, ConfigProperty>> stackConfigurations =
+ new HashMap<>();
+
+ /**
+ * Map of service to set of excluded config types
+ */
+ private Map<String, Set<String>> excludedConfigurationTypes =
+ new HashMap<>();
+
+ /**
+ * Ambari Management Controller, used to obtain Stack definitions
+ */
+ private final AmbariManagementController controller;
+
+
+ /**
+ * Constructor.
+ *
+ * @param stack
+ * the stack (not {@code null}).
+ * @param ambariManagementController
+ * the management controller (not {@code null}).
+ * @throws AmbariException
+ */
+ public StackV2(StackEntity stack, AmbariManagementController ambariManagementController) throws AmbariException {
+ this(stack.getStackName(), stack.getStackVersion(), ambariManagementController);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name stack name
+ * @param version stack version
+ *
+ * @throws AmbariException an exception occurred getting stack information
+ * for the specified name and version
+ */
+ //todo: don't pass management controller in constructor
+ public StackV2(String name, String version, AmbariManagementController controller) throws AmbariException {
+ this.name = name;
+ this.version = version;
+ this.controller = controller;
+
+ Set<StackServiceResponse> stackServices = controller.getStackServices(
+ Collections.singleton(new StackServiceRequest(name, version, null)));
+
+ for (StackServiceResponse stackService : stackServices) {
+ String serviceName = stackService.getServiceName();
+ parseComponents(serviceName);
+ parseExcludedConfigurations(stackService);
+ parseConfigurations(stackService);
+ registerConditionalDependencies();
+ }
+
+ //todo: already done for each service
+ parseStackConfigurations();
+ }
+
+ /**
+ * Obtain stack name.
+ *
+ * @return stack name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Obtain stack version.
+ *
+ * @return stack version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Obtain repo version.
+ * @return
+ */
+ public String getRepoVersion() { return repoVersion; }
+
+ Map<DependencyInfo, String> getDependencyConditionalServiceMap() {
+ return dependencyConditionalServiceMap;
+ }
+
+ /**
+ * Get services contained in the stack.
+ *
+ * @return collection of all services for the stack
+ */
+ public Collection<String> getServices() {
+ return serviceComponents.keySet();
+ }
+
+ /**
+ * Get components contained in the stack for the specified service.
+ *
+ * @param service service name
+ *
+ * @return collection of component names for the specified service
+ */
+ public Collection<String> getComponents(String service) {
+ return serviceComponents.get(service);
+ }
+
+ /**
+ * Get all service components
+ *
+ * @return map of service to associated components
+ */
+ public Map<String, Collection<String>> getComponents() {
+ Map<String, Collection<String>> serviceComponents = new HashMap<>();
+ for (String service : getServices()) {
+ Collection<String> components = new HashSet<>();
+ components.addAll(getComponents(service));
+ serviceComponents.put(service, components);
+ }
+ return serviceComponents;
+ }
+
+ /**
+ * Get info for the specified component.
+ *
+ * @param component component name
+ *
+ * @return component information for the requested component
+ * or null if the component doesn't exist in the stack
+ */
+ public ComponentInfo getComponentInfo(String component) {
+ ComponentInfo componentInfo = null;
+ String service = getServiceForComponent(component);
+ if (service != null) {
+ try {
+ componentInfo = controller.getAmbariMetaInfo().getComponent(
+ getName(), getVersion(), service, component);
+ } catch (AmbariException e) {
+ // just return null if component doesn't exist
+ }
+ }
+ return componentInfo;
+ }
+
+ /**
+ * Get all configuration types, including excluded types for the specified service.
+ *
+ * @param service service name
+ *
+ * @return collection of all configuration types for the specified service
+ */
+ public Collection<String> getAllConfigurationTypes(String service) {
+ return serviceConfigurations.get(service).keySet();
+ }
+
+ /**
+ * Get configuration types for the specified service.
+ * This doesn't include any service excluded types.
+ *
+ * @param service service name
+ *
+ * @return collection of all configuration types for the specified service
+ */
+ public Collection<String> getConfigurationTypes(String service) {
+ Set<String> serviceTypes = new HashSet<>(serviceConfigurations.get(service).keySet());
+ serviceTypes.removeAll(getExcludedConfigurationTypes(service));
+
+ return serviceTypes;
+ }
+
+ /**
+ * Get the set of excluded configuration types for this service.
+ *
+ * @param service service name
+ *
+ * @return Set of names of excluded config types. Will not return null.
+ */
+ public Set<String> getExcludedConfigurationTypes(String service) {
+ return excludedConfigurationTypes.containsKey(service) ?
+ excludedConfigurationTypes.get(service) :
+ Collections.emptySet();
+ }
+
+ /**
+ * Get config properties for the specified service and configuration type.
+ *
+ * @param service service name
+ * @param type configuration type
+ *
+ * @return map of property names to values for the specified service and configuration type
+ */
+ public Map<String, String> getConfigurationProperties(String service, String type) {
+ Map<String, String> configMap = new HashMap<>();
+ Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
+ if (configProperties != null) {
+ for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+ configMap.put(configProperty.getKey(), configProperty.getValue().getValue());
+ }
+ }
+ return configMap;
+ }
+
+ public Map<String, ConfigProperty> getConfigurationPropertiesWithMetadata(String service, String type) {
+ return serviceConfigurations.get(service).get(type);
+ }
+
+ /**
+ * Get all required config properties for the specified service.
+ *
+ * @param service service name
+ *
+ * @return collection of all required properties for the given service
+ */
+ public Collection<ConfigProperty> getRequiredConfigurationProperties(String service) {
+ Collection<ConfigProperty> requiredConfigProperties = new HashSet<>();
+ Map<String, Map<String, ConfigProperty>> serviceProperties = requiredServiceConfigurations.get(service);
+ if (serviceProperties != null) {
+ for (Map.Entry<String, Map<String, ConfigProperty>> typePropertiesEntry : serviceProperties.entrySet()) {
+ requiredConfigProperties.addAll(typePropertiesEntry.getValue().values());
+ }
+ }
+ return requiredConfigProperties;
+ }
+
+ /**
+ * Get required config properties for the specified service which belong to the specified property type.
+ *
+ * @param service service name
+ * @param propertyType property type
+ *
+ * @return collection of required properties for the given service and property type
+ */
+ public Collection<ConfigProperty> getRequiredConfigurationProperties(String service, PropertyInfo.PropertyType propertyType) {
+ Collection<ConfigProperty> matchingProperties = new HashSet<>();
+ Map<String, Map<String, ConfigProperty>> requiredProperties = requiredServiceConfigurations.get(service);
+ if (requiredProperties != null) {
+ for (Map.Entry<String, Map<String, ConfigProperty>> typePropertiesEntry : requiredProperties.entrySet()) {
+ for (ConfigProperty configProperty : typePropertiesEntry.getValue().values()) {
+ if (configProperty.getPropertyTypes().contains(propertyType)) {
+ matchingProperties.add(configProperty);
+ }
+ }
+
+ }
+ }
+ return matchingProperties;
+ }
+
+ public boolean isPasswordProperty(String service, String type, String propertyName) {
+ return (serviceConfigurations.containsKey(service) &&
+ serviceConfigurations.get(service).containsKey(type) &&
+ serviceConfigurations.get(service).get(type).containsKey(propertyName) &&
+ serviceConfigurations.get(service).get(type).get(propertyName).getPropertyTypes().
+ contains(PropertyInfo.PropertyType.PASSWORD));
+ }
+
+ //todo
+ public Map<String, String> getStackConfigurationProperties(String type) {
+ Map<String, String> configMap = new HashMap<>();
+ Map<String, ConfigProperty> configProperties = stackConfigurations.get(type);
+ if (configProperties != null) {
+ for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+ configMap.put(configProperty.getKey(), configProperty.getValue().getValue());
+ }
+ }
+ return configMap;
+ }
+
+ public boolean isKerberosPrincipalNameProperty(String service, String type, String propertyName) {
+ return (serviceConfigurations.containsKey(service) &&
+ serviceConfigurations.get(service).containsKey(type) &&
+ serviceConfigurations.get(service).get(type).containsKey(propertyName) &&
+ serviceConfigurations.get(service).get(type).get(propertyName).getPropertyTypes().
+ contains(PropertyInfo.PropertyType.KERBEROS_PRINCIPAL));
+ }
+ /**
+ * Get config attributes for the specified service and configuration type.
+ *
+ * @param service service name
+ * @param type configuration type
+ *
+ * @return map of attribute names to map of property names to attribute values
+ * for the specified service and configuration type
+ */
+ public Map<String, Map<String, String>> getConfigurationAttributes(String service, String type) {
+ Map<String, Map<String, String>> attributesMap = new HashMap<>();
+ Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
+ if (configProperties != null) {
+ for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+ String propertyName = configProperty.getKey();
+ Map<String, String> propertyAttributes = configProperty.getValue().getAttributes();
+ if (propertyAttributes != null) {
+ for (Map.Entry<String, String> propertyAttribute : propertyAttributes.entrySet()) {
+ String attributeName = propertyAttribute.getKey();
+ String attributeValue = propertyAttribute.getValue();
+ if (attributeValue != null) {
+ Map<String, String> attributes = attributesMap.get(attributeName);
+ if (attributes == null) {
+ attributes = new HashMap<>();
+ attributesMap.put(attributeName, attributes);
+ }
+ attributes.put(propertyName, attributeValue);
+ }
+ }
+ }
+ }
+ }
+ return attributesMap;
+ }
+
+ //todo:
+ public Map<String, Map<String, String>> getStackConfigurationAttributes(String type) {
+ Map<String, Map<String, String>> attributesMap = new HashMap<>();
+ Map<String, ConfigProperty> configProperties = stackConfigurations.get(type);
+ if (configProperties != null) {
+ for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+ String propertyName = configProperty.getKey();
+ Map<String, String> propertyAttributes = configProperty.getValue().getAttributes();
+ if (propertyAttributes != null) {
+ for (Map.Entry<String, String> propertyAttribute : propertyAttributes.entrySet()) {
+ String attributeName = propertyAttribute.getKey();
+ String attributeValue = propertyAttribute.getValue();
+ Map<String, String> attributes = attributesMap.get(attributeName);
+ if (attributes == null) {
+ attributes = new HashMap<>();
+ attributesMap.put(attributeName, attributes);
+ }
+ attributes.put(propertyName, attributeValue);
+ }
+ }
+ }
+ }
+ return attributesMap;
+ }
+
+ /**
+ * Get the service for the specified component.
+ *
+ * @param component component name
+ *
+ * @return service name that contains tha specified component
+ */
+ public String getServiceForComponent(String component) {
+ return componentService.get(component);
+ }
+
+ /**
+ * Get the names of the services which contains the specified components.
+ *
+ * @param components collection of components
+ *
+ * @return collection of services which contain the specified components
+ */
+ public Collection<String> getServicesForComponents(Collection<String> components) {
+ Set<String> services = new HashSet<>();
+ for (String component : components) {
+ services.add(getServiceForComponent(component));
+ }
+
+ return services;
+ }
+
+ /**
+ * Obtain the service name which corresponds to the specified configuration.
+ *
+ * @param config configuration type
+ *
+ * @return name of service which corresponds to the specified configuration type
+ */
+ public String getServiceForConfigType(String config) {
+ for (Map.Entry<String, Map<String, Map<String, ConfigProperty>>> entry : serviceConfigurations.entrySet()) {
+ Map<String, Map<String, ConfigProperty>> typeMap = entry.getValue();
+ String serviceName = entry.getKey();
+ if (typeMap.containsKey(config) && !getExcludedConfigurationTypes(serviceName).contains(config)) {
+ return serviceName;
+ }
+ }
+ throw new IllegalArgumentException(
+ "Specified configuration type is not associated with any service: " + config);
+ }
+
+ /**
+ * Return the dependencies specified for the given component.
+ *
+ * @param component component to get dependency information for
+ *
+ * @return collection of dependency information for the specified component
+ */
+ //todo: full dependency graph
+ public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+ return dependencies.containsKey(component) ? dependencies.get(component) :
+ Collections.emptySet();
+ }
+
+ /**
+ * Get the service, if any, that a component dependency is conditional on.
+ *
+ * @param dependency dependency to get conditional service for
+ *
+ * @return conditional service for provided component or null if dependency
+ * is not conditional on a service
+ */
+ public String getConditionalServiceForDependency(DependencyInfo dependency) {
+ return dependencyConditionalServiceMap.get(dependency);
+ }
+
+ public String getExternalComponentConfig(String component) {
+ return dbDependencyInfo.get(component);
+ }
+
+ /**
+ * Obtain the required cardinality for the specified component.
+ */
+ public Cardinality getCardinality(String component) {
+ return new Cardinality(cardinalityRequirements.get(component));
+ }
+
+ /**
+ * Obtain auto-deploy information for the specified component.
+ */
+ public AutoDeployInfo getAutoDeployInfo(String component) {
+ return componentAutoDeployInfo.get(component);
+ }
+
+ public boolean isMasterComponent(String component) {
+ return masterComponents.contains(component);
+ }
+
+ public Configuration getConfiguration(Collection<String> services) {
+ Map<String, Map<String, Map<String, String>>> attributes = new HashMap<>();
+ Map<String, Map<String, String>> properties = new HashMap<>();
+
+ for (String service : services) {
+ Collection<String> serviceConfigTypes = getConfigurationTypes(service);
+ for (String type : serviceConfigTypes) {
+ Map<String, String> typeProps = properties.get(type);
+ if (typeProps == null) {
+ typeProps = new HashMap<>();
+ properties.put(type, typeProps);
+ }
+ typeProps.putAll(getConfigurationProperties(service, type));
+
+ Map<String, Map<String, String>> stackTypeAttributes = getConfigurationAttributes(service, type);
+ if (!stackTypeAttributes.isEmpty()) {
+ if (! attributes.containsKey(type)) {
+ attributes.put(type, new HashMap<>());
+ }
+ Map<String, Map<String, String>> typeAttributes = attributes.get(type);
+ for (Map.Entry<String, Map<String, String>> attribute : stackTypeAttributes.entrySet()) {
+ String attributeName = attribute.getKey();
+ Map<String, String> attributeProps = typeAttributes.get(attributeName);
+ if (attributeProps == null) {
+ attributeProps = new HashMap<>();
+ typeAttributes.put(attributeName, attributeProps);
+ }
+ attributeProps.putAll(attribute.getValue());
+ }
+ }
+ }
+ }
+ return new Configuration(properties, attributes);
+ }
+
+ public Configuration getConfiguration() {
+ Map<String, Map<String, Map<String, String>>> stackAttributes = new HashMap<>();
+ Map<String, Map<String, String>> stackConfigs = new HashMap<>();
+
+ for (String service : getServices()) {
+ for (String type : getAllConfigurationTypes(service)) {
+ Map<String, String> typeProps = stackConfigs.get(type);
+ if (typeProps == null) {
+ typeProps = new HashMap<>();
+ stackConfigs.put(type, typeProps);
+ }
+ typeProps.putAll(getConfigurationProperties(service, type));
+
+ Map<String, Map<String, String>> stackTypeAttributes = getConfigurationAttributes(service, type);
+ if (!stackTypeAttributes.isEmpty()) {
+ if (! stackAttributes.containsKey(type)) {
+ stackAttributes.put(type, new HashMap<>());
+ }
+ Map<String, Map<String, String>> typeAttrs = stackAttributes.get(type);
+ for (Map.Entry<String, Map<String, String>> attribute : stackTypeAttributes.entrySet()) {
+ String attributeName = attribute.getKey();
+ Map<String, String> attributes = typeAttrs.get(attributeName);
+ if (attributes == null) {
+ attributes = new HashMap<>();
+ typeAttrs.put(attributeName, attributes);
+ }
+ attributes.putAll(attribute.getValue());
+ }
+ }
+ }
+ }
+ return new Configuration(stackConfigs, stackAttributes);
+ }
+
+ /**
+ * Parse components for the specified service from the stack definition.
+ *
+ * @param service service name
+ *
+ * @throws AmbariException an exception occurred getting components from the stack definition
+ */
+ private void parseComponents(String service) throws AmbariException{
+ Collection<String> componentSet = new HashSet<>();
+
+ Set<StackServiceComponentResponse> components = controller.getStackComponents(
+ Collections.singleton(new StackServiceComponentRequest(name, version, service, null)));
+
+ // stack service components
+ for (StackServiceComponentResponse component : components) {
+ String componentName = component.getComponentName();
+ componentSet.add(componentName);
+ componentService.put(componentName, service);
+ String cardinality = component.getCardinality();
+ if (cardinality != null) {
+ cardinalityRequirements.put(componentName, cardinality);
+ }
+ AutoDeployInfo autoDeploy = component.getAutoDeploy();
+ if (autoDeploy != null) {
+ componentAutoDeployInfo.put(componentName, autoDeploy);
+ }
+
+ // populate component dependencies
+ //todo: remove usage of AmbariMetaInfo
+ Collection<DependencyInfo> componentDependencies = controller.getAmbariMetaInfo().getComponentDependencies(
+ name, version, service, componentName);
+
+ if (componentDependencies != null && ! componentDependencies.isEmpty()) {
+ dependencies.put(componentName, componentDependencies);
+ }
+ if (component.isMaster()) {
+ masterComponents.add(componentName);
+ }
+ }
+ serviceComponents.put(service, componentSet);
+ }
+
+ /**
+ * Parse configurations for the specified service from the stack definition.
+ *
+ * @param stackService service to parse the stack configuration for
+ *
+ * @throws AmbariException an exception occurred getting configurations from the stack definition
+ */
+ private void parseConfigurations(StackServiceResponse stackService) throws AmbariException {
+ String service = stackService.getServiceName();
+ Map<String, Map<String, ConfigProperty>> mapServiceConfig = new HashMap<>();
+ Map<String, Map<String, ConfigProperty>> mapRequiredServiceConfig = new HashMap<>();
+
+
+ serviceConfigurations.put(service, mapServiceConfig);
+ requiredServiceConfigurations.put(service, mapRequiredServiceConfig);
+
+ Set<StackConfigurationResponse> serviceConfigs = controller.getStackConfigurations(
+ Collections.singleton(new StackConfigurationRequest(name, version, service, null)));
+ Set<StackConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
+ Collections.singleton(new StackLevelConfigurationRequest(name, version, null)));
+ serviceConfigs.addAll(stackLevelConfigs);
+
+ // shouldn't have any required properties in stack level configuration
+ for (StackConfigurationResponse config : serviceConfigs) {
+ ConfigProperty configProperty = new ConfigProperty(config);
+ String type = configProperty.getType();
+
+ Map<String, ConfigProperty> mapTypeConfig = mapServiceConfig.get(type);
+ if (mapTypeConfig == null) {
+ mapTypeConfig = new HashMap<>();
+ mapServiceConfig.put(type, mapTypeConfig);
+ }
+
+ mapTypeConfig.put(config.getPropertyName(), configProperty);
+ if (config.isRequired()) {
+ Map<String, ConfigProperty> requiredTypeConfig = mapRequiredServiceConfig.get(type);
+ if (requiredTypeConfig == null) {
+ requiredTypeConfig = new HashMap<>();
+ mapRequiredServiceConfig.put(type, requiredTypeConfig);
+ }
+ requiredTypeConfig.put(config.getPropertyName(), configProperty);
+ }
+ }
+
+ // So far we added only config types that have properties defined
+ // in stack service definition. Since there might be config types
+ // with no properties defined we need to add those separately
+ Set<String> configTypes = stackService.getConfigTypes().keySet();
+ for (String configType: configTypes) {
+ if (!mapServiceConfig.containsKey(configType)) {
+ mapServiceConfig.put(configType, Collections.emptyMap());
+ }
+ }
+ }
+
+ private void parseStackConfigurations () throws AmbariException {
+
+ Set<StackConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
+ Collections.singleton(new StackLevelConfigurationRequest(name, version, null)));
+
+ for (StackConfigurationResponse config : stackLevelConfigs) {
+ ConfigProperty configProperty = new ConfigProperty(config);
+ String type = configProperty.getType();
+
+ Map<String, ConfigProperty> mapTypeConfig = stackConfigurations.get(type);
+ if (mapTypeConfig == null) {
+ mapTypeConfig = new HashMap<>();
+ stackConfigurations.put(type, mapTypeConfig);
+ }
+
+ mapTypeConfig.put(config.getPropertyName(),
+ configProperty);
+ }
+ }
+
+ /**
+ * Obtain the excluded configuration types from the StackServiceResponse
+ *
+ * @param stackServiceResponse the response object associated with this stack service
+ */
+ private void parseExcludedConfigurations(StackServiceResponse stackServiceResponse) {
+ excludedConfigurationTypes.put(stackServiceResponse.getServiceName(), stackServiceResponse.getExcludedConfigTypes());
+ }
+
+ /**
+ * Register conditional dependencies.
+ */
+ //todo: This information should be specified in the stack definition.
+ void registerConditionalDependencies() {
+ dbDependencyInfo.put("MYSQL_SERVER", "global/hive_database");
+ }
+
+ /**
+ * Contains a configuration property's value and attributes.
+ */
+ public static class ConfigProperty {
+ private ValueAttributesInfo propertyValueAttributes = null;
+ private String name;
+ private String value;
+ private Map<String, String> attributes;
+ private Set<PropertyInfo.PropertyType> propertyTypes;
+ private String type;
+ private Set<PropertyDependencyInfo> dependsOnProperties =
+ Collections.emptySet();
+
+ public ConfigProperty(StackConfigurationResponse config) {
+ this.name = config.getPropertyName();
+ this.value = config.getPropertyValue();
+ this.attributes = config.getPropertyAttributes();
+ this.propertyTypes = config.getPropertyType();
+ this.type = normalizeType(config.getType());
+ this.dependsOnProperties = config.getDependsOnProperties();
+ this.propertyValueAttributes = config.getPropertyValueAttributes();
+ }
+
+ public ConfigProperty(String type, String name, String value) {
+ this.type = type;
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public Set<PropertyInfo.PropertyType> getPropertyTypes() {
+ return propertyTypes;
+ }
+
+ public void setPropertyTypes(Set<PropertyInfo.PropertyType> propertyTypes) {
+ this.propertyTypes = propertyTypes;
+ }
+
+ public Map<String, String> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(Map<String, String> attributes) {
+ this.attributes = attributes;
+ }
+
+ Set<PropertyDependencyInfo> getDependsOnProperties() {
+ return this.dependsOnProperties;
+ }
+
+ private String normalizeType(String type) {
+ //strip .xml from type
+ if (type.endsWith(".xml")) {
+ type = type.substring(0, type.length() - 4);
+ }
+ return type;
+ }
+
+ public ValueAttributesInfo getPropertyValueAttributes() {
+ return propertyValueAttributes;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9c8ed58d/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
new file mode 100644
index 0000000..fa893b3b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distribut
+ * ed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+import org.apache.ambari.server.controller.StackV2;
+import org.apache.ambari.server.orm.entities.BlueprintEntity;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Blueprint implementation.
+ */
+public class BlueprintImplV2 implements BlueprintV2 {
+
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public HostGroupV2 getHostGroup(String name) {
+ return null;
+ }
+
+ @Override
+ public Map<String, HostGroupV2> getHostGroups() {
+ return null;
+ }
+
+ @Override
+ public Collection<StackV2> getStacks() {
+ return null;
+ }
+
+ @Override
+ public Collection<ServiceGroup> getServiceGroups() {
+ return null;
+ }
+
+ @Override
+ public Collection<Service> getAllServices() {
+ return null;
+ }
+
+ @Override
+ public Collection<ComponentV2> getComponents(Service service) {
+ return null;
+ }
+
+ @Override
+ public Collection<HostGroupV2> getHostGroupsForService(Service service) {
+ return null;
+ }
+
+ @Override
+ public Collection<HostGroupV2> getHostGroupsForComponent(ComponentV2 component) {
+ return null;
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ return null;
+ }
+
+ @Override
+ public Setting getSetting() {
+ return null;
+ }
+
+ @Override
+ public String getRecoveryEnabled(String serviceName, String componentName) {
+ return null;
+ }
+
+ @Override
+ public String getCredentialStoreEnabled(String serviceName) {
+ return null;
+ }
+
+ @Override
+ public boolean shouldSkipFailure() {
+ return false;
+ }
+
+ @Override
+ public SecurityConfiguration getSecurity() {
+ return null;
+ }
+
+ @Override
+ public void validateTopology() throws InvalidTopologyException {
+
+ }
+
+ @Override
+ public void validateRequiredProperties() throws InvalidTopologyException {
+
+ }
+
+ @Override
+ public boolean isValidConfigType(String configType) {
+ return false;
+ }
+
+ @Override
+ public BlueprintEntity toEntity() {
+ return null;
+ }
+
+ @Override
+ public List<RepositorySetting> getRepositorySettings() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9c8ed58d/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
new file mode 100644
index 0000000..134a614
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+import org.apache.ambari.server.controller.StackV2;
+import org.apache.ambari.server.orm.entities.BlueprintEntity;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Blueprint representation.
+ */
+public interface BlueprintV2 {
+
+ /**
+ * Get the name of the blueprint.
+ *
+ * @return blueprint name
+ */
+ String getName();
+
+ /**
+ * Get a hostgroup specified by name.
+ *
+ * @param name name of the host group to get
+ *
+ * @return the host group with the given name or null
+ */
+ HostGroupV2 getHostGroup(String name);
+
+ /**
+ * Get the hot groups contained in the blueprint.
+ * @return map of host group name to host group
+ */
+ Map<String, HostGroupV2> getHostGroups();
+
+ /**
+ * Get stacks associated with the blueprint.
+ *
+ * @return associated stacks
+ */
+ Collection<StackV2> getStacks();
+
+
+ Collection<ServiceGroup> getServiceGroups();
+
+ /**
+ * Get all of the services represented in the blueprint.
+ *
+ * @return collection of all represented service names
+ */
+ Collection<Service> getAllServices();
+
+ /**
+ * Get the components that are included in the blueprint for the specified service.
+ *
+ * @param service service name
+ *
+ * @return collection of component names for the service. Will not return null.
+ */
+ Collection<ComponentV2> getComponents(Service service);
+
+
+ /**
+ * Get the host groups which contain components for the specified service.
+ *
+ * @param service service name
+ *
+ * @return collection of host groups containing components for the specified service;
+ * will not return null
+ */
+ Collection<HostGroupV2> getHostGroupsForService(Service service);
+
+ /**
+ * Get the host groups which contain the give component.
+ *
+ * @param component component name
+ *
+ * @return collection of host groups containing the specified component; will not return null
+ */
+ Collection<HostGroupV2> getHostGroupsForComponent(ComponentV2 component);
+
+ /**
+ * Get the Blueprint cluster scoped configuration.
+ * The blueprint cluster scoped configuration has the stack
+ * configuration with the config types associated with the blueprint
+ * set as it's parent.
+ *
+ * @return blueprint cluster scoped configuration
+ */
+ Configuration getConfiguration();
+
+ /**
+ * Get the Blueprint cluster scoped setting.
+ * The blueprint cluster scoped setting has the setting properties
+ * with the setting names associated with the blueprint.
+ *
+ * @return blueprint cluster scoped setting
+ */
+ Setting getSetting();
+
+
+ /**
+ * Get whether a component is enabled for auto start.
+ *
+ * @param serviceName - Service name.
+ * @param componentName - Component name.
+ *
+ * @return null if value is not specified; true or false if specified.
+ */
+ String getRecoveryEnabled(String serviceName, String componentName);
+
+ /**
+ * Get whether a service is enabled for credential store use.
+ *
+ * @param serviceName - Service name.
+ *
+ * @return null if value is not specified; true or false if specified.
+ */
+ String getCredentialStoreEnabled(String serviceName);
+
+ /**
+ * Check if auto skip failure is enabled.
+ * @return true if enabled, otherwise false.
+ */
+ boolean shouldSkipFailure();
+
+
+ SecurityConfiguration getSecurity();
+
+ /**
+ * Validate the blueprint topology.
+ *
+ * @throws InvalidTopologyException if the topology is invalid
+ */
+ void validateTopology() throws InvalidTopologyException;
+
+ /**
+ * Validate that the blueprint contains all of the required properties.
+ *
+ * @throws InvalidTopologyException if the blueprint doesn't contain all required properties
+ */
+ void validateRequiredProperties() throws InvalidTopologyException;
+
+ /**
+ *
+ * A config type is valid if there are services related to except cluster-env and global.
+ * @param configType
+ * @return
+ */
+ boolean isValidConfigType(String configType);
+
+ /**
+ * Obtain the blueprint as an entity.
+ *
+ * @return entity representation of the blueprint
+ */
+ BlueprintEntity toEntity();
+
+ List<RepositorySetting> getRepositorySettings();
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9c8ed58d/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
new file mode 100644
index 0000000..175fe99
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+
+import org.apache.ambari.server.controller.internal.ProvisionAction;
+
+public class ComponentV2 {
+
+ private final String name;
+
+ private final Service service;
+
+ private final ProvisionAction provisionAction;
+
+ private final Configuration configuration;
+
+
+ public ComponentV2(String name, Service service) {
+ this(name, service, null, null);
+ }
+
+ public ComponentV2(String name, Service service, ProvisionAction provisionAction, Configuration configuration) {
+ this.name = name;
+ this.service = service;
+ this.provisionAction = provisionAction;
+ this.configuration = configuration;
+ }
+
+ /**
+ * Gets the name of this component
+ *
+ * @return component name
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Gets the provision action associated with this component.
+ *
+ * @return the provision action for this component, which
+ * may be null if the default action is to be used
+ */
+ public ProvisionAction getProvisionAction() {
+ return this.provisionAction;
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9c8ed58d/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
new file mode 100644
index 0000000..506fed0
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+import org.apache.ambari.server.controller.internal.ProvisionAction;
+
+import java.util.Collection;
+import java.util.regex.Pattern;
+
+/**
+ * Host Group representation.
+ */
+public interface HostGroupV2 {
+
+ /**
+ * Compiled regex for hostgroup token.
+ */
+ Pattern HOSTGROUP_REGEX = Pattern.compile("%HOSTGROUP::(\\S+?)%");
+ /**
+ * Get the name of the host group.
+ *
+ * @return the host group name
+ */
+ String getName();
+
+ /**
+ * Get the name of the associated blueprint
+ *
+ * @return associated blueprint name
+ */
+ String getBlueprintName();
+
+ /**
+ * Get the fully qualified host group name in the form of
+ * blueprintName:hostgroupName
+ *
+ * @return fully qualified host group name
+ */
+ String getFullyQualifiedName();
+
+ /**
+ * Get all of the host group components.
+ *
+ * @return collection of component instances
+ */
+ Collection<ComponentV2> getComponents();
+
+ /**
+ * Get all of the host group component names
+ *
+ * @return collection of component names as String
+ */
+ Collection<String> getComponentNames();
+
+ /**
+ * Get all host group component names for instances
+ * that have the specified provision action association.
+ *
+ * @param provisionAction the provision action that must be associated
+ * with the component names returned
+ *
+ * @return collection of component names as String that are associated with
+ * the specified provision action
+ */
+ Collection<String> getComponentNames(ProvisionAction provisionAction);
+
+ /**
+ * Get the host group components which belong to the specified service.
+ *
+ * @param service service name
+ *
+ * @return collection of component names for the specified service; will not return null
+ */
+ Collection<ComponentV2> getComponents(Service service);
+
+ /**
+ * Determine if the host group contains a master component.
+ *
+ * @return true if the host group contains a master component; false otherwise
+ */
+ boolean containsMasterComponent();
+
+ /**
+ * Get all of the services associated with the host group components.
+ *
+ * @return collection of service names
+ */
+ Collection<Service> getServices();
+
+ /**
+ * Get the configuration associated with the host group.
+ * The host group configuration has the blueprint cluster scoped
+ * configuration set as it's parent.
+ *
+ * @return host group configuration
+ */
+ Configuration getConfiguration();
+
+ /**
+ * Get the cardinality value that was specified for the host group.
+ * This is simply meta-data for the stack that a deployer can use
+ * and this information is not used by ambari.
+ *
+ * @return the cardinality specified for the hostgroup
+ */
+ String getCardinality();
+}
+