001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.apache.hadoop.yarn.api.records;
020
021 import org.apache.hadoop.classification.InterfaceAudience.Public;
022 import org.apache.hadoop.classification.InterfaceStability.Stable;
023 import org.apache.hadoop.yarn.api.ContainerManagementProtocol;
024 import org.apache.hadoop.yarn.util.Records;
025
026 /**
027 * <p><code>LocalResource</code> represents a local resource required to
028 * run a container.</p>
029 *
030 * <p>The <code>NodeManager</code> is responsible for localizing the resource
031 * prior to launching the container.</p>
032 *
033 * <p>Applications can specify {@link LocalResourceType} and
034 * {@link LocalResourceVisibility}.</p>
035 *
036 * @see LocalResourceType
037 * @see LocalResourceVisibility
038 * @see ContainerLaunchContext
039 * @see ApplicationSubmissionContext
040 * @see ContainerManagementProtocol#startContainers(org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)
041 */
042 @Public
043 @Stable
044 public abstract class LocalResource {
045
046 @Public
047 @Stable
048 public static LocalResource newInstance(URL url, LocalResourceType type,
049 LocalResourceVisibility visibility, long size, long timestamp,
050 String pattern) {
051 LocalResource resource = Records.newRecord(LocalResource.class);
052 resource.setResource(url);
053 resource.setType(type);
054 resource.setVisibility(visibility);
055 resource.setSize(size);
056 resource.setTimestamp(timestamp);
057 resource.setPattern(pattern);
058 return resource;
059 }
060
061 @Public
062 @Stable
063 public static LocalResource newInstance(URL url, LocalResourceType type,
064 LocalResourceVisibility visibility, long size, long timestamp) {
065 return newInstance(url, type, visibility, size, timestamp, null);
066 }
067
068 /**
069 * Get the <em>location</em> of the resource to be localized.
070 * @return <em>location</em> of the resource to be localized
071 */
072 @Public
073 @Stable
074 public abstract URL getResource();
075
076 /**
077 * Set <em>location</em> of the resource to be localized.
078 * @param resource <em>location</em> of the resource to be localized
079 */
080 @Public
081 @Stable
082 public abstract void setResource(URL resource);
083
084 /**
085 * Get the <em>size</em> of the resource to be localized.
086 * @return <em>size</em> of the resource to be localized
087 */
088 @Public
089 @Stable
090 public abstract long getSize();
091
092 /**
093 * Set the <em>size</em> of the resource to be localized.
094 * @param size <em>size</em> of the resource to be localized
095 */
096 @Public
097 @Stable
098 public abstract void setSize(long size);
099
100 /**
101 * Get the original <em>timestamp</em> of the resource to be localized, used
102 * for verification.
103 * @return <em>timestamp</em> of the resource to be localized
104 */
105 @Public
106 @Stable
107 public abstract long getTimestamp();
108
109 /**
110 * Set the <em>timestamp</em> of the resource to be localized, used
111 * for verification.
112 * @param timestamp <em>timestamp</em> of the resource to be localized
113 */
114 @Public
115 @Stable
116 public abstract void setTimestamp(long timestamp);
117
118 /**
119 * Get the <code>LocalResourceType</code> of the resource to be localized.
120 * @return <code>LocalResourceType</code> of the resource to be localized
121 */
122 @Public
123 @Stable
124 public abstract LocalResourceType getType();
125
126 /**
127 * Set the <code>LocalResourceType</code> of the resource to be localized.
128 * @param type <code>LocalResourceType</code> of the resource to be localized
129 */
130 @Public
131 @Stable
132 public abstract void setType(LocalResourceType type);
133
134 /**
135 * Get the <code>LocalResourceVisibility</code> of the resource to be
136 * localized.
137 * @return <code>LocalResourceVisibility</code> of the resource to be
138 * localized
139 */
140 @Public
141 @Stable
142 public abstract LocalResourceVisibility getVisibility();
143
144 /**
145 * Set the <code>LocalResourceVisibility</code> of the resource to be
146 * localized.
147 * @param visibility <code>LocalResourceVisibility</code> of the resource to be
148 * localized
149 */
150 @Public
151 @Stable
152 public abstract void setVisibility(LocalResourceVisibility visibility);
153
154 /**
155 * Get the <em>pattern</em> that should be used to extract entries from the
156 * archive (only used when type is <code>PATTERN</code>).
157 * @return <em>pattern</em> that should be used to extract entries from the
158 * archive.
159 */
160 @Public
161 @Stable
162 public abstract String getPattern();
163
164 /**
165 * Set the <em>pattern</em> that should be used to extract entries from the
166 * archive (only used when type is <code>PATTERN</code>).
167 * @param pattern <em>pattern</em> that should be used to extract entries
168 * from the archive.
169 */
170 @Public
171 @Stable
172 public abstract void setPattern(String pattern);
173 }