ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject [11/50] ambari git commit: AMBARI-18976. Config History request execution time depends on config versions count. (mpapirkovskyy)
Date Thu, 01 Dec 2016 08:13:54 GMT
AMBARI-18976. Config History request execution time depends on config versions count. (mpapirkovskyy)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/911b9177
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/911b9177
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/911b9177

Branch: refs/heads/branch-feature-AMBARI-18901
Commit: 911b917783d66a44958e791e49d76b755d943f85
Parents: 568d1e6
Author: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Authored: Wed Nov 23 19:03:14 2016 +0200
Committer: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Committed: Mon Nov 28 18:42:05 2016 +0200

----------------------------------------------------------------------
 .../internal/ClusterControllerImpl.java         |  2 +-
 .../ServiceConfigVersionResourceProvider.java   |  3 +-
 .../logging/LoggingSearchPropertyProvider.java  | 11 ++++-
 .../ambari/server/orm/dao/ClusterDAO.java       | 24 +++++++++++
 .../ambari/server/orm/dao/ServiceConfigDAO.java | 13 +++---
 .../orm/entities/ClusterConfigEntity.java       |  7 +++-
 .../entities/ClusterConfigMappingEntity.java    |  6 +++
 .../orm/entities/ServiceConfigEntity.java       |  5 ++-
 .../server/state/cluster/ClusterImpl.java       | 42 +++++---------------
 9 files changed, 67 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
