diff --git hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java index f901ed8..0d78473 100644 --- hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java +++ hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java @@ -46,8 +46,8 @@ import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.Container; -import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease; +import org.apache.hadoop.yarn.api.records.DecreasedContainer; +import org.apache.hadoop.yarn.api.records.IncreasedContainer; import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.NMToken; import org.apache.hadoop.yarn.api.records.NodeReport; @@ -254,8 +254,8 @@ public AllocateResponse allocate(AllocateRequest request) Resources.none(), null, 1, null, Collections.emptyList(), yarnToken, - Collections.emptyList(), - Collections.emptyList()); + Collections.emptyList(), + Collections.emptyList()); } } } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateRequest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateRequest.java index 2458d9b..6c36868 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateRequest.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateRequest.java @@ -26,7 +26,7 @@ import org.apache.hadoop.yarn.api.records.Container; import org.apache.hadoop.yarn.api.records.ContainerId; import org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest; +import org.apache.hadoop.yarn.api.records.ContainerResourceChangeRequest; import org.apache.hadoop.yarn.api.records.ResourceRequest; import org.apache.hadoop.yarn.util.Records; @@ -61,16 +61,18 @@ public static AllocateRequest newInstance(int responseID, float appProgress, List containersToBeReleased, ResourceBlacklistRequest resourceBlacklistRequest) { return newInstance(responseID, appProgress, resourceAsk, - containersToBeReleased, resourceBlacklistRequest, null); + containersToBeReleased, resourceBlacklistRequest, null, null); } @Public @Stable - public static AllocateRequest newInstance(int responseID, float appProgress, - List resourceAsk, - List containersToBeReleased, - ResourceBlacklistRequest resourceBlacklistRequest, - List increaseRequests) { + public static AllocateRequest newInstance(int responseID, + float appProgress, + List resourceAsk, + List containersToBeReleased, + ResourceBlacklistRequest resourceBlacklistRequest, + List increaseRequests, + List decreaseRequests) { AllocateRequest allocateRequest = Records.newRecord(AllocateRequest.class); allocateRequest.setResponseId(responseID); allocateRequest.setProgress(appProgress); @@ -78,6 +80,7 @@ public static AllocateRequest newInstance(int responseID, float appProgress, allocateRequest.setReleaseList(containersToBeReleased); allocateRequest.setResourceBlacklistRequest(resourceBlacklistRequest); allocateRequest.setIncreaseRequests(increaseRequests); + allocateRequest.setDecreaseRequests(decreaseRequests); return allocateRequest; } @@ -184,20 +187,38 @@ public abstract void setResourceBlacklistRequest( ResourceBlacklistRequest resourceBlacklistRequest); /** - * Get the ContainerResourceIncreaseRequest being sent by the - * ApplicationMaster + * Get the list of container resource increase requests being sent by the + * ApplicationMaster. */ @Public @Stable - public abstract List getIncreaseRequests(); - + public abstract List getIncreaseRequests(); + /** - * Set the ContainerResourceIncreaseRequest to inform the - * ResourceManager about some container's resources need to be - * increased + * Set the list of container resource increase requests to inform the + * ResourceManager about the containers whose resources need + * to be increased. */ @Public @Stable public abstract void setIncreaseRequests( - List increaseRequests); + List increaseRequests); + + /** + * Get the list of container resource decrease requests being sent by the + * ApplicationMaster. + */ + @Public + @Stable + public abstract List getDecreaseRequests(); + + /** + * Set the list of container resource decrease requests to inform the + * ResourceManager about the containers whose resources need + * to be decreased. + */ + @Public + @Stable + public abstract void setDecreaseRequests( + List decreaseRequests); } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateResponse.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateResponse.java index c4fdb79..4b33243 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateResponse.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/AllocateResponse.java @@ -28,8 +28,8 @@ import org.apache.hadoop.yarn.api.ApplicationMasterProtocol; import org.apache.hadoop.yarn.api.records.AMCommand; import org.apache.hadoop.yarn.api.records.Container; -import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease; +import org.apache.hadoop.yarn.api.records.DecreasedContainer; +import org.apache.hadoop.yarn.api.records.IncreasedContainer; import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.NMToken; import org.apache.hadoop.yarn.api.records.NodeReport; @@ -94,8 +94,8 @@ public static AllocateResponse newInstance(int responseId, List allocatedContainers, List updatedNodes, Resource availResources, AMCommand command, int numClusterNodes, PreemptionMessage preempt, List nmTokens, - List increasedContainers, - List decreasedContainers) { + List increasedContainers, + List decreasedContainers) { AllocateResponse response = newInstance(responseId, completedContainers, allocatedContainers, updatedNodes, availResources, command, numClusterNodes, preempt, nmTokens); @@ -111,8 +111,8 @@ public static AllocateResponse newInstance(int responseId, List allocatedContainers, List updatedNodes, Resource availResources, AMCommand command, int numClusterNodes, PreemptionMessage preempt, List nmTokens, Token amRMToken, - List increasedContainers, - List decreasedContainers) { + List increasedContainers, + List decreasedContainers) { AllocateResponse response = newInstance(responseId, completedContainers, allocatedContainers, updatedNodes, availResources, command, numClusterNodes, preempt, @@ -267,7 +267,7 @@ public static AllocateResponse newInstance(int responseId, */ @Public @Stable - public abstract List getIncreasedContainers(); + public abstract List getIncreasedContainers(); /** * Set the list of newly increased containers by ResourceManager @@ -275,14 +275,14 @@ public static AllocateResponse newInstance(int responseId, @Private @Unstable public abstract void setIncreasedContainers( - List increasedContainers); + List increasedContainers); /** * Get the list of newly decreased containers by NodeManager */ @Public @Stable - public abstract List getDecreasedContainers(); + public abstract List getDecreasedContainers(); /** * Set the list of newly decreased containers by NodeManager @@ -290,7 +290,7 @@ public abstract void setIncreasedContainers( @Private @Unstable public abstract void setDecreasedContainers( - List decreasedContainers); + List decreasedContainers); /** * The AMRMToken that belong to this attempt diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceChangeRequest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceChangeRequest.java new file mode 100644 index 0000000..ed5e589 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceChangeRequest.java @@ -0,0 +1,80 @@ +/** + * 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.Public; +import org.apache.hadoop.yarn.util.Records; + +/** + * Used by Application Master, send a container resource increase request to + * Resource Manager + */ +@Public +public abstract class ContainerResourceChangeRequest { + @Public + public static ContainerResourceChangeRequest newInstance( + ContainerId existingContainerId, Resource targetCapability) { + ContainerResourceChangeRequest context = Records + .newRecord(ContainerResourceChangeRequest.class); + context.setContainerId(existingContainerId); + context.setCapability(targetCapability); + return context; + } + + @Public + public abstract ContainerId getContainerId(); + + @Public + public abstract void setContainerId(ContainerId containerId); + + @Public + public abstract Resource getCapability(); + + @Public + public abstract void setCapability(Resource capability); + + @Override + public int hashCode() { + return getCapability().hashCode() + getContainerId().hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other instanceof ContainerResourceChangeRequest) { + ContainerResourceChangeRequest ctx = + (ContainerResourceChangeRequest) other; + + if (getContainerId() == null && ctx.getContainerId() != null) { + return false; + } else if (!getContainerId().equals(ctx.getContainerId())) { + return false; + } + + if (getCapability() == null && ctx.getCapability() != null) { + return false; + } else if (!getCapability().equals(ctx.getCapability())) { + return false; + } + + return true; + } else { + return false; + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceDecrease.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceDecrease.java deleted file mode 100644 index d766d92..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceDecrease.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.Public; -import org.apache.hadoop.yarn.util.Records; - -/** - * Used by Application Master to ask Node Manager reduce size of a specified - * container - */ -public abstract class ContainerResourceDecrease { - @Public - public static ContainerResourceDecrease newInstance( - ContainerId existingContainerId, Resource targetCapability) { - ContainerResourceDecrease context = Records - .newRecord(ContainerResourceDecrease.class); - context.setContainerId(existingContainerId); - context.setCapability(targetCapability); - return context; - } - - @Public - public abstract ContainerId getContainerId(); - - @Public - public abstract void setContainerId(ContainerId containerId); - - @Public - public abstract Resource getCapability(); - - @Public - public abstract void setCapability(Resource capability); - - @Override - public int hashCode() { - return getCapability().hashCode() + getContainerId().hashCode(); - } - - @Override - public boolean equals(Object other) { - if (other instanceof ContainerResourceDecrease) { - ContainerResourceDecrease ctx = (ContainerResourceDecrease)other; - - if (getContainerId() == null && ctx.getContainerId() != null) { - return false; - } else if (!getContainerId().equals(ctx.getContainerId())) { - return false; - } - - if (getCapability() == null && ctx.getCapability() != null) { - return false; - } else if (!getCapability().equals(ctx.getCapability())) { - return false; - } - - return true; - } else { - return false; - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceIncrease.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceIncrease.java deleted file mode 100644 index f4c1560..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceIncrease.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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.Public; -import org.apache.hadoop.yarn.util.Records; - -/** - * Represent a new increased container accepted by Resource Manager - */ -public abstract class ContainerResourceIncrease { - @Public - public static ContainerResourceIncrease newInstance( - ContainerId existingContainerId, Resource targetCapability, Token token) { - ContainerResourceIncrease context = Records - .newRecord(ContainerResourceIncrease.class); - context.setContainerId(existingContainerId); - context.setCapability(targetCapability); - context.setContainerToken(token); - return context; - } - - @Public - public abstract ContainerId getContainerId(); - - @Public - public abstract void setContainerId(ContainerId containerId); - - @Public - public abstract Resource getCapability(); - - @Public - public abstract void setCapability(Resource capability); - - @Public - public abstract Token getContainerToken(); - - @Public - public abstract void setContainerToken(Token token); - - @Override - public int hashCode() { - return getCapability().hashCode() + getContainerId().hashCode(); - } - - @Override - public boolean equals(Object other) { - if (other instanceof ContainerResourceIncrease) { - ContainerResourceIncrease ctx = (ContainerResourceIncrease)other; - - if (getContainerId() == null && ctx.getContainerId() != null) { - return false; - } else if (!getContainerId().equals(ctx.getContainerId())) { - return false; - } - - if (getCapability() == null && ctx.getCapability() != null) { - return false; - } else if (!getCapability().equals(ctx.getCapability())) { - return false; - } - - return true; - } else { - return false; - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceIncreaseRequest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceIncreaseRequest.java deleted file mode 100644 index 9e3b640..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ContainerResourceIncreaseRequest.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.Public; -import org.apache.hadoop.yarn.util.Records; - -/** - * Used by Application Master, send a container resource increase request to - * Resource Manager - */ -@Public -public abstract class ContainerResourceIncreaseRequest { - @Public - public static ContainerResourceIncreaseRequest newInstance( - ContainerId existingContainerId, Resource targetCapability) { - ContainerResourceIncreaseRequest context = Records - .newRecord(ContainerResourceIncreaseRequest.class); - context.setContainerId(existingContainerId); - context.setCapability(targetCapability); - return context; - } - - @Public - public abstract ContainerId getContainerId(); - - @Public - public abstract void setContainerId(ContainerId containerId); - - @Public - public abstract Resource getCapability(); - - @Public - public abstract void setCapability(Resource capability); - - @Override - public int hashCode() { - return getCapability().hashCode() + getContainerId().hashCode(); - } - - @Override - public boolean equals(Object other) { - if (other instanceof ContainerResourceIncreaseRequest) { - ContainerResourceIncreaseRequest ctx = - (ContainerResourceIncreaseRequest) other; - - if (getContainerId() == null && ctx.getContainerId() != null) { - return false; - } else if (!getContainerId().equals(ctx.getContainerId())) { - return false; - } - - if (getCapability() == null && ctx.getCapability() != null) { - return false; - } else if (!getCapability().equals(ctx.getCapability())) { - return false; - } - - return true; - } else { - return false; - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/DecreasedContainer.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/DecreasedContainer.java new file mode 100644 index 0000000..7193fe9 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/DecreasedContainer.java @@ -0,0 +1,78 @@ +/** + * 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.Public; +import org.apache.hadoop.yarn.util.Records; + +/** + * Used by Application Master to ask Node Manager reduce size of a specified + * container + */ +public abstract class DecreasedContainer { + @Public + public static DecreasedContainer newInstance( + ContainerId existingContainerId, Resource targetCapability) { + DecreasedContainer context = Records + .newRecord(DecreasedContainer.class); + context.setContainerId(existingContainerId); + context.setCapability(targetCapability); + return context; + } + + @Public + public abstract ContainerId getContainerId(); + + @Public + public abstract void setContainerId(ContainerId containerId); + + @Public + public abstract Resource getCapability(); + + @Public + public abstract void setCapability(Resource capability); + + @Override + public int hashCode() { + return getCapability().hashCode() + getContainerId().hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other instanceof DecreasedContainer) { + DecreasedContainer ctx = (DecreasedContainer)other; + + if (getContainerId() == null && ctx.getContainerId() != null) { + return false; + } else if (!getContainerId().equals(ctx.getContainerId())) { + return false; + } + + if (getCapability() == null && ctx.getCapability() != null) { + return false; + } else if (!getCapability().equals(ctx.getCapability())) { + return false; + } + + return true; + } else { + return false; + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/IncreasedContainer.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/IncreasedContainer.java new file mode 100644 index 0000000..f5f1215 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/IncreasedContainer.java @@ -0,0 +1,84 @@ +/** + * 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.Public; +import org.apache.hadoop.yarn.util.Records; + +/** + * Represent a new increased container accepted by Resource Manager + */ +public abstract class IncreasedContainer { + @Public + public static IncreasedContainer newInstance( + ContainerId existingContainerId, Resource targetCapability, Token token) { + IncreasedContainer context = Records + .newRecord(IncreasedContainer.class); + context.setContainerId(existingContainerId); + context.setCapability(targetCapability); + context.setContainerToken(token); + return context; + } + + @Public + public abstract ContainerId getContainerId(); + + @Public + public abstract void setContainerId(ContainerId containerId); + + @Public + public abstract Resource getCapability(); + + @Public + public abstract void setCapability(Resource capability); + + @Public + public abstract Token getContainerToken(); + + @Public + public abstract void setContainerToken(Token token); + + @Override + public int hashCode() { + return getCapability().hashCode() + getContainerId().hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other instanceof IncreasedContainer) { + IncreasedContainer ctx = (IncreasedContainer)other; + + if (getContainerId() == null && ctx.getContainerId() != null) { + return false; + } else if (!getContainerId().equals(ctx.getContainerId())) { + return false; + } + + if (getCapability() == null && ctx.getCapability() != null) { + return false; + } else if (!getCapability().equals(ctx.getCapability())) { + return false; + } + + return true; + } else { + return false; + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto index f801409..131e4b9 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto @@ -456,6 +456,7 @@ message ContainerStatusProto { optional ContainerStateProto state = 2; optional string diagnostics = 3 [default = "N/A"]; optional int32 exit_status = 4 [default = -1000]; + optional ResourceProto capability = 5; } enum ContainerExitStatusProto { @@ -465,18 +466,18 @@ enum ContainerExitStatusProto { DISKS_FAILED = -101; } -message ContainerResourceIncreaseRequestProto { +message ContainerResourceChangeRequestProto { optional ContainerIdProto container_id = 1; optional ResourceProto capability = 2; } -message ContainerResourceIncreaseProto { +message IncreasedContainerProto { optional ContainerIdProto container_id = 1; optional ResourceProto capability = 2; optional hadoop.common.TokenProto container_token = 3; } -message ContainerResourceDecreaseProto { +message DecreasedContainerProto { optional ContainerIdProto container_id = 1; optional ResourceProto capability = 2; } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto index 098785a..f0fb430 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_service_protos.proto @@ -66,7 +66,8 @@ message AllocateRequestProto { optional ResourceBlacklistRequestProto blacklist_request = 3; optional int32 response_id = 4; optional float progress = 5; - repeated ContainerResourceIncreaseRequestProto increase_request = 6; + repeated ContainerResourceChangeRequestProto increase_request = 6; + repeated ContainerResourceChangeRequestProto decrease_request = 7; } message NMTokenProto { @@ -84,8 +85,8 @@ message AllocateResponseProto { optional int32 num_cluster_nodes = 7; optional PreemptionMessageProto preempt = 8; repeated NMTokenProto nm_tokens = 9; - repeated ContainerResourceIncreaseProto increased_containers = 10; - repeated ContainerResourceDecreaseProto decreased_containers = 11; + repeated IncreasedContainerProto increased_containers = 10; + repeated DecreasedContainerProto decreased_containers = 11; optional hadoop.common.TokenProto am_rm_token = 12; } @@ -278,6 +279,15 @@ message GetContainerStatusesResponseProto { repeated ContainerExceptionMapProto failed_requests = 2; } +message IncreaseContainersResourceRequestProto { + repeated hadoop.common.TokenProto increase_containers = 1; +} + +message IncreaseContainersResourceResponseProto { + repeated ContainerIdProto succeeded_requests = 1; + repeated ContainerExceptionMapProto failed_requests = 2; +} + ////////////////////////////////////////////////////// /////// Application_History_Protocol ///////////////// ////////////////////////////////////////////////////// diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateRequestPBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateRequestPBImpl.java index dc11165..c8a45c7 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateRequestPBImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateRequestPBImpl.java @@ -27,15 +27,15 @@ import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest; +import org.apache.hadoop.yarn.api.records.ContainerResourceChangeRequest; import org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest; import org.apache.hadoop.yarn.api.records.ResourceRequest; import org.apache.hadoop.yarn.api.records.impl.pb.ContainerIdPBImpl; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreaseRequestPBImpl; +import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceChangeRequestPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.ResourceBlacklistRequestPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.ResourceRequestPBImpl; import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProto; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceChangeRequestProto; import org.apache.hadoop.yarn.proto.YarnProtos.ResourceBlacklistRequestProto; import org.apache.hadoop.yarn.proto.YarnProtos.ResourceRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.AllocateRequestProto; @@ -52,7 +52,8 @@ private List ask = null; private List release = null; - private List increaseRequests = null; + private List increaseRequests = null; + private List decreaseRequests = null; private ResourceBlacklistRequest blacklistRequest = null; public AllocateRequestPBImpl() { @@ -101,6 +102,9 @@ private void mergeLocalToBuilder() { if (this.increaseRequests != null) { addIncreaseRequestsToProto(); } + if (this.decreaseRequests != null) { + addDecreaseRequestsToProto(); + } if (this.blacklistRequest != null) { builder.setBlacklistRequest(convertToProtoFormat(this.blacklistRequest)); } @@ -162,14 +166,14 @@ public void setAskList(final List resourceRequests) { } @Override - public List getIncreaseRequests() { + public List getIncreaseRequests() { initIncreaseRequests(); return this.increaseRequests; } @Override public void setIncreaseRequests( - List increaseRequests) { + List increaseRequests) { if (increaseRequests == null) { return; } @@ -177,7 +181,24 @@ public void setIncreaseRequests( this.increaseRequests.clear(); this.increaseRequests.addAll(increaseRequests); } - + + @Override + public List getDecreaseRequests() { + initDecreaseRequests(); + return this.decreaseRequests; + } + + @Override + public void setDecreaseRequests( + List decreaseRequests) { + if (decreaseRequests == null) { + return; + } + initDecreaseRequests(); + this.decreaseRequests.clear(); + this.decreaseRequests.addAll(decreaseRequests); + } + @Override public ResourceBlacklistRequest getResourceBlacklistRequest() { AllocateRequestProtoOrBuilder p = viaProto ? proto : builder; @@ -252,28 +273,42 @@ private void initIncreaseRequests() { return; } AllocateRequestProtoOrBuilder p = viaProto ? proto : builder; - List list = + List list = p.getIncreaseRequestList(); - this.increaseRequests = new ArrayList(); + this.increaseRequests = new ArrayList(); - for (ContainerResourceIncreaseRequestProto c : list) { + for (ContainerResourceChangeRequestProto c : list) { this.increaseRequests.add(convertFromProtoFormat(c)); } } - + + private void initDecreaseRequests() { + if (this.decreaseRequests != null) { + return; + } + AllocateRequestProtoOrBuilder p = viaProto ? proto : builder; + List list = + p.getDecreaseRequestList(); + this.decreaseRequests = new ArrayList<>(); + + for (ContainerResourceChangeRequestProto c : list) { + this.decreaseRequests.add(convertFromProtoFormat(c)); + } + } + private void addIncreaseRequestsToProto() { maybeInitBuilder(); builder.clearIncreaseRequest(); if (increaseRequests == null) { return; } - Iterable iterable = - new Iterable() { + Iterable iterable = + new Iterable() { @Override - public Iterator iterator() { - return new Iterator() { + public Iterator iterator() { + return new Iterator() { - Iterator iter = + Iterator iter = increaseRequests.iterator(); @Override @@ -282,7 +317,7 @@ public boolean hasNext() { } @Override - public ContainerResourceIncreaseRequestProto next() { + public ContainerResourceChangeRequestProto next() { return convertToProtoFormat(iter.next()); } @@ -296,7 +331,43 @@ public void remove() { }; builder.addAllIncreaseRequest(iterable); } - + + private void addDecreaseRequestsToProto() { + maybeInitBuilder(); + builder.clearDecreaseRequest(); + if (decreaseRequests == null) { + return; + } + Iterable iterable = + new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + + Iterator iter = + decreaseRequests.iterator(); + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public ContainerResourceChangeRequestProto next() { + return convertToProtoFormat(iter.next()); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + + } + }; + builder.addAllDecreaseRequest(iterable); + } + @Override public List getReleaseList() { initReleases(); @@ -367,14 +438,14 @@ private ResourceRequestProto convertToProtoFormat(ResourceRequest t) { return ((ResourceRequestPBImpl)t).getProto(); } - private ContainerResourceIncreaseRequestPBImpl convertFromProtoFormat( - ContainerResourceIncreaseRequestProto p) { - return new ContainerResourceIncreaseRequestPBImpl(p); + private ContainerResourceChangeRequestPBImpl convertFromProtoFormat( + ContainerResourceChangeRequestProto p) { + return new ContainerResourceChangeRequestPBImpl(p); } - private ContainerResourceIncreaseRequestProto convertToProtoFormat( - ContainerResourceIncreaseRequest t) { - return ((ContainerResourceIncreaseRequestPBImpl) t).getProto(); + private ContainerResourceChangeRequestProto convertToProtoFormat( + ContainerResourceChangeRequest t) { + return ((ContainerResourceChangeRequestPBImpl) t).getProto(); } private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateResponsePBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateResponsePBImpl.java index f2796fd..84811a9 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateResponsePBImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/AllocateResponsePBImpl.java @@ -29,8 +29,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; import org.apache.hadoop.yarn.api.records.AMCommand; import org.apache.hadoop.yarn.api.records.Container; -import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease; +import org.apache.hadoop.yarn.api.records.DecreasedContainer; +import org.apache.hadoop.yarn.api.records.IncreasedContainer; import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.NMToken; import org.apache.hadoop.yarn.api.records.NodeReport; @@ -38,8 +38,8 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Token; import org.apache.hadoop.yarn.api.records.impl.pb.ContainerPBImpl; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceDecreasePBImpl; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreasePBImpl; +import org.apache.hadoop.yarn.api.records.impl.pb.DecreasedContainerPBImpl; +import org.apache.hadoop.yarn.api.records.impl.pb.IncreasedContainerPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.ContainerStatusPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.NMTokenPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.NodeReportPBImpl; @@ -48,8 +48,8 @@ import org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.TokenPBImpl; import org.apache.hadoop.yarn.proto.YarnProtos.ContainerProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProto; +import org.apache.hadoop.yarn.proto.YarnProtos.DecreasedContainerProto; +import org.apache.hadoop.yarn.proto.YarnProtos.IncreasedContainerProto; import org.apache.hadoop.yarn.proto.YarnProtos.ContainerStatusProto; import org.apache.hadoop.yarn.proto.YarnProtos.NodeReportProto; import org.apache.hadoop.yarn.proto.YarnProtos.PreemptionMessageProto; @@ -72,8 +72,8 @@ private List allocatedContainers = null; private List nmTokens = null; private List completedContainersStatuses = null; - private List increasedContainers = null; - private List decreasedContainers = null; + private List increasedContainers = null; + private List decreasedContainers = null; private List updatedNodes = null; private PreemptionMessage preempt; @@ -147,13 +147,13 @@ private synchronized void mergeLocalToBuilder() { } if (this.increasedContainers != null) { builder.clearIncreasedContainers(); - Iterable iterable = + Iterable iterable = getIncreaseProtoIterable(this.increasedContainers); builder.addAllIncreasedContainers(iterable); } if (this.decreasedContainers != null) { builder.clearDecreasedContainers(); - Iterable iterable = + Iterable iterable = getChangeProtoIterable(this.decreasedContainers); builder.addAllDecreasedContainers(iterable); } @@ -333,14 +333,14 @@ public synchronized void setPreemptionMessage(PreemptionMessage preempt) { } @Override - public synchronized List getIncreasedContainers() { + public synchronized List getIncreasedContainers() { initLocalIncreasedContainerList(); return increasedContainers; } @Override public synchronized void setIncreasedContainers( - List increasedContainers) { + List increasedContainers) { if (increasedContainers == null) return; initLocalIncreasedContainerList(); @@ -348,14 +348,14 @@ public synchronized void setIncreasedContainers( } @Override - public synchronized List getDecreasedContainers() { + public synchronized List getDecreasedContainers() { initLocalDecreasedContainerList(); return decreasedContainers; } @Override public synchronized void setDecreasedContainers( - List decreasedContainers) { + List decreasedContainers) { if (decreasedContainers == null) { return; } @@ -390,10 +390,10 @@ private synchronized void initLocalIncreasedContainerList() { return; } AllocateResponseProtoOrBuilder p = viaProto ? proto : builder; - List list = p.getIncreasedContainersList(); - increasedContainers = new ArrayList(); + List list = p.getIncreasedContainersList(); + increasedContainers = new ArrayList(); - for (ContainerResourceIncreaseProto c : list) { + for (IncreasedContainerProto c : list) { increasedContainers.add(convertFromProtoFormat(c)); } } @@ -403,10 +403,10 @@ private synchronized void initLocalDecreasedContainerList() { return; } AllocateResponseProtoOrBuilder p = viaProto ? proto : builder; - List list = p.getDecreasedContainersList(); - decreasedContainers = new ArrayList(); + List list = p.getDecreasedContainersList(); + decreasedContainers = new ArrayList(); - for (ContainerResourceDecreaseProto c : list) { + for (DecreasedContainerProto c : list) { decreasedContainers.add(convertFromProtoFormat(c)); } } @@ -453,16 +453,16 @@ private synchronized void initLocalNewNMTokenList() { } } - private synchronized Iterable + private synchronized Iterable getIncreaseProtoIterable( - final List newContainersList) { + final List newContainersList) { maybeInitBuilder(); - return new Iterable() { + return new Iterable() { @Override - public synchronized Iterator iterator() { - return new Iterator() { + public synchronized Iterator iterator() { + return new Iterator() { - Iterator iter = newContainersList + Iterator iter = newContainersList .iterator(); @Override @@ -471,7 +471,7 @@ public synchronized boolean hasNext() { } @Override - public synchronized ContainerResourceIncreaseProto next() { + public synchronized IncreasedContainerProto next() { return convertToProtoFormat(iter.next()); } @@ -485,16 +485,16 @@ public synchronized void remove() { }; } - private synchronized Iterable + private synchronized Iterable getChangeProtoIterable( - final List newContainersList) { + final List newContainersList) { maybeInitBuilder(); - return new Iterable() { + return new Iterable() { @Override - public synchronized Iterator iterator() { - return new Iterator() { + public synchronized Iterator iterator() { + return new Iterator() { - Iterator iter = newContainersList + Iterator iter = newContainersList .iterator(); @Override @@ -503,7 +503,7 @@ public synchronized boolean hasNext() { } @Override - public synchronized ContainerResourceDecreaseProto next() { + public synchronized DecreasedContainerProto next() { return convertToProtoFormat(iter.next()); } @@ -655,24 +655,24 @@ private synchronized void initLocalFinishedContainerList() { } } - private synchronized ContainerResourceIncrease convertFromProtoFormat( - ContainerResourceIncreaseProto p) { - return new ContainerResourceIncreasePBImpl(p); + private synchronized IncreasedContainer convertFromProtoFormat( + IncreasedContainerProto p) { + return new IncreasedContainerPBImpl(p); } - private synchronized ContainerResourceIncreaseProto convertToProtoFormat( - ContainerResourceIncrease t) { - return ((ContainerResourceIncreasePBImpl) t).getProto(); + private synchronized IncreasedContainerProto convertToProtoFormat( + IncreasedContainer t) { + return ((IncreasedContainerPBImpl) t).getProto(); } - private synchronized ContainerResourceDecrease convertFromProtoFormat( - ContainerResourceDecreaseProto p) { - return new ContainerResourceDecreasePBImpl(p); + private synchronized DecreasedContainer convertFromProtoFormat( + DecreasedContainerProto p) { + return new DecreasedContainerPBImpl(p); } - private synchronized ContainerResourceDecreaseProto convertToProtoFormat( - ContainerResourceDecrease t) { - return ((ContainerResourceDecreasePBImpl) t).getProto(); + private synchronized DecreasedContainerProto convertToProtoFormat( + DecreasedContainer t) { + return ((DecreasedContainerPBImpl) t).getProto(); } private synchronized NodeReportPBImpl convertFromProtoFormat( diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceChangeRequestPBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceChangeRequestPBImpl.java new file mode 100644 index 0000000..b16a22d --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceChangeRequestPBImpl.java @@ -0,0 +1,141 @@ +/** + * 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.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.ContainerResourceChangeRequest; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceChangeRequestProto; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceChangeRequestProtoOrBuilder; +import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto; + + +public class ContainerResourceChangeRequestPBImpl extends + ContainerResourceChangeRequest { + ContainerResourceChangeRequestProto proto = + ContainerResourceChangeRequestProto.getDefaultInstance(); + ContainerResourceChangeRequestProto.Builder builder = null; + boolean viaProto = false; + + private ContainerId existingContainerId = null; + private Resource targetCapability = null; + + public ContainerResourceChangeRequestPBImpl() { + builder = ContainerResourceChangeRequestProto.newBuilder(); + } + + public ContainerResourceChangeRequestPBImpl( + ContainerResourceChangeRequestProto proto) { + this.proto = proto; + viaProto = true; + } + + public ContainerResourceChangeRequestProto getProto() { + mergeLocalToProto(); + proto = viaProto ? proto : builder.build(); + viaProto = true; + return proto; + } + + @Override + public ContainerId getContainerId() { + ContainerResourceChangeRequestProtoOrBuilder p = viaProto ? proto + : builder; + if (this.existingContainerId != null) { + return this.existingContainerId; + } + if (p.hasContainerId()) { + this.existingContainerId = convertFromProtoFormat(p.getContainerId()); + } + return this.existingContainerId; + } + + @Override + public void setContainerId(ContainerId existingContainerId) { + maybeInitBuilder(); + if (existingContainerId == null) { + builder.clearContainerId(); + } + this.existingContainerId = existingContainerId; + } + + @Override + public Resource getCapability() { + ContainerResourceChangeRequestProtoOrBuilder p = viaProto ? proto + : builder; + if (this.targetCapability != null) { + return this.targetCapability; + } + if (p.hasCapability()) { + this.targetCapability = convertFromProtoFormat(p.getCapability()); + } + return this.targetCapability; + } + + @Override + public void setCapability(Resource targetCapability) { + maybeInitBuilder(); + if (targetCapability == null) { + builder.clearCapability(); + } + this.targetCapability = targetCapability; + } + + private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) { + return new ContainerIdPBImpl(p); + } + + private ContainerIdProto convertToProtoFormat(ContainerId t) { + return ((ContainerIdPBImpl) t).getProto(); + } + + private Resource convertFromProtoFormat(ResourceProto p) { + return new ResourcePBImpl(p); + } + + private ResourceProto convertToProtoFormat(Resource t) { + return ((ResourcePBImpl) t).getProto(); + } + + private void mergeLocalToProto() { + if (viaProto) { + maybeInitBuilder(); + } + mergeLocalToBuilder(); + proto = builder.build(); + viaProto = true; + } + + private void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = ContainerResourceChangeRequestProto.newBuilder(proto); + } + viaProto = false; + } + + private void mergeLocalToBuilder() { + if (this.existingContainerId != null) { + builder.setContainerId(convertToProtoFormat(this.existingContainerId)); + } + if (this.targetCapability != null) { + builder.setCapability(convertToProtoFormat(this.targetCapability)); + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceDecreasePBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceDecreasePBImpl.java deleted file mode 100644 index 1834132..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceDecreasePBImpl.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * 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.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProtoOrBuilder; -import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto; - -public class ContainerResourceDecreasePBImpl extends ContainerResourceDecrease { - ContainerResourceDecreaseProto proto = ContainerResourceDecreaseProto - .getDefaultInstance(); - ContainerResourceDecreaseProto.Builder builder = null; - boolean viaProto = false; - - private ContainerId existingContainerId = null; - private Resource targetCapability = null; - - public ContainerResourceDecreasePBImpl() { - builder = ContainerResourceDecreaseProto.newBuilder(); - } - - public ContainerResourceDecreasePBImpl(ContainerResourceDecreaseProto proto) { - this.proto = proto; - viaProto = true; - } - - public ContainerResourceDecreaseProto getProto() { - mergeLocalToProto(); - proto = viaProto ? proto : builder.build(); - viaProto = true; - return proto; - } - - @Override - public ContainerId getContainerId() { - ContainerResourceDecreaseProtoOrBuilder p = viaProto ? proto : builder; - if (this.existingContainerId != null) { - return this.existingContainerId; - } - if (p.hasContainerId()) { - this.existingContainerId = convertFromProtoFormat(p.getContainerId()); - } - return this.existingContainerId; - } - - @Override - public void setContainerId(ContainerId existingContainerId) { - maybeInitBuilder(); - if (existingContainerId == null) { - builder.clearContainerId(); - } - this.existingContainerId = existingContainerId; - } - - @Override - public Resource getCapability() { - ContainerResourceDecreaseProtoOrBuilder p = viaProto ? proto : builder; - if (this.targetCapability != null) { - return this.targetCapability; - } - if (p.hasCapability()) { - this.targetCapability = convertFromProtoFormat(p.getCapability()); - } - return this.targetCapability; - } - - @Override - public void setCapability(Resource targetCapability) { - maybeInitBuilder(); - if (targetCapability == null) { - builder.clearCapability(); - } - this.targetCapability = targetCapability; - } - - private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) { - return new ContainerIdPBImpl(p); - } - - private ContainerIdProto convertToProtoFormat(ContainerId t) { - return ((ContainerIdPBImpl) t).getProto(); - } - - private Resource convertFromProtoFormat(ResourceProto p) { - return new ResourcePBImpl(p); - } - - private ResourceProto convertToProtoFormat(Resource t) { - return ((ResourcePBImpl) t).getProto(); - } - - private void mergeLocalToProto() { - if (viaProto) { - maybeInitBuilder(); - } - mergeLocalToBuilder(); - proto = builder.build(); - viaProto = true; - } - - private void maybeInitBuilder() { - if (viaProto || builder == null) { - builder = ContainerResourceDecreaseProto.newBuilder(proto); - } - viaProto = false; - } - - private void mergeLocalToBuilder() { - if (this.existingContainerId != null) { - builder.setContainerId(convertToProtoFormat(this.existingContainerId)); - } - if (this.targetCapability != null) { - builder.setCapability(convertToProtoFormat(this.targetCapability)); - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceIncreasePBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceIncreasePBImpl.java deleted file mode 100644 index 4e4f3a7..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceIncreasePBImpl.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * 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.security.proto.SecurityProtos.TokenProto; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.Token; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProtoOrBuilder; -import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto; - -public class ContainerResourceIncreasePBImpl extends ContainerResourceIncrease { - ContainerResourceIncreaseProto proto = ContainerResourceIncreaseProto - .getDefaultInstance(); - ContainerResourceIncreaseProto.Builder builder = null; - boolean viaProto = false; - - private ContainerId existingContainerId = null; - private Resource targetCapability = null; - private Token token = null; - - public ContainerResourceIncreasePBImpl() { - builder = ContainerResourceIncreaseProto.newBuilder(); - } - - public ContainerResourceIncreasePBImpl(ContainerResourceIncreaseProto proto) { - this.proto = proto; - viaProto = true; - } - - public ContainerResourceIncreaseProto getProto() { - mergeLocalToProto(); - proto = viaProto ? proto : builder.build(); - viaProto = true; - return proto; - } - - @Override - public ContainerId getContainerId() { - ContainerResourceIncreaseProtoOrBuilder p = viaProto ? proto : builder; - if (this.existingContainerId != null) { - return this.existingContainerId; - } - if (p.hasContainerId()) { - this.existingContainerId = convertFromProtoFormat(p.getContainerId()); - } - return this.existingContainerId; - } - - @Override - public void setContainerId(ContainerId existingContainerId) { - maybeInitBuilder(); - if (existingContainerId == null) { - builder.clearContainerId(); - } - this.existingContainerId = existingContainerId; - } - - @Override - public Resource getCapability() { - ContainerResourceIncreaseProtoOrBuilder p = viaProto ? proto : builder; - if (this.targetCapability != null) { - return this.targetCapability; - } - if (p.hasCapability()) { - this.targetCapability = convertFromProtoFormat(p.getCapability()); - } - return this.targetCapability; - } - - @Override - public void setCapability(Resource targetCapability) { - maybeInitBuilder(); - if (targetCapability == null) { - builder.clearCapability(); - } - this.targetCapability = targetCapability; - } - - @Override - public Token getContainerToken() { - ContainerResourceIncreaseProtoOrBuilder p = viaProto ? proto : builder; - if (this.token != null) { - return this.token; - } - if (p.hasContainerToken()) { - this.token = convertFromProtoFormat(p.getContainerToken()); - } - return this.token; - } - - @Override - public void setContainerToken(Token token) { - maybeInitBuilder(); - if (token == null) { - builder.clearContainerToken(); - } - this.token = token; - } - - private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) { - return new ContainerIdPBImpl(p); - } - - private ContainerIdProto convertToProtoFormat(ContainerId t) { - return ((ContainerIdPBImpl) t).getProto(); - } - - private Resource convertFromProtoFormat(ResourceProto p) { - return new ResourcePBImpl(p); - } - - private ResourceProto convertToProtoFormat(Resource t) { - return ((ResourcePBImpl) t).getProto(); - } - - private Token convertFromProtoFormat(TokenProto p) { - return new TokenPBImpl(p); - } - - private TokenProto convertToProtoFormat(Token t) { - return ((TokenPBImpl) t).getProto(); - } - - private void mergeLocalToProto() { - if (viaProto) { - maybeInitBuilder(); - } - mergeLocalToBuilder(); - proto = builder.build(); - viaProto = true; - } - - private void maybeInitBuilder() { - if (viaProto || builder == null) { - builder = ContainerResourceIncreaseProto.newBuilder(proto); - } - viaProto = false; - } - - private void mergeLocalToBuilder() { - if (this.existingContainerId != null) { - builder.setContainerId(convertToProtoFormat(this.existingContainerId)); - } - if (this.targetCapability != null) { - builder.setCapability(convertToProtoFormat(this.targetCapability)); - } - if (this.token != null) { - builder.setContainerToken(convertToProtoFormat(this.token)); - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceIncreaseRequestPBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceIncreaseRequestPBImpl.java deleted file mode 100644 index f5ebf6c..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerResourceIncreaseRequestPBImpl.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * 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.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProtoOrBuilder; -import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto; - - -public class ContainerResourceIncreaseRequestPBImpl extends - ContainerResourceIncreaseRequest { - ContainerResourceIncreaseRequestProto proto = - ContainerResourceIncreaseRequestProto.getDefaultInstance(); - ContainerResourceIncreaseRequestProto.Builder builder = null; - boolean viaProto = false; - - private ContainerId existingContainerId = null; - private Resource targetCapability = null; - - public ContainerResourceIncreaseRequestPBImpl() { - builder = ContainerResourceIncreaseRequestProto.newBuilder(); - } - - public ContainerResourceIncreaseRequestPBImpl( - ContainerResourceIncreaseRequestProto proto) { - this.proto = proto; - viaProto = true; - } - - public ContainerResourceIncreaseRequestProto getProto() { - mergeLocalToProto(); - proto = viaProto ? proto : builder.build(); - viaProto = true; - return proto; - } - - @Override - public ContainerId getContainerId() { - ContainerResourceIncreaseRequestProtoOrBuilder p = viaProto ? proto - : builder; - if (this.existingContainerId != null) { - return this.existingContainerId; - } - if (p.hasContainerId()) { - this.existingContainerId = convertFromProtoFormat(p.getContainerId()); - } - return this.existingContainerId; - } - - @Override - public void setContainerId(ContainerId existingContainerId) { - maybeInitBuilder(); - if (existingContainerId == null) { - builder.clearContainerId(); - } - this.existingContainerId = existingContainerId; - } - - @Override - public Resource getCapability() { - ContainerResourceIncreaseRequestProtoOrBuilder p = viaProto ? proto - : builder; - if (this.targetCapability != null) { - return this.targetCapability; - } - if (p.hasCapability()) { - this.targetCapability = convertFromProtoFormat(p.getCapability()); - } - return this.targetCapability; - } - - @Override - public void setCapability(Resource targetCapability) { - maybeInitBuilder(); - if (targetCapability == null) { - builder.clearCapability(); - } - this.targetCapability = targetCapability; - } - - private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) { - return new ContainerIdPBImpl(p); - } - - private ContainerIdProto convertToProtoFormat(ContainerId t) { - return ((ContainerIdPBImpl) t).getProto(); - } - - private Resource convertFromProtoFormat(ResourceProto p) { - return new ResourcePBImpl(p); - } - - private ResourceProto convertToProtoFormat(Resource t) { - return ((ResourcePBImpl) t).getProto(); - } - - private void mergeLocalToProto() { - if (viaProto) { - maybeInitBuilder(); - } - mergeLocalToBuilder(); - proto = builder.build(); - viaProto = true; - } - - private void maybeInitBuilder() { - if (viaProto || builder == null) { - builder = ContainerResourceIncreaseRequestProto.newBuilder(proto); - } - viaProto = false; - } - - private void mergeLocalToBuilder() { - if (this.existingContainerId != null) { - builder.setContainerId(convertToProtoFormat(this.existingContainerId)); - } - if (this.targetCapability != null) { - builder.setCapability(convertToProtoFormat(this.targetCapability)); - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/DecreasedContainerPBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/DecreasedContainerPBImpl.java new file mode 100644 index 0000000..9301adc --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/DecreasedContainerPBImpl.java @@ -0,0 +1,136 @@ +/** + * 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.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.DecreasedContainer; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto; +import org.apache.hadoop.yarn.proto.YarnProtos.DecreasedContainerProto; +import org.apache.hadoop.yarn.proto.YarnProtos.DecreasedContainerProtoOrBuilder; +import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto; + +public class DecreasedContainerPBImpl extends DecreasedContainer { + DecreasedContainerProto proto = DecreasedContainerProto + .getDefaultInstance(); + DecreasedContainerProto.Builder builder = null; + boolean viaProto = false; + + private ContainerId existingContainerId = null; + private Resource targetCapability = null; + + public DecreasedContainerPBImpl() { + builder = DecreasedContainerProto.newBuilder(); + } + + public DecreasedContainerPBImpl(DecreasedContainerProto proto) { + this.proto = proto; + viaProto = true; + } + + public DecreasedContainerProto getProto() { + mergeLocalToProto(); + proto = viaProto ? proto : builder.build(); + viaProto = true; + return proto; + } + + @Override + public ContainerId getContainerId() { + DecreasedContainerProtoOrBuilder p = viaProto ? proto : builder; + if (this.existingContainerId != null) { + return this.existingContainerId; + } + if (p.hasContainerId()) { + this.existingContainerId = convertFromProtoFormat(p.getContainerId()); + } + return this.existingContainerId; + } + + @Override + public void setContainerId(ContainerId existingContainerId) { + maybeInitBuilder(); + if (existingContainerId == null) { + builder.clearContainerId(); + } + this.existingContainerId = existingContainerId; + } + + @Override + public Resource getCapability() { + DecreasedContainerProtoOrBuilder p = viaProto ? proto : builder; + if (this.targetCapability != null) { + return this.targetCapability; + } + if (p.hasCapability()) { + this.targetCapability = convertFromProtoFormat(p.getCapability()); + } + return this.targetCapability; + } + + @Override + public void setCapability(Resource targetCapability) { + maybeInitBuilder(); + if (targetCapability == null) { + builder.clearCapability(); + } + this.targetCapability = targetCapability; + } + + private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) { + return new ContainerIdPBImpl(p); + } + + private ContainerIdProto convertToProtoFormat(ContainerId t) { + return ((ContainerIdPBImpl) t).getProto(); + } + + private Resource convertFromProtoFormat(ResourceProto p) { + return new ResourcePBImpl(p); + } + + private ResourceProto convertToProtoFormat(Resource t) { + return ((ResourcePBImpl) t).getProto(); + } + + private void mergeLocalToProto() { + if (viaProto) { + maybeInitBuilder(); + } + mergeLocalToBuilder(); + proto = builder.build(); + viaProto = true; + } + + private void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = DecreasedContainerProto.newBuilder(proto); + } + viaProto = false; + } + + private void mergeLocalToBuilder() { + if (this.existingContainerId != null) { + builder.setContainerId(convertToProtoFormat(this.existingContainerId)); + } + if (this.targetCapability != null) { + builder.setCapability(convertToProtoFormat(this.targetCapability)); + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/IncreasedContainerPBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/IncreasedContainerPBImpl.java new file mode 100644 index 0000000..c7ff03b --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/IncreasedContainerPBImpl.java @@ -0,0 +1,171 @@ +/** + * 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.security.proto.SecurityProtos.TokenProto; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.IncreasedContainer; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.Token; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto; +import org.apache.hadoop.yarn.proto.YarnProtos.IncreasedContainerProto; +import org.apache.hadoop.yarn.proto.YarnProtos.IncreasedContainerProtoOrBuilder; +import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto; + +public class IncreasedContainerPBImpl extends IncreasedContainer { + IncreasedContainerProto proto = IncreasedContainerProto + .getDefaultInstance(); + IncreasedContainerProto.Builder builder = null; + boolean viaProto = false; + + private ContainerId existingContainerId = null; + private Resource targetCapability = null; + private Token token = null; + + public IncreasedContainerPBImpl() { + builder = IncreasedContainerProto.newBuilder(); + } + + public IncreasedContainerPBImpl(IncreasedContainerProto proto) { + this.proto = proto; + viaProto = true; + } + + public IncreasedContainerProto getProto() { + mergeLocalToProto(); + proto = viaProto ? proto : builder.build(); + viaProto = true; + return proto; + } + + @Override + public ContainerId getContainerId() { + IncreasedContainerProtoOrBuilder p = viaProto ? proto : builder; + if (this.existingContainerId != null) { + return this.existingContainerId; + } + if (p.hasContainerId()) { + this.existingContainerId = convertFromProtoFormat(p.getContainerId()); + } + return this.existingContainerId; + } + + @Override + public void setContainerId(ContainerId existingContainerId) { + maybeInitBuilder(); + if (existingContainerId == null) { + builder.clearContainerId(); + } + this.existingContainerId = existingContainerId; + } + + @Override + public Resource getCapability() { + IncreasedContainerProtoOrBuilder p = viaProto ? proto : builder; + if (this.targetCapability != null) { + return this.targetCapability; + } + if (p.hasCapability()) { + this.targetCapability = convertFromProtoFormat(p.getCapability()); + } + return this.targetCapability; + } + + @Override + public void setCapability(Resource targetCapability) { + maybeInitBuilder(); + if (targetCapability == null) { + builder.clearCapability(); + } + this.targetCapability = targetCapability; + } + + @Override + public Token getContainerToken() { + IncreasedContainerProtoOrBuilder p = viaProto ? proto : builder; + if (this.token != null) { + return this.token; + } + if (p.hasContainerToken()) { + this.token = convertFromProtoFormat(p.getContainerToken()); + } + return this.token; + } + + @Override + public void setContainerToken(Token token) { + maybeInitBuilder(); + if (token == null) { + builder.clearContainerToken(); + } + this.token = token; + } + + private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) { + return new ContainerIdPBImpl(p); + } + + private ContainerIdProto convertToProtoFormat(ContainerId t) { + return ((ContainerIdPBImpl) t).getProto(); + } + + private Resource convertFromProtoFormat(ResourceProto p) { + return new ResourcePBImpl(p); + } + + private ResourceProto convertToProtoFormat(Resource t) { + return ((ResourcePBImpl) t).getProto(); + } + + private Token convertFromProtoFormat(TokenProto p) { + return new TokenPBImpl(p); + } + + private TokenProto convertToProtoFormat(Token t) { + return ((TokenPBImpl) t).getProto(); + } + + private void mergeLocalToProto() { + if (viaProto) { + maybeInitBuilder(); + } + mergeLocalToBuilder(); + proto = builder.build(); + viaProto = true; + } + + private void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = IncreasedContainerProto.newBuilder(proto); + } + viaProto = false; + } + + private void mergeLocalToBuilder() { + if (this.existingContainerId != null) { + builder.setContainerId(convertToProtoFormat(this.existingContainerId)); + } + if (this.targetCapability != null) { + builder.setCapability(convertToProtoFormat(this.targetCapability)); + } + if (this.token != null) { + builder.setContainerToken(convertToProtoFormat(this.token)); + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateRequest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateRequest.java index 5ea29f8..81817fa 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateRequest.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateRequest.java @@ -21,26 +21,33 @@ import java.util.ArrayList; import java.util.List; +import org.apache.hadoop.yarn.api.records.ContainerResourceChangeRequest; import org.junit.Assert; import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl; import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest; import org.apache.hadoop.yarn.proto.YarnServiceProtos.AllocateRequestProto; import org.junit.Test; public class TestAllocateRequest { @Test - public void testAllcoateRequestWithIncrease() { - List incRequests = - new ArrayList(); + public void testAllcoateRequestWithIncreaseAndDecrease() { + List incRequests = + new ArrayList(); + List decRequests = + new ArrayList(); for (int i = 0; i < 3; i++) { - incRequests.add(ContainerResourceIncreaseRequest.newInstance(null, - Resource.newInstance(0, i))); + incRequests.add(ContainerResourceChangeRequest.newInstance(null, + Resource.newInstance(0, i))); + } + for (int i = 0; i < 3; i++) { + decRequests.add(ContainerResourceChangeRequest.newInstance(null, + Resource.newInstance(0, i))); } AllocateRequest r = - AllocateRequest.newInstance(123, 0f, null, null, null, incRequests); + AllocateRequest.newInstance(123, 0f, null, null, null, + incRequests, decRequests); // serde AllocateRequestProto p = ((AllocateRequestPBImpl) r).getProto(); @@ -49,18 +56,24 @@ public void testAllcoateRequestWithIncrease() { // check value Assert.assertEquals(123, r.getResponseId()); Assert.assertEquals(incRequests.size(), r.getIncreaseRequests().size()); + Assert.assertEquals(decRequests.size(), r.getDecreaseRequests().size()); for (int i = 0; i < incRequests.size(); i++) { Assert.assertEquals(r.getIncreaseRequests().get(i).getCapability() .getVirtualCores(), incRequests.get(i).getCapability() .getVirtualCores()); } + for (int i = 0; i < decRequests.size(); i++) { + Assert.assertEquals(r.getDecreaseRequests().get(i).getCapability() + .getVirtualCores(), decRequests.get(i).getCapability() + .getVirtualCores()); + } } @Test - public void testAllcoateRequestWithoutIncrease() { + public void testAllcoateRequestWithoutIncreaseAndDecrease() { AllocateRequest r = - AllocateRequest.newInstance(123, 0f, null, null, null, null); + AllocateRequest.newInstance(123, 0f, null, null, null, null, null); // serde AllocateRequestProto p = ((AllocateRequestPBImpl) r).getProto(); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateResponse.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateResponse.java index fbe9af9..2d9e17f 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateResponse.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestAllocateResponse.java @@ -25,8 +25,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateResponsePBImpl; import org.apache.hadoop.yarn.api.records.AMCommand; import org.apache.hadoop.yarn.api.records.Container; -import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease; +import org.apache.hadoop.yarn.api.records.DecreasedContainer; +import org.apache.hadoop.yarn.api.records.IncreasedContainer; import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.NMToken; import org.apache.hadoop.yarn.api.records.NodeReport; @@ -55,17 +55,17 @@ @SuppressWarnings("deprecation") @Test public void testAllocateResponseWithIncDecContainers() { - List incContainers = - new ArrayList(); - List decContainers = - new ArrayList(); + List incContainers = + new ArrayList(); + List decContainers = + new ArrayList(); for (int i = 0; i < 3; i++) { - incContainers.add(ContainerResourceIncrease.newInstance(null, - Resource.newInstance(1024, i), null)); + incContainers.add(IncreasedContainer.newInstance(null, + Resource.newInstance(1024, i), null)); } for (int i = 0; i < 5; i++) { - decContainers.add(ContainerResourceDecrease.newInstance(null, - Resource.newInstance(1024, i))); + decContainers.add(DecreasedContainer.newInstance(null, + Resource.newInstance(1024, i))); } AllocateResponse r = diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceChangeRequest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceChangeRequest.java new file mode 100644 index 0000000..575025c --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceChangeRequest.java @@ -0,0 +1,68 @@ +/** + * 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.impl.pb.ContainerResourceChangeRequestPBImpl; +import org.junit.Assert; + +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.ContainerResourceChangeRequest; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceChangeRequestProto; +import org.junit.Test; + +public class TestContainerResourceChangeRequest { + @Test + public void ContainerResourceIncreaseRequest() { + ContainerId containerId = ContainerId + .newContainerId(ApplicationAttemptId.newInstance( + ApplicationId.newInstance(1234, 3), 3), 7); + Resource resource = Resource.newInstance(1023, 3); + ContainerResourceChangeRequest context = ContainerResourceChangeRequest + .newInstance(containerId, resource); + + // to proto and get it back + ContainerResourceChangeRequestProto proto = + ((ContainerResourceChangeRequestPBImpl) context).getProto(); + ContainerResourceChangeRequest contextRecover = + new ContainerResourceChangeRequestPBImpl(proto); + + // check value + Assert.assertEquals(contextRecover.getContainerId(), containerId); + Assert.assertEquals(contextRecover.getCapability(), resource); + } + + @Test + public void testResourceChangeContextWithNullField() { + ContainerResourceChangeRequest context = ContainerResourceChangeRequest + .newInstance(null, null); + + // to proto and get it back + ContainerResourceChangeRequestProto proto = + ((ContainerResourceChangeRequestPBImpl) context).getProto(); + ContainerResourceChangeRequest contextRecover = + new ContainerResourceChangeRequestPBImpl(proto); + + // check value + Assert.assertNull(contextRecover.getContainerId()); + Assert.assertNull(contextRecover.getCapability()); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceDecrease.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceDecrease.java deleted file mode 100644 index 29b0ffe..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceDecrease.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * 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.junit.Assert; - -import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; -import org.apache.hadoop.yarn.api.records.ApplicationId; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceDecreasePBImpl; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProto; -import org.junit.Test; - -public class TestContainerResourceDecrease { - @Test - public void testResourceDecreaseContext() { - ContainerId containerId = ContainerId - .newContainerId(ApplicationAttemptId.newInstance( - ApplicationId.newInstance(1234, 3), 3), 7); - Resource resource = Resource.newInstance(1023, 3); - ContainerResourceDecrease ctx = ContainerResourceDecrease.newInstance( - containerId, resource); - - // get proto and recover to ctx - ContainerResourceDecreaseProto proto = - ((ContainerResourceDecreasePBImpl) ctx).getProto(); - ctx = new ContainerResourceDecreasePBImpl(proto); - - // check values - Assert.assertEquals(ctx.getCapability(), resource); - Assert.assertEquals(ctx.getContainerId(), containerId); - } - - @Test - public void testResourceDecreaseContextWithNull() { - ContainerResourceDecrease ctx = ContainerResourceDecrease.newInstance(null, - null); - - // get proto and recover to ctx; - ContainerResourceDecreaseProto proto = - ((ContainerResourceDecreasePBImpl) ctx).getProto(); - ctx = new ContainerResourceDecreasePBImpl(proto); - - // check values - Assert.assertNull(ctx.getCapability()); - Assert.assertNull(ctx.getContainerId()); - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceIncrease.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceIncrease.java deleted file mode 100644 index 932d5a7..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceIncrease.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * 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 java.util.Arrays; - -import org.junit.Assert; - -import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; -import org.apache.hadoop.yarn.api.records.ApplicationId; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.Token; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreasePBImpl; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProto; -import org.junit.Test; - -public class TestContainerResourceIncrease { - @Test - public void testResourceIncreaseContext() { - byte[] identifier = new byte[] { 1, 2, 3, 4 }; - Token token = Token.newInstance(identifier, "", "".getBytes(), ""); - ContainerId containerId = ContainerId - .newContainerId(ApplicationAttemptId.newInstance( - ApplicationId.newInstance(1234, 3), 3), 7); - Resource resource = Resource.newInstance(1023, 3); - ContainerResourceIncrease ctx = ContainerResourceIncrease.newInstance( - containerId, resource, token); - - // get proto and recover to ctx - ContainerResourceIncreaseProto proto = - ((ContainerResourceIncreasePBImpl) ctx).getProto(); - ctx = new ContainerResourceIncreasePBImpl(proto); - - // check values - Assert.assertEquals(ctx.getCapability(), resource); - Assert.assertEquals(ctx.getContainerId(), containerId); - Assert.assertTrue(Arrays.equals(ctx.getContainerToken().getIdentifier() - .array(), identifier)); - } - - @Test - public void testResourceIncreaseContextWithNull() { - ContainerResourceIncrease ctx = ContainerResourceIncrease.newInstance(null, - null, null); - - // get proto and recover to ctx; - ContainerResourceIncreaseProto proto = - ((ContainerResourceIncreasePBImpl) ctx).getProto(); - ctx = new ContainerResourceIncreasePBImpl(proto); - - // check values - Assert.assertNull(ctx.getContainerToken()); - Assert.assertNull(ctx.getCapability()); - Assert.assertNull(ctx.getContainerId()); - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceIncreaseRequest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceIncreaseRequest.java deleted file mode 100644 index cf4dabf..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestContainerResourceIncreaseRequest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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.junit.Assert; - -import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; -import org.apache.hadoop.yarn.api.records.ApplicationId; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreaseRequestPBImpl; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProto; -import org.junit.Test; - -public class TestContainerResourceIncreaseRequest { - @Test - public void ContainerResourceIncreaseRequest() { - ContainerId containerId = ContainerId - .newContainerId(ApplicationAttemptId.newInstance( - ApplicationId.newInstance(1234, 3), 3), 7); - Resource resource = Resource.newInstance(1023, 3); - ContainerResourceIncreaseRequest context = ContainerResourceIncreaseRequest - .newInstance(containerId, resource); - - // to proto and get it back - ContainerResourceIncreaseRequestProto proto = - ((ContainerResourceIncreaseRequestPBImpl) context).getProto(); - ContainerResourceIncreaseRequest contextRecover = - new ContainerResourceIncreaseRequestPBImpl(proto); - - // check value - Assert.assertEquals(contextRecover.getContainerId(), containerId); - Assert.assertEquals(contextRecover.getCapability(), resource); - } - - @Test - public void testResourceChangeContextWithNullField() { - ContainerResourceIncreaseRequest context = ContainerResourceIncreaseRequest - .newInstance(null, null); - - // to proto and get it back - ContainerResourceIncreaseRequestProto proto = - ((ContainerResourceIncreaseRequestPBImpl) context).getProto(); - ContainerResourceIncreaseRequest contextRecover = - new ContainerResourceIncreaseRequestPBImpl(proto); - - // check value - Assert.assertNull(contextRecover.getContainerId()); - Assert.assertNull(contextRecover.getCapability()); - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestDecreasedContainer.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestDecreasedContainer.java new file mode 100644 index 0000000..e49660f --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestDecreasedContainer.java @@ -0,0 +1,66 @@ +/** + * 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.DecreasedContainer; +import org.apache.hadoop.yarn.api.records.impl.pb.DecreasedContainerPBImpl; +import org.junit.Assert; + +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.proto.YarnProtos.DecreasedContainerProto; +import org.junit.Test; + +public class TestDecreasedContainer { + @Test + public void testResourceDecreaseContext() { + ContainerId containerId = ContainerId + .newContainerId(ApplicationAttemptId.newInstance( + ApplicationId.newInstance(1234, 3), 3), 7); + Resource resource = Resource.newInstance(1023, 3); + DecreasedContainer ctx = DecreasedContainer.newInstance( + containerId, resource); + + // get proto and recover to ctx + DecreasedContainerProto proto = + ((DecreasedContainerPBImpl) ctx).getProto(); + ctx = new DecreasedContainerPBImpl(proto); + + // check values + Assert.assertEquals(ctx.getCapability(), resource); + Assert.assertEquals(ctx.getContainerId(), containerId); + } + + @Test + public void testResourceDecreaseContextWithNull() { + DecreasedContainer ctx = DecreasedContainer.newInstance(null, + null); + + // get proto and recover to ctx; + DecreasedContainerProto proto = + ((DecreasedContainerPBImpl) ctx).getProto(); + ctx = new DecreasedContainerPBImpl(proto); + + // check values + Assert.assertNull(ctx.getCapability()); + Assert.assertNull(ctx.getContainerId()); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestIncreasedContainer.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestIncreasedContainer.java new file mode 100644 index 0000000..8a855af --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestIncreasedContainer.java @@ -0,0 +1,74 @@ +/** + * 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 java.util.Arrays; + +import org.apache.hadoop.yarn.api.records.IncreasedContainer; +import org.apache.hadoop.yarn.api.records.impl.pb.IncreasedContainerPBImpl; +import org.junit.Assert; + +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.Token; +import org.apache.hadoop.yarn.proto.YarnProtos.IncreasedContainerProto; +import org.junit.Test; + +public class TestIncreasedContainer { + @Test + public void testResourceIncreaseContext() { + byte[] identifier = new byte[] { 1, 2, 3, 4 }; + Token token = Token.newInstance(identifier, "", "".getBytes(), ""); + ContainerId containerId = ContainerId + .newContainerId(ApplicationAttemptId.newInstance( + ApplicationId.newInstance(1234, 3), 3), 7); + Resource resource = Resource.newInstance(1023, 3); + IncreasedContainer ctx = IncreasedContainer.newInstance( + containerId, resource, token); + + // get proto and recover to ctx + IncreasedContainerProto proto = + ((IncreasedContainerPBImpl) ctx).getProto(); + ctx = new IncreasedContainerPBImpl(proto); + + // check values + Assert.assertEquals(ctx.getCapability(), resource); + Assert.assertEquals(ctx.getContainerId(), containerId); + Assert.assertTrue(Arrays.equals(ctx.getContainerToken().getIdentifier() + .array(), identifier)); + } + + @Test + public void testResourceIncreaseContextWithNull() { + IncreasedContainer ctx = IncreasedContainer.newInstance(null, + null, null); + + // get proto and recover to ctx; + IncreasedContainerProto proto = + ((IncreasedContainerPBImpl) ctx).getProto(); + ctx = new IncreasedContainerPBImpl(proto); + + // check values + Assert.assertNull(ctx.getContainerToken()); + Assert.assertNull(ctx.getCapability()); + Assert.assertNull(ctx.getContainerId()); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestPBImplRecords.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestPBImplRecords.java index 8dacd3b..9b87411 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestPBImplRecords.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestPBImplRecords.java @@ -113,9 +113,9 @@ import org.apache.hadoop.yarn.api.records.ContainerId; import org.apache.hadoop.yarn.api.records.ContainerLaunchContext; import org.apache.hadoop.yarn.api.records.ContainerReport; -import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease; -import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest; +import org.apache.hadoop.yarn.api.records.ContainerResourceChangeRequest; +import org.apache.hadoop.yarn.api.records.DecreasedContainer; +import org.apache.hadoop.yarn.api.records.IncreasedContainer; import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.LocalResource; import org.apache.hadoop.yarn.api.records.LogAggregationContext; @@ -155,9 +155,9 @@ import org.apache.hadoop.yarn.api.records.impl.pb.ContainerLaunchContextPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.ContainerPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.ContainerReportPBImpl; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceDecreasePBImpl; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreasePBImpl; -import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreaseRequestPBImpl; +import org.apache.hadoop.yarn.api.records.impl.pb.DecreasedContainerPBImpl; +import org.apache.hadoop.yarn.api.records.impl.pb.IncreasedContainerPBImpl; +import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceChangeRequestPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.ContainerStatusPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.LocalResourcePBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.NMTokenPBImpl; @@ -190,9 +190,9 @@ import org.apache.hadoop.yarn.proto.YarnProtos.ContainerLaunchContextProto; import org.apache.hadoop.yarn.proto.YarnProtos.ContainerProto; import org.apache.hadoop.yarn.proto.YarnProtos.ContainerReportProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProto; -import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProto; +import org.apache.hadoop.yarn.proto.YarnProtos.DecreasedContainerProto; +import org.apache.hadoop.yarn.proto.YarnProtos.IncreasedContainerProto; +import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceChangeRequestProto; import org.apache.hadoop.yarn.proto.YarnProtos.ContainerStatusProto; import org.apache.hadoop.yarn.proto.YarnProtos.LocalResourceProto; import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdProto; @@ -467,9 +467,9 @@ public static void setup() throws Exception { generateByNewInstance(ContainerLaunchContext.class); generateByNewInstance(ApplicationSubmissionContext.class); generateByNewInstance(ContainerReport.class); - generateByNewInstance(ContainerResourceDecrease.class); - generateByNewInstance(ContainerResourceIncrease.class); - generateByNewInstance(ContainerResourceIncreaseRequest.class); + generateByNewInstance(DecreasedContainer.class); + generateByNewInstance(IncreasedContainer.class); + generateByNewInstance(ContainerResourceChangeRequest.class); generateByNewInstance(ContainerStatus.class); generateByNewInstance(PreemptionContainer.class); generateByNewInstance(PreemptionResourceRequest.class); @@ -955,21 +955,21 @@ public void testContainerReportPBImpl() throws Exception { } @Test - public void testContainerResourceDecreasePBImpl() throws Exception { - validatePBImplRecord(ContainerResourceDecreasePBImpl.class, - ContainerResourceDecreaseProto.class); + public void testDecreasedContainerPBImpl() throws Exception { + validatePBImplRecord(DecreasedContainerPBImpl.class, + DecreasedContainerProto.class); } @Test - public void testContainerResourceIncreasePBImpl() throws Exception { - validatePBImplRecord(ContainerResourceIncreasePBImpl.class, - ContainerResourceIncreaseProto.class); + public void testIncreasedContainerPBImpl() throws Exception { + validatePBImplRecord(IncreasedContainerPBImpl.class, + IncreasedContainerProto.class); } @Test - public void testContainerResourceIncreaseRequestPBImpl() throws Exception { - validatePBImplRecord(ContainerResourceIncreaseRequestPBImpl.class, - ContainerResourceIncreaseRequestProto.class); + public void testContainerResourceChangeRequestPBImpl() throws Exception { + validatePBImplRecord(ContainerResourceChangeRequestPBImpl.class, + ContainerResourceChangeRequestProto.class); } @Test