You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2014/08/19 04:31:21 UTC

git commit: AMBARI-6908 - Alerts: AlertDefinition Should Have a Label (jonathanhurley)

Repository: ambari
Updated Branches:
  refs/heads/trunk ab128d4ac -> bbd9179ad


AMBARI-6908 - Alerts: AlertDefinition Should Have a Label (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: bbd9179ad9e6fdc503649bf2cde5484ae8d78571
Parents: ab128d4
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Mon Aug 18 21:01:32 2014 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Mon Aug 18 22:31:04 2014 -0400

----------------------------------------------------------------------
 .../AlertDefinitionResourceProvider.java        | 140 +++++++++++--------
 .../orm/entities/AlertDefinitionEntity.java     |  22 +++
 .../server/upgrade/UpgradeCatalog170.java       |   1 +
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |   1 +
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |   1 +
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |   1 +
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |   1 +
 .../src/main/resources/properties.json          |   1 +
 .../AlertDefinitionResourceProviderTest.java    | 137 +++++++++---------
 .../server/upgrade/UpgradeCatalog170Test.java   |   4 +-
 10 files changed, 182 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/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 6f00c27..07b033e 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
@@ -57,6 +57,7 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
   protected static final String ALERT_DEF_CLUSTER_NAME = "AlertDefinition/cluster_name";
   protected static final String ALERT_DEF_ID = "AlertDefinition/id";
   protected static final String ALERT_DEF_NAME = "AlertDefinition/name";
+  protected static final String ALERT_DEF_LABEL = "AlertDefinition/label";
   protected static final String ALERT_DEF_INTERVAL = "AlertDefinition/interval";
   protected static final String ALERT_DEF_SOURCE_TYPE = "AlertDefinition/source/type";
   protected static final String ALERT_DEF_SOURCE = "AlertDefinition/source";
@@ -64,13 +65,13 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
   protected static final String ALERT_DEF_COMPONENT_NAME = "AlertDefinition/component_name";
   protected static final String ALERT_DEF_ENABLED = "AlertDefinition/enabled";
   protected static final String ALERT_DEF_SCOPE = "AlertDefinition/scope";
-  
+
   private static Set<String> pkPropertyIds = new HashSet<String>(
       Arrays.asList(ALERT_DEF_ID, ALERT_DEF_NAME));
   private static AlertDefinitionDAO alertDefinitionDAO = null;
-  
+
   private static Gson gson = new Gson();
-  
+
   /**
    * @param instance
    */
@@ -78,13 +79,13 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
   public static void init(AlertDefinitionDAO instance) {
     alertDefinitionDAO = instance;
   }
-  
+
   AlertDefinitionResourceProvider(Set<String> propertyIds,
       Map<Resource.Type, String> keyPropertyIds,
       AmbariManagementController managementController) {
     super(propertyIds, keyPropertyIds, managementController);
   }
-  
+
   @Override
   protected Set<String> getPKPropertyIds() {
     return pkPropertyIds;
@@ -103,49 +104,55 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
       }
     });
     notifyCreate(Resource.Type.AlertDefinition, request);
-    
+
     return getRequestStatus(null);
   }
-  
+
   private void createAlertDefinitions(Set<Map<String, Object>> requestMaps)
     throws AmbariException {
     List<AlertDefinitionEntity> entities = new ArrayList<AlertDefinitionEntity>();
-    
+
     for (Map<String, Object> requestMap : requestMaps) {
       entities.add(toCreateEntity(requestMap));
     }
 
     // !!! TODO multi-create in a transaction
-    for (AlertDefinitionEntity entity : entities)
+    for (AlertDefinitionEntity entity : entities) {
       alertDefinitionDAO.create(entity);
+    }
   }
