Skip to content
Closed
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
6,975 changes: 6,975 additions & 0 deletions AMBARI-22945.002.patch

Large diffs are not rendered by default.

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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public ServiceComponentNotFoundException (String clusterName,
+ ", serviceComponentName=" + serviceComponentName);
}

public ServiceComponentNotFoundException (String clusterName,
String serviceName, String serviceType, String serviceGroupName, Long serviceComponentId) {
super("ServiceComponent not found"
+ ", clusterName=" + clusterName
+ ", serviceGroupName=" + serviceGroupName
+ ", serviceName=" + serviceName
+ ", serviceType=" + serviceType
+ ", serviceComponentId=" + serviceComponentId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ public HostComponentService(String clusterName, String hostName) {
}

/**
* Handles GET /clusters/{clusterID}/hosts/{hostID}/host_components/{hostComponentID}
* Handles GET /clusters/{clusterName}/hosts/{hostID}/host_components/{hostComponentID}
* Get a specific host_component.
*
* @param headers http headers
* @param ui uri info
* @param hostComponentName host_component id
* @return host_component resource representation
* @param hostComponentId host_component id
* @return host_component resource representation
*/
@GET @ApiIgnore // until documented
@Path("{hostComponentName}")
@Path("{hostComponentId}")
@Produces("text/plain")
public Response getHostComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("hostComponentName") String hostComponentName, @QueryParam("format") String format) {
@PathParam("hostComponentId") String hostComponentId, @QueryParam("format") String format) {

//todo: needs to be refactored when properly handling exceptions
if (m_hostName == null) {
Expand All @@ -93,11 +93,11 @@ public Response getHostComponent(String body, @Context HttpHeaders headers, @Con
}

if (format != null && format.equals("client_config_tar")) {
return createClientConfigResource(body, headers, ui, hostComponentName);
return createClientConfigResource(body, headers, ui, hostComponentId);
}

return handleRequest(headers, body, ui, Request.Type.GET,
createHostComponentResource(m_clusterName, m_hostName, hostComponentName));
createHostComponentResource(m_clusterName, m_hostName, hostComponentId));
}

/**
Expand Down Expand Up @@ -144,18 +144,18 @@ public Response createHostComponents(String body, @Context HttpHeaders headers,
* @param body http body
* @param headers http headers
* @param ui uri info
* @param hostComponentName host_component id
* @param hostComponentId host_component id
*
* @return host_component resource representation
*/
@POST @ApiIgnore // until documented
@Path("{hostComponentName}")
@Path("{hostComponentId}")
@Produces("text/plain")
public Response createHostComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("hostComponentName") String hostComponentName) {
@PathParam("hostComponentId") String hostComponentId) {

return handleRequest(headers, body, ui, Request.Type.POST,
createHostComponentResource(m_clusterName, m_hostName, hostComponentName));
createHostComponentResource(m_clusterName, m_hostName, hostComponentId));
}

/**
Expand All @@ -165,18 +165,18 @@ public Response createHostComponent(String body, @Context HttpHeaders headers, @
* @param body http body
* @param headers http headers
* @param ui uri info
* @param hostComponentName host_component id
* @param hostComponentId host_component id
*
* @return information regarding updated host_component
*/
@PUT @ApiIgnore // until documented
@Path("{hostComponentName}")
@Path("{hostComponentId}")
@Produces("text/plain")
public Response updateHostComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("hostComponentName") String hostComponentName) {
@PathParam("hostComponentId") String hostComponentId) {

return handleRequest(headers, body, ui, Request.Type.PUT,
createHostComponentResource(m_clusterName, m_hostName, hostComponentName));
createHostComponentResource(m_clusterName, m_hostName, hostComponentId));
}

/**
Expand All @@ -203,18 +203,18 @@ public Response updateHostComponents(String body, @Context HttpHeaders headers,
*
* @param headers http headers
* @param ui uri info
* @param hostComponentName host_component id
* @param hostComponentId host_component id
*
* @return host_component resource representation
*/
@DELETE @ApiIgnore // until documented
@Path("{hostComponentName}")
@Path("{hostComponentId}")
@Produces("text/plain")
public Response deleteHostComponent(@Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("hostComponentName") String hostComponentName) {
@PathParam("hostComponentId") String hostComponentId) {

return handleRequest(headers, null, ui, Request.Type.DELETE,
createHostComponentResource(m_clusterName, m_hostName, hostComponentName));
createHostComponentResource(m_clusterName, m_hostName, hostComponentId));
}

