ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [47/50] ambari git commit: AMBARI-20685 - Upgrade Progress Dialog Executes Query Which Causes StackOverflow in JPA (jonathanhurley)
Date Thu, 06 Apr 2017 18:58:36 GMT
AMBARI-20685 - Upgrade Progress Dialog Executes Query Which Causes StackOverflow in JPA (jonathanhurley)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 92894811ec18ce5eae9aa10071f3bad022d4bcf5
Parents: e8c506f
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Wed Apr 5 16:29:22 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Thu Apr 6 11:41:58 2017 -0400

----------------------------------------------------------------------
 .../internal/StageResourceProvider.java         |  4 +-
 .../internal/UpgradeItemResourceProvider.java   | 61 +++++++++-----------
 .../ambari/server/orm/entities/StageEntity.java | 19 +++---
 .../server/orm/entities/StageEntityPK.java      | 35 +++++------
 .../ambari/server/state/UpgradeHelper.java      | 48 ---------------
 5 files changed, 55 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/92894811/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
index 8759844..db9a0e2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
@@ -216,7 +216,7 @@ public class StageResourceProvider extends AbstractControllerResourceProvider
im
 
     List<StageEntity> entities = dao.findAll(request, predicate);
     for (StageEntity entity : entities) {
-      results.add(toResource(cache, entity, propertyIds));
+      results.add(StageResourceProvider.toResource(cache, entity, propertyIds));
     }
 
     cache.clear();
@@ -273,7 +273,7 @@ public class StageResourceProvider extends AbstractControllerResourceProvider
im
    *
    * @return the new resource
    */