-  
+
   private AlertDefinitionEntity toCreateEntity(Map<String, Object> requestMap)
     throws AmbariException {
 
     String clusterName = (String) requestMap.get(ALERT_DEF_CLUSTER_NAME);
-    
-    if (null == clusterName || clusterName.isEmpty())
+
+    if (null == clusterName || clusterName.isEmpty()) {
       throw new IllegalArgumentException("Invalid argument, cluster name is required");
-    
-    if (!requestMap.containsKey(ALERT_DEF_INTERVAL))
+    }
+
+    if (!requestMap.containsKey(ALERT_DEF_INTERVAL)) {
       throw new IllegalArgumentException("Check interval must be specified");
-    
+    }
+
     Integer interval = Integer.valueOf((String) requestMap.get(ALERT_DEF_INTERVAL));
 
-    if (!requestMap.containsKey(ALERT_DEF_NAME))
+    if (!requestMap.containsKey(ALERT_DEF_NAME)) {
       throw new IllegalArgumentException("Definition name must be specified");
-    
-    if (!requestMap.containsKey(ALERT_DEF_SERVICE_NAME))
+    }
+
+    if (!requestMap.containsKey(ALERT_DEF_SERVICE_NAME)) {
       throw new IllegalArgumentException("Service name must be specified");
-    
-    if (!requestMap.containsKey(ALERT_DEF_SOURCE_TYPE))
+    }
+
+    if (!requestMap.containsKey(ALERT_DEF_SOURCE_TYPE)) {
       throw new IllegalArgumentException(String.format(
           "Source type must be specified and one of %s", EnumSet.allOf(
               SourceType.class)));
+    }
 
     JsonObject jsonObj = new JsonObject();
-    
+
     for (Entry<String, Object> entry : requestMap.entrySet()) {
       String propCat = PropertyHelper.getPropertyCategory(entry.getKey());
       String propName = PropertyHelper.getPropertyName(entry.getKey());
@@ -155,26 +162,28 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
       }
     }
 
-    if (0 == jsonObj.entrySet().size())
+    if (0 == jsonObj.entrySet().size()) {
       throw new IllegalArgumentException("Source must be specified");
-    
+    }
+
     Cluster cluster = getManagementController().getClusters().getCluster(clusterName);
-    
+
     AlertDefinitionEntity entity = new AlertDefinitionEntity();
     entity.setClusterId(Long.valueOf(cluster.getClusterId()));
     entity.setComponentName((String) requestMap.get(ALERT_DEF_COMPONENT_NAME));
     entity.setDefinitionName((String) requestMap.get(ALERT_DEF_NAME));
+    entity.setLabel((String) requestMap.get(ALERT_DEF_LABEL));
 
     boolean enabled = requestMap.containsKey(ALERT_DEF_ENABLED) ?
         Boolean.parseBoolean((String)requestMap.get(ALERT_DEF_ENABLED)) : true;
-    
+
     entity.setEnabled(enabled);
     entity.setHash(UUID.randomUUID().toString());
     entity.setScheduleInterval(interval);
     entity.setServiceName((String) requestMap.get(ALERT_DEF_SERVICE_NAME));
     entity.setSourceType((String) requestMap.get(ALERT_DEF_SOURCE_TYPE));
     entity.setSource(jsonObj.toString());
-    
+
     Scope scope = null;
     String desiredScope = (String) requestMap.get(ALERT_DEF_SCOPE);
     if (null != desiredScope && desiredScope.length() > 0) {
@@ -190,17 +199,18 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
   public Set<Resource> getResources(Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException,
       NoSuchResourceException, NoSuchParentResourceException {
-    
+
     Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate);
-    
+
     Set<Resource> results = new HashSet<Resource>();
-    
+
     for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
       String clusterName = (String) propertyMap.get(ALERT_DEF_CLUSTER_NAME);
-      
-      if (null == clusterName || clusterName.isEmpty())
+
+      if (null == clusterName || clusterName.isEmpty()) {
         throw new IllegalArgumentException("Invalid argument, cluster name is required");
-      
+      }
+
       String id = (String) propertyMap.get(ALERT_DEF_ID);
       if (null != id) {
         AlertDefinitionEntity entity = alertDefinitionDAO.findById(Long.parseLong(id));
@@ -208,14 +218,14 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
           results.add(toResource(false, clusterName, entity, requestPropertyIds));
         }
       } else {
-        
+
         Cluster cluster = null;
         try {
           cluster = getManagementController().getClusters().getCluster(clusterName);
         } catch (AmbariException e) {
           throw new NoSuchResourceException("Parent Cluster resource doesn't exist", e);
         }
-        
+
         List<AlertDefinitionEntity> entities = alertDefinitionDAO.findAll(
             cluster.getClusterId());
 
@@ -224,7 +234,7 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
         }
       }
     }
