Search in sources :

Example 16 with Path

use of edu.iu.dsc.tws.api.data.Path in project twister2 by DSC-SPIDAL.

the class TestBinaryFileFormatter method main.

public static void main(String[] args) {
    Config.Builder builder = new Config.Builder();
    builder.put("input.file.path", "/tmp/2000.bin");
    builder.put("RECORD_LENGTH", 1000 * Short.BYTES);
    Config txtFileConf = builder.build();
    Path path = new Path("/tmp/2000.bin");
    InputPartitioner binaryInputPartitioner = new BinaryInputPartitioner(path, 1000 * Short.BYTES);
    binaryInputPartitioner.configure(txtFileConf);
    int count = 0;
    int minSplits = 4;
    double expectedSum = 1.6375350724E1;
    double newSum = 0.0;
    Buffer buffer;
    try {
        InputSplit[] inputSplits = binaryInputPartitioner.createInputSplits(minSplits);
        InputSplitAssigner inputSplitAssigner = binaryInputPartitioner.getInputSplitAssigner(inputSplits);
        InputSplit currentSplit;
        byte[] line = new byte[2000];
        ByteBuffer byteBuffer = ByteBuffer.allocate(2000);
        byteBuffer.order(ByteOrder.BIG_ENDIAN);
        while ((currentSplit = inputSplitAssigner.getNextInputSplit("localhost", 0)) != null) {
            currentSplit.open(txtFileConf);
            while (currentSplit.nextRecord(line) != null) {
                byteBuffer.clear();
                byteBuffer.put(line);
                byteBuffer.flip();
                buffer = byteBuffer.asShortBuffer();
                short[] shortArray = new short[1000];
                ((ShortBuffer) buffer).get(shortArray);
                for (short i : shortArray) {
                    newSum += i;
                    count++;
                }
            }
        }
        LOG.info("Sum and count values are:" + newSum + "\t" + count);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) Buffer(java.nio.Buffer) ShortBuffer(java.nio.ShortBuffer) ByteBuffer(java.nio.ByteBuffer) InputSplitAssigner(edu.iu.dsc.tws.data.fs.io.InputSplitAssigner) Config(edu.iu.dsc.tws.api.config.Config) BinaryInputPartitioner(edu.iu.dsc.tws.data.api.formatters.BinaryInputPartitioner) ByteBuffer(java.nio.ByteBuffer) InputSplit(edu.iu.dsc.tws.data.fs.io.InputSplit) ShortBuffer(java.nio.ShortBuffer) InputPartitioner(edu.iu.dsc.tws.data.api.InputPartitioner) BinaryInputPartitioner(edu.iu.dsc.tws.data.api.formatters.BinaryInputPartitioner)

Example 17 with Path

use of edu.iu.dsc.tws.api.data.Path in project twister2 by DSC-SPIDAL.

the class LocalFileSystem method open.

@Override
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
    Path directoryPath = path;
    final File file = pathToFile(directoryPath, bufferSize);
    return new LocalDataInputStream(file);
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) File(java.io.File)

Example 18 with Path

use of edu.iu.dsc.tws.api.data.Path in project twister2 by DSC-SPIDAL.

the class LocalFileSystem method create.

@Override
public FSDataOutputStream create(Path filePath) throws IOException {
    final Path parent = filePath.getParent();
    if (parent != null && !mkdirs(parent)) {
        throw new IOException("Mkdirs failed to create " + parent);
    }
    final File file = pathToFile(filePath);
    return new LocalDataOutputStream(file);
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) IOException(java.io.IOException) File(java.io.File)

Example 19 with Path

use of edu.iu.dsc.tws.api.data.Path in project twister2 by DSC-SPIDAL.

the class DataNodeLocatorUtils method findDataNodesLocation.

/**
 * This method receives the input data list for each vertex and find the location of the
 * datanodes in the HDFS and returns the data node list.
 */
public List<String> findDataNodesLocation(List<String> inputFileList) {
    List<String> dataNodes = new ArrayList<>();
    FileSystem fileSystem;
    try {
        for (String anInputFileList : inputFileList) {
            Path path = new Path(anInputFileList);
            fileSystem = FileSystemUtils.get(path.toUri(), config);
            this.datasetName = anInputFileList;
            if (config.get(DataObjectConstants.FILE_SYSTEM).equals(DataContext.TWISTER2_HDFS_FILESYSTEM)) {
                FileStatus fileStatus = fileSystem.getFileStatus(new Path(datasetName));
                if (!fileStatus.getPath().isNullOrEmpty()) {
                    // dataNodes = getDataNodes(new String[]{this.datasetName});
                    dataNodes = getDataNodes();
                }
            } else if (config.get(DataObjectConstants.FILE_SYSTEM).equals(DataContext.TWISTER2_LOCAL_FILESYSTEM)) {
                FileStatus fileStatus = fileSystem.getFileStatus(new Path(datasetName));
                if (!fileStatus.getPath().isNullOrEmpty()) {
                    String datanodeName = InetAddress.getLocalHost().getHostName();
                    dataNodes.add(datanodeName);
                }
            }
        }
    } catch (IOException ioe) {
        throw new RuntimeException("IOException Occured");
    }
    return dataNodes;
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) FileStatus(edu.iu.dsc.tws.api.data.FileStatus) FileSystem(edu.iu.dsc.tws.api.data.FileSystem) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 20 with Path

use of edu.iu.dsc.tws.api.data.Path in project twister2 by DSC-SPIDAL.

the class TextOutputWriter method createOutput.

public void createOutput() {
    try {
        if (fs.exists(path)) {
            fs.delete(path, true);
        }
        outputStream = fs.create(new Path(path, generateRandom(10) + ".txt"));
        pw = new PrintWriter(outputStream);
    } catch (IOException e) {
        throw new RuntimeException("IOException Occured");
    }
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

Path (edu.iu.dsc.tws.api.data.Path)61 IOException (java.io.IOException)23 FileSystem (edu.iu.dsc.tws.api.data.FileSystem)19 FileStatus (edu.iu.dsc.tws.api.data.FileStatus)14 ArrayList (java.util.ArrayList)12 Config (edu.iu.dsc.tws.api.config.Config)11 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)8 FileInputSplit (edu.iu.dsc.tws.data.api.splits.FileInputSplit)8 ExecutionRuntime (edu.iu.dsc.tws.executor.core.ExecutionRuntime)8 BlockLocation (edu.iu.dsc.tws.api.data.BlockLocation)7 FSDataOutputStream (edu.iu.dsc.tws.api.data.FSDataOutputStream)7 PrintWriter (java.io.PrintWriter)7 File (java.io.File)6 LocalTextInputPartitioner (edu.iu.dsc.tws.data.api.formatters.LocalTextInputPartitioner)5 Test (org.junit.Test)5 ComputeGraph (edu.iu.dsc.tws.api.compute.graph.ComputeGraph)4 LocalCSVInputPartitioner (edu.iu.dsc.tws.data.api.formatters.LocalCSVInputPartitioner)4 LocalFixedInputPartitioner (edu.iu.dsc.tws.data.api.formatters.LocalFixedInputPartitioner)4 DataGenerator (edu.iu.dsc.tws.tsched.utils.DataGenerator)4 CSVInputSplit (edu.iu.dsc.tws.data.api.splits.CSVInputSplit)3