index 32bed7b..c752e80 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
@@ -858,7 +858,7 @@ public class ClusterControllerImpl implements ClusterController {
       if (compVal == 0) {
         Schema schema = getSchema(resourceType);
 
-        for (Type type : Type.values()) {
+        for (Type type : schema.getKeyTypes()) {
           String keyPropertyId = schema.getKeyPropertyId(type);
           if (keyPropertyId != null) {
             compVal = compareValues(resource1.getPropertyValue(keyPropertyId),

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceConfigVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceConfigVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceConfigVersionResourceProvider.java
index 2edbe9b..e5ca389 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceConfigVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceConfigVersionResourceProvider.java
@@ -91,8 +91,9 @@ public class ServiceConfigVersionResourceProvider extends
     PROPERTY_IDS.add(SERVICE_CONFIG_VERSION_IS_COMPATIBLE_PROPERTY_ID);
 
     // keys
-    KEY_PROPERTY_IDS.put(Resource.Type.ServiceConfigVersion,SERVICE_CONFIG_VERSION_SERVICE_NAME_PROPERTY_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.Service,SERVICE_CONFIG_VERSION_SERVICE_NAME_PROPERTY_ID);
     KEY_PROPERTY_IDS.put(Resource.Type.Cluster,SERVICE_CONFIG_VERSION_CLUSTER_NAME_PROPERTY_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.ServiceConfigVersion,SERVICE_CONFIG_VERSION_PROPERTY_ID);
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
index d9db290..16788ed 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
@@ -39,8 +39,10 @@ import org.apache.log4j.Logger;
 
 import java.util.Collections;
 import java.util.EnumSet;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -73,7 +75,7 @@ public class LoggingSearchPropertyProvider implements PropertyProvider {
 
   @Override
   public Set<Resource> populateResources(Set<Resource> resources, Request request,
Predicate predicate) throws SystemException {
-
+    Map<String, Boolean> isLogSearchRunning = new HashMap<>();
     for (Resource resource : resources) {
       // obtain the required identifying properties on the host component resource
       final String componentName = (String)resource.getPropertyValue(PropertyHelper.getPropertyId("HostRoles",
"component_name"));
@@ -90,7 +92,12 @@ public class LoggingSearchPropertyProvider implements PropertyProvider
{
         continue;
       }
 
-      if (!logSearchServerRunning(clusterName)) {
+      Boolean isLogSearchRunningForSpecifiedCluster = isLogSearchRunning.get(clusterName);
+      if (isLogSearchRunningForSpecifiedCluster == null) {
+        isLogSearchRunningForSpecifiedCluster = logSearchServerRunning(clusterName);
+        isLogSearchRunning.put(clusterName, isLogSearchRunningForSpecifiedCluster);
+      }
+      if (!isLogSearchRunningForSpecifiedCluster) {
         continue;
       }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
index e93ac0e..b727c72 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
@@ -116,6 +116,18 @@ public class ClusterDAO {
   }
 
   @RequiresSession
+  public List<ClusterConfigEntity> getLatestClusterConfigsByTypes(Long clusterId, List<String>
types) {
+    TypedQuery<ClusterConfigEntity> query = entityManagerProvider.get().createNamedQuery(
+      "ClusterConfigEntity.findLatestClusterConfigsByTypes",
+      ClusterConfigEntity.class);
+
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("types", types);
+
+    return daoUtils.selectList(query);
+  }
+
+  @RequiresSession
   public ClusterConfigEntity findConfig(Long clusterId, String type, Long version) {
     CriteriaBuilder cb = entityManagerProvider.get().getCriteriaBuilder();
     CriteriaQuery<ClusterConfigEntity> cq = cb.createQuery(ClusterConfigEntity.class);
@@ -240,6 +252,18 @@ public class ClusterDAO {
     return daoUtils.selectList(query);
   }
 
+  @RequiresSession
+  public List<ClusterConfigMappingEntity> getLatestClusterConfigMappingsEntityByType(long
clusterId, String configType) {
+    TypedQuery<ClusterConfigMappingEntity> query = entityManagerProvider.get().createNamedQuery(
+      "ClusterConfigMappingEntity.findLatestClusterConfigMappingsByType",
+      ClusterConfigMappingEntity.class);
+
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("typeName", configType);
+
+    return daoUtils.selectList(query);
+  }
+
   /**
    * Gets selected mappings for provided config types
    * @param clusterId cluster id

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java
----------------------------------------------------------------------
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 2cbee8d..212a9f0 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
@@ -115,14 +115,13 @@ public class ServiceConfigDAO {
 
   @RequiresSession
   public List<ServiceConfigEntity> getLastServiceConfigs(Long clusterId) {
-    TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().
-      createQuery("SELECT scv FROM ServiceConfigEntity scv " +
-        "WHERE scv.clusterId = ?1 AND scv.createTimestamp = (" +
-        "SELECT MAX(scv2.createTimestamp) FROM ServiceConfigEntity scv2 " +
-        "WHERE scv2.serviceName = scv.serviceName AND scv2.clusterId = ?1 AND scv2.groupId
IS NULL)",
-        ServiceConfigEntity.class);
+    TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createNamedQuery(
+      "ServiceConfigEntity.findLatestServiceConfigsByCluster",
+      ServiceConfigEntity.class);
 
-    return daoUtils.selectList(query, clusterId);
+    query.setParameter("clusterId", clusterId);
+
+    return daoUtils.selectList(query);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
index bf0faee..937e872 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
@@ -55,7 +55,12 @@ import javax.persistence.UniqueConstraint;
     @NamedQuery(name = "ClusterConfigEntity.findClusterConfigMappingsByStack",
       query = "SELECT mapping FROM ClusterConfigMappingEntity mapping " +
         "JOIN ClusterConfigEntity config ON mapping.typeName = config.type AND mapping.tag
= config.tag " +
-        "WHERE mapping.clusterId = :clusterId AND config.stack = :stack")
+        "WHERE mapping.clusterId = :clusterId AND config.stack = :stack"),
+    @NamedQuery(name = "ClusterConfigEntity.findLatestClusterConfigsByTypes",
+      query = "SELECT cc FROM ClusterConfigEntity cc " +
+        "JOIN ClusterConfigMappingEntity ccm " +
+        "ON cc.clusterId = ccm.clusterId AND cc.type = ccm.typeName AND cc.tag = ccm.tag
" +
+        "WHERE cc.clusterId = :clusterId AND ccm.selectedInd > 0 AND ccm.typeName IN :types")
 })
 
 public class ClusterConfigEntity {

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigMappingEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigMappingEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigMappingEntity.java
index c3c3e9e..04c6030 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigMappingEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigMappingEntity.java
@@ -23,6 +23,8 @@ import javax.persistence.Id;
 import javax.persistence.IdClass;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.Table;
 
 /**
@@ -31,6 +33,10 @@ import javax.persistence.Table;
 @Table(name = "clusterconfigmapping")
 @Entity
 @IdClass(ClusterConfigMappingEntityPK.class)
+@NamedQueries({
+  @NamedQuery(name = "ClusterConfigMappingEntity.findLatestClusterConfigMappingsByType",
+    query = "SELECT mapping FROM ClusterConfigMappingEntity mapping WHERE mapping.clusterId
= :clusterId AND mapping.selectedInd > 0 AND mapping.typeName = :typeName")})
+
 public class ClusterConfigMappingEntity {
 
   @Id

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigEntity.java
----------------------------------------------------------------------
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 7c28835..0df6f68 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
@@ -51,7 +51,8 @@ import javax.persistence.TableGenerator;
     @NamedQuery(name = "ServiceConfigEntity.findNextServiceConfigVersion", query = "SELECT
COALESCE(MAX(serviceConfig.version), 0) + 1 AS nextVersion FROM ServiceConfigEntity serviceConfig
WHERE serviceConfig.serviceName=:serviceName AND serviceConfig.clusterId=:clusterId"),
     @NamedQuery(name = "ServiceConfigEntity.findAllServiceConfigsByStack", query = "SELECT
serviceConfig FROM ServiceConfigEntity serviceConfig WHERE serviceConfig.clusterId=:clusterId
AND serviceConfig.stack=:stack"),
     @NamedQuery(name = "ServiceConfigEntity.findLatestServiceConfigsByStack", query = "SELECT
serviceConfig FROM ServiceConfigEntity serviceConfig WHERE serviceConfig.clusterId = :clusterId
AND serviceConfig.version = (SELECT MAX(serviceConfig2.version) FROM ServiceConfigEntity serviceConfig2
WHERE serviceConfig2.clusterId=:clusterId AND serviceConfig2.stack=:stack AND serviceConfig2.serviceName
= serviceConfig.serviceName)"),
-    @NamedQuery(name = "ServiceConfigEntity.findLatestServiceConfigsByService", query = "SELECT
scv FROM ServiceConfigEntity scv WHERE scv.clusterId = :clusterId AND scv.serviceName = :serviceName
AND scv.version = (SELECT MAX(scv2.version) FROM ServiceConfigEntity scv2 WHERE (scv2.serviceName
= :serviceName AND scv2.clusterId = :clusterId) AND (scv2.groupId = scv.groupId OR (scv2.groupId
IS NULL AND scv.groupId IS NULL)))")})
+    @NamedQuery(name = "ServiceConfigEntity.findLatestServiceConfigsByService", query = "SELECT
scv FROM ServiceConfigEntity scv WHERE scv.clusterId = :clusterId AND scv.serviceName = :serviceName
AND scv.version = (SELECT MAX(scv2.version) FROM ServiceConfigEntity scv2 WHERE (scv2.serviceName
= :serviceName AND scv2.clusterId = :clusterId) AND (scv2.groupId = scv.groupId OR (scv2.groupId
IS NULL AND scv.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.serviceName)")})
 public class ServiceConfigEntity {
   @Id
   @Column(name = "service_config_id")
@@ -263,4 +264,4 @@ public class ServiceConfigEntity {
     }
     return true;
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/911b9177/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
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 8b157c7..7bf24ce 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
@@ -2534,12 +2534,10 @@ public class ClusterImpl implements Cluster {
     if (serviceConfigEntity.getGroupId() == null) {
       Collection<String> configTypes = serviceConfigTypes.get(serviceName);
       List<ClusterConfigMappingEntity> mappingEntities =
-          clusterDAO.getClusterConfigMappingEntitiesByCluster(getClusterId());
+          clusterDAO.getSelectedConfigMappingByTypes(getClusterId(), new ArrayList<>(configTypes));
       for (ClusterConfigMappingEntity entity : mappingEntities) {
-        if (configTypes.contains(entity.getType()) && entity.isSelected() > 0)
{
-          entity.setSelected(0);
-          entity = clusterDAO.mergeConfigMapping(entity);
-        }
+        entity.setSelected(0);
+        clusterDAO.mergeConfigMapping(entity);
       }
 
       for (ClusterConfigEntity configEntity : serviceConfigEntity.getClusterConfigEntities())
{
@@ -2599,14 +2597,12 @@ public class ClusterImpl implements Cluster {
   @Transactional
   void selectConfig(String type, String tag, String user) {
     Collection<ClusterConfigMappingEntity> entities =
-        clusterDAO.getClusterConfigMappingEntitiesByCluster(getClusterId());
+      clusterDAO.getLatestClusterConfigMappingsEntityByType(getClusterId(), type);
 
     //disable previous config
     for (ClusterConfigMappingEntity e : entities) {
-      if (e.isSelected() > 0 && e.getType().equals(type)) {
-        e.setSelected(0);
-        e = clusterDAO.mergeConfigMapping(e);
-      }
+      e.setSelected(0);
+      clusterDAO.mergeConfigMapping(e);
     }
 
     ClusterEntity clusterEntity = getClusterEntity();
@@ -2672,32 +2668,15 @@ public class ClusterImpl implements Cluster {
   }
 
   private List<ClusterConfigEntity> getClusterConfigEntitiesByService(String serviceName)
{
-    List<ClusterConfigEntity> configEntities = new ArrayList<ClusterConfigEntity>();
-
-    //add configs from this service
     Collection<String> configTypes = serviceConfigTypes.get(serviceName);
-    for (ClusterConfigMappingEntity mappingEntity : clusterDAO.getClusterConfigMappingEntitiesByCluster(getClusterId()))
{
-      if (mappingEntity.isSelected() > 0 && configTypes.contains(mappingEntity.getType()))
{
-        ClusterConfigEntity configEntity =
-          clusterDAO.findConfig(getClusterId(), mappingEntity.getType(), mappingEntity.getTag());
-        if (configEntity != null) {
-          configEntities.add(configEntity);
-        } else {
-          LOG.error("Desired cluster config type={}, tag={} is not present in database,"
+
-            " unable to add to service config version");
-        }
-      }
-    }
-    return configEntities;
+    return clusterDAO.getLatestClusterConfigsByTypes(getClusterId(), new ArrayList<>(configTypes));
   }
 
   @Override
   public Config getDesiredConfigByType(String configType) {
-    for (ClusterConfigMappingEntity e : clusterDAO.getClusterConfigMappingEntitiesByCluster(
-        getClusterId())) {
-      if (e.isSelected() > 0 && e.getType().equals(configType)) {
-        return getConfig(e.getType(), e.getTag());
-      }
+    List<ClusterConfigMappingEntity> entities = clusterDAO.getLatestClusterConfigMappingsEntityByType(getClusterId(),
configType);
+    if (!entities.isEmpty()) {
+      return getConfig(configType, entities.get(0).getTag());
     }
 
     return null;
@@ -3454,5 +3433,4 @@ public class ClusterImpl implements Cluster {
 
     m_clusterPropertyCache.clear();
   }
-
 }


Mime
View raw message