-    
+
     return results;
   }
 
@@ -236,40 +246,44 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     for (Map<String, Object> requestPropMap : request.getProperties()) {
       for (Map<String, Object> propertyMap : getPropertyMaps(requestPropMap, predicate)) {
         Long id = (Long) propertyMap.get(ALERT_DEF_ID);
-        
+
         AlertDefinitionEntity entity = alertDefinitionDAO.findById(id.longValue());
-        if (null == entity)
+        if (null == entity) {
           continue;
+        }
 
-        if (propertyMap.containsKey(ALERT_DEF_NAME))
+        if (propertyMap.containsKey(ALERT_DEF_NAME)) {
           entity.setDefinitionName((String) propertyMap.get(ALERT_DEF_NAME));
-        
+        }
+
         if (propertyMap.containsKey(ALERT_DEF_ENABLED)) {
           entity.setEnabled(Boolean.parseBoolean(
               (String) propertyMap.get(ALERT_DEF_ENABLED)));
         }
-        
+
         if (propertyMap.containsKey(ALERT_DEF_INTERVAL)) {
           entity.setScheduleInterval(Integer.valueOf(
               (String) propertyMap.get(ALERT_DEF_INTERVAL)));
         }
-                
+
         if (propertyMap.containsKey(ALERT_DEF_SCOPE)){
           Scope scope = null;
           String desiredScope = (String) propertyMap.get(ALERT_DEF_SCOPE);
-              
-          if (null != desiredScope && desiredScope.length() > 0)
+
+          if (null != desiredScope && desiredScope.length() > 0) {
             scope = Scope.valueOf((desiredScope));
-         
+          }
+
           entity.setScope(scope);
         }
-        
 
-        if (propertyMap.containsKey(ALERT_DEF_SOURCE_TYPE))
+
+        if (propertyMap.containsKey(ALERT_DEF_SOURCE_TYPE)) {
           entity.setSourceType((String) propertyMap.get(ALERT_DEF_SOURCE_TYPE));
-          
+        }
+
         JsonObject jsonObj = new JsonObject();
-        
+
         for (Entry<String, Object> entry : propertyMap.entrySet()) {
           String propCat = PropertyHelper.getPropertyCategory(entry.getKey());
           String propName = PropertyHelper.getPropertyName(entry.getKey());
@@ -278,16 +292,16 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
             jsonObj.addProperty(propName, entry.getValue().toString());
           }
         }
-        
+
         entity.setHash(UUID.randomUUID().toString());
-        
+
         alertDefinitionDAO.merge(entity);
       }
     }
-    
+
     notifyUpdate(Resource.Type.AlertDefinition, request, predicate);
 
-    return getRequestStatus(null);    
+    return getRequestStatus(null);
   }
 
   @Override
@@ -297,7 +311,7 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
 
     Set<Resource> resources = getResources(
         new RequestImpl(null, null, null, null), predicate);
