All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.yarn.api.records.Container Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
/**
* 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.Private;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.classification.InterfaceStability.Stable;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.api.ApplicationMasterProtocol;
import org.apache.hadoop.yarn.api.ContainerManagementProtocol;
import org.apache.hadoop.yarn.util.Records;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * {@code Container} represents an allocated resource in the cluster.
 * 

* The {@code ResourceManager} is the sole authority to allocate any * {@code Container} to applications. The allocated {@code Container} * is always on a single node and has a unique {@link ContainerId}. It has * a specific amount of {@link Resource} allocated. *

* It includes details such as: *

    *
  • {@link ContainerId} for the container, which is globally unique.
  • *
  • * {@link NodeId} of the node on which it is allocated. *
  • *
  • HTTP uri of the node.
  • *
  • {@link Resource} allocated to the container.
  • *
  • {@link Priority} at which the container was allocated.
  • *
  • * Container {@link Token} of the container, used to securely verify * authenticity of the allocation. *
  • *
* * Typically, an {@code ApplicationMaster} receives the {@code Container} * from the {@code ResourceManager} during resource-negotiation and then * talks to the {@code NodeManager} to start/stop containers. * * @see ApplicationMasterProtocol#allocate(org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest) * @see ContainerManagementProtocol#startContainers(org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest) * @see ContainerManagementProtocol#stopContainers(org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest) */ @Public @Stable public abstract class Container implements Comparable { @Private @Unstable public static Container newInstance(ContainerId containerId, NodeId nodeId, String nodeHttpAddress, Resource resource, Priority priority, Token containerToken) { return newInstance(containerId, nodeId, nodeHttpAddress, resource, priority, containerToken, ExecutionType.GUARANTEED); } @Private @Unstable public static Container newInstance(ContainerId containerId, NodeId nodeId, String nodeHttpAddress, Resource resource, Priority priority, Token containerToken, ExecutionType executionType) { Container container = Records.newRecord(Container.class); container.setId(containerId); container.setNodeId(nodeId); container.setNodeHttpAddress(nodeHttpAddress); container.setResource(resource); container.setPriority(priority); container.setContainerToken(containerToken); container.setExecutionType(executionType); return container; } /** * Get the globally unique identifier for the container. * @return globally unique identifier for the container */ @Public @Stable public abstract ContainerId getId(); @Private @Unstable public abstract void setId(ContainerId id); /** * Get the identifier of the node on which the container is allocated. * @return identifier of the node on which the container is allocated */ @Public @Stable public abstract NodeId getNodeId(); @Private @Unstable public abstract void setNodeId(NodeId nodeId); /** * Get the http uri of the node on which the container is allocated. * @return http uri of the node on which the container is allocated */ @Public @Stable public abstract String getNodeHttpAddress(); @Private @Unstable public abstract void setNodeHttpAddress(String nodeHttpAddress); /** * Get the exposed ports of the node on which the container is allocated. * @return exposed ports of the node on which the container is allocated */ @Public @Stable public abstract Map>> getExposedPorts(); @Private @Unstable public abstract void setExposedPorts( Map>> ports); /** * Get the Resource allocated to the container. * @return Resource allocated to the container */ @Public @Stable public abstract Resource getResource(); @Private @Unstable public abstract void setResource(Resource resource); /** * Get the Priority at which the Container was * allocated. * @return Priority at which the Container was * allocated */ @Public @Stable public abstract Priority getPriority(); @Private @Unstable public abstract void setPriority(Priority priority); /** * Get the ContainerToken for the container. *

ContainerToken is the security token used by the framework * to verify authenticity of any Container.

* *

The ResourceManager, on container allocation provides a * secure token which is verified by the NodeManager on * container launch.

* *

Applications do not need to care about ContainerToken, they * are transparently handled by the framework - the allocated * Container includes the ContainerToken.

* * @see ApplicationMasterProtocol#allocate(org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest) * @see ContainerManagementProtocol#startContainers(org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest) * * @return ContainerToken for the container */ @Public @Stable public abstract Token getContainerToken(); @Private @Unstable public abstract void setContainerToken(Token containerToken); /** * Get the ExecutionType for the container. * @return ExecutionType for the container. */ @Private @Unstable public abstract ExecutionType getExecutionType(); /** * Set the ExecutionType for the container. * @param executionType ExecutionType */ @Private @Unstable public abstract void setExecutionType(ExecutionType executionType); /** * Get the optional ID corresponding to the original {@code * ResourceRequest{@link #getAllocationRequestId()}}s which is satisfied by * this allocated {@code Container}. *

* The scheduler may return multiple {@code AllocateResponse}s corresponding * to the same ID as and when scheduler allocates {@code Container}s. * Applications can continue to completely ignore the returned ID in * the response and use the allocation for any of their outstanding requests. *

* * @return the ID corresponding to the original allocation request * which is satisfied by this allocation. */ @Public @Evolving public long getAllocationRequestId() { throw new UnsupportedOperationException(); } /** * Set the optional ID corresponding to the original {@code * ResourceRequest{@link #setAllocationRequestId(long)} * etAllocationRequestId()}}s which is satisfied by this allocated {@code * Container}. *

* The scheduler may return multiple {@code AllocateResponse}s corresponding * to the same ID as and when scheduler allocates {@code Container}s. * Applications can continue to completely ignore the returned ID in * the response and use the allocation for any of their outstanding requests. * If the ID is not set, scheduler will continue to work as previously and all * allocated {@code Container}(s) will have the default ID, -1. *

* * @param allocationRequestID the ID corresponding to the original * allocation request which is satisfied by this * allocation. */ @Private @Unstable public void setAllocationRequestId(long allocationRequestID) { throw new UnsupportedOperationException(); } /** * Get the version of this container. The version will be incremented when * a container is updated. * * @return version of this container. */ @Private @Unstable public int getVersion() { return 0; } /** * Set the version of this container. * @param version of this container. */ @Private @Unstable public void setVersion(int version) { throw new UnsupportedOperationException(); } @Private @Unstable public Set getAllocationTags() { return Collections.emptySet(); } @Private @Unstable public void setAllocationTags(Set allocationTags) { } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy