|
36 | 36 | import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; |
37 | 37 |
|
38 | 38 | import org.apache.commons.collections4.keyvalue.DefaultMapEntry; |
| 39 | +import org.apache.hadoop.yarn.conf.YarnConfiguration; |
39 | 40 | import org.apache.hadoop.yarn.server.api.records.NodeStatus; |
40 | 41 | import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer; |
41 | 42 | import org.slf4j.Logger; |
@@ -139,6 +140,7 @@ public class RMNodeImpl implements RMNode, EventHandler<RMNodeEvent> { |
139 | 140 | private Integer decommissioningTimeout; |
140 | 141 |
|
141 | 142 | private long timeStamp; |
| 143 | + private final boolean opportunisticContainersEnabled; |
142 | 144 | /* Aggregated resource utilization for the containers. */ |
143 | 145 | private ResourceUtilization containersUtilization; |
144 | 146 | /* Resource utilization for the node. */ |
@@ -407,6 +409,8 @@ public RMNodeImpl(NodeId nodeId, RMContext context, String hostName, |
407 | 409 | this.healthReport = "Healthy"; |
408 | 410 | this.lastHealthReportTime = System.currentTimeMillis(); |
409 | 411 | this.nodeManagerVersion = nodeManagerVersion; |
| 412 | + this.opportunisticContainersEnabled = YarnConfiguration |
| 413 | + .isOpportunisticContainerAllocationEnabled(context.getYarnConfiguration()); |
410 | 414 | this.timeStamp = 0; |
411 | 415 | // If physicalResource is not available, capability is a reasonable guess |
412 | 416 | this.physicalResource = physResource==null ? capability : physResource; |
@@ -1583,7 +1587,6 @@ private void handleContainerStatus(List<ContainerStatus> containerStatuses) { |
1583 | 1587 | List<Map.Entry<ApplicationId, ContainerStatus>> needUpdateContainers = |
1584 | 1588 | new ArrayList<Map.Entry<ApplicationId, ContainerStatus>>(); |
1585 | 1589 | int numRemoteRunningContainers = 0; |
1586 | | - final Resource allocatedResource = Resource.newInstance(Resources.none()); |
1587 | 1590 |
|
1588 | 1591 | for (ContainerStatus remoteContainer : containerStatuses) { |
1589 | 1592 | ContainerId containerId = remoteContainer.getContainerId(); |
@@ -1654,15 +1657,18 @@ private void handleContainerStatus(List<ContainerStatus> containerStatuses) { |
1654 | 1657 | .unregister(new AllocationExpirationInfo(containerId)); |
1655 | 1658 | } |
1656 | 1659 |
|
1657 | | - if ((remoteContainer.getState() == ContainerState.RUNNING || |
1658 | | - remoteContainer.getState() == ContainerState.NEW) && |
1659 | | - remoteContainer.getCapability() != null) { |
1660 | | - Resources.addTo(allocatedResource, remoteContainer.getCapability()); |
| 1660 | + if (opportunisticContainersEnabled){ |
| 1661 | + Resource allocatedResource = Resource.newInstance(Resources.none()); |
| 1662 | + Resource capability = remoteContainer.getCapability(); |
| 1663 | + if ((remoteContainer.getState() == ContainerState.RUNNING || |
| 1664 | + remoteContainer.getState() == ContainerState.NEW) && |
| 1665 | + remoteContainer.getCapability() != null) { |
| 1666 | + Resources.addTo(allocatedResource, remoteContainer.getCapability()); |
| 1667 | + } |
| 1668 | + allocatedContainerResource = allocatedResource; |
1661 | 1669 | } |
1662 | 1670 | } |
1663 | 1671 |
|
1664 | | - allocatedContainerResource = allocatedResource; |
1665 | | - |
1666 | 1672 | List<ContainerStatus> lostContainers = |
1667 | 1673 | findLostContainers(numRemoteRunningContainers, containerStatuses); |
1668 | 1674 | for (ContainerStatus remoteContainer : lostContainers) { |
|
0 commit comments