YARN-6789. Add Client API to get all supported resource types from RM. (Sunil G via wangda)
Change-Id: I366d8db6f6700acd087db5acb7a1be7e41b2b68d
(cherry picked from commit df3855541a
)
This commit is contained in:
parent
255668a2a6
commit
4af3deaeb0
|
@ -66,6 +66,7 @@ import org.apache.hadoop.yarn.api.records.NodeReport;
|
|||
import org.apache.hadoop.yarn.api.records.NodeState;
|
||||
import org.apache.hadoop.yarn.api.records.Priority;
|
||||
import org.apache.hadoop.yarn.api.records.QueueUserACLInfo;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
|
||||
import org.apache.hadoop.yarn.api.records.SignalContainerCommand;
|
||||
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||
import org.apache.hadoop.yarn.api.records.YarnClusterMetrics;
|
||||
|
@ -517,4 +518,10 @@ public class ResourceMgrDelegate extends YarnClient {
|
|||
throws YarnException, IOException {
|
||||
client.killApplication(appId, diagnostics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceTypeInfo> getResourceTypeInfo()
|
||||
throws YarnException, IOException {
|
||||
return client.getResourceTypeInfo();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -494,6 +496,13 @@ public class TestClientRedirect {
|
|||
throws YarnException, IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request)
|
||||
throws YarnException, IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class HistoryService extends AMService implements HSClientProtocol {
|
||||
|
|
|
@ -65,6 +65,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
|
||||
|
@ -589,4 +591,19 @@ public interface ApplicationClientProtocol extends ApplicationBaseProtocol {
|
|||
public UpdateApplicationTimeoutsResponse updateApplicationTimeouts(
|
||||
UpdateApplicationTimeoutsRequest request)
|
||||
throws YarnException, IOException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The interface to get the details for a specific resource profile.
|
||||
* </p>
|
||||
* @param request request to get the details of a resource profile
|
||||
* @return Response containing the details for a particular resource profile
|
||||
* @throws YarnException if resource profiles are not enabled on the RM or
|
||||
* the profile cannot be found
|
||||
* @throws IOException in case of other errors
|
||||
*/
|
||||
@Public
|
||||
@Unstable
|
||||
GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.api.protocolrecords;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.yarn.util.Records;
|
||||
|
||||
/**
|
||||
* Request class for getting all the resource profiles from the RM.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Unstable
|
||||
public abstract class GetAllResourceTypeInfoRequest {
|
||||
|
||||
public static GetAllResourceTypeInfoRequest newInstance() {
|
||||
return Records.newRecord(GetAllResourceTypeInfoRequest.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.api.protocolrecords;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
|
||||
import org.apache.hadoop.yarn.util.Records;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Response class for getting all the resource profiles from the RM.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Unstable
|
||||
public abstract class GetAllResourceTypeInfoResponse {
|
||||
|
||||
public static GetAllResourceTypeInfoResponse newInstance() {
|
||||
return Records.newRecord(GetAllResourceTypeInfoResponse.class);
|
||||
}
|
||||
|
||||
public abstract void setResourceTypeInfo(List<ResourceTypeInfo> resourceTypes);
|
||||
|
||||
public abstract List<ResourceTypeInfo> getResourceTypeInfo();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || !(other instanceof GetAllResourceTypeInfoResponse)) {
|
||||
return false;
|
||||
}
|
||||
return ((GetAllResourceTypeInfoResponse) other).getResourceTypeInfo()
|
||||
.equals(this.getResourceTypeInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getResourceTypeInfo().hashCode();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.api.records;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceAudience.Public;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.classification.InterfaceStability.Evolving;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
|
||||
import org.apache.hadoop.yarn.util.Records;
|
||||
|
||||
/**
|
||||
* Class to encapsulate information about a ResourceType - the name of the
|
||||
* resource, the units(milli, micro, etc), the type(countable).
|
||||
*/
|
||||
public abstract class ResourceTypeInfo implements Comparable<ResourceTypeInfo> {
|
||||
|
||||
/**
|
||||
* Get the name for the resource.
|
||||
*
|
||||
* @return resource name
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Set the name for the resource.
|
||||
*
|
||||
* @param rName
|
||||
* name for the resource
|
||||
*/
|
||||
public abstract void setName(String rName);
|
||||
|
||||
/**
|
||||
* Get units for the resource.
|
||||
*
|
||||
* @return units for the resource
|
||||
*/
|
||||
public abstract String getDefaultUnit();
|
||||
|
||||
/**
|
||||
* Set the units for the resource.
|
||||
*
|
||||
* @param rUnits
|
||||
* units for the resource
|
||||
*/
|
||||
public abstract void setDefaultUnit(String rUnits);
|
||||
|
||||
/**
|
||||
* Get the resource type.
|
||||
*
|
||||
* @return the resource type
|
||||
*/
|
||||
public abstract ResourceTypes getResourceType();
|
||||
|
||||
/**
|
||||
* Set the resource type.
|
||||
*
|
||||
* @param type
|
||||
* the resource type
|
||||
*/
|
||||
public abstract void setResourceType(ResourceTypes type);
|
||||
|
||||
/**
|
||||
* Create a new instance of ResourceTypeInfo from another object.
|
||||
*
|
||||
* @param other
|
||||
* the object from which the new object should be created
|
||||
* @return the new ResourceTypeInfo object
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Unstable
|
||||
public static ResourceTypeInfo newInstance(ResourceTypeInfo other) {
|
||||
ResourceTypeInfo resourceType = Records.newRecord(ResourceTypeInfo.class);
|
||||
copy(other, resourceType);
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of ResourceTypeInfo from name, units and type.
|
||||
*
|
||||
* @param name name of resource type
|
||||
* @param units units of resource type
|
||||
* @param type such as countable, etc.
|
||||
* @return the new ResourceTypeInfo object
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Unstable
|
||||
public static ResourceTypeInfo newInstance(String name, String units,
|
||||
ResourceTypes type) {
|
||||
ResourceTypeInfo resourceType = Records.newRecord(ResourceTypeInfo.class);
|
||||
resourceType.setName(name);
|
||||
resourceType.setResourceType(type);
|
||||
resourceType.setDefaultUnit(units);
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of ResourceTypeInfo from name, units
|
||||
*
|
||||
* @param name name of resource type
|
||||
* @param units units of resource type
|
||||
* @return the new ResourceTypeInfo object
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Unstable
|
||||
public static ResourceTypeInfo newInstance(String name, String units) {
|
||||
return ResourceTypeInfo.newInstance(name, units, ResourceTypes.COUNTABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of ResourceTypeInfo from name
|
||||
*
|
||||
* @param name name of resource type
|
||||
* @return the new ResourceTypeInfo object
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Unstable
|
||||
public static ResourceTypeInfo newInstance(String name) {
|
||||
return ResourceTypeInfo.newInstance(name, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the content of the source ResourceTypeInfo object to the
|
||||
* destination object, overwriting all properties of the destination object.
|
||||
*
|
||||
* @param src
|
||||
* Source ResourceTypeInfo object
|
||||
* @param dst
|
||||
* Destination ResourceTypeInfo object
|
||||
*/
|
||||
|
||||
public static void copy(ResourceTypeInfo src, ResourceTypeInfo dst) {
|
||||
dst.setName(src.getName());
|
||||
dst.setResourceType(src.getResourceType());
|
||||
dst.setDefaultUnit(src.getDefaultUnit());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "name: " + this.getName() + ", units: " + this.getDefaultUnit()
|
||||
+ ", type: " + getResourceType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof ResourceTypeInfo)) {
|
||||
return false;
|
||||
}
|
||||
ResourceTypeInfo r = (ResourceTypeInfo) obj;
|
||||
return this.getName().equals(r.getName())
|
||||
&& this.getResourceType().equals(r.getResourceType())
|
||||
&& this.getDefaultUnit().equals(r.getDefaultUnit());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 47;
|
||||
int result = prime + getName().hashCode();
|
||||
result = prime * result + getResourceType().hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ResourceTypeInfo other) {
|
||||
int diff = this.getName().compareTo(other.getName());
|
||||
if (diff == 0) {
|
||||
diff = this.getDefaultUnit().compareTo(other.getDefaultUnit());
|
||||
if (diff == 0) {
|
||||
diff = this.getResourceType().compareTo(other.getResourceType());
|
||||
}
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
}
|
|
@ -548,4 +548,17 @@ public class ResourceUtils {
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default unit by given resource type.
|
||||
* @param resourceType resourceType
|
||||
* @return default unit
|
||||
*/
|
||||
public static String getDefaultUnit(String resourceType) {
|
||||
ResourceInformation ri = getResourceTypes().get(resourceType);
|
||||
if (null != ri) {
|
||||
return ri.getUnits();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,4 +61,5 @@ service ApplicationClientProtocolService {
|
|||
rpc updateApplicationPriority (UpdateApplicationPriorityRequestProto) returns (UpdateApplicationPriorityResponseProto);
|
||||
rpc signalToContainer(SignalContainerRequestProto) returns (SignalContainerResponseProto);
|
||||
rpc updateApplicationTimeouts (UpdateApplicationTimeoutsRequestProto) returns (UpdateApplicationTimeoutsResponseProto);
|
||||
rpc getResourceTypeInfo(GetAllResourceTypeInfoRequestProto) returns (GetAllResourceTypeInfoResponseProto);
|
||||
}
|
||||
|
|
|
@ -64,6 +64,12 @@ message ResourceInformationProto {
|
|||
optional ResourceTypesProto type = 4;
|
||||
}
|
||||
|
||||
message ResourceTypeInfoProto {
|
||||
required string name = 1;
|
||||
optional string units = 2;
|
||||
optional ResourceTypesProto type = 3;
|
||||
}
|
||||
|
||||
message ResourceProto {
|
||||
optional int64 memory = 1;
|
||||
optional int32 virtual_cores = 2;
|
||||
|
|
|
@ -279,6 +279,13 @@ message UpdateApplicationTimeoutsResponseProto {
|
|||
repeated ApplicationUpdateTimeoutMapProto application_timeouts = 1;
|
||||
}
|
||||
|
||||
message GetAllResourceTypeInfoRequestProto {
|
||||
}
|
||||
|
||||
message GetAllResourceTypeInfoResponseProto {
|
||||
repeated ResourceTypeInfoProto resource_type_info = 1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
/////// client_NM_Protocol ///////////////////////////
|
||||
//////////////////////////////////////////////////////
|
||||
|
|
|
@ -61,6 +61,8 @@ import org.apache.hadoop.yarn.api.records.QueueInfo;
|
|||
import org.apache.hadoop.yarn.api.records.QueueUserACLInfo;
|
||||
import org.apache.hadoop.yarn.api.records.ReservationDefinition;
|
||||
import org.apache.hadoop.yarn.api.records.ReservationId;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
|
||||
import org.apache.hadoop.yarn.api.records.SignalContainerCommand;
|
||||
import org.apache.hadoop.yarn.api.records.Token;
|
||||
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||
|
@ -855,4 +857,18 @@ public abstract class YarnClient extends AbstractService {
|
|||
throw new UnsupportedOperationException("The sub-class extending "
|
||||
+ YarnClient.class.getName() + " is expected to implement this !");
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Get available resource types supported by RM.
|
||||
* </p>
|
||||
* @return list of supported resource types with detailed information
|
||||
* @throws YarnException if resource profiles are not enabled or the profile
|
||||
* cannot be found
|
||||
* @throws IOException in case of other others
|
||||
*/
|
||||
@Public
|
||||
@Unstable
|
||||
public abstract List<ResourceTypeInfo> getResourceTypeInfo()
|
||||
throws YarnException, IOException;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.hadoop.security.UserGroupInformation;
|
|||
import org.apache.hadoop.security.token.TokenIdentifier;
|
||||
import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -99,6 +100,8 @@ import org.apache.hadoop.yarn.api.records.NodeState;
|
|||
import org.apache.hadoop.yarn.api.records.Priority;
|
||||
import org.apache.hadoop.yarn.api.records.QueueInfo;
|
||||
import org.apache.hadoop.yarn.api.records.QueueUserACLInfo;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
|
||||
import org.apache.hadoop.yarn.api.records.SignalContainerCommand;
|
||||
import org.apache.hadoop.yarn.api.records.Token;
|
||||
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||
|
@ -938,4 +941,12 @@ public class YarnClientImpl extends YarnClient {
|
|||
throws YarnException, IOException {
|
||||
return rmClient.updateApplicationTimeouts(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceTypeInfo> getResourceTypeInfo()
|
||||
throws YarnException, IOException {
|
||||
GetAllResourceTypeInfoRequest request =
|
||||
GetAllResourceTypeInfoRequest.newInstance();
|
||||
return rmClient.getResourceTypeInfo(request).getResourceTypeInfo();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,6 +89,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.CancelDelegationTokenRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.CancelDelegationTokenResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FailApplicationAttemptRequestPBImpl;
|
||||
|
@ -147,6 +149,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SignalContainerRequest
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SignalContainerResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetAllResourceTypeInfoRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetAllResourceTypeInfoResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||
import org.apache.hadoop.yarn.ipc.RPCUtil;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos;
|
||||
|
@ -619,4 +623,18 @@ public class ApplicationClientProtocolPBClientImpl implements ApplicationClientP
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException {
|
||||
YarnServiceProtos.GetAllResourceTypeInfoRequestProto requestProto =
|
||||
((GetAllResourceTypeInfoRequestPBImpl) request).getProto();
|
||||
try {
|
||||
return new GetAllResourceTypeInfoResponsePBImpl(
|
||||
proxy.getResourceTypeInfo(null, requestProto));
|
||||
} catch (ServiceException e) {
|
||||
RPCUtil.unwrapAndThrowException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationPriorityRespo
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.CancelDelegationTokenRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.CancelDelegationTokenResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FailApplicationAttemptRequestPBImpl;
|
||||
|
@ -116,6 +117,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.UpdateApplicationTimeo
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.UpdateApplicationTimeoutsResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetAllResourceTypeInfoRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetAllResourceTypeInfoResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.FailApplicationAttemptRequestProto;
|
||||
|
@ -169,6 +172,8 @@ import org.apache.hadoop.yarn.proto.YarnServiceProtos.UpdateApplicationTimeoutsR
|
|||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.UpdateApplicationTimeoutsResponseProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.SubmitApplicationRequestProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.SubmitApplicationResponseProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllResourceTypeInfoRequestProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllResourceTypeInfoResponseProto;
|
||||
|
||||
import com.google.protobuf.RpcController;
|
||||
import com.google.protobuf.ServiceException;
|
||||
|
@ -631,4 +636,20 @@ public class ApplicationClientProtocolPBServiceImpl implements ApplicationClient
|
|||
throw new ServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponseProto getResourceTypeInfo(
|
||||
RpcController controller, GetAllResourceTypeInfoRequestProto proto)
|
||||
throws ServiceException {
|
||||
GetAllResourceTypeInfoRequestPBImpl req = new GetAllResourceTypeInfoRequestPBImpl(
|
||||
proto);
|
||||
try {
|
||||
GetAllResourceTypeInfoResponse resp = real.getResourceTypeInfo(req);
|
||||
return ((GetAllResourceTypeInfoResponsePBImpl) resp).getProto();
|
||||
} catch (YarnException ye) {
|
||||
throw new ServiceException(ye);
|
||||
} catch (IOException ie) {
|
||||
throw new ServiceException(ie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.api.protocolrecords.impl.pb;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllResourceTypeInfoRequestProto;
|
||||
|
||||
/**
|
||||
* Protobuf implementation class for GetAllResourceTypeInfoRequest.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
@InterfaceStability.Unstable
|
||||
public class GetAllResourceTypeInfoRequestPBImpl
|
||||
extends GetAllResourceTypeInfoRequest {
|
||||
|
||||
private GetAllResourceTypeInfoRequestProto proto =
|
||||
GetAllResourceTypeInfoRequestProto.getDefaultInstance();
|
||||
private GetAllResourceTypeInfoRequestProto.Builder builder = null;
|
||||
|
||||
private boolean viaProto = false;
|
||||
|
||||
public GetAllResourceTypeInfoRequestPBImpl() {
|
||||
builder = GetAllResourceTypeInfoRequestProto.newBuilder();
|
||||
}
|
||||
|
||||
public GetAllResourceTypeInfoRequestPBImpl(
|
||||
GetAllResourceTypeInfoRequestProto proto) {
|
||||
this.proto = proto;
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
public GetAllResourceTypeInfoRequestProto getProto() {
|
||||
proto = viaProto ? proto : builder.build();
|
||||
viaProto = true;
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getProto().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null)
|
||||
return false;
|
||||
if (other.getClass().isAssignableFrom(this.getClass())) {
|
||||
return this.getProto().equals(this.getClass().cast(other).getProto());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.api.protocolrecords.impl.pb;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ResourceTypeInfoPBImpl;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceTypeInfoProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllResourceTypeInfoResponseProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllResourceTypeInfoResponseProtoOrBuilder;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Protobuf implementation class for the GetAllResourceTypeInfoResponse.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
@InterfaceStability.Unstable
|
||||
public class GetAllResourceTypeInfoResponsePBImpl
|
||||
extends
|
||||
GetAllResourceTypeInfoResponse {
|
||||
|
||||
private GetAllResourceTypeInfoResponseProto proto = GetAllResourceTypeInfoResponseProto
|
||||
.getDefaultInstance();
|
||||
private GetAllResourceTypeInfoResponseProto.Builder builder = null;
|
||||
private boolean viaProto = false;
|
||||
|
||||
private List<ResourceTypeInfo> resourceTypeInfo;
|
||||
|
||||
public GetAllResourceTypeInfoResponsePBImpl() {
|
||||
builder = GetAllResourceTypeInfoResponseProto.newBuilder();
|
||||
}
|
||||
|
||||
public GetAllResourceTypeInfoResponsePBImpl(
|
||||
GetAllResourceTypeInfoResponseProto proto) {
|
||||
this.proto = proto;
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
public GetAllResourceTypeInfoResponseProto getProto() {
|
||||
mergeLocalToProto();
|
||||
proto = viaProto ? proto : builder.build();
|
||||
viaProto = true;
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getProto().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResourceTypeInfo(List<ResourceTypeInfo> resourceTypes) {
|
||||
if (resourceTypeInfo == null) {
|
||||
builder.clearResourceTypeInfo();
|
||||
}
|
||||
this.resourceTypeInfo = resourceTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceTypeInfo> getResourceTypeInfo() {
|
||||
initResourceTypeInfosList();
|
||||
return this.resourceTypeInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
if (other.getClass().isAssignableFrom(this.getClass())) {
|
||||
return this.getProto().equals(this.getClass().cast(other).getProto());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return TextFormat.shortDebugString(getProto());
|
||||
}
|
||||
|
||||
private void mergeLocalToBuilder() {
|
||||
if (this.resourceTypeInfo != null) {
|
||||
addResourceTypeInfosToProto();
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeLocalToProto() {
|
||||
if (viaProto) {
|
||||
maybeInitBuilder();
|
||||
}
|
||||
mergeLocalToBuilder();
|
||||
proto = builder.build();
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
private void maybeInitBuilder() {
|
||||
if (viaProto || builder == null) {
|
||||
builder = GetAllResourceTypeInfoResponseProto.newBuilder(proto);
|
||||
}
|
||||
viaProto = false;
|
||||
}
|
||||
|
||||
// Once this is called. containerList will never be null - until a getProto
|
||||
// is called.
|
||||
private void initResourceTypeInfosList() {
|
||||
if (this.resourceTypeInfo != null) {
|
||||
return;
|
||||
}
|
||||
GetAllResourceTypeInfoResponseProtoOrBuilder p = viaProto ? proto : builder;
|
||||
List<ResourceTypeInfoProto> list = p.getResourceTypeInfoList();
|
||||
resourceTypeInfo = new ArrayList<ResourceTypeInfo>();
|
||||
|
||||
for (ResourceTypeInfoProto a : list) {
|
||||
resourceTypeInfo.add(convertFromProtoFormat(a));
|
||||
}
|
||||
}
|
||||
|
||||
private void addResourceTypeInfosToProto() {
|
||||
maybeInitBuilder();
|
||||
builder.clearResourceTypeInfo();
|
||||
if (resourceTypeInfo == null) {
|
||||
return;
|
||||
}
|
||||
Iterable<ResourceTypeInfoProto> iterable = new Iterable<ResourceTypeInfoProto>() {
|
||||
@Override
|
||||
public Iterator<ResourceTypeInfoProto> iterator() {
|
||||
return new Iterator<ResourceTypeInfoProto>() {
|
||||
|
||||
Iterator<ResourceTypeInfo> iter = resourceTypeInfo.iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iter.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceTypeInfoProto next() {
|
||||
return convertToProtoFormat(iter.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
builder.addAllResourceTypeInfo(iterable);
|
||||
}
|
||||
|
||||
private ResourceTypeInfoPBImpl convertFromProtoFormat(
|
||||
ResourceTypeInfoProto p) {
|
||||
return new ResourceTypeInfoPBImpl(p);
|
||||
}
|
||||
|
||||
private ResourceTypeInfoProto convertToProtoFormat(ResourceTypeInfo t) {
|
||||
return ((ResourceTypeInfoPBImpl) t).getProto();
|
||||
}
|
||||
}
|
|
@ -63,6 +63,7 @@ public class ResourcePBImpl extends BaseResource {
|
|||
|
||||
public ResourcePBImpl() {
|
||||
builder = ResourceProto.newBuilder();
|
||||
initResources();
|
||||
}
|
||||
|
||||
public ResourcePBImpl(ResourceProto proto) {
|
||||
|
@ -94,7 +95,6 @@ public class ResourcePBImpl extends BaseResource {
|
|||
@Override
|
||||
public long getMemorySize() {
|
||||
// memory should always be present
|
||||
initResources();
|
||||
ResourceInformation ri = resources[MandatoryResources.MEMORY.getId()];
|
||||
|
||||
if (ri.getUnits().isEmpty()) {
|
||||
|
@ -119,7 +119,6 @@ public class ResourcePBImpl extends BaseResource {
|
|||
@Override
|
||||
public int getVirtualCores() {
|
||||
// vcores should always be present
|
||||
initResources();
|
||||
return (int) resources[MandatoryResources.VCORES.getId()].getValue();
|
||||
}
|
||||
|
||||
|
@ -140,7 +139,11 @@ public class ResourcePBImpl extends BaseResource {
|
|||
ResourceTypes type =
|
||||
entry.hasType() ? ProtoUtils.convertFromProtoFormat(entry.getType()) :
|
||||
ResourceTypes.COUNTABLE;
|
||||
String units = entry.hasUnits() ? entry.getUnits() : "";
|
||||
|
||||
// When unit not specified in proto, use the default unit.
|
||||
String units =
|
||||
entry.hasUnits() ? entry.getUnits() : ResourceUtils.getDefaultUnit(
|
||||
entry.getKey());
|
||||
long value = entry.hasValue() ? entry.getValue() : 0L;
|
||||
ResourceInformation ri = ResourceInformation
|
||||
.newInstance(entry.getKey(), units, value, type, 0L, Long.MAX_VALUE);
|
||||
|
@ -185,21 +188,18 @@ public class ResourcePBImpl extends BaseResource {
|
|||
|
||||
@Override
|
||||
public ResourceInformation[] getResources() {
|
||||
initResources();
|
||||
return super.getResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceInformation getResourceInformation(String resource)
|
||||
throws ResourceNotFoundException {
|
||||
initResources();
|
||||
return super.getResourceInformation(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getResourceValue(String resource)
|
||||
throws ResourceNotFoundException {
|
||||
initResources();
|
||||
return super.getResourceValue(resource);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.api.records.impl.pb;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
||||
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceTypeInfoProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceTypesProto;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* {@code ResourceTypeInfoPBImpl} which implements the
|
||||
* {@link ResourceTypeInfo} class which represents different resource types
|
||||
* supported in YARN.
|
||||
*/
|
||||
@Private
|
||||
@Unstable
|
||||
public class ResourceTypeInfoPBImpl extends ResourceTypeInfo {
|
||||
|
||||
ResourceTypeInfoProto proto = ResourceTypeInfoProto.getDefaultInstance();
|
||||
ResourceTypeInfoProto.Builder builder = null;
|
||||
boolean viaProto = false;
|
||||
|
||||
private String name = null;
|
||||
private String defaultUnit = null;
|
||||
private ResourceTypes resourceTypes = null;
|
||||
|
||||
public ResourceTypeInfoPBImpl() {
|
||||
builder = ResourceTypeInfoProto.newBuilder();
|
||||
}
|
||||
|
||||
public ResourceTypeInfoPBImpl(ResourceTypeInfoProto proto) {
|
||||
this.proto = proto;
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
public ResourceTypeInfoProto getProto() {
|
||||
mergeLocalToProto();
|
||||
return proto;
|
||||
}
|
||||
|
||||
private void mergeLocalToProto() {
|
||||
if (viaProto) {
|
||||
maybeInitBuilder();
|
||||
}
|
||||
mergeLocalToBuilder();
|
||||
proto = builder.build();
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
private void mergeLocalToBuilder() {
|
||||
if (this.name != null) {
|
||||
builder.setName(this.name);
|
||||
}
|
||||
if (this.defaultUnit != null) {
|
||||
builder.setUnits(this.defaultUnit);
|
||||
}
|
||||
if (this.resourceTypes != null) {
|
||||
builder.setType(convertToProtoFormat(this.resourceTypes));
|
||||
}
|
||||
}
|
||||
|
||||
private void maybeInitBuilder() {
|
||||
if (viaProto || builder == null) {
|
||||
builder = YarnProtos.ResourceTypeInfoProto.newBuilder(proto);
|
||||
}
|
||||
viaProto = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (this.name != null) {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
YarnProtos.ResourceTypeInfoProtoOrBuilder p = viaProto ? proto : builder;
|
||||
return p.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String rName) {
|
||||
maybeInitBuilder();
|
||||
if (rName == null) {
|
||||
builder.clearName();
|
||||
}
|
||||
this.name = rName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultUnit() {
|
||||
if (this.defaultUnit != null) {
|
||||
return this.defaultUnit;
|
||||
}
|
||||
|
||||
YarnProtos.ResourceTypeInfoProtoOrBuilder p = viaProto ? proto : builder;
|
||||
return p.getUnits();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultUnit(String rUnits) {
|
||||
maybeInitBuilder();
|
||||
if (rUnits == null) {
|
||||
builder.clearUnits();
|
||||
}
|
||||
this.defaultUnit = rUnits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceTypes getResourceType() {
|
||||
if (this.resourceTypes != null) {
|
||||
return this.resourceTypes;
|
||||
}
|
||||
|
||||
YarnProtos.ResourceTypeInfoProtoOrBuilder p = viaProto ? proto : builder;
|
||||
return convertFromProtoFormat(p.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResourceType(ResourceTypes type) {
|
||||
maybeInitBuilder();
|
||||
if (type == null) {
|
||||
builder.clearType();
|
||||
}
|
||||
this.resourceTypes = type;
|
||||
}
|
||||
|
||||
public static ResourceTypesProto convertToProtoFormat(ResourceTypes e) {
|
||||
return ResourceTypesProto.valueOf(e.name());
|
||||
}
|
||||
|
||||
public static ResourceTypes convertFromProtoFormat(ResourceTypesProto e) {
|
||||
return ResourceTypes.valueOf(e.name());
|
||||
}
|
||||
}
|
|
@ -29,6 +29,8 @@ import org.apache.hadoop.security.proto.SecurityProtos.TokenProto;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.CommitResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.ContainerUpdateRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.ContainerUpdateResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.ReInitializeContainerRequest;
|
||||
|
@ -42,6 +44,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.CancelDelegationTokenR
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.CancelDelegationTokenResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetAllResourceTypeInfoRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetAllResourceTypeInfoResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetApplicationAttemptReportRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetApplicationAttemptReportResponsePBImpl;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetApplicationAttemptsRequestPBImpl;
|
||||
|
@ -144,6 +148,7 @@ import org.apache.hadoop.yarn.api.records.ResourceInformation;
|
|||
import org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceOption;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceUtilization;
|
||||
import org.apache.hadoop.yarn.api.records.SerializedException;
|
||||
import org.apache.hadoop.yarn.api.records.StrictPreemptionContract;
|
||||
|
@ -182,12 +187,14 @@ import org.apache.hadoop.yarn.api.records.impl.pb.ResourceBlacklistRequestPBImpl
|
|||
import org.apache.hadoop.yarn.api.records.impl.pb.ResourceOptionPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ResourceRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ResourceTypeInfoPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.SerializedExceptionPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.StrictPreemptionContractPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.TokenPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.URLPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.UpdateContainerRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.YarnClusterMetricsPBImpl;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ApplicationAttemptIdProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ApplicationAttemptReportProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ApplicationIdProto;
|
||||
|
@ -1161,4 +1168,22 @@ public class TestPBImplRecords extends BasePBImplRecordsTest {
|
|||
validatePBImplRecord(ExecutionTypeRequestPBImpl.class,
|
||||
ExecutionTypeRequestProto.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceTypesInfoPBImpl() throws Exception {
|
||||
validatePBImplRecord(ResourceTypeInfoPBImpl.class,
|
||||
YarnProtos.ResourceTypeInfoProto.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllResourceTypesInfoRequestPBImpl() throws Exception {
|
||||
validatePBImplRecord(GetAllResourceTypeInfoRequestPBImpl.class,
|
||||
YarnServiceProtos.GetAllResourceTypeInfoRequestProto.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllResourceTypesInfoResponsePBImpl() throws Exception {
|
||||
validatePBImplRecord(GetAllResourceTypeInfoResponsePBImpl.class,
|
||||
YarnServiceProtos.GetAllResourceTypeInfoResponseProto.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.api;
|
||||
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceInformation;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test class to handle various proto related tests for resources.
|
||||
*/
|
||||
public class TestResourcePBImpl {
|
||||
@Test
|
||||
public void testEmptyResourcePBInit() throws Exception {
|
||||
Resource res = new ResourcePBImpl();
|
||||
// Assert to check it sets resource value and unit to default.
|
||||
Assert.assertEquals(0, res.getMemorySize());
|
||||
Assert.assertEquals(ResourceInformation.MEMORY_MB.getUnits(),
|
||||
res.getResourceInformation(ResourceInformation.MEMORY_MB.getName())
|
||||
.getUnits());
|
||||
Assert.assertEquals(ResourceInformation.VCORES.getUnits(),
|
||||
res.getResourceInformation(ResourceInformation.VCORES.getName())
|
||||
.getUnits());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourcePBInitFromOldPB() throws Exception {
|
||||
YarnProtos.ResourceProto proto =
|
||||
YarnProtos.ResourceProto.newBuilder().setMemory(1024).setVirtualCores(3)
|
||||
.build();
|
||||
// Assert to check it sets resource value and unit to default.
|
||||
Resource res = new ResourcePBImpl(proto);
|
||||
Assert.assertEquals(1024, res.getMemorySize());
|
||||
Assert.assertEquals(3, res.getVirtualCores());
|
||||
Assert.assertEquals(ResourceInformation.MEMORY_MB.getUnits(),
|
||||
res.getResourceInformation(ResourceInformation.MEMORY_MB.getName())
|
||||
.getUnits());
|
||||
Assert.assertEquals(ResourceInformation.VCORES.getUnits(),
|
||||
res.getResourceInformation(ResourceInformation.VCORES.getName())
|
||||
.getUnits());
|
||||
}
|
||||
}
|
|
@ -41,6 +41,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -852,4 +854,10 @@ public class MockResourceManagerFacade implements ApplicationClientProtocol,
|
|||
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,6 +112,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationPriorityReque
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationPriorityResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAccessType;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptReport;
|
||||
|
@ -1799,4 +1801,13 @@ public class ClientRMService extends AbstractService implements
|
|||
this.displayPerUserApps = displayPerUserApps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException {
|
||||
GetAllResourceTypeInfoResponse response =
|
||||
GetAllResourceTypeInfoResponse.newInstance();
|
||||
response.setResourceTypeInfo(
|
||||
resourceProfilesManager.getAllResourceTypeInfo());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ import org.apache.hadoop.security.UserGroupInformation;
|
|||
import org.apache.hadoop.yarn.MockApps;
|
||||
import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.ApplicationsRequestScope;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -116,6 +118,7 @@ import org.apache.hadoop.yarn.api.records.ReservationId;
|
|||
import org.apache.hadoop.yarn.api.records.ReservationRequest;
|
||||
import org.apache.hadoop.yarn.api.records.ReservationRequests;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceInformation;
|
||||
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
||||
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||
|
@ -2143,4 +2146,46 @@ public class TestClientRMService {
|
|||
rmService.getApplications(request).getApplicationList().size());
|
||||
rmService.setDisplayPerUserApps(false);
|
||||
}
|
||||
|
||||
public void testGetResourceTypesInfoWhenResourceProfileDisabled()
|
||||
throws Exception {
|
||||
YarnConfiguration conf = new YarnConfiguration();
|
||||
MockRM rm = new MockRM(conf) {
|
||||
protected ClientRMService createClientRMService() {
|
||||
return new ClientRMService(this.rmContext, scheduler,
|
||||
this.rmAppManager, this.applicationACLsManager, this.queueACLsManager,
|
||||
this.getRMContext().getRMDelegationTokenSecretManager());
|
||||
}
|
||||
};
|
||||
rm.start();
|
||||
|
||||
YarnRPC rpc = YarnRPC.create(conf);
|
||||
InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress();
|
||||
LOG.info("Connecting to ResourceManager at " + rmAddress);
|
||||
ApplicationClientProtocol client =
|
||||
(ApplicationClientProtocol) rpc
|
||||
.getProxy(ApplicationClientProtocol.class, rmAddress, conf);
|
||||
|
||||
// Make call
|
||||
GetAllResourceTypeInfoRequest request =
|
||||
GetAllResourceTypeInfoRequest.newInstance();
|
||||
GetAllResourceTypeInfoResponse response = client.getResourceTypeInfo(request);
|
||||
|
||||
Assert.assertEquals(2, response.getResourceTypeInfo().size());
|
||||
|
||||
// Check memory
|
||||
Assert.assertEquals(ResourceInformation.MEMORY_MB.getName(),
|
||||
response.getResourceTypeInfo().get(0).getName());
|
||||
Assert.assertEquals(ResourceInformation.MEMORY_MB.getUnits(),
|
||||
response.getResourceTypeInfo().get(0).getDefaultUnit());
|
||||
|
||||
// Check vcores
|
||||
Assert.assertEquals(ResourceInformation.VCORES.getName(),
|
||||
response.getResourceTypeInfo().get(1).getName());
|
||||
Assert.assertEquals(ResourceInformation.VCORES.getUnits(),
|
||||
response.getResourceTypeInfo().get(1).getDefaultUnit());
|
||||
|
||||
rm.stop();
|
||||
rpc.stopProxy(client, conf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1603,7 +1603,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
public void verifyAppInfo(JSONObject info, RMApp app, boolean hasResourceReqs)
|
||||
throws JSONException, Exception {
|
||||
|
||||
int expectedNumberOfElements = 36 + (hasResourceReqs ? 2 : 0);
|
||||
int expectedNumberOfElements = 38 + (hasResourceReqs ? 2 : 0);
|
||||
String appNodeLabelExpression = null;
|
||||
String amNodeLabelExpression = null;
|
||||
if (app.getApplicationSubmissionContext()
|
||||
|
|
|
@ -27,6 +27,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -303,6 +305,12 @@ public class DefaultClientRequestInterceptor
|
|||
return clientRMProxy.updateApplicationTimeouts(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException {
|
||||
return clientRMProxy.getResourceTypeInfo(request);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setRMClient(ApplicationClientProtocol clientRM) {
|
||||
this.clientRMProxy = clientRM;
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -709,4 +711,9 @@ public class FederationClientInterceptor
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -403,6 +405,13 @@ public class RouterClientRMService extends AbstractService
|
|||
return pipeline.getRootInterceptor().updateApplicationTimeouts(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException {
|
||||
RequestInterceptorChainWrapper pipeline = getInterceptorChain();
|
||||
return pipeline.getRootInterceptor().getResourceTypeInfo(request);
|
||||
}
|
||||
|
||||
private RequestInterceptorChainWrapper getInterceptorChain()
|
||||
throws IOException {
|
||||
String user = UserGroupInformation.getCurrentUser().getUserName();
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenRequest;
|
|||
import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest;
|
||||
|
@ -264,4 +266,10 @@ public class PassThroughClientRequestInterceptor
|
|||
throws YarnException, IOException {
|
||||
return getNextInterceptor().updateApplicationTimeouts(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAllResourceTypeInfoResponse getResourceTypeInfo(
|
||||
GetAllResourceTypeInfoRequest request) throws YarnException, IOException {
|
||||
return getNextInterceptor().getResourceTypeInfo(request);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue