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

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

commit b1f8afdf5e646a03b1ae0fc0d52644f001871525
Merge: c210fe5 b211832
Author: Jayush Luniya <jluniya@HW11039.local>
AuthorDate: Sat Jul 7 01:56:34 2018 -0700

    Merge remote-tracking branch 'origin/trunk' into branch-feature-AMBARI-14714

 .../stackVersions/StackVersionsCreateCtrl.js       |   2 +-
 .../resources/ui/admin-web/app/views/sideNav.html  |   2 +-
 .../src/main/python/ambari_agent/FileCache.py      |   5 +-
 .../main/python/resource_management/core/sudo.py   |  14 +-
 .../model/inputconfig/impl/InputConfigGson.java    |   2 +-
 .../impl/MapFieldCopyDescriptorImpl.java           |   2 +-
 .../impl/MapFieldNameDescriptorImpl.java           |   8 +-
 .../impl/MapFieldValueDescriptorImpl.java          |   8 +-
 .../inputconfig/impl/PostMapValuesAdapter.java     |   8 +-
 .../ambari/logsearch/domain/StoryDataRegistry.java |  24 ++
 .../apache/ambari/logsearch/domain/WebClient.java  |  79 ++++
 .../ambari/logsearch/steps/LogSearchApiSteps.java  |  46 +--
 .../logsearch/steps/LogSearchConfigApiSteps.java   |  67 ++++
 .../logsearch/story/LogSearchBackendStories.java   |  15 +-
 .../backend/log_search_cofig_api_tests.story       |   9 +
 .../src/main/resources/alias_config.json           |   6 +-
 .../src/main/resources/filters.config.json         |  54 +--
 .../resources/samples/config/config_audit.json     |  52 +--
 .../model/common/LSServerMapFieldCopy.java         |   2 +-
 .../model/common/LSServerMapFieldName.java         |   2 +-
 .../model/common/LSServerMapFieldValue.java        |   2 +-
 .../LSServerPostMapValuesListDeserializer.java     |  20 +-
 ambari-logsearch/ambari-logsearch-web/.gitignore   |  21 ++
 .../src/mockdata/mock-data-get.ts                  |  28 +-
 .../shipper-conf/input.config-ambari.json          | 176 ++++-----
 .../logfeeder/shipper-conf/input.config-hdfs.json  |  52 +--
 .../logfeeder/shipper-conf/input.config-hst.json   |   2 +-
 ...ctionEvent.java => AmbariRuntimeException.java} |  39 +-
 .../server/agent/stomp/AgentConfigsHolder.java     |   7 +-
 .../server/agent/stomp/AgentHostDataHolder.java    |  74 ++--
 .../server/agent/stomp/AlertDefinitionsHolder.java |  40 ++-
 .../server/agent/stomp/HostLevelParamsHolder.java  |  76 ++--
 .../server/agent/stomp/dto/AlertCluster.java       |  45 ++-
 .../server/agent/stomp/dto/ClusterConfigs.java     |   7 -
 .../agent/stomp/dto/HostLevelParamsCluster.java    |   8 -
 .../server/agent/stomp/dto/HostRepositories.java   |   8 -
 .../api/resources/ClusterResourceDefinition.java   |   1 +
 .../ambari/server/controller/KerberosHelper.java   |  18 +-
 .../server/controller/KerberosHelperImpl.java      | 111 ++++--
 .../controller/UpdateConfigurationPolicy.java      | 116 ++++++
 .../controller/internal/HostResourceProvider.java  |   5 +-
 .../internal/UpgradeResourceProvider.java          | 139 ++++++--
 .../ambari/server/events/AgentActionEvent.java     |   6 +-
 .../server/events/AgentConfigsUpdateEvent.java     |  11 +-
 .../server/events/ExecutionCommandEvent.java       |  19 +-
 .../server/events/HostLevelParamsUpdateEvent.java  |  17 +-
 .../alerts/AlertDefinitionsUIUpdateListener.java   |   8 +-
 .../events/publishers/AgentCommandsPublisher.java  |  58 ++-
 .../AbstractPrepareKerberosServerAction.java       | 168 ++++++++-
 .../kerberos/CreateKeytabFilesServerAction.java    |   4 +-
 .../kerberos/KerberosServerAction.java             |  31 +-
 .../PrepareDisableKerberosServerAction.java        |   2 +-
 .../PrepareEnableKerberosServerAction.java         |   2 +-
 .../PrepareKerberosIdentitiesServerAction.java     |  27 +-
 .../stageutils/KerberosKeytabController.java       |  19 +-
 .../org/apache/ambari/server/state/Cluster.java    |   3 +
 .../org/apache/ambari/server/state/Clusters.java   |   4 +-
 .../apache/ambari/server/state/ConfigHelper.java   |   3 +-
 .../ambari/server/state/alert/AlertDefinition.java |  38 ++
 .../server/state/alert/AlertDefinitionHash.java    |  11 +-
 .../ambari/server/state/cluster/ClusterImpl.java   |  12 +-
 .../ambari/server/state/cluster/ClustersImpl.java  |   4 +-
 .../ambari/server/upgrade/UpgradeCatalog270.java   | 166 ++++++---
 .../src/main/python/ambari_server/setupSecurity.py |  53 +--
 .../package/templates/input.config-hive.json.j2    |   2 +-
 .../0.5.0/properties/input.config-ambari.json.j2   | 362 +++++++++----------
 .../package/templates/input.config-spark.json.j2   |   2 +-
 .../package/templates/input.config-spark2.json.j2  |   2 +-
 .../ambari/server/agent/HeartbeatTestHelper.java   |   5 +-
 .../ambari/server/agent/TestHeartbeatHandler.java  |  18 +-
 .../server/agent/stomp/AgentDataHolderTest.java    |  10 +-
 .../agent/stomp/AlertDefinitionsHolderTest.java    | 121 +++++++
 .../agent/stomp/HostLevelParamsHolderTest.java     | 118 ++++++
 .../AmbariCustomCommandExecutionHelperTest.java    |   6 +-
 .../AbstractPrepareKerberosServerActionTest.java   | 397 +++++++++++++++++++--
 .../server/upgrade/UpgradeCatalog270Test.java      |  12 +
 ambari-web/app/assets/test/tests.js                |   1 +
 .../app/mixins/wizard/assign_master_components.js  |   6 +-
 ambari-web/app/models/host.js                      |   2 +
 ambari-web/app/routes/main.js                      |  12 +-
 ambari-web/app/styles/hosts.less                   |   9 +
 ambari-web/app/styles/top-nav.less                 |   8 +-
 .../widgets/service_config_password_field.hbs      |  16 +-
 ambari-web/app/templates/main/host/details.hbs     |  13 +-
 ambari-web/app/utils/config.js                     |   6 +-
 ambari-web/app/views/common/controls_view.js       |   2 +-
 ambari-web/app/views/main/host/details.js          |   4 +-
 .../main/admin/federation/step1_controller_test.js | 142 ++++++++
 ambari-web/test/utils/config_test.js               |  18 +
 ambari-web/test/views/main/host/details_test.js    |  16 +-
 90 files changed, 2455 insertions(+), 923 deletions(-)

