Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with property which is a Collection: System Center 2012 VMM service #26

Closed
jhellan opened this issue Jun 14, 2013 · 8 comments
Closed
Assignees
Labels

Comments

@jhellan
Copy link

jhellan commented Jun 14, 2013

Here's a very simple program that calls the VMM service and fails:

require 'ruby_odata'
svc = OData::Service.new "http://:9090/SC2012/VMM/Microsoft.Management.Odata.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
svc.VirtualMachines
vms = svc.execute

The final statement fails with the following backtrace:

/var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:640:in `complex_type_to_class': undefined method `new' for nil:NilClass (NoMethodError)
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:682:in `parse_value'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:393:in `block in entry_to_class'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:239:in `block in each'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `upto'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `each'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:391:in `entry_to_class'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:359:in `block in build_classes_from_result'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:239:in `block in each'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `upto'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `each'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:358:in `build_classes_from_result'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:306:in `handle_collection_result'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:102:in `execute'
    from ./rb2.rb:7:in `'

A VirtualMachine entry can be found at https://gist.github.com/jhellan/5781766

I did some tracing, and found that it failed when it got to this property:

<d:VMNetworkAssignments m:type="Collection(VMM.VMNetworkAssignment)"/>

This is the first property that is a collection, so I wonder if that could be the reason.

@visoft
Copy link
Owner

visoft commented Jun 15, 2013

Could you also provide me with a gist of the metadata for the service? Just request http://:9090/SC2012/VMM/Microsoft.Management.Odata.svc/$metadata

@ghost ghost assigned visoft Jun 15, 2013
@jhellan
Copy link
Author

jhellan commented Jun 15, 2013

Here it is: https://gist.github.com/jhellan/5789199

@visoft
Copy link
Owner

visoft commented Jun 15, 2013

I need the actual resulting feed xml from the query, what is the results of the following query

http://:9090/SC2012/VMM/Microsoft.Management.Odata.svc/VirtualMachines?$top=1

(or change the $top to something else, just wanted to limit what you brought back)

The resulting XML should start with a <feed> element.

@jhellan
Copy link
Author

jhellan commented Jun 15, 2013

Hope this helps: https://gist.github.com/jhellan/5789559

@visoft
Copy link
Owner

visoft commented Jun 16, 2013

I checked the fix into the develop branch.

There may be another bug however. Could you get me the results of a query that returns an entity where you have a collection of complex types in the results. You'll probably have to eager load one of these.

A "complex type" would just be a class that is in the VMM namespace (like VMNetworkAssignment). I want to make sure I have coverage for that scenario now that the the complex type class resolves properly. I suspect it will work, but just want to make sure.

@jhellan
Copy link
Author

jhellan commented Jun 16, 2013

Thanks. That worked.
As to the last question, is this relevant?

The following program fails:

require 'ruby_odata'
svc = OData::Service.new "http://:9090/SC2012/VMM/Microsoft.Management.Odata.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
svc.HardwareProfiles.filter("Memory eq 3500")
hs = svc.execute

The gist https://gist.github.com/jhellan/5791590 contains the result when I do this with curl. I see

<category term="VMM.HardwareProfile" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

The backtrace is

/var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:652:in `block in complex_type_to_class': undefined method `element=' for # (NoMethodError)
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:239:in `block in each'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `upto'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `each'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:651:in `complex_type_to_class'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:689:in `parse_value'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:393:in `block in entry_to_class'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:239:in `block in each'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `upto'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `each'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:391:in `entry_to_class'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:359:in `block in build_classes_from_result'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:239:in `block in each'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `upto'
    from /var/lib/gems/1.9.1/gems/nokogiri-1.5.6/lib/nokogiri/xml/node_set.rb:238:in `each'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:358:in `build_classes_from_result'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:306:in `handle_collection_result'
    from /var/lib/gems/1.9.1/gems/ruby_odata-0.1.3/lib/ruby_odata/service.rb:102:in `execute'
    from ./rb4.rb:9:in `'

@visoft
Copy link
Owner

visoft commented Jun 16, 2013

Thanks!

That's exactly what I was thinking could been a problem. Try the latest version of the develop branch.

@jhellan
Copy link
Author

jhellan commented Jun 16, 2013

Works great. Thanks!

Jon

@visoft visoft closed this as completed Jun 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants