YARN-8683. Support to display pending scheduling requests in RM app attempt page. Contributed by Tao Yang.

This commit is contained in:
Weiwei Yang 2018-08-21 19:00:31 +08:00
parent d3fef7a5c5
commit 54d0bf8935
9 changed files with 129 additions and 9 deletions

View File

@ -877,6 +877,16 @@ public List<ResourceRequest> getPendingResourceRequestsForAttempt(
return null; return null;
} }
@Override
public List<SchedulingRequest> getPendingSchedulingRequestsForAttempt(
ApplicationAttemptId attemptId) {
SchedulerApplicationAttempt attempt = getApplicationAttempt(attemptId);
if (attempt != null) {
return attempt.getAppSchedulingInfo().getAllSchedulingRequests();
}
return null;
}
@Override @Override
public Priority checkAndGetApplicationPriority( public Priority checkAndGetApplicationPriority(
Priority priorityRequestedByApp, UserGroupInformation user, Priority priorityRequestedByApp, UserGroupInformation user,

View File

@ -476,6 +476,23 @@ public List<ResourceRequest> getAllResourceRequests() {
return ret; return ret;
} }
/**
* Fetch SchedulingRequests.
* @return All pending SchedulingRequests.
*/
public List<SchedulingRequest> getAllSchedulingRequests() {
List<SchedulingRequest> ret = new ArrayList<>();
try {
this.readLock.lock();
schedulerKeyToAppPlacementAllocator.values().stream()
.filter(ap -> ap.getSchedulingRequest() != null)
.forEach(ap -> ret.add(ap.getSchedulingRequest()));
} finally {
this.readLock.unlock();
}
return ret;
}
public PendingAsk getNextPendingAsk() { public PendingAsk getNextPendingAsk() {
try { try {
readLock.lock(); readLock.lock();

View File

@ -363,6 +363,16 @@ public Priority updateApplicationPriority(Priority newPriority,
List<ResourceRequest> getPendingResourceRequestsForAttempt( List<ResourceRequest> getPendingResourceRequestsForAttempt(
ApplicationAttemptId attemptId); ApplicationAttemptId attemptId);
/**
* Get pending scheduling request for specified application attempt.
*
* @param attemptId the id of the application attempt
*
* @return pending scheduling requests
*/
List<SchedulingRequest> getPendingSchedulingRequestsForAttempt(
ApplicationAttemptId attemptId);
/** /**
* Get cluster max priority. * Get cluster max priority.
* *

View File

@ -192,4 +192,10 @@ public void initialize(AppSchedulingInfo appSchedulingInfo,
this.rmContext = rmContext; this.rmContext = rmContext;
this.schedulerRequestKey = schedulerRequestKey; this.schedulerRequestKey = schedulerRequestKey;
} }
/**
* Get pending SchedulingRequest.
* @return SchedulingRequest
*/
public abstract SchedulingRequest getSchedulingRequest();
} }

View File

@ -425,4 +425,9 @@ public ContainerRequest allocate(SchedulerRequestKey schedulerKey,
writeLock.unlock(); writeLock.unlock();
} }
} }
@Override
public SchedulingRequest getSchedulingRequest() {
return null;
}
} }

View File

@ -505,8 +505,8 @@ public void showRequests() {
} }
} }
@VisibleForTesting @Override
SchedulingRequest getSchedulingRequest() { public SchedulingRequest getSchedulingRequest() {
return schedulingRequest; return schedulingRequest;
} }

View File

