ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-15602 - Database Changes to Support Alert Repeat Tolerance (jonathanhurley)
Date Tue, 29 Mar 2016 12:39:45 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 172d02aa4 -> e09ae1c6e


AMBARI-15602 - Database Changes to Support Alert Repeat Tolerance (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: e09ae1c6eb466bdfe742137fa33012b315f1bad1
Parents: 172d02a
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Mon Mar 28 13:18:16 2016 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue Mar 29 08:39:32 2016 -0400

----------------------------------------------------------------------
 .../AlertDefinitionResourceProvider.java        | 28 ++++++
 .../orm/entities/AlertDefinitionEntity.java     | 97 +++++++++++++++++++-
 .../server/upgrade/UpgradeCatalog240.java       | 21 ++++-
 .../main/resources/Ambari-DDL-Derby-CREATE.sql  |  2 +
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  2 +
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  2 +
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  2 +
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  2 +
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql |  2 +
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   |  2 +
 .../server/upgrade/UpgradeCatalog240Test.java   | 24 ++++-
 11 files changed, 179 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
index 08a708f..ca3fb63 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
@@ -87,6 +87,9 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
   protected static final String ALERT_DEF_ENABLED = "AlertDefinition/enabled";
   protected static final String ALERT_DEF_SCOPE = "AlertDefinition/scope";
   protected static final String ALERT_DEF_IGNORE_HOST = "AlertDefinition/ignore_host";
+  protected static final String ALERT_DEF_REPEAT_TOLERANCE = "AlertDefinition/repeat_tolerance";
+  protected static final String ALERT_DEF_REPEAT_TOLERANCE_ENABLED = "AlertDefinition/repeat_tolerance_enabled";
+
 
   protected static final String ALERT_DEF_SOURCE = "AlertDefinition/source";
   protected static final String ALERT_DEF_SOURCE_TYPE = "AlertDefinition/source/type";
@@ -150,6 +153,8 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     PROPERTY_IDS.add(ALERT_DEF_ENABLED);
     PROPERTY_IDS.add(ALERT_DEF_SCOPE);
     PROPERTY_IDS.add(ALERT_DEF_IGNORE_HOST);
+    PROPERTY_IDS.add(ALERT_DEF_REPEAT_TOLERANCE);
+    PROPERTY_IDS.add(ALERT_DEF_REPEAT_TOLERANCE_ENABLED);
     PROPERTY_IDS.add(ALERT_DEF_SOURCE);
 
     // keys
@@ -453,6 +458,17 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
       scope = Scope.ANY;
     }
 
+    Integer repeatTolerance = null;
+    if (requestMap.containsKey(ALERT_DEF_REPEAT_TOLERANCE)) {
+      repeatTolerance = Integer.valueOf((String) requestMap.get(ALERT_DEF_REPEAT_TOLERANCE));
+    }
+
+    Boolean repeatToleranceEnabled = null;
+    if (requestMap.containsKey(ALERT_DEF_REPEAT_TOLERANCE_ENABLED)) {
+      repeatToleranceEnabled = Boolean.valueOf(
+          requestMap.get(ALERT_DEF_REPEAT_TOLERANCE_ENABLED).toString());
+    }
+
     if (StringUtils.isEmpty(clusterName)) {
       throw new IllegalArgumentException(
           "Invalid argument, cluster name is required");
@@ -603,6 +619,16 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
       managed = true;
     }
 
