Ejemplo n.º 1
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessOptions(List <string> args)
            {
                name = StringUtils.PopOptionWithArgument("-n", args);
                string v = StringUtils.PopOptionWithArgument("-v", args);

                if (v != null)
                {
                    value = XAttrCodec.DecodeValue(v);
                }
                xname = StringUtils.PopOptionWithArgument("-x", args);
                if (name != null && xname != null)
                {
                    throw new HadoopIllegalArgumentException("Can not specify both '-n name' and '-x name' option."
                                                             );
                }
                if (name == null && xname == null)
                {
                    throw new HadoopIllegalArgumentException("Must specify '-n name' or '-x name' option."
                                                             );
                }
                if (args.IsEmpty())
                {
                    throw new HadoopIllegalArgumentException("<path> is missing.");
                }
                if (args.Count > 1)
                {
                    throw new HadoopIllegalArgumentException("Too many arguments.");
                }
            }
Ejemplo n.º 2
0
 /// <exception cref="System.IO.IOException"/>
 public FSSetXAttr(string path, string name, string encodedValue, EnumSet <XAttrSetFlag
                                                                           > flag)
 {
     this.path  = new Path(path);
     this.name  = name;
     this.value = XAttrCodec.DecodeValue(encodedValue);
     this.flag  = flag;
 }
Ejemplo n.º 3
0
        public virtual void TestGetXAttrFromJson()
        {
            string jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"},"
                                + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
            ObjectReader reader = new ObjectMapper().Reader(typeof(IDictionary));
            IDictionary <object, object> json = reader.ReadValue(jsonString);

            // Get xattr: user.a2
            byte[] value = JsonUtil.GetXAttr(json, "user.a2");
            Assert.AssertArrayEquals(XAttrCodec.DecodeValue("0x313131"), value);
        }
Ejemplo n.º 4
0
 /// <summary>Decode xattr value from string</summary>
 /// <exception cref="System.IO.IOException"/>
 private byte[] DecodeXAttrValue(string value)
 {
     if (value != null)
     {
         return(XAttrCodec.DecodeValue(value));
     }
     else
     {
         return(new byte[0]);
     }
 }
Ejemplo n.º 5
0
        public virtual void TestXAttrValueParam()
        {
            XAttrValueParam p = new XAttrValueParam("0x313233");

            Assert.AssertArrayEquals(p.GetXAttrValue(), XAttrCodec.DecodeValue("0x313233"));
        }
Ejemplo n.º 6
0
        public virtual void TestToXAttrMap()
        {
            string jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"},"
                                + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
            ObjectReader reader = new ObjectMapper().Reader(typeof(IDictionary));
            IDictionary <object, object> json = reader.ReadValue(jsonString);
            XAttr xAttr1 = (new XAttr.Builder()).SetNameSpace(XAttr.NameSpace.User).SetName("a1"
                                                                                            ).SetValue(XAttrCodec.DecodeValue("0x313233")).Build();
            XAttr xAttr2 = (new XAttr.Builder()).SetNameSpace(XAttr.NameSpace.User).SetName("a2"
                                                                                            ).SetValue(XAttrCodec.DecodeValue("0x313131")).Build();
            IList <XAttr> xAttrs = Lists.NewArrayList();

            xAttrs.AddItem(xAttr1);
            xAttrs.AddItem(xAttr2);
            IDictionary <string, byte[]> xAttrMap       = XAttrHelper.BuildXAttrMap(xAttrs);
            IDictionary <string, byte[]> parsedXAttrMap = JsonUtil.ToXAttrs(json);

            NUnit.Framework.Assert.AreEqual(xAttrMap.Count, parsedXAttrMap.Count);
            IEnumerator <KeyValuePair <string, byte[]> > iter = xAttrMap.GetEnumerator();

            while (iter.HasNext())
            {
                KeyValuePair <string, byte[]> entry = iter.Next();
                Assert.AssertArrayEquals(entry.Value, parsedXAttrMap[entry.Key]);
            }
        }
Ejemplo n.º 7
0
        public virtual void TestToJsonFromXAttrs()
        {
            string jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"},"
                                + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
            XAttr xAttr1 = (new XAttr.Builder()).SetNameSpace(XAttr.NameSpace.User).SetName("a1"
                                                                                            ).SetValue(XAttrCodec.DecodeValue("0x313233")).Build();
            XAttr xAttr2 = (new XAttr.Builder()).SetNameSpace(XAttr.NameSpace.User).SetName("a2"
                                                                                            ).SetValue(XAttrCodec.DecodeValue("0x313131")).Build();
            IList <XAttr> xAttrs = Lists.NewArrayList();

            xAttrs.AddItem(xAttr1);
            xAttrs.AddItem(xAttr2);
            NUnit.Framework.Assert.AreEqual(jsonString, JsonUtil.ToJsonString(xAttrs, XAttrCodec
                                                                              .Hex));
        }
Ejemplo n.º 8
0
        /// <exception cref="System.IO.IOException"/>
        public virtual byte[] GetXAttrValue()
        {
            string v = GetValue();

            return(XAttrCodec.DecodeValue(v));
        }