You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2017/06/07 15:51:40 UTC
[2/3] ambari git commit: AMBARI-21193. Add TopologyChange event to
the server (mpapirkovskyy)
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/AlertUpdateEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AlertUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AlertUpdateEvent.java
new file mode 100644
index 0000000..df5ab4d
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AlertUpdateEvent.java
@@ -0,0 +1,45 @@
+/**
+ * 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.state.Alert;
+
+public class AlertUpdateEvent implements AmbariUpdateEvent {
+ private List<Alert> alerts = new ArrayList<>();
+
+ public AlertUpdateEvent(List<Alert> alerts) {
+ this.alerts = alerts;
+ }
+
+ public List<Alert> getAlerts() {
+ return alerts;
+ }
+
+ public void setAlerts(List<Alert> alerts) {
+ this.alerts = alerts;
+ }
+
+ @Override
+ public String getDestination() {
+ return "/events/alerts";
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariUpdateEvent.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..62f253b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariUpdateEvent.java
@@ -0,0 +1,26 @@
+/**
+ * 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.beans.Transient;
+
+public interface AmbariUpdateEvent {
+
+ @Transient
+ String getDestination();
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/CommandEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/CommandEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/CommandEvent.java
new file mode 100644
index 0000000..cee2fa3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/CommandEvent.java
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+public class CommandEvent implements AmbariUpdateEvent {
+ @Override
+ public String getDestination() {
+ return "/command";
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/ConfigsUpdateEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/ConfigsUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/ConfigsUpdateEvent.java
new file mode 100644
index 0000000..738badb
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/ConfigsUpdateEvent.java
@@ -0,0 +1,200 @@
+/**
+ * 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.orm.entities.ClusterConfigEntity;
+import org.apache.ambari.server.orm.entities.ServiceConfigEntity;
+
+public class ConfigsUpdateEvent implements AmbariUpdateEvent {
+
+ private Long serviceConfigId;
+ private Long clusterId;
+ private String serviceName;
+ private Long groupId;
+ private Long version;
+ private String user;
+ private String note;
+ private List<String> hostNames;
+ private Long createtime;
+ private String groupName;
+ //TODO configs
+
+ private List<ClusterConfig> configs = new ArrayList<>();
+
+ public ConfigsUpdateEvent(ServiceConfigEntity configs, String configGroupName, List<String> hostNames) {
+ this.serviceConfigId = configs.getServiceConfigId();
+ this.clusterId = configs.getClusterEntity().getClusterId();
+ this.serviceName = configs.getServiceName();
+ this.groupId = configs.getGroupId();
+ this.version = configs.getVersion();
+ this.user = configs.getUser();
+ this.note = configs.getNote();
+ this.hostNames = hostNames == null ? null : new ArrayList<>(hostNames);
+ for (ClusterConfigEntity clusterConfigEntity : configs.getClusterConfigEntities()) {
+ this.configs.add(new ClusterConfig(clusterConfigEntity.getClusterId(),
+ clusterConfigEntity.getType(),
+ clusterConfigEntity.getTag(),
+ clusterConfigEntity.getVersion()));
+ }
+ this.createtime = configs.getCreateTimestamp();
+ this.groupName = configGroupName;
+ }
+
+ public Long getServiceConfigId() {
+ return serviceConfigId;
+ }
+
+ public void setServiceConfigId(Long serviceConfigId) {
+ this.serviceConfigId = serviceConfigId;
+ }
+
+ public Long getClusterId() {
+ return clusterId;
+ }
+
+ public void setClusterId(Long clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public Long getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(Long groupId) {
+ this.groupId = groupId;
+ }
+
+ public Long getVersion() {
+ return version;
+ }
+
+ public void setVersion(Long version) {
+ this.version = version;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getNote() {
+ return note;
+ }
+
+ public void setNote(String note) {
+ this.note = note;
+ }
+
+ public List<String> getHostNames() {
+ return hostNames;
+ }
+
+ public void setHostNames(List<String> hostNames) {
+ this.hostNames = hostNames;
+ }
+
+ public List<ClusterConfig> getConfigs() {
+ return configs;
+ }
+
+ public void setConfigs(List<ClusterConfig> configs) {
+ this.configs = configs;
+ }
+
+ public Long getCreatetime() {
+ return createtime;
+ }
+
+ public void setCreatetime(Long createtime) {
+ this.createtime = createtime;
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ @Override
+ public String getDestination() {
+ return "/events/configs";
+ }
+
+ public class ClusterConfig {
+ private Long clusterId;
+ private String type;
+ private String tag;
+ private Long version;
+
+ public ClusterConfig(Long clusterId, String type, String tag, Long version) {
+ this.clusterId = clusterId;
+ this.type = type;
+ this.tag = tag;
+ this.version = version;
+ }
+
+ public Long getClusterId() {
+ return clusterId;
+ }
+
+ public void setClusterId(Long clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ public Long getVersion() {
+ return version;
+ }
+
+ public void setVersion(Long version) {
+ this.version = version;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdateEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdateEvent.java
new file mode 100644
index 0000000..7500fca
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdateEvent.java
@@ -0,0 +1,94 @@
+/**
+ * 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.HostComponentStateEntity;
+import org.apache.ambari.server.state.State;
+
+public class HostComponentUpdateEvent implements AmbariUpdateEvent {
+
+ private Long id;
+ private Long clusterId;
+ private String serviceName;
+ private String hostName;
+ private String componentName;
+ private State currentState;
+
+ public HostComponentUpdateEvent(HostComponentStateEntity stateEntity) {
+ this.id = stateEntity.getId();
+ this.clusterId = stateEntity.getClusterId();
+ this.serviceName = stateEntity.getServiceName();
+ this.hostName = stateEntity.getHostEntity().getHostName();
+ this.currentState = stateEntity.getCurrentState();
+ this.componentName = stateEntity.getComponentName();
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getClusterId() {
+ return clusterId;
+ }
+
+ public void setClusterId(Long clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ public String getComponentName() {
+ return componentName;
+ }
+
+ public void setComponentName(String componentName) {
+ this.componentName = componentName;
+ }
+
+ public State getCurrentState() {
+ return currentState;
+ }
+
+ public void setCurrentState(State currentState) {
+ this.currentState = currentState;
+ }
+
+ @Override
+ public String getDestination() {
+ return "/events/hostcomponents";
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/MetadataUpdateEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/MetadataUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/MetadataUpdateEvent.java
new file mode 100644
index 0000000..956b73c
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/MetadataUpdateEvent.java
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+public class MetadataUpdateEvent implements AmbariUpdateEvent {
+ @Override
+ public String getDestination() {
+ return "/events/metadata";
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/RequestUpdateEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/RequestUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/RequestUpdateEvent.java
new file mode 100644
index 0000000..682ce50
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/RequestUpdateEvent.java
@@ -0,0 +1,108 @@
+/**
+ * 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.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.controller.internal.CalculatedStatus;
+import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.orm.entities.RequestEntity;
+import org.apache.ambari.server.topology.TopologyManager;
+
+public class RequestUpdateEvent implements AmbariUpdateEvent {
+
+ private Long clusterId;
+ private Long endTime;
+ private Long requestId;
+ private Double progressPercent;
+ private String requestContext;
+ private HostRoleStatus requestStatus;
+ private Long startTime;
+
+
+ public RequestUpdateEvent(RequestEntity requestEntity, HostRoleCommandDAO hostRoleCommandDAO, TopologyManager topologyManager) {
+ this.clusterId = requestEntity.getClusterId();
+ this.endTime = requestEntity.getEndTime();
+ this.requestId = requestEntity.getRequestId();
+ this.progressPercent = CalculatedStatus.statusFromRequest(hostRoleCommandDAO, topologyManager, requestEntity.getRequestId()).getPercent();
+ this.requestContext = requestEntity.getRequestContext();
+ this.requestStatus = requestEntity.getStatus();
+ this.startTime = requestEntity.getStartTime();
+ }
+
+ public Long getRequestId() {
+ return requestId;
+ }
+
+ public void setRequestId(Long requestId) {
+ this.requestId = requestId;
+ }
+
+ public Long getClusterId() {
+ return clusterId;
+ }
+
+ public void setClusterId(Long clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ public String getRequestContext() {
+ return requestContext;
+ }
+
+ public void setRequestContext(String requestContext) {
+ this.requestContext = requestContext;
+ }
+
+ public Long getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(Long endTime) {
+ this.endTime = endTime;
+ }
+
+ public Double getProgressPercent() {
+ return progressPercent;
+ }
+
+ public void setProgressPercent(Double progressPercent) {
+ this.progressPercent = progressPercent;
+ }
+
+ public HostRoleStatus getRequestStatus() {
+ return requestStatus;
+ }
+
+ public void setRequestStatus(HostRoleStatus requestStatus) {
+ this.requestStatus = requestStatus;
+ }
+
+ public Long getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(Long startTime) {
+ this.startTime = startTime;
+ }
+
+ @Override
+ public String getDestination() {
+ return "/events/requests";
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/TopologyUpdateEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/TopologyUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/TopologyUpdateEvent.java
new file mode 100644
index 0000000..9655924
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/TopologyUpdateEvent.java
@@ -0,0 +1,63 @@
+/**
+ * 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.Map;
+
+import org.apache.ambari.server.agent.stomp.dto.TopologyCluster;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class TopologyUpdateEvent implements AmbariUpdateEvent {
+ @JsonProperty("clustersTopologies")
+ private Map<String, TopologyCluster> clusters;
+
+ private EventType eventType;
+
+ public TopologyUpdateEvent(Map<String, TopologyCluster> clusters, EventType eventType) {
+ this.clusters = clusters;
+ this.eventType = eventType;
+ }
+
+ public Map<String, TopologyCluster> getClusters() {
+ return clusters;
+ }
+
+ public void setClusters(Map<String, TopologyCluster> clusters) {
+ this.clusters = clusters;
+ }
+
+ public EventType getEventType() {
+ return eventType;
+ }
+
+ public void setEventType(EventType eventType) {
+ this.eventType = eventType;
+ }
+
+ @Override
+ public String getDestination() {
+ return "/events/topology";
+ }
+
+ public enum EventType {
+ ADD,
+ DELETE,
+ UPDATE
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
index 2faadba..0976fd5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
@@ -31,8 +31,10 @@ 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.AlertUpdateEvent;
import org.apache.ambari.server.events.InitialAlertEvent;
import org.apache.ambari.server.events.publishers.AlertEventPublisher;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
import org.apache.ambari.server.orm.RequiresSession;
import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
import org.apache.ambari.server.orm.dao.AlertsDAO;
@@ -88,6 +90,9 @@ public class AlertReceivedListener {
@Inject
Provider<Clusters> m_clusters;
+ @Inject
+ private StateUpdateEventPublisher stateUpdateEventPublisher;
+
/**
* Used to calculate the maintenance state of new alerts being created.
* Consider the case where you have disabled alerts for a component in MM.
@@ -143,6 +148,7 @@ public class AlertReceivedListener {
List<AlertCurrentEntity> toCreateHistoryAndMerge = new ArrayList<>();
List<AlertEvent> alertEvents = new ArrayList<>(20);
+ List<Alert> updatedAlerts = new ArrayList<>();
for (Alert alert : alerts) {
// jobs that were running when a service/component/host was changed
@@ -339,6 +345,7 @@ public class AlertReceivedListener {
// create the event to fire later
alertEvents.add(new AlertStateChangeEvent(clusterId, alert, current, oldState, oldFirmness));
+ updatedAlerts.add(alert);
}
}
@@ -350,6 +357,9 @@ public class AlertReceivedListener {
for (AlertEvent eventToFire : alertEvents) {
m_alertEventPublisher.publish(eventToFire);
}
+ if (!updatedAlerts.isEmpty()) {
+ stateUpdateEventPublisher.publish(new AlertUpdateEvent(updatedAlerts));
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/requests/StateUpdateListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/requests/StateUpdateListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/requests/StateUpdateListener.java
new file mode 100644
index 0000000..940dc76
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/requests/StateUpdateListener.java
@@ -0,0 +1,52 @@
+
+/**
+ * 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.requests;
+
+import org.apache.ambari.server.events.AmbariUpdateEvent;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.messaging.simp.SimpMessagingTemplate;
+
+import com.google.common.eventbus.AllowConcurrentEvents;
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Injector;
+
+public class StateUpdateListener {
+
+ private final static Logger LOG = LoggerFactory.getLogger(StateUpdateListener.class);
+
+ @Autowired
+ SimpMessagingTemplate simpMessagingTemplate;
+
+ public StateUpdateListener(Injector injector) {
+ StateUpdateEventPublisher stateUpdateEventPublisher =
+ injector.getInstance(StateUpdateEventPublisher.class);
+ stateUpdateEventPublisher.register(this);
+ }
+
+ @Subscribe
+ @AllowConcurrentEvents
+ public void onUpdateEvent(AmbariUpdateEvent event) {
+ LOG.debug("Received status update event {}", event.toString());
+ simpMessagingTemplate.convertAndSend(event.getDestination(), event);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java
index 93eef36..9eb9f77 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java
@@ -35,15 +35,19 @@ import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.actionmanager.Request;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.controller.internal.CalculatedStatus;
+import org.apache.ambari.server.events.RequestUpdateEvent;
import org.apache.ambari.server.events.TaskCreateEvent;
import org.apache.ambari.server.events.TaskUpdateEvent;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
import org.apache.ambari.server.events.publishers.TaskEventPublisher;
+import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.RequestDAO;
import org.apache.ambari.server.orm.dao.StageDAO;
import org.apache.ambari.server.orm.entities.RequestEntity;
import org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntity;
import org.apache.ambari.server.orm.entities.StageEntity;
import org.apache.ambari.server.orm.entities.StageEntityPK;
+import org.apache.ambari.server.topology.TopologyManager;
import org.jboss.netty.util.internal.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -92,11 +96,23 @@ public class TaskStatusListener {
private RequestDAO requestDAO;
+ private HostRoleCommandDAO hostRoleCommandDAO;
+
+ private TopologyManager topologyManager;
+
+ private StateUpdateEventPublisher stateUpdateEventPublisher;
+
@Inject
- public TaskStatusListener(TaskEventPublisher taskEventPublisher, StageDAO stageDAO, RequestDAO requestDAO) {
+ public TaskStatusListener(TaskEventPublisher taskEventPublisher, StageDAO stageDAO, RequestDAO requestDAO,
+ StateUpdateEventPublisher stateUpdateEventPublisher,
+ HostRoleCommandDAO hostRoleCommandDAO,
+ TopologyManager topologyManager) {
this.stageDAO = stageDAO;
this.requestDAO = requestDAO;
+ this.stateUpdateEventPublisher = stateUpdateEventPublisher;
+ this.hostRoleCommandDAO = hostRoleCommandDAO;
+ this.topologyManager = topologyManager;
taskEventPublisher.register(this);
}
@@ -263,7 +279,8 @@ public class TaskStatusListener {
ActiveRequest request = activeRequestMap.get(reportedRequestId);
Boolean didStatusChange = updateRequestStatus(reportedRequestId, stagesWithChangedTaskStatus);
if (didStatusChange) {
- requestDAO.updateStatus(reportedRequestId, request.getStatus(), request.getDisplayStatus());
+ RequestEntity updated = requestDAO.updateStatus(reportedRequestId, request.getStatus(), request.getDisplayStatus());
+ stateUpdateEventPublisher.publish(new RequestUpdateEvent(updated, hostRoleCommandDAO, topologyManager));
}
if (request.isCompleted() && isAllTasksCompleted(reportedRequestId)) {
// Request is considered ton have been finished if request status and all of it's tasks status are completed
@@ -606,4 +623,4 @@ public class TaskStatusListener {
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/StateUpdateEventPublisher.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/StateUpdateEventPublisher.java b/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/StateUpdateEventPublisher.java
new file mode 100644
index 0000000..62fe44c
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/StateUpdateEventPublisher.java
@@ -0,0 +1,45 @@
+/**
+ * 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.publishers;
+
+import java.util.concurrent.Executors;
+
+import org.apache.ambari.server.events.AmbariUpdateEvent;
+
+import com.google.common.eventbus.AsyncEventBus;
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Singleton;
+
+@Singleton
+public final class StateUpdateEventPublisher {
+
+ private final EventBus m_eventBus;
+
+ public StateUpdateEventPublisher() {
+ m_eventBus = new AsyncEventBus("ambari-update-bus",
+ Executors.newSingleThreadExecutor());
+ }
+
+ public void publish(AmbariUpdateEvent event) {
+ m_eventBus.post(event);
+ }
+
+ public void register(Object object) {
+ m_eventBus.register(object);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
index 8f16cb2..91d9fd1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
@@ -192,11 +192,11 @@ public class RequestDAO implements Cleanable {
}
@Transactional
- public void updateStatus(long requestId, HostRoleStatus status, HostRoleStatus displayStatus) {
+ public RequestEntity updateStatus(long requestId, HostRoleStatus status, HostRoleStatus displayStatus) {
RequestEntity requestEntity = findByPK(requestId);
requestEntity.setStatus(status);
requestEntity.setDisplayStatus(displayStatus);
- merge(requestEntity);
+ return merge(requestEntity);
}
@Transactional
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ResourceEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ResourceEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ResourceEntity.java
index 16c1660..53146b1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ResourceEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ResourceEntity.java
@@ -34,8 +34,6 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
/**
* Represents a resource.
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index 49fc8c0..3e04a87 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.ClusterResponse;
import org.apache.ambari.server.controller.ServiceConfigVersionResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.ClusterConfigChangedEvent;
import org.apache.ambari.server.metadata.RoleCommandOrder;
import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
@@ -501,7 +502,7 @@ public interface Cluster {
* @param serviceName
* @throws AmbariException
*/
- void deleteService(String serviceName) throws AmbariException;
+ void deleteService(String serviceName, DeleteHostComponentStatusMetaData deleteMetaData) throws AmbariException;
/**
* Gets if the cluster can be deleted
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
index 5964e33..1f8c18e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
@@ -22,6 +22,7 @@ import java.util.Map;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.ServiceResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
public interface Service {
@@ -82,14 +83,14 @@ public interface Service {
*/
boolean canBeRemoved();
- void deleteAllComponents() throws AmbariException;
+ void deleteAllComponents(DeleteHostComponentStatusMetaData deleteMetaData);
- void deleteServiceComponent(String componentName)
+ void deleteServiceComponent(String componentName, DeleteHostComponentStatusMetaData deleteMetaData)
throws AmbariException;
boolean isClientOnlyService();
- void delete() throws AmbariException;
+ void delete(DeleteHostComponentStatusMetaData deleteMetaData);
/**
* Sets the maintenance state for the service
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
index e93ab9a..3995c23 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
@@ -22,6 +22,7 @@ import java.util.Map;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.ServiceComponentResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
public interface ServiceComponent {
@@ -88,13 +89,13 @@ public interface ServiceComponent {
boolean canBeRemoved();
- void deleteAllServiceComponentHosts() throws AmbariException;
+ void deleteAllServiceComponentHosts(DeleteHostComponentStatusMetaData deleteMetaData) throws AmbariException;
- void deleteServiceComponentHosts(String hostname)
+ void deleteServiceComponentHosts(String hostname, DeleteHostComponentStatusMetaData deleteMetaData)
throws AmbariException;
ServiceComponentHost addServiceComponentHost(
String hostName) throws AmbariException;
- void delete() throws AmbariException;
+ void delete(DeleteHostComponentStatusMetaData deleteMetaData);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
index 104e456..8e6d33b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.ServiceComponentHostResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
@@ -193,7 +194,7 @@ public interface ServiceComponentHost {
boolean canBeRemoved();
- void delete() throws AmbariException;
+ void delete(DeleteHostComponentStatusMetaData deleteMetaData);
/**
* Updates the tags that have been recognized by a START action.
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
index f6ddc6d..dbc7464 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
@@ -31,6 +31,7 @@ import org.apache.ambari.server.ObjectNotFoundException;
import org.apache.ambari.server.ServiceComponentHostNotFoundException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ServiceComponentResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.ServiceComponentRecoveryChangedEvent;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
@@ -508,7 +509,7 @@ public class ServiceComponentImpl implements ServiceComponent {
@Override
@Transactional
- public void deleteAllServiceComponentHosts() throws AmbariException {
+ public void deleteAllServiceComponentHosts(DeleteHostComponentStatusMetaData deleteMetaData) {
readWriteLock.writeLock().lock();
try {
LOG.info("Deleting all servicecomponenthosts for component" + ", clusterName="
@@ -516,15 +517,16 @@ public class ServiceComponentImpl implements ServiceComponent {
+ ", recoveryEnabled=" + isRecoveryEnabled());
for (ServiceComponentHost sch : hostComponents.values()) {
if (!sch.canBeRemoved()) {
- throw new AmbariException("Found non removable hostcomponent " + " when trying to delete"
+ deleteMetaData.setAmbariException(new AmbariException("Found non removable hostcomponent " + " when trying to delete"
+ " all hostcomponents from servicecomponent" + ", clusterName=" + getClusterName()
+ ", serviceName=" + getServiceName() + ", componentName=" + getName()
- + ", recoveryEnabled=" + isRecoveryEnabled() + ", hostname=" + sch.getHostName());
+ + ", recoveryEnabled=" + isRecoveryEnabled() + ", hostname=" + sch.getHostName()));
+ return;
}
}
for (ServiceComponentHost serviceComponentHost : hostComponents.values()) {
- serviceComponentHost.delete();
+ serviceComponentHost.delete(deleteMetaData);
}
hostComponents.clear();
@@ -534,7 +536,7 @@ public class ServiceComponentImpl implements ServiceComponent {
}
@Override
- public void deleteServiceComponentHosts(String hostname) throws AmbariException {
+ public void deleteServiceComponentHosts(String hostname, DeleteHostComponentStatusMetaData deleteMetaData) throws AmbariException {
readWriteLock.writeLock().lock();
try {
ServiceComponentHost sch = getServiceComponentHost(hostname);
@@ -549,7 +551,7 @@ public class ServiceComponentImpl implements ServiceComponent {
+ ", recoveryEnabled=" + isRecoveryEnabled()
+ ", hostname=" + sch.getHostName());
}
- sch.delete();
+ sch.delete(deleteMetaData);
hostComponents.remove(hostname);
} finally {
@@ -559,10 +561,13 @@ public class ServiceComponentImpl implements ServiceComponent {
@Override
@Transactional
- public void delete() throws AmbariException {
+ public void delete(DeleteHostComponentStatusMetaData deleteMetaData) {
readWriteLock.writeLock().lock();
try {
- deleteAllServiceComponentHosts();
+ deleteAllServiceComponentHosts(deleteMetaData);
+ if (deleteMetaData.getAmbariException() != null) {
+ return;
+ }
ServiceComponentDesiredStateEntity desiredStateEntity = serviceComponentDesiredStateDAO.findById(
desiredStateEntityId);
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
index a0c0db1..f9202e0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
@@ -31,6 +31,7 @@ import org.apache.ambari.server.ObjectNotFoundException;
import org.apache.ambari.server.ServiceComponentNotFoundException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ServiceResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.MaintenanceModeEvent;
import org.apache.ambari.server.events.ServiceInstalledEvent;
import org.apache.ambari.server.events.ServiceRemovedEvent;
@@ -516,7 +517,7 @@ public class ServiceImpl implements Service {
@Override
@Transactional
- public void deleteAllComponents() throws AmbariException {
+ public void deleteAllComponents(DeleteHostComponentStatusMetaData deleteMetaData) {
lock.lock();
try {
LOG.info("Deleting all components for service" + ", clusterName=" + cluster.getClusterName()
@@ -524,14 +525,18 @@ public class ServiceImpl implements Service {
// FIXME check dependencies from meta layer
for (ServiceComponent component : components.values()) {
if (!component.canBeRemoved()) {
- throw new AmbariException("Found non removable component when trying to"
+ deleteMetaData.setAmbariException(new AmbariException("Found non removable component when trying to"
+ " delete all components from service" + ", clusterName=" + cluster.getClusterName()
- + ", serviceName=" + getName() + ", componentName=" + component.getName());
+ + ", serviceName=" + getName() + ", componentName=" + component.getName()));
+ return;
}
}
for (ServiceComponent serviceComponent : components.values()) {
- serviceComponent.delete();
+ serviceComponent.delete(deleteMetaData);
+ if (deleteMetaData.getAmbariException() != null) {
+ return;
+ }
}
components.clear();
@@ -541,7 +546,7 @@ public class ServiceImpl implements Service {
}
@Override
- public void deleteServiceComponent(String componentName)
+ public void deleteServiceComponent(String componentName, DeleteHostComponentStatusMetaData deleteMetaData)
throws AmbariException {
lock.lock();
try {
@@ -556,7 +561,7 @@ public class ServiceImpl implements Service {
+ ", componentName=" + componentName);
}
- component.delete();
+ component.delete(deleteMetaData);
components.remove(componentName);
} finally {
lock.unlock();
@@ -570,11 +575,19 @@ public class ServiceImpl implements Service {
@Override
@Transactional
- public void delete() throws AmbariException {
- deleteAllComponents();
- deleteAllServiceConfigs();
+ public void delete(DeleteHostComponentStatusMetaData deleteMetaData) {
+ deleteAllComponents(deleteMetaData);
+ if (deleteMetaData.getAmbariException() != null) {
+ return;
+ }
+ try {
+ deleteAllServiceConfigs();
- removeEntities();
+ removeEntities();
+ } catch (AmbariException e) {
+ deleteMetaData.setAmbariException(e);
+ return;
+ }
// publish the service removed event
StackId stackId = cluster.getDesiredStackVersion();
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index b86c5cd..f41c620 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -37,6 +37,7 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.persistence.EntityManager;
@@ -61,14 +62,17 @@ import org.apache.ambari.server.controller.ConfigurationResponse;
import org.apache.ambari.server.controller.MaintenanceStateHelper;
import org.apache.ambari.server.controller.RootServiceResponseFactory.Services;
import org.apache.ambari.server.controller.ServiceConfigVersionResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.controller.internal.UpgradeResourceProvider;
import org.apache.ambari.server.events.AmbariEvent.AmbariEventType;
import org.apache.ambari.server.events.ClusterConfigChangedEvent;
import org.apache.ambari.server.events.ClusterEvent;
+import org.apache.ambari.server.events.ConfigsUpdateEvent;
import org.apache.ambari.server.events.jpa.EntityManagerCacheInvalidationEvent;
import org.apache.ambari.server.events.jpa.JPAEvent;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.events.publishers.JPAEventPublisher;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
import org.apache.ambari.server.logging.LockFactory;
import org.apache.ambari.server.metadata.RoleCommandOrder;
import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
@@ -145,8 +149,10 @@ import org.apache.ambari.server.state.scheduler.RequestExecution;
import org.apache.ambari.server.state.scheduler.RequestExecutionFactory;
import org.apache.ambari.server.state.stack.upgrade.Direction;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostSummary;
+import org.apache.ambari.server.topology.TopologyDeleteFormer;
import org.apache.ambari.server.topology.TopologyRequest;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -292,6 +298,9 @@ public class ClusterImpl implements Cluster {
@Inject
private TopologyRequestDAO topologyRequestDAO;
+ @Inject
+ private TopologyDeleteFormer topologyDeleteFormer;
+
/**
* Data access object used for looking up stacks from the database.
*/
@@ -327,6 +336,9 @@ public class ClusterImpl implements Cluster {
@Inject
private UpgradeContextFactory upgradeContextFactory;
+ @Inject
+ private StateUpdateEventPublisher stateUpdateEventPublisher;
+
/**
* A simple cache for looking up {@code cluster-env} properties for a cluster.
* This map is changed whenever {{cluster-env}} is changed and we receive a
@@ -2007,9 +2019,12 @@ public class ClusterImpl implements Cluster {
}
}
+ DeleteHostComponentStatusMetaData deleteMetaData = new DeleteHostComponentStatusMetaData();
for (Service service : services.values()) {
- deleteService(service);
+ deleteService(service, deleteMetaData);
+ topologyDeleteFormer.processDeleteMetaDataException(deleteMetaData);
}
+ topologyDeleteFormer.processDeleteCluster(Long.toString(getClusterId()));
services.clear();
} finally {
clusterGlobalLock.writeLock().unlock();
@@ -2017,7 +2032,7 @@ public class ClusterImpl implements Cluster {
}
@Override
- public void deleteService(String serviceName)
+ public void deleteService(String serviceName, DeleteHostComponentStatusMetaData deleteMetaData)
throws AmbariException {
clusterGlobalLock.writeLock().lock();
try {
@@ -2026,11 +2041,12 @@ public class ClusterImpl implements Cluster {
+ getClusterName() + ", serviceName=" + service.getName());
// FIXME check dependencies from meta layer
if (!service.canBeRemoved()) {
- throw new AmbariException("Could not delete service from cluster"
- + ", clusterName=" + getClusterName()
- + ", serviceName=" + service.getName());
+ deleteMetaData.setAmbariException(new AmbariException("Could not delete service from cluster"
+ + ", clusterName=" + getClusterName()
+ + ", serviceName=" + service.getName()));
+ return;
}
- deleteService(service);
+ deleteService(service, deleteMetaData);
services.remove(serviceName);
} finally {
@@ -2048,10 +2064,13 @@ public class ClusterImpl implements Cluster {
* @throws AmbariException
* @see ServiceComponentHost
*/
- private void deleteService(Service service) throws AmbariException {
+ private void deleteService(Service service, DeleteHostComponentStatusMetaData deleteMetaData) {
final String serviceName = service.getName();
- service.delete();
+ service.delete(deleteMetaData);
+ if (deleteMetaData.getAmbariException() != null) {
+ return;
+ }
serviceComponentHosts.remove(serviceName);
@@ -2296,10 +2315,17 @@ public class ClusterImpl implements Cluster {
serviceConfigEntity.setStack(clusterEntity.getDesiredStack());
serviceConfigDAO.create(serviceConfigEntity);
+ List<String> groupHostNames = null;
if (configGroup != null) {
+ if (MapUtils.isNotEmpty(configGroup.getHosts())) {
+ groupHostNames = configGroup.getHosts().entrySet().stream().map(h -> h.getValue().getHostName())
+ .collect(Collectors.toList());
+ }
serviceConfigEntity.setHostIds(new ArrayList<>(configGroup.getHosts().keySet()));
serviceConfigEntity = serviceConfigDAO.merge(serviceConfigEntity);
}
+ stateUpdateEventPublisher.publish(new ConfigsUpdateEvent(serviceConfigEntity,
+ configGroup == null ? null : configGroup.getName(), groupHostNames));
} finally {
clusterGlobalLock.writeLock().unlock();
}
@@ -2556,6 +2582,7 @@ public class ClusterImpl implements Cluster {
throw new ObjectNotFoundException("Service config version with serviceName={} and version={} not found");
}
+ String configGroupName = null;
// disable all configs related to service
if (serviceConfigEntity.getGroupId() == null) {
Collection<String> configTypes = serviceConfigTypes.get(serviceName);
@@ -2573,6 +2600,7 @@ public class ClusterImpl implements Cluster {
Long configGroupId = serviceConfigEntity.getGroupId();
ConfigGroup configGroup = clusterConfigGroups.get(configGroupId);
if (configGroup != null) {
+ configGroupName = configGroup.getName();
Map<String, Config> groupDesiredConfigs = new HashMap<>();
for (ClusterConfigEntity entity : serviceConfigEntity.getClusterConfigEntities()) {
Config config = allConfigs.get(entity.getType()).get(entity.getTag());
@@ -2614,7 +2642,15 @@ public class ClusterImpl implements Cluster {
serviceConfigEntityClone.setNote(serviceConfigVersionNote);
serviceConfigEntityClone.setVersion(nextServiceConfigVersion);
+ List<String> groupHostNames = null;
+ if (CollectionUtils.isNotEmpty(serviceConfigEntity.getHostIds())) {
+ groupHostNames = getHosts().stream()
+ .filter(h -> serviceConfigEntity.getHostIds().contains(h.getHostId()))
+ .map(h -> h.getHostName()).collect(Collectors.toList());
+ }
+
serviceConfigDAO.create(serviceConfigEntityClone);
+ stateUpdateEventPublisher.publish(new ConfigsUpdateEvent(serviceConfigEntityClone, configGroupName, groupHostNames));
return convertToServiceConfigVersionResponse(serviceConfigEntityClone);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index f1e93ac..6ba9ff7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.state.svccomphost;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -32,13 +33,19 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.agent.AlertDefinitionCommand;
+import org.apache.ambari.server.agent.stomp.dto.TopologyCluster;
+import org.apache.ambari.server.agent.stomp.dto.TopologyComponent;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ServiceComponentHostResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.AlertHashInvalidationEvent;
+import org.apache.ambari.server.events.HostComponentUpdateEvent;
import org.apache.ambari.server.events.MaintenanceModeEvent;
import org.apache.ambari.server.events.ServiceComponentInstalledEvent;
import org.apache.ambari.server.events.ServiceComponentUninstalledEvent;
+import org.apache.ambari.server.events.TopologyUpdateEvent;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
@@ -121,6 +128,9 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
@Inject
private RepositoryVersionHelper repositoryVersionHelper;
+ @Inject
+ StateUpdateEventPublisher stateUpdateEventPublisher;
+
/**
* Used for creating commands to send to the agents when alert definitions are
* added as the result of a service install.
@@ -895,6 +905,17 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
if (stateEntity != null) {
stateEntity.setVersion(version);
stateEntity = hostComponentStateDAO.merge(stateEntity);
+ Map<String, TopologyCluster> topologyUpdates = new HashMap<>();
+ topologyUpdates.put(Long.toString(getClusterId()), new TopologyCluster());
+ Long hostId = getHost().getHostId();
+ topologyUpdates.get(Long.toString(getClusterId())).addTopologyComponent(TopologyComponent.newBuilder()
+ .setComponentName(getServiceComponentName())
+ .setVersion(stateEntity.getVersion())
+ .setHostIds(new HashSet<>(Collections.singletonList(hostId)))
+ .build());
+ TopologyUpdateEvent hostComponentVersionUpdate = new TopologyUpdateEvent(topologyUpdates,
+ TopologyUpdateEvent.EventType.UPDATE);
+ stateUpdateEventPublisher.publish(hostComponentVersionUpdate);
} else {
LOG.warn("Setting a member on an entity object that may have been "
+ "previously deleted, serviceName = " + getServiceName() + ", " + "componentName = "
@@ -1007,8 +1028,12 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
try {
stateMachine.doTransition(event.getType(), event);
HostComponentStateEntity stateEntity = getStateEntity();
+ boolean statusUpdated = !stateEntity.getCurrentState().equals(stateMachine.getCurrentState());
stateEntity.setCurrentState(stateMachine.getCurrentState());
stateEntity = hostComponentStateDAO.merge(stateEntity);
+ if (statusUpdated) {
+ stateUpdateEventPublisher.publish(new HostComponentUpdateEvent(stateEntity));
+ }
// TODO Audit logs
} catch (InvalidStateTransitionException e) {
LOG.error("Can't handle ServiceComponentHostEvent event at"
@@ -1359,10 +1384,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
}
@Override
- public void delete() {
+ public void delete(DeleteHostComponentStatusMetaData deleteMetaData) {
boolean fireRemovalEvent = false;
writeLock.lock();
+ String version = getVersion();
try {
removeEntities();
fireRemovalEvent = true;
@@ -1390,6 +1416,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
hostName, recoveryEnabled);
eventPublisher.publish(event);
+ deleteMetaData.addDeletedHostComponent(componentName,
+ hostName,
+ getHost().getHostId(),
+ Long.toString(clusterId),
+ version);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyDeleteFormer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyDeleteFormer.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyDeleteFormer.java
new file mode 100644
index 0000000..199f127
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyDeleteFormer.java
@@ -0,0 +1,98 @@
+/**
+ * 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.topology;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.agent.stomp.dto.TopologyCluster;
+import org.apache.ambari.server.agent.stomp.dto.TopologyComponent;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
+import org.apache.ambari.server.events.TopologyUpdateEvent;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+public class TopologyDeleteFormer {
+
+ @Inject
+ private StateUpdateEventPublisher stateUpdateEventPublisher;
+
+ public void processDeleteMetaDataException(DeleteHostComponentStatusMetaData metaData) throws AmbariException {
+ if (metaData.getAmbariException() != null) {
+
+ TopologyUpdateEvent topologyUpdateEvent = new TopologyUpdateEvent(
+ createUpdateFromDeleteMetaData(metaData),
+ TopologyUpdateEvent.EventType.DELETE
+ );
+ stateUpdateEventPublisher.publish(topologyUpdateEvent);
+
+ throw metaData.getAmbariException();
+ }
+ }
+ public void processDeleteMetaData(DeleteHostComponentStatusMetaData metaData) {
+ TopologyUpdateEvent topologyUpdateEvent = new TopologyUpdateEvent(
+ createUpdateFromDeleteMetaData(metaData),
+ TopologyUpdateEvent.EventType.DELETE
+ );
+ stateUpdateEventPublisher.publish(topologyUpdateEvent);
+ }
+
+ public void processDeleteCluster(String clusterId) {
+ Map<String, TopologyCluster> topologyUpdates = new HashMap<>();
+ topologyUpdates.put(clusterId, new TopologyCluster());
+ TopologyUpdateEvent topologyUpdateEvent = new TopologyUpdateEvent(
+ topologyUpdates,
+ TopologyUpdateEvent.EventType.DELETE
+ );
+ stateUpdateEventPublisher.publish(topologyUpdateEvent);
+ }
+
+ public Map<String, TopologyCluster> createUpdateFromDeleteMetaData(DeleteHostComponentStatusMetaData metaData) {
+ Map<String, TopologyCluster> topologyUpdates = new HashMap<>();
+
+ for (DeleteHostComponentStatusMetaData.HostComponent hostComponent : metaData.getRemovedHostComponents()) {
+ TopologyComponent deletedComponent = TopologyComponent.newBuilder()
+ .setComponentName(hostComponent.getComponentName())
+ .setVersion(hostComponent.getVersion())
+ .setHostIds(new HashSet<>(Arrays.asList(hostComponent.getHostId())))
+ .build();
+
+ String clusterId = hostComponent.getClusterId();
+ if (!topologyUpdates.containsKey(clusterId)) {
+ topologyUpdates.put(clusterId, new TopologyCluster());
+ }
+
+ if (!topologyUpdates.get(clusterId).getTopologyComponents().contains(deletedComponent)) {
+ topologyUpdates.get(clusterId).addTopologyComponent(deletedComponent);
+ } else {
+ topologyUpdates.get(clusterId).getTopologyComponents()
+ .stream().filter(t -> t.equals(deletedComponent))
+ .forEach(t -> t.addHostId(hostComponent.getHostId()));
+ }
+ }
+
+ return topologyUpdates;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
index edf107a..eb030c6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
@@ -480,6 +480,7 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog {
return;
}
+ //TODO Event for hostcomponents removing
for (ClusterEntity cluster : clusters) {
ClusterServiceEntity nagios = clusterServiceDao.findByClusterAndServiceNames(
cluster.getClusterName(), "NAGIOS");
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
index 3a93fbf..e9a087a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
@@ -36,6 +36,7 @@ import org.apache.ambari.server.H2DatabaseCleaner;
import org.apache.ambari.server.agent.HeartbeatTestHelper;
import org.apache.ambari.server.agent.RecoveryConfig;
import org.apache.ambari.server.agent.RecoveryConfigHelper;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -180,7 +181,7 @@ public class RecoveryConfigHelperTest {
assertEquals(recoveryConfig.getEnabledComponents(), "DATANODE,NAMENODE");
// Uninstall HDFS::DATANODE from host1
- hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).delete();
+ hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).delete(new DeleteHostComponentStatusMetaData());
// Verify that the config is stale
boolean isConfigStale = recoveryConfigHelper.isConfigStale(cluster.getClusterName(), DummyHostname1,
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
index 7c34521..1f44279 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
@@ -528,7 +528,7 @@ public class ComponentResourceProviderTest {
expect(serviceComponentHost.getDesiredState()).andReturn(hostComponentState);
- service.deleteServiceComponent("Component100");
+ service.deleteServiceComponent("Component100", new DeleteHostComponentStatusMetaData());
expectLastCall().once();
// replay
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
index 44c2493..bad5854 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
@@ -858,7 +858,7 @@ public class ServiceResourceProviderTest {
expect(service.getName()).andReturn(serviceName).anyTimes();
expect(service.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
expect(service.getCluster()).andReturn(cluster);
- cluster.deleteService(serviceName);
+ cluster.deleteService(serviceName, new DeleteHostComponentStatusMetaData());
// replay
replay(managementController, clusters, cluster, service);
@@ -906,7 +906,7 @@ public class ServiceResourceProviderTest {
expect(service.getName()).andReturn(serviceName).anyTimes();
expect(service.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
expect(service.getCluster()).andReturn(cluster);
- cluster.deleteService(serviceName);
+ cluster.deleteService(serviceName, new DeleteHostComponentStatusMetaData());
// replay
replay(managementController, clusters, cluster, service);
@@ -1074,7 +1074,7 @@ public class ServiceResourceProviderTest {
expect(sch3.canBeRemoved()).andReturn(sch3State.isRemovableState()).anyTimes();
expect(service.getCluster()).andReturn(cluster);
- cluster.deleteService(serviceName);
+ cluster.deleteService(serviceName, new DeleteHostComponentStatusMetaData());
// replay
replay(managementController, clusters, cluster, service,
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
index 6fb0028..b5fd75e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
@@ -25,6 +25,7 @@ import java.util.UUID;
import javax.persistence.EntityManager;
import org.apache.ambari.server.H2DatabaseCleaner;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.AmbariEvent.AmbariEventType;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -192,7 +193,7 @@ public class EventsTest {
AlertDefinitionEntity definition = hdfsDefinitions.get(0);
// delete HDFS
- m_cluster.getService("HDFS").delete();
+ m_cluster.getService("HDFS").delete(new DeleteHostComponentStatusMetaData());
// verify the event was received
Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
@@ -242,7 +243,7 @@ public class EventsTest {
Assert.assertEquals(0, hdfsDefinitions.size());
// delete HDFS
- m_cluster.getService("HDFS").delete();
+ m_cluster.getService("HDFS").delete(new DeleteHostComponentStatusMetaData());
// verify the event was received
Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
@@ -293,7 +294,7 @@ public class EventsTest {
Assert.assertNull(group);
// delete HDFS
- m_cluster.getService("HDFS").delete();
+ m_cluster.getService("HDFS").delete(new DeleteHostComponentStatusMetaData());
// verify the event was received
Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
@@ -315,7 +316,7 @@ public class EventsTest {
installHdfsService();
Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
- m_cluster.getServiceComponentHosts(HOSTNAME).get(0).delete();
+ m_cluster.getServiceComponentHosts(HOSTNAME).get(0).delete(new DeleteHostComponentStatusMetaData());
Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java
index 90b8687..896b576 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java
@@ -32,9 +32,11 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.events.TaskCreateEvent;
import org.apache.ambari.server.events.TaskUpdateEvent;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
import org.apache.ambari.server.events.publishers.TaskEventPublisher;
import org.apache.ambari.server.orm.dao.ExecutionCommandDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
+import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.RequestDAO;
import org.apache.ambari.server.orm.dao.StageDAO;
import org.apache.ambari.server.orm.entities.RequestEntity;
@@ -42,6 +44,7 @@ import org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntity;
import org.apache.ambari.server.orm.entities.StageEntity;
import org.apache.ambari.server.orm.entities.StageEntityPK;
import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.topology.TopologyManager;
import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.Assert;
@@ -53,6 +56,7 @@ import com.google.inject.Inject;
public class TaskStatusListenerTest extends EasyMockSupport {
private TaskEventPublisher publisher = new TaskEventPublisher();
+ private StateUpdateEventPublisher statePublisher = new StateUpdateEventPublisher();
@Inject
private ExecutionCommandDAO executionCommandDAO;
@@ -85,6 +89,8 @@ public class TaskStatusListenerTest extends EasyMockSupport {
HostRoleStatus hostRoleStatus = HostRoleStatus.PENDING;
StageDAO stageDAO = createNiceMock(StageDAO.class);
+ HostRoleCommandDAO hostRoleCommandDAO = createNiceMock(HostRoleCommandDAO.class);
+ TopologyManager topologyManager = createNiceMock(TopologyManager.class);
RequestDAO requestDAO = createNiceMock(RequestDAO.class);
StageEntity stageEntity = createNiceMock(StageEntity.class);
RequestEntity requestEntity = createNiceMock(RequestEntity.class);
@@ -108,7 +114,8 @@ public class TaskStatusListenerTest extends EasyMockSupport {
EasyMock.replay(requestDAO);
TaskCreateEvent event = new TaskCreateEvent(hostRoleCommands);
- TaskStatusListener listener = new TaskStatusListener(publisher,stageDAO,requestDAO);
+ TaskStatusListener listener = new TaskStatusListener(publisher,stageDAO,requestDAO,statePublisher,
+ hostRoleCommandDAO,topologyManager);
Assert.assertTrue(listener.getActiveTasksMap().isEmpty());
Assert.assertTrue(listener.getActiveStageMap().isEmpty());
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
index dc9ce5e..c0d445a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
@@ -34,6 +34,7 @@ import java.util.UUID;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.H2DatabaseCleaner;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.ServiceComponentInstalledEvent;
import org.apache.ambari.server.events.ServiceComponentUninstalledEvent;
import org.apache.ambari.server.events.ServiceInstalledEvent;
@@ -502,7 +503,7 @@ public class HostVersionOutOfSyncListenerTest {
List<ServiceComponentHost> hostComponents = c1.getServiceComponentHosts(host3);
for (ServiceComponentHost sch : hostComponents) {
if (sch.getServiceName().equals("HDFS")) {
- sch.delete();
+ sch.delete(new DeleteHostComponentStatusMetaData());
StackId clusterStackId = c1.getDesiredStackVersion();
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
index 8e8bed3..711a3c6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
@@ -33,6 +33,7 @@ import org.apache.ambari.server.H2DatabaseCleaner;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ServiceComponentResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.OrmTestHelper;
@@ -438,17 +439,14 @@ public class ServiceComponentTest {
sch1.setState(State.STARTED);
sch2.setState(State.STARTED);
- try {
- // delete the SC
- sc.delete();
- Assert.assertTrue("Delete must fail as some SCH are in STARTED state", false);
- }catch(AmbariException e) {
- // expected
- }
+ // delete the SC
+ DeleteHostComponentStatusMetaData deleteMetaData = new DeleteHostComponentStatusMetaData();
+ sc.delete(deleteMetaData);
+ Assert.assertNull("Delete must fail as some SCH are in STARTED state", deleteMetaData.getAmbariException());
sch1.setState(State.INSTALLED);
sch2.setState(State.INSTALL_FAILED);
- sc.delete();
+ sc.delete(new DeleteHostComponentStatusMetaData());
// verify history is gone, too
serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
@@ -514,7 +512,7 @@ public class ServiceComponentTest {
assertEquals(1, componentHistoryList.size());
// delete the SC
- sc.delete();
+ sc.delete(new DeleteHostComponentStatusMetaData());
// verify history is gone, too
serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
@@ -628,7 +626,7 @@ public class ServiceComponentTest {
assertEquals(RepositoryVersionState.CURRENT, persistedVersion.getState());
- sc.delete();
+ sc.delete(new DeleteHostComponentStatusMetaData());
serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
cluster.getClusterId(), serviceName, componentName);
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
index fc12e44..812ae36 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
@@ -29,6 +29,7 @@ import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.H2DatabaseCleaner;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ServiceResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
@@ -205,7 +206,7 @@ public class ServiceTest {
s.getServiceComponent("HDFS_CLIENT").getDesiredState());
// delete service component
- s.deleteServiceComponent("NAMENODE");
+ s.deleteServiceComponent("NAMENODE", new DeleteHostComponentStatusMetaData());
assertEquals(3, s.getServiceComponents().size());
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
index 8c23b69..5d8f6dd 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.state.alerts;
import java.util.UUID;
import org.apache.ambari.server.H2DatabaseCleaner;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.AlertDefinitionChangedEvent;
import org.apache.ambari.server.events.AlertDefinitionDeleteEvent;
import org.apache.ambari.server.events.AmbariEvent;
@@ -133,7 +134,7 @@ public class AlertEventPublisherTest {
Assert.assertEquals(0, dispatchDao.findAllGroups().size());
installHdfsService();
Assert.assertEquals(1, dispatchDao.findAllGroups().size());
- cluster.getService("HDFS").delete();
+ cluster.getService("HDFS").delete(new DeleteHostComponentStatusMetaData());
Assert.assertEquals(0, dispatchDao.findAllGroups().size());
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
index 76f9130..3836d6b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
@@ -38,6 +38,7 @@ import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.H2DatabaseCleaner;
import org.apache.ambari.server.HostNotFoundException;
import org.apache.ambari.server.controller.AmbariSessionManager;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.state.Cluster;
@@ -242,7 +243,7 @@ public class ClusterImplTest {
ServiceComponentHost tezClientHost2 = tezClient.addServiceComponentHost(hostName2);
// When
- cluster.deleteService(serviceToDelete);
+ cluster.deleteService(serviceToDelete, new DeleteHostComponentStatusMetaData());
// Then
assertFalse("Deleted service should be removed from the service collection !", cluster.getServices().containsKey(serviceToDelete));
http://git-wip-us.apache.org/repos/asf/ambari/blob/c2ab4a3c/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
index 76689f4..04c0ead 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
@@ -58,6 +58,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ClusterResponse;
import org.apache.ambari.server.controller.ConfigurationResponse;
import org.apache.ambari.server.controller.ServiceConfigVersionResponse;
+import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
import org.apache.ambari.server.events.ClusterConfigChangedEvent;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -1109,7 +1110,7 @@ public class ClusterTest {
assertEquals(2, injector.getProvider(EntityManager.class).get().
createQuery("SELECT service FROM ClusterServiceEntity service").getResultList().size());
- c1.deleteService("HDFS");
+ c1.deleteService("HDFS", new DeleteHostComponentStatusMetaData());
assertEquals(1, c1.getServices().size());
assertEquals(1, injector.getProvider(EntityManager.class).get().
@@ -1146,7 +1147,7 @@ public class ClusterTest {
c1.getActiveServiceConfigVersions();
Assert.assertEquals(1, activeServiceConfigVersions.size());
- c1.deleteService("HDFS");
+ c1.deleteService("HDFS", new DeleteHostComponentStatusMetaData());
Assert.assertEquals(0, c1.getServices().size());
Assert.assertEquals(0, c1.getServiceConfigVersions().size());