1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-20 10:50:08 +03:00

Merge branch 'master' of git.opennebula.org:one

This commit is contained in:
Ruben S. Montero 2011-07-08 20:01:55 +02:00
commit f444451d06
18 changed files with 1095 additions and 218 deletions

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
@ -19,6 +19,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
@ -41,15 +42,14 @@ public class Client{
//--------------------------------------------------------------------------
/**
* Creates a new xml-rpc client with default options:
* the auth. file will be assumed to be at $ONE_AUTH, and
* the endpoint will be set to $ONE_XMLRPC.
* <br/>
* Creates a new xml-rpc client with default options: the auth. file will be
* assumed to be at $ONE_AUTH, and the endpoint will be set to $ONE_XMLRPC. <br/>
* It is the equivalent of Client(null, null).
*
* @throws Exception if one authorization file cannot be located.
* @throws ClientConfigurationException
* if the default configuration options are invalid.
*/
public Client() throws Exception
public Client() throws ClientConfigurationException
{
setOneAuth(null);
setOneEndPoint(null);
@ -58,13 +58,16 @@ public class Client{
/**
* Creates a new xml-rpc client with specified options.
*
* @param secret A string containing the ONE user:password tuple.
* Can be null
* @param endpoint Where the rpc server is listening, must be something
* like "http://localhost:2633/RPC2". Can be null
* @throws Exception if the authorization options are invalid
* @param secret
* A string containing the ONE user:password tuple. Can be null
* @param endpoint
* Where the rpc server is listening, must be something like
* "http://localhost:2633/RPC2". Can be null
* @throws ClientConfigurationException
* if the configuration options are invalid
*/
public Client(String secret, String endpoint) throws Exception
public Client(String secret, String endpoint)
throws ClientConfigurationException
{
setOneAuth(secret);
setOneEndPoint(endpoint);
@ -129,7 +132,7 @@ public class Client{
private XmlRpcClient client;
private void setOneAuth(String secret) throws Exception
private void setOneAuth(String secret) throws ClientConfigurationException
{
String oneSecret = secret;
@ -157,7 +160,8 @@ public class Client{
if(token.length != 2 )
{
throw new Exception("Wrong format for authorization string: "
throw new ClientConfigurationException(
"Wrong format for authorization string: "
+ oneSecret + "\nFormat expected is user:password");
}
@ -182,15 +186,26 @@ public class Client{
}
catch (FileNotFoundException e)
{
throw new Exception("ONE_AUTH file not present");
// This comes first, since it is a special case of IOException
throw new ClientConfigurationException("ONE_AUTH file not present");
}
catch (IOException e)
{
// You could have the file but for some reason the program can not
// read it
throw new ClientConfigurationException("ONE_AUTH file unreadable");
}
catch (NoSuchAlgorithmException e)
{
throw new Exception("Error initializing MessageDigest with SHA-1");
// A client application cannot recover if the SHA-1 digest
// algorithm cannot be initialized
throw new RuntimeException(
"Error initializing MessageDigest with SHA-1", e);
}
}
private void setOneEndPoint(String endpoint) throws Exception
private void setOneEndPoint(String endpoint)
throws ClientConfigurationException
{
oneEndPoint = "http://localhost:2633/RPC2";
@ -216,7 +231,8 @@ public class Client{
}
catch (MalformedURLException e)
{
throw new Exception("The URL "+oneEndPoint+" is malformed.");
throw new ClientConfigurationException(
"The URL "+oneEndPoint+" is malformed.");
}
client = new XmlRpcClient();

View File

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client;
/**
* This exception is thrown when a a new Client is constructed with wrong
* authorization options.
*/
public class ClientConfigurationException extends OneException
{
private static final long serialVersionUID = -3220098130946406458L;
public ClientConfigurationException(String message)
{
super(message);
}
}

View File

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client;
/**
* The <code>OneException</code> class is a generic OpenNebula exception.
*/
public class OneException extends Exception
{
private static final long serialVersionUID = -2281517151282894589L;
public OneException(String message)
{
super(message);
}
}

View File

@ -37,16 +37,35 @@ public abstract class Pool{
protected Client client;
protected String elementName;
protected String infoMethod;
protected NodeList poolElements;
/**
* Sets the Pool attributes.
* All resources in the pool
*/
public final static int ALL = -2;
/**
* Connected user's resources
*/
public final static int MINE = -3;
/**
* Connected user's resources, and the ones in his group
*/
public final static int MINE_GROUP = -1;
/**
* Protected constructor, to be called from subclasses.
*
* @param elementName Name of the PoolElement's xml element
* @param client XML-RPC client which will handle calls
* @param infoMethod XML-RPC info method for the subclass Pool
*/
protected Pool(String elementName, Client client)
protected Pool(String elementName, Client client, String infoMethod)
{
this.elementName = elementName;
this.infoMethod = infoMethod;
this.client = client;
}
@ -59,6 +78,76 @@ public abstract class Pool{
*/
public abstract PoolElement factory(Node node);
/***************************************************************************
* Info methods
**************************************************************************/
protected static OneResponse info(Client client, String infoMethod)
{
return xmlrpcInfo(client, infoMethod);
}
protected static OneResponse info(Client client, String infoMethod,
int filter, int startId, int endId)
{
return xmlrpcInfo(client, infoMethod, filter, startId, endId);
}
protected static OneResponse infoAll(Client client, String infoMethod)
{
return xmlrpcInfo(client, infoMethod, ALL, -1, -1);
}
protected static OneResponse infoMine(Client client, String infoMethod)
{
return xmlrpcInfo(client, infoMethod, MINE, -1, -1);
}
protected static OneResponse infoGroup(Client client, String infoMethod)
{
return xmlrpcInfo(client, infoMethod, MINE_GROUP, -1, -1);
}
private static OneResponse xmlrpcInfo(Client client, String infoMethod, Object...args)
{
return client.call(infoMethod, args);
}
protected OneResponse info()
{
OneResponse response = info(client, infoMethod);
processInfo(response);
return response;
}
protected OneResponse infoAll()
{
OneResponse response = infoAll(client, infoMethod);
processInfo(response);
return response;
}
protected OneResponse infoMine()
{
OneResponse response = infoMine(client, infoMethod);
processInfo(response);
return response;
}
protected OneResponse infoGroup()
{
OneResponse response = infoGroup(client, infoMethod);
processInfo(response);
return response;
}
protected OneResponse info(int filter, int startId, int endId)
{
OneResponse response = info(client, infoMethod, filter, startId, endId);
processInfo(response);
return response;
}
/**
* After a *pool.info call, this method builds the internal xml
* representation of the pool.
@ -114,6 +203,13 @@ public abstract class Pool{
return theElement;
}
/**
* Returns the element with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the element to retrieve
* @return The element with the given Id, or null if it was not found.
*/
protected PoolElement getById(int id)
{
// TODO: Use xpath to find the element /<elementName>/ID

View File

@ -136,8 +136,10 @@ public class Acl extends PoolElement{
* @param rule a rule string, e.g. "#5 HOST+VM/@12 INFO+CREATE+DELETE"
* @return If successful the message contains the associated
* id generated for this rule.
* @throws RuleParseException If the rule syntax is wrong.
*/
public static OneResponse allocate(Client client, String rule)
throws RuleParseException
{
String[] components = parseRule(rule);
return allocate(client, components[0], components[1], components[2]);
@ -236,8 +238,9 @@ public class Acl extends PoolElement{
*
* @param rule an ACL rule in string format
* @return an Array containing 3 Strings (hex 64b numbers)
* @throws RuleParseException If the rule syntax is wrong.
*/
public static String[] parseRule(String rule)
public static String[] parseRule(String rule) throws RuleParseException
{
String [] ret = new String[3];
@ -245,8 +248,8 @@ public class Acl extends PoolElement{
if( components.length != 3 )
{
// TODO: throw "String needs three components: User, Resource, Rights"
return ret;
throw new RuleParseException(
"String needs three components: User, Resource, Rights");
}
ret[0] = parseUsers(components[0]);
@ -262,7 +265,7 @@ public class Acl extends PoolElement{
* @param users Users component string
* @return A string containing a hex number
*/
private static String parseUsers(String users)
private static String parseUsers(String users) throws RuleParseException
{
return Long.toHexString( calculateIds(users) );
}
@ -274,14 +277,14 @@ public class Acl extends PoolElement{
* @return A string containing a hex number
*/
private static String parseResources(String resources)
throws RuleParseException
{
long ret = 0;
String[] resourcesComponents = resources.split("/");
if( resourcesComponents.length != 2 )
{
// TODO: throw "Resource '#{resources}' malformed"
return "";
throw new RuleParseException("Resource '"+resources+"' malformed");
}
for( String resource : resourcesComponents[0].split("\\+") )
@ -290,7 +293,8 @@ public class Acl extends PoolElement{
if( !RESOURCES.containsKey(resource) )
{
// TODO: throw "Resource '#{resource}' does not exist"
throw new RuleParseException("Resource '" + resource
+ "' does not exist");
}
ret += RESOURCES.get(resource);
@ -307,7 +311,7 @@ public class Acl extends PoolElement{
* @param rights Rights component string
* @return A string containing a hex number
*/
private static String parseRights(String rights)
private static String parseRights(String rights) throws RuleParseException
{
long ret = 0;
@ -318,8 +322,8 @@ public class Acl extends PoolElement{
if( !RIGHTS.containsKey(right) )
{
// TODO throw "Right '#{right}' does not exist"
return "";
throw new RuleParseException("Right '" + right
+ "' does not exist");
}
ret += RIGHTS.get(right);
@ -335,12 +339,11 @@ public class Acl extends PoolElement{
* @param id Rule Id string
* @return the numeric value for the given id_str
*/
private static long calculateIds(String id)
private static long calculateIds(String id) throws RuleParseException
{
if( !id.matches("^([#@]\\d+|\\*)$") )
{
// TODO: throw "ID string '#{id_str}' malformed"
return 0;
throw new RuleParseException("ID string '" + id + "' malformed");
}
long value = USERS.get( "" + id.charAt(0) );

View File

@ -40,7 +40,7 @@ public class AclPool extends Pool implements Iterable<Acl>{
*/
public AclPool(Client client)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
}
@Override
@ -58,7 +58,7 @@ public class AclPool extends Pool implements Iterable<Acl>{
*/
public static OneResponse info(Client client)
{
return client.call(INFO_METHOD);
return Pool.info(client, INFO_METHOD);
}
/**
@ -68,9 +68,7 @@ public class AclPool extends Pool implements Iterable<Acl>{
*/
public OneResponse info()
{
OneResponse response = info(client);
super.processInfo(response);
return response;
return super.info();
}
public Iterator<Acl> iterator()
@ -91,6 +89,13 @@ public class AclPool extends Pool implements Iterable<Acl>{
return ab.iterator();
}
/**
* Returns the ACl rule with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the ACl rule to retrieve
* @return The ACl rule with the given Id, or null if it was not found.
*/
public Acl getById(int id)
{
return (Acl) super.getById(id);

View File

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.acl;
import org.opennebula.client.OneException;
public class RuleParseException extends OneException
{
private static final long serialVersionUID = 5992480039195389371L;
public RuleParseException(String message)
{
super(message);
}
}

View File

@ -40,7 +40,7 @@ public class GroupPool extends Pool implements Iterable<Group>{
*/
public GroupPool(Client client)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
}
@Override
@ -58,7 +58,7 @@ public class GroupPool extends Pool implements Iterable<Group>{
*/
public static OneResponse info(Client client)
{
return client.call(INFO_METHOD);
return Pool.info(client, INFO_METHOD);
}
/**
@ -68,9 +68,7 @@ public class GroupPool extends Pool implements Iterable<Group>{
*/
public OneResponse info()
{
OneResponse response = info(client);
super.processInfo(response);
return response;
return super.info();
}
public Iterator<Group> iterator()
@ -90,4 +88,16 @@ public class GroupPool extends Pool implements Iterable<Group>{
return ab.iterator();
}
/**
* Returns the Group with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the Group to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public Group getById(int id)
{
return (Group) super.getById(id);
}
}

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
@ -40,7 +40,7 @@ public class HostPool extends Pool implements Iterable<Host>{
*/
public HostPool(Client client)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
}
@Override
@ -51,26 +51,24 @@ public class HostPool extends Pool implements Iterable<Host>{
/**
* Retrieves all the hosts in the pool.
*
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client)
{
return client.call(INFO_METHOD);
return Pool.info(client, INFO_METHOD);
}
/**
* Loads the xml representation of the host pool.
*
*
* @see HostPool#info(Client)
*/
public OneResponse info()
{
OneResponse response = info(client);
super.processInfo(response);
return response;
return super.info();
}
public Iterator<Host> iterator()
@ -90,4 +88,16 @@ public class HostPool extends Pool implements Iterable<Host>{
return ab.iterator();
}
/**
* Returns the Host with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the Host to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public Host getById(int id)
{
return (Host) super.getById(id);
}
}

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
@ -37,33 +37,36 @@ public class ImagePool extends Pool implements Iterable<Image>
/**
* Creates a new Image pool with the default filter flag value
* set to 0 (Images belonging to user with UID 0)
*
* set to {@link Pool#MINE_GROUP} (Images belonging to the connected user,
* and the ones in his group)
*
* @param client XML-RPC Client.
*
*
* @see ImagePool#ImagePool(Client, int)
*/
public ImagePool(Client client)
{
super(ELEMENT_NAME, client);
this.filter = 0;
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = MINE_GROUP;
}
/**
* Creates a new Image pool.
*
*
* @param client XML-RPC Client.
* @param filter Filter flag used by default in the method
* @param filter Filter flag to use by default in the method
* {@link ImagePool#info()}. Possible values:
* <ul>
* <li><= -2: All Images</li>
* <li>-1: Connected user's Images and public ones</li>
* <li>{@link Pool#ALL}: All Images</li>
* <li>{@link Pool#MINE}: Connected user's Images</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Images, and the ones in
* his group</li>
* <li>>= 0: UID User's Images</li>
* </ul>
*/
public ImagePool(Client client, int filter)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = filter;
}
@ -77,14 +80,15 @@ public class ImagePool extends Pool implements Iterable<Image>
}
/**
* Retrieves all or part of the images in the pool.
*
* Retrieves all or part of the Images in the pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag used by default in the method
* {@link ImagePool#info()}. Possible values:
* @param filter Filter flag to use. Possible values:
* <ul>
* <li><= -2: All Images</li>
* <li>-1: Connected user's Images and public ones</li>
* <li>{@link Pool#ALL}: All Images</li>
* <li>{@link Pool#MINE}: Connected user's Images</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Images, and the ones in
* his group</li>
* <li>>= 0: UID User's Images</li>
* </ul>
* @return If successful the message contains the string
@ -92,24 +96,139 @@ public class ImagePool extends Pool implements Iterable<Image>
*/
public static OneResponse info(Client client, int filter)
{
return client.call(INFO_METHOD, filter);
return Pool.info(client, INFO_METHOD, filter, -1, -1);
}
/**
* Retrieves all the Images in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoAll(Client client)
{
return Pool.infoAll(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Images.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoMine(Client client)
{
return Pool.infoMine(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Images and the ones in
* his group.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoGroup(Client client)
{
return Pool.infoGroup(client, INFO_METHOD);
}
/**
* Retrieves all or part of the Images in the pool. The Images to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Images</li>
* <li>{@link Pool#MINE}: Connected user's Images</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Images, and the ones in
* his group</li>
* <li>>= 0: UID User's Images</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter,
int startId, int endId)
{
return Pool.info(client, INFO_METHOD, filter, startId, endId);
}
/**
* Loads the xml representation of all or part of the
* Images in the pool. The filter used is the one set in
* the constructor.
*
*
* @see ImagePool#info(Client, int)
*
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info()
{
OneResponse response = info(client, filter);
super.processInfo(response);
return response;
return super.info(filter, -1, -1);
}
/**
* Loads the xml representation of all the Images in the pool.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoAll()
{
return super.infoAll();
}
/**
* Loads the xml representation of all the connected user's Images.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoMine()
{
return super.infoMine();
}
/**
* Loads the xml representation of all the connected user's Images and
* the ones in his group.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoGroup()
{
return super.infoGroup();
}
/**
* Retrieves all or part of the Images in the pool. The Images to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Images</li>
* <li>{@link Pool#MINE}: Connected user's Images</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Images, and the ones in
* his group</li>
* <li>>= 0: UID User's Images</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info(int filter, int startId, int endId)
{
return super.info(filter, startId, endId);
}
public Iterator<Image> iterator()
@ -129,4 +248,16 @@ public class ImagePool extends Pool implements Iterable<Image>
return ab.iterator();
}
/**
* Returns the Image with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the Image to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public Image getById(int id)
{
return (Image) super.getById(id);
}
}

View File

@ -37,7 +37,8 @@ public class TemplatePool extends Pool implements Iterable<Template>
/**
* Creates a new Template pool with the default filter flag value
* set to 0 (Templates belonging to user with UID 0)
* set to {@link Pool#MINE_GROUP} (Template belonging to the connected user,
* and the ones in his group)
*
* @param client XML-RPC Client.
*
@ -45,25 +46,27 @@ public class TemplatePool extends Pool implements Iterable<Template>
*/
public TemplatePool(Client client)
{
super(ELEMENT_NAME, client);
this.filter = 0;
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = MINE_GROUP;
}
/**
* Creates a new Template pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag used by default in the method
* @param filter Filter flag to use by default in the method
* {@link TemplatePool#info()}. Possible values:
* <ul>
* <li><= -2: All Templates</li>
* <li>-1: Connected user's Templates and public ones</li>
* <li>{@link Pool#ALL}: All Templates</li>
* <li>{@link Pool#MINE}: Connected user's Templates</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Templates, and the ones in
* his group</li>
* <li>>= 0: UID User's Templates</li>
* </ul>
*/
public TemplatePool(Client client, int filter)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = filter;
}
@ -77,14 +80,15 @@ public class TemplatePool extends Pool implements Iterable<Template>
}
/**
* Retrieves all or part of the templates in the pool.
* Retrieves all or part of the Templates in the pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag used by default in the method
* {@link TemplatePool#info()}. Possible values:
* @param filter Filter flag to use. Possible values:
* <ul>
* <li><= -2: All Templates</li>
* <li>-1: Connected user's Templates and public ones</li>
* <li>{@link Pool#ALL}: All Templates</li>
* <li>{@link Pool#MINE}: Connected user's Templates</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Templates, and the ones in
* his group</li>
* <li>>= 0: UID User's Templates</li>
* </ul>
* @return If successful the message contains the string
@ -92,7 +96,68 @@ public class TemplatePool extends Pool implements Iterable<Template>
*/
public static OneResponse info(Client client, int filter)
{
return client.call(INFO_METHOD, filter);
return Pool.info(client, INFO_METHOD, filter, -1, -1);
}
/**
* Retrieves all the Templates in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoAll(Client client)
{
return Pool.infoAll(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Templates.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoMine(Client client)
{
return Pool.infoMine(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Templates and the ones in
* his group.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoGroup(Client client)
{
return Pool.infoGroup(client, INFO_METHOD);
}
/**
* Retrieves all or part of the Templates in the pool. The Templates to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Templates</li>
* <li>{@link Pool#MINE}: Connected user's Templates</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Templates, and the ones in
* his group</li>
* <li>>= 0: UID User's Templates</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter,
int startId, int endId)
{
return Pool.info(client, INFO_METHOD, filter, startId, endId);
}
/**
@ -107,9 +172,63 @@ public class TemplatePool extends Pool implements Iterable<Template>
*/
public OneResponse info()
{
OneResponse response = info(client, filter);
super.processInfo(response);
return response;
return super.info(filter, -1, -1);
}
/**
* Loads the xml representation of all the Templates in the pool.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoAll()
{
return super.infoAll();
}
/**
* Loads the xml representation of all the connected user's Templates.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoMine()
{
return super.infoMine();
}
/**
* Loads the xml representation of all the connected user's Templates and
* the ones in his group.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoGroup()
{
return super.infoGroup();
}
/**
* Retrieves all or part of the Templates in the pool. The Templates to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Templates</li>
* <li>{@link Pool#MINE}: Connected user's Templates</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Templates, and the ones in
* his group</li>
* <li>>= 0: UID User's Templates</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info(int filter, int startId, int endId)
{
return super.info(filter, startId, endId);
}
public Iterator<Template> iterator()
@ -129,4 +248,16 @@ public class TemplatePool extends Pool implements Iterable<Template>
return ab.iterator();
}
/**
* Returns the Template with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the ACl rule to retrieve
* @return The Template with the given Id, or null if it was not found.
*/
public Template getById(int id)
{
return (Template) super.getById(id);
}
}

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
@ -40,7 +40,7 @@ public class UserPool extends Pool implements Iterable<User>{
*/
public UserPool(Client client)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
}
@Override
@ -49,16 +49,24 @@ public class UserPool extends Pool implements Iterable<User>{
return new User(node, client);
}
/**
* Retrieves all the users in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client)
{
return Pool.info(client, INFO_METHOD);
}
/**
* Loads the xml representation of the user pool.
*/
public OneResponse info()
{
OneResponse response = client.call(INFO_METHOD);
super.processInfo(response);
return response;
return super.info();
}
public Iterator<User> iterator()
@ -78,4 +86,16 @@ public class UserPool extends Pool implements Iterable<User>{
return ab.iterator();
}
/**
* Returns the User with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the User to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public User getById(int id)
{
return (User) super.getById(id);
}
}

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
@ -34,37 +34,50 @@ public class VirtualMachinePool extends Pool implements Iterable<VirtualMachine>
private static final String ELEMENT_NAME = "VM";
private static final String INFO_METHOD = "vmpool.info";
private int filter;
/**
* Creates a new VM pool with the default filter flag value
* set to 0 (VMs belonging to user with UID 0)
*
* Flag for Virtual Machines in any state.
*/
public static final int ALL_VM = -2;
/**
* Flag for Virtual Machines in any state, except for DONE.
*/
public static final int NOT_DONE = -1;
private int filter;
/**
* Creates a new Virtual Machine pool with the default filter flag value
* set to {@link Pool#MINE_GROUP} (Virtual Machines belonging to the connected user,
* and the ones in his group)
*
* @param client XML-RPC Client.
*
*
* @see VirtualMachinePool#VirtualMachinePool(Client, int)
*/
public VirtualMachinePool(Client client)
{
super(ELEMENT_NAME, client);
this.filter = 0;
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = MINE_GROUP;
}
/**
* Creates a new VM pool.
*
* Creates a new Virtual Machine pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag used by default in the method
* @param filter Filter flag to use by default in the method
* {@link VirtualMachinePool#info()}. Possible values:
* <ul>
* <li><= -2: All VMs</li>
* <li>-1: Connected user's VMs</li>
* <li>>= 0: UID User's VMs</li>
* <li>{@link Pool#ALL}: All Virtual Machines</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Machines</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Machines, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Machines</li>
* </ul>
*/
public VirtualMachinePool(Client client, int filter)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = filter;
}
@ -74,38 +87,171 @@ public class VirtualMachinePool extends Pool implements Iterable<VirtualMachine>
return new VirtualMachine(node, client);
}
/**
* Retrieves all or part of the VMs in the pool.
*
* Retrieves all or part of the Virtual Machines in the pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag. Possible values:
* @param filter Filter flag to use. Possible values:
* <ul>
* <li><= -2: All VMs</li>
* <li>-1: Connected user's VMs</li>
* <li>>= 0: UID User's VMs</li>
* <li>{@link Pool#ALL}: All Virtual Machines</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Machines</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Machines, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Machines</li>
* </ul>
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter)
{
return client.call(INFO_METHOD, filter);
return client.call(INFO_METHOD, filter, -1, -1, NOT_DONE);
}
/**
* Retrieves all the Virtual Machines in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoAll(Client client)
{
return client.call(INFO_METHOD, ALL, -1, -1, NOT_DONE);
}
/**
* Retrieves all the connected user's Virtual Machines.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoMine(Client client)
{
return client.call(INFO_METHOD, MINE, -1, -1, NOT_DONE);
}
/**
* Retrieves all the connected user's Virtual Machines and the ones in
* his group.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoGroup(Client client)
{
return client.call(INFO_METHOD, MINE_GROUP, -1, -1, NOT_DONE);
}
/**
* Retrieves all or part of the Virtual Machines in the pool. The
* Virtual Machines to retrieve can be also filtered by Id, specifying the
* first and last Id to include; and by state.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Virtual Machines</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Machines</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Machines, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Machines</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @param state Numeric state of the Virtual Machines wanted, or one
* of {@link VirtualMachinePool#ALL_VM} or
* {@link VirtualMachinePool#NOT_DONE}
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter,
int startId, int endId, int state)
{
return client.call(INFO_METHOD, filter, startId, endId, state);
}
/**
* Loads the xml representation of all or part of the
* VMs in the pool. The filter used is the one set in
* Virtual Machines in the pool. The filter used is the one set in
* the constructor.
*
*
* @see VirtualMachinePool#info(Client, int)
*
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info()
{
OneResponse response = info(client, filter);
super.processInfo(response);
processInfo(response);
return response;
}
/**
* Loads the xml representation of all the Virtual Machines in the pool.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoAll()
{
OneResponse response = infoAll(client);
processInfo(response);
return response;
}
/**
* Loads the xml representation of all the connected user's Virtual Machines.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoMine()
{
OneResponse response = infoMine(client);
processInfo(response);
return response;
}
/**
* Loads the xml representation of all the connected user's Virtual Machines and
* the ones in his group.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoGroup()
{
OneResponse response = infoGroup(client);
processInfo(response);
return response;
}
/**
* Retrieves all or part of the Virtual Machines in the pool. The Virtual Machines to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Virtual Machines</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Machines</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Machines, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Machines</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @param state Numeric state of the Virtual Machines wanted
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info(int filter, int startId, int endId, int state)
{
OneResponse response = info(client, filter, startId, endId, state);
processInfo(response);
return response;
}
@ -126,4 +272,16 @@ public class VirtualMachinePool extends Pool implements Iterable<VirtualMachine>
return ab.iterator();
}
/**
* Returns the Virtual Machine with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the ACl rule to retrieve
* @return The Virtual Machine with the given Id, or null if it was not found.
*/
public VirtualMachine getById(int id)
{
return (VirtualMachine) super.getById(id);
}
}

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
@ -37,34 +37,37 @@ public class VirtualNetworkPool extends Pool implements Iterable<VirtualNetwork>
private int filter;
/**
* Creates a new VN pool with the default filter flag value
* set to 0 (VNs belonging to user with UID 0)
*
* Creates a new Virtual Network pool with the default filter flag value
* set to {@link Pool#MINE_GROUP} (Virtual Networks belonging to the connected user,
* and the ones in his group)
*
* @param client XML-RPC Client.
*
*
* @see VirtualNetworkPool#VirtualNetworkPool(Client, int)
*/
public VirtualNetworkPool(Client client)
{
super(ELEMENT_NAME, client);
this.filter = 0;
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = MINE_GROUP;
}
/**
* Creates a new VN pool.
*
* Creates a new Virtual Network pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag used by default in the method
* @param filter Filter flag to use by default in the method
* {@link VirtualNetworkPool#info()}. Possible values:
* <ul>
* <li><= -2: All VNs</li>
* <li>-1: Connected user's VNs</li>
* <li>>= 0: UID User's VNs</li>
* <li>{@link Pool#ALL}: All Virtual Networks</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Networks</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Networks, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Networks</li>
* </ul>
*/
public VirtualNetworkPool(Client client, int filter)
{
super(ELEMENT_NAME, client);
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = filter;
}
@ -75,37 +78,155 @@ public class VirtualNetworkPool extends Pool implements Iterable<VirtualNetwork>
}
/**
* Retrieves all or part of the VNs in the pool.
*
* Retrieves all or part of the Virtual Networks in the pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag. Possible values:
* @param filter Filter flag to use. Possible values:
* <ul>
* <li><= -2: All VNs</li>
* <li>-1: Connected user's VNs</li>
* <li>>= 0: UID User's VNs</li>
* <li>{@link Pool#ALL}: All Virtual Networks</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Networks</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Networks, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Networks</li>
* </ul>
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter)
{
return client.call(INFO_METHOD, filter);
return Pool.info(client, INFO_METHOD, filter, -1, -1);
}
/**
* Retrieves all the Virtual Networks in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoAll(Client client)
{
return Pool.infoAll(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Virtual Networks.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoMine(Client client)
{
return Pool.infoMine(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Virtual Networks and the ones in
* his group.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoGroup(Client client)
{
return Pool.infoGroup(client, INFO_METHOD);
}
/**
* Retrieves all or part of the Virtual Networks in the pool. The Virtual Networks to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Virtual Networks</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Networks</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Networks, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Networks</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter,
int startId, int endId)
{
return Pool.info(client, INFO_METHOD, filter, startId, endId);
}
/**
* Loads the xml representation of all or part of the
* VNs in the pool. The filter used is the one set in
* Virtual Networks in the pool. The filter used is the one set in
* the constructor.
*
*
* @see VirtualNetworkPool#info(Client, int)
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info()
{
OneResponse response = info(client, filter);
super.processInfo(response);
return response;
return super.info(filter, -1, -1);
}
/**
* Loads the xml representation of all the Virtual Networks in the pool.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoAll()
{
return super.infoAll();
}
/**
* Loads the xml representation of all the connected user's Virtual Networks.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoMine()
{
return super.infoMine();
}
/**
* Loads the xml representation of all the connected user's Virtual Networks and
* the ones in his group.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoGroup()
{
return super.infoGroup();
}
/**
* Retrieves all or part of the Virtual Networks in the pool. The Virtual Networks to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Virtual Networks</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Networks</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Networks, and the ones in
* his group</li>
* <li>>= 0: UID User's Virtual Networks</li>
* </ul>
* @param startId Lowest Id to retrieve
* @param endId Biggest Id to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info(int filter, int startId, int endId)
{
return super.info(filter, startId, endId);
}
public Iterator<VirtualNetwork> iterator()
@ -125,4 +246,16 @@ public class VirtualNetworkPool extends Pool implements Iterable<VirtualNetwork>
return ab.iterator();
}
/**
* Returns the Virtual Network with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the Virtual Network to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public VirtualNetwork getById(int id)
{
return (VirtualNetwork) super.getById(id);
}
}

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, 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.
@ -80,7 +80,7 @@ public class AclTest
{
res = aclPool.info();
assertTrue( !res.isError() );
assertEquals(1, aclPool.getLength());
}
@ -90,60 +90,67 @@ public class AclTest
// Allocate rule "#1 VM+HOST/@1 INFO+CREATE"
res = Acl.allocate(client, "0x100000001", "0x3200000001", "0x11");
assertTrue( !res.isError() );
aclPool.info();
acl = aclPool.getById( res.getIntMessage() );
assertNotNull(acl);
assertEquals(res.getIntMessage(), acl.id());
assertEquals(0x100000001L, acl.user());
assertEquals(0x3200000001L, acl.resource());
assertEquals(0x11L, acl.rights());
assertEquals("#1 VM+HOST/@1 CREATE+INFO", acl.toString());
}
@Test
public void numericAllocate()
{
// Allocate rule "#1 VM+HOST/@1 INFO+CREATE"
res = Acl.allocate(client, 0x100000001L, 214748364801L, 0x11L);
assertTrue( !res.isError() );
aclPool.info();
acl = aclPool.getById( res.getIntMessage() );
assertNotNull(acl);
assertEquals(res.getIntMessage(), acl.id());
assertEquals(0x100000001L, acl.user());
assertEquals(0x3200000001L, acl.resource());
assertEquals(0x11L, acl.rights());
assertEquals("#1 VM+HOST/@1 CREATE+INFO", acl.toString());
}
@Test
public void ruleAllocate()
{
res = Acl.allocate(client, "@507 IMAGE/#456 CREATE");
assertTrue( !res.isError() );
aclPool.info();
acl = aclPool.getById( res.getIntMessage() );
assertNotNull(acl);
try
{
res = Acl.allocate(client, "@507 IMAGE/#456 CREATE");
assertTrue( !res.isError() );
assertEquals(res.getIntMessage(), acl.id());
assertEquals(0x2000001fbL, acl.user());
assertEquals(0x81000001c8L, acl.resource());
assertEquals(0x1L, acl.rights());
assertEquals("@507 IMAGE/#456 CREATE", acl.toString());
aclPool.info();
acl = aclPool.getById( res.getIntMessage() );
assertNotNull(acl);
assertEquals(res.getIntMessage(), acl.id());
assertEquals(0x2000001fbL, acl.user());
assertEquals(0x81000001c8L, acl.resource());
assertEquals(0x1L, acl.rights());
assertEquals("@507 IMAGE/#456 CREATE", acl.toString());
}
catch (RuleParseException e)
{
assertTrue( false );
}
}
@Test
public void parseRules()
{
String[] rules = {
String[] rules = {
"#3 TEMPLATE/#0 INFO",
"#2 IMAGE/#0 INFO",
"@107 IMAGE+TEMPLATE/@100 INFO",
@ -158,7 +165,7 @@ public class AclTest
0x400000000L,
0x100000929L
};
long[] resources = {
0x20100000000L,
0x8100000000L,
@ -166,7 +173,7 @@ public class AclTest
0x29200000064L,
0x29400000000L
};
long[] rights = {
0x10L,
0x10L,
@ -177,37 +184,101 @@ public class AclTest
for( int i = 0; i < rules.length; i++ )
{
res = Acl.allocate(client, rules[i]);
assertTrue( !res.isError() );
aclPool.info();
acl = aclPool.getById( res.getIntMessage() );
assertNotNull(acl);
try
{
res = Acl.allocate(client, rules[i]);
assertTrue( !res.isError() );
assertEquals(res.getIntMessage(), acl.id());
assertEquals(users[i], acl.user());
assertEquals(resources[i], acl.resource());
assertEquals(rights[i], acl.rights());
aclPool.info();
acl = aclPool.getById( res.getIntMessage() );
assertNotNull(acl);
assertEquals(res.getIntMessage(), acl.id());
assertEquals(users[i], acl.user());
assertEquals(resources[i], acl.resource());
assertEquals(rights[i], acl.rights());
}
catch (RuleParseException e)
{
assertTrue(
"Rule " + rules[i]
+ " has been wrongly reported as invalid; "
+ e.getMessage(),
false);
}
}
assertTrue( true );
}
@Test
public void delete()
{
res = Acl.allocate(client, "#1 HOST/@2 INFO_POOL");
assertTrue( !res.isError() );
aclPool.info();
assertTrue( aclPool.getLength() == 2 );
try
{
res = Acl.allocate(client, "#1 HOST/@2 INFO_POOL");
assertTrue( !res.isError() );
res = Acl.delete(client, res.getIntMessage());
assertTrue( !res.isError() );
aclPool.info();
assertTrue( aclPool.getLength() == 1 );
aclPool.info();
assertTrue( aclPool.getLength() == 2 );
res = Acl.delete(client, res.getIntMessage());
assertTrue( !res.isError() );
aclPool.info();
assertTrue( aclPool.getLength() == 1 );
}
catch (RuleParseException e)
{
assertTrue(
"Rule has been wrongly reported as invalid; "
+ e.getMessage(),
false);
}
}
@Test
public void wrongRules()
{
String[] rules = {
"#-3 TEMPLATE/#0 INFO",
"#+3 TEMPLATE/#0 INFO",
"@3+ TEMPLATE/#0 INFO",
"*3 TEMPLATE/#0 INFO",
"# TEMPLATE/#0 INFO",
"@@ TEMPLATE/#0 INFO",
"@#3 TEMPLATE/#0 INFO",
"#3 TEMPLATE+HOS/#0 INFO",
"#3 /#0 INFO",
"#3 TEMPLATE/# INFO",
"#3 TEMPLATE/#5 INFO CREATE",
"#3 TEMPLATE/#5",
"#3 ",
"",
"#2 IMAGE @10654 INFO",
"#2 IMAGE/ INFO",
"#2 IMAGE#0 INFO",
"#2 IMAGE/# INFO",
"#2 IMAGE/@- INFO",
"#2 IMAGE/#0/#0 INFO",
"#2 IMAGE/#0/INFO CREATE",
"#2 IMAGE/#0/INFO+CREATE",
"#2 IMAGE/#0 IFO",
"#2 IMAGE/#0 INFO+CREAT",
};
for( int i = 0; i < rules.length; i++ )
{
try
{
res = Acl.allocate(client, rules[i]);
assertTrue( "Rule " + rules[i] +
" should have thrown an exception",
false);
}
catch (RuleParseException e)
{
}
}
}
}

View File

@ -132,7 +132,8 @@ public class GroupTest
assertTrue( !found );
}
@Test
// Commented out, secondary groups do not exist any more
// @Test
public void userGroupRelations()
{
Hashtable<String, User> users = new Hashtable<String, User>();

View File

@ -98,7 +98,8 @@ public class ImageTest
image = new Image(imgid, client);
imagePool.info();
res = imagePool.info();
assertTrue( !res.isError() );
boolean found = false;
for(Image img : imagePool)

View File

@ -127,7 +127,8 @@ public class VirtualMachineTest
@Test
public void allocate()
{
vmPool.info();
res = vmPool.info();
assertTrue( !res.isError() );
boolean found = false;
for(VirtualMachine vm : vmPool)