Repository: ambari Updated Branches: refs/heads/trunk f2114d8c9 -> e8c80e221
AMBARI-6839 - Alerts: Update Oracle Alert DDL for CLOB (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e8c80e22 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e8c80e22 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e8c80e22 Branch: refs/heads/trunk Commit: e8c80e2213c40e42d89f4db870ab0a8bf0b9e15c Parents: f2114d8 Author: Jonathan Hurley <jhur...@hortonworks.com> Authored: Tue Aug 12 20:23:26 2014 -0400 Committer: Jonathan Hurley <jhur...@hortonworks.com> Committed: Tue Aug 12 23:21:52 2014 -0400 ---------------------------------------------------------------------- .../orm/entities/AlertDefinitionEntity.java | 67 +++++++++++--------- .../server/orm/entities/AlertTargetEntity.java | 34 ++++++---- .../server/upgrade/UpgradeCatalog170.java | 17 +++-- .../main/resources/Ambari-DDL-Oracle-CREATE.sql | 4 +- 4 files changed, 72 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e8c80e22/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 3aa0e62..de30921 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 @@ -19,6 +19,7 @@ package org.apache.ambari.server.orm.entities; import java.util.Set; +import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -28,6 +29,7 @@ import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Lob; import javax.persistence.ManyToMany; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -58,6 +60,8 @@ public class AlertDefinitionEntity { @Column(name = "definition_id", nullable = false, updatable = false) private Long definitionId; + @Lob + @Basic @Column(name = "alert_source", nullable = false, length = 32672) private String source; @@ -69,7 +73,7 @@ public class AlertDefinitionEntity { @Column(name = "definition_name", nullable = false, length = 255) private String definitionName; - + @Column(name = "scope", length = 255) @Enumerated(value = EnumType.STRING) private Scope scope; @@ -104,7 +108,7 @@ public class AlertDefinitionEntity { /** * Gets the unique identifier for this alert definition. - * + * * @return the ID. */ public Long getDefinitionId() { @@ -113,7 +117,7 @@ public class AlertDefinitionEntity { /** * Sets the unique identifier for this alert definition. - * + * * @param definitionId * the ID (not {@code null}). */ @@ -125,7 +129,7 @@ public class AlertDefinitionEntity { * Gets the source that defines the type of alert and the alert properties. * This is typically a JSON structure that can be mapped to a first-class * object. - * + * * @return the alert source (never {@code null}). */ public String getSource() { @@ -135,19 +139,19 @@ public class AlertDefinitionEntity { /** * Sets the source of the alert, typically in JSON, that defines the type of * the alert and its properties. - * + * * @param alertSource * the alert source (not {@code null}). */ public void setSource(String alertSource) { - this.source = alertSource; + source = alertSource; } /** * Gets the ID of the cluster that this alert definition is created for. Each * cluster has their own set of alert definitions that are not shared with any * other cluster. - * + * * @return the ID of the cluster (never {@code null}). */ public Long getClusterId() { @@ -158,7 +162,7 @@ public class AlertDefinitionEntity { * Sets the ID of the cluster that this alert definition is created for. Each * cluster has their own set of alert definitions that are not shared with any * other cluster. - * + * * @param clusterId * the ID of the cluster (not {@code null}). */ @@ -169,7 +173,7 @@ public class AlertDefinitionEntity { /** * Gets the component name that this alert is associated with, if any. Some * alerts are scoped at the service level and will not have a component name. - * + * * @return the component name or {@code null} if none. */ public String getComponentName() { @@ -179,7 +183,7 @@ public class AlertDefinitionEntity { /** * Sets the component name that this alert is associated with, if any. Some * alerts are scoped at the service level and will not have a component name. - * + * * @param componentName * the component name or {@code null} if none. */ @@ -190,7 +194,7 @@ public class AlertDefinitionEntity { /** * Gets the scope of the alert definition. The scope is defined as either * being for a {@link Scope#SERVICE} or {@link Scope#HOST}. - * + * * @return the scope, or {@code null} if not defined. */ public Scope getScope() { @@ -200,7 +204,7 @@ public class AlertDefinitionEntity { /** * Sets the scope of the alert definition. The scope is defined as either * being for a {@link Scope#SERVICE} or {@link Scope#HOST}. - * + * * @param scope * the scope to set, or {@code null} for none. */ @@ -211,7 +215,7 @@ public class AlertDefinitionEntity { /** * Gets the name of this alert definition. Alert definition names are unique * within a cluster. - * + * * @return the name of the alert definition (never {@code null}). */ public String getDefinitionName() { @@ -221,7 +225,7 @@ public class AlertDefinitionEntity { /** * Sets the name of this alert definition. Alert definition names are unique * within a cluster. - * + * * @param definitionName * the name of the alert definition (not {@code null}). */ @@ -233,7 +237,7 @@ public class AlertDefinitionEntity { * Gets whether this alert definition is enabled. Disabling an alert * definition will prevent agents from scheduling the alerts. No alerts will * be triggered and no alert data will be collected. - * + * * @return {@code true} if this alert definition is enabled, {@code false} * otherwise. */ @@ -243,7 +247,7 @@ public class AlertDefinitionEntity { /** * Sets whether this alert definition is enabled. - * + * * @param enabled * {@code true} if this alert definition is enabled, {@code false} * otherwise. @@ -255,7 +259,7 @@ public class AlertDefinitionEntity { /** * Gets the unique hash for the current state of this definition. If a * property of this definition changes, a new hash is calculated. - * + * * @return the unique hash or {@code null} if there is none. */ public String getHash() { @@ -265,7 +269,7 @@ public class AlertDefinitionEntity { /** * Gets the unique hash for the current state of this definition. If a * property of this definition changes, a new hash is calculated. - * + * * @param hash * the unique hash to set or {@code null} for none. */ @@ -275,7 +279,7 @@ public class AlertDefinitionEntity { /** * Gets the alert trigger interval, in seconds. - * + * * @return the interval, in seconds. */ public Integer getScheduleInterval() { @@ -284,7 +288,7 @@ public class AlertDefinitionEntity { /** * Sets the alert trigger interval, in seconds. - * + * * @param scheduleInterval * the interval, in seconds. */ @@ -295,7 +299,7 @@ public class AlertDefinitionEntity { /** * Gets the name of the service that this alert definition is associated with. * Every alert definition is associated with exactly one service. - * + * * @return the name of the service (never {@code null}). */ public String getServiceName() { @@ -305,7 +309,7 @@ public class AlertDefinitionEntity { /** * Gets the name of the service that this alert definition is associated with. * Every alert definition is associated with exactly one service. - * + * * @param serviceName * the name of the service (not {@code null}). */ @@ -331,7 +335,7 @@ public class AlertDefinitionEntity { /** * Gets the alert groups that this alert definition is associated with. - * + * * @return the groups, or {@code null} if none. */ public Set<AlertGroupEntity> getAlertGroups() { @@ -340,7 +344,7 @@ public class AlertDefinitionEntity { /** * Sets the alert groups that this alert definition is associated with. - * + * * @param alertGroups * the groups, or {@code null} for none. */ @@ -355,13 +359,15 @@ public class AlertDefinitionEntity { @PreRemove public void preRemove() { Set<AlertGroupEntity> groups = getAlertGroups(); - if (null == groups || groups.size() == 0) + if (null == groups || groups.size() == 0) { return; + } for (AlertGroupEntity group : groups) { Set<AlertDefinitionEntity> definitions = group.getAlertDefinitions(); - if (null != definitions) + if (null != definitions) { definitions.remove(this); + } } } @@ -370,17 +376,20 @@ public class AlertDefinitionEntity { */ @Override public boolean equals(Object object) { - if (this == object) + if (this == object) { return true; + } - if (object == null || getClass() != object.getClass()) + if (object == null || getClass() != object.getClass()) { return false; + } AlertDefinitionEntity that = (AlertDefinitionEntity) object; if (definitionId != null ? !definitionId.equals(that.definitionId) - : that.definitionId != null) + : that.definitionId != null) { return false; + } return true; } http://git-wip-us.apache.org/repos/asf/ambari/blob/e8c80e22/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java index 6f9ab89..74da92c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -28,6 +29,7 @@ import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Lob; import javax.persistence.ManyToMany; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -58,6 +60,8 @@ public class AlertTargetEntity { @Column(name = "notification_type", nullable = false, length = 64) private String notificationType; + @Lob + @Basic @Column(length = 32672) private String properties; @@ -73,7 +77,7 @@ public class AlertTargetEntity { /** * Gets the unique ID of this alert target. - * + * * @return the ID of the target (never {@code null}). */ public Long getTargetId() { @@ -82,7 +86,7 @@ public class AlertTargetEntity { /** * Sets the unique ID of this alert target. - * + * * @param targetId * the ID of the alert target (not {@code null}). */ @@ -92,7 +96,7 @@ public class AlertTargetEntity { /** * Gets the description of this alert target. - * + * * @return the description or {@code null} if none. */ public String getDescription() { @@ -101,7 +105,7 @@ public class AlertTargetEntity { /** * Sets the description for this alert target. - * + * * @param description * the description or {@code null} for none. */ @@ -139,7 +143,7 @@ public class AlertTargetEntity { /** * Gets the name of this alert target. - * + * * @return the alert target name (never {@code null}). */ public String getTargetName() { @@ -148,7 +152,7 @@ public class AlertTargetEntity { /** * Sets the name of this alert target. - * + * * @param targetName * the name (not {@code null}). */ @@ -159,13 +163,14 @@ public class AlertTargetEntity { /** * Gets an immutable set of the alert groups that this target is associated * with. - * + * * @return the groups that will send to this target when an alert in that * group is received, or an empty set for none. */ public Set<AlertGroupEntity> getAlertGroups() { - if (null == alertGroups) + if (null == alertGroups) { return Collections.emptySet(); + } return Collections.unmodifiableSet(alertGroups); } @@ -173,12 +178,13 @@ public class AlertTargetEntity { /** * Adds the specified alert group to the groups that this target is associated * with. This is used to complement the JPA bidirectional association. - * + * * @param alertGroup */ protected void addAlertGroup(AlertGroupEntity alertGroup) { - if (null == alertGroups) + if (null == alertGroups) { alertGroups = new HashSet<AlertGroupEntity>(); + } alertGroups.add(alertGroup); } @@ -187,12 +193,13 @@ public class AlertTargetEntity { * Removes the specified alert group to the groups that this target is * associated with. This is used to complement the JPA bidirectional * association. - * + * * @param alertGroup */ protected void removeAlertGroup(AlertGroupEntity alertGroup) { - if (null != alertGroups) + if (null != alertGroups) { alertGroups.remove(alertGroup); + } } /** @@ -202,8 +209,9 @@ public class AlertTargetEntity { @PreRemove public void preRemove() { Set<AlertGroupEntity> groups = getAlertGroups(); - if (null == groups || groups.size() == 0) + if (null == groups || groups.size() == 0) { return; + } for (AlertGroupEntity group : groups) { group.removeAlertTarget(this); http://git-wip-us.apache.org/repos/asf/ambari/blob/e8c80e22/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java index ab9d18b..9a0f4ca 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java @@ -27,6 +27,14 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.AmbariManagementController; @@ -45,10 +53,6 @@ import org.slf4j.LoggerFactory; import com.google.inject.Inject; import com.google.inject.Injector; -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.*; - /** * Upgrade catalog for version 1.7.0. */ @@ -401,7 +405,8 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog { columns.add(new DBColumnInfo("enabled", Short.class, 1, 1, false)); columns.add(new DBColumnInfo("schedule_interval", Integer.class, null, null, false)); columns.add(new DBColumnInfo("source_type", String.class, 255, null, false)); - columns.add(new DBColumnInfo("alert_source", String.class, 4000, null, false)); + columns.add(new DBColumnInfo("alert_source", char[].class, 32672, null, + false)); columns.add(new DBColumnInfo("hash", String.class, 64, null, false)); dbAccessor.createTable(ALERT_TABLE_DEFINITION, columns, "definition_id"); @@ -482,7 +487,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog { columns.add(new DBColumnInfo("target_id", Long.class, null, null, false)); columns.add(new DBColumnInfo("target_name", String.class, 255, null, false)); columns.add(new DBColumnInfo("notification_type", String.class, 64, null, false)); - columns.add(new DBColumnInfo("properties", String.class, 4000, null, true)); + columns.add(new DBColumnInfo("properties", char[].class, 32672, null, true)); columns.add(new DBColumnInfo("description", String.class, 1024, null, true)); dbAccessor.createTable(ALERT_TABLE_TARGET, columns, "target_id"); http://git-wip-us.apache.org/repos/asf/ambari/blob/e8c80e22/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 6a8f35d..87d0fd9 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -156,7 +156,7 @@ CREATE TABLE alert_definition ( enabled NUMBER(1) DEFAULT 1 NOT NULL, schedule_interval NUMBER(10) NOT NULL, source_type VARCHAR2(255) NOT NULL, - alert_source VARCHAR2(4000) NOT NULL, + alert_source CLOB NOT NULL, hash VARCHAR2(64) NOT NULL, PRIMARY KEY (definition_id), FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id), @@ -205,7 +205,7 @@ CREATE TABLE alert_target ( target_id NUMBER(19) NOT NULL, target_name VARCHAR2(255) NOT NULL UNIQUE, notification_type VARCHAR2(64) NOT NULL, - properties VARCHAR2(4000), + properties CLOB, description VARCHAR2(1024), PRIMARY KEY (target_id) );