public HdfsLogAppendStream(Uri logUri, bool deleteIfExists)
        {
            _logUri = logUri;
            string logPath      = _logUri.AbsolutePath;
            string logDirectory = logPath.Substring(0, logPath.LastIndexOf('/'));

            _writePosition = 0;

            try
            {
                _hdfs = new HdfsInstance(_logUri);
                _hdfs.EnsureDirectory(logDirectory);
                if (_hdfs.IsFileExists(logPath))
                {
                    if (deleteIfExists)
                    {
                        _hdfs.DeleteFile(logPath, false);
                    }
                    else
                    {
                        throw new ApplicationException("Log file " + logUri.AbsoluteUri + " already exists");
                    }
                }
                _writer = _hdfs.OpenCreate(logPath, 1024 * 1024, -1);
            }
            catch (Exception e)
            {
                throw new ApplicationException("HdfsLogAppendStream failed to open writer", e);
            }
        }
Exemple #2
0
 public HdfsStreamReader(HdfsInstance instance, string dfsPath, long offset, long length, int byteBufferSize)
     : base(byteBufferSize)
 {
     this.reader      = instance.OpenReader(dfsPath);
     this.offset      = offset;
     this.bytesToRead = length;
 }
Exemple #3
0
        public override void Rename(Uri dstPath, Uri srcPath)
        {
            HdfsInstance dstInstance = this.Instance(dstPath);
            HdfsInstance srcInstance = this.Instance(srcPath);

            if (dstInstance != srcInstance)
            {
                throw new ApplicationException("Can't rename HDFS files from different file systems: " + dstPath.AbsoluteUri + ", " + srcPath.AbsoluteUri);
            }
            dstInstance.RenameFile(dstPath.AbsolutePath, srcPath.AbsolutePath);
        }
Exemple #4
0
        private HdfsInstance Instance(Uri uri)
        {
            NameNode nameNodeAndPort = new NameNode(uri.Host, uri.Port);

            HdfsInstance instance;

            if (!this.instances.TryGetValue(nameNodeAndPort, out instance))
            {
                instance = new HdfsInstance(uri);
                this.instances.Add(nameNodeAndPort, instance);
            }

            return(instance);
        }
        public HdfsLogReaderStream(Uri logUri)
        {
            _logUri       = logUri;
            _readPosition = 0; // this is the current read position

            try
            {
                _hdfs = new HdfsInstance(_logUri);
                string logPath = _logUri.AbsolutePath;
                _cachedReader = _hdfs.OpenReader(logPath);
            }
            catch (Exception e)
            {
                throw new ApplicationException("HdfsLogReaderStream failed to open reader", e);
            }
        }
Exemple #6
0
 public HdfsStreamWriter(HdfsInstance instance, string dfsPath, string user, int bufferSize, long blockSize)
 {
     this.writer = instance.OpenCreate(dfsPath, bufferSize, blockSize);
     instance.SetOwnerAndPermission(dfsPath, user, null, Convert.ToInt16("644", 8));
 }