You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2018/05/16 17:56:52 UTC
[ambari] branch branch-feature-AMBARI-14714 updated: AMBARI-23746.
Distinguish componentId and hostComponentId (#1288)
This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by this push:
new fbdfeb6 AMBARI-23746. Distinguish componentId and hostComponentId (#1288)
fbdfeb6 is described below
commit fbdfeb67297fa251d383568af7baf8ee7947c559
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Wed May 16 19:56:49 2018 +0200
AMBARI-23746. Distinguish componentId and hostComponentId (#1288)
---
.../controller/AmbariManagementControllerImpl.java | 36 ++++++++++++----------
.../controller/ServiceComponentHostRequest.java | 24 +++++++--------
.../internal/HostComponentResourceProvider.java | 2 +-
.../org/apache/ambari/server/state/Cluster.java | 2 ++
.../ambari/server/state/cluster/ClusterImpl.java | 21 ++++++++++---
.../server/state/cluster/ClusterImplTest.java | 7 +++++
6 files changed, 58 insertions(+), 34 deletions(-)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index f601c83..b49874f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -1398,13 +1398,15 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
}
- if (request.getComponentId() != null) {
- Service service = cluster.getServiceByComponentId(request.getComponentId());
- if (Strings.isNullOrEmpty(request.getServiceGroupName())) {
- request.setServiceGroupName(service.getServiceGroupName());
- }
- if (Strings.isNullOrEmpty(request.getServiceName())) {
- request.setServiceName(service.getName());
+ if (request.getHostComponentId() != null) {
+ ServiceComponentHost sch = cluster.getHostComponentById(request.getHostComponentId());
+ if (sch != null) {
+ if (Strings.isNullOrEmpty(request.getServiceGroupName())) {
+ request.setServiceGroupName(sch.getServiceGroupName());
+ }
+ if (Strings.isNullOrEmpty(request.getServiceName())) {
+ request.setServiceName(sch.getServiceName());
+ }
}
}
@@ -1482,18 +1484,18 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
*/
ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = null;
HostComponentStateEntity hostComponentStateEntity = null;
- if (request.getComponentId() != null) {
- hostComponentStateEntity = hostComponentStateDAO.findById(request.getComponentId());
+ if (request.getHostComponentId() != null) {
+ hostComponentStateEntity = hostComponentStateDAO.findById(request.getHostComponentId());
if (hostComponentStateEntity == null) {
throw new AmbariException("Could not find Host Component resource for"
- + " componentId = "+ request.getComponentId());
+ + " componentId = "+ request.getHostComponentId());
}
serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(hostComponentStateEntity.getClusterId(),
hostComponentStateEntity.getServiceGroupId(), hostComponentStateEntity.getServiceId(),
hostComponentStateEntity.getComponentName(), hostComponentStateEntity.getComponentType());
if (serviceComponentDesiredStateEntity == null) {
throw new AmbariException("Could not find Service Component resource for"
- + " componentId = " + request.getComponentId() + ", serviceGroupId = " + hostComponentStateEntity.getServiceGroupId()
+ + " componentId = " + request.getHostComponentId() + ", serviceGroupId = " + hostComponentStateEntity.getServiceGroupId()
+ ", serviceId = " + hostComponentStateEntity.getServiceId() + ", componentName = " + hostComponentStateEntity.getComponentName()
+ ", componntType = " + hostComponentStateEntity.getComponentType());
}
@@ -1574,7 +1576,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
response.add(r);
} catch (ServiceComponentHostNotFoundException e) {
- if (request.getServiceName() == null || request.getComponentId() == null) {
+ if (request.getServiceName() == null || request.getHostComponentId() == null) {
// Ignore the exception if either the service name or component name are not specified.
// This is an artifact of how we get host_components and can happen in the case where
// we get all host_components for a host, for example.
@@ -1586,7 +1588,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
// condition.
LOG.debug("ServiceComponentHost not found ", e);
throw new ServiceComponentHostNotFoundException(cluster.getClusterName(),
- request.getServiceName(), request.getComponentId(), request.getHostname());
+ request.getServiceName(), request.getHostComponentId(), request.getHostname());
}
}
} else {
@@ -3797,7 +3799,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
// if any request are for the whole host, they need to be expanded
for (ServiceComponentHostRequest request : requests) {
- if (null == request.getComponentId()) {
+ if (null == request.getHostComponentId()) {
if (null == request.getClusterName() || request.getClusterName().isEmpty() ||
null == request.getHostname() || request.getHostname().isEmpty()) {
throw new IllegalArgumentException("Cluster name and hostname must be specified.");
@@ -3832,10 +3834,10 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
Service s = null;
if (StringUtils.isEmpty(request.getServiceName())) {
- hostComponentStateEntity = hostComponentStateDAO.findById(request.getComponentId());
+ hostComponentStateEntity = hostComponentStateDAO.findById(request.getHostComponentId());
if (hostComponentStateEntity == null) {
throw new AmbariException("Could not find Host Component resource for"
- + " componentId = "+ request.getComponentId());
+ + " componentId = "+ request.getHostComponentId());
}
s = cluster.getService(hostComponentStateEntity.getServiceId());
request.setServiceGroupName(s.getServiceGroupName());
@@ -3848,7 +3850,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
+ ", clusterName=" + request.getClusterName()
+ ", serviceGroupName=" + request.getServiceGroupName()
+ ", serviceName=" + request.getServiceName()
- + ", componentId=" + request.getComponentId()
+ + ", componentId=" + request.getHostComponentId()
+ ", componentName=" + request.getComponentName()
+ ", componentType=" + request.getComponentType()
+ ", hostname=" + request.getHostname()
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
index f9d5c57..1fb2088 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
@@ -26,7 +26,7 @@ public class ServiceComponentHostRequest {
private String clusterName; // REF
private String serviceGroupName;
private String serviceName;
- private Long componentId;
+ private Long hostComponentId;
private String componentName;
private String componentType;
private String hostname;
@@ -41,7 +41,7 @@ public class ServiceComponentHostRequest {
public ServiceComponentHostRequest(String clusterName,
String serviceGroupName,
String serviceName,
- Long componentId,
+ Long hostComponentId,
String componentName,
String componentType,
String hostname,
@@ -49,7 +49,7 @@ public class ServiceComponentHostRequest {
this.clusterName = clusterName;
this.serviceGroupName = serviceGroupName;
this.serviceName = serviceName;
- this.componentId = componentId;
+ this.hostComponentId = hostComponentId;
this.componentName = componentName;
this.componentType = componentType;
this.hostname = hostname;
@@ -91,10 +91,10 @@ public class ServiceComponentHostRequest {
}
/**
- * @return the componentd
+ * @return the ID of the host component
*/
- public Long getComponentId() {
- return componentId;
+ public Long getHostComponentId() {
+ return hostComponentId;
}
/**
@@ -112,10 +112,10 @@ public class ServiceComponentHostRequest {
}
/**
- * @param componentId the componentId to set
+ * @param hostComponentId ID of the host component the request applies to
*/
- public void setComponentId(Long componentId) {
- this.componentId = componentId;
+ public void setHostComponentId(Long hostComponentId) {
+ this.hostComponentId = hostComponentId;
}
/**
@@ -201,7 +201,7 @@ public class ServiceComponentHostRequest {
sb.append("{" + " clusterName=").append(clusterName)
.append(", serviceGroupName=").append(serviceGroupName)
.append(", serviceName=").append(serviceName)
- .append(", componentId=").append(componentId)
+ .append(", componentId=").append(hostComponentId)
.append(", componentName=").append(componentName)
.append(", componentType=").append(componentType)
.append(", hostname=").append(hostname)
@@ -244,7 +244,7 @@ public class ServiceComponentHostRequest {
return Objects.equals(clusterName, other.clusterName) &&
Objects.equals(serviceGroupName, other.serviceGroupName) &&
Objects.equals(serviceName, other.serviceName) &&
- Objects.equals(componentId, other.componentId) &&
+ Objects.equals(hostComponentId, other.hostComponentId) &&
Objects.equals(componentName, other.componentName) &&
Objects.equals(componentType, other.componentType) &&
Objects.equals(hostname, other.hostname) &&
@@ -259,7 +259,7 @@ public class ServiceComponentHostRequest {
@Override
public int hashCode() {
- return Objects.hash(clusterName, serviceGroupName, serviceName, componentId, componentName, componentType, hostname,
+ return Objects.hash(clusterName, serviceGroupName, serviceName, hostComponentId, componentName, componentType, hostname,
publicHostname, desiredState, state, desiredStackId, staleConfig, adminState, maintenanceState);
}
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
index 62fe38e..69642d0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
@@ -344,7 +344,7 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
notifyDelete(Resource.Type.HostComponent, predicate);
for(ServiceComponentHostRequest svcCmpntHostReq : requests) {
- deleteStatusMetaData.addDeletedKey("component_id: "+svcCmpntHostReq.getComponentId());
+ deleteStatusMetaData.addDeletedKey("component_id: "+svcCmpntHostReq.getHostComponentId());
}
return getRequestStatus(null, null, deleteStatusMetaData);
}
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 1447cca..03e3151 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
@@ -178,6 +178,8 @@ public interface Cluster {
String getComponentType(Long componentId) throws AmbariException;
+ ServiceComponentHost getHostComponentById(Long hostComponentId);
+
/**
* Get all services
*
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 8af5934..c1f5ef9 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
@@ -31,6 +31,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -209,6 +210,7 @@ public class ClusterImpl implements Cluster {
* [ ServiceName -> [ ServiceComponentName -> [ HostName -> [ ... ] ] ] ]
*/
private final ConcurrentMap<String, ConcurrentMap<String, ConcurrentMap<String, ServiceComponentHost>>> serviceComponentHosts = new ConcurrentHashMap<>();
+ private final Map<Long, ServiceComponentHost> serviceComponentHostsById = new ConcurrentHashMap<>();
/**
* [ HostName -> [ ... ] ]
@@ -467,6 +469,8 @@ public class ClusterImpl implements Cluster {
serviceComponentHosts.get(service.getName()).get(componentName).put(hostname,
svcHostComponent);
}
+
+ serviceComponentHostsById.put(svcHostComponent.getHostComponentId(), svcHostComponent);
}
}
}
@@ -762,14 +766,16 @@ public class ClusterImpl implements Cluster {
}
if (LOG.isDebugEnabled()) {
- LOG.debug("Adding a new ServiceComponentHost, clusterName={}, clusterId={}, serviceName={}, serviceComponentName{}, hostname= {}",
- getClusterName(), getClusterId(), serviceName, componentName, hostname);
+ LOG.debug("Adding a new ServiceComponentHost, clusterName={}, clusterId={}, serviceName={}, serviceComponentName={}, hostname={}, hostComponentId={}",
+ getClusterName(), getClusterId(), serviceName, componentName, hostname, svcCompHost.getHostComponentId());
}
serviceComponentHosts.get(serviceName).get(componentName).put(hostname,
svcCompHost);
serviceComponentHostsByHost.get(hostname).add(svcCompHost);
+
+ serviceComponentHostsById.put(svcCompHost.getHostComponentId(), svcCompHost);
}
@Override
@@ -836,13 +842,14 @@ public class ClusterImpl implements Cluster {
}
if (LOG.isDebugEnabled()) {
- LOG.debug("Removing a ServiceComponentHost, clusterName={}, clusterId={}, serviceName={}, serviceComponentName{}, hostname= {}",
- getClusterName(), getClusterId(), serviceName, componentName, hostname);
+ LOG.debug("Removing a ServiceComponentHost, clusterName={}, clusterId={}, serviceName={}, serviceComponentName{}, hostname={}, hostComponentId={}",
+ getClusterName(), getClusterId(), serviceName, componentName, hostname, schToRemove.getHostComponentId());
}
serviceComponentHosts.get(serviceName).get(componentName).remove(hostname);
if (schToRemove != null) {
serviceComponentHostsByHost.get(hostname).remove(schToRemove);
+ serviceComponentHostsById.remove(schToRemove.getHostComponentId());
}
}
@@ -1228,6 +1235,11 @@ public class ClusterImpl implements Cluster {
}
@Override
+ public ServiceComponentHost getHostComponentById(Long hostComponentId) {
+ return serviceComponentHostsById.get(hostComponentId);
+ }
+
+ @Override
public String getComponentName(Long componentId) throws AmbariException {
for (Service service : services.values()) {
for (ServiceComponent component : service.getServiceComponents().values()) {
@@ -1832,6 +1844,7 @@ public class ClusterImpl implements Cluster {
services.remove(serviceName);
servicesById.remove(service.getServiceId());
serviceConfigTypes.remove(service.getServiceId());
+ serviceComponentHostsById.values().removeIf(each -> Objects.equals(each.getServiceId(), service.getServiceId()));
for (List<ServiceComponentHost> serviceComponents : serviceComponentHostsByHost.values()) {
Iterables.removeIf(serviceComponents, new Predicate<ServiceComponentHost>() {
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 a8795b3..f526cc0 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
@@ -26,6 +26,8 @@ import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -251,6 +253,9 @@ public class ClusterImplTest {
ServiceComponentHost tezClientHost1 = tezClient.addServiceComponentHost(hostName1);
ServiceComponentHost tezClientHost2 = tezClient.addServiceComponentHost(hostName2);
+ assertSame(tezClientHost1, cluster.getHostComponentById(tezClientHost1.getHostComponentId()));
+ assertSame(tezClientHost2, cluster.getHostComponentById(tezClientHost2.getHostComponentId()));
+
// When
cluster.deleteService(serviceToDelete, new DeleteHostComponentStatusMetaData());
@@ -264,6 +269,8 @@ public class ClusterImplTest {
assertTrue("All components of the deleted service should be removed from all hosts", checkHost1 && checkHost2);
+ assertNull(cluster.getHostComponentById(tezClientHost1.getHostComponentId()));
+ assertNull(cluster.getHostComponentById(tezClientHost2.getHostComponentId()));
}
@Test
--
To stop receiving notification emails like this one, please contact
adoroszlai@apache.org.