You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2018/03/22 21:59:25 UTC

[ambari] branch branch-feature-AMBARI-14714 updated (f216e674 -> 4c8f4f6)

This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a change to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git.


    from f216e674 Fix checkstyle issue (#757)
     new ee8fd80  AMBARI-22875. Remove FreeBuilder
     new db9b80c  AMBARI-22875. Reapply some changes lost in the merge
     new 4c8f4f6  AMBARI-14714. Fix unit tests after merge

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ambari-project/pom.xml                             |   7 -
 ambari-server/pom.xml                              |   4 -
 .../controller/AmbariManagementControllerImpl.java |   8 +-
 .../server/controller/internal/CompositeStack.java |   3 +-
 .../ambari/server/controller/internal/Stack.java   |   4 +-
 .../controller/internal/StackDefinition.java       |   5 +-
 .../orm/dao/HostComponentDesiredStateDAO.java      |  23 +-
 .../orm/dao/ServiceComponentDesiredStateDAO.java   |   8 +-
 .../ambari/server/orm/dao/ServiceConfigDAO.java    |   8 +-
 .../entities/HostComponentDesiredStateEntity.java  |   3 -
 .../server/orm/entities/ServiceConfigEntity.java   |   2 +-
 .../apache/ambari/server/state/ConfigHelper.java   |   7 +-
 .../ambari/server/state/ServiceComponentImpl.java  |   8 -
 .../ambari/server/state/cluster/ClusterImpl.java   |   4 +-
 .../apache/ambari/server/topology/Blueprint.java   |  55 +-
 .../BlueprintBasedClusterProvisionRequest.java     |  41 +-
 .../ambari/server/topology/BlueprintImpl.java      | 135 ----
 .../server/topology/ClusterTopologyImpl.java       |   7 +-
 .../ambari/server/topology/ResolvedComponent.java  |   2 -
 .../server/topology/ResolvedComponent_Builder.java | 715 +++++++++++++++++++++
 .../org/apache/ambari/server/topology/Setting.java |   2 +-
 .../server/topology/StackComponentResolver.java    |  17 +-
 .../BlueprintConfigurationProcessorTest.java       |   3 +-
 .../StackUpgradeConfigurationMergeTest.java        |  10 +
 .../server/topology/ClusterTopologyImplTest.java   |  25 +-
 .../apache/ambari/server/utils/StageUtilsTest.java |  10 +-
 26 files changed, 792 insertions(+), 324 deletions(-)
 create mode 100644 ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent_Builder.java

-- 
To stop receiving notification emails like this one, please contact
adoroszlai@apache.org.

[ambari] 02/03: AMBARI-22875. Reapply some changes lost in the merge

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit db9b80cb570ff11184e4e0fbc4c7378fa290c752
Author: Doroszlai, Attila <ad...@apache.org>
AuthorDate: Wed Mar 21 22:47:21 2018 +0100

    AMBARI-22875. Reapply some changes lost in the merge
---
 .../server/controller/internal/CompositeStack.java |   3 +-
 .../ambari/server/controller/internal/Stack.java   |   4 +-
 .../controller/internal/StackDefinition.java       |   5 +-
 .../apache/ambari/server/topology/Blueprint.java   |  55 +--------
 .../BlueprintBasedClusterProvisionRequest.java     |  41 +------
 .../ambari/server/topology/BlueprintImpl.java      | 135 ---------------------
 .../server/topology/ClusterTopologyImpl.java       |   7 +-
 .../org/apache/ambari/server/topology/Setting.java |   2 +-
 .../server/topology/StackComponentResolver.java    |  17 +--
 .../BlueprintConfigurationProcessorTest.java       |   1 -
 .../server/topology/ClusterTopologyImplTest.java   |  25 ++--
 11 files changed, 39 insertions(+), 256 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompositeStack.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompositeStack.java
index 333a20a..8839857 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompositeStack.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompositeStack.java
@@ -34,6 +34,7 @@ import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.DependencyInfo;
 import org.apache.ambari.server.state.PropertyInfo;
+import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.topology.Cardinality;
 import org.apache.ambari.server.topology.Configuration;
@@ -210,7 +211,7 @@ public class CompositeStack implements StackDefinition {
 
   @Override
   @Nonnull
-  public Stream<Pair<StackId, String>> getServicesForComponent(String component) {
+  public Stream<Pair<StackId, ServiceInfo>> getServicesForComponent(String component) {
     return stacks.stream()
       .flatMap(stack -> stack.getServicesForComponent(component));
   }
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java
index 1014245..2911cea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java
@@ -385,10 +385,10 @@ public class Stack implements StackDefinition {
 
   @Override
   @Nonnull
-  public Stream<Pair<StackId, String>> getServicesForComponent(String component) {
+  public Stream<Pair<StackId, ServiceInfo>> getServicesForComponent(String component) {
     String service = getServiceForComponent(component);
     return service != null
-      ? Stream.of(Pair.of(getStackId(), service))
+      ? Stream.of(Pair.of(getStackId(), stackInfo.getService(service)))
       : Stream.empty();
   }
 
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinition.java
index 3f9c74f..ae07ad2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinition.java
@@ -29,6 +29,7 @@ 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.PropertyInfo;
+import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.topology.Cardinality;
 import org.apache.ambari.server.topology.Configuration;
@@ -204,10 +205,10 @@ public interface StackDefinition {
   String getServiceForComponent(String component);
 
   /**
-   * Get (stackID, service) pairs which contain the specified component in this stack.
+   * Get (stackID, service info) pairs which contain the specified component in this stack.
    */
   @Nonnull
-  Stream<Pair<StackId, String>> getServicesForComponent(String component);
+  Stream<Pair<StackId, ServiceInfo>> getServicesForComponent(String component);
 
   /**
    * Obtain the service name which corresponds to the specified configuration.
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Blueprint.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Blueprint.java
index e218772..6445624 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Blueprint.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Blueprint.java
@@ -24,9 +24,7 @@ import java.util.Set;
 
 import javax.annotation.Nonnull;
 
-import org.apache.ambari.server.controller.internal.Stack;
 import org.apache.ambari.server.orm.entities.BlueprintEntity;
-import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 
 /**
@@ -76,56 +74,7 @@ public interface Blueprint {
   Setting getSetting();
 
   /**
-   *
-   * Get all of the services represented in the blueprint.
-   *
-   * @return collection of all represented service names
-   */
-  Collection<String> getServices();
-
-  /**
-  * @return collection of all service infos
-   */
-  Collection<ServiceInfo> getServiceInfos();
-
-  /**
-   * 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<String> getComponents(String service);
-
-  /**
-   * 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();
-
-  /**
-   * Get the stack associated with the blueprint.
-   *
-   * @return associated stack
+   * @return the set of stack (mpack) IDs associated with the blueprint
    */
   Set<StackId> getStackIds();
 
@@ -136,8 +85,6 @@ public interface Blueprint {
    */
   Collection<MpackInstance> getMpacks();
 
-  Stack getStack();
-
   /**
    * Get the host groups which contain the give component.
    *
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java
index 5b8b93c..22d4bab 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java
@@ -29,11 +29,9 @@ import javax.annotation.Nonnull;
 
 import org.apache.ambari.server.controller.internal.ProvisionAction;
 import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
-import org.apache.ambari.server.controller.internal.Stack;
 import org.apache.ambari.server.controller.internal.StackDefinition;
 import org.apache.ambari.server.orm.entities.BlueprintEntity;
 import org.apache.ambari.server.state.SecurityType;
-import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -98,36 +96,6 @@ public class BlueprintBasedClusterProvisionRequest implements Blueprint, Provisi
   }
 
   @Override
-  public Collection<String> getServices() {
-    return null;
-  }
-
-  @Override
-  public Collection<ServiceInfo> getServiceInfos() {
-    return null;
-  }
-
-  @Override
-  public Collection<String> getComponents(String service) {
-    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 Set<StackId> getStackIds() {
     return stackIds;
   }
@@ -138,11 +106,6 @@ public class BlueprintBasedClusterProvisionRequest implements Blueprint, Provisi
   }
 
   @Override
-  public Stack getStack() {
-    return null;
-  }
-
-  @Override
   public Collection<HostGroup> getHostGroupsForComponent(String component) {
     return blueprint.getHostGroupsForComponent(component);
   }
@@ -195,6 +158,10 @@ public class BlueprintBasedClusterProvisionRequest implements Blueprint, Provisi
     return request.getProvisionAction();
   }
 
+  public StackDefinition getStack() {
+    return stack;
+  }
+
   public Map<String, Map<String, ServiceInstance>> getServicesByMpack() {
     Map<String, Map<String, ServiceInstance>> result = new HashMap<>();
     for (MpackInstance mpack : mpacks) {
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java
index 4c6882b..7948fe0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java
@@ -30,7 +30,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.function.Supplier;
 
-import org.apache.ambari.server.controller.internal.Stack;
 import org.apache.ambari.server.orm.entities.BlueprintConfigEntity;
 import org.apache.ambari.server.orm.entities.BlueprintConfiguration;
 import org.apache.ambari.server.orm.entities.BlueprintEntity;
@@ -41,10 +40,8 @@ import org.apache.ambari.server.orm.entities.HostGroupConfigEntity;
 import org.apache.ambari.server.orm.entities.HostGroupEntity;
 import org.apache.ambari.server.orm.entities.MpackInstanceServiceEntity;
 import org.apache.ambari.server.stack.NoSuchStackException;
-import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.utils.JsonUtils;
-import org.apache.commons.lang.StringUtils;
 
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.google.common.base.Preconditions;
@@ -65,7 +62,6 @@ public class BlueprintImpl implements Blueprint {
   private final SecurityConfiguration security;
   private final Setting setting;
   private final List<RepositorySetting> repoSettings;
-  private Stack stack;
 
   public BlueprintImpl(BlueprintEntity entity, Set<StackId> stackIds) throws NoSuchStackException {
     name = entity.getBlueprintName();
@@ -138,141 +134,10 @@ public class BlueprintImpl implements Blueprint {
   }
 
   @Override
-  public Collection<String> getServices() {
-    return null;
-  }
-
-  @Override
-  public Collection<ServiceInfo> getServiceInfos() {
-    return null;
-  }
-
-  @Override
-  public Collection<String> getComponents(String service) {
-    return null;
-  }
-
   public Collection<MpackInstance> getMpacks() {
     return mpacks;
   }
 
-
-  /**
-   * Get whether the specified component in the service 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.
-   */
-  @Override
-  public String getRecoveryEnabled(String serviceName, String componentName) {
-    Set<Map<String, String>> settingValue;
-
-    if (setting == null)
-      return null;
-
-    // If component name was specified in the list of "component_settings",
-    // determine if recovery_enabled is true or false and return it.
-    settingValue = setting.getSettingValue(Setting.SETTING_NAME_COMPONENT_SETTINGS);
-    for (Map<String, String> setting : settingValue) {
-      String name = setting.get(Setting.SETTING_NAME_NAME);
-      if (StringUtils.equals(name, componentName)) {
-        if (!StringUtils.isEmpty(setting.get(Setting.SETTING_NAME_RECOVERY_ENABLED))) {
-          return setting.get(Setting.SETTING_NAME_RECOVERY_ENABLED);
-        }
-      }
-    }
-
-    // If component name is not specified, look up it's service.
-    settingValue = setting.getSettingValue(Setting.SETTING_NAME_SERVICE_SETTINGS);
-    for ( Map<String, String> setting : settingValue){
-      String name = setting.get(Setting.SETTING_NAME_NAME);
-      if (StringUtils.equals(name, serviceName)) {
-        if (!StringUtils.isEmpty(setting.get(Setting.SETTING_NAME_RECOVERY_ENABLED))) {
-          return setting.get(Setting.SETTING_NAME_RECOVERY_ENABLED);
-        }
-      }
-    }
-
-    // If service name is not specified, look up the cluster setting.
-    settingValue = setting.getSettingValue(Setting.SETTING_NAME_RECOVERY_SETTINGS);
-    for (Map<String, String> setting : settingValue) {
-      if (!StringUtils.isEmpty(setting.get(Setting.SETTING_NAME_RECOVERY_ENABLED))) {
-        return setting.get(Setting.SETTING_NAME_RECOVERY_ENABLED);
-      }
-    }
-
-    return null;
-  }
-
-  /**
-   * Get whether the specified service is enabled for credential store use.
-   *
-   * <pre>
-   *     {@code
-   *       {
-   *         "service_settings" : [
-   *         { "name" : "RANGER",
-   *           "recovery_enabled" : "true",
-   *           "credential_store_enabled" : "true"
-   *         },
-   *         { "name" : "HIVE",
-   *           "recovery_enabled" : "true",
-   *           "credential_store_enabled" : "false"
-   *         },
-   *         { "name" : "TEZ",
-   *           "recovery_enabled" : "false"
-   *         }
-   *       ]
-   *     }
-   *   }
-   * </pre>
-   *
-   * @param serviceName - Service name.
-   *
-   * @return null if value is not specified; true or false if specified.
-   */
-  @Override
-  public String getCredentialStoreEnabled(String serviceName) {
-    if (setting == null)
-      return null;
-
-    // Look up the service and return the credential_store_enabled value.
-    Set<Map<String, String>> settingValue = setting.getSettingValue(Setting.SETTING_NAME_SERVICE_SETTINGS);
-    for (Map<String, String> setting : settingValue) {
-      String name = setting.get(Setting.SETTING_NAME_NAME);
-      if (StringUtils.equals(name, serviceName)) {
-        if (!StringUtils.isEmpty(setting.get(Setting.SETTING_NAME_CREDENTIAL_STORE_ENABLED))) {
-          return setting.get(Setting.SETTING_NAME_CREDENTIAL_STORE_ENABLED);
-        }
-        break;
-      }
-    }
-
-    return null;
-  }
-
-  @Override
-  public boolean shouldSkipFailure() {
-    if (setting == null) {
-      return false;
-    }
-    Set<Map<String, String>> settingValue = setting.getSettingValue(Setting.SETTING_NAME_DEPLOYMENT_SETTINGS);
-    for (Map<String, String> setting : settingValue) {
-      if (setting.containsKey(Setting.SETTING_NAME_SKIP_FAILURE)) {
-        return setting.get(Setting.SETTING_NAME_SKIP_FAILURE).equalsIgnoreCase("true");
-      }
-    }
-    return false;
-  }
-
-  @Override
-  public Stack getStack() {
-    return stack;
-  }
-
   /**
    * Get host groups which contain a component.
    *
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
index ffcb683..c7297e2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
@@ -372,11 +372,8 @@ public class ClusterTopologyImpl implements ClusterTopology {
 
   @Override
   public boolean isComponentHadoopCompatible(String component) {
-    return blueprint.getServiceInfos().stream()
-      .filter(service -> service.getComponentByName(component) != null)
-      .findFirst()
-      .map(service -> HADOOP_COMPATIBLE_FS.equals(service.getServiceType()))
-      .orElse(false);
+    return getStack().getServicesForComponent(component)
+      .anyMatch(stackIdService -> HADOOP_COMPATIBLE_FS.equals(stackIdService.getRight().getServiceType()));
   }
 
   private void registerHostGroupInfo(Map<String, HostGroupInfo> requestedHostGroupInfoMap) throws InvalidTopologyException {
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java
index 29289cc..cf13473 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java
@@ -63,7 +63,7 @@ public class Setting {
    *     }
    *   </pre>
    */
-  protected static final String SETTING_NAME_CREDENTIAL_STORE_ENABLED = "credential_store_enabled";
+  private static final String SETTING_NAME_CREDENTIAL_STORE_ENABLED = "credential_store_enabled";
 
   /**
    * Settings.
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/StackComponentResolver.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/StackComponentResolver.java
index 9d524d0..6db9a46 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/StackComponentResolver.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/StackComponentResolver.java
@@ -28,6 +28,7 @@ import java.util.Set;
 import java.util.stream.Stream;
 
 import org.apache.ambari.server.controller.internal.StackDefinition;
+import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.commons.lang3.tuple.Pair;
 import org.slf4j.Logger;
@@ -53,20 +54,20 @@ public class StackComponentResolver implements ComponentResolver {
       result.put(hg.getName(), new HashSet<>());
 
       for (Component comp : hg.getComponents()) {
-        Stream<Pair<StackId, String>> servicesForComponent = stack.getServicesForComponent(comp.getName());
+        Stream<Pair<StackId, ServiceInfo>> servicesForComponent = stack.getServicesForComponent(comp.getName());
         servicesForComponent = filterByMpackName(comp, servicesForComponent);
         servicesForComponent = filterByServiceName(comp, servicesForComponent, mpackServices, uniqueServices);
 
-        Set<Pair<StackId, String>> serviceMatches = servicesForComponent.collect(toSet());
+        Set<Pair<StackId, ServiceInfo>> serviceMatches = servicesForComponent.collect(toSet());
 
         if (serviceMatches.size() != 1) {
           String msg = formatResolutionProblemMessage(hg, comp, serviceMatches);
           LOG.warn("Component resolution failure:" + msg);
           problems.add(msg);
         } else {
-          Pair<StackId, String> stackService = serviceMatches.iterator().next();
+          Pair<StackId, ServiceInfo> stackService = serviceMatches.iterator().next();
           StackId stackId = stackService.getLeft();
-          String serviceType = stackService.getRight();
+          String serviceType = stackService.getRight().getServiceType();
 
           ResolvedComponent resolved = ResolvedComponent.builder(comp)
             .stackId(stackId)
@@ -86,7 +87,7 @@ public class StackComponentResolver implements ComponentResolver {
     return result;
   }
 
-  private static String formatResolutionProblemMessage(HostGroup hg, Component comp, Set<Pair<StackId, String>> serviceMatches) {
+  private static String formatResolutionProblemMessage(HostGroup hg, Component comp, Set<Pair<StackId, ServiceInfo>> serviceMatches) {
     boolean multipleMatches = !serviceMatches.isEmpty();
     String problem = multipleMatches ? "Multiple services" : "No service";
 
@@ -108,7 +109,7 @@ public class StackComponentResolver implements ComponentResolver {
   }
 
   // if component references a specific service instance, filter the stream by the type of that service
-  private static Stream<Pair<StackId, String>> filterByServiceName(Component comp, Stream<Pair<StackId, String>> stream,
+  private static Stream<Pair<StackId, ServiceInfo>> filterByServiceName(Component comp, Stream<Pair<StackId, ServiceInfo>> stream,
     Map<String, Map<String, ServiceInstance>> mpackServices, Map<String, ServiceInstance> uniqueServices
   ) {
     if (!Strings.isNullOrEmpty(comp.getServiceInstance())) {
@@ -121,7 +122,7 @@ public class StackComponentResolver implements ComponentResolver {
       if (service != null) {
         String serviceType = service.getType();
 
-        return stream.filter(pair -> pair.getRight().equals(serviceType));
+        return stream.filter(pair -> pair.getRight().getServiceType().equals(serviceType));
       }
     }
 
@@ -129,7 +130,7 @@ public class StackComponentResolver implements ComponentResolver {
   }
 
   // if component references a specific mpack instance, filter the stream by the name of that mpack
-  private static Stream<Pair<StackId, String>> filterByMpackName(Component comp, Stream<Pair<StackId, String>> stream) {
+  private static Stream<Pair<StackId, ServiceInfo>> filterByMpackName(Component comp, Stream<Pair<StackId, ServiceInfo>> stream) {
     if (!Strings.isNullOrEmpty(comp.getMpackInstance())) {
       return stream.filter(pair -> pair.getLeft().getStackName().equals(comp.getMpackInstance()));
     }
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
index b92a00e..84e3593 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
@@ -159,7 +159,6 @@ public class BlueprintConfigurationProcessorTest extends EasyMockSupport {
     expect(ambariContext.composeStacks(anyObject())).andReturn(stack).anyTimes();
     expect(bp.getStackIds()).andReturn(ImmutableSet.of(STACK_ID)).anyTimes();
     expect(bp.getName()).andReturn("test-bp").anyTimes();
-    expect(bp.getServiceInfos()).andReturn(Collections.emptyList()).anyTimes();
 
     expect(stack.getName()).andReturn(STACK_NAME).atLeastOnce();
     expect(stack.getVersion()).andReturn(STACK_VERSION).atLeastOnce();
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
index ec979f2..58262ea 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
@@ -33,10 +33,13 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Stream;
 
+import org.apache.ambari.server.controller.internal.StackDefinition;
 import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
+import org.apache.commons.lang3.tuple.Pair;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -58,7 +61,10 @@ public class ClusterTopologyImplTest {
   private static final HostGroup group2 = createNiceMock(HostGroup.class);
   private static final HostGroup group3 = createNiceMock(HostGroup.class);
   private static final HostGroup group4 = createNiceMock(HostGroup.class);
+  private static final StackId STACK_ID = new StackId("HDP", "2.6");
+  private static final ImmutableSet<StackId> STACK_IDS = ImmutableSet.of(STACK_ID);
   private final AmbariContext ambariContext = createNiceMock(AmbariContext.class);
+  private final StackDefinition stack = createNiceMock(StackDefinition.class);
   private final Map<String, HostGroupInfo> hostGroupInfoMap = new HashMap<>();
   private final Map<String, HostGroup> hostGroupMap = new HashMap<>();
 
@@ -67,7 +73,6 @@ public class ClusterTopologyImplTest {
 
   @Before
   public void setUp() throws Exception {
-
     configuration = new Configuration(new HashMap<>(),
       new HashMap<>());
     bpconfiguration = new Configuration(new HashMap<>(),
@@ -105,7 +110,7 @@ public class ClusterTopologyImplTest {
     group4Info.setPredicate(predicate);
 
     expect(blueprint.getConfiguration()).andReturn(bpconfiguration).anyTimes();
-    expect(blueprint.getStackIds()).andReturn(ImmutableSet.of(new StackId("HDP", "2.6"))).anyTimes();
+    expect(blueprint.getStackIds()).andReturn(STACK_IDS).anyTimes();
 
     hostGroupMap.put("group1", group1);
     hostGroupMap.put("group2", group2);
@@ -127,6 +132,8 @@ public class ClusterTopologyImplTest {
     Set<Component> group4Components = new HashSet<>();
     group4Components.add(new Component("component5"));
 
+    expect(ambariContext.composeStacks(STACK_IDS)).andReturn(stack).anyTimes();
+
     expect(blueprint.getHostGroups()).andReturn(hostGroupMap).anyTimes();
     expect(blueprint.getHostGroup("group1")).andReturn(group1).anyTimes();
     expect(blueprint.getHostGroup("group2")).andReturn(group2).anyTimes();
@@ -151,8 +158,8 @@ public class ClusterTopologyImplTest {
 
   @After
   public void tearDown() {
-    verify(blueprint, group1, group2, group3, group4);
-    reset(blueprint, group1, group2, group3, group4);
+    verify(ambariContext, stack, blueprint, group1, group2, group3, group4);
+    reset(ambariContext, stack, blueprint, group1, group2, group3, group4);
 
 
     hostGroupInfoMap.clear();
@@ -160,7 +167,7 @@ public class ClusterTopologyImplTest {
   }
 
   private void replayAll() {
-    replay(blueprint, group1, group2, group3, group4);
+    replay(ambariContext, stack, blueprint, group1, group2, group3, group4);
   }
 
 
@@ -236,12 +243,10 @@ public class ClusterTopologyImplTest {
 
   @Test
   public void testDecidingIfComponentIsHadoopCompatible() throws Exception {
-    expect(blueprint.getServiceInfos()).andReturn(asList(
-      aHCFSWith(aComponent("ONEFS_CLIENT")),
-      aServiceWith(aComponent("ZOOKEEPER_CLIENT")))
-    ).anyTimes();
+    expect(stack.getServicesForComponent("ONEFS_CLIENT")).andAnswer(() -> Stream.of(Pair.of(STACK_ID, aHCFSWith(aComponent("ONEFS_CLIENT"))))).anyTimes();
+    expect(stack.getServicesForComponent("ZOOKEEPER_CLIENT")).andAnswer(() -> Stream.of(Pair.of(STACK_ID, aServiceWith(aComponent("ZOOKEEPER_CLIENT"))))).anyTimes();
     replayAll();
-    ClusterTopologyImpl topology = new ClusterTopologyImpl(null, new TestTopologyRequest(TopologyRequest.Type.PROVISION));
+    ClusterTopologyImpl topology = new ClusterTopologyImpl(ambariContext, new TestTopologyRequest(TopologyRequest.Type.PROVISION));
     assertTrue(topology.isComponentHadoopCompatible("ONEFS_CLIENT"));
     assertFalse(topology.isComponentHadoopCompatible("ZOOKEEPER_CLIENT"));
   }

-- 
To stop receiving notification emails like this one, please contact
adoroszlai@apache.org.

[ambari] 01/03: AMBARI-22875. Remove FreeBuilder

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit ee8fd80fb884360c5395dc97ff18d7cb539c9ae6
Author: Doroszlai, Attila <ad...@apache.org>
AuthorDate: Wed Mar 21 21:19:09 2018 +0100

    AMBARI-22875. Remove FreeBuilder
---
 ambari-project/pom.xml                             |   7 -
 ambari-server/pom.xml                              |   4 -
 .../ambari/server/topology/ResolvedComponent.java  |   2 -
 .../server/topology/ResolvedComponent_Builder.java | 715 +++++++++++++++++++++
 4 files changed, 715 insertions(+), 13 deletions(-)

diff --git a/ambari-project/pom.xml b/ambari-project/pom.xml
index 2f49d31..3c7b9cd 100644
--- a/ambari-project/pom.xml
+++ b/ambari-project/pom.xml
@@ -613,13 +613,6 @@
         <version>${swagger.maven.plugin.version}</version>
       </dependency>
       <dependency>
-        <groupId>org.inferred</groupId>
-        <artifactId>freebuilder</artifactId>
-        <version>1.14.8</version>
-        <optional>true</optional>
-        <scope>provided</scope>
-      </dependency>
-      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-annotations</artifactId>
         <version>${fasterxml.jackson.version}</version>
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index dd7d14a..22c94bf 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1806,10 +1806,6 @@
         </exclusion>
       </exclusions>
     </dependency>
-    <dependency>
-      <groupId>org.inferred</groupId>
-      <artifactId>freebuilder</artifactId>
-    </dependency>
   </dependencies>
 
   <pluginRepositories>
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent.java
index 85e524b..b6463ad 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent.java
@@ -20,13 +20,11 @@ package org.apache.ambari.server.topology;
 import java.util.Optional;
 
 import org.apache.ambari.server.state.StackId;
-import org.inferred.freebuilder.FreeBuilder;
 
 /**
  * I provide additional information for a component specified in the blueprint,
  * based on values resolved from the stack and sensible defaults.
  */
-@FreeBuilder
 public interface ResolvedComponent {
 
   StackId stackId();
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent_Builder.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent_Builder.java
new file mode 100644
index 0000000..7f3e805
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ResolvedComponent_Builder.java
@@ -0,0 +1,715 @@
+/*
+ * 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 java.util.EnumSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.UnaryOperator;
+
+import javax.annotation.Nullable;
+
+import org.apache.ambari.server.state.StackId;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+
+/**
+ * Auto-generated superclass of {@link ResolvedComponent.Builder}, derived from the API of {@link
+ * ResolvedComponent}.
+ */
+abstract class ResolvedComponent_Builder {
+
+  /** Creates a new builder using {@code value} as a template. */
+  public static ResolvedComponent.Builder from(ResolvedComponent value) {
+    return new ResolvedComponent.Builder().mergeFrom(value);
+  }
+
+  private static final Joiner COMMA_JOINER = Joiner.on(", ").skipNulls();
+
+  private enum Property {
+    STACK_ID("stackId"),
+    SERVICE_TYPE("serviceType"),
+    COMPONENT_NAME("componentName"),
+    COMPONENT("component"),
+    ;
+
+    private final String name;
+
+    private Property(String name) {
+      this.name = name;
+    }
+
+    @Override
+    public String toString() {
+      return name;
+    }
+  }
+
+  private StackId stackId;
+  // Store a nullable object instead of an Optional. Escape analysis then
+  // allows the JVM to optimize away the Optional objects created by and
+  // passed to our API.
+  private String serviceGroupName = null;
+  private String serviceType;
+  // Store a nullable object instead of an Optional. Escape analysis then
+  // allows the JVM to optimize away the Optional objects created by and
+  // passed to our API.
+  private String serviceName = null;
+  private String componentName;
+  private boolean masterComponent;
+  private Component component;
+  private final EnumSet<Property> _unsetProperties =
+      EnumSet.allOf(ResolvedComponent_Builder.Property.class);
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#stackId()}.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code stackId} is null
+   */
+  public ResolvedComponent.Builder stackId(StackId stackId) {
+    this.stackId = Preconditions.checkNotNull(stackId);
+    _unsetProperties.remove(ResolvedComponent_Builder.Property.STACK_ID);
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Replaces the value to be returned by {@link ResolvedComponent#stackId()} by applying {@code
+   * mapper} to it and using the result.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code mapper} is null or returns null
+   * @throws IllegalStateException if the field has not been set
+   */
+  public ResolvedComponent.Builder mapStackId(UnaryOperator<StackId> mapper) {
+    Preconditions.checkNotNull(mapper);
+    return stackId(mapper.apply(stackId()));
+  }
+
+  /**
+   * Returns the value that will be returned by {@link ResolvedComponent#stackId()}.
+   *
+   * @throws IllegalStateException if the field has not been set
+   */
+  public StackId stackId() {
+    Preconditions.checkState(
+        !_unsetProperties.contains(ResolvedComponent_Builder.Property.STACK_ID), "stackId not set");
+    return stackId;
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceGroupName()}.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code serviceGroupName} is null
+   */
+  public ResolvedComponent.Builder serviceGroupName(String serviceGroupName) {
+    this.serviceGroupName = Preconditions.checkNotNull(serviceGroupName);
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceGroupName()}.
+   *
+   * @return this {@code Builder} object
+   */
+  public ResolvedComponent.Builder serviceGroupName(Optional<? extends String> serviceGroupName) {
+    if (serviceGroupName.isPresent()) {
+      return serviceGroupName(serviceGroupName.get());
+    } else {
+      return clearServiceGroupName();
+    }
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceGroupName()}.
+   *
+   * @return this {@code Builder} object
+   */
+  public ResolvedComponent.Builder nullableServiceGroupName(@Nullable String serviceGroupName) {
+    if (serviceGroupName != null) {
+      return serviceGroupName(serviceGroupName);
+    } else {
+      return clearServiceGroupName();
+    }
+  }
+
+  /**
+   * If the value to be returned by {@link ResolvedComponent#serviceGroupName()} is present,
+   * replaces it by applying {@code mapper} to it and using the result.
+   *
+   * <p>If the result is null, clears the value.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code mapper} is null
+   */
+  public ResolvedComponent.Builder mapServiceGroupName(UnaryOperator<String> mapper) {
+    return serviceGroupName(serviceGroupName().map(mapper));
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceGroupName()} to {@link
+   * Optional#empty() Optional.empty()}.
+   *
+   * @return this {@code Builder} object
+   */
+  public ResolvedComponent.Builder clearServiceGroupName() {
+    serviceGroupName = null;
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /** Returns the value that will be returned by {@link ResolvedComponent#serviceGroupName()}. */
+  public Optional<String> serviceGroupName() {
+    return Optional.ofNullable(serviceGroupName);
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceType()}.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code serviceType} is null
+   */
+  public ResolvedComponent.Builder serviceType(String serviceType) {
+    this.serviceType = Preconditions.checkNotNull(serviceType);
+    _unsetProperties.remove(ResolvedComponent_Builder.Property.SERVICE_TYPE);
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Replaces the value to be returned by {@link ResolvedComponent#serviceType()} by applying {@code
+   * mapper} to it and using the result.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code mapper} is null or returns null
+   * @throws IllegalStateException if the field has not been set
+   */
+  public ResolvedComponent.Builder mapServiceType(UnaryOperator<String> mapper) {
+    Preconditions.checkNotNull(mapper);
+    return serviceType(mapper.apply(serviceType()));
+  }
+
+  /**
+   * Returns the value that will be returned by {@link ResolvedComponent#serviceType()}.
+   *
+   * @throws IllegalStateException if the field has not been set
+   */
+  public String serviceType() {
+    Preconditions.checkState(
+        !_unsetProperties.contains(ResolvedComponent_Builder.Property.SERVICE_TYPE),
+        "serviceType not set");
+    return serviceType;
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceName()}.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code serviceName} is null
+   */
+  public ResolvedComponent.Builder serviceName(String serviceName) {
+    this.serviceName = Preconditions.checkNotNull(serviceName);
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceName()}.
+   *
+   * @return this {@code Builder} object
+   */
+  public ResolvedComponent.Builder serviceName(Optional<? extends String> serviceName) {
+    if (serviceName.isPresent()) {
+      return serviceName(serviceName.get());
+    } else {
+      return clearServiceName();
+    }
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceName()}.
+   *
+   * @return this {@code Builder} object
+   */
+  public ResolvedComponent.Builder nullableServiceName(@Nullable String serviceName) {
+    if (serviceName != null) {
+      return serviceName(serviceName);
+    } else {
+      return clearServiceName();
+    }
+  }
+
+  /**
+   * If the value to be returned by {@link ResolvedComponent#serviceName()} is present, replaces it
+   * by applying {@code mapper} to it and using the result.
+   *
+   * <p>If the result is null, clears the value.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code mapper} is null
+   */
+  public ResolvedComponent.Builder mapServiceName(UnaryOperator<String> mapper) {
+    return serviceName(serviceName().map(mapper));
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#serviceName()} to {@link
+   * Optional#empty() Optional.empty()}.
+   *
+   * @return this {@code Builder} object
+   */
+  public ResolvedComponent.Builder clearServiceName() {
+    serviceName = null;
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /** Returns the value that will be returned by {@link ResolvedComponent#serviceName()}. */
+  public Optional<String> serviceName() {
+    return Optional.ofNullable(serviceName);
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#componentName()}.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code componentName} is null
+   */
+  public ResolvedComponent.Builder componentName(String componentName) {
+    this.componentName = Preconditions.checkNotNull(componentName);
+    _unsetProperties.remove(ResolvedComponent_Builder.Property.COMPONENT_NAME);
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Replaces the value to be returned by {@link ResolvedComponent#componentName()} by applying
+   * {@code mapper} to it and using the result.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code mapper} is null or returns null
+   * @throws IllegalStateException if the field has not been set
+   */
+  public ResolvedComponent.Builder mapComponentName(UnaryOperator<String> mapper) {
+    Preconditions.checkNotNull(mapper);
+    return componentName(mapper.apply(componentName()));
+  }
+
+  /**
+   * Returns the value that will be returned by {@link ResolvedComponent#componentName()}.
+   *
+   * @throws IllegalStateException if the field has not been set
+   */
+  public String componentName() {
+    Preconditions.checkState(
+        !_unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT_NAME),
+        "componentName not set");
+    return componentName;
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#masterComponent()}.
+   *
+   * @return this {@code Builder} object
+   */
+  public ResolvedComponent.Builder masterComponent(boolean masterComponent) {
+    this.masterComponent = masterComponent;
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Replaces the value to be returned by {@link ResolvedComponent#masterComponent()} by applying
+   * {@code mapper} to it and using the result.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code mapper} is null or returns null
+   */
+  public ResolvedComponent.Builder mapMasterComponent(UnaryOperator<Boolean> mapper) {
+    return masterComponent(mapper.apply(masterComponent()));
+  }
+
+  /** Returns the value that will be returned by {@link ResolvedComponent#masterComponent()}. */
+  public boolean masterComponent() {
+    return masterComponent;
+  }
+
+  /**
+   * Sets the value to be returned by {@link ResolvedComponent#component()}.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code component} is null
+   */
+  public ResolvedComponent.Builder component(Component component) {
+    this.component = Preconditions.checkNotNull(component);
+    _unsetProperties.remove(ResolvedComponent_Builder.Property.COMPONENT);
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Replaces the value to be returned by {@link ResolvedComponent#component()} by applying {@code
+   * mapper} to it and using the result.
+   *
+   * @return this {@code Builder} object
+   * @throws NullPointerException if {@code mapper} is null or returns null
+   * @throws IllegalStateException if the field has not been set
+   */
+  public ResolvedComponent.Builder mapComponent(UnaryOperator<Component> mapper) {
+    Preconditions.checkNotNull(mapper);
+    return component(mapper.apply(component()));
+  }
+
+  /**
+   * Returns the value that will be returned by {@link ResolvedComponent#component()}.
+   *
+   * @throws IllegalStateException if the field has not been set
+   */
+  public Component component() {
+    Preconditions.checkState(
+        !_unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT),
+        "component not set");
+    return component;
+  }
+
+  /** Sets all property values using the given {@code ResolvedComponent} as a template. */
+  public ResolvedComponent.Builder mergeFrom(ResolvedComponent value) {
+    ResolvedComponent_Builder _defaults = new ResolvedComponent.Builder();
+    if (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.STACK_ID)
+        || !Objects.equals(value.stackId(), _defaults.stackId())) {
+      stackId(value.stackId());
+    }
+    value.serviceGroupName().ifPresent(this::serviceGroupName);
+    if (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.SERVICE_TYPE)
+        || !Objects.equals(value.serviceType(), _defaults.serviceType())) {
+      serviceType(value.serviceType());
+    }
+    value.serviceName().ifPresent(this::serviceName);
+    if (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT_NAME)
+        || !Objects.equals(value.componentName(), _defaults.componentName())) {
+      componentName(value.componentName());
+    }
+    if (!Objects.equals(value.masterComponent(), _defaults.masterComponent())) {
+      masterComponent(value.masterComponent());
+    }
+    if (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT)
+        || !Objects.equals(value.component(), _defaults.component())) {
+      component(value.component());
+    }
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Copies values from the given {@code Builder}. Does not affect any properties not set on the
+   * input.
+   */
+  public ResolvedComponent.Builder mergeFrom(ResolvedComponent.Builder template) {
+    // Upcast to access private fields; otherwise, oddly, we get an access violation.
+    ResolvedComponent_Builder base = template;
+    ResolvedComponent_Builder _defaults = new ResolvedComponent.Builder();
+    if (!base._unsetProperties.contains(ResolvedComponent_Builder.Property.STACK_ID)
+        && (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.STACK_ID)
+            || !Objects.equals(template.stackId(), _defaults.stackId()))) {
+      stackId(template.stackId());
+    }
+    template.serviceGroupName().ifPresent(this::serviceGroupName);
+    if (!base._unsetProperties.contains(ResolvedComponent_Builder.Property.SERVICE_TYPE)
+        && (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.SERVICE_TYPE)
+            || !Objects.equals(template.serviceType(), _defaults.serviceType()))) {
+      serviceType(template.serviceType());
+    }
+    template.serviceName().ifPresent(this::serviceName);
+    if (!base._unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT_NAME)
+        && (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT_NAME)
+            || !Objects.equals(template.componentName(), _defaults.componentName()))) {
+      componentName(template.componentName());
+    }
+    if (!Objects.equals(template.masterComponent(), _defaults.masterComponent())) {
+      masterComponent(template.masterComponent());
+    }
+    if (!base._unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT)
+        && (_defaults._unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT)
+            || !Objects.equals(template.component(), _defaults.component()))) {
+      component(template.component());
+    }
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /** Resets the state of this builder. */
+  public ResolvedComponent.Builder clear() {
+    ResolvedComponent_Builder _defaults = new ResolvedComponent.Builder();
+    stackId = _defaults.stackId;
+    serviceGroupName = _defaults.serviceGroupName;
+    serviceType = _defaults.serviceType;
+    serviceName = _defaults.serviceName;
+    componentName = _defaults.componentName;
+    masterComponent = _defaults.masterComponent;
+    component = _defaults.component;
+    _unsetProperties.clear();
+    _unsetProperties.addAll(_defaults._unsetProperties);
+    return (ResolvedComponent.Builder) this;
+  }
+
+  /**
+   * Returns a newly-created {@link ResolvedComponent} based on the contents of the {@code Builder}.
+   *
+   * @throws IllegalStateException if any field has not been set
+   */
+  public ResolvedComponent build() {
+    Preconditions.checkState(_unsetProperties.isEmpty(), "Not set: %s", _unsetProperties);
+    return new ResolvedComponent_Builder.Value(this);
+  }
+
+  /**
+   * Returns a newly-created partial {@link ResolvedComponent} for use in unit tests. State checking
+   * will not be performed. Unset properties will throw an {@link UnsupportedOperationException}
+   * when accessed via the partial object.
+   *
+   * <p>Partials should only ever be used in tests. They permit writing robust test cases that won't
+   * fail if this type gains more application-level constraints (e.g. new required fields) in
+   * future. If you require partially complete values in production code, consider using a Builder.
+   */
+  @VisibleForTesting()
+  public ResolvedComponent buildPartial() {
+    return new ResolvedComponent_Builder.Partial(this);
+  }
+
+  private static final class Value implements ResolvedComponent {
+    private final StackId stackId;
+    // Store a nullable object instead of an Optional. Escape analysis then
+    // allows the JVM to optimize away the Optional objects created by our
+    // getter method.
+    private final String serviceGroupName;
+    private final String serviceType;
+    // Store a nullable object instead of an Optional. Escape analysis then
+    // allows the JVM to optimize away the Optional objects created by our
+    // getter method.
+    private final String serviceName;
+    private final String componentName;
+    private final boolean masterComponent;
+    private final Component component;
+
+    private Value(ResolvedComponent_Builder builder) {
+      this.stackId = builder.stackId;
+      this.serviceGroupName = builder.serviceGroupName;
+      this.serviceType = builder.serviceType;
+      this.serviceName = builder.serviceName;
+      this.componentName = builder.componentName;
+      this.masterComponent = builder.masterComponent;
+      this.component = builder.component;
+    }
+
+    @Override
+    public StackId stackId() {
+      return stackId;
+    }
+
+    @Override
+    public Optional<String> serviceGroupName() {
+      return Optional.ofNullable(serviceGroupName);
+    }
+
+    @Override
+    public String serviceType() {
+      return serviceType;
+    }
+
+    @Override
+    public Optional<String> serviceName() {
+      return Optional.ofNullable(serviceName);
+    }
+
+    @Override
+    public String componentName() {
+      return componentName;
+    }
+
+    @Override
+    public boolean masterComponent() {
+      return masterComponent;
+    }
+
+    @Override
+    public Component component() {
+      return component;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (!(obj instanceof ResolvedComponent_Builder.Value)) {
+        return false;
+      }
+      ResolvedComponent_Builder.Value other = (ResolvedComponent_Builder.Value) obj;
+      return Objects.equals(stackId, other.stackId)
+          && Objects.equals(serviceGroupName, other.serviceGroupName)
+          && Objects.equals(serviceType, other.serviceType)
+          && Objects.equals(serviceName, other.serviceName)
+          && Objects.equals(componentName, other.componentName)
+          && Objects.equals(masterComponent, other.masterComponent)
+          && Objects.equals(component, other.component);
+    }
+
+    @Override
+    public int hashCode() {
+      return Objects.hash(
+          stackId,
+          serviceGroupName,
+          serviceType,
+          serviceName,
+          componentName,
+          masterComponent,
+          component);
+    }
+
+    @Override
+    public String toString() {
+      return "ResolvedComponent{"
+          + COMMA_JOINER.join(
+              "stackId=" + stackId,
+              (serviceGroupName != null ? "serviceGroupName=" + serviceGroupName : null),
+              "serviceType=" + serviceType,
+              (serviceName != null ? "serviceName=" + serviceName : null),
+              "componentName=" + componentName,
+              "masterComponent=" + masterComponent,
+              "component=" + component)
+          + "}";
+    }
+  }
+
+  private static final class Partial implements ResolvedComponent {
+    private final StackId stackId;
+    // Store a nullable object instead of an Optional. Escape analysis then
+    // allows the JVM to optimize away the Optional objects created by our
+    // getter method.
+    private final String serviceGroupName;
+    private final String serviceType;
+    // Store a nullable object instead of an Optional. Escape analysis then
+    // allows the JVM to optimize away the Optional objects created by our
+    // getter method.
+    private final String serviceName;
+    private final String componentName;
+    private final boolean masterComponent;
+    private final Component component;
+    private final EnumSet<ResolvedComponent_Builder.Property> _unsetProperties;
+
+    Partial(ResolvedComponent_Builder builder) {
+      this.stackId = builder.stackId;
+      this.serviceGroupName = builder.serviceGroupName;
+      this.serviceType = builder.serviceType;
+      this.serviceName = builder.serviceName;
+      this.componentName = builder.componentName;
+      this.masterComponent = builder.masterComponent;
+      this.component = builder.component;
+      this._unsetProperties = builder._unsetProperties.clone();
+    }
+
+    @Override
+    public StackId stackId() {
+      if (_unsetProperties.contains(ResolvedComponent_Builder.Property.STACK_ID)) {
+        throw new UnsupportedOperationException("stackId not set");
+      }
+      return stackId;
+    }
+
+    @Override
+    public Optional<String> serviceGroupName() {
+      return Optional.ofNullable(serviceGroupName);
+    }
+
+    @Override
+    public String serviceType() {
+      if (_unsetProperties.contains(ResolvedComponent_Builder.Property.SERVICE_TYPE)) {
+        throw new UnsupportedOperationException("serviceType not set");
+      }
+      return serviceType;
+    }
+
+    @Override
+    public Optional<String> serviceName() {
+      return Optional.ofNullable(serviceName);
+    }
+
+    @Override
+    public String componentName() {
+      if (_unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT_NAME)) {
+        throw new UnsupportedOperationException("componentName not set");
+      }
+      return componentName;
+    }
+
+    @Override
+    public boolean masterComponent() {
+      return masterComponent;
+    }
+
+    @Override
+    public Component component() {
+      if (_unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT)) {
+        throw new UnsupportedOperationException("component not set");
+      }
+      return component;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (!(obj instanceof ResolvedComponent_Builder.Partial)) {
+        return false;
+      }
+      ResolvedComponent_Builder.Partial other = (ResolvedComponent_Builder.Partial) obj;
+      return Objects.equals(stackId, other.stackId)
+          && Objects.equals(serviceGroupName, other.serviceGroupName)
+          && Objects.equals(serviceType, other.serviceType)
+          && Objects.equals(serviceName, other.serviceName)
+          && Objects.equals(componentName, other.componentName)
+          && Objects.equals(masterComponent, other.masterComponent)
+          && Objects.equals(component, other.component)
+          && Objects.equals(_unsetProperties, other._unsetProperties);
+    }
+
+    @Override
+    public int hashCode() {
+      return Objects.hash(
+          stackId,
+          serviceGroupName,
+          serviceType,
+          serviceName,
+          componentName,
+          masterComponent,
+          component,
+          _unsetProperties);
+    }
+
+    @Override
+    public String toString() {
+      return "partial ResolvedComponent{"
+          + COMMA_JOINER.join(
+              (!_unsetProperties.contains(ResolvedComponent_Builder.Property.STACK_ID)
+                  ? "stackId=" + stackId
+                  : null),
+              (serviceGroupName != null ? "serviceGroupName=" + serviceGroupName : null),
+              (!_unsetProperties.contains(ResolvedComponent_Builder.Property.SERVICE_TYPE)
+                  ? "serviceType=" + serviceType
+                  : null),
+              (serviceName != null ? "serviceName=" + serviceName : null),
+              (!_unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT_NAME)
+                  ? "componentName=" + componentName
+                  : null),
+              "masterComponent=" + masterComponent,
+              (!_unsetProperties.contains(ResolvedComponent_Builder.Property.COMPONENT)
+                  ? "component=" + component
+                  : null))
+          + "}";
+    }
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
adoroszlai@apache.org.

[ambari] 03/03: AMBARI-14714. Fix unit tests after merge

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit 4c8f4f66016d606096eb6d67a7e4cdaad1be14cf
Author: Doroszlai, Attila <ad...@apache.org>
AuthorDate: Wed Mar 21 23:25:36 2018 +0100

    AMBARI-14714. Fix unit tests after merge
---
 .../controller/AmbariManagementControllerImpl.java |  8 ++++----
 .../orm/dao/HostComponentDesiredStateDAO.java      | 23 +---------------------
 .../orm/dao/ServiceComponentDesiredStateDAO.java   |  8 ++++----
 .../ambari/server/orm/dao/ServiceConfigDAO.java    |  8 ++++----
 .../entities/HostComponentDesiredStateEntity.java  |  3 ---
 .../server/orm/entities/ServiceConfigEntity.java   |  2 +-
 .../apache/ambari/server/state/ConfigHelper.java   |  7 ++++---
 .../ambari/server/state/ServiceComponentImpl.java  |  8 --------
 .../ambari/server/state/cluster/ClusterImpl.java   |  4 ++--
 .../BlueprintConfigurationProcessorTest.java       |  2 ++
 .../StackUpgradeConfigurationMergeTest.java        | 10 ++++++++++
 .../apache/ambari/server/utils/StageUtilsTest.java | 10 ++++++----
 12 files changed, 38 insertions(+), 55 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 06ddc81..3b07476 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -448,10 +448,10 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     masterHostname =  InetAddress.getLocalHost().getCanonicalHostName();
     maintenanceStateHelper = injector.getInstance(MaintenanceStateHelper.class);
     kerberosHelper = injector.getInstance(KerberosHelper.class);
-    hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
-    serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
     m_metadataHolder = injector.getProvider(MetadataHolder.class);
     m_agentConfigsHolder = injector.getProvider(AgentConfigsHolder.class);
+    hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
+    serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
     if(configs != null)
     {
       if (configs.getApiSSLAuthentication()) {
@@ -841,7 +841,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   Set<ServiceComponentHostResponse> persistServiceComponentHosts(Set<ServiceComponentHostRequest> requests)
     throws AmbariException {
     Multimap<Cluster, ServiceComponentHost> schMap = ArrayListMultimap.create();
-    Map<Long, Map<String, List<String>>> serviceComponentNames = new HashMap<>();
+    Map<Long, Map<Long, List<String>>> serviceComponentNames = new HashMap<>();
     Map<Long, Map<String, Map<String, ServiceComponentDesiredStateEntity>>> serviceComponentDesiredStateEntities = new HashMap<>();
 
     for (ServiceComponentHostRequest request : requests) {
@@ -850,7 +850,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       ServiceComponent sc = s.getServiceComponent(
           request.getComponentName());
       serviceComponentNames.computeIfAbsent(sc.getClusterId(), c -> new HashMap<>())
-          .computeIfAbsent(sc.getServiceName(), h ->new ArrayList<>()).add(sc.getName());
+          .computeIfAbsent(sc.getServiceId(), h ->new ArrayList<>()).add(sc.getName());
     }
 
     List<ServiceComponentDesiredStateEntity> entities = serviceComponentDesiredStateDAO.findByNames(serviceComponentNames);
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
index 347a512..c0eb90b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
@@ -93,34 +93,13 @@ public class HostComponentDesiredStateDAO {
   @RequiresSession
   public HostComponentDesiredStateEntity findByIndex(Long componentId) {
     final TypedQuery<HostComponentDesiredStateEntity> query = entityManagerProvider.get()
-      .createNamedQuery("HostComponentDesiredStateEntity.findByIndexAndHost", HostComponentDesiredStateEntity.class);
+      .createNamedQuery("HostComponentDesiredStateEntity.findByIndex", HostComponentDesiredStateEntity.class);
 
     query.setParameter("id", componentId);
 
     return daoUtils.selectSingle(query);
   }
 
-  /**
-   * Retrieve the single Host Component Desired State for the given unique cluster, service, component, and host.
-   *
-   * @param clusterId Cluster ID
-   * @param serviceName Service Name
-   * @param componentName Component Name
-   * @return Return the Host Component Desired State entity that match the criteria.
-   */
-  @RequiresSession
-  public List<HostComponentDesiredStateEntity> findByIndex(Long clusterId, String serviceName,
-                                                     String componentName) {
-    final TypedQuery<HostComponentDesiredStateEntity> query = entityManagerProvider.get()
-      .createNamedQuery("HostComponentDesiredStateEntity.findByIndex", HostComponentDesiredStateEntity.class);
-
-    query.setParameter("clusterId", clusterId);
-    query.setParameter("serviceName", serviceName);
-    query.setParameter("componentName", componentName);
-
-    return daoUtils.selectList(query);
-  }
-
   @RequiresSession
   public List<HostComponentDesiredStateEntity> findByHostsAndCluster(Collection<Long> hostIds, Long clusterId) {
     final TypedQuery<HostComponentDesiredStateEntity> query = entityManagerProvider.get()
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
index 0cac5bc..b2b5803 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
@@ -147,7 +147,7 @@ public class ServiceComponentDesiredStateDAO {
    * @return all found entities according to input map.
    */
   @RequiresSession
-  public List<ServiceComponentDesiredStateEntity> findByNames(Map<Long, Map<String, List<String>>> serviceComponentDesiredStates) {
+  public List<ServiceComponentDesiredStateEntity> findByNames(Map<Long, Map<Long, List<String>>> serviceComponentDesiredStates) {
     if (MapUtils.isEmpty(serviceComponentDesiredStates)) {
       return Collections.emptyList();
     }
@@ -156,10 +156,10 @@ public class ServiceComponentDesiredStateDAO {
     Root<ServiceComponentDesiredStateEntity> desiredStates = cq.from(ServiceComponentDesiredStateEntity.class);
 
     List<Predicate> clusters = new ArrayList<>();
-    for (Map.Entry<Long, Map<String, List<String>>> cluster : serviceComponentDesiredStates.entrySet()) {
+    for (Map.Entry<Long, Map<Long, List<String>>> cluster : serviceComponentDesiredStates.entrySet()) {
       List<Predicate> services = new ArrayList<>();
-      for (Map.Entry<String, List<String>> service : cluster.getValue().entrySet()) {
-        services.add(cb.and(cb.equal(desiredStates.get("serviceName"), service.getKey()),
+      for (Map.Entry<Long, List<String>> service : cluster.getValue().entrySet()) {
+        services.add(cb.and(cb.equal(desiredStates.get("serviceId"), service.getKey()),
             desiredStates.get("componentName").in(service.getValue())));
       }
       clusters.add(cb.and(cb.equal(desiredStates.get("clusterId"), cluster.getKey()),
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java
index f8d5aa7..5c4a59e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java
@@ -162,18 +162,18 @@ public class ServiceConfigDAO {
    *  Gets the latest service config versions of default config group for a service
    * @param clusterId
    *          the cluster (not {@code null}).
-   * @param serviceName
-   *          Name of the service whose latest service config versions needs to be retrieved .
+   * @param serviceId
+   *          ID of the service whose latest service config versions needs to be retrieved
    * @return all default group service configurations for the cluster and service.
    */
   @RequiresSession
-  public ServiceConfigEntity getLastServiceConfigForServiceDefaultGroup(Long clusterId, String serviceName) {
+  public ServiceConfigEntity getLastServiceConfigForServiceDefaultGroup(Long clusterId, Long serviceId) {
     TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createNamedQuery(
         "ServiceConfigEntity.findLatestServiceConfigsByServiceDefaultGroup",
         ServiceConfigEntity.class);
 
     query.setParameter("clusterId", clusterId);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("serviceId", serviceId);
 
     return daoUtils.selectOne(query);
   }
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
index 5667805..0129efb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
@@ -68,9 +68,6 @@ import com.google.common.base.Objects;
   @NamedQuery(name = "HostComponentDesiredStateEntity.findByIndex", query =
     "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE hcds.id=:id"),
 
-  @NamedQuery(name = "HostComponentDesiredStateEntity.findByIndexAndHost", query =
-    "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE hcds.clusterId=:clusterId AND hcds.serviceName=:serviceName AND hcds.componentName=:componentName AND hcds.hostId=:hostId"),
-
   @NamedQuery(name = "HostComponentDesiredStateEntity.findByHostsAndCluster", query =
     "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE hcds.hostId IN :hostIds AND hcds.clusterId=:clusterId"),
 })
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigEntity.java
index 33e7c29..c5fa873 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigEntity.java
@@ -64,7 +64,7 @@ import javax.persistence.TableGenerator;
         query = "SELECT scv FROM ServiceConfigEntity scv WHERE scv.clusterId = :clusterId AND scv.serviceId = :serviceId AND (scv.groupId = null OR scv.groupId IN (SELECT cg.groupId from ConfigGroupEntity cg)) AND scv.version = (SELECT MAX(scv2.version) FROM ServiceConfigEntity scv2 WHERE (scv2.serviceId = :serviceId AND scv2.clusterId = :clusterId) AND (scv2.groupId = scv.groupId OR (scv2.groupId IS NULL AND scv.groupId IS NULL)))"),
     @NamedQuery(
         name = "ServiceConfigEntity.findLatestServiceConfigsByServiceDefaultGroup",
-        query = "SELECT scv FROM ServiceConfigEntity scv WHERE scv.clusterId = :clusterId AND scv.serviceName = :serviceName AND scv.groupId = null AND scv.version = (SELECT MAX(scv2.version) FROM ServiceConfigEntity scv2 WHERE (scv2.serviceName = :serviceName AND scv2.clusterId = :clusterId) AND scv2.groupId IS NULL)"),
+        query = "SELECT scv FROM ServiceConfigEntity scv WHERE scv.clusterId = :clusterId AND scv.serviceId = :serviceId AND scv.groupId = null AND scv.version = (SELECT MAX(scv2.version) FROM ServiceConfigEntity scv2 WHERE (scv2.serviceId = :serviceId AND scv2.clusterId = :clusterId) AND scv2.groupId IS NULL)"),
     @NamedQuery(
         name = "ServiceConfigEntity.findLatestServiceConfigsByCluster",
         query = "SELECT scv FROM ServiceConfigEntity scv WHERE scv.clusterId = :clusterId AND scv.serviceConfigId IN (SELECT MAX(scv1.serviceConfigId) FROM ServiceConfigEntity scv1 WHERE (scv1.clusterId = :clusterId) AND (scv1.groupId IS NULL) GROUP BY scv1.serviceId)") })
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
index 41c56b5..a51e5ee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
@@ -1625,12 +1625,13 @@ public class ConfigHelper {
    * @param currentServiceConfigEntity service config entity with populated current cluster configs
    * @param configGroupId id of config group contained changed configs. Can be null in case group is default
    * @param clusterId cluster id
-   * @param serviceName service name configs were changed for
+   * @param serviceId service name configs were changed for
    * @return map of type names to collections of properties' names were changed.
    */
   public Map<String, Collection<String>> getChangedConfigTypes(Cluster cluster,
                                                                 ServiceConfigEntity currentServiceConfigEntity,
-                                                                Long configGroupId, Long clusterId, String serviceName) {
+                                                                Long configGroupId, Long clusterId, Long serviceId
+  ) {
     ServiceConfigEntity previousServiceConfigEntity;
     List<ClusterConfigEntity> previousConfigEntities = new ArrayList<>();
     List<ClusterConfigEntity> currentConfigEntities = new ArrayList<>();
@@ -1646,7 +1647,7 @@ public class ConfigHelper {
     // Service config with custom group contains not all config types, so it is needed
     // to complement it with configs from default group
     previousServiceConfigEntity =
-        serviceConfigDAO.getLastServiceConfigForServiceDefaultGroup(clusterId, serviceName);
+        serviceConfigDAO.getLastServiceConfigForServiceDefaultGroup(clusterId, serviceId);
     if (previousServiceConfigEntity != null) {
       for (ClusterConfigEntity clusterConfigEntity : previousServiceConfigEntity.getClusterConfigEntities()) {
         // Add only configs not present yet
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
index c69de33..fb37ec7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.state;
 
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -179,13 +178,6 @@ public class ServiceComponentImpl implements ServiceComponent {
 
     updateComponentInfo();
 
-    List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findByIndex(
-        service.getClusterId(),
-        service.getName(),
-        serviceComponentDesiredStateEntity.getComponentName()
-    );
-
-
     for (HostComponentStateEntity hostComponentStateEntity : serviceComponentDesiredStateEntity.getHostComponentStateEntities()) {
 
       HostComponentDesiredStateEntity hostComponentDesiredStateEntity = hostComponentDesiredStateDAO.findByIndex(
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 9c153d6..1b909e1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -2083,7 +2083,7 @@ public class ClusterImpl implements Cluster {
       Map<String, Collection<String>> changedConfigs = configHelper.getChangedConfigTypes(this, serviceConfigEntity,
           configGroup == null ? null : configGroup.getId(),
           clusterId,
-          serviceConfigEntity.getServiceName());
+          serviceConfigEntity.getServiceId());
 
       long nextServiceConfigVersion = serviceConfigDAO.findNextServiceConfigVersion(clusterId,
         serviceId);
@@ -2423,7 +2423,7 @@ public class ClusterImpl implements Cluster {
       }
     }
     Map<String, Collection<String>> changedConfigs = configHelper.getChangedConfigTypes(this, serviceConfigEntity,
-        serviceConfigEntity.getGroupId(), clusterId, serviceConfigEntity.getServiceName());
+        serviceConfigEntity.getGroupId(), clusterId, serviceConfigEntity.getServiceId());
 
     ClusterEntity clusterEntity = getClusterEntity();
     long nextServiceConfigVersion = serviceConfigDAO.findNextServiceConfigVersion(
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
index 84e3593..7b42468 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
@@ -45,6 +45,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Stream;
 
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.AmbariServer;
@@ -164,6 +165,7 @@ public class BlueprintConfigurationProcessorTest extends EasyMockSupport {
     expect(stack.getVersion()).andReturn(STACK_VERSION).atLeastOnce();
     // return false for all components since for this test we don't care about the value
     expect(stack.isMasterComponent(anyObject())).andReturn(false).anyTimes();
+    expect(stack.getServicesForComponent(anyObject())).andAnswer(() -> Stream.empty()).anyTimes();
     expect(stack.getConfigurationPropertiesWithMetadata(anyObject(String.class), anyObject(String.class))).andReturn(Collections.emptyMap()).anyTimes();
 
     expect(serviceInfo.getRequiredProperties()).andReturn(Collections.emptyMap()).anyTimes();
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
index 9957ac0..0b643629 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
@@ -59,6 +59,7 @@ import org.apache.ambari.server.orm.dao.StageDAO;
 import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.ServiceConfigEntity;
+import org.apache.ambari.server.registry.RegistryManager;
 import org.apache.ambari.server.resources.RootLevelSettingsManagerFactory;
 import org.apache.ambari.server.scheduler.ExecutionScheduler;
 import org.apache.ambari.server.security.authorization.Users;
@@ -66,6 +67,7 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
 import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.ClusterSettingFactory;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.ConfigFactory;
@@ -78,6 +80,7 @@ import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentFactory;
 import org.apache.ambari.server.state.ServiceComponentHostFactory;
 import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.ServiceGroupFactory;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.UpgradeContext;
 import org.apache.ambari.server.state.UpgradeContextFactory;
@@ -89,7 +92,9 @@ import org.apache.ambari.server.state.stack.OsFamily;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.apache.ambari.server.testutils.PartialNiceMockBinder;
+import org.apache.ambari.server.topology.ComponentResolver;
 import org.apache.ambari.server.topology.PersistedState;
+import org.apache.ambari.server.topology.StackFactory;
 import org.apache.ambari.server.topology.tasks.ConfigureClusterTaskFactory;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
@@ -491,6 +496,11 @@ public class StackUpgradeConfigurationMergeTest extends EasyMockSupport {
       binder.bind(AuditLogger.class).toInstance(createNiceMock(AuditLoggerDefaultImpl.class));
       binder.bind(MetadataHolder.class).toInstance(createNiceMock(MetadataHolder.class));
       binder.bind(AgentConfigsHolder.class).toInstance(createNiceMock(AgentConfigsHolder.class));
+      binder.bind(ClusterSettingFactory.class).toInstance(createNiceMock(ClusterSettingFactory.class));
+      binder.bind(RegistryManager.class).toInstance(createNiceMock(RegistryManager.class));
+      binder.bind(ServiceGroupFactory.class).toInstance(createNiceMock(ServiceGroupFactory.class));
+      binder.bind(StackFactory.class).toInstance(createNiceMock(StackFactory.class));
+      binder.bind(ComponentResolver.class).toInstance(createNiceMock(ComponentResolver.class));
 
       binder.requestStaticInjection(UpgradeResourceProvider.class);
 
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
index 9a85a12..13d2a1b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
@@ -53,23 +53,24 @@ import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.mpack.MpackManagerFactory;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.registry.RegistryManager;
 import org.apache.ambari.server.resources.RootLevelSettingsManagerFactory;
 import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.ClusterSettingFactory;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceGroupFactory;
 import org.apache.ambari.server.state.UpgradeContextFactory;
 import org.apache.ambari.server.testutils.PartialNiceMockBinder;
 import org.apache.ambari.server.topology.ComponentResolver;
 import org.apache.ambari.server.topology.DefaultStackFactory;
-import org.apache.ambari.server.topology.PersistedState;
 import org.apache.ambari.server.topology.StackComponentResolver;
 import org.apache.ambari.server.topology.StackFactory;
 import org.apache.ambari.server.topology.TopologyManager;
@@ -112,14 +113,15 @@ public class StageUtilsTest extends EasyMockSupport {
         bind(AmbariMetaInfo.class).toInstance(createMock(AmbariMetaInfo.class));
         bind(TopologyManager.class).toInstance(createNiceMock(TopologyManager.class));
         bind(HostDAO.class).toInstance(createNiceMock(HostDAO.class));
-        bind(PersistedState.class).toInstance(createNiceMock(PersistedState.class));
         bind(HostRoleCommandDAO.class).toInstance(createNiceMock(HostRoleCommandDAO.class));
         bind(MpackManagerFactory.class).toInstance(createNiceMock(MpackManagerFactory.class));
-        bind(AmbariManagementController.class).toInstance(createNiceMock(AmbariManagementController.class));
         bind(RootLevelSettingsManagerFactory.class).toInstance(createNiceMock(RootLevelSettingsManagerFactory.class));
         bind(ComponentResolver.class).to(StackComponentResolver.class);
         bind(BlueprintValidator.class).to(BasicBlueprintValidator.class);
         bind(StackFactory.class).to(DefaultStackFactory.class);
+        bind(ClusterSettingFactory.class).toInstance(createNiceMock(ClusterSettingFactory.class));
+        bind(RegistryManager.class).toInstance(createNiceMock(RegistryManager.class));
+        bind(ServiceGroupFactory.class).toInstance(createNiceMock(ServiceGroupFactory.class));
         install(new FactoryModuleBuilder().build(ExecutionCommandWrapperFactory.class));
         install(new FactoryModuleBuilder().build(UpgradeContextFactory.class));
       }

-- 
To stop receiving notification emails like this one, please contact
adoroszlai@apache.org.