@ -87,10 +87,14 @@ private void createResourceRequestsTable(Block html) {
.h3("Total Outstanding Resource Requests: " .h3("Total Outstanding Resource Requests: "
+ getTotalResource(resourceRequests)) + getTotalResource(resourceRequests))
.table("#resourceRequests").thead().tr().th(".priority", "Priority") .table("#resourceRequests").thead().tr().th(".priority", "Priority")
.th(".allocationRequestId", "AllocationRequestId")
.th(".resource", "ResourceName").th(".capacity", "Capability") .th(".resource", "ResourceName").th(".capacity", "Capability")
.th(".containers", "NumContainers") .th(".containers", "NumContainers")
.th(".relaxlocality", "RelaxLocality") .th(".relaxlocality", "RelaxLocality")
.th(".labelexpression", "NodeLabelExpression").__().__().tbody(); .th(".labelexpression", "NodeLabelExpression")
.th(".executiontype", "ExecutionType")
.th(".allocationTags", "AllocationTags")
.th(".placementConstraint", "PlacementConstraint").__().__().tbody();
StringBuilder resourceRequestTableData = new StringBuilder("[\n"); StringBuilder resourceRequestTableData = new StringBuilder("[\n");
for (ResourceRequestInfo resourceRequest : resourceRequests) { for (ResourceRequestInfo resourceRequest : resourceRequests) {
@ -99,7 +103,11 @@ private void createResourceRequestsTable(Block html) {
} }
resourceRequestTableData.append("[\"") resourceRequestTableData.append("[\"")
.append(String.valueOf(resourceRequest.getPriority())).append("\",\"") .append(String.valueOf(resourceRequest.getPriority())).append("\",\"")
.append(resourceRequest.getResourceName()).append("\",\"") .append(String.valueOf(resourceRequest.getAllocationRequestId()))
.append("\",\"")
.append(resourceRequest.getResourceName() == null ? "N/A"
: resourceRequest.getResourceName())
.append("\",\"")
.append(StringEscapeUtils.escapeEcmaScript(StringEscapeUtils .append(StringEscapeUtils.escapeEcmaScript(StringEscapeUtils
.escapeHtml4(String.valueOf(resourceRequest.getCapability())))) .escapeHtml4(String.valueOf(resourceRequest.getCapability()))))
.append("\",\"") .append("\",\"")
@ -109,6 +117,15 @@ private void createResourceRequestsTable(Block html) {
.append("\",\"") .append("\",\"")
.append(resourceRequest.getNodeLabelExpression() == null ? "N/A" .append(resourceRequest.getNodeLabelExpression() == null ? "N/A"
: resourceRequest.getNodeLabelExpression()) : resourceRequest.getNodeLabelExpression())
.append("\",\"")
.append(resourceRequest.getExecutionTypeRequest() == null ? "N/A"
: resourceRequest.getExecutionTypeRequest().getExecutionType())
.append("\",\"")
.append(resourceRequest.getAllocationTags() == null ? "N/A" :
StringUtils.join(resourceRequest.getAllocationTags(), ","))
.append("\",\"")
.append(resourceRequest.getPlacementConstraint() == null ? "N/A"
: resourceRequest.getPlacementConstraint())
.append("\"],\n"); .append("\"],\n");
} }
if (resourceRequestTableData if (resourceRequestTableData
@ -132,7 +149,8 @@ private Resource getTotalResource(List<ResourceRequestInfo> requests) {
if (request.getNumContainers() == 0) { if (request.getNumContainers() == 0) {
continue; continue;
} }
if (request.getResourceName().equals(ResourceRequest.ANY)) { if (request.getResourceName() == null || request.getResourceName()
.equals(ResourceRequest.ANY)) {
Resources.addTo( Resources.addTo(
totalResource, totalResource,
Resources.multiply(request.getCapability().getResource(), Resources.multiply(request.getCapability().getResource(),

View File

@ -36,6 +36,7 @@
import org.apache.hadoop.yarn.api.records.LogAggregationStatus; import org.apache.hadoop.yarn.api.records.LogAggregationStatus;
import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.api.records.ResourceRequest; import org.apache.hadoop.yarn.api.records.ResourceRequest;
import org.apache.hadoop.yarn.api.records.SchedulingRequest;
import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
@ -230,6 +231,15 @@ public AppInfo(ResourceManager rm, RMApp app, Boolean hasAccess,
resourceRequests.add(new ResourceRequestInfo(req)); resourceRequests.add(new ResourceRequestInfo(req));
} }
} }
List<SchedulingRequest> schedulingRequestsRaw = rm.getRMContext()
.getScheduler().getPendingSchedulingRequestsForAttempt(
attempt.getAppAttemptId());
if (schedulingRequestsRaw != null) {
for (SchedulingRequest req : schedulingRequestsRaw) {
resourceRequests.add(new ResourceRequestInfo(req));
}
}
} }
} }
} }

View File

@ -21,11 +21,13 @@
import org.apache.hadoop.yarn.api.records.ExecutionTypeRequest; import org.apache.hadoop.yarn.api.records.ExecutionTypeRequest;
import org.apache.hadoop.yarn.api.records.Priority; import org.apache.hadoop.yarn.api.records.Priority;
import org.apache.hadoop.yarn.api.records.ResourceRequest; import org.apache.hadoop.yarn.api.records.ResourceRequest;
import org.apache.hadoop.yarn.api.records.SchedulingRequest;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.Set;
/** /**
* Simple class representing a resource request. * Simple class representing a resource request.
@ -36,6 +38,8 @@ public class ResourceRequestInfo {
@XmlElement(name = "priority") @XmlElement(name = "priority")
private int priority; private int priority;
@XmlElement(name = "allocationRequestId")
private long allocationRequestId;
@XmlElement(name = "resourceName") @XmlElement(name = "resourceName")
private String resourceName; private String resourceName;
@XmlElement(name = "capability") @XmlElement(name = "capability")
@ -50,16 +54,17 @@ public class ResourceRequestInfo {
@XmlElement(name = "executionTypeRequest") @XmlElement(name = "executionTypeRequest")
private ExecutionTypeRequestInfo executionTypeRequest; private ExecutionTypeRequestInfo executionTypeRequest;
@XmlElement(name = "executionType") @XmlElement(name = "placementConstraint")
private String executionType; private String placementConstraint;
@XmlElement(name = "enforceExecutionType") @XmlElement(name = "allocationTags")
private boolean enforceExecutionType; private Set<String> allocationTags;
public ResourceRequestInfo() { public ResourceRequestInfo() {
} }
public ResourceRequestInfo(ResourceRequest request) { public ResourceRequestInfo(ResourceRequest request) {
priority = request.getPriority().getPriority(); priority = request.getPriority().getPriority();
allocationRequestId = request.getAllocationRequestId();
resourceName = request.getResourceName(); resourceName = request.getResourceName();
capability = new ResourceInfo(request.getCapability()); capability = new ResourceInfo(request.getCapability());
numContainers = request.getNumContainers(); numContainers = request.getNumContainers();
@ -71,6 +76,21 @@ public ResourceRequestInfo(ResourceRequest request) {
} }
} }
public ResourceRequestInfo(SchedulingRequest request) {
priority = request.getPriority().getPriority();
allocationRequestId = request.getAllocationRequestId();
capability = new ResourceInfo(request.getResourceSizing().getResources());
numContainers = request.getResourceSizing().getNumAllocations();
if (request.getExecutionType() != null) {
executionTypeRequest =
new ExecutionTypeRequestInfo(request.getExecutionType());
}
allocationTags = request.getAllocationTags();
if (request.getPlacementConstraint() != null) {
placementConstraint = request.getPlacementConstraint().toString();
}
}
public Priority getPriority() { public Priority getPriority() {
return Priority.newInstance(priority); return Priority.newInstance(priority);
} }
@ -128,4 +148,28 @@ public void setExecutionTypeRequest(
public ExecutionTypeRequestInfo getExecutionTypeRequest() { public ExecutionTypeRequestInfo getExecutionTypeRequest() {
return executionTypeRequest; return executionTypeRequest;
} }
public String getPlacementConstraint() {
return placementConstraint;
}
public void setPlacementConstraint(String placementConstraint) {
this.placementConstraint = placementConstraint;
}
public Set<String> getAllocationTags() {
return allocationTags;
}
public void setAllocationTags(Set<String> allocationTags) {
this.allocationTags = allocationTags;
}
public long getAllocationRequestId() {
return allocationRequestId;
}
public void setAllocationRequestId(long allocationRequestId) {
this.allocationRequestId = allocationRequestId;
}
} }