Mailing List Archive

Java XML RPC with Xen-API?
Hello!

I am experimenting with a Java client to access xend through the
Xen-API. Using the Apache XML-RPC library (version 3) I could open a
session that returned the status value and the uuid of the session. When I
try to call VM.get_all() in a subsequent step, the returned HashMap again
contains the status code but as a second parameter a quite useless Java
'Object' -- not a Vector or so. I see, though, that Xend returns a list of
UUIDs of the managed domains. Is there any way to have the second
parameter become something more useful like a Vector or a String[] or does
another client library do this better?

Thanks.

Stefan
Re: Java XML RPC with Xen-API? [ In reply to ]
I believe the object is a map, here is a code fragment that might help:

/*
Unimplemented...
Object kernelKernel=execute("VM.get_kernel_kernel", params);
*/

java.util.Map result=(java.util.Map)execute("VM.get_record",
params);

/*
Set keyset=result.keySet();
for(Object key : keyset) {
LOG.debug("XXX key %s value %b \"%s\"\n",
(String)key, null==result.get((String)key),
result.get((String)key));
}
*/

String kernelKernel=(String)result.get("PV_kernel");
/Evan

Stefan Berger wrote:

>
> Hello!
>
> I am experimenting with a Java client to access xend through the
> Xen-API. Using the Apache XML-RPC library (version 3) I could open a
> session that returned the status value and the uuid of the session.
> When I try to call VM.get_all() in a subsequent step, the returned
> HashMap again contains the status code but as a second parameter a
> quite useless Java 'Object' -- not a Vector or so. I see, though, that
> Xend returns a list of UUIDs of the managed domains. Is there any way
> to have the second parameter become something more useful like a
> Vector or a String[] or does another client library do this better?
>
> Thanks.
>
> Stefan
>
>------------------------------------------------------------------------
>
>_______________________________________________
>xen-api mailing list
>xen-api@lists.xensource.com
>http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>
>
Re: Java XML RPC with Xen-API? [ In reply to ]
Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 12:42:01 PM:

