Explorar el Código

AMBARI-9781 - Aggregate Alerts Are Not Calculated When Receiving the Initial Alert Instance (jonathanhurley)

Jonathan Hurley hace 10 años
padre
commit
d9af23b180

+ 90 - 0
ambari-server/src/main/java/org/apache/ambari/server/events/InitialAlertEvent.java

@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.events;
+
+import org.apache.ambari.server.orm.entities.AlertCurrentEntity;
+import org.apache.ambari.server.orm.entities.AlertHistoryEntity;
+import org.apache.ambari.server.state.Alert;
+
+/**
+ * The {@link InitialAlertEvent} is fired the first time that an alert is
+ * received from an agent. This is different from a
+ * {@link AlertStateChangeEvent} since there is no state change occurring for
+ * the first alert being received.
+ */
+public class InitialAlertEvent extends AlertEvent {
+
+  /**
+   * The current alert, including state and history.
+   */
+  private final AlertCurrentEntity m_currentAlert;
+
+  /**
+   * The historical record for the initial alert.
+   */
+  private final AlertHistoryEntity m_history;
+
+  /**
+   * Constructor.
+   *
+   * @param clusterId
+   *          the ID of the cluster
+   * @param alert
+   *          the alert that was received.
+   * @param currentAlert
+   *          the current alert created or updated.
+   */
+  public InitialAlertEvent(long clusterId, Alert alert,
+      AlertCurrentEntity currentAlert) {
+    super(clusterId, alert);
+
+    m_currentAlert = currentAlert;
+    m_history = currentAlert.getAlertHistory();
+  }
+
+  /**
+   * Gets the current alert.
+   *
+   * @return the current alert.
+   */
+  public AlertCurrentEntity getCurrentAlert() {
+    return m_currentAlert;
+  }
+
+  /**
+   * Gets the newly created item in alert history.
+   *
+   * @return the newly created historical item.
+   */
+  public AlertHistoryEntity getNewHistoricalEntry() {
+    return m_history;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String toString() {
+    StringBuilder buffer = new StringBuilder("InitialAlertEvent{ ");
+    buffer.append("cluserId=").append(m_clusterId);
+    buffer.append(", alert=").append(m_alert);
+
+    buffer.append("}");
+    return buffer.toString();
+  }
+}

+ 38 - 18
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertAggregateListener.java

@@ -22,6 +22,7 @@ import java.text.MessageFormat;
 import org.apache.ambari.server.EagerSingleton;
 import org.apache.ambari.server.events.AlertReceivedEvent;
 import org.apache.ambari.server.events.AlertStateChangeEvent;
+import org.apache.ambari.server.events.InitialAlertEvent;
 import org.apache.ambari.server.events.publishers.AlertEventPublisher;
 import org.apache.ambari.server.orm.dao.AlertSummaryDTO;
 import org.apache.ambari.server.orm.dao.AlertsDAO;
@@ -72,12 +73,27 @@ public class AlertAggregateListener {
   }
 
   /**
-   * Consume an alert that was received.
+   * Consumes an {@link InitialAlertEvent}.
    */
   @Subscribe
-  public void onAlertEvent(AlertStateChangeEvent event) {
+  public void onInitialAlertEvent(InitialAlertEvent event) {
+    onAlertEvent(event.getClusterId(), event.getAlert());
+  }
+
+  /**
+   * Consumes an {@link AlertStateChangeEvent}.
+   */
+  @Subscribe
+  public void onAlertStateChangeEvent(AlertStateChangeEvent event) {
+    onAlertEvent(event.getClusterId(), event.getAlert());
+  }
+
+  /**
+   * Calculates the aggregate alert state for the aggregated alert specified.
+   */
+  private void onAlertEvent(long clusterId, Alert alert) {
     AlertDefinition aggregateDefinition = m_aggregateMapping.getAggregateDefinition(
-        event.getClusterId(), event.getAlert().getName());
+        clusterId, alert.getName());
 
     if (null == aggregateDefinition || null == m_alertsDao) {
       return;
@@ -85,8 +101,8 @@ public class AlertAggregateListener {
 
     AggregateSource aggregateSource = (AggregateSource) aggregateDefinition.getSource();
 
-    AlertSummaryDTO summary = m_alertsDao.findAggregateCounts(
-        event.getClusterId(), aggregateSource.getAlertName());
+    AlertSummaryDTO summary = m_alertsDao.findAggregateCounts(clusterId,
+        aggregateSource.getAlertName());
 
     // OK should be based off of true OKs and those in maintenance mode
     int okCount = summary.getOkCount() + summary.getMaintenanceCount();
@@ -96,16 +112,16 @@ public class AlertAggregateListener {
     int unknownCount = summary.getUnknownCount();
     int totalCount = okCount + warningCount + criticalCount + unknownCount;
 
-    Alert alert = new Alert(aggregateDefinition.getName(), null,
+    Alert aggregateAlert = new Alert(aggregateDefinition.getName(), null,
         aggregateDefinition.getServiceName(), null, null, AlertState.UNKNOWN);
 
-    alert.setLabel(aggregateDefinition.getLabel());
-    alert.setTimestamp(System.currentTimeMillis());
+    aggregateAlert.setLabel(aggregateDefinition.getLabel());
+    aggregateAlert.setTimestamp(System.currentTimeMillis());
 
     if (0 == totalCount) {
-      alert.setText("There are no instances of the aggregated alert.");
+      aggregateAlert.setText("There are no instances of the aggregated alert.");
     } else if (summary.getUnknownCount() > 0) {
-      alert.setText("There are alerts with a state of UNKNOWN.");
+      aggregateAlert.setText("There are alerts with a state of UNKNOWN.");
     } else {
       Reporting reporting = aggregateSource.getReporting();
 
@@ -115,25 +131,29 @@ public class AlertAggregateListener {
       double value = (double) (numerator) / denominator;
 
       if (value >= reporting.getCritical().getValue()) {
-        alert.setState(AlertState.CRITICAL);
-        alert.setText(MessageFormat.format(reporting.getCritical().getText(),
+        aggregateAlert.setState(AlertState.CRITICAL);
+        aggregateAlert.setText(MessageFormat.format(
+            reporting.getCritical().getText(),
             denominator, numerator));
 
       } else if (value >= reporting.getWarning().getValue()) {
-        alert.setState(AlertState.WARNING);
-        alert.setText(MessageFormat.format(reporting.getWarning().getText(),
+        aggregateAlert.setState(AlertState.WARNING);
+        aggregateAlert.setText(MessageFormat.format(
+            reporting.getWarning().getText(),
             denominator, numerator));
 
       } else {
-        alert.setState(AlertState.OK);
-        alert.setText(MessageFormat.format(reporting.getOk().getText(),
+        aggregateAlert.setState(AlertState.OK);
+        aggregateAlert.setText(MessageFormat.format(
+            reporting.getOk().getText(),
             denominator, numerator));
       }
-
     }
 
     // make a new event and allow others to consume it
-    AlertReceivedEvent aggEvent = new AlertReceivedEvent(event.getClusterId(), alert);
+    AlertReceivedEvent aggEvent = new AlertReceivedEvent(clusterId,
+        aggregateAlert);
+
     m_publisher.publish(aggEvent);
   }
 }

+ 6 - 1
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java

@@ -26,6 +26,7 @@ import org.apache.ambari.server.controller.RootServiceResponseFactory.Services;
 import org.apache.ambari.server.events.AlertEvent;
 import org.apache.ambari.server.events.AlertReceivedEvent;
 import org.apache.ambari.server.events.AlertStateChangeEvent;
+import org.apache.ambari.server.events.InitialAlertEvent;
 import org.apache.ambari.server.events.publishers.AlertEventPublisher;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.AlertsDAO;
@@ -150,9 +151,13 @@ public class AlertReceivedListener {
       current.setAlertHistory(history);
       current.setLatestTimestamp(alert.getTimestamp());
       current.setOriginalTimestamp(Long.valueOf(alert.getTimestamp()));
-
       m_alertsDao.create(current);
 
+      // broadcast the initial alert being received
+      InitialAlertEvent initialAlertEvent = new InitialAlertEvent(
+          event.getClusterId(), event.getAlert(), current);
+
+      m_alertEventPublisher.publish(initialAlertEvent);
     } else if (alert.getState() == current.getAlertHistory().getAlertState()) {
       current.setLatestTimestamp(alert.getTimestamp());
       current.setLatestText(alert.getText());

+ 19 - 19
ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java

@@ -135,10 +135,10 @@ public class EventsTest {
    */
   @Test
   public void testServiceInstalledEvent() throws Exception {
-    Class<?> eventClass = ServiceInstalledEvent.class;
-    Assert.assertFalse(m_listener.isEventReceived(eventClass));
+    Class<? extends AmbariEvent> eventClass = ServiceInstalledEvent.class;
+    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
     installHdfsService();
-    Assert.assertTrue(m_listener.isEventReceived(eventClass));
+    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
   }
 
   /**
@@ -148,11 +148,11 @@ public class EventsTest {
    */
   @Test
   public void testServiceRemovedEvent() throws Exception {
-    Class<?> eventClass = ServiceRemovedEvent.class;
-    Assert.assertFalse(m_listener.isEventReceived(eventClass));
+    Class<? extends AmbariEvent> eventClass = ServiceRemovedEvent.class;
+    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
     installHdfsService();
     m_cluster.deleteAllServices();
-    Assert.assertTrue(m_listener.isEventReceived(eventClass));
+    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
   }
 
   /**
@@ -162,13 +162,13 @@ public class EventsTest {
    */
   @Test
   public void testServiceComponentUninstalledEvent() throws Exception {
-    Class<?> eventClass = ServiceComponentUninstalledEvent.class;
+    Class<? extends AmbariEvent> eventClass = ServiceComponentUninstalledEvent.class;
     installHdfsService();
 
-    Assert.assertFalse(m_listener.isEventReceived(eventClass));
+    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
     m_cluster.getServiceComponentHosts(HOSTNAME).get(0).delete();
 
-    Assert.assertTrue(m_listener.isEventReceived(eventClass));
+    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
   }
 
   /**
@@ -180,32 +180,32 @@ public class EventsTest {
   public void testMaintenanceModeEvents() throws Exception {
     installHdfsService();
     Service service = m_cluster.getService("HDFS");
-    Class<?> eventClass = MaintenanceModeEvent.class;
+    Class<? extends AmbariEvent> eventClass = MaintenanceModeEvent.class;
 
-    Assert.assertFalse(m_listener.isEventReceived(eventClass));
+    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
     service.setMaintenanceState(MaintenanceState.ON);
-    Assert.assertTrue(m_listener.isEventReceived(eventClass));
-    Assert.assertEquals(1, m_listener.getEventReceivedCount(eventClass));
+    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
+    Assert.assertEquals(1, m_listener.getAmbariEventReceivedCount(eventClass));
 
     m_listener.reset();
-    Assert.assertFalse(m_listener.isEventReceived(eventClass));
+    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
 
     List<ServiceComponentHost> componentHosts = m_cluster.getServiceComponentHosts(HOSTNAME);
     ServiceComponentHost componentHost = componentHosts.get(0);
     componentHost.setMaintenanceState(MaintenanceState.OFF);
 
-    Assert.assertTrue(m_listener.isEventReceived(eventClass));
-    Assert.assertEquals(1, m_listener.getEventReceivedCount(eventClass));
+    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
+    Assert.assertEquals(1, m_listener.getAmbariEventReceivedCount(eventClass));
 
     m_listener.reset();
-    Assert.assertFalse(m_listener.isEventReceived(eventClass));
+    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
 
     Host host = m_clusters.getHost(HOSTNAME);
     host.setMaintenanceState(m_cluster.getClusterId(), MaintenanceState.ON);
     host.setMaintenanceState(m_cluster.getClusterId(), MaintenanceState.OFF);
 
-    Assert.assertTrue(m_listener.isEventReceived(eventClass));
-    Assert.assertEquals(2, m_listener.getEventReceivedCount(eventClass));
+    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
+    Assert.assertEquals(2, m_listener.getAmbariEventReceivedCount(eventClass));
   }
 
   /**

+ 55 - 15
ambari-server/src/test/java/org/apache/ambari/server/events/MockEventListener.java

@@ -37,13 +37,20 @@ public class MockEventListener {
    * When an event is received, its class is captured and the event object is
    * added to the list.
    */
-  private final Map<Class<?>, List<Object>> m_receivedEvents = new HashMap<Class<?>, List<Object>>();
+  private final Map<Class<?>, List<Object>> m_receivedAmbariEvents = new HashMap<Class<?>, List<Object>>();
+
+  /**
+   * When an event is received, its class is captured and the event object is
+   * added to the list.
+   */
+  private final Map<Class<?>, List<Object>> m_receivedAlertEvents = new HashMap<Class<?>, List<Object>>();
 
   /**
    * Resets the captured events.
    */
   public void reset() {
-    m_receivedEvents.clear();
+    m_receivedAmbariEvents.clear();
+    m_receivedAlertEvents.clear();
   }
 
   /**
@@ -52,12 +59,40 @@ public class MockEventListener {
    * @param clazz
    * @return
    */
-  public boolean isEventReceived(Class<?> clazz) {
-    if (!m_receivedEvents.containsKey(clazz)) {
+  public boolean isAmbariEventReceived(Class<? extends AmbariEvent> clazz) {
+    if (!m_receivedAmbariEvents.containsKey(clazz)) {
       return false;
     }
 
-    return m_receivedEvents.get(clazz).size() > 0;
+    return m_receivedAmbariEvents.get(clazz).size() > 0;
+  }
+
+  /**
+   * Gets whether an event of the specified class was received.
+   *
+   * @param clazz
+   * @return
+   */
+  public boolean isAlertEventReceived(Class<? extends AlertEvent> clazz) {
+    if (!m_receivedAlertEvents.containsKey(clazz)) {
+      return false;
+    }
+
+    return m_receivedAlertEvents.get(clazz).size() > 0;
+  }
+
+  /**
+   * Gets the total number of events received for the specified class.
+   *
+   * @param clazz
+   * @return
+   */
+  public int getAmbariEventReceivedCount(Class<? extends AmbariEvent> clazz) {
+    if (!m_receivedAmbariEvents.containsKey(clazz)) {
+      return 0;
+    }
+
+    return m_receivedAmbariEvents.get(clazz).size();
   }
 
   /**
@@ -66,32 +101,37 @@ public class MockEventListener {
    * @param clazz
    * @return
    */
-  public int getEventReceivedCount(Class<?> clazz){
-    if (!m_receivedEvents.containsKey(clazz)) {
+  public int getAlertEventReceivedCount(Class<? extends AlertEvent> clazz) {
+    if (!m_receivedAlertEvents.containsKey(clazz)) {
       return 0;
     }
 
-    return m_receivedEvents.get(clazz).size();
+    return m_receivedAlertEvents.get(clazz).size();
   }
 
   /**
    * @param event
    */
   @Subscribe
-  public void onEvent(AmbariEvent event) {
-    handleEvent(event);
+  public void onAmbariEvent(AmbariEvent event) {
+    List<Object> events = m_receivedAmbariEvents.get(event.getClass());
+    if (null == events) {
+      events = new ArrayList<Object>();
+      m_receivedAmbariEvents.put(event.getClass(), events);
+    }
+
+    events.add(event);
   }
 
   /**
-   * Inserts the event into the map of class to event invocations.
-   *
    * @param event
    */
-  private void handleEvent(Object event) {
-    List<Object> events = m_receivedEvents.get(event.getClass());
+  @Subscribe
+  public void onAlertEvent(AlertEvent event) {
+    List<Object> events = m_receivedAlertEvents.get(event.getClass());
     if (null == events) {
       events = new ArrayList<Object>();
-      m_receivedEvents.put(event.getClass(), events);
+      m_receivedAlertEvents.put(event.getClass(), events);
     }
 
     events.add(event);

+ 202 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java

@@ -0,0 +1,202 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.state.alerts;
+
+import java.lang.reflect.Field;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.events.AlertReceivedEvent;
+import org.apache.ambari.server.events.InitialAlertEvent;
+import org.apache.ambari.server.events.MockEventListener;
+import org.apache.ambari.server.events.listeners.alerts.AlertLifecycleListener;
+import org.apache.ambari.server.events.listeners.alerts.AlertReceivedListener;
+import org.apache.ambari.server.events.listeners.alerts.AlertServiceStateListener;
+import org.apache.ambari.server.events.publishers.AlertEventPublisher;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
+import org.apache.ambari.server.orm.dao.AlertsDAO;
+import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
+import org.apache.ambari.server.state.Alert;
+import org.apache.ambari.server.state.AlertState;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.StackId;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.persist.PersistService;
+import com.google.inject.util.Modules;
+
+/**
+ * Tests that {@link InitialAlertEventTest} instances are fired correctly.
+ */
+public class InitialAlertEventTest {
+
+  private AlertsDAO m_alertsDao;
+  private AlertEventPublisher m_eventPublisher;
+  private Injector m_injector;
+  private MockEventListener m_listener;
+
+  private AlertDefinitionDAO m_definitionDao;
+  private Clusters m_clusters;
+  private Cluster m_cluster;
+  private String m_clusterName;
+  private ServiceFactory m_serviceFactory;
+  private AmbariMetaInfo m_metaInfo;
+
+  /**
+   *
+   */
+  @Before
+  public void setup() throws Exception {
+    m_injector = Guice.createInjector(Modules.override(
+        new InMemoryDefaultTestModule()).with(new MockModule()));
+
+    m_injector.getInstance(GuiceJpaInitializer.class);
+
+    // get a mock listener
+    m_listener = m_injector.getInstance(MockEventListener.class);
+
+    m_alertsDao = m_injector.getInstance(AlertsDAO.class);
+
+    // create the publisher and mock listener
+    m_eventPublisher = m_injector.getInstance(AlertEventPublisher.class);
+    EventBus synchronizedBus = new EventBus();
+
+    // register listeners needed
+    synchronizedBus.register(m_listener);
+    synchronizedBus.register(m_injector.getInstance(AlertLifecycleListener.class));
+    synchronizedBus.register(m_injector.getInstance(AlertServiceStateListener.class));
+    synchronizedBus.register(m_injector.getInstance(AlertReceivedListener.class));
+
+    // !!! need a synchronous op for testing
+    Field field = AlertEventPublisher.class.getDeclaredField("m_eventBus");
+    field.setAccessible(true);
+    field.set(m_eventPublisher, synchronizedBus);
+
+    m_definitionDao = m_injector.getInstance(AlertDefinitionDAO.class);
+    m_clusters = m_injector.getInstance(Clusters.class);
+    m_serviceFactory = m_injector.getInstance(ServiceFactory.class);
+
+    m_metaInfo = m_injector.getInstance(AmbariMetaInfo.class);
+    m_metaInfo.init();
+
+    m_clusterName = "c1";
+    m_clusters.addCluster(m_clusterName);
+    m_cluster = m_clusters.getCluster(m_clusterName);
+    m_cluster.setDesiredStackVersion(new StackId("HDP", "2.0.6"));
+    Assert.assertNotNull(m_cluster);
+
+    // install HDFS to get 6 definitions
+    installHdfsService();
+    Assert.assertEquals(1, m_cluster.getServices().size());
+    Assert.assertEquals(6, m_definitionDao.findAll().size());
+  }
+
+  /**
+   * @throws Exception
+   */
+  @After
+  public void teardown() throws Exception {
+    m_injector.getInstance(PersistService.class).stop();
+    m_injector = null;
+  }
+
+  /**
+   * Tests that when a new alert is received that an {@link InitialAlertEvent}
+   * is fired.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testInitialAlertEvent() throws Exception {
+    // ensure there are no historical items
+    Assert.assertEquals(0, m_alertsDao.findAll().size());
+    Assert.assertEquals(0,
+        m_listener.getAlertEventReceivedCount(InitialAlertEvent.class));
+
+    // get a definition to use for the incoming alert
+    AlertDefinitionEntity definition = m_definitionDao.findAll(
+        m_cluster.getClusterId()).get(0);
+
+    // create the "first" alert
+    Alert alert = new Alert(definition.getDefinitionName(), null,
+        definition.getServiceName(), definition.getComponentName(), null,
+        AlertState.OK);
+
+    AlertReceivedEvent event = new AlertReceivedEvent(m_cluster.getClusterId(),
+        alert);
+
+    // public the received event
+    m_eventPublisher.publish(event);
+
+    // ensure we now have a history item
+    Assert.assertEquals(1, m_alertsDao.findAll().size());
+
+    // verify that the initial alert event was triggered
+    Assert.assertEquals(1,
+        m_listener.getAlertEventReceivedCount(InitialAlertEvent.class));
+
+    // clear the initial alert event that was recorded
+    m_listener.reset();
+
+    // alert the alert and re-fire
+    alert.setState(AlertState.WARNING);
+    m_eventPublisher.publish(event);
+
+    // ensure that the initial alert event was NOT received again
+    Assert.assertEquals(0,
+        m_listener.getAlertEventReceivedCount(InitialAlertEvent.class));
+  }
+
+  /**
+   * Calls {@link Service#persist()} to mock a service install.
+   */
+  private void installHdfsService() throws Exception {
+    String serviceName = "HDFS";
+    Service service = m_serviceFactory.createNew(m_cluster, serviceName);
+    m_cluster.addService(service);
+    service.persist();
+    service = m_cluster.getService(serviceName);
+
+    Assert.assertNotNull(service);
+  }
+
+  /**
+   *
+   */
+  private class MockModule implements Module {
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void configure(Binder binder) {
+    }
+  }
+}

+ 4 - 4
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java

@@ -440,7 +440,7 @@ public class AlertDataManagerTest {
     AlertStateChangeEvent event = new AlertStateChangeEvent(
         m_cluster.getClusterId(), alert, current, AlertState.OK);
 
-    listener.onAlertEvent(event);
+    listener.onAlertStateChangeEvent(event);
     assertNotNull(ref.get());
     assertEquals(AlertState.OK, ref.get().getState());
     assertTrue(ref.get().getText().indexOf("0/4") > -1);
@@ -449,7 +449,7 @@ public class AlertDataManagerTest {
     current.getAlertHistory().setAlertState(AlertState.CRITICAL);
     m_dao.merge(current.getAlertHistory());
 
-    listener.onAlertEvent(event);
+    listener.onAlertStateChangeEvent(event);
     assertEquals("aggregate_test", ref.get().getName());
     assertEquals(AlertState.OK, ref.get().getState());
     assertTrue(ref.get().getText().indexOf("1/4") > -1);
@@ -461,7 +461,7 @@ public class AlertDataManagerTest {
     current.getAlertHistory().setAlertState(AlertState.WARNING);
     m_dao.merge(current.getAlertHistory());
 
-    listener.onAlertEvent(event);
+    listener.onAlertStateChangeEvent(event);
     assertEquals("aggregate_test", ref.get().getName());
     assertEquals(AlertState.WARNING, ref.get().getState());
     assertTrue(ref.get().getText().indexOf("2/4") > -1);
@@ -473,7 +473,7 @@ public class AlertDataManagerTest {
     current.getAlertHistory().setAlertState(AlertState.CRITICAL);
     m_dao.merge(current.getAlertHistory());
 
-    listener.onAlertEvent(event);
+    listener.onAlertStateChangeEvent(event);
     assertEquals("aggregate_test", ref.get().getName());
     assertEquals(AlertState.CRITICAL, ref.get().getState());
     assertTrue(ref.get().getText().indexOf("3/4") > -1);