Feature #1544: Move configuration call to new System class, and add a method to check if the OCA and oned versions are compatible

This commit is contained in:
Carlos Martín authored and Tino Vazquez committed 2012-12-21 11:14:08 +01:00
1 parent ca96110b72
commit 58ad96203a
5 files changed
+135 -21

No files matched your search

@@ -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
//--------------------------------------------------------------------------
@@ -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
*
+20 -6
View File
@@ -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 );
}
}
-4
View File
@@ -172,9 +172,5 @@ module OpenNebula
def get_version()
call("system.version")
end
def get_config()
call("system.config")
end
end
end
+43 -1
View File
@@ -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