> I believe the object is a map, here is a code fragment that might help:
>
> /*
> Unimplemented...
> Object kernelKernel=execute("VM.get_kernel_kernel",
params);
> */
>
> java.util.Map result=(java.util.Map)execute("VM.
> get_record", params);
>

For get_record I also get a map, where the 'Value' key itself contains a
java.util.Map as value type.
Another function that returns a 'Set' is get_by_label_name, which also
returns an Object as value to the 'Value' key. Maybe it's the functions
that return 'Set's that cannot be deserialized or are not properly
serialized ?

Stefan


> /*
> Set keyset=result.keySet();
> for(Object key : keyset) {
> LOG.debug("XXX key %s value %b \"%s\"\n",
> (String)key, null==result.get((String)key),
> result.get((String)key));
> }
> */
>
> String kernelKernel=(String)result.get("PV_kernel");
> /Evan
>
> Stefan Berger wrote:
>
> Hello!
>
> I am experimenting with a Java client to access xend through the
> Xen-API. Using the Apache XML-RPC library (version 3) I could open a
> session that returned the status value and the uuid of the session.
> When I try to call VM.get_all() in a subsequent step, the returned
> HashMap again contains the status code but as a second parameter a
> quite useless Java 'Object' -- not a Vector or so. I see, though,
> that Xend returns a list of UUIDs of the managed domains. Is there
> any way to have the second parameter become something more useful
> like a Vector or a String[] or does another client library do this
better?
>
> Thanks.
>
> Stefan
>
>
> _______________________________________________
> xen-api mailing list
> xen-api@lists.xensource.com
> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>
Re: Java XML RPC with Xen-API? [ In reply to ]
My "execute" method returns result.get("Value"), you should then be able
to cast that into a java Set, and iterate through all the key/value pairs.

I'm pretty sure this all works as expected.

Evan
Stefan Berger wrote:
>
> Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 12:42:01 PM:
>
> > I believe the object is a map, here is a code fragment that might help:
> >
> > /*
> > Unimplemented...
> > Object kernelKernel=execute("VM.get_kernel_kernel",
> params);
> > */
> >
> > java.util.Map result=(java.util.Map)execute("VM.
> > get_record", params);
> >
>
> For get_record I also get a map, where the 'Value' key itself contains
> a java.util.Map as value type.
> Another function that returns a 'Set' is get_by_label_name, which also
> returns an Object as value to the 'Value' key. Maybe it's the
> functions that return 'Set's that cannot be deserialized or are not
> properly serialized ?
>
> Stefan
>
>
> > /*
> > Set keyset=result.keySet();
> > for(Object key : keyset) {
> > LOG.debug("XXX key %s value %b \"%s\"\n",
> > (String)key, null==result.get((String)key),
> > result.get((String)key));
> > }
> > */
> >
> > String kernelKernel=(String)result.get("PV_kernel");
> > /Evan
> >
> > Stefan Berger wrote:
> >
> > Hello!
> >
> > I am experimenting with a Java client to access xend through the
> > Xen-API. Using the Apache XML-RPC library (version 3) I could open a
> > session that returned the status value and the uuid of the session.
> > When I try to call VM.get_all() in a subsequent step, the returned
> > HashMap again contains the status code but as a second parameter a
> > quite useless Java 'Object' -- not a Vector or so. I see, though,
> > that Xend returns a list of UUIDs of the managed domains. Is there
> > any way to have the second parameter become something more useful
> > like a Vector or a String[] or does another client library do this
> better?
> >
> > Thanks.
> >
> > Stefan
> >
> >
> > _______________________________________________
> > xen-api mailing list
> > xen-api@lists.xensource.com
> > http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
> >


_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
Re: Java XML RPC with Xen-API? [ In reply to ]
Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 01:50:40 PM:

> My "execute" method returns result.get("Value"), you should then be able

> to cast that into a java Set, and iterate through all the key/value
pairs.

I would hope so, too, but it results in a ClassCastException. Which XML
RPC library are you using and what version?


Stefan

>
> I'm pretty sure this all works as expected.
>
> Evan
> Stefan Berger wrote:
> >
> > Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 12:42:01 PM:
> >
> > > I believe the object is a map, here is a code fragment that might
help:
> > >
> > > /*
> > > Unimplemented...
> > > Object kernelKernel=execute("VM.get_kernel_kernel",
> > params);
> > > */
> > >
> > > java.util.Map result=(java.util.Map)execute("VM.
> > > get_record", params);
> > >
> >
> > For get_record I also get a map, where the 'Value' key itself contains

> > a java.util.Map as value type.
> > Another function that returns a 'Set' is get_by_label_name, which also

> > returns an Object as value to the 'Value' key. Maybe it's the
> > functions that return 'Set's that cannot be deserialized or are not
> > properly serialized ?
> >
> > Stefan
> >
> >
> > > /*
> > > Set keyset=result.keySet();
> > > for(Object key : keyset) {
> > > LOG.debug("XXX key %s value %b \"%s\"\n",
> > > (String)key,
null==result.get((String)key),
> > > result.get((String)key));
> > > }
> > > */
> > >
> > > String kernelKernel=(String)result.get("PV_kernel");
> > > /Evan
> > >
> > > Stefan Berger wrote:
> > >
> > > Hello!
> > >
> > > I am experimenting with a Java client to access xend through the
> > > Xen-API. Using the Apache XML-RPC library (version 3) I could open a
> > > session that returned the status value and the uuid of the session.
> > > When I try to call VM.get_all() in a subsequent step, the returned
> > > HashMap again contains the status code but as a second parameter a
> > > quite useless Java 'Object' -- not a Vector or so. I see, though,
> > > that Xend returns a list of UUIDs of the managed domains. Is there
> > > any way to have the second parameter become something more useful
> > > like a Vector or a String[] or does another client library do this
> > better?
> > >
> > > Thanks.
> > >
> > > Stefan
> > >
> > >
> > > _______________________________________________
> > > xen-api mailing list
> > > xen-api@lists.xensource.com
> > > http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
> > >
>
Re: Java XML RPC with Xen-API? [ In reply to ]
On Mon, Apr 02, 2007 at 03:37:17PM -0400, Stefan Berger wrote:

> Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 01:50:40 PM:
>
> > My "execute" method returns result.get("Value"), you should then be able
> > to cast that into a java Set, and iterate through all the key/value
> pairs.
>
> I would hope so, too, but it results in a ClassCastException. Which XML
> RPC library are you using and what version?

Glancing through the Apache XML-RPC library, version 3, it looks like you should
either be able to cast that to either an Object [], or failing that, a
List. Xen-API's Sets are marshalled as XML-RPC <array>s on the wire, and
it's up to the client library how to interpret that.

If you call getClass() on the result, you can see what it's giving you
back.

Ewan.

_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
Re: Java XML RPC with Xen-API? [ In reply to ]
Apache xmlrpc-3.0, and their internal transport, ie:
m_client.setTransportFactory(new
XmlRpcCommonsTransportFactory(m_client)). I had started out using
Java's http transport, but ran into problems. Sorry, can't quite
remember what they were.

Evan

Stefan Berger wrote:
>
> Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 01:50:40 PM:
>
> > My "execute" method returns result.get("Value"), you should then be
> able
> > to cast that into a java Set, and iterate through all the key/value
> pairs.
>
> I would hope so, too, but it results in a ClassCastException. Which
> XML RPC library are you using and what version?
>
>
> Stefan
>
> >
> > I'm pretty sure this all works as expected.
> >
> > Evan
> > Stefan Berger wrote:
> > >
> > > Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 12:42:01 PM:
> > >
> > > > I believe the object is a map, here is a code fragment that
> might help:
> > > >
> > > > /*
> > > > Unimplemented...
> > > > Object kernelKernel=execute("VM.get_kernel_kernel",
> > > params);
> > > > */
> > > >
> > > > java.util.Map result=(java.util.Map)execute("VM.
> > > > get_record", params);
> > > >
> > >
> > > For get_record I also get a map, where the 'Value' key itself
> contains
> > > a java.util.Map as value type.
> > > Another function that returns a 'Set' is get_by_label_name, which
> also
> > > returns an Object as value to the 'Value' key. Maybe it's the
> > > functions that return 'Set's that cannot be deserialized or are not
> > > properly serialized ?
> > >
> > > Stefan
> > >
> > >
> > > > /*
> > > > Set keyset=result.keySet();
> > > > for(Object key : keyset) {
> > > > LOG.debug("XXX key %s value %b \"%s\"\n",
> > > > (String)key,
> null==result.get((String)key),
> > > > result.get((String)key));
> > > > }
> > > > */
> > > >
> > > > String kernelKernel=(String)result.get("PV_kernel");
> > > > /Evan
> > > >
> > > > Stefan Berger wrote:
> > > >
> > > > Hello!
> > > >
> > > > I am experimenting with a Java client to access xend through the
> > > > Xen-API. Using the Apache XML-RPC library (version 3) I could open a
> > > > session that returned the status value and the uuid of the session.
> > > > When I try to call VM.get_all() in a subsequent step, the returned
> > > > HashMap again contains the status code but as a second parameter a
> > > > quite useless Java 'Object' -- not a Vector or so. I see, though,
> > > > that Xend returns a list of UUIDs of the managed domains. Is there
> > > > any way to have the second parameter become something more useful
> > > > like a Vector or a String[] or does another client library do this
> > > better?
> > > >
> > > > Thanks.
> > > >
> > > > Stefan
> > > >
> > > >
> > > > _______________________________________________
> > > > xen-api mailing list
> > > > xen-api@lists.xensource.com
> > > > http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
> > > >
> >
Re: Java XML RPC with Xen-API? [ In reply to ]
Ewan Mellor <ewan@xensource.com> wrote on 04/02/2007 05:40:26 PM:

> On Mon, Apr 02, 2007 at 03:37:17PM -0400, Stefan Berger wrote:
>
> > Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 01:50:40 PM:
> >
> > > My "execute" method returns result.get("Value"), you should then be
able
> > > to cast that into a java Set, and iterate through all the key/value
> > pairs.
> >
> > I would hope so, too, but it results in a ClassCastException. Which
XML
> > RPC library are you using and what version?
>
> Glancing through the Apache XML-RPC library, version 3, it looks
> like you should
> either be able to cast that to either an Object [], or failing that, a
> List. Xen-API's Sets are marshalled as XML-RPC <array>s on the wire,
and
> it's up to the client library how to interpret that.
>
> If you call getClass() on the result, you can see what it's giving you
> back.
>

Here is what is coming back:

This first one is for estblishing the session -- works

-->{Status=Success, Value=7f0a5d0b-c0ff-f948-36e5-cbad03caf24c}
UUID: 7f0a5d0b-c0ff-f948-36e5-cbad03caf24c


The VM.get_all returns a 'Set' -- only an Object comes back

Calling VM.get_all(7f0a5d0b-c0ff-f948-36e5-cbad03caf24c,...)
Returned object = {Status=Success, Value=[Ljava.lang.Object;@1faba46}
'Value' has type class [Ljava.lang.Object;

A Map is returned from VM.get_record():

Calling VM.get_record(7f0a5d0b-c0ff-f948-36e5-cbad03caf24c,...)
Returned object = {Status=Success, Value={actions_after_suspend=restart,
user_version=1, domid=0, memory_static_max=17592186040320,
memory_dynamic_min=1048576000, is_control_domain=true,
actions_after_shutdown=destroy,
resident_on=1e86bcf9-3ddb-406a-4a31-702944839f28,
memory_dynamic_max=1048576000, PV_ramdisk=,
security_label=sHype:xm-test:SystemManagement, PV_args=,
uuid=00000000-0000-0000-0000-000000000000, name_label=Domain-0,
PV_kernel=, actions_after_crash=restart, VCPUs_at_startup=4,
memory_static_min=0, other_config={}, name_description=Domain-0,
PV_bootloader=, auto_power_on=false, consoles=[Ljava.lang.Object;@3570b0,
VIFs=[Ljava.lang.Object;@79717e, platform={},
VBDs=[Ljava.lang.Object;@10a2d64, PV_bootloader_args=,
metrics=2714b0e7-45b2-8ed3-31db-a31c8237750e,
VTPMs=[Ljava.lang.Object;@12a3722, actions_after_reboot=restart,
HVM_boot_policy=, tools_version={}, VCPUs_params={cap=0, weight=256},
is_a_template=false, PCI_bus=, HVM_boot_params={}, power_state=Running,
VCPUs_max=4}}
'Value' has type class java.util.HashMap


A set comes back here:

Calling VM.get_by_name_label(7f0a5d0b-c0ff-f948-36e5-cbad03caf24c,...)
Returned object = {Status=Success, Value=[Ljava.lang.Object;@cfec48}
'Value' has type class [Ljava.lang.Object;


Neither with the normal TranportFactory nor the
XmlRpcCommonsTransportFactory (which pulls in an amazing amount of other
jars) could I get a better result type...

Stefan

> Ewan.
Re: Java XML RPC with Xen-API? [ In reply to ]
On Mon, Apr 02, 2007 at 11:21:58PM -0400, Stefan Berger wrote:

> Ewan Mellor <ewan@xensource.com> wrote on 04/02/2007 05:40:26 PM:
>
> > On Mon, Apr 02, 2007 at 03:37:17PM -0400, Stefan Berger wrote:
> >
> > > Evan Bigall <evan.bigall@scalent.com> wrote on 04/02/2007 01:50:40 PM:
> > >
> > > > My "execute" method returns result.get("Value"), you should then be
> able
> > > > to cast that into a java Set, and iterate through all the key/value
> > > pairs.
> > >
> > > I would hope so, too, but it results in a ClassCastException. Which
> XML
> > > RPC library are you using and what version?
> >
> > Glancing through the Apache XML-RPC library, version 3, it looks
> > like you should
> > either be able to cast that to either an Object [], or failing that, a
> > List. Xen-API's Sets are marshalled as XML-RPC <array>s on the wire,
> and
> > it's up to the client library how to interpret that.
> >
> > If you call getClass() on the result, you can see what it's giving you
> > back.
> >
>
> Here is what is coming back:
>
> This first one is for estblishing the session -- works
>
> -->{Status=Success, Value=7f0a5d0b-c0ff-f948-36e5-cbad03caf24c}
> UUID: 7f0a5d0b-c0ff-f948-36e5-cbad03caf24c
>
> The VM.get_all returns a 'Set' -- only an Object comes back
>
> Calling VM.get_all(7f0a5d0b-c0ff-f948-36e5-cbad03caf24c,...)
> Returned object = {Status=Success, Value=[Ljava.lang.Object;@1faba46}
> 'Value' has type class [Ljava.lang.Object;

[Ljava.lang.Object means an Object[]. This is what I would expect. Each
element in that will be a String, so you will have to cast Value to Object [],
and then cast each element in that array to String (because object references
are strings on the wire).

Ewan.

_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
Re: Java XML RPC with Xen-API? [ In reply to ]
Ewan Mellor <ewan@xensource.com> wrote on 04/03/2007 05:14:37 AM:

> On Mon, Apr 02, 2007 at 11:21:58PM -0400, Stefan Berger wrote:
>
> > Ewan Mellor <ewan@xensource.com> wrote on 04/02/2007 05:40:26 PM:
> >

> >
> > Calling VM.get_all(7f0a5d0b-c0ff-f948-36e5-cbad03caf24c,...)
> > Returned object = {Status=Success, Value=[Ljava.lang.Object;@1faba46}
> > 'Value' has type class [Ljava.lang.Object;
>
> [Ljava.lang.Object means an Object[]. This is what I would expect. Each
> element in that will be a String, so you will have to cast Value to
Object [],
> and then cast each element in that array to String (because object
references
> are strings on the wire).

Yes, that's it. Thanks!

Stefan
>
> Ewan.