diff --git a/src/oca/java/src/org/opennebula/client/Client.java b/src/oca/java/src/org/opennebula/client/Client.java index 2fff759a34..7d4c87ad83 100644 --- a/src/oca/java/src/org/opennebula/client/Client.java +++ b/src/oca/java/src/org/opennebula/client/Client.java @@ -129,16 +129,6 @@ public class Client{ return call("system.version"); } - /** - * Calls OpenNebula and retrieves oned configuration - * - * @return The server's xml-rpc response encapsulated - */ - public OneResponse get_config() - { - return call("system.config"); - } - //-------------------------------------------------------------------------- // PRIVATE ATTRIBUTES AND METHODS //-------------------------------------------------------------------------- diff --git a/src/oca/java/src/org/opennebula/client/OneSystem.java b/src/oca/java/src/org/opennebula/client/OneSystem.java index d40aa83bae..88c61edf19 100644 --- a/src/oca/java/src/org/opennebula/client/OneSystem.java +++ b/src/oca/java/src/org/opennebula/client/OneSystem.java @@ -32,12 +32,84 @@ public class OneSystem private static final String GROUP_QUOTA_INFO = "groupquota.info"; private static final String GROUP_QUOTA_UPDATE = "groupquota.update"; + public static final String VERSION = "3.9.0"; public OneSystem(Client client) { this.client = client; } + /** + * Calls OpenNebula and retrieves the oned version + * + * @return The server's xml-rpc response encapsulated + */ + public OneResponse getOnedVersion() + { + return client.call("system.version"); + } + + /** + * Returns whether of not the oned version is the same as the OCA version + * + * @return true if oned is the same version + */ + public boolean compatibleVersion() + { + OneResponse r = getOnedVersion(); + + if (r.isError()) + { + return false; + } + + String[] ocaVersion = VERSION.split("\\.", 3); + String[] onedVersion = r.getMessage().split("\\.", 3); + + return ocaVersion.length == onedVersion.length && + ocaVersion[0].equals(onedVersion[0]) && + ocaVersion[1].equals(onedVersion[1]); + } + + /** + * Calls OpenNebula and retrieves oned configuration + * + * @return The server's xml-rpc response encapsulated + */ + public OneResponse getConfiguration() + { + return client.call("system.config"); + } + + /** + * Calls OpenNebula and retrieves oned configuration + * + * @return The xml root node in case of success, null otherwise + */ + public Node getConfigurationXML() + { + OneResponse r = getConfiguration(); + Node xml = null; + + if (r.isError()) + { + return null; + } + + try + { + DocumentBuilder builder = + DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = builder.parse( + new ByteArrayInputStream(r.getMessage().getBytes())); + + xml = doc.getDocumentElement(); + } + catch (Exception e) {} + + return xml; + } + /** * Gets the default user quota limits * diff --git a/src/oca/java/test/SessionTest.java b/src/oca/java/test/SessionTest.java index 2bb971162b..d6b94c6e2b 100644 --- a/src/oca/java/test/SessionTest.java +++ b/src/oca/java/test/SessionTest.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,6 +17,7 @@ import static org.junit.Assert.*; import org.junit.Test; import org.opennebula.client.*; +import org.w3c.dom.Node; public class SessionTest { @@ -51,7 +52,7 @@ public class SessionTest { } assertNull("Client should complain about misspelled url", oneClient); - } + } @Test public void version() @@ -63,11 +64,24 @@ public class SessionTest { } catch (Exception e) { - System.out.println(e.getMessage()); + assertTrue( e.getMessage(), false ); } - OneResponse res = oneClient.get_version(); + OneSystem system = new OneSystem(oneClient); + OneResponse res = system.getOnedVersion(); assertTrue( res.getErrorMessage(), !res.isError() ); + + res = system.getConfiguration(); + assertTrue( res.getErrorMessage(), !res.isError() ); + + Node config = system.getConfigurationXML(); + assertTrue( "XML configuration is null", config != null ); + + boolean compatible = system.compatibleVersion(); + assertTrue( + "Incompatible version reported, " + + OneSystem.VERSION + ", " + system.getOnedVersion().getMessage(), + compatible ); } } diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/OpenNebula.rb index a2e7f4f8ca..9e60d0be8f 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/OpenNebula.rb @@ -172,9 +172,5 @@ module OpenNebula def get_version() call("system.version") end - - def get_config() - call("system.config") - end end end diff --git a/src/oca/ruby/OpenNebula/System.rb b/src/oca/ruby/OpenNebula/System.rb index d7e0b1aa78..9092e0be85 100644 --- a/src/oca/ruby/OpenNebula/System.rb +++ b/src/oca/ruby/OpenNebula/System.rb @@ -27,7 +27,9 @@ module OpenNebula :userquotainfo => "userquota.info", :userquotaupdate => "userquota.update", :groupquotainfo => "groupquota.info", - :groupquotaupdate => "groupquota.update" + :groupquotaupdate => "groupquota.update", + :version => "system.version", + :config => "system.config" } ####################################################################### @@ -44,6 +46,46 @@ module OpenNebula # XML-RPC Methods ####################################################################### + # Gets the oned version + # + # @return [String, OpenNebula::Error] the oned version in case + # of success, Error otherwise + def get_oned_version() + return @client.call("system.version") + end + + # Returns whether of not the oned version is the same as the OCA version + # + # @return [true, false, OpenNebula::Error] true if oned is the same + # version + def compatible_version() + no_revision = VERSION[/^\d+\.\d+\./] + oned_v = get_oned_version + + if OpenNebula.is_error?(oned_v) + return oned_v + end + + return (oned_v =~ /#{no_revision}/) != nil + end + + # Gets the oned configuration + # + # @return [XMLElement, OpenNebula::Error] the oned configuration in case + # of success, Error otherwise + def get_configuration() + rc = @client.call(SYSTEM_METHODS[:config]) + + if OpenNebula.is_error?(rc) + return rc + end + + config = XMLElement.new + config.initialize_xml(rc, 'TEMPLATE') + + return config + end + # Gets the default user quota limits # # @return [XMLElement, OpenNebula::Error] the default user quota in case