0

我正在尝试通过 OneFS REST API 在我们的 Isilon 集群上创建存储配额。我正在使用来自前 EMC 工程师的类库,并添加了我自己的方法来创建配额,但无法弄清楚为什么返回 400 错误。这目前是通过一个简单的控制台应用程序发送的,并且相同的有效负载和 URL 在 Postman 中没有任何问题。我真的很想继续使用和构建这个库,因为已经完成了很多工作。任何帮助或见解将不胜感激。

我从 Main 调用 CreateQuota 方法

 static void Main(string[] args)
    {

        //DisplayQuotas();

        bool qcontainer = false;
        bool qenforced = false;
        bool qincludesnaps = false;
        bool qthresincludeoverhead = false;
        string qtype = "directory";
        string qpath = "/path/to/myquota/diectory";         
        SmartQuotas quotas = new SmartQuotas(service);
        quotas.CreateQuota(qcontainer, qenforced, qincludesnaps, qthresincludeoverhead, qtype, qpath);

    }

我添加的 CreateQuota 方法,它利用另一个类的 DataMemberAttribute - 这是在现有方法之后建模的,用于创建 SMB 共享。

public Quota CreateQuota(bool container, bool enforced, bool include_snapshots, bool thresholds_include_overhead, string type, string path)
    {
        Quota quota = new Quota();
        quota.Container = container;
        quota.Enforced = enforced;
        quota.IncludeSnapshots = include_snapshots;
        quota.ThresholdsIncludeOverhead = thresholds_include_overhead;
        quota.Type = type;
        quota.Path = path;
       
        Post<Quota>("/platform/1/quota/quotas", quota);
        
        //quota = GetQuotas()[0];

        return quota;
    }

这是 Post 方法,它使用 DataContractSerializer,我觉得这是我的问题的一部分。我只是不确定为什么我发送的正文不会被正确解析并且也无法反序列化以查看我的请求的外观。

 protected void Post<T>(string resource, T body)
    {
        try
        {
            // Create a web request object pointing to the Isilon server and Resource String
            HttpWebRequest request = _Service.CreateRequest(resource);
            request.Method = "POST";

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
            serializer.WriteObject(request.GetRequestStream(), (T)body);

            // Attempt at reading the stream but throws System.NotSupportedException
            //T t2 = (T)serializer.ReadObject(request.GetRequestStream());
     
            // Send the request to the Isilon cluster and get there response
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            response.Close();


        }
        catch(WebException e)
        {
            Console.WriteLine("This is the WebException from a POST attempt: " + e.Message);
            if(e.Status == WebExceptionStatus.ProtocolError)
            {
                Console.WriteLine("Status Code: {0}", ((HttpWebResponse)e.Response).StatusCode);
                Console.Write("Status Description: {0}", ((HttpWebResponse)e.Response).StatusDescription);
            }
        }

    }

这也是 DataContract 类的精简版本,在我链接到的 Git 存储库中可见。

[DataContract]
public class Quota
{
    // Enables the SMB shares using the quota directory to see the quota threshold as the share size.
    [DataMember(Name = "container", EmitDefaultValue = false)]
    public bool Container;

    // True if the quota provides enforcement, otherwise an accounting quota
    [DataMember(Name = "enforced", EmitDefaultValue = false)]
    public bool Enforced;

    // True if the quota governs snapshot data as well as head data.
    [DataMember(Name = "include_snapshots", EmitDefaultValue = false)]
    public bool IncludeSnapshots;

    // True if the thresholds apply to the data plus file system overhead that is required to store the data
    // (such as physical useage)
    [DataMember(Name = "thresholds_include_overhead", EmitDefaultValue = false)]
    public bool ThresholdsIncludeOverhead;

            // Type of quota - User, group, directory
    [DataMember(Name = "type", EmitDefaultValue = false)]
    public string Type;

    // OneFS path
    [DataMember(Name = "path", EmitDefaultValue = false)]
    public string Path;

}
4

1 回答 1

0

结果证明是相当直截了当的——阈值对象的模式有一个嵌套值,该值没有正确形成。我最终使用 RestSharp 自己从头开始进行此调用,并仔细查看了 OneFS API 文档,这两个文档最终都帮助我了解了这里发生的情况。

于 2020-10-12T13:07:40.157 回答