Example usage for org.apache.hadoop.yarn.factories RecordFactory newRecordInstance

List of usage examples for org.apache.hadoop.yarn.factories RecordFactory newRecordInstance

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.factories RecordFactory newRecordInstance.

Prototype

public <T> T newRecordInstance(Class<T> clazz);

Source Link

Usage

From source file:org.apache.tez.dag.app.launcher.TestTezLocalCacheManager.java

License:Apache License

private static LocalResource createFile(String content) throws IOException {
    FileContext fs = FileContext.getLocalFSFileContext();

    java.nio.file.Path tempFile = Files.createTempFile("test-cache-manager", ".txt");
    File temp = tempFile.toFile();
    temp.deleteOnExit();/*  w ww  .  j  av a 2 s . c om*/
    Path p = new Path("file:///" + tempFile.toAbsolutePath().toString());

    Files.write(tempFile, content.getBytes());

    RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
    LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
    URL yarnUrlFromPath = ConverterUtils.getYarnUrlFromPath(p);
    ret.setResource(yarnUrlFromPath);
    ret.setSize(content.getBytes().length);
    ret.setType(LocalResourceType.FILE);
    ret.setVisibility(LocalResourceVisibility.PRIVATE);
    ret.setTimestamp(fs.getFileStatus(p).getModificationTime());
    return ret;
}