diff --cc 
ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolder.java
index 783ad4f,b309bbb..69fa512
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolder.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolder.java
@@@ -21,9 -23,13 +23,12 @@@ import java.util.SortedMap
  import java.util.TreeMap;
  
  import org.apache.ambari.server.AmbariException;
+ import org.apache.ambari.server.agent.CommandRepository;
+ import org.apache.ambari.server.agent.RecoveryConfig;
  import org.apache.ambari.server.agent.RecoveryConfigHelper;
  import org.apache.ambari.server.agent.stomp.dto.HostLevelParamsCluster;
+ import org.apache.ambari.server.agent.stomp.dto.HostRepositories;
  import org.apache.ambari.server.controller.AmbariManagementController;
 -import org.apache.ambari.server.events.ClusterComponentsRepoChangedEvent;
  import org.apache.ambari.server.events.HostLevelParamsUpdateEvent;
  import org.apache.ambari.server.events.MaintenanceModeEvent;
  import org.apache.ambari.server.events.ServiceComponentRecoveryChangedEvent;
diff --cc 
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 16b4636,287e1a5..2e2f988
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@@ -78,8 -81,12 +82,10 @@@ import org.apache.ambari.server.securit
  import org.apache.ambari.server.security.authorization.AuthorizationHelper;
  import org.apache.ambari.server.security.authorization.ResourceType;
  import org.apache.ambari.server.security.authorization.RoleAuthorization;
+ import 
org.apache.ambari.server.serveraction.kerberos.KerberosOperationException;
  import org.apache.ambari.server.state.Cluster;
  import org.apache.ambari.server.state.Clusters;
+ import org.apache.ambari.server.state.ConfigHelper;
 -import org.apache.ambari.server.state.Service;
 -import org.apache.ambari.server.state.ServiceComponent;
  import org.apache.ambari.server.state.StackId;
  import org.apache.ambari.server.state.UpgradeContext;
  import org.apache.ambari.server.state.UpgradeContextFactory;
@@@ -692,7 -726,9 +734,9 @@@ public class UpgradeResourceProvider ex
      Cluster cluster = upgradeContext.getCluster();
      Direction direction = upgradeContext.getDirection();
  
+     ConfigHelper configHelper = getManagementController().getConfigHelper();
+ 
 -    List<UpgradeGroupHolder> groups = s_upgradeHelper.createSequence(pack, 
upgradeContext);
 +    List<UpgradeGroupHolder> groups = 
