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

Java OCA: Fix pool.info methods, there are new mandatory parameters in the xml-rpc calls.

Change the default filter flag from user 0 to MINE_GROUP.
This commit is contained in:
Carlos Martín 2011-07-08 19:18:07 +02:00
parent 7fb8b590bf
commit 727a77ea0d
12 changed files with 829 additions and 132 deletions

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

@ -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

@ -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

@ -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)