diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java index a02af709116..774ee3f743e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java @@ -1027,10 +1027,6 @@ public void onContainerStarted(ContainerId containerId, } @Override - public void onContainerResourceIncreased( - ContainerId containerId, Resource resource) {} - - @Override public void onStartContainerError(ContainerId containerId, Throwable t) { LOG.error("Failed to start Container " + containerId, t); containers.remove(containerId); @@ -1054,6 +1050,21 @@ public void onStopContainerError(ContainerId containerId, Throwable t) { public void onIncreaseContainerResourceError( ContainerId containerId, Throwable t) {} + @Override + public void onContainerResourceIncreased( + ContainerId containerId, Resource resource) {} + + @Override + public void onUpdateContainerResourceError( + ContainerId containerId, Throwable t) { + + } + + @Override + public void onContainerResourceUpdated(ContainerId containerId, + Resource resource) { + + } } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/NMClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/NMClient.java index c1447ba4a41..9aeeb71c77b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/NMClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/NMClient.java @@ -36,6 +36,8 @@ import org.apache.hadoop.yarn.client.api.impl.NMClientImpl; import org.apache.hadoop.yarn.exceptions.YarnException; +import javax.ws.rs.DELETE; + @InterfaceAudience.Public @InterfaceStability.Stable public abstract class NMClient extends AbstractService { @@ -104,10 +106,28 @@ protected NMClient(String name) { * @throws YarnException YarnException. * @throws IOException IOException. */ + @Deprecated public abstract void increaseContainerResource(Container container) throws YarnException, IOException; /** + *
Update the resources of a container.
+ * + *The ApplicationMaster or other applications that use the
+ * client must provide the details of the container, including the Id and
+ * the target resource encapsulated in the updated container token via
+ * {@link Container}.
+ *
Stop an started container.
* * @param containerId the Id of the started container diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/NMClientAsync.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/NMClientAsync.java index c94942ae903..a5f29282197 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/NMClientAsync.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/NMClientAsync.java @@ -38,6 +38,8 @@ import com.google.common.annotations.VisibleForTesting; +import javax.ws.rs.DELETE; + /** *NMClientAsync handles communication with all the NodeManagers
* and provides asynchronous updates on getting responses from them. It
@@ -177,9 +179,23 @@ protected NMClientAsync(String name, NMClient client,
public abstract void startContainerAsync(
Container container, ContainerLaunchContext containerLaunchContext);
+ @Deprecated
public abstract void increaseContainerResourceAsync(Container container);
/**
+ * Update the resources of a container.
+ * + *The ApplicationMaster or other applications that use the
+ * client must provide the details of the container, including the Id and
+ * the target resource encapsulated in the updated container token via
+ * {@link Container}.
+ *
Re-Initialize the Container.
* * @param containerId the Id of the container to Re-Initialize. @@ -301,10 +317,21 @@ public abstract void onStartContainerError( * @param containerId the Id of the container * @param resource the target resource of the container */ + @Deprecated public abstract void onContainerResourceIncreased( ContainerId containerId, Resource resource); /** + * The API is called whenNodeManager responds to indicate
+ * the container resource has been successfully updated.
+ *
+ * @param containerId the Id of the container
+ * @param resource the target resource of the container
+ */
+ public abstract void onContainerResourceUpdated(
+ ContainerId containerId, Resource resource);
+
+ /**
* The API is called when an exception is raised in the process of
* querying the status of a container.
*
@@ -321,11 +348,22 @@ public abstract void onGetContainerStatusError(
* @param containerId the Id of the container
* @param t the raised exception
*/
+ @Deprecated
public abstract void onIncreaseContainerResourceError(
ContainerId containerId, Throwable t);
/**
* The API is called when an exception is raised in the process of
+ * updating container resource.
+ *
+ * @param containerId the Id of the container
+ * @param t the raised exception
+ */
+ public abstract void onUpdateContainerResourceError(
+ ContainerId containerId, Throwable t);
+
+ /**
+ * The API is called when an exception is raised in the process of
* stopping a container.
*
* @param containerId the Id of the container
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/impl/NMClientAsyncImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/impl/NMClientAsyncImpl.java
index 20be71eaa71..2b3d1026da6 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/impl/NMClientAsyncImpl.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/async/impl/NMClientAsyncImpl.java
@@ -267,18 +267,42 @@ public void increaseContainerResourceAsync(Container container) {
}
AbstractCallbackHandler handler = (AbstractCallbackHandler) callbackHandler;
if (containers.get(container.getId()) == null) {
- handler.onIncreaseContainerResourceError(
+ handler.onUpdateContainerResourceError(
container.getId(),
RPCUtil.getRemoteException(
"Container " + container.getId() +
" is neither started nor scheduled to start"));
}
try {
- events.put(new IncreaseContainerResourceEvent(container));
+ events.put(new UpdateContainerResourceEvent(container));
} catch (InterruptedException e) {
LOG.warn("Exception when scheduling the event of increasing resource of "
+ "Container " + container.getId());
- handler.onIncreaseContainerResourceError(container.getId(), e);
+ handler.onUpdateContainerResourceError(container.getId(), e);
+ }
+ }
+
+ @Override
+ public void updateContainerResourceAsync(Container container) {
+ if (!(callbackHandler instanceof AbstractCallbackHandler)) {
+ LOG.error("Callback handler does not implement container resource "
+ + "increase callback methods");
+ return;
+ }
+ AbstractCallbackHandler handler = (AbstractCallbackHandler) callbackHandler;
+ if (containers.get(container.getId()) == null) {
+ handler.onUpdateContainerResourceError(
+ container.getId(),
+ RPCUtil.getRemoteException(
+ "Container " + container.getId() +
+ " is neither started nor scheduled to start"));
+ }
+ try {
+ events.put(new UpdateContainerResourceEvent(container));
+ } catch (InterruptedException e) {
+ LOG.warn("Exception when scheduling the event of increasing resource of "
+ + "Container " + container.getId());
+ handler.onUpdateContainerResourceError(container.getId(), e);
}
}
@@ -427,7 +451,7 @@ protected ContainerEventProcessor getContainerEventProcessor(
START_CONTAINER,
STOP_CONTAINER,
QUERY_CONTAINER,
- INCREASE_CONTAINER_RESOURCE,
+ UPDATE_CONTAINER_RESOURCE,
REINITIALIZE_CONTAINER,
RESTART_CONTAINER,
ROLLBACK_LAST_REINIT,
@@ -503,13 +527,13 @@ public boolean isAutoCommit() {
}
}
- protected static class IncreaseContainerResourceEvent extends ContainerEvent {
+ protected static class UpdateContainerResourceEvent extends ContainerEvent {
private Container container;
- public IncreaseContainerResourceEvent(Container container) {
+ public UpdateContainerResourceEvent(Container container) {
super(container.getId(), container.getNodeId(),
container.getContainerToken(),
- ContainerEventType.INCREASE_CONTAINER_RESOURCE);
+ ContainerEventType.UPDATE_CONTAINER_RESOURCE);
this.container = container;
}
@@ -536,8 +560,8 @@ public Container getContainer() {
// Transitions from RUNNING state
.addTransition(ContainerState.RUNNING, ContainerState.RUNNING,
- ContainerEventType.INCREASE_CONTAINER_RESOURCE,
- new IncreaseContainerResourceTransition())
+ ContainerEventType.UPDATE_CONTAINER_RESOURCE,
+ new UpdateContainerResourceTransition())
// Transitions for Container Upgrade
.addTransition(ContainerState.RUNNING,
@@ -566,7 +590,7 @@ public Container getContainer() {
.addTransition(ContainerState.DONE, ContainerState.DONE,
EnumSet.of(ContainerEventType.START_CONTAINER,
ContainerEventType.STOP_CONTAINER,
- ContainerEventType.INCREASE_CONTAINER_RESOURCE))
+ ContainerEventType.UPDATE_CONTAINER_RESOURCE))
// Transition from FAILED state
.addTransition(ContainerState.FAILED, ContainerState.FAILED,
@@ -576,7 +600,7 @@ public Container getContainer() {
ContainerEventType.RESTART_CONTAINER,
ContainerEventType.COMMIT_LAST_REINT,
ContainerEventType.ROLLBACK_LAST_REINIT,
- ContainerEventType.INCREASE_CONTAINER_RESOURCE));
+ ContainerEventType.UPDATE_CONTAINER_RESOURCE));
protected static class StartContainerTransition implements
MultipleArcTransition