public virtual void TestWebImageViewer()
        {
            WebImageViewer viewer = new WebImageViewer(NetUtils.CreateSocketAddr("localhost:0"
                                                                                 ));

            try
            {
                viewer.InitServer(originalFsimage.GetAbsolutePath());
                int port = viewer.GetPort();
                // create a WebHdfsFileSystem instance
                URI               uri     = new URI("webhdfs://localhost:" + port.ToString());
                Configuration     conf    = new Configuration();
                WebHdfsFileSystem webhdfs = (WebHdfsFileSystem)FileSystem.Get(uri, conf);
                // verify the number of directories
                FileStatus[] statuses = webhdfs.ListStatus(new Path("/"));
                NUnit.Framework.Assert.AreEqual(NumDirs + 3, statuses.Length);
                // contains empty and xattr directory
                // verify the number of files in the directory
                statuses = webhdfs.ListStatus(new Path("/dir0"));
                NUnit.Framework.Assert.AreEqual(FilesPerDir, statuses.Length);
                // compare a file
                FileStatus status   = webhdfs.ListStatus(new Path("/dir0/file0"))[0];
                FileStatus expected = writtenFiles["/dir0/file0"];
                CompareFile(expected, status);
                // LISTSTATUS operation to an empty directory
                statuses = webhdfs.ListStatus(new Path("/emptydir"));
                NUnit.Framework.Assert.AreEqual(0, statuses.Length);
                // LISTSTATUS operation to a invalid path
                Uri url = new Uri("http://localhost:" + port + "/webhdfs/v1/invalid/?op=LISTSTATUS"
                                  );
                VerifyHttpResponseCode(HttpURLConnection.HttpNotFound, url);
                // LISTSTATUS operation to a invalid prefix
                url = new Uri("http://localhost:" + port + "/foo");
                VerifyHttpResponseCode(HttpURLConnection.HttpNotFound, url);
                // GETFILESTATUS operation
                status = webhdfs.GetFileStatus(new Path("/dir0/file0"));
                CompareFile(expected, status);
                // GETFILESTATUS operation to a invalid path
                url = new Uri("http://localhost:" + port + "/webhdfs/v1/invalid/?op=GETFILESTATUS"
                              );
                VerifyHttpResponseCode(HttpURLConnection.HttpNotFound, url);
                // invalid operation
                url = new Uri("http://localhost:" + port + "/webhdfs/v1/?op=INVALID");
                VerifyHttpResponseCode(HttpURLConnection.HttpBadRequest, url);
                // invalid method
                url = new Uri("http://localhost:" + port + "/webhdfs/v1/?op=LISTSTATUS");
                HttpURLConnection connection = (HttpURLConnection)url.OpenConnection();
                connection.SetRequestMethod("POST");
                connection.Connect();
                NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpBadMethod, connection.GetResponseCode
                                                    ());
            }
            finally
            {
                // shutdown the viewer
                viewer.Close();
            }
        }
        public virtual void TestWebImageViewerForAcl()
        {
            WebImageViewer viewer = new WebImageViewer(NetUtils.CreateSocketAddr("localhost:0"
                                                                                 ));

            try
            {
                viewer.InitServer(originalFsimage.GetAbsolutePath());
                int port = viewer.GetPort();
                // create a WebHdfsFileSystem instance
                URI               uri     = new URI("webhdfs://localhost:" + port.ToString());
                Configuration     conf    = new Configuration();
                WebHdfsFileSystem webhdfs = (WebHdfsFileSystem)FileSystem.Get(uri, conf);
                // GETACLSTATUS operation to a directory without ACL
                AclStatus acl = webhdfs.GetAclStatus(new Path("/dirWithNoAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/dirWithNoAcl"], acl);
                // GETACLSTATUS operation to a directory with a default ACL
                acl = webhdfs.GetAclStatus(new Path("/dirWithDefaultAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/dirWithDefaultAcl"], acl);
                // GETACLSTATUS operation to a file without ACL
                acl = webhdfs.GetAclStatus(new Path("/noAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/noAcl"], acl);
                // GETACLSTATUS operation to a file with a ACL
                acl = webhdfs.GetAclStatus(new Path("/withAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/withAcl"], acl);
                // GETACLSTATUS operation to a file with several ACL entries
                acl = webhdfs.GetAclStatus(new Path("/withSeveralAcls"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/withSeveralAcls"], acl);
                // GETACLSTATUS operation to a invalid path
                Uri url = new Uri("http://localhost:" + port + "/webhdfs/v1/invalid/?op=GETACLSTATUS"
                                  );
                HttpURLConnection connection = (HttpURLConnection)url.OpenConnection();
                connection.SetRequestMethod("GET");
                connection.Connect();
                NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpNotFound, connection.GetResponseCode
                                                    ());
            }
            finally
            {
                // shutdown the viewer
                viewer.Close();
            }
        }
Beispiel #3
0
        /// <exception cref="System.Exception"/>
        public static int Run(string[] args)
        {
            Options options = BuildOptions();

            if (args.Length == 0)
            {
                PrintUsage();
                return(0);
            }
            CommandLineParser parser = new PosixParser();
            CommandLine       cmd;

            try
            {
                cmd = parser.Parse(options, args);
            }
            catch (ParseException)
            {
                System.Console.Out.WriteLine("Error parsing command-line options: ");
                PrintUsage();
                return(-1);
            }
            if (cmd.HasOption("h"))
            {
                // print help and exit
                PrintUsage();
                return(0);
            }
            string inputFile  = cmd.GetOptionValue("i");
            string processor  = cmd.GetOptionValue("p", "Web");
            string outputFile = cmd.GetOptionValue("o", "-");
            string delimiter  = cmd.GetOptionValue("delimiter", PBImageDelimitedTextWriter.DefaultDelimiter
                                                   );
            string        tempPath = cmd.GetOptionValue("t", string.Empty);
            Configuration conf     = new Configuration();

            try
            {
                using (TextWriter @out = outputFile.Equals("-") ? System.Console.Out : new TextWriter
                                             (outputFile, "UTF-8"))
                {
                    switch (processor)
                    {
                    case "FileDistribution":
                    {
                        long maxSize = long.Parse(cmd.GetOptionValue("maxSize", "0"));
                        int  step    = System.Convert.ToInt32(cmd.GetOptionValue("step", "0"));
                        new FileDistributionCalculator(conf, maxSize, step, @out).Visit(new RandomAccessFile
                                                                                            (inputFile, "r"));
                        break;
                    }

                    case "XML":
                    {
                        new PBImageXmlWriter(conf, @out).Visit(new RandomAccessFile(inputFile, "r"));
                        break;
                    }

                    case "Web":
                    {
                        string addr = cmd.GetOptionValue("addr", "localhost:5978");
                        using (WebImageViewer viewer = new WebImageViewer(NetUtils.CreateSocketAddr(addr)
                                                                          ))
                        {
                            viewer.Start(inputFile);
                        }
                        break;
                    }

                    case "Delimited":
                    {
                        using (PBImageDelimitedTextWriter writer = new PBImageDelimitedTextWriter(@out, delimiter
                                                                                                  , tempPath))
                        {
                            writer.Visit(new RandomAccessFile(inputFile, "r"));
                        }
                        break;
                    }
                    }
                    return(0);
                }
            }
            catch (EOFException)
            {
                System.Console.Error.WriteLine("Input file ended unexpectedly. Exiting");
            }
            catch (IOException e)
            {
                System.Console.Error.WriteLine("Encountered exception.  Exiting: " + e.Message);
            }
            return(-1);
        }
Beispiel #4
0
 public _ChannelInitializer_92(WebImageViewer _enclosing, FSImageLoader loader)
 {
     this._enclosing = _enclosing;
     this.loader     = loader;
 }