private List<UpdateContainerRequest> createUpdateList() { List<UpdateContainerRequest> updateList = new ArrayList<>(); for (Map.Entry<ContainerId, SimpleEntry<Container, Resource>> entry : change.entrySet()) { Resource targetCapability = entry.getValue().getValue(); Resource currCapability = entry.getValue().getKey().getResource(); int version = entry.getValue().getKey().getVersion(); ContainerUpdateType updateType = ContainerUpdateType.INCREASE_RESOURCE; if (Resources.fitsIn(targetCapability, currCapability)) { updateType = ContainerUpdateType.DECREASE_RESOURCE; } updateList.add( UpdateContainerRequest.newInstance(version, entry.getKey(), updateType, targetCapability)); } return updateList; }
private List<UpdateContainerRequest> createUpdateList() { List<UpdateContainerRequest> updateList = new ArrayList<>(); for (Map.Entry<ContainerId, SimpleEntry<Container, UpdateContainerRequest>> entry : change.entrySet()) { Resource targetCapability = entry.getValue().getValue().getCapability(); ExecutionType targetExecType = entry.getValue().getValue().getExecutionType(); ContainerUpdateType updateType = entry.getValue().getValue().getContainerUpdateType(); int version = entry.getValue().getKey().getVersion(); updateList.add( UpdateContainerRequest.newInstance(version, entry.getKey(), updateType, targetCapability, targetExecType)); } return updateList; }
private static String validateContainerIdAndVersion( Set<ContainerId> outstandingUpdate, UpdateContainerRequest updateReq, RMContainer rmContainer) { String msg = null; if (rmContainer == null) { msg = INVALID_CONTAINER_ID; } // Only allow updates if the requested version matches the current // version if (msg == null && updateReq.getContainerVersion() != rmContainer.getContainer().getVersion()) { msg = INCORRECT_CONTAINER_VERSION_ERROR; } // No more than 1 container update per request. if (msg == null && outstandingUpdate.contains(updateReq.getContainerId())) { msg = UPDATE_OUTSTANDING_ERROR; } return msg; }
"UpdateContainerRequest cannot be null!!"); requestContainerUpdate(container, UpdateContainerRequest.newInstance( container.getVersion(), container.getId(), Resources.fitsIn(capability, container.getResource()) ? ContainerUpdateType.DECREASE_RESOURCE :
"UpdateContainerRequest cannot be null!!"); requestContainerUpdate(container, UpdateContainerRequest.newInstance( container.getVersion(), container.getId(), Resources.fitsIn(capability, container.getResource()) ? ContainerUpdateType.DECREASE_RESOURCE :
@Override public void onContainerStatusReceived(ContainerId containerId, ContainerStatus containerStatus) { if (LOG.isDebugEnabled()) { LOG.debug("Container Status: id=" + containerId + ", status=" + containerStatus); } // If promote_opportunistic_after_start is set, automatically promote // opportunistic containers to guaranteed. if (autoPromoteContainers) { if (containerStatus.getState() == ContainerState.RUNNING) { Container container = containers.get(containerId); if (container.getExecutionType() == ExecutionType.OPPORTUNISTIC) { // Promote container LOG.info("Promoting container {} to {}", container.getId(), container.getExecutionType()); UpdateContainerRequest updateRequest = UpdateContainerRequest .newInstance(container.getVersion(), container.getId(), ContainerUpdateType.PROMOTE_EXECUTION_TYPE, null, ExecutionType.GUARANTEED); amRMClient.requestContainerUpdate(container, updateRequest); } } } }
private static void checkAndcreateUpdateError( List<UpdateContainerError> errors, UpdateContainerRequest updateReq, RMContainer rmContainer, String msg) { if (msg != null) { UpdateContainerError updateError = RECORD_FACTORY .newRecordInstance(UpdateContainerError.class); updateError.setReason(msg); updateError.setUpdateContainerRequest(updateReq); if (rmContainer != null) { updateError.setCurrentContainerVersion( rmContainer.getContainer().getVersion()); } else { updateError.setCurrentContainerVersion(-1); } errors.add(updateError); } }
/** * Rollback container update after expiry. * @param containerId ContainerId. */ protected void rollbackContainerUpdate( ContainerId containerId) { RMContainer rmContainer = getRMContainer(containerId); if (rmContainer == null) { LOG.info("Cannot rollback resource for container " + containerId + ". The container does not exist."); return; } T app = getCurrentAttemptForContainer(containerId); if (getCurrentAttemptForContainer(containerId) == null) { LOG.info("Cannot rollback resource for container " + containerId + ". The application that the container " + "belongs to does not exist."); return; } if (Resources.fitsIn(rmContainer.getLastConfirmedResource(), rmContainer.getContainer().getResource())) { LOG.info("Roll back resource for container " + containerId); handleDecreaseRequests(app, Arrays.asList( UpdateContainerRequest.newInstance( rmContainer.getContainer().getVersion(), rmContainer.getContainerId(), ContainerUpdateType.DECREASE_RESOURCE, rmContainer.getLastConfirmedResource(), null))); } }
try { changeContainerResourceInternal(container.getId(), container.getVersion(), container.getResource(), false); } catch (YarnException e) { LOG.error("Unable to decrease container resource", e);
.thenReturn(rmContainer); Container container = Mockito.mock(Container.class); Mockito.when(container.getVersion()).thenReturn(containerVersion); Mockito.when(rmContainer.getContainer()).thenReturn(container); Mockito.when(scheduler.getNormalizedResource(capabilityOk, maxAllocation))
ContainerType containerType = ContainerType.TASK; if (updateType != null) { container.setVersion(container.getVersion() + 1); .createContainerToken(container.getId(), container.getVersion(), container.getNodeId(), getUser(), container.getResource(), container.getPriority(), rmContainer.getCreationTime(),
private RMContainer createDemotedRMContainer( SchedulerApplicationAttempt appAttempt, OpportunisticContainerContext oppCntxt, RMContainer rmContainer) { SchedulerRequestKey sk = SchedulerRequestKey.extractFrom(rmContainer.getContainer()); Container demotedContainer = BuilderUtils.newContainer( ContainerId.newContainerId(appAttempt.getApplicationAttemptId(), oppCntxt.getContainerIdGenerator().generateContainerId()), rmContainer.getContainer().getNodeId(), rmContainer.getContainer().getNodeHttpAddress(), rmContainer.getContainer().getResource(), sk.getPriority(), null, ExecutionType.OPPORTUNISTIC, sk.getAllocationRequestId()); demotedContainer.setVersion(rmContainer.getContainer().getVersion()); return SchedulerUtils.createOpportunisticRmContainer( rmContext, demotedContainer, false); }
Assert.assertEquals(ExecutionType.GUARANTEED, uc.getExecutionType()); Assert.assertEquals(uc.getId(), container.getId()); Assert.assertEquals(uc.getVersion(), container.getVersion() + 1); Arrays.asList(UpdateContainerRequest.newInstance(uc.getVersion(), uc.getId(), ContainerUpdateType.DEMOTE_EXECUTION_TYPE, null, ExecutionType.OPPORTUNISTIC))); Assert.assertEquals(ExecutionType.OPPORTUNISTIC, uc.getExecutionType()); Assert.assertEquals(uc.getId(), container.getId()); Assert.assertEquals(uc.getVersion(), container.getVersion() + 2);
private RMContainer createDecreasedRMContainer( SchedulerApplicationAttempt appAttempt, UpdateContainerRequest uReq, RMContainer rmContainer) { SchedulerRequestKey sk = SchedulerRequestKey.extractFrom(rmContainer.getContainer()); Container decreasedContainer = BuilderUtils.newContainer( ContainerId.newContainerId(appAttempt.getApplicationAttemptId(), appAttempt.getNewContainerId()), rmContainer.getContainer().getNodeId(), rmContainer.getContainer().getNodeHttpAddress(), Resources.none(), sk.getPriority(), null, rmContainer.getExecutionType(), sk.getAllocationRequestId()); decreasedContainer.setVersion(rmContainer.getContainer().getVersion()); RMContainer newRmContainer = new RMContainerImpl(decreasedContainer, sk, appAttempt.getApplicationAttemptId(), decreasedContainer.getNodeId(), appAttempt.getUser(), rmContext, rmContainer.isRemotelyAllocated()); appAttempt.addRMContainer(decreasedContainer.getId(), rmContainer); ((AbstractYarnScheduler) rmContext.getScheduler()).getNode( decreasedContainer.getNodeId()).allocateContainer(newRmContainer); return newRmContainer; }
newContainer.setAllocationRequestId( existingRMContainer.getContainer().getAllocationRequestId()); newContainer.setVersion(existingRMContainer.getContainer().getVersion());
Assert.assertEquals(ExecutionType.GUARANTEED, uc.getExecutionType()); Assert.assertEquals(uc.getId(), container.getId()); Assert.assertEquals(uc.getVersion(), container.getVersion() + 1);