[ 
https://issues.apache.org/jira/browse/AMBARI-22739?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16318358#comment-16318358
 ] 

ASF GitHub Bot commented on AMBARI-22739:
-----------------------------------------

mpapirkovskyy closed pull request #72: [AMBARI-22739] Add event for changes in 
alert groups
URL: https://github.com/apache/ambari/pull/72
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/AlertGroupUpdate.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/AlertGroupUpdate.java
new file mode 100644
index 00000000000..89b61b0a08f
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/AlertGroupUpdate.java
@@ -0,0 +1,124 @@
+/*
+ * 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.agent.stomp.dto;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.ambari.server.orm.entities.AlertGroupEntity;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class AlertGroupUpdate {
+
+  @JsonProperty("cluster_id")
+  private Long clusterId;
+
+  @JsonProperty("default")
+  private Boolean defaultGroup;
+
+  @JsonProperty("definitions")
+  private List<Long> definitions;
+
+  @JsonProperty("id")
+  private Long id;
+
+  @JsonProperty("name")
+  private String name;
+
+  @JsonProperty("service_name")
+  private String serviceName;
+
+  @JsonProperty("targets")
+  private List<Long> targets;
+
+  public AlertGroupUpdate(AlertGroupEntity alertGroupEntity) {
+    this.clusterId = alertGroupEntity.getClusterId();
+    this.defaultGroup = alertGroupEntity.isDefault();
+    this.definitions = 
alertGroupEntity.getAlertDefinitions().stream().map((al) -> 
al.getDefinitionId())
+        .collect(Collectors.toList());
+    this.id = alertGroupEntity.getGroupId();
+    this.name = alertGroupEntity.getGroupName();
+    this.serviceName = alertGroupEntity.getServiceName();
+    this.targets = alertGroupEntity.getAlertTargets().stream().map((at) -> 
at.getTargetId())
+        .collect(Collectors.toList());
+  }
+
+  public AlertGroupUpdate(Long id) {
+    this.id = id;
+  }
+
+  public Long getClusterId() {
+    return clusterId;
+  }
+
+  public void setClusterId(Long clusterId) {
+    this.clusterId = clusterId;
+  }
+
+  public Boolean getDefaultGroup() {
+    return defaultGroup;
+  }
+
+  public void setDefaultGroup(Boolean defaultGroup) {
+    this.defaultGroup = defaultGroup;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public List<Long> getDefinitions() {
+    return definitions;
+  }
+
+  public void setDefinitions(List<Long> definitions) {
+    this.definitions = definitions;
+  }
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  public List<Long> getTargets() {
+    return targets;
+  }
+
+  public void setTargets(List<Long> targets) {
+    this.targets = targets;
+  }
+}
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
index e707496542d..a3e0a1b2d19 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -29,6 +30,7 @@
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.StaticallyInject;
+import org.apache.ambari.server.agent.stomp.dto.AlertGroupUpdate;
 import org.apache.ambari.server.controller.AlertDefinitionResponse;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
@@ -40,6 +42,9 @@
 import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.events.AlertGroupsUpdateEvent;
+import org.apache.ambari.server.events.UpdateEventType;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.AlertDispatchDAO;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
@@ -112,6 +117,9 @@
   @Inject
   private static AlertDefinitionDAO s_definitionDao;
 
+  @Inject
+  private static StateUpdateEventPublisher stateUpdateEventPublisher;
+
   /**
    * Constructor.
    *
@@ -395,6 +403,10 @@ private void updateAlertGroups(Set<Map<String, Object>> 
requestMaps)
       }
 
       s_dao.merge(entity);
+      AlertGroupsUpdateEvent alertGroupsUpdateEvent = new 
AlertGroupsUpdateEvent(Collections.singletonList(
+          new AlertGroupUpdate(entity)),
+          UpdateEventType.UPDATE);
+      stateUpdateEventPublisher.publish(alertGroupsUpdateEvent);
     }
   }
 
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/events/AlertGroupsUpdateEvent.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/events/AlertGroupsUpdateEvent.java
new file mode 100644
index 00000000000..12eebedc18f
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/events/AlertGroupsUpdateEvent.java
@@ -0,0 +1,55 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ambari.server.agent.stomp.dto.AlertGroupUpdate;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+public class AlertGroupsUpdateEvent extends AmbariUpdateEvent {
+
+  @JsonProperty("groups")
+  private List<AlertGroupUpdate> groups;
+
+  @JsonProperty("updateType")
+  private UpdateEventType type;
+
+  public AlertGroupsUpdateEvent(List<AlertGroupUpdate> groups, UpdateEventType 
type) {
+    super(Type.ALERT_GROUP);
+    this.groups = groups;
+    this.type = type;
+  }
+
+  public static AlertGroupsUpdateEvent deleteAlertGroupsUpdateEvent(List<Long> 
alertGroupIdsToDelete) {
+    List<AlertGroupUpdate> alertGroupUpdates = new 
ArrayList<>(alertGroupIdsToDelete.size());
+    for (Long alertGroupIdToDelete : alertGroupIdsToDelete) {
+      alertGroupUpdates.add(new AlertGroupUpdate(alertGroupIdToDelete));
+    }
+    return new AlertGroupsUpdateEvent(alertGroupUpdates, 
UpdateEventType.DELETE);
+  }
+
+  public List<AlertGroupUpdate> getGroups() {
+    return groups;
+  }
+}
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariUpdateEvent.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariUpdateEvent.java
index cfd910b94bb..4a522bac531 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariUpdateEvent.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariUpdateEvent.java
@@ -45,6 +45,7 @@ public String getMetricName() {
 
   public enum Type {
     ALERT("events.alerts"),
+    ALERT_GROUP("events.alert_group"),
     METADATA("events.metadata"),
     HOSTLEVELPARAMS("events.hostlevelparams"),
     UI_TOPOLOGY("events.topology_update"),
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/events/DefaultMessageEmitter.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/events/DefaultMessageEmitter.java
index 3ae5955d497..254a652449b 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/events/DefaultMessageEmitter.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/events/DefaultMessageEmitter.java
@@ -30,6 +30,7 @@
   private final Map<AmbariUpdateEvent.Type, String> DEFAULT_DESTINATIONS =
       Collections.unmodifiableMap(new HashMap<AmbariUpdateEvent.Type, 
String>(){{
         put(AmbariUpdateEvent.Type.ALERT, "/events/alerts");
+        put(AmbariUpdateEvent.Type.ALERT_GROUP, "/events/alert_group");
         put(AmbariUpdateEvent.Type.METADATA, "/events/metadata");
         put(AmbariUpdateEvent.Type.HOSTLEVELPARAMS, "/host_level_params");
         put(AmbariUpdateEvent.Type.UI_TOPOLOGY, "/events/ui_topologies");
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/events/UpdateEventType.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/events/UpdateEventType.java
new file mode 100644
index 00000000000..8cf97293b88
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/events/UpdateEventType.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Is used to inform the agent about update assignment.
+ */
+//TODO refactor other update events to use this class instead own update types.
+public enum UpdateEventType {
+  CREATE,
+  UPDATE,
+  DELETE;
+}
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertGroupsUpdateListener.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertGroupsUpdateListener.java
new file mode 100644
index 00000000000..9fef7668c58
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertGroupsUpdateListener.java
@@ -0,0 +1,69 @@
+/*
+ * 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.listeners.alerts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.EagerSingleton;
+import org.apache.ambari.server.agent.stomp.dto.AlertGroupUpdate;
+import org.apache.ambari.server.events.AlertDefinitionDeleteEvent;
+import org.apache.ambari.server.events.AlertGroupsUpdateEvent;
+import org.apache.ambari.server.events.UpdateEventType;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
+import org.apache.ambari.server.orm.dao.AlertDispatchDAO;
+import org.apache.ambari.server.orm.entities.AlertGroupEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+@EagerSingleton
+public class AlertGroupsUpdateListener {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(AlertGroupsUpdateListener.class);
+
+  @Inject
+  private StateUpdateEventPublisher stateUpdateEventPublisher;
+
+  @Inject
+  private AlertDispatchDAO alertDispatchDAO;
+
+  @Inject
+  public AlertGroupsUpdateListener(AmbariEventPublisher ambariEventPublisher) {
+    ambariEventPublisher.register(this);
+  }
+
+  @Subscribe
+  public void onAlertDefinitionDeleted(AlertDefinitionDeleteEvent event) 
throws AmbariException {
+    List<AlertGroupUpdate> alertGroupUpdates = new ArrayList<>();
+    for (AlertGroupEntity alertGroupEntity : 
alertDispatchDAO.findAllGroups(event.getClusterId())) {
+      if 
(alertGroupEntity.getAlertDefinitions().contains(event.getDefinition().getDefinitionId()))
 {
+        AlertGroupUpdate alertGroupUpdate = new 
AlertGroupUpdate(alertGroupEntity);
+        
alertGroupUpdate.getTargets().remove(event.getDefinition().getDefinitionId());
+        alertGroupUpdates.add(alertGroupUpdate);
+      }
+    }
+    stateUpdateEventPublisher.publish(new 
AlertGroupsUpdateEvent(alertGroupUpdates, UpdateEventType.UPDATE));
+  }
+}
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
index 9fdba33e9e3..c8508fcec66 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
@@ -25,13 +25,17 @@
 import javax.persistence.TypedQuery;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.agent.stomp.dto.AlertGroupUpdate;
 import org.apache.ambari.server.controller.RootComponent;
 import org.apache.ambari.server.controller.RootService;
 import 
org.apache.ambari.server.controller.internal.AlertDefinitionResourceProvider;
 import org.apache.ambari.server.events.AlertDefinitionChangedEvent;
 import org.apache.ambari.server.events.AlertDefinitionDeleteEvent;
 import org.apache.ambari.server.events.AlertDefinitionRegistrationEvent;
+import org.apache.ambari.server.events.AlertGroupsUpdateEvent;
+import org.apache.ambari.server.events.UpdateEventType;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.AlertGroupEntity;
@@ -101,6 +105,9 @@
   @Inject
   private AlertDefinitionFactory alertDefinitionFactory;
 
+  @Inject
+  private StateUpdateEventPublisher stateUpdateEventPublisher;
+
   /**
    * Gets an alert definition with the specified ID.
    *
@@ -347,6 +354,10 @@ public void create(AlertDefinitionEntity alertDefinition)
     }
 
     group.addAlertDefinition(alertDefinition);
+    AlertGroupsUpdateEvent alertGroupsUpdateEvent = new 
AlertGroupsUpdateEvent(Collections.singletonList(
+        new AlertGroupUpdate(group)),
+        UpdateEventType.UPDATE);
+    stateUpdateEventPublisher.publish(alertGroupsUpdateEvent);
     dispatchDao.merge(group);
 
     // publish the alert definition registration
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
index 17460481131..e6ac4665811 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
@@ -19,9 +19,11 @@
 
 import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.locks.Lock;
+import java.util.stream.Collectors;
 
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
@@ -30,12 +32,16 @@
 import javax.persistence.metamodel.SingularAttribute;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.agent.stomp.dto.AlertGroupUpdate;
 import org.apache.ambari.server.api.query.JpaPredicateVisitor;
 import org.apache.ambari.server.api.query.JpaSortBuilder;
 import org.apache.ambari.server.controller.AlertNoticeRequest;
 import org.apache.ambari.server.controller.RootService;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.events.AlertGroupsUpdateEvent;
+import org.apache.ambari.server.events.UpdateEventType;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.AlertGroupEntity;
@@ -82,6 +88,9 @@
   @Inject
   private Provider<Clusters> m_clusters;
 
+  @Inject
+  private StateUpdateEventPublisher stateUpdateEventPublisher;
+
   /**
    * Used for ensuring that the concurrent nature of the event handler methods
    * don't collide when attempting to creation alert groups for the same
@@ -412,9 +421,14 @@ public void createGroups(List<AlertGroupEntity> entities) {
       return;
     }
 
+    List<AlertGroupUpdate> alertGroupUpdates = new 
ArrayList<>(entities.size());
     for (AlertGroupEntity entity : entities) {
-      create(entity);
+      create(entity, false);
+      alertGroupUpdates.add(new AlertGroupUpdate(entity));
     }
+    AlertGroupsUpdateEvent alertGroupsUpdateEvent = new 
AlertGroupsUpdateEvent(alertGroupUpdates,
+        UpdateEventType.CREATE);
+    stateUpdateEventPublisher.publish(alertGroupsUpdateEvent);
   }
 
   /**
@@ -425,6 +439,18 @@ public void createGroups(List<AlertGroupEntity> entities) {
    */
   @Transactional
   public void create(AlertGroupEntity group) {
+    create(group, true);
+  }
+
+  /**
+   * Persists a new alert group.
+   *
+   * @param group the group to persist (not {@code null}).
+   * @param fireEvent should alert group update event to be fired
+   */
+  @Transactional
+  public void create(AlertGroupEntity group, boolean fireEvent) {
+
     entityManagerProvider.get().persist(group);
 
     // associate the group with all alert targets
@@ -435,6 +461,12 @@ public void create(AlertGroupEntity group) {
       }
       entityManagerProvider.get().merge(group);
     }