-  private Resource toResource(
+  static Resource toResource(
       Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache,
       StageEntity entity,
       Set<String> requestedIds) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/92894811/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
index bf0fa33..21b6c64 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
@@ -41,6 +41,8 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.orm.dao.HostRoleCommandStatusSummaryDTO;
 import org.apache.ambari.server.orm.dao.StageDAO;
 import org.apache.ambari.server.orm.dao.UpgradeDAO;
 import org.apache.ambari.server.orm.entities.StageEntity;
@@ -53,7 +55,6 @@ 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.state.Cluster;
-import org.apache.ambari.server.state.UpgradeHelper;
 import org.apache.ambari.server.utils.SecretReference;
 import org.apache.commons.lang.StringUtils;
 
@@ -84,12 +85,8 @@ public class UpgradeItemResourceProvider extends ReadOnlyResourceProvider
{
   @Inject
   private static StageDAO s_stageDao;
 
-  /**
-   * Used to generated the correct tasks and stages during an upgrade.
-   */
   @Inject
-  private static UpgradeHelper s_upgradeHelper;
-
+  private static HostRoleCommandDAO s_hostRoleCommandDAO;
 
   static {
     // properties
@@ -232,38 +229,36 @@ public class UpgradeItemResourceProvider extends ReadOnlyResourceProvider
{
         }
       }
 
+      Map<Long, HostRoleCommandStatusSummaryDTO> requestAggregateCounts = s_hostRoleCommandDAO.findAggregateCounts(requestId);
+      Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<>();
+      cache.put(requestId, requestAggregateCounts);
+
       // !!! need to do some lookup for stages, so use a stageid -> resource for
       // when that happens
-      Map<Long, Resource> resultMap = new HashMap<>();
-
       for (UpgradeItemEntity entity : entities) {
-        Resource r = toResource(entity, requestPropertyIds);
-        resultMap.put(entity.getStageId(), r);
-      }
-
-      if (!resultMap.isEmpty()) {
-        if (null != clusterName) {
-          Set<Resource> stages = s_upgradeHelper.getStageResources(clusterName,
-              requestId, new ArrayList<>(resultMap.keySet()));
-
-          for (Resource stage : stages) {
-            Long l = (Long) stage.getPropertyValue(StageResourceProvider.STAGE_STAGE_ID);
-
-            Resource r = resultMap.get(l);
-            if (null != r) {
-              for (String propertyId : StageResourceProvider.PROPERTY_IDS) {
-                // Attempt to mask any passwords in fields that are property maps.
-                Object value = stage.getPropertyValue(propertyId);
-                if (StageResourceProvider.PROPERTIES_TO_MASK_PASSWORD_IN.contains(propertyId)
&&
-                    value.getClass().equals(String.class) && !StringUtils.isBlank((String)
value)) {
-                  value = SecretReference.maskPasswordInPropertyMap((String) value);
-                }
-                setResourceProperty(r, STAGE_MAPPED_IDS.get(propertyId), value, requestPropertyIds);
-              }
-            }
+        Resource upgradeItemResource = toResource(entity, requestPropertyIds);
+
+        StageEntityPK stagePrimaryKey = new StageEntityPK();
+        stagePrimaryKey.setRequestId(requestId);
+        stagePrimaryKey.setStageId(entity.getStageId());
+
+        StageEntity stageEntity = s_stageDao.findByPK(stagePrimaryKey);
+        Resource stageResource = StageResourceProvider.toResource(cache, stageEntity,
+            StageResourceProvider.PROPERTY_IDS);
+
+        for (String propertyId : StageResourceProvider.PROPERTY_IDS) {
+          // Attempt to mask any passwords in fields that are property maps.
+          Object value = stageResource.getPropertyValue(propertyId);
+          if (StageResourceProvider.PROPERTIES_TO_MASK_PASSWORD_IN.contains(propertyId)
+              && value.getClass().equals(String.class) && !StringUtils.isBlank((String)
value)) {
+            value = SecretReference.maskPasswordInPropertyMap((String) value);
           }
+
+          setResourceProperty(upgradeItemResource, STAGE_MAPPED_IDS.get(propertyId), value,
+              requestPropertyIds);
         }
-        results.addAll(resultMap.values());
+
+        results.add(upgradeItemResource);
       }
     }
     return results;

http://git-wip-us.apache.org/repos/asf/ambari/blob/92894811/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
index 49c1594..d035729 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
@@ -43,43 +43,42 @@ import org.apache.ambari.server.actionmanager.HostRoleStatus;
 
 @Entity
 @Table(name = "stage")
-@IdClass(org.apache.ambari.server.orm.entities.StageEntityPK.class)
+@IdClass(StageEntityPK.class)
 @NamedQueries({
     @NamedQuery(
         name = "StageEntity.findFirstStageByStatus",
         query = "SELECT stage.requestId, MIN(stage.stageId) from StageEntity stage, HostRoleCommandEntity
hrc WHERE hrc.status IN :statuses AND hrc.stageId = stage.stageId AND hrc.requestId = stage.requestId
GROUP by stage.requestId ORDER BY stage.requestId"),
     @NamedQuery(
-        name = "StageEntity.findByPK",
-        query = "SELECT stage from StageEntity stage WHERE stage.requestId = :requestId AND
stage.stageId = :stageId"),
-    @NamedQuery(
         name = "StageEntity.findByRequestIdAndCommandStatuses",
         query = "SELECT stage from StageEntity stage WHERE stage.status IN :statuses AND
stage.requestId = :requestId ORDER BY stage.stageId") })
 public class StageEntity {
 
-  @Column(name = "cluster_id", updatable = false, nullable = false)
   @Basic
+  @Column(name = "cluster_id", updatable = false, nullable = false)
   private Long clusterId = Long.valueOf(-1L);
 
-  @Column(name = "request_id", insertable = false, updatable = false, nullable = false)
   @Id
+  @Column(name = "request_id", insertable = false, updatable = false, nullable = false)
   private Long requestId;
 
-  @Column(name = "stage_id", nullable = false)
   @Id
+  @Column(name = "stage_id", insertable = true, updatable = false, nullable = false)
   private Long stageId = 0L;
 
+  @Basic
   @Column(name = "skippable", nullable = false)
   private Integer skippable = Integer.valueOf(0);
 
+  @Basic
   @Column(name = "supports_auto_skip_failure", nullable = false)
   private Integer supportsAutoSkipOnFailure = Integer.valueOf(0);
 
-  @Column(name = "log_info")
   @Basic
+  @Column(name = "log_info")
   private String logInfo = "";
 
-  @Column(name = "request_context")
   @Basic
+  @Column(name = "request_context")
   private String requestContext = "";
 
   @Basic
@@ -107,8 +106,8 @@ public class StageEntity {
   @Basic(fetch = FetchType.LAZY)
   private byte[] commandParamsStage;
 
-  @Column(name = "host_params")
   @Basic
+  @Column(name = "host_params")
   private byte[] hostParamsStage;
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/92894811/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java
index 34d175c..c0ccc65 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java
@@ -19,16 +19,15 @@
 package org.apache.ambari.server.orm.entities;
 
 import java.io.Serializable;
+import java.util.Objects;
 
-import javax.persistence.Column;
-import javax.persistence.Id;
+import org.apache.commons.lang.builder.EqualsBuilder;
 
 @SuppressWarnings("serial")
 public class StageEntityPK implements Serializable {
   private Long requestId;
+  private Long stageId;
 
-  @Id
-  @Column(name = "request_id")
   public Long getRequestId() {
     return requestId;
   }
@@ -37,10 +36,6 @@ public class StageEntityPK implements Serializable {
     this.requestId = requestId;
   }
 
-  private Long stageId;
-
-  @Id
-  @Column(name = "stage_id")
   public Long getStageId() {
     return stageId;
   }
@@ -50,23 +45,25 @@ public class StageEntityPK implements Serializable {
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-
-    StageEntityPK that = (StageEntityPK) o;
+  public boolean equals(Object object) {
+    if (this == object) {
+      return true;
+    }
 
-    if (requestId != null ? !requestId.equals(that.requestId) : that.requestId != null) return
false;
-    if (stageId != null ? !stageId.equals(that.stageId) : that.stageId != null) return false;
+    if (object == null || getClass() != object.getClass()) {
+      return false;
+    }
 
-    return true;
+    StageEntityPK that = (StageEntityPK) object;
+    EqualsBuilder equalsBuilder = new EqualsBuilder();
+    equalsBuilder.append(requestId, that.requestId);
+    equalsBuilder.append(stageId, that.stageId);
+    return equalsBuilder.isEquals();
   }
 
   @Override
   public int hashCode() {
-    int result = requestId != null ? requestId.hashCode() : 0;
-    result = 31 * result + (stageId != null ? stageId.hashCode() : 0);
-    return result;
+    return Objects.hash(requestId, stageId);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/92894811/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
index eee913a..5a8c25e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
@@ -30,7 +30,6 @@ import java.util.regex.Pattern;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.controller.internal.StageResourceProvider;
 import org.apache.ambari.server.controller.internal.TaskResourceProvider;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
 import org.apache.ambari.server.controller.spi.ClusterController;
@@ -667,53 +666,6 @@ public class UpgradeHelper {
   }
 
   /**
-   * Gets a set of Stages resources to aggregate an UpgradeItem with Stage.
-   *
-   * @param clusterName the cluster name
-   * @param requestId the request id containing the stages
-   * @param stageIds the list of stages to fetch
-   * @return the list of Stage resources
-   * @throws UnsupportedPropertyException
-   * @throws NoSuchResourceException
-   * @throws NoSuchParentResourceException
-   * @throws SystemException
-   */
-  // !!! FIXME this feels very wrong
-  public Set<Resource> getStageResources(String clusterName, Long requestId, List<Long>
stageIds)
-      throws UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException,
SystemException {
-    ClusterController clusterController = ClusterControllerHelper.getClusterController();
-
-    Request request = PropertyHelper.getReadRequest();
-
-
-    Predicate p1 = new PredicateBuilder().property(StageResourceProvider.STAGE_CLUSTER_NAME).equals(clusterName).toPredicate();
-    Predicate p2 = new PredicateBuilder().property(StageResourceProvider.STAGE_REQUEST_ID).equals(requestId).toPredicate();
-    Predicate p3 = null;
-
-    if (1 == stageIds.size()) {
-      p3 = new PredicateBuilder().property(StageResourceProvider.STAGE_STAGE_ID).equals(stageIds.get(0)).toPredicate();
-    } else if (stageIds.size() > 0) {
-      PredicateBuilder pb = new PredicateBuilder();
-
-      int i = 0;
-      for (Long stageId : stageIds) {
-        if (i++ < stageIds.size()-1) {
-          pb = pb.property(StageResourceProvider.STAGE_STAGE_ID).equals(stageId).or();
-        } else {
-          pb.property(StageResourceProvider.STAGE_STAGE_ID).equals(stageId);
-        }
-      }
-
-      p3 = pb.toPredicate();
-    }
-
-    QueryResponse response = clusterController.getResources(Resource.Type.Stage,
-        request, new AndPredicate(p1, p2, p3));
-
-    return response.getResources();
-  }
-
-  /**
    * Get a single resource for the task with the given parameters.
    * @param clusterName Cluster Name
    * @param requestId Request Id


Mime
View raw message