本文整理汇总了Java中org.apache.hadoop.yarn.api.records.LocalResource.setResource方法的典型用法代码示例。如果您正苦于以下问题:Java LocalResource.setResource方法的具体用法?Java LocalResource.setResource怎么用?Java LocalResource.setResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.yarn.api.records.LocalResource
的用法示例。
在下文中一共展示了LocalResource.setResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
public void addResource(FileSystem fs, Configuration conf, Path destPath,
Map<String, LocalResource> localResources, LocalResourceType resourceType, String link,
Map<URI, FileStatus> statCache, boolean appMasterOnly) throws IOException {
FileStatus destStatus = fs.getFileStatus(destPath);
LocalResource amJarRsrc = Records.newRecord(LocalResource.class);
amJarRsrc.setType(resourceType);
LocalResourceVisibility visibility = getVisibility(conf, destPath.toUri(), statCache);
amJarRsrc.setVisibility(visibility);
amJarRsrc.setResource(ConverterUtils.getYarnUrlFromPath(destPath));
amJarRsrc.setTimestamp(destStatus.getModificationTime());
amJarRsrc.setSize(destStatus.getLen());
if (link == null || link.isEmpty())
throw new IOException("You must specify a valid link name");
localResources.put(link, amJarRsrc);
}
示例2: createJar
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
static LocalResource createJar(FileContext files, Path p,
LocalResourceVisibility vis) throws IOException {
LOG.info("Create jar file " + p);
File jarFile = new File((files.makeQualified(p)).toUri());
FileOutputStream stream = new FileOutputStream(jarFile);
LOG.info("Create jar out stream ");
JarOutputStream out = new JarOutputStream(stream, new Manifest());
LOG.info("Done writing jar stream ");
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(p));
FileStatus status = files.getFileStatus(p);
ret.setSize(status.getLen());
ret.setTimestamp(status.getModificationTime());
ret.setType(LocalResourceType.PATTERN);
ret.setVisibility(vis);
ret.setPattern("classes/.*");
return ret;
}
示例3: createJarFile
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
static LocalResource createJarFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File archiveFile = new File(p.toUri().getPath() + ".jar");
archiveFile.createNewFile();
JarOutputStream out = new JarOutputStream(
new FileOutputStream(archiveFile));
out.putNextEntry(new JarEntry(p.getName()));
out.write(bytes);
out.closeEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".jar")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".jar"))
.getModificationTime());
return ret;
}
示例4: createZipFile
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
static LocalResource createZipFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File archiveFile = new File(p.toUri().getPath() + ".ZIP");
archiveFile.createNewFile();
ZipOutputStream out = new ZipOutputStream(
new FileOutputStream(archiveFile));
out.putNextEntry(new ZipEntry(p.getName()));
out.write(bytes);
out.closeEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".ZIP")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".ZIP"))
.getModificationTime());
return ret;
}
示例5: setupEsZipResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
private Map<String, LocalResource> setupEsZipResource(Config conf) {
// elasticsearch.zip
Map<String, LocalResource> resources = new LinkedHashMap<String, LocalResource>();
LocalResource esZip = Records.newRecord(LocalResource.class);
String esZipHdfsPath = conf.esZipHdfsPath();
Path p = new Path(esZipHdfsPath);
FileStatus fsStat;
try {
fsStat = FileSystem.get(cfg).getFileStatus(p);
} catch (IOException ex) {
throw new IllegalArgumentException(
String.format("Cannot find Elasticsearch zip at [%s]; make sure the artifacts have been properly provisioned and the correct permissions are in place.", esZipHdfsPath), ex);
}
// use the normalized path as otherwise YARN chokes down the line
esZip.setResource(ConverterUtils.getYarnUrlFromPath(fsStat.getPath()));
esZip.setSize(fsStat.getLen());
esZip.setTimestamp(fsStat.getModificationTime());
esZip.setType(LocalResourceType.ARCHIVE);
esZip.setVisibility(LocalResourceVisibility.PUBLIC);
resources.put(conf.esZipName(), esZip);
return resources;
}
示例6: setupEsYarnJar
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
private Map<String, LocalResource> setupEsYarnJar() {
Map<String, LocalResource> resources = new LinkedHashMap<String, LocalResource>();
LocalResource esYarnJar = Records.newRecord(LocalResource.class);
Path p = new Path(clientCfg.jarHdfsPath());
FileStatus fsStat;
try {
fsStat = FileSystem.get(client.getConfiguration()).getFileStatus(p);
} catch (IOException ex) {
throw new IllegalArgumentException(
String.format("Cannot find jar [%s]; make sure the artifacts have been properly provisioned and the correct permissions are in place.", clientCfg.jarHdfsPath()), ex);
}
// use the normalized path as otherwise YARN chokes down the line
esYarnJar.setResource(ConverterUtils.getYarnUrlFromPath(fsStat.getPath()));
esYarnJar.setSize(fsStat.getLen());
esYarnJar.setTimestamp(fsStat.getModificationTime());
esYarnJar.setType(LocalResourceType.FILE);
esYarnJar.setVisibility(LocalResourceVisibility.PUBLIC);
resources.put(clientCfg.jarName(), esYarnJar);
return resources;
}
示例7: createApplicationResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
private LocalResource createApplicationResource(FileContext fs, Path p, LocalResourceType type) throws IOException {
LocalResource rsrc = recordFactory.newRecordInstance(LocalResource.class);
FileStatus rsrcStat = fs.getFileStatus(p);
rsrc.setResource(ConverterUtils.getYarnUrlFromPath(fs.getDefaultFileSystem().resolvePath(rsrcStat.getPath())));
rsrc.setSize(rsrcStat.getLen());
rsrc.setTimestamp(rsrcStat.getModificationTime());
rsrc.setType(type);
rsrc.setVisibility(LocalResourceVisibility.APPLICATION);
return rsrc;
}
示例8: createFile
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
static LocalResource createFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException {
createFile(files, p, len, r);
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(p));
ret.setSize(len);
ret.setType(LocalResourceType.FILE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(p).getModificationTime());
return ret;
}
示例9: createTarFile
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
static LocalResource createTarFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File archiveFile = new File(p.toUri().getPath() + ".tar");
archiveFile.createNewFile();
TarArchiveOutputStream out = new TarArchiveOutputStream(
new FileOutputStream(archiveFile));
TarArchiveEntry entry = new TarArchiveEntry(p.getName());
entry.setSize(bytes.length);
out.putArchiveEntry(entry);
out.write(bytes);
out.closeArchiveEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".tar")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".tar"))
.getModificationTime());
return ret;
}
示例10: createTgzFile
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
static LocalResource createTgzFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File gzipFile = new File(p.toUri().getPath() + ".tar.gz");
gzipFile.createNewFile();
TarArchiveOutputStream out = new TarArchiveOutputStream(
new GZIPOutputStream(new FileOutputStream(gzipFile)));
TarArchiveEntry entry = new TarArchiveEntry(p.getName());
entry.setSize(bytes.length);
out.putArchiveEntry(entry);
out.write(bytes);
out.closeArchiveEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".tar.gz")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".tar.gz"))
.getModificationTime());
return ret;
}
示例11: newLocalResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
public static LocalResource newLocalResource(URL url, LocalResourceType type,
LocalResourceVisibility visibility, long size, long timestamp,
boolean shouldBeUploadedToSharedCache) {
LocalResource resource =
recordFactory.newRecordInstance(LocalResource.class);
resource.setResource(url);
resource.setType(type);
resource.setVisibility(visibility);
resource.setSize(size);
resource.setTimestamp(timestamp);
resource.setShouldBeUploadedToSharedCache(shouldBeUploadedToSharedCache);
return resource;
}
示例12: createResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
static LocalResource createResource() {
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
assertTrue(ret instanceof LocalResourcePBImpl);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(
"hdfs://y.ak:8020/foo/bar")));
ret.setSize(4344L);
ret.setTimestamp(3141592653589793L);
ret.setVisibility(LocalResourceVisibility.PUBLIC);
return ret;
}
示例13: createApplicationResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
private LocalResource createApplicationResource(FileContext fs, Path p, LocalResourceType type)
throws IOException {
LocalResource rsrc = recordFactory.newRecordInstance(LocalResource.class);
FileStatus rsrcStat = fs.getFileStatus(p);
rsrc.setResource(ConverterUtils.getYarnUrlFromPath(fs
.getDefaultFileSystem().resolvePath(rsrcStat.getPath())));
rsrc.setSize(rsrcStat.getLen());
rsrc.setTimestamp(rsrcStat.getModificationTime());
rsrc.setType(type);
rsrc.setVisibility(LocalResourceVisibility.APPLICATION);
return rsrc;
}
示例14: addResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
public static void addResource(YarnConfiguration conf, Map<String, LocalResource> resources, Path path) throws IOException {
LocalResource res = Records.newRecord(LocalResource.class);
FileStatus stat = FileSystem.get(conf).getFileStatus(path);
res.setResource(ConverterUtils.getYarnUrlFromPath(path));
res.setSize(stat.getLen());
res.setTimestamp(stat.getModificationTime());
res.setType(LocalResourceType.FILE);
res.setVisibility(LocalResourceVisibility.APPLICATION);
resources.put(path.getName(), res);
}
示例15: registerLocalResource
import org.apache.hadoop.yarn.api.records.LocalResource; //导入方法依赖的package包/类
private static LocalResource registerLocalResource(FileSystem fs, Path remoteRsrcPath) throws IOException {
LocalResource localResource = Records.newRecord(LocalResource.class);
FileStatus jarStat = fs.getFileStatus(remoteRsrcPath);
localResource.setResource(ConverterUtils.getYarnUrlFromURI(remoteRsrcPath.toUri()));
localResource.setSize(jarStat.getLen());
localResource.setTimestamp(jarStat.getModificationTime());
localResource.setType(LocalResourceType.FILE);
localResource.setVisibility(LocalResourceVisibility.APPLICATION);
return localResource;
}