/**
Expand All @@ -235,14 +235,14 @@ public Response deleteHostComponents(String body, @Context HttpHeaders headers,
}

@GET @ApiIgnore // until documented
@Path("{hostComponentName}/processes")
@Path("{hostComponentId}/processes")
@Produces("text/plain")
public Response getProcesses(@Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("hostComponentName") String hostComponentName) {
@PathParam("hostComponentId") String hostComponentId) {
Map<Resource.Type,String> mapIds = new HashMap<>();
mapIds.put(Resource.Type.Cluster, m_clusterName);
mapIds.put(Resource.Type.Host, m_hostName);
mapIds.put(Resource.Type.HostComponent, hostComponentName);
mapIds.put(Resource.Type.HostComponent, hostComponentId);

ResourceInstance ri = createResource(Resource.Type.HostComponentProcess, mapIds);

Expand All @@ -254,25 +254,25 @@ public Response getProcesses(@Context HttpHeaders headers, @Context UriInfo ui,
*
* @param clusterName cluster name
* @param hostName host name
* @param hostComponentName host_component name
* @param hostComponentId host_component id
*
* @return a host resource instance
*/
ResourceInstance createHostComponentResource(String clusterName, String hostName, String hostComponentName) {
ResourceInstance createHostComponentResource(String clusterName, String hostName, String hostComponentId) {
Map<Resource.Type,String> mapIds = new HashMap<>();
mapIds.put(Resource.Type.Cluster, clusterName);
mapIds.put(Resource.Type.Host, hostName);
mapIds.put(Resource.Type.HostComponent, hostComponentName);
mapIds.put(Resource.Type.HostComponent, hostComponentId);

return createResource(Resource.Type.HostComponent, mapIds);
}

private Response createClientConfigResource(String body, HttpHeaders headers, UriInfo ui,
String hostComponentName) {
String hostComponentId) {
Map<Resource.Type,String> mapIds = new HashMap<>();
mapIds.put(Resource.Type.Cluster, m_clusterName);
mapIds.put(Resource.Type.Host, m_hostName);
mapIds.put(Resource.Type.Component, hostComponentName);
mapIds.put(Resource.Type.Component, hostComponentId);

Response response = handleRequest(headers, body, ui, Request.Type.GET,
createResource(Resource.Type.ClientConfig, mapIds));
Expand All @@ -284,10 +284,10 @@ private Response createClientConfigResource(String body, HttpHeaders headers, Ur

String filePrefixName;

if (StringUtils.isEmpty(hostComponentName)) {
if (StringUtils.isEmpty(hostComponentId)) {
filePrefixName = m_hostName + "(" + Resource.InternalType.Host.toString().toUpperCase()+")";
} else {
filePrefixName = hostComponentName;
filePrefixName = hostComponentId;
}

Validate.notNull(filePrefixName, "compressed config file name should not be null");
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 @@ -624,6 +624,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 @@ -647,8 +654,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 @@ -1254,7 +1263,7 @@ private Set<ServiceComponentHostResponse> getHostComponents(
}
}

if (request.getComponentName() != null) {
if (request.getComponentName() != null ) {
if (StringUtils.isBlank(request.getServiceName())) {

// !!! FIXME the assumption that a component is unique across all stacks is a ticking
Expand All @@ -1267,7 +1276,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 component Name : {}", request.getComponentName());
throw new ServiceComponentHostNotFoundException(
cluster.getClusterName(), null, request.getComponentName(), request.getHostname());
}
Expand Down Expand Up @@ -1323,11 +1332,15 @@ private Set<ServiceComponentHostResponse> getHostComponents(
Set<ServiceComponent> components = new HashSet<>();
if (request.getComponentName() != null) {
components.add(s.getServiceComponent(request.getComponentName()));
} else {
}else {
components.addAll(s.getServiceComponents().values());
}
for (ServiceComponent sc : components) {
if (request.getComponentName() != null) {
if (request.getComponentId() != null && sc.getId() != null) {
if (sc.getId() != request.getComponentId()) {
continue;
}
} else if (request.getComponentName() != null && sc.getName() != null) {
if (!sc.getName().equals(request.getComponentName())) {
continue;
}
Expand Down Expand Up @@ -1388,7 +1401,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 @@ -1400,7 +1413,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 @@ -3562,10 +3575,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 @@ -3595,6 +3612,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 @@ -3635,8 +3657,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);
request.getServiceGroupName(), sch.getServiceName(), sch.getServiceComponentId(), sch.getServiceComponentName(),
sch.getServiceComponentType(), sch.getHostName(), null);
expanded.add(schr);
}
}
Expand All @@ -3662,6 +3684,7 @@ public DeleteStatusMetaData deleteHostComponents(
+ ", clusterName=" + request.getClusterName()
+ ", serviceName=" + request.getServiceName()
+ ", componentName=" + request.getComponentName()
+ ", componentType=" + request.getComponentType()
+ ", hostname=" + request.getHostname()
+ ", request=" + request);

Expand Down
Loading