use V2 objects in TopologyManager
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/65d44cd5 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/65d44cd5 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/65d44cd5 Branch: refs/heads/branch-feature-AMBARI-14714-ui Commit: 65d44cd505f5056499dc29f91d911e604a0b72d8 Parents: b0ff5da Author: Sandor Magyari <[email protected]> Authored: Mon Oct 16 16:27:50 2017 +0200 Committer: Sandor Magyari <[email protected]> Committed: Mon Oct 16 20:14:17 2017 +0200 ---------------------------------------------------------------------- .../query/render/ClusterBlueprintRenderer.java | 60 +- .../server/api/services/ServiceService.java | 2 +- .../StackAdvisorBlueprintProcessor.java | 37 +- .../users/ActiveWidgetLayoutService.java | 2 +- .../api/services/views/ViewInstanceService.java | 2 +- .../ambari/server/controller/StackV2.java | 826 ------------------ .../controller/internal/BaseClusterRequest.java | 41 +- .../BlueprintConfigurationProcessor.java | 304 ++++--- .../internal/ConfigurationContext.java | 59 ++ .../internal/ExportBlueprintRequest.java | 55 +- .../internal/ProvisionClusterRequest.java | 34 +- .../internal/ScaleClusterRequest.java | 20 +- .../server/controller/internal/StackV2.java | 829 +++++++++++++++++++ .../server/controller/internal/UnitUpdater.java | 20 +- .../ambari/server/topology/AmbariContext.java | 297 +++---- .../server/topology/BlueprintFactory.java | 14 +- .../ambari/server/topology/BlueprintImplV2.java | 40 +- .../ambari/server/topology/BlueprintV2.java | 42 +- .../server/topology/BlueprintValidatorImpl.java | 78 +- .../topology/ClusterConfigurationRequest.java | 79 +- .../ambari/server/topology/ClusterTopology.java | 21 +- .../server/topology/ClusterTopologyImpl.java | 93 +-- .../ambari/server/topology/ComponentV2.java | 17 +- .../ambari/server/topology/HostGroupInfo.java | 27 +- .../ambari/server/topology/HostGroupV2.java | 6 + .../ambari/server/topology/HostRequest.java | 58 +- .../ambari/server/topology/LogicalRequest.java | 26 +- .../server/topology/PersistedStateImpl.java | 55 +- .../apache/ambari/server/topology/Service.java | 25 +- .../ambari/server/topology/ServiceGroup.java | 1 + .../ambari/server/topology/TopologyManager.java | 62 +- .../ambari/server/topology/TopologyRequest.java | 10 +- .../tasks/PersistHostResourcesTask.java | 23 +- .../validators/ClusterConfigTypeValidator.java | 11 +- .../validators/HiveServiceValidator.java | 50 +- .../RequiredConfigPropertiesValidator.java | 102 +-- .../validators/RequiredPasswordValidator.java | 32 +- .../validators/StackConfigTypeValidator.java | 37 +- .../topology/validators/UnitValidator.java | 42 +- .../server/api/services/AmbariMetaInfoTest.java | 2 +- .../api/services/RootServiceServiceTest.java | 2 +- .../server/api/services/ServiceServiceTest.java | 2 +- .../AmbariManagementControllerTest.java | 6 +- .../server/state/cluster/ClusterTest.java | 2 +- .../server/topology/BlueprintImplTest.java | 10 +- .../topology/ClusterTopologyImplTest.java | 58 +- 46 files changed, 1782 insertions(+), 1839 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/65d44cd5/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java index acdf9ed..4f71255 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java @@ -18,57 +18,24 @@ package org.apache.ambari.server.api.query.render; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.api.query.QueryInfo; import org.apache.ambari.server.api.services.Request; -import org.apache.ambari.server.api.services.Result; -import org.apache.ambari.server.api.services.ResultImpl; -import org.apache.ambari.server.api.services.ResultPostProcessor; -import org.apache.ambari.server.api.services.ResultPostProcessorImpl; +import org.apache.ambari.server.api.services.*; import org.apache.ambari.server.api.util.TreeNode; import org.apache.ambari.server.api.util.TreeNodeImpl; import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.controller.AmbariServer; -import org.apache.ambari.server.controller.internal.ArtifactResourceProvider; -import org.apache.ambari.server.controller.internal.BlueprintConfigurationProcessor; -import org.apache.ambari.server.controller.internal.BlueprintResourceProvider; -import org.apache.ambari.server.controller.internal.ExportBlueprintRequest; -import org.apache.ambari.server.controller.internal.RequestImpl; -import org.apache.ambari.server.controller.internal.ResourceImpl; -import org.apache.ambari.server.controller.internal.Stack; -import org.apache.ambari.server.controller.spi.ClusterController; -import org.apache.ambari.server.controller.spi.NoSuchParentResourceException; -import org.apache.ambari.server.controller.spi.NoSuchResourceException; -import org.apache.ambari.server.controller.spi.Predicate; -import org.apache.ambari.server.controller.spi.Resource; -import org.apache.ambari.server.controller.spi.ResourceProvider; -import org.apache.ambari.server.controller.spi.SystemException; -import org.apache.ambari.server.controller.spi.UnsupportedPropertyException; +import org.apache.ambari.server.controller.internal.*; +import org.apache.ambari.server.controller.spi.*; import org.apache.ambari.server.controller.utilities.PredicateBuilder; import org.apache.ambari.server.state.SecurityType; -import org.apache.ambari.server.topology.AmbariContext; -import org.apache.ambari.server.topology.ClusterTopology; -import org.apache.ambari.server.topology.ClusterTopologyImpl; -import org.apache.ambari.server.topology.Component; -import org.apache.ambari.server.topology.Configuration; -import org.apache.ambari.server.topology.HostGroup; -import org.apache.ambari.server.topology.HostGroupInfo; -import org.apache.ambari.server.topology.InvalidTopologyException; -import org.apache.ambari.server.topology.InvalidTopologyTemplateException; -import org.apache.ambari.server.topology.SecurityConfigurationFactory; +import org.apache.ambari.server.topology.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.*; + /** * Renderer which renders a cluster resource as a blueprint. */ @@ -193,12 +160,15 @@ public class ClusterBlueprintRenderer extends BaseRenderer implements Renderer { throw new RuntimeException("Unable to process blueprint export request: " + e, e); } - BlueprintConfigurationProcessor configProcessor = new BlueprintConfigurationProcessor(topology); + ConfigurationContext configurationContext = new ConfigurationContext(topology.getBlueprint().getStacks().iterator().next(), + topology.getBlueprint().getConfiguration()); + BlueprintConfigurationProcessor configProcessor = new BlueprintConfigurationProcessor(topology, configurationContext); configProcessor.doUpdateForBlueprintExport(); - Stack stack = topology.getBlueprint().getStack(); - blueprintResource.setProperty("Blueprints/stack_name", stack.getName()); - blueprintResource.setProperty("Blueprints/stack_version", stack.getVersion()); + //TODO add service groups + //Stack stack = topology.getBlueprint().getStack(); + //blueprintResource.setProperty("Blueprints/stack_name", stack.getName()); + //blueprintResource.setProperty("Blueprints/stack_version", stack.getVersion()); if (topology.isClusterKerberosEnabled()) { Map<String, Object> securityConfigMap = new LinkedHashMap<>(); @@ -443,9 +413,9 @@ public class ClusterBlueprintRenderer extends BaseRenderer implements Renderer { * * @return list of component names for the host */ - private List<Map<String, String>> processHostGroupComponents(HostGroup group) { + private List<Map<String, String>> processHostGroupComponents(HostGroupV2 group) { List<Map<String, String>> listHostGroupComponents = new ArrayList<>(); - for (Component component : group.getComponents()) { + for (ComponentV2 component : group.getComponents()) { Map<String, String> mapComponentProperties = new HashMap<>(); listHostGroupComponents.add(mapComponentProperties); mapComponentProperties.put("name", component.getName()); http://git-wip-us.apache.org/repos/asf/ambari/blob/65d44cd5/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java index 12f4bca..cb0ad20 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java @@ -122,7 +122,7 @@ public class ServiceService extends BaseService { @Path("") // This is needed if class level path is not present otherwise no Swagger docs will be generated for this method @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Get all services", - nickname = "ServiceService#getServices", + nickname = "ServiceService#getServiceConfigs", notes = "Returns all services.", response = ServiceResponse.ServiceResponseSwagger.class, responseContainer = RESPONSE_CONTAINER_LIST) http://git-wip-us.apache.org/repos/asf/ambari/blob/65d44cd5/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java index 273c0ff..441f71d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java @@ -18,34 +18,23 @@ 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 com.google.common.base.Preconditions; +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; import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest.StackAdvisorRequestType; import org.apache.ambari.server.api.services.stackadvisor.recommendations.RecommendationResponse; import org.apache.ambari.server.api.services.stackadvisor.recommendations.RecommendationResponse.BlueprintConfigurations; import org.apache.ambari.server.controller.internal.ConfigurationTopologyException; -import org.apache.ambari.server.controller.internal.Stack; +import org.apache.ambari.server.controller.internal.StackV2; import org.apache.ambari.server.state.ValueAttributesInfo; -import org.apache.ambari.server.topology.AdvisedConfiguration; -import org.apache.ambari.server.topology.Blueprint; -import org.apache.ambari.server.topology.ClusterTopology; -import org.apache.ambari.server.topology.ConfigRecommendationStrategy; -import org.apache.ambari.server.topology.HostGroup; -import org.apache.ambari.server.topology.HostGroupInfo; +import org.apache.ambari.server.topology.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; -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; +import java.util.*; /** * Generate advised configurations for blueprint cluster provisioning by the stack advisor. @@ -89,14 +78,14 @@ public class StackAdvisorBlueprintProcessor { } private StackAdvisorRequest createStackAdvisorRequest(ClusterTopology clusterTopology, StackAdvisorRequestType requestType) { - Stack stack = clusterTopology.getBlueprint().getStack(); + StackV2 stack = clusterTopology.getBlueprint().getStacks().iterator().next(); 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())) + .forServices(new ArrayList<>(clusterTopology.getBlueprint().getAllServiceTypes())) .forHosts(gatherHosts(clusterTopology)) .forHostsGroupBindings(gatherHostGroupBindings(clusterTopology)) .forHostComponents(gatherHostGroupComponents(clusterTopology)) @@ -117,7 +106,7 @@ public class StackAdvisorBlueprintProcessor { 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()) { + for (Map.Entry<String, HostGroupV2> hgEnrty: clusterTopology.getBlueprint().getHostGroups().entrySet()) { hgComponentsMap.put(hgEnrty.getKey(), Sets.newCopyOnWriteArraySet(hgEnrty.getValue().getComponentNames())); } return hgComponentsMap; @@ -176,7 +165,7 @@ public class StackAdvisorBlueprintProcessor { Map<String, BlueprintConfigurations> recommendedConfigurations = response.getRecommendations().getBlueprint().getConfigurations(); - Blueprint blueprint = topology.getBlueprint(); + BlueprintV2 blueprint = topology.getBlueprint(); for (Map.Entry<String, BlueprintConfigurations> configEntry : recommendedConfigurations.entrySet()) { String configType = configEntry.getKey(); http://git-wip-us.apache.org/repos/asf/ambari/blob/65d44cd5/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java index e7cdabb..2667a0c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java @@ -64,7 +64,7 @@ public class ActiveWidgetLayoutService extends BaseService { */ @GET @Produces("text/plain") - @ApiOperation(value = "Get user widget layouts", nickname = "ActiveWidgetLayoutService#getServices", notes = "Returns all active widget layouts for user.", response = ActiveWidgetLayoutResponse.class, responseContainer = "List") + @ApiOperation(value = "Get user widget layouts", nickname = "ActiveWidgetLayoutService#getServiceConfigs", notes = "Returns all active widget layouts for user.", response = ActiveWidgetLayoutResponse.class, responseContainer = "List") @ApiImplicitParams({ @ApiImplicitParam(name = "fields", value = "Filter user layout details", defaultValue = "WidgetLayoutInfo/*", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "sortBy", value = "Sort layouts (asc | desc)", defaultValue = "WidgetLayoutInfo/user_name.asc", dataType = "string", paramType = "query"), http://git-wip-us.apache.org/repos/asf/ambari/blob/65d44cd5/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java index e4ebedb..036f1bd 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java @@ -76,7 +76,7 @@ public class ViewInstanceService extends BaseService { */ @GET @Produces("text/plain") - @ApiOperation(value = "Get all view instances", nickname = "ViewInstanceService#getServices", notes = "Returns all instances for a view version.", response = ViewInstanceResponse.class, responseContainer = "List") + @ApiOperation(value = "Get all view instances", nickname = "ViewInstanceService#getServiceConfigs", notes = "Returns all instances for a view version.", response = ViewInstanceResponse.class, responseContainer = "List") @ApiImplicitParams({ @ApiImplicitParam(name = "fields", value = "Filter view instance details", defaultValue = "ViewInstanceInfo/*", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "sortBy", value = "Sort users (asc | desc)", defaultValue = "ViewInstanceInfo/instance_name.desc", dataType = "string", paramType = "query"), http://git-wip-us.apache.org/repos/asf/ambari/blob/65d44cd5/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 deleted file mode 100644 index a6d8979..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java +++ /dev/null @@ -1,826 +0,0 @@ -/* - * 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 java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.orm.entities.StackEntity; -import org.apache.ambari.server.state.AutoDeployInfo; -import org.apache.ambari.server.state.ComponentInfo; -import org.apache.ambari.server.state.DependencyInfo; -import org.apache.ambari.server.state.PropertyDependencyInfo; -import org.apache.ambari.server.state.PropertyInfo; -import org.apache.ambari.server.state.ValueAttributesInfo; -import org.apache.ambari.server.topology.Cardinality; -import org.apache.ambari.server.topology.Configuration; - -/** - * 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<ReadOnlyConfigurationResponse> serviceConfigs = controller.getStackConfigurations( - Collections.singleton(new StackConfigurationRequest(name, version, service, null))); - Set<ReadOnlyConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations( - Collections.singleton(new StackLevelConfigurationRequest(name, version, null))); - serviceConfigs.addAll(stackLevelConfigs); - - // shouldn't have any required properties in stack level configuration - for (ReadOnlyConfigurationResponse 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<ReadOnlyConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations( - Collections.singleton(new StackLevelConfigurationRequest(name, version, null))); - - for (ReadOnlyConfigurationResponse 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(ReadOnlyConfigurationResponse 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/65d44cd5/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java index 77eafeb..c3858ba 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java @@ -18,24 +18,15 @@ package org.apache.ambari.server.controller.internal; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - import org.apache.ambari.server.api.predicate.InvalidQueryException; import org.apache.ambari.server.api.predicate.QueryLexer; import org.apache.ambari.server.api.predicate.Token; import org.apache.ambari.server.controller.spi.Resource; import org.apache.ambari.server.controller.spi.ResourceProvider; import org.apache.ambari.server.controller.utilities.ClusterControllerHelper; -import org.apache.ambari.server.topology.Blueprint; -import org.apache.ambari.server.topology.BlueprintFactory; -import org.apache.ambari.server.topology.Configuration; -import org.apache.ambari.server.topology.HostGroupInfo; -import org.apache.ambari.server.topology.InvalidTopologyTemplateException; -import org.apache.ambari.server.topology.SecurityConfiguration; -import org.apache.ambari.server.topology.TopologyRequest; +import org.apache.ambari.server.topology.*; + +import java.util.*; /** * Provides common cluster request functionality. @@ -62,12 +53,7 @@ public abstract class BaseClusterRequest implements TopologyRequest { * blueprint */ //todo: change interface to only return blueprint name - protected Blueprint blueprint; - - /** - * configuration - */ - protected Configuration configuration; + protected BlueprintV2 blueprint; /** * security configuration @@ -80,6 +66,11 @@ public abstract class BaseClusterRequest implements TopologyRequest { protected static BlueprintFactory blueprintFactory; /** + * List of services + */ + protected Collection<Service> serviceConfigs; + + /** * Lexer used to obtain property names from a predicate string */ private static final QueryLexer queryLexer = new QueryLexer(); @@ -104,13 +95,19 @@ public abstract class BaseClusterRequest implements TopologyRequest { } @Override - public Blueprint getBlueprint() { + public BlueprintV2 getBlueprint() { return blueprint; } @Override + public Collection<Service> getServiceConfigs() { + return serviceConfigs; + } + + @Override + @Deprecated public Configuration getConfiguration() { - return configuration; + return null; } @Override @@ -155,7 +152,7 @@ public abstract class BaseClusterRequest implements TopologyRequest { * * @param blueprint blueprint */ - protected void setBlueprint(Blueprint blueprint) { + protected void setBlueprint(BlueprintV2 blueprint) { this.blueprint = blueprint; } @@ -164,8 +161,8 @@ public abstract class BaseClusterRequest implements TopologyRequest { * * @param configuration configuration */ + @Deprecated protected void setConfiguration(Configuration configuration) { - this.configuration = configuration; } /**