+    if (fireEvent) {
+      AlertGroupsUpdateEvent alertGroupsUpdateEvent = new 
AlertGroupsUpdateEvent(
+          Collections.singletonList(new AlertGroupUpdate(group)),
+          UpdateEventType.CREATE);
+      stateUpdateEventPublisher.publish(alertGroupsUpdateEvent);
+    }
   }
 
   /**
@@ -518,7 +550,23 @@ public AlertGroupEntity merge(AlertGroupEntity alertGroup) 
{
    */
   @Transactional
   public void remove(AlertGroupEntity alertGroup) {
+    remove(alertGroup, true);
+  }
+
+  /**
+   * Removes the specified alert group from the database.
+   *
+   * @param alertGroup the group to remove.
+   * @param fireEvent should alert group update event to be fired.
+   */
+  @Transactional
+  public void remove(AlertGroupEntity alertGroup, boolean fireEvent) {
     entityManagerProvider.get().remove(merge(alertGroup));
+    if (fireEvent) {
+      AlertGroupsUpdateEvent alertGroupsUpdateEvent = 
AlertGroupsUpdateEvent.deleteAlertGroupsUpdateEvent(
+          Collections.singletonList(alertGroup.getGroupId()));
+      stateUpdateEventPublisher.publish(alertGroupsUpdateEvent);
+    }
   }
 
   /**
@@ -532,8 +580,11 @@ public void remove(AlertGroupEntity alertGroup) {
   public void removeAllGroups(long clusterId) {
     List<AlertGroupEntity> groups = findAllGroups(clusterId);
     for (AlertGroupEntity group : groups) {
-      remove(group);
+      remove(group, false);
     }
+    AlertGroupsUpdateEvent alertGroupsUpdateEvent = 
AlertGroupsUpdateEvent.deleteAlertGroupsUpdateEvent(
+        
groups.stream().map(AlertGroupEntity::getGroupId).collect(Collectors.toList()));
+    stateUpdateEventPublisher.publish(alertGroupsUpdateEvent);
   }
 
   /**
@@ -594,6 +645,10 @@ public void create(AlertTargetEntity alertTarget) {
       for (AlertGroupEntity group : groups) {
         group.addAlertTarget(alertTarget);
         merge(group);
+        AlertGroupsUpdateEvent alertGroupsUpdateEvent = new 
AlertGroupsUpdateEvent(Collections.singletonList(
+            new AlertGroupUpdate(group)),
+            UpdateEventType.UPDATE);
+        stateUpdateEventPublisher.publish(alertGroupsUpdateEvent);
       }
     }
   }
@@ -629,6 +684,13 @@ public AlertTargetEntity merge(AlertTargetEntity 
alertTarget) {
    */
   @Transactional
   public void remove(AlertTargetEntity alertTarget) {
+    List<AlertGroupUpdate> alertGroupUpdates = new ArrayList<>();
+    for (AlertGroupEntity alertGroupEntity : alertTarget.getAlertGroups()) {
+      AlertGroupUpdate alertGroupUpdate = new 
AlertGroupUpdate(alertGroupEntity);
+      alertGroupUpdate.getTargets().remove(alertTarget.getTargetId());
+      alertGroupUpdates.add(alertGroupUpdate);
+    }
+    stateUpdateEventPublisher.publish(new 
AlertGroupsUpdateEvent(alertGroupUpdates, UpdateEventType.UPDATE));
     entityManagerProvider.get().remove(alertTarget);
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add event for changes in alert groups
> -------------------------------------
>
>                 Key: AMBARI-22739
>                 URL: https://issues.apache.org/jira/browse/AMBARI-22739
>             Project: Ambari
>          Issue Type: Task
>          Components: ambari-server
>    Affects Versions: 3.0.0
>            Reporter: Myroslav Papirkovskyi
>            Assignee: Myroslav Papirkovskyi
>             Fix For: 3.0.0
>
>
> Server should raise events to publish created/removed/updated alert groups to 
> STOMP topic.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to