+    if (null != repeatTolerance) {
+      entity.setRepeatTolerance(repeatTolerance);
+      managed = true;
+    }
+
+    if (null != repeatToleranceEnabled) {
+      entity.setRepeatToleranceEnabled(repeatToleranceEnabled);
+      managed = true;
+    }
+
     if (managed) {
       AlertResourceProviderUtils.verifyManageAuthorization(entity);
     } else if (toggled) {
@@ -697,6 +723,8 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     setResourceProperty(resource, ALERT_DEF_IGNORE_HOST, Boolean.valueOf(entity.isHostIgnored()),
requestedIds);
     setResourceProperty(resource, ALERT_DEF_SCOPE, entity.getScope(), requestedIds);
     setResourceProperty(resource, ALERT_DEF_HELP_URL, entity.getHelpURL(), requestedIds);
+    setResourceProperty(resource, ALERT_DEF_REPEAT_TOLERANCE, entity.getRepeatTolerance(),
requestedIds);
+    setResourceProperty(resource, ALERT_DEF_REPEAT_TOLERANCE_ENABLED, Boolean.valueOf(entity.isRepeatToleranceEnabled()),
requestedIds);
 
     boolean sourceTypeRequested = setResourceProperty(resource,
         ALERT_DEF_SOURCE_TYPE, entity.getSourceType(), requestedIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
index b08935c..638646c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
@@ -22,8 +22,30 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
-import javax.persistence.*;
-
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EntityManager;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.PreRemove;
+import javax.persistence.QueryHint;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.UniqueConstraint;
+
+import org.apache.ambari.server.state.AlertState;
 import org.apache.ambari.server.state.alert.Scope;
 import org.apache.ambari.server.state.alert.SourceType;
 
@@ -111,6 +133,21 @@ public class AlertDefinitionEntity {
   private Integer ignoreHost = Integer.valueOf(0);
 
   /**
+   * Indicates how many sequential alerts must be received for a non-OK state
+   * change to be considered correct. This value is meant to eliminate
+   * false-positive notifications on alerts which are flaky.
+   */
+  @Column(name = "repeat_tolerance", nullable = false)
+  private Integer repeatTolerance = Integer.valueOf(1);
+
+  /**
+   * If {@code 1}, then the value of {@link #repeatTolerance} is used to
+   * override the global alert tolerance value.
+   */
+  @Column(name = "repeat_tolerance_enabled", nullable = false)
+  private Short repeatToleranceEnabled = Short.valueOf((short) 0);
+
+  /**
    * Bi-directional many-to-many association to {@link AlertGroupEntity}
    */
   @ManyToMany(mappedBy = "alertDefinitions", cascade = {CascadeType.PERSIST,
@@ -453,6 +490,62 @@ public class AlertDefinitionEntity {
   }
 
   /**
+   * Gets the number of sequential instances of an non-OK {@link AlertState}
+   * must be received in order to consider the alert instance as truly being in
+   * that {@link AlertState}.
+   * <p/>
+   * A value of 1 or less indicates that there is no tolerance and a single
+   * alert will cause dispatching of alert notifications.
+   *
+   * @return the repeatTolerance
+   */
+  public int getRepeatTolerance() {
+    return repeatTolerance;
+  }
+
+  /**
+   * Sets the number of sequential instances of an non-OK {@link AlertState}
+   * must be received in order to consider the alert instance as truly being in
+   * that {@link AlertState}.
+   * <p/>
+   * A value of 1 or less indicates that there is no tolerance and a single
+   * alert will cause dispatching of alert notifications.
+   *
+   * @param repeatTolerance
+   *          the tolerance to set
+   */
+  public void setRepeatTolerance(int repeatTolerance) {
+    this.repeatTolerance = repeatTolerance;
+  }
+
+  /**
+   * Gets whether this definition overrides the default global tolerance value
+   * specified in {@code cluster-env/alerts.repeat.tolerance}. If enabled, the
+   * value from {@link #getRepeatTolerance()} should be used to calculate retry
+   * tolerance.
+   *
+   * @return the repeatToleranceEnabled {@code true} to override the global
+   *         value.
+   */
+  public boolean isRepeatToleranceEnabled() {
+    return repeatToleranceEnabled == Short.valueOf((short) 0) ? false : true;
+  }
+
+  /**
+   * Sets whether this definition overrides the default global tolerance value
+   * specified in {@code cluster-env/alerts.repeat.tolerance}. If enabled, the
+   * value from {@link #getRepeatTolerance()} should be used to calculate retry
+   * tolerance.
+   *
+   * @param repeatToleranceEnabled
+   *          {@code true} to override the defautlt value and use the value
+   *          returned from {@link #getRepeatTolerance()}.
+   */
+  public void setRepeatToleranceEnabled(boolean enabled) {
+    repeatToleranceEnabled = enabled ? Short.valueOf((short) 1) : 0;
+  }
+
+  /**
    * Adds the specified alert group to the groups that this definition is
    * associated with. This is used to complement the JPA bidirectional
    * association.

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
index 38a3614..eb7d750 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
@@ -66,6 +66,8 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
   protected static final String ADMIN_PERMISSION_TABLE = "adminpermission";
   protected static final String ALERT_DEFINITION_TABLE = "alert_definition";
   protected static final String HELP_URL_COLUMN = "help_url";
+  protected static final String REPEAT_TOLERANCE_COLUMN = "repeat_tolerance";
+  protected static final String REPEAT_TOLERANCE_ENABLED_COLUMN = "repeat_tolerance_enabled";
   protected static final String PERMISSION_ID_COL = "permission_name";
   protected static final String SORT_ORDER_COL = "sort_order";
   protected static final String REPO_VERSION_TABLE = "repo_version";
@@ -445,8 +447,25 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
         new DBColumnInfo(SORT_ORDER_COL, Short.class, null, 1, false));
   }
 
+  /**
+   * Updates the {@value #ALERT_DEFINITION_TABLE} in the following ways:
+   * <ul>
+   * <li>Craetes the {@value #HELP_URL_COLUMN} column</li>
+   * <li>Craetes the {@value #REPEAT_TOLERANCE_COLUMN} column</li>
+   * <li>Craetes the {@value #REPEAT_TOLERANCE_ENABLED_COLUMN} column</li>
+   * </ul>
+   *
+   * @throws SQLException
+   */
   protected void updateAlertDefinitionTable() throws SQLException {
-    dbAccessor.addColumn(ALERT_DEFINITION_TABLE, new DBColumnInfo(HELP_URL_COLUMN, String.class,
512, null, true));
+    dbAccessor.addColumn(ALERT_DEFINITION_TABLE,
+        new DBColumnInfo(HELP_URL_COLUMN, String.class, 512, null, true));
+
+    dbAccessor.addColumn(ALERT_DEFINITION_TABLE,
+        new DBColumnInfo(REPEAT_TOLERANCE_COLUMN, Integer.class, null, 1, false));
+
+    dbAccessor.addColumn(ALERT_DEFINITION_TABLE,
+        new DBColumnInfo(REPEAT_TOLERANCE_ENABLED_COLUMN, Short.class, null, 0, false));
   }
 
   protected void setRoleSortOrder() throws SQLException {

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index f8c97ca..4a0479e 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -877,6 +877,8 @@ CREATE TABLE alert_definition (
   alert_source VARCHAR(3000) NOT NULL,
   hash VARCHAR(64) NOT NULL,
   ignore_host SMALLINT DEFAULT 0 NOT NULL,
+  repeat_tolerance INTEGER DEFAULT 1 NOT NULL,
+  repeat_tolerance_enabled SMALLINT DEFAULT 0 NOT NULL,
   PRIMARY KEY (definition_id),
   FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id),
   CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index b306c0a..e40165d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -890,6 +890,8 @@ CREATE TABLE alert_definition (
   alert_source TEXT NOT NULL,
   hash VARCHAR(64) NOT NULL,
   ignore_host SMALLINT DEFAULT 0 NOT NULL,
+  repeat_tolerance INTEGER DEFAULT 1 NOT NULL,
+  repeat_tolerance_enabled SMALLINT DEFAULT 0 NOT NULL,
   PRIMARY KEY (definition_id),
   FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id),
   CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 37744f8..e85ea49 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -880,6 +880,8 @@ CREATE TABLE alert_definition (
   alert_source CLOB NOT NULL,
   hash VARCHAR2(64) NOT NULL,
   ignore_host NUMBER(1) DEFAULT 0 NOT NULL,
+  repeat_tolerance NUMBER(10) DEFAULT 1 NOT NULL,
+  repeat_tolerance_enabled NUMBER(1) DEFAULT 0 NOT NULL,
   PRIMARY KEY (definition_id),
   FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id),
   CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index eba1745..8bcda31 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -884,6 +884,8 @@ CREATE TABLE alert_definition (
   alert_source TEXT NOT NULL,
   hash VARCHAR(64) NOT NULL,
   ignore_host SMALLINT DEFAULT 0 NOT NULL,
+  repeat_tolerance INTEGER DEFAULT 1 NOT NULL,
+  repeat_tolerance_enabled SMALLINT DEFAULT 0 NOT NULL,
   PRIMARY KEY (definition_id),
   FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id),
   CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index cad0a39..c7d7cff 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -970,6 +970,8 @@ CREATE TABLE ambari.alert_definition (
   alert_source TEXT NOT NULL,
   hash VARCHAR(64) NOT NULL,
   ignore_host SMALLINT DEFAULT 0 NOT NULL,
+  repeat_tolerance INTEGER DEFAULT 1 NOT NULL,
+  repeat_tolerance_enabled SMALLINT DEFAULT 0 NOT NULL,
   PRIMARY KEY (definition_id),
   FOREIGN KEY (cluster_id) REFERENCES ambari.clusters(cluster_id),
   CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index 346af50..4bd7a7a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -879,6 +879,8 @@ CREATE TABLE alert_definition (
   alert_source TEXT NOT NULL,
   hash VARCHAR(64) NOT NULL,
   ignore_host SMALLINT DEFAULT 0 NOT NULL,
+  repeat_tolerance INTEGER DEFAULT 1 NOT NULL,
+  repeat_tolerance_enabled SMALLINT DEFAULT 0 NOT NULL,
   PRIMARY KEY (definition_id),
   FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id),
   CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index e238a76..063db3a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -990,6 +990,8 @@ CREATE TABLE alert_definition (
   alert_source TEXT NOT NULL,
   hash VARCHAR(64) NOT NULL,
   ignore_host SMALLINT DEFAULT 0 NOT NULL,
+  repeat_tolerance INTEGER DEFAULT 1 NOT NULL,
+  repeat_tolerance_enabled SMALLINT DEFAULT 0 NOT NULL,
   PRIMARY KEY CLUSTERED (definition_id),
   FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id),
   CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)

http://git-wip-us.apache.org/repos/asf/ambari/blob/e09ae1c6/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
index 7b2d797..ef2a96e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
@@ -19,8 +19,6 @@
 package org.apache.ambari.server.upgrade;
 
 
-import javax.persistence.EntityManager;
-import junit.framework.Assert;
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createMockBuilder;
@@ -46,6 +44,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.persistence.EntityManager;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
@@ -68,6 +68,8 @@ import com.google.inject.Injector;
 import com.google.inject.Module;
 import com.google.inject.Provider;
 
+import junit.framework.Assert;
+
 public class UpgradeCatalog240Test {
   private static Injector injector;
   private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class);
@@ -165,7 +167,11 @@ public class UpgradeCatalog240Test {
         UpgradeCatalog240.CLUSTER_UPGRADE_ID_COLUMN, UpgradeCatalog240.UPGRADE_TABLE, "upgrade_id",
false);
 
     Capture<DBAccessor.DBColumnInfo> capturedHelpURLColumnInfo = newCapture();
+    Capture<DBAccessor.DBColumnInfo> capturedRepeatToleranceColumnInfo = newCapture();
+    Capture<DBAccessor.DBColumnInfo> capturedRepeatToleranceEnabledColumnInfo = newCapture();
     dbAccessor.addColumn(eq(UpgradeCatalog240.ALERT_DEFINITION_TABLE), capture(capturedHelpURLColumnInfo));
+    dbAccessor.addColumn(eq(UpgradeCatalog240.ALERT_DEFINITION_TABLE), capture(capturedRepeatToleranceColumnInfo));
+    dbAccessor.addColumn(eq(UpgradeCatalog240.ALERT_DEFINITION_TABLE), capture(capturedRepeatToleranceEnabledColumnInfo));
 
     replay(dbAccessor, configuration, connection, statement, resultSet);
 
@@ -251,6 +257,20 @@ public class UpgradeCatalog240Test {
     Assert.assertEquals(null, columnHelpURLInfo.getDefaultValue());
     Assert.assertEquals(true, columnHelpURLInfo.isNullable());
 
+    DBAccessor.DBColumnInfo columnRepeatToleranceInfo = capturedRepeatToleranceColumnInfo.getValue();
+    Assert.assertNotNull(columnRepeatToleranceInfo);
+    Assert.assertEquals(UpgradeCatalog240.REPEAT_TOLERANCE_COLUMN, columnRepeatToleranceInfo.getName());
+    Assert.assertEquals(Integer.class, columnRepeatToleranceInfo.getType());
+    Assert.assertEquals(1, columnRepeatToleranceInfo.getDefaultValue());
+    Assert.assertEquals(false, columnRepeatToleranceInfo.isNullable());
+
+    DBAccessor.DBColumnInfo columnRepeatToleranceEnabledInfo = capturedRepeatToleranceEnabledColumnInfo.getValue();
+    Assert.assertNotNull(columnRepeatToleranceEnabledInfo);
+    Assert.assertEquals(UpgradeCatalog240.REPEAT_TOLERANCE_ENABLED_COLUMN, columnRepeatToleranceEnabledInfo.getName());
+    Assert.assertEquals(Short.class, columnRepeatToleranceEnabledInfo.getType());
+    Assert.assertEquals(0, columnRepeatToleranceEnabledInfo.getDefaultValue());
+    Assert.assertEquals(false, columnRepeatToleranceEnabledInfo.isNullable());
+
     assertEquals(expectedCaptures, actualCaptures);
 
     verify(dbAccessor);


Mime
View raw message