mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 13:15:14 +09:00
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:
1 parent
085fa15535
commit
95e86aafce
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
|
||||
*
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user