-    
+
     Set<Long> definitionIds = new HashSet<Long>();
 
     for (final Resource resource : resources) {
@@ -307,7 +321,7 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     for (Long definitionId : definitionIds) {
 
       LOG.info("Deleting alert definition {}", definitionId);
-      
+
       final AlertDefinitionEntity ad = alertDefinitionDAO.findById(definitionId.longValue());
 
       modifyResources(new Command<Void>() {
@@ -323,11 +337,11 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     return getRequestStatus(null);
 
   }
-  
+
   private Resource toResource(boolean isCollection, String clusterName,
       AlertDefinitionEntity entity, Set<String> requestedIds) {
     Resource resource = new ResourceImpl(Resource.Type.AlertDefinition);
-    
+
     setResourceProperty(resource, ALERT_DEF_CLUSTER_NAME, clusterName, requestedIds);
     setResourceProperty(resource, ALERT_DEF_ID, entity.getDefinitionId(), requestedIds);
     setResourceProperty(resource, ALERT_DEF_NAME, entity.getDefinitionName(), requestedIds);
@@ -337,22 +351,24 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     setResourceProperty(resource, ALERT_DEF_ENABLED, Boolean.valueOf(entity.getEnabled()), requestedIds);
     setResourceProperty(resource, ALERT_DEF_SCOPE, entity.getScope(), requestedIds);
     setResourceProperty(resource, ALERT_DEF_SOURCE_TYPE, entity.getSourceType(), requestedIds);
-    
+    setResourceProperty(resource, ALERT_DEF_LABEL, entity.getLabel(),
+        requestedIds);
+
     if (!isCollection && null != resource.getPropertyValue(ALERT_DEF_SOURCE_TYPE)) {
-      
+
       try {
         Map<String, String> map = gson.<Map<String, String>>fromJson(entity.getSource(), Map.class);
-        
+
         for (Entry<String, String> entry : map.entrySet()) {
           String subProp = PropertyHelper.getPropertyId(ALERT_DEF_SOURCE, entry.getKey());
-          resource.setProperty(subProp, entry.getValue());  
+          resource.setProperty(subProp, entry.getValue());
         }
       } catch (Exception e) {
         LOG.error("Could not coerce alert JSON into a type");
       }
     }
-    
+
     return resource;
   }
-  
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/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 23ad8f4..0062388 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
@@ -74,6 +74,9 @@ public class AlertDefinitionEntity {
   @Column(name = "definition_name", nullable = false, length = 255)
   private String definitionName;
 
+  @Column(name = "label", nullable = true, length = 255)
+  private String label;
+
   @Column(name = "scope", length = 255)
   @Enumerated(value = EnumType.STRING)
   private Scope scope;
@@ -353,6 +356,25 @@ public class AlertDefinitionEntity {
   }
 
   /**
+   * Sets a human readable label for this alert definition.
+   * 
+   * @param label
+   *          the label or {@code null} if none.
+   */
+  public void setLabel(String label) {
+    this.label = label;
+  }
+
+  /**
+   * Gets the label for this alert definition.
+   * 
+   * @return the label or {@code null} if none.
+   */
+  public String getLabel() {
+    return label;
+  }
+
+  /**
    * Called before {@link EntityManager#remove(Object)} for this entity, removes
    * the non-owning relationship between definitions and groups.
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/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 bef01c1..144900e 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
@@ -574,6 +574,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
     columns.add(new DBColumnInfo("service_name", String.class, 255, null, false));
     columns.add(new DBColumnInfo("component_name", String.class, 255, null, true));
     columns.add(new DBColumnInfo("scope", String.class, 255, null, true));
+    columns.add(new DBColumnInfo("label", String.class, 255, null, true));
     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));

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/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 b39ca5d..fe39612 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -157,6 +157,7 @@ CREATE TABLE alert_definition (
   service_name VARCHAR(255) NOT NULL,
   component_name VARCHAR(255),
   scope VARCHAR(255),
+  label VARCHAR(255),
   enabled SMALLINT DEFAULT 1 NOT NULL,
   schedule_interval INTEGER NOT NULL,
   source_type VARCHAR(255) NOT NULL,

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/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 500313b..e311646 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -148,6 +148,7 @@ CREATE TABLE alert_definition (
   service_name VARCHAR2(255) NOT NULL,
   component_name VARCHAR2(255),
   scope VARCHAR2(255),
+  label VARCHAR2(255),
   enabled NUMBER(1) DEFAULT 1 NOT NULL,
   schedule_interval NUMBER(10) NOT NULL,
   source_type VARCHAR2(255) NOT NULL,

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/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 a13f415..25d973f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -181,6 +181,7 @@ CREATE TABLE alert_definition (
   service_name VARCHAR(255) NOT NULL,
   component_name VARCHAR(255),
   scope VARCHAR(255),
+  label VARCHAR(255),
   enabled SMALLINT DEFAULT 1 NOT NULL,
   schedule_interval INTEGER NOT NULL,
   source_type VARCHAR(255) NOT NULL,

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/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 ff38b24..2d5b267 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
@@ -246,6 +246,7 @@ CREATE TABLE ambari.alert_definition (
   service_name VARCHAR(255) NOT NULL,
   component_name VARCHAR(255),
   scope VARCHAR(255),
+  label VARCHAR(255),
   enabled SMALLINT DEFAULT 1 NOT NULL,
   schedule_interval INTEGER NOT NULL,
   source_type VARCHAR(255) NOT NULL,

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/ambari-server/src/main/resources/properties.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/properties.json b/ambari-server/src/main/resources/properties.json
index 55b451e..aa2bf71 100644
--- a/ambari-server/src/main/resources/properties.json
+++ b/ambari-server/src/main/resources/properties.json
@@ -416,6 +416,7 @@
       "AlertDefinition/component_name",
       "AlertDefinition/id",
       "AlertDefinition/name",
+      "AlertDefinition/label",
       "AlertDefinition/interval",
       "AlertDefinition/enabled",
       "AlertDefinition/scope",

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
index fc57389..bf51ecb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
@@ -56,91 +56,98 @@ import org.junit.Test;
 public class AlertDefinitionResourceProviderTest {
 
   AlertDefinitionDAO dao = null;
-  
+
   @Before
   public void before() {
     dao = createStrictMock(AlertDefinitionDAO.class);
-    
+
     AlertDefinitionResourceProvider.init(dao);
   }
-  
+
   @Test
   public void testGetResourcesNoPredicate() throws Exception {
     AlertDefinitionResourceProvider provider = createProvider(null);
-    
+
     Request request = PropertyHelper.getReadRequest("AlertDefinition/cluster_name",
         "AlertDefinition/id");
-    
+
     Set<Resource> results = provider.getResources(request, null);
-    
+
     assertEquals(0, results.size());
-  }  
+  }
 
   @Test
   public void testGetResourcesClusterPredicate() throws Exception {
     Request request = PropertyHelper.getReadRequest(
         AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME,
         AlertDefinitionResourceProvider.ALERT_DEF_ID,
-        AlertDefinitionResourceProvider.ALERT_DEF_NAME);
-    
+        AlertDefinitionResourceProvider.ALERT_DEF_NAME,
+        AlertDefinitionResourceProvider.ALERT_DEF_LABEL);
+
     AmbariManagementController amc = createMock(AmbariManagementController.class);
     Clusters clusters = createMock(Clusters.class);
     Cluster cluster = createMock(Cluster.class);
     expect(amc.getClusters()).andReturn(clusters).atLeastOnce();
     expect(clusters.getCluster((String) anyObject())).andReturn(cluster).atLeastOnce();
     expect(cluster.getClusterId()).andReturn(Long.valueOf(1)).anyTimes();
-    
+
     Predicate predicate = new PredicateBuilder().property(
-        AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME).equals("c1").toPredicate();    
-    
+        AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME).equals("c1").toPredicate();
+
     expect(dao.findAll(1L)).andReturn(getMockEntities());
 
     replay(amc, clusters, cluster, dao);
-    
-    AlertDefinitionResourceProvider provider = createProvider(amc);    
+
+    AlertDefinitionResourceProvider provider = createProvider(amc);
     Set<Resource> results = provider.getResources(request, predicate);
-    
+
     assertEquals(1, results.size());
-    
+
     Resource r = results.iterator().next();
-    
+
     Assert.assertEquals("my_def", r.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_NAME));
-    
+
+    Assert.assertEquals("Mock Label",
+        r.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_LABEL));
+
     verify(amc, clusters, cluster, dao);
   }
-  
+
   @Test
   public void testGetSingleResource() throws Exception {
     Request request = PropertyHelper.getReadRequest(
         AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME,
         AlertDefinitionResourceProvider.ALERT_DEF_ID,
         AlertDefinitionResourceProvider.ALERT_DEF_NAME,
+        AlertDefinitionResourceProvider.ALERT_DEF_LABEL,
         AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_TYPE);
-    
+
     AmbariManagementController amc = createMock(AmbariManagementController.class);
     Clusters clusters = createMock(Clusters.class);
     Cluster cluster = createMock(Cluster.class);
     expect(amc.getClusters()).andReturn(clusters).atLeastOnce();
     expect(clusters.getCluster((String) anyObject())).andReturn(cluster).atLeastOnce();
     expect(cluster.getClusterId()).andReturn(Long.valueOf(1)).anyTimes();
-    
+
     Predicate predicate = new PredicateBuilder().property(
         AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME).equals("c1")
-          .and().property(AlertDefinitionResourceProvider.ALERT_DEF_ID).equals("1").toPredicate();    
-    
+          .and().property(AlertDefinitionResourceProvider.ALERT_DEF_ID).equals("1").toPredicate();
+
     expect(dao.findById(1L)).andReturn(getMockEntities().get(0));
 
     replay(amc, clusters, cluster, dao);
-    
-    AlertDefinitionResourceProvider provider = createProvider(amc);    
+
+    AlertDefinitionResourceProvider provider = createProvider(amc);
     Set<Resource> results = provider.getResources(request, predicate);
-    
+
     assertEquals(1, results.size());
-    
+
     Resource r = results.iterator().next();
-    
+
     Assert.assertEquals("my_def", r.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_NAME));
     Assert.assertEquals("metric", r.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_TYPE));
+    Assert.assertEquals("Mock Label",
+        r.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_LABEL));
     Assert.assertNotNull(r.getPropertyValue("AlertDefinition/source/type"));
   }
 
@@ -156,24 +163,26 @@ public class AlertDefinitionResourceProviderTest {
     Capture<AlertDefinitionEntity> entityCapture = new Capture<AlertDefinitionEntity>();
     dao.create(capture(entityCapture));
     expectLastCall();
-    
+
     replay(amc, clusters, cluster, dao);
-    
+
     AlertDefinitionResourceProvider provider = createProvider(amc);
-    
+
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME, "c1");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_INTERVAL, "1");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_NAME, "my_def");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SERVICE_NAME, "HDFS");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_TYPE, "METRIC");
-    
+    requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_LABEL,
+        "Mock Label (Create)");
+
     Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
 
     provider.createResources(request);
-    
+
     Assert.assertTrue(entityCapture.hasCaptured());
-    AlertDefinitionEntity entity = entityCapture.getValue(); 
+    AlertDefinitionEntity entity = entityCapture.getValue();
     Assert.assertNotNull(entity);
 
     Assert.assertEquals(Long.valueOf(1), entity.getClusterId());
@@ -186,11 +195,12 @@ public class AlertDefinitionResourceProviderTest {
     Assert.assertEquals("HDFS", entity.getServiceName());
     Assert.assertNotNull(entity.getSource());
     Assert.assertEquals("METRIC", entity.getSourceType());
-    
+    Assert.assertEquals("Mock Label (Create)", entity.getLabel());
+
     verify(amc, clusters, cluster, dao);
 
   }
-  
+
   @Test
   public void testUpdateResources() throws Exception {
     AmbariManagementController amc = createMock(AmbariManagementController.class);
@@ -203,40 +213,40 @@ public class AlertDefinitionResourceProviderTest {
     Capture<AlertDefinitionEntity> entityCapture = new Capture<AlertDefinitionEntity>();
     dao.create(capture(entityCapture));
     expectLastCall();
-    
+
     replay(amc, clusters, cluster, dao);
-    
+
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME, "c1");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_INTERVAL, "1");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_NAME, "my_def");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SERVICE_NAME, "HDFS");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_TYPE, "METRIC");
-    
+
     Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
 
     AlertDefinitionResourceProvider provider = createProvider(amc);
-    
+
     provider.createResources(request);
-    
+
     Assert.assertTrue(entityCapture.hasCaptured());
-    AlertDefinitionEntity entity = entityCapture.getValue(); 
+    AlertDefinitionEntity entity = entityCapture.getValue();
     Assert.assertNotNull(entity);
-    
+
     Predicate p = new PredicateBuilder().property(
         AlertDefinitionResourceProvider.ALERT_DEF_ID).equals("1").and().property(
             AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME).equals("c1").toPredicate();
     // everything is mocked, there is no DB
     entity.setDefinitionId(Long.valueOf(1));
-    
+
     String oldName = entity.getDefinitionName();
     String oldHash = entity.getHash();
-    
+
     resetToStrict(dao);
     expect(dao.findById(1L)).andReturn(entity).anyTimes();
     expect(dao.merge((AlertDefinitionEntity) anyObject())).andReturn(entity).anyTimes();
     replay(dao);
-    
+
     requestProps = new HashMap<String, Object>();
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME, "c1");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_INTERVAL, "1");
@@ -244,15 +254,15 @@ public class AlertDefinitionResourceProviderTest {
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SERVICE_NAME, "HDFS");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_TYPE, "METRIC");
     request = PropertyHelper.getUpdateRequest(requestProps, null);
-    
+
     provider.updateResources(request, p);
 
     Assert.assertFalse(oldHash.equals(entity.getHash()));
     Assert.assertFalse(oldName.equals(entity.getDefinitionName()));
-    
+
     verify(amc, clusters, cluster, dao);
   }
-  
+
   @Test
   public void testDeleteResources() throws Exception {
     AmbariManagementController amc = createMock(AmbariManagementController.class);
@@ -265,9 +275,9 @@ public class AlertDefinitionResourceProviderTest {
     Capture<AlertDefinitionEntity> entityCapture = new Capture<AlertDefinitionEntity>();
     dao.create(capture(entityCapture));
     expectLastCall();
-    
+
     replay(amc, clusters, cluster, dao);
-    
+
     AlertDefinitionResourceProvider provider = createProvider(amc);
 
     Map<String, Object> requestProps = new HashMap<String, Object>();
@@ -276,57 +286,58 @@ public class AlertDefinitionResourceProviderTest {
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_NAME, "my_def");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SERVICE_NAME, "HDFS");
     requestProps.put(AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_TYPE, "METRIC");
-    
+
     Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
 
     provider.createResources(request);
 
     Assert.assertTrue(entityCapture.hasCaptured());
-    AlertDefinitionEntity entity = entityCapture.getValue(); 
+    AlertDefinitionEntity entity = entityCapture.getValue();
     Assert.assertNotNull(entity);
-    
+
     Predicate p = new PredicateBuilder().property(
         AlertDefinitionResourceProvider.ALERT_DEF_ID).equals("1").and().property(
             AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME).equals("c1").toPredicate();
     // everything is mocked, there is no DB
     entity.setDefinitionId(Long.valueOf(1));
-    
+
     resetToStrict(dao);
     expect(dao.findById(1L)).andReturn(entity).anyTimes();
     dao.remove(capture(entityCapture));
     expectLastCall();
     replay(dao);
-    
+
     provider.deleteResources(p);
-    
+
     AlertDefinitionEntity entity1 = entityCapture.getValue();
     Assert.assertEquals(Long.valueOf(1), entity1.getDefinitionId());
-    
+
     verify(amc, clusters, cluster, dao);
-    
+
   }
-  
+
   private AlertDefinitionResourceProvider createProvider(AmbariManagementController amc) {
     return new AlertDefinitionResourceProvider(
         PropertyHelper.getPropertyIds(Resource.Type.AlertDefinition),
         PropertyHelper.getKeyPropertyIds(Resource.Type.AlertDefinition),
         amc);
   }
-  
+
   private List<AlertDefinitionEntity> getMockEntities() {
     AlertDefinitionEntity entity = new AlertDefinitionEntity();
     entity.setClusterId(Long.valueOf(1L));
     entity.setComponentName(null);
     entity.setDefinitionId(Long.valueOf(1L));
     entity.setDefinitionName("my_def");
+    entity.setLabel("Mock Label");
     entity.setEnabled(true);
     entity.setHash("tmphash");
     entity.setScheduleInterval(Integer.valueOf(2));
     entity.setServiceName(null);
     entity.setSourceType("metric");
     entity.setSource("{'jmx': 'beanName/attributeName', 'host': '{{aa:123445}}'}");
-    
+
     return Arrays.asList(entity);
   }
-  
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bbd9179a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
index 4033f03..6262a2b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
@@ -197,7 +197,7 @@ public class UpgradeCatalog170Test {
     assertViewColumns(maskColumnCapture);
     assertViewParameterColumns(maskedColumnCapture);
 
-    assertEquals(11, alertDefinitionColumnCapture.getValue().size());
+    assertEquals(12, alertDefinitionColumnCapture.getValue().size());
     assertEquals(11, alertHistoryColumnCapture.getValue().size());
     assertEquals(6, alertCurrentColumnCapture.getValue().size());
     assertEquals(4, alertGroupColumnCapture.getValue().size());
@@ -282,7 +282,7 @@ public class UpgradeCatalog170Test {
     upgradeCatalog.updateConfigurationProperties("hbase-env",
         Collections.singletonMap("hbase_regionserver_xmn_ratio", "0.2"), false, false);
     expectLastCall();
-    
+
     upgradeCatalog.updateConfigurationProperties("yarn-env",
         Collections.singletonMap("min_user_id", "1000"), false, false);
     expectLastCall();