s_upgradeHelper.createSequence(upgradeContext, upgradePlan);
  
      if (groups.isEmpty()) {
        throw new AmbariException("There are no groupings available");
@@@ -755,38 -813,94 +799,85 @@@
        List<UpgradeItemEntity> itemEntities = new ArrayList<>();
  
        for (StageWrapper wrapper : group.items) {
-         if (wrapper.getType() == StageWrapper.Type.SERVER_SIDE_ACTION) {
-           // !!! each stage is guaranteed to be of one type. but because there
-           // is a bug that prevents one stage with multiple tasks assigned for
-           // the same host, break them out into individual stages.
-           for (TaskWrapper taskWrapper : wrapper.getTasks()) {
-             Task task = taskWrapper.getTask();
--
-             if (upgradeContext.isManualVerificationAutoSkipped()
-                 && task.getType() == Task.Type.MANUAL) {
-               continue;
+         switch(wrapper.getType()) {
+           case SERVER_SIDE_ACTION:{
+             // !!! each stage is guaranteed to be of one type. but because 
there
+             // is a bug that prevents one stage with multiple tasks assigned 
for
+             // the same host, break them out into individual stages.
+             for (TaskWrapper taskWrapper : wrapper.getTasks()) {
 -              for (Task task : taskWrapper.getTasks()) {
 -                if (upgradeContext.isManualVerificationAutoSkipped()
 -                    && task.getType() == Task.Type.MANUAL) {
 -                  continue;
 -                }
 -
 -                UpgradeItemEntity itemEntity = new UpgradeItemEntity();
++              Task task = taskWrapper.getTask();
++              if (upgradeContext.isManualVerificationAutoSkipped()
++                  && task.getType() == Task.Type.MANUAL) {
++                continue;
++              }
+ 
 -                itemEntity.setText(wrapper.getText());
 -                itemEntity.setTasks(wrapper.getTasksJson());
 -                itemEntity.setHosts(wrapper.getHostsJson());
++              UpgradeItemEntity itemEntity = new UpgradeItemEntity();
++              itemEntity.setText(wrapper.getText());
++              itemEntity.setTasks(wrapper.getTasksJson());
++              itemEntity.setHosts(wrapper.getHostsJson());
+ 
 -                injectVariables(configHelper, cluster, itemEntity);
 -                if (makeServerSideStage(group, upgradeContext, 
effectiveStack, req,
 -                    itemEntity, (ServerSideActionTask) task, 
configUpgradePack)) {
 -                  itemEntities.add(itemEntity);
 -                }
++              injectVariables(configHelper, cluster, itemEntity);
++              if (makeServerSideStage(group, upgradeContext, null, req,
++                  itemEntity, (ServerSideActionTask) task, 
configUpgradePack)) {
++                itemEntities.add(itemEntity);
+               }
+             }
+             break;
+           }
+           case REGENERATE_KEYTABS: {
+             try {
+               // remmeber how many stages we had before adding keytab stuff
+               int stageCount = req.getStages().size();
+ 
+               // build a map of request properties which say to
+               //   - only regenerate missing tabs
+               //   - allow all tasks which fail to be retried (so the upgrade 
doesn't abort)
+               Map<String, String> requestProperties = new HashMap<>();
+               
requestProperties.put(SupportedCustomOperation.REGENERATE_KEYTABS.name().toLowerCase(),
 "missing");
+               requestProperties.put(KerberosHelper.ALLOW_RETRY, 
Boolean.TRUE.toString().toLowerCase());
+               
requestProperties.put(KerberosHelper.DIRECTIVE_CONFIG_UPDATE_POLICY, 
UpdateConfigurationPolicy.NEW_AND_IDENTITIES.name());
+ 
+               // add stages to the upgrade which will regenerate missing 
keytabs only
+               req = s_kerberosHelper.get().executeCustomOperations(cluster, 
requestProperties, req, null);
+ 
+               // for every stage which was added for kerberos stuff create an
+               // associated upgrade item for it
+               List<Stage> stages = req.getStages();
+               int newStageCount = stages.size();
+               for (int i = stageCount; i < newStageCount; i++) {
+                 Stage stage = stages.get(i);
+                 stage.setSkippable(group.skippable);
+                 
stage.setAutoSkipFailureSupported(group.supportsAutoSkipOnFailure);
+ 
+                 UpgradeItemEntity itemEntity = new UpgradeItemEntity();
+                 itemEntity.setStageId(stage.getStageId());
+                 itemEntity.setText(stage.getRequestContext());
+                 itemEntity.setTasks(wrapper.getTasksJson());
+                 itemEntity.setHosts(wrapper.getHostsJson());
+                 itemEntities.add(itemEntity);
+                 injectVariables(configHelper, cluster, itemEntity);
+               }
+             } catch (KerberosOperationException kerberosOperationException) {
+               throw new AmbariException("Unable to build keytab regeneration 
stage",
+                   kerberosOperationException);
              }
  
+             break;
+           }
+           default: {
              UpgradeItemEntity itemEntity = new UpgradeItemEntity();
- 
              itemEntity.setText(wrapper.getText());
              itemEntity.setTasks(wrapper.getTasksJson());
              itemEntity.setHosts(wrapper.getHostsJson());
+             itemEntities.add(itemEntity);
  
-             if (makeServerSideStage(group, upgradeContext, null, req,
-                 itemEntity, (ServerSideActionTask) task, configUpgradePack)) {
-               itemEntities.add(itemEntity);
-             }
+             injectVariables(configHelper, cluster, itemEntity);
+ 
+             // upgrade items match a stage
 -            createStage(group, upgradeContext, effectiveStack, req, 
itemEntity, wrapper);
++            createStage(group, upgradeContext, null, req, itemEntity, 
wrapper);
+ 
+             break;
            }
-         } else {
-           UpgradeItemEntity itemEntity = new UpgradeItemEntity();
-           itemEntity.setText(wrapper.getText());
-           itemEntity.setTasks(wrapper.getTasksJson());
-           itemEntity.setHosts(wrapper.getHostsJson());
-           itemEntities.add(itemEntity);
- 
-           // upgrade items match a stage
-           createStage(group, upgradeContext, null, req, itemEntity, wrapper);
          }
        }
  
diff --cc 
ambari-server/src/main/java/org/apache/ambari/server/events/publishers/AgentCommandsPublisher.java
index c4fb497,c64131d..c549752
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/AgentCommandsPublisher.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/AgentCommandsPublisher.java
@@@ -33,6 -34,6 +34,8 @@@ import java.util.List
  import java.util.Map;
  import java.util.Set;
  import java.util.TreeMap;
++import java.util.function.Function;
++import java.util.stream.Collectors;
  
  import org.apache.ambari.server.AmbariException;
  import org.apache.ambari.server.agent.AgentCommand;
@@@ -248,4 -257,32 +259,33 @@@ public class AgentCommandsPublisher 
        ec.setKerberosCommandParams(kcp);
      }
    }
+ 
+   private Map<String, Collection<String>> adjustServiceComponentFilter(String 
clusterName, Map<String, ? extends Collection<String>> serviceComponentFilter) 
throws AmbariException {
+     Map<String, Collection<String>> adjustedFilter = new HashMap<>();
+     Cluster cluster = clusters.getCluster(clusterName);
+ 
 -    Map<String, Service> installedServices = (cluster == null) ? null : 
cluster.getServices();
++    Map<String, Service> installedServices = (cluster == null) ? null : 
cluster.getServices().stream().collect(
++      Collectors.toMap(Service::getName, Function.identity()));
+ 
+     if(!MapUtils.isEmpty(installedServices)) {
+       if (serviceComponentFilter != null) {
+         // prune off services that are not installed, or considered installed 
- like AMBARI
+         for(Map.Entry<String, ? extends Collection<String>> entry: 
serviceComponentFilter.entrySet()) {
+           String serviceName = entry.getKey();
+ 
+           if(installedServices.containsKey(serviceName)) {
+             adjustedFilter.put(serviceName, entry.getValue());
+           }
+         }
+       } else {
+         // return only the set of installed services
+         for(String serviceName: installedServices.keySet()) {
+           // Add an entry to indicate the service and all of it's components 
should be considered
+           adjustedFilter.put(serviceName, Collections.singletonList("*"));
+         }
+       }
+     }
+ 
+     return adjustedFilter;
+   }
  }
diff --cc 
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 0844aa0,821bdbc..048ab3a
--- 
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
@@@ -2796,18 -2246,7 +2796,8 @@@ public class ClusterImpl implements Clu
  
    @Override
    public Collection<Host> getHosts() {
-     Map<String, Host> hosts;
- 
-     try {
-       //todo: why the hell does this method throw AmbariException???
-       //todo: this is ridiculous that I need to get hosts for this cluster 
from Clusters!!!
-       //todo: should I getHosts using the same logic as the other getHosts 
call?  At least that doesn't throw AmbariException.
-       hosts = clusters.getHostsForCluster(clusterName);
-     } catch (AmbariException e) {
-       //todo: in what conditions is AmbariException thrown?
-       throw new RuntimeException("Unable to get hosts for cluster: " + 
clusterName, e);
-     }
 -    return clusters.getHostsForCluster(clusterName).values();
++    Map<String, Host> hosts = clusters.getHostsForCluster(clusterName);
 +    return hosts == null ? Collections.emptyList() : hosts.values();
    }
  
    private ClusterHealthReport getClusterHealthReport(
diff --cc 
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
index d77a1dc,43bbc87..c1689bb
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
@@@ -1079,41 -1075,107 +1070,108 @@@ public class UpgradeCatalog270 extends 
      if (MapUtils.isEmpty(clusterMap))
        return;
  
-     ServiceConfigDAO serviceConfigDAO = 
injector.getInstance(ServiceConfigDAO.class);
-     for (ServiceConfigEntity serviceConfigEntity : 
serviceConfigDAO.findAll()) {
-       if (AMBARI_INFRA_OLD_NAME.equals(serviceConfigEntity.getServiceName())) 
{
-         serviceConfigEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
-         serviceConfigDAO.merge(serviceConfigEntity);
-       }
-     }
+     EntityManager entityManager = getEntityManagerProvider().get();
+     ClusterServiceDAO clusterServiceDAO = 
injector.getInstance(ClusterServiceDAO.class);
+     HostComponentStateDAO hostComponentStateDAO = 
injector.getInstance(HostComponentStateDAO.class);
+     HostComponentDesiredStateDAO hostComponentDesiredStateDAO = 
injector.getInstance(HostComponentDesiredStateDAO.class);
+     ServiceDesiredStateDAO serviceDesiredStateDAO = 
injector.getInstance(ServiceDesiredStateDAO.class);
+     ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = 
injector.getInstance(ServiceComponentDesiredStateDAO.class);
  
-     AlertDefinitionDAO alertDefinitionDAO = 
injector.getInstance(AlertDefinitionDAO.class);
      for (final Cluster cluster : clusterMap.values()) {
-       for (AlertDefinitionEntity alertDefinitionEntity : 
alertDefinitionDAO.findByService(cluster.getClusterId(), 
AMBARI_INFRA_OLD_NAME)) {
-         alertDefinitionEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
-         alertDefinitionDAO.merge(alertDefinitionEntity);
 -      ClusterServiceEntityPK clusterServiceEntityPK = new 
ClusterServiceEntityPK();
 -      clusterServiceEntityPK.setClusterId(cluster.getClusterId());
 -      clusterServiceEntityPK.setServiceName(AMBARI_INFRA_OLD_NAME);
 -      ClusterServiceEntity clusterServiceEntity = 
clusterServiceDAO.findByPK(clusterServiceEntityPK);
 -      if (clusterServiceEntity == null)
 -        continue;
 -
 -      List<ServiceComponentDesiredStateEntity> 
serviceComponentDesiredStateEntities =
 -              new 
ArrayList<>(clusterServiceEntity.getServiceComponentDesiredStateEntities());
 -      ServiceDesiredStateEntity serviceDesiredStateEntity = 
clusterServiceEntity.getServiceDesiredStateEntity();
 -      List<HostComponentStateEntity> hostComponentStateEntities = 
hostComponentStateDAO.findByService(AMBARI_INFRA_OLD_NAME);
 -      List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities 
= new ArrayList<>();
 -      for (ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity : 
clusterServiceEntity.getServiceComponentDesiredStateEntities()) {
 -        hostComponentDesiredStateEntities.addAll(
 -                
hostComponentDesiredStateDAO.findByIndex(cluster.getClusterId(), 
AMBARI_INFRA_OLD_NAME, serviceComponentDesiredStateEntity.getComponentName()));
 -      }
 -
 -      for (HostComponentStateEntity hostComponentStateEntity : 
hostComponentStateEntities) {
 -        hostComponentStateDAO.remove(hostComponentStateEntity);
 -        entityManager.detach(hostComponentStateEntity);
 -        hostComponentStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
 -      }
 -
 -      for (HostComponentDesiredStateEntity hostComponentDesiredStateEntity : 
hostComponentDesiredStateEntities) {
 -        hostComponentDesiredStateDAO.remove(hostComponentDesiredStateEntity);
 -        entityManager.detach(hostComponentDesiredStateEntity);
 -        hostComponentDesiredStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
 -      }
 -
 -      clusterServiceEntity.getServiceComponentDesiredStateEntities().clear();
 -      for (ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity : serviceComponentDesiredStateEntities) {
 -        
serviceComponentDesiredStateDAO.remove(serviceComponentDesiredStateEntity);
 -        entityManager.detach(serviceComponentDesiredStateEntity);
 -        
serviceComponentDesiredStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
 -      }
 -
 -      if (serviceDesiredStateEntity != null) {
 -        clusterServiceEntity.setServiceDesiredStateEntity(null);
 -        serviceDesiredStateDAO.remove(serviceDesiredStateEntity);
 -        entityManager.detach(serviceDesiredStateEntity);
 -        serviceDesiredStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
--      }
 -
 -      clusterServiceDAO.remove(clusterServiceEntity);
 -      entityManager.detach(clusterServiceEntity);
 -
 -      clusterServiceEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
 -      
clusterServiceEntity.setServiceDesiredStateEntity(serviceDesiredStateEntity);
 -      clusterServiceDAO.create(clusterServiceEntity);
 -
 -      for (ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity : serviceComponentDesiredStateEntities)
 -        
serviceComponentDesiredStateDAO.create(serviceComponentDesiredStateEntity);
 -      for (HostComponentStateEntity hostComponentStateEntity : 
hostComponentStateEntities)
 -        hostComponentStateDAO.create(hostComponentStateEntity);
 -      for (HostComponentDesiredStateEntity hostComponentDesiredStateEntity : 
hostComponentDesiredStateEntities)
 -        hostComponentDesiredStateDAO.create(hostComponentDesiredStateEntity);
++      // TODO: [AMP] Revisit logic
++//      ClusterServiceEntity clusterServiceEntity = 
clusterServiceDAO.findByPK(cluster.getClusterId());
++//      if (clusterServiceEntity == null)
++//        continue;
++//
++//      List<ServiceComponentDesiredStateEntity> 
serviceComponentDesiredStateEntities =
++//              new 
ArrayList<>(clusterServiceEntity.getServiceComponentDesiredStateEntities());
++//      ServiceDesiredStateEntity serviceDesiredStateEntity = 
clusterServiceEntity.getServiceDesiredStateEntity();
++//
++//      List<HostComponentStateEntity> hostComponentStateEntities = 
hostComponentStateDAO.findByService(AMBARI_INFRA_OLD_NAME);
++//      List<HostComponentDesiredStateEntity> 
hostComponentDesiredStateEntities = new ArrayList<>();
++//
++//
++//      for (ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity : 
clusterServiceEntity.getServiceComponentDesiredStateEntities()) {
++//        hostComponentDesiredStateEntities.addAll(
++//                
hostComponentDesiredStateDAO.findByIndex(cluster.getClusterId(), 
AMBARI_INFRA_OLD_NAME, serviceComponentDesiredStateEntity.getComponentName()));
++//      }
++//
++//      for (HostComponentStateEntity hostComponentStateEntity : 
hostComponentStateEntities) {
++//        hostComponentStateDAO.remove(hostComponentStateEntity);
++//        entityManager.detach(hostComponentStateEntity);
++//        hostComponentStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
++//      }
++//
++//      for (HostComponentDesiredStateEntity hostComponentDesiredStateEntity 
: hostComponentDesiredStateEntities) {
++//        
hostComponentDesiredStateDAO.remove(hostComponentDesiredStateEntity);
++//        entityManager.detach(hostComponentDesiredStateEntity);
++//        
hostComponentDesiredStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
++//      }
++//
++//      
clusterServiceEntity.getServiceComponentDesiredStateEntities().clear();
++//      for (ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity : serviceComponentDesiredStateEntities) {
++//        
serviceComponentDesiredStateDAO.remove(serviceComponentDesiredStateEntity);
++//        entityManager.detach(serviceComponentDesiredStateEntity);
++//        
serviceComponentDesiredStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
++//      }
++//
++//      if (serviceDesiredStateEntity != null) {
++//        clusterServiceEntity.setServiceDesiredStateEntity(null);
++//        serviceDesiredStateDAO.remove(serviceDesiredStateEntity);
++//        entityManager.detach(serviceDesiredStateEntity);
++//        serviceDesiredStateEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
++//      }
++//
++//      clusterServiceDAO.remove(clusterServiceEntity);
++//      entityManager.detach(clusterServiceEntity);
++//
++//      clusterServiceEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
++//      
clusterServiceEntity.setServiceDesiredStateEntity(serviceDesiredStateEntity);
++//      clusterServiceDAO.create(clusterServiceEntity);
++//
++//      for (ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity : serviceComponentDesiredStateEntities)
++//        
serviceComponentDesiredStateDAO.create(serviceComponentDesiredStateEntity);
++//      for (HostComponentStateEntity hostComponentStateEntity : 
hostComponentStateEntities)
++//        hostComponentStateDAO.create(hostComponentStateEntity);
++//      for (HostComponentDesiredStateEntity hostComponentDesiredStateEntity 
: hostComponentDesiredStateEntities)
++//        
hostComponentDesiredStateDAO.create(hostComponentDesiredStateEntity);
      }
  
-     AlertDispatchDAO alertDispatchDAO = 
injector.getInstance(AlertDispatchDAO.class);
-     for (AlertGroupEntity alertGroupEntity : 
alertDispatchDAO.findAllGroups()) {
-       if (AMBARI_INFRA_OLD_NAME.equals(alertGroupEntity.getServiceName())) {
-         alertGroupEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
-         alertGroupEntity.setGroupName(AMBARI_INFRA_NEW_NAME);
-         alertDispatchDAO.merge(alertGroupEntity);
+     executeInTransaction(() -> {
+       TypedQuery<ServiceConfigEntity> serviceConfigUpdate = 
entityManager.createQuery(
+               "UPDATE ServiceConfigEntity SET serviceName = :newServiceName 
WHERE serviceName = :oldServiceName", ServiceConfigEntity.class);
+       serviceConfigUpdate.setParameter("newServiceName", 
AMBARI_INFRA_NEW_NAME);
+       serviceConfigUpdate.setParameter("oldServiceName", 
AMBARI_INFRA_OLD_NAME);
+       serviceConfigUpdate.executeUpdate();
+     });
+ 
+     executeInTransaction(() -> {
+       for (final Cluster cluster : clusterMap.values()) {
+         TypedQuery<AlertDefinitionEntity> alertDefinitionUpdate = 
entityManager.createQuery(
+                 "UPDATE AlertDefinitionEntity SET serviceName = 
:newServiceName WHERE serviceName = :oldServiceName AND clusterId = 
:clusterId", AlertDefinitionEntity.class);
+         alertDefinitionUpdate.setParameter("clusterId", 
cluster.getClusterId());
+         alertDefinitionUpdate.setParameter("newServiceName", 
AMBARI_INFRA_NEW_NAME);
+         alertDefinitionUpdate.setParameter("oldServiceName", 
AMBARI_INFRA_OLD_NAME);
+         alertDefinitionUpdate.executeUpdate();
        }
-     }
- 
-     AlertsDAO alertsDAO = injector.getInstance(AlertsDAO.class);
-     for (AlertHistoryEntity alertHistoryEntity : alertsDAO.findAll()) {
-       if (AMBARI_INFRA_OLD_NAME.equals(alertHistoryEntity.getServiceName())) {
-         alertHistoryEntity.setServiceName(AMBARI_INFRA_NEW_NAME);
-         alertsDAO.merge(alertHistoryEntity);
-       }
-     }
+     });
+ 
+     executeInTransaction(() -> {
+       TypedQuery<AlertGroupEntity> alertGroupUpdate = 
entityManager.createQuery("UPDATE AlertGroupEntity SET serviceName = 
:newServiceName, groupName = :newServiceName WHERE serviceName = 
:oldServiceName", AlertGroupEntity.class);
+       alertGroupUpdate.setParameter("newServiceName", AMBARI_INFRA_NEW_NAME);
+       alertGroupUpdate.setParameter("oldServiceName", AMBARI_INFRA_OLD_NAME);
+       alertGroupUpdate.executeUpdate();
+     });
+ 
+     executeInTransaction(() -> {
+       TypedQuery<AlertHistoryEntity> alertHistoryUpdate = 
entityManager.createQuery("UPDATE AlertHistoryEntity SET serviceName = 
:newServiceName WHERE serviceName = :oldServiceName", AlertHistoryEntity.class);
+       alertHistoryUpdate.setParameter("newServiceName", 
AMBARI_INFRA_NEW_NAME);
+       alertHistoryUpdate.setParameter("oldServiceName", 
AMBARI_INFRA_OLD_NAME);
+       alertHistoryUpdate.executeUpdate();
+     });
  
      // Force the clusters object to reload to ensure the renamed service is 
accounted for
-     
getEntityManagerProvider().get().getEntityManagerFactory().getCache().evictAll();
+     entityManager.getEntityManagerFactory().getCache().evictAll();
      clusters.invalidateAllClusters();
    }
  
diff --cc 
ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index 424e652,75d5a7a..cfb786c
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@@ -1414,6 -1412,12 +1414,12 @@@ public class TestHeartbeatHandler 
      List<Map<String, String>> kcp;
      Map<String, String> properties;
  
+     Cluster cluster = heartbeatTestHelper.getDummyCluster();
+     Service hdfs = addService(cluster, HDFS);
 -    hdfs.addServiceComponent(DATANODE);
 -    hdfs.addServiceComponent(NAMENODE);
 -    hdfs.addServiceComponent(SECONDARY_NAMENODE);
++    hdfs.addServiceComponent(DATANODE, DATANODE);
++    hdfs.addServiceComponent(NAMENODE, NAMENODE);
++    hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE);
+ 
      kcp = testInjectKeytabSetKeytab("c6403.ambari.apache.org");
      Assert.assertNotNull(kcp);
      Assert.assertEquals(1, kcp.size());
@@@ -1450,6 -1454,12 +1456,12 @@@
  
    @Test
    public void testInjectKeytabNotApplicableHost() throws Exception {
+     Cluster cluster = heartbeatTestHelper.getDummyCluster();
+     Service hdfs = addService(cluster, HDFS);
 -    hdfs.addServiceComponent(DATANODE);
 -    hdfs.addServiceComponent(NAMENODE);
 -    hdfs.addServiceComponent(SECONDARY_NAMENODE);
++    hdfs.addServiceComponent(DATANODE, DATANODE);
++    hdfs.addServiceComponent(NAMENODE, NAMENODE);
++    hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE);
+ 
      List<Map<String, String>> kcp;
      kcp = testInjectKeytabSetKeytab("c6401.ambari.apache.org");
      Assert.assertNotNull(kcp);
diff --cc 
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index ba76b80,528e589..65abb4e
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@@ -153,15 -141,15 +153,15 @@@ public class AmbariCustomCommandExecuti
      ambariManagementController = 
injector.getInstance(AmbariManagementController.class);
      clusters = injector.getInstance(Clusters.class);
  
 -    
EasyMock.expect(configHelper.getPropertyValuesWithPropertyType(EasyMock.anyObject(StackId.class),
 +    
expect(configHelper.getPropertiesWithPropertyType(EasyMock.anyObject(StackId.class),
          EasyMock.anyObject(PropertyInfo.PropertyType.class),
          EasyMock.anyObject(Cluster.class),
 -        EasyMock.anyObject(Map.class))).andReturn(Collections.EMPTY_SET);
 +        EasyMock.anyObject(Map.class))).andReturn(Collections.emptyMap());
  
-     expect(configHelper.getHostActualConfigs(EasyMock.anyLong())).andReturn(
-         new AgentConfigsUpdateEvent(new TreeMap<>())).anyTimes();
+     
EasyMock.expect(configHelper.getHostActualConfigs(EasyMock.anyLong())).andReturn(
+         new AgentConfigsUpdateEvent(null, new TreeMap<>())).anyTimes();
  
 -    EasyMock.replay(configHelper);
 +    replay(configHelper);
  
      
StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
      StageUtils.setConfiguration(injector.getInstance(Configuration.class));
diff --cc 
ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerActionTest.java
index 586b023,47ccef5..4be2680
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerActionTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerActionTest.java
@@@ -130,10 -269,11 +269,11 @@@ public class AbstractPrepareKerberosSer
        put(zookeeperService, null);
      }};
  
-     
expect(kerberosDescriptor.getProperties()).andReturn(descriptorProperties).atLeastOnce();
-     
expect(kerberosIdentityDataFileWriterFactory.createKerberosIdentityDataFileWriter((File)anyObject())).andReturn(kerberosIdentityDataFileWriter);
+     KerberosIdentityDataFileWriterFactory 
kerberosIdentityDataFileWriterFactory = 
injector.getInstance(KerberosIdentityDataFileWriterFactory.class);
+     
expect(kerberosIdentityDataFileWriterFactory.createKerberosIdentityDataFileWriter(anyObject(File.class))).andReturn(kerberosIdentityDataFileWriter);
+ 
      // it's important to pass a copy of clusterServices
 -    expect(cluster.getServices()).andReturn(new 
HashMap<>(clusterServices)).atLeastOnce();
 +    expect(cluster.getServicesByName()).andReturn(new 
HashMap<>(clusterServices)).atLeastOnce();
  
      
expect(serviceComponentHostHDFS.getHostName()).andReturn(hostName).atLeastOnce();
      
expect(serviceComponentHostHDFS.getServiceName()).andReturn(hdfsService).atLeastOnce();
diff --cc ambari-web/app/assets/test/tests.js
index 078f14c,0be62bf..3311b5b
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@@ -66,8 -66,10 +66,9 @@@ var files = 
    'test/controllers/main/admin/kerberos/step7_controller_test',
    'test/controllers/main/admin/kerberos/step8_controller_test',
    'test/controllers/main/admin/service_auto_start_test',
 -  'test/controllers/main/admin/stack_and_upgrade_controller_test',
    'test/controllers/main/admin/stack_upgrade_history_controller_test',
    'test/controllers/main/admin/serviceAccounts_controller_test',
+   'test/controllers/main/admin/federation/step1_controller_test',
    'test/controllers/main/admin/highAvailability_controller_test',
    'test/controllers/main/admin/highAvailability/progress_controller_test',
    
'test/controllers/main/admin/highAvailability/progress_popup_controller_test',
diff --cc ambari-web/app/mixins/wizard/assign_master_components.js
index ecdb9c3,25bf86c..518959c
--- a/ambari-web/app/mixins/wizard/assign_master_components.js
+++ b/ambari-web/app/mixins/wizard/assign_master_components.js
@@@ -1199,17 -1180,16 +1199,17 @@@ App.AssignMasterComponents = Em.Mixin.c
      }
  
      this.set('validationInProgress', true);
 -
 -    // load recommendations with partial request
 +    
      this.getRecommendedHosts({
        hosts: hostNames,
 +      mpack_instances: mpackInstances,
        components: this.getCurrentComponentHostMap()
-     }).then(function() {
+     }).done(function() {
        self.validateSelectedHostComponents({
          hosts: hostNames,
 +        mpack_instances: mpackInstances,
          blueprint: self.get('recommendations')
-       }).then(function() {
+       }).always(function() {
          if (callback) {
            callback();
          }

Reply via email to