Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ public ServiceComponentHostNotFoundException(String clusterName,
+ ", hostName=" + hostName);
}

public ServiceComponentHostNotFoundException(String clusterName,
String serviceName, Long serviceComponentId, String hostName) {
super("ServiceComponentHost not found"
+ ", clusterName=" + clusterName
+ ", serviceName=" + serviceName
+ ", serviceComponentId=" + serviceComponentId
+ ", hostName=" + hostName);
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import org.apache.ambari.server.api.resources.ResourceInstance;
import org.apache.ambari.server.controller.ReadOnlyConfigurationResponse;
import org.apache.ambari.server.controller.internal.MpackResourceProvider;
import org.apache.ambari.server.controller.internal.RootClusterSettingsResourceProvider;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.http.HttpStatus;
Expand Down Expand Up @@ -69,8 +68,6 @@ public RootClusterSettingService() {
@ApiOperation(value = "Returns information for all the read only 'cluster settings'",
response = ReadOnlyConfigurationResponse.ReadOnlyConfigurationResponseSwagger.class, responseContainer = RESPONSE_CONTAINER_LIST)
@ApiImplicitParams({
@ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = DATA_TYPE_STRING,
paramType = PARAM_TYPE_QUERY, defaultValue = MpackResourceProvider.MPACK_RESOURCE_ID),
@ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, dataType = DATA_TYPE_STRING,
paramType = PARAM_TYPE_QUERY),
@ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ RequestStatusResponse createAction(ExecuteActionRequest actionRequest, Map<Strin
*/
String findService(Cluster cluster, String componentName) throws AmbariException;

/**
* Get service name by cluster instance and component id
*
* @param cluster the cluster instance
* @param componentId the component id in Long type
*
* @return a service name
*
* @throws AmbariException if service name is null or empty
*/

String findService(Cluster cluster, Long componentId) throws AmbariException;

/**
* Get the clusters for this management controller.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,23 @@
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
import org.apache.ambari.server.orm.dao.ExtensionDAO;
import org.apache.ambari.server.orm.dao.ExtensionLinkDAO;
import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
import org.apache.ambari.server.orm.dao.SettingDAO;
import org.apache.ambari.server.orm.dao.StackDAO;
import org.apache.ambari.server.orm.dao.WidgetDAO;
import org.apache.ambari.server.orm.dao.WidgetLayoutDAO;
import org.apache.ambari.server.orm.entities.ClusterEntity;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
import org.apache.ambari.server.orm.entities.ExtensionLinkEntity;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.orm.entities.MpackEntity;
import org.apache.ambari.server.orm.entities.RepoDefinitionEntity;
import org.apache.ambari.server.orm.entities.RepoOsEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.SettingEntity;
import org.apache.ambari.server.orm.entities.StackEntity;
import org.apache.ambari.server.orm.entities.WidgetEntity;
Expand Down Expand Up @@ -327,6 +331,13 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle

@Inject
private ClusterServiceDAO clusterServiceDAO;

@Inject
private ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;

@Inject
private HostComponentStateDAO hostComponentStateDAO;

@Inject
private ExtensionDAO extensionDAO;
@Inject
Expand Down Expand Up @@ -388,6 +399,9 @@ public AmbariManagementControllerImpl(ActionManager actionManager,
masterHostname = InetAddress.getLocalHost().getCanonicalHostName();
maintenanceStateHelper = injector.getInstance(MaintenanceStateHelper.class);
kerberosHelper = injector.getInstance(KerberosHelper.class);
hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);

if(configs != null)
{
if (configs.getApiSSLAuthentication()) {
Expand Down Expand Up @@ -616,6 +630,13 @@ public synchronized Set<ServiceComponentHostResponse> createHostComponents(Set<S
for (ServiceComponentHostRequest request : requests) {
validateServiceComponentHostRequest(request);

// TODO: Multi_Component_Instance. When we go into multiple component instance mode, we will need make
// component_type as manadatory field. As of now, we are just copying component_name into component_type,
// if not provided. Further, need to add validation check too.
if(StringUtils.isBlank(request.getComponentType())) {
request.setComponentType(request.getComponentName());
}

Cluster cluster;
try {
cluster = clusters.getCluster(request.getClusterName());
Expand All @@ -639,8 +660,10 @@ public synchronized Set<ServiceComponentHostResponse> createHostComponents(Set<S
}

if (LOG.isDebugEnabled()) {
LOG.debug("Received a createHostComponent request, clusterName={}, serviceGroupName={}, serviceName={}, componentName={}, hostname={}, request={}",
request.getClusterName(), request.getServiceGroupName(), request.getServiceName(), request.getComponentName(), request.getHostname(), request);
LOG.debug("Received a createHostComponent request, clusterName={}, serviceGroupName={}, serviceName={}, " +
"componentName={}, componentType={}, hostname={}, request={}", request.getClusterName(),
request.getServiceGroupName(), request.getServiceName(), request.getComponentName(),
request.getComponentType(), request.getHostname(), request);
}

if (!hostComponentNames.containsKey(request.getClusterName())) {
Expand Down Expand Up @@ -1259,7 +1282,7 @@ private Set<ServiceComponentHostResponse> getHostComponents(
}

if (StringUtils.isBlank(serviceName)) {
LOG.error("Unable to find service for component {}", request.getComponentName());
LOG.error("Unable to find service for componentName : {}", request.getComponentName());
throw new ServiceComponentHostNotFoundException(
cluster.getClusterName(), null, request.getComponentName(), request.getHostname());
}
Expand Down Expand Up @@ -1310,6 +1333,31 @@ private Set<ServiceComponentHostResponse> getHostComponents(
Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs();
Map<String, Host> hosts = clusters.getHostsForCluster(cluster.getClusterName());

/*
This is a core step in retrieving a given component instance in multi-host component instances world.
We fetch the 'HostComponentStateEntity' based on the 'host component Id' passed-in in the request. if it exists,
we use the service group Id, service Id, componentName and componentType to query the unique ServiceComponentEntity
associated with it.
*/
ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = null;
HostComponentStateEntity hostComponentStateEntity = null;
if (request.getComponentId() != null) {
hostComponentStateEntity = hostComponentStateDAO.findById(request.getComponentId());
if (hostComponentStateEntity == null) {
throw new AmbariException("Could not find Host Component resource for"
+ " componentId = "+ request.getComponentId());
}
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()
+ ", serviceId = " + hostComponentStateEntity.getServiceId() + ", componentName = " + hostComponentStateEntity.getComponentName()
+ ", componntType = " + hostComponentStateEntity.getComponentType());
}
}

for (Service s : services) {
// filter on component name if provided
Set<ServiceComponent> components = new HashSet<>();
Expand All @@ -1318,9 +1366,12 @@ private Set<ServiceComponentHostResponse> getHostComponents(
} else {
components.addAll(s.getServiceComponents().values());
}

for (ServiceComponent sc : components) {
if (request.getComponentName() != null) {
if (!sc.getName().equals(request.getComponentName())) {
if (serviceComponentDesiredStateEntity != null &&
serviceComponentDesiredStateEntity.getId() != null &&
sc.getId() != null) {
if (!sc.getId().equals(serviceComponentDesiredStateEntity.getId())) {
continue;
}
}
Expand Down Expand Up @@ -1380,7 +1431,7 @@ private Set<ServiceComponentHostResponse> getHostComponents(

response.add(r);
} catch (ServiceComponentHostNotFoundException e) {
if (request.getServiceName() == null || request.getComponentName() == null) {
if (request.getServiceName() == null || request.getComponentId() == 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.
Expand All @@ -1392,7 +1443,7 @@ private Set<ServiceComponentHostResponse> getHostComponents(
// condition.
LOG.debug("ServiceComponentHost not found ", e);
throw new ServiceComponentHostNotFoundException(cluster.getClusterName(),
request.getServiceName(), request.getComponentName(), request.getHostname());
request.getServiceName(), request.getComponentId(), request.getHostname());
}
}
} else {
Expand Down Expand Up @@ -3512,10 +3563,14 @@ public void validateServiceComponentHostRequest(ServiceComponentHostRequest requ
|| request.getClusterName().isEmpty()
|| request.getComponentName() == null
|| request.getComponentName().isEmpty()
|| request.getServiceName() == null
|| request.getServiceName().isEmpty()
|| request.getServiceGroupName() == null
|| request.getServiceGroupName().isEmpty()
|| request.getHostname() == null
|| request.getHostname().isEmpty()) {
throw new IllegalArgumentException("Invalid arguments"
+ ", cluster name, component name and host name should be"
+ ", cluster name, component name, service name, service group name and host name should be"
+ " provided");
}

Expand Down Expand Up @@ -3545,6 +3600,11 @@ public String findService(Cluster cluster, String componentName) throws AmbariEx
return cluster.getServiceByComponentName(componentName).getName();
}

@Override
public String findService(Cluster cluster, Long componentId) throws AmbariException {
return cluster.getServiceByComponentId(componentId).getName();
}

@Override
public synchronized void deleteCluster(ClusterRequest request)
throws AmbariException {
Expand Down Expand Up @@ -3585,8 +3645,8 @@ public DeleteStatusMetaData deleteHostComponents(

for (ServiceComponentHost sch : cluster.getServiceComponentHosts(request.getHostname())) {
ServiceComponentHostRequest schr = new ServiceComponentHostRequest(request.getClusterName(),
request.getServiceGroupName(), sch.getServiceName(), sch.getServiceComponentName(),
sch.getHostName(), null);
sch.getServiceGroupName(), sch.getServiceName(), sch.getServiceComponentId(), sch.getServiceComponentName(),
sch.getServiceComponentType(), sch.getHostName(), null);
expanded.add(schr);
}
}
Expand All @@ -3612,6 +3672,7 @@ public DeleteStatusMetaData deleteHostComponents(
+ ", clusterName=" + request.getClusterName()
+ ", serviceName=" + request.getServiceName()
+ ", componentName=" + request.getComponentName()
+ ", componentType=" + request.getComponentType()
+ ", hostname=" + request.getHostname()
+ ", request=" + request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class ServiceComponentHostRequest {
private String clusterName; // REF
private String serviceGroupName;
private String serviceName;
private Long componentId;
private String componentName;
private String componentType;
private String hostname;
private String publicHostname;
private String state;
Expand All @@ -39,17 +41,31 @@ public class ServiceComponentHostRequest {
public ServiceComponentHostRequest(String clusterName,
String serviceGroupName,
String serviceName,
Long componentId,
String componentName,
String componentType,
String hostname,
String desiredState) {
this.clusterName = clusterName;
this.serviceGroupName = serviceGroupName;
this.serviceName = serviceName;
this.componentId = componentId;
this.componentName = componentName;
this.componentType = componentType;
this.hostname = hostname;
this.desiredState = desiredState;
}

public ServiceComponentHostRequest(String clusterName,
String serviceGroupName,
String serviceName,
String componentName,
String componentType,
String hostname,
String desiredState) {
this(clusterName, serviceGroupName, serviceName, null, componentName, componentType, hostname, desiredState);
}

/**
* @return the service group Name
*/
Expand All @@ -74,6 +90,13 @@ public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

/**
* @return the componentd
*/
public Long getComponentId() {
return componentId;
}

/**
* @return the componentName
*/
Expand All @@ -88,6 +111,22 @@ public void setComponentName(String componentName) {
this.componentName = componentName;
}

/**
* @param componentId the componentId to set
*/
public void setComponentId(Long componentId) {
this.componentId = componentId;
}

/**
* @return the componentType
*/
public String getComponentType() { return componentType; }

/**
* @param componentType the componenType to set
*/
public void setComponentType(String componentType) { this.componentType = componentType; }
/**
* @return the hostname
*/
Expand Down Expand Up @@ -162,7 +201,9 @@ public String toString() {
sb.append("{" + " clusterName=").append(clusterName)
.append(", serviceGroupName=").append(serviceGroupName)
.append(", serviceName=").append(serviceName)
.append(", componentId=").append(componentId)
.append(", componentName=").append(componentName)
.append(", componentType=").append(componentType)
.append(", hostname=").append(hostname)
.append(", publicHostname=").append(publicHostname)
.append(", desiredState=").append(desiredState)
Expand Down Expand Up @@ -203,7 +244,9 @@ public boolean equals(Object obj) {
return Objects.equals(clusterName, other.clusterName) &&
Objects.equals(serviceGroupName, other.serviceGroupName) &&
Objects.equals(serviceName, other.serviceName) &&
Objects.equals(componentId, other.componentId) &&
Objects.equals(componentName, other.componentName) &&
Objects.equals(componentType, other.componentType) &&
Objects.equals(hostname, other.hostname) &&
Objects.equals(publicHostname, other.publicHostname) &&
Objects.equals(desiredState, other.desiredState) &&
Expand All @@ -216,7 +259,7 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return Objects.hash(clusterName, serviceGroupName, serviceName, componentName, hostname, publicHostname,
desiredState, state, desiredStackId, staleConfig, adminState, maintenanceState);
return Objects.hash(clusterName, serviceGroupName, serviceName, componentId, componentName, componentType, hostname,
publicHostname, desiredState, state, desiredStackId, staleConfig, adminState, maintenanceState);
}
}
Loading