YARN-11160. Support getResourceProfiles, getResourceProfile API's for Federation#4540
YARN-11160. Support getResourceProfiles, getResourceProfile API's for Federation#4540goiri merged 9 commits intoapache:trunkfrom
Conversation
|
💔 -1 overall
This message was automatically generated. |
|
💔 -1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
| GetAllResourceProfilesResponse response = interceptor.getResourceProfiles(request); | ||
|
|
||
| Assert.assertNotNull(response); | ||
| Assert.assertEquals(response.getResourceProfiles().get("maximum").getMemorySize(), 32768); |
There was a problem hiding this comment.
Can we extract some of these?
resProfiles = response.getResourceProfiles()
maxResProfiles = resProfiles.get("maximum")
There was a problem hiding this comment.
Thanks for your suggestion, I will fix it.
| Assert.assertEquals(response.getResource().getMemorySize(), 32768); | ||
| Assert.assertEquals(response.getResource().getVirtualCores(), 16); | ||
|
|
||
| request = GetResourceProfileRequest.newInstance("default"); |
| import org.apache.hadoop.yarn.api.protocolrecords.GetQueueUserAclsInfoResponse; | ||
| import org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse; | ||
| import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse; | ||
| import org.apache.hadoop.yarn.api.protocolrecords.*; |
| GetResourceProfileResponse response = | ||
| RouterYarnClientUtils.mergeClusterResourceProfileResponse(responses); | ||
| Resource resource = response.getResource(); | ||
| Assert.assertEquals(resource.getVirtualCores(), 3); |
There was a problem hiding this comment.
Thanks for the suggestion, I will fix it.
|
🎊 +1 overall
This message was automatically generated. |
|
Hi, @goiri , Please help me review the code again, Thank you very much! |
|
🎊 +1 overall
This message was automatically generated. |
| String key = entry.getKey(); | ||
| Resource value = entry.getValue(); | ||
| if (profilesMap.containsKey(key)) { | ||
| Resource resourceValue = profilesMap.get(key); |
There was a problem hiding this comment.
I think in Resource or ResourceUtils there was something to add to an existing resource.
There was a problem hiding this comment.
Thanks for your suggestion, I will modify the code.
| Resource resource = Resource.newInstance(0, 0); | ||
| for (GetResourceProfileResponse response : responses) { | ||
| if (response != null && response.getResource() != null) { | ||
| resource.setMemorySize(resource.getMemorySize() + response.getResource().getMemorySize()); |
There was a problem hiding this comment.
OK, i will fix it.
|
🎊 +1 overall
This message was automatically generated. |
| */ | ||
| String[] keys = { "memory", ResourceInformation.MEMORY_URI, | ||
| ResourceInformation.VCORES_URI }; | ||
| String[] keys = {"memory", ResourceInformation.MEMORY_URI, |
There was a problem hiding this comment.
As we are at it... let's make it a single line.
| return res; | ||
| } | ||
|
|
||
| public static Resource mergeResources(Resource r1, Resource r2) { |
There was a problem hiding this comment.
I was referring to Resources.add():
There was a problem hiding this comment.
I will use the method Resource add(Resource lhs, Resource rhs), this method looks fine.
|
🎊 +1 overall
This message was automatically generated. |
| LOG.error("Unable to get resource profiles due to exception.", ex); | ||
| throw ex; | ||
| } | ||
| long stopTime = clock.getTime(); |
There was a problem hiding this comment.
Couldn't we move this and the setting inside of the try?
There was a problem hiding this comment.
code show as below:
long startTime = clock.getTime();
ClientMethod remoteMethod = new ClientMethod("getResourceProfile",
new Class[] {GetResourceProfileRequest.class}, new Object[] {request});
Collection<GetResourceProfileResponse> resourceProfile = null;
try {
resourceProfile = invokeAppClientProtocolMethod(true, remoteMethod,
GetResourceProfileResponse.class);
} catch (Exception ex) {
routerMetrics.incrGetResourceProfileFailedRetrieved();
RouterServerUtil.logAndThrowException("Unable to get resource profile due to exception.",
ex);
}
long stopTime = clock.getTime();
startTime - stopTime represents the execution time of the code fragment
I think the current way should be a little better, can this part stay as it is?
| } | ||
| long stopTime = clock.getTime(); | ||
| routerMetrics.succeededGetResourceProfilesRetrieved(stopTime - startTime); | ||
| // Merge the GetAllResourceProfilesResponse |
There was a problem hiding this comment.
I will remove it.
| String key = entry.getKey(); | ||
| Resource r1 = profilesMap.getOrDefault(key, null); | ||
| Resource r2 = entry.getValue(); | ||
| profilesMap.put(key, r1 == null ? r2 : Resources.add(r1, r2)); |
There was a problem hiding this comment.
I would extract this as:
rAdd = r1 == null ? r2 : Resources.add(r1, r2);
There was a problem hiding this comment.
This is a good idea.
| Map<String, Resource> resProfiles = response.getResourceProfiles(); | ||
|
|
||
| Resource maxResProfiles = resProfiles.get("maximum"); | ||
| Assert.assertEquals(maxResProfiles.getMemorySize(), 32768); |
|
🎊 +1 overall
This message was automatically generated. |
|
@goiri Please help to review the code again, thank you very much! I will follow up with YARN-11161. |
|
@goiri Can you help merge this pr to trunk branch? thank you very much! I will follow up with YARN-11161. |
|
@goiri thank you very much! |
YARN-11160. Support getResourceProfiles, getResourceProfile API's for Federation.