From 727a77ea0d3e0edf19938636305d321267307dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 8 Jul 2011 19:18:07 +0200 Subject: [PATCH] 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. --- .../java/src/org/opennebula/client/Pool.java | 100 +++++++- .../org/opennebula/client/acl/AclPool.java | 15 +- .../opennebula/client/group/GroupPool.java | 20 +- .../org/opennebula/client/host/HostPool.java | 30 ++- .../opennebula/client/image/ImagePool.java | 181 +++++++++++++-- .../client/template/TemplatePool.java | 163 +++++++++++-- .../org/opennebula/client/user/UserPool.java | 38 ++- .../client/vm/VirtualMachinePool.java | 216 +++++++++++++++--- .../client/vnet/VirtualNetworkPool.java | 189 ++++++++++++--- src/oca/java/test/GroupTest.java | 3 +- src/oca/java/test/ImageTest.java | 3 +- src/oca/java/test/VirtualMachineTest.java | 3 +- 12 files changed, 829 insertions(+), 132 deletions(-) diff --git a/src/oca/java/src/org/opennebula/client/Pool.java b/src/oca/java/src/org/opennebula/client/Pool.java index 9bd7a85d8a..39391828d9 100644 --- a/src/oca/java/src/org/opennebula/client/Pool.java +++ b/src/oca/java/src/org/opennebula/client/Pool.java @@ -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 //ID diff --git a/src/oca/java/src/org/opennebula/client/acl/AclPool.java b/src/oca/java/src/org/opennebula/client/acl/AclPool.java index 22c6ddab1a..09c3b4f91b 100644 --- a/src/oca/java/src/org/opennebula/client/acl/AclPool.java +++ b/src/oca/java/src/org/opennebula/client/acl/AclPool.java @@ -40,7 +40,7 @@ public class AclPool extends Pool implements Iterable{ */ 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{ */ 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{ */ public OneResponse info() { - OneResponse response = info(client); - super.processInfo(response); - return response; + return super.info(); } public Iterator iterator() @@ -91,6 +89,13 @@ public class AclPool extends Pool implements Iterable{ 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); diff --git a/src/oca/java/src/org/opennebula/client/group/GroupPool.java b/src/oca/java/src/org/opennebula/client/group/GroupPool.java index 74038a2d4a..f05c0f3a86 100644 --- a/src/oca/java/src/org/opennebula/client/group/GroupPool.java +++ b/src/oca/java/src/org/opennebula/client/group/GroupPool.java @@ -40,7 +40,7 @@ public class GroupPool extends Pool implements Iterable{ */ 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{ */ 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{ */ public OneResponse info() { - OneResponse response = info(client); - super.processInfo(response); - return response; + return super.info(); } public Iterator iterator() @@ -90,4 +88,16 @@ public class GroupPool extends Pool implements Iterable{ 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); + } } diff --git a/src/oca/java/src/org/opennebula/client/host/HostPool.java b/src/oca/java/src/org/opennebula/client/host/HostPool.java index 30de30d744..6dac87fe6a 100644 --- a/src/oca/java/src/org/opennebula/client/host/HostPool.java +++ b/src/oca/java/src/org/opennebula/client/host/HostPool.java @@ -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{ */ 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{ /** * 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 iterator() @@ -90,4 +88,16 @@ public class HostPool extends Pool implements Iterable{ 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); + } } diff --git a/src/oca/java/src/org/opennebula/client/image/ImagePool.java b/src/oca/java/src/org/opennebula/client/image/ImagePool.java index a571ac33ab..ad5153c898 100644 --- a/src/oca/java/src/org/opennebula/client/image/ImagePool.java +++ b/src/oca/java/src/org/opennebula/client/image/ImagePool.java @@ -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 /** * 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: *
    - *
  • <= -2: All Images
  • - *
  • -1: Connected user's Images and public ones
  • + *
  • {@link Pool#ALL}: All Images
  • + *
  • {@link Pool#MINE}: Connected user's Images
  • + *
  • {@link Pool#MINE_GROUP}: Connected user's Images, and the ones in + * his group
  • *
  • >= 0: UID User's Images
  • *
*/ 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 } /** - * 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: *
    - *
  • <= -2: All Images
  • - *
  • -1: Connected user's Images and public ones
  • + *
  • {@link Pool#ALL}: All Images
  • + *
  • {@link Pool#MINE}: Connected user's Images
  • + *
  • {@link Pool#MINE_GROUP}: Connected user's Images, and the ones in + * his group
  • *
  • >= 0: UID User's Images
  • *
* @return If successful the message contains the string @@ -92,24 +96,139 @@ public class ImagePool extends Pool implements Iterable */ 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: + *
    + *
  • {@link Pool#ALL}: All Images
  • + *
  • {@link Pool#MINE}: Connected user's Images
  • + *
  • {@link Pool#MINE_GROUP}: Connected user's Images, and the ones in + * his group
  • + *
  • >= 0: UID User's Images
  • + *
+ * @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: + *
    + *
  • {@link Pool#ALL}: All Images
  • + *
  • {@link Pool#MINE}: Connected user's Images
  • + *
  • {@link Pool#MINE_GROUP}: Connected user's Images, and the ones in + * his group
  • + *
  • >= 0: UID User's Images
  • + *
+ * @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 iterator() @@ -129,4 +248,16 @@ public class ImagePool extends Pool implements Iterable 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); + } } diff --git a/src/oca/java/src/org/opennebula/client/template/TemplatePool.java b/src/oca/java/src/org/opennebula/client/template/TemplatePool.java index 4d95e5dcee..12c9a17495 100644 --- a/src/oca/java/src/org/opennebula/client/template/TemplatePool.java +++ b/src/oca/java/src/org/opennebula/client/template/TemplatePool.java @@ -37,7 +37,8 @@ public class TemplatePool extends Pool implements Iterable