From 97fbc1bb4e5f624ab726087e1883015ced6c9e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 9 Jun 2016 16:19:24 +0200 Subject: [PATCH] Bug #4521: Update Java OCA to 5.0 --- .../java/share/examples/VMachineSample.java | 22 +- .../src/org/opennebula/client/Client.java | 2 +- .../java/src/org/opennebula/client/Pool.java | 15 +- .../src/org/opennebula/client/acl/Acl.java | 4 +- .../client/datastore/Datastore.java | 3 +- .../opennebula/client/document/Document.java | 4 +- .../client/document/DocumentPool.java | 8 +- .../src/org/opennebula/client/host/Host.java | 7 +- .../org/opennebula/client/image/Image.java | 7 +- .../opennebula/client/image/ImagePool.java | 8 +- .../client/marketplace/MarketPlace.java | 350 ++++++++++++ .../client/marketplace/MarketPlacePool.java | 103 ++++ .../client/marketplaceapp/MarketPlaceApp.java | 469 +++++++++++++++ .../marketplaceapp/MarketPlaceAppPool.java | 263 +++++++++ .../client/secgroup/SecurityGroup.java | 29 + .../client/secgroup/SecurityGroupPool.java | 8 +- .../opennebula/client/template/Template.java | 215 ++++++- .../client/template/TemplatePool.java | 8 +- .../src/org/opennebula/client/user/User.java | 4 +- .../opennebula/client/vm/VirtualMachine.java | 112 +--- .../client/vm/VirtualMachinePool.java | 12 +- .../client/vnet/VirtualNetworkPool.java | 8 +- .../client/vrouter/VirtualRouter.java | 50 ++ .../client/vrouter/VirtualRouterPool.java | 8 +- src/oca/java/test/AclTest.java | 8 +- src/oca/java/test/HostTest.java | 4 +- src/oca/java/test/VirtualMachineTest.java | 24 +- src/oca/java/test/VirtualNetworkTest.java | 4 + src/oca/java/test/VirtualRouterTest.java | 5 +- src/oca/java/test/all_tests.sh | 35 +- src/oca/java/test/oned.conf | 532 +++++++++++------- src/oca/java/test/test.sh | 3 + 32 files changed, 1931 insertions(+), 403 deletions(-) create mode 100644 src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java create mode 100644 src/oca/java/src/org/opennebula/client/marketplace/MarketPlacePool.java create mode 100644 src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java create mode 100644 src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceAppPool.java diff --git a/src/oca/java/share/examples/VMachineSample.java b/src/oca/java/share/examples/VMachineSample.java index 2a6672eb68..9922b6412a 100644 --- a/src/oca/java/share/examples/VMachineSample.java +++ b/src/oca/java/share/examples/VMachineSample.java @@ -43,10 +43,10 @@ public class VMachineSample{ // exist. String vmTemplate = "NAME = vm_from_java CPU = 0.1 MEMORY = 64\n" - + "DISK = [\n" - + "\tsource = \"/home/user/vmachines/ttylinux/ttylinux.img\",\n" - + "\ttarget = \"hda\",\n" - + "\treadonly = \"no\" ]\n" + + "#DISK = [\n" + + "#\tsource = \"/home/user/vmachines/ttylinux/ttylinux.img\",\n" + + "#\ttarget = \"hda\",\n" + + "#\treadonly = \"no\" ]\n" + "# NIC = [ NETWORK = \"Non existing network\" ]\n" + "FEATURES = [ acpi=\"no\" ]"; @@ -123,8 +123,8 @@ public class VMachineSample{ "\nThese are all the Virtual Machines in the pool:"); for ( VirtualMachine vmachine : vmPool ) { - System.out.println("\tID :" + vmachine.getId() + - ", Name :" + vmachine.getName() ); + System.out.println("\tID : " + vmachine.getId() + + ", Name : " + vmachine.getName() ); // Check if we have found the VM we are looking for if ( vmachine.getId().equals( ""+newVMID ) ) @@ -134,9 +134,9 @@ public class VMachineSample{ } // We have also some useful helpers for the actions you can perform - // on a virtual machine, like cancel: - rc = vm.cancel(); - System.out.println("\nTrying to cancel the VM " + vm.getId() + + // on a virtual machine, like suspend: + rc = vm.suspend(); + System.out.println("\nTrying to suspend the VM " + vm.getId() + " (should fail)..."); // This is all the information you can get from the OneResponse: @@ -145,8 +145,8 @@ public class VMachineSample{ System.out.println("\t Msg: " + rc.getMessage()); System.out.println("\t ErrMsg: " + rc.getErrorMessage()); - rc = vm.finalizeVM(); - System.out.println("\nTrying to finalize (delete) the VM " + + rc = vm.terminate(); + System.out.println("\nTrying to terminate the VM " + vm.getId() + "..."); System.out.println("\tOpenNebula response"); diff --git a/src/oca/java/src/org/opennebula/client/Client.java b/src/oca/java/src/org/opennebula/client/Client.java index fa6071ea7f..a2152a3b37 100644 --- a/src/oca/java/src/org/opennebula/client/Client.java +++ b/src/oca/java/src/org/opennebula/client/Client.java @@ -41,7 +41,7 @@ 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.
+ * assumed to be at $ONE_AUTH, and the endpoint will be set to $ONE_XMLRPC.
* It is the equivalent of Client(null, null). * * @throws ClientConfigurationException diff --git a/src/oca/java/src/org/opennebula/client/Pool.java b/src/oca/java/src/org/opennebula/client/Pool.java index 2a6dfb2f85..7d4a7fd62d 100644 --- a/src/oca/java/src/org/opennebula/client/Pool.java +++ b/src/oca/java/src/org/opennebula/client/Pool.java @@ -21,6 +21,10 @@ import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -40,6 +44,8 @@ public abstract class Pool{ protected String infoMethod; protected NodeList poolElements; + protected static XPath xpath; + /** * All resources in the pool */ @@ -67,6 +73,12 @@ public abstract class Pool{ this.elementName = elementName; this.infoMethod = infoMethod; this.client = client; + + if(xpath == null) + { + XPathFactory factory = XPathFactory.newInstance(); + xpath = factory.newXPath(); + } } /** @@ -171,11 +183,12 @@ public abstract class Pool{ new ByteArrayInputStream(info.getMessage().getBytes())); xml = doc.getDocumentElement(); - poolElements = xml.getElementsByTagName(elementName); + poolElements = (NodeList) xpath.evaluate(elementName, xml, XPathConstants.NODESET); } catch (ParserConfigurationException e) {} catch (SAXException e) {} catch (IOException e) {} + catch (XPathExpressionException e) {} } /** diff --git a/src/oca/java/src/org/opennebula/client/acl/Acl.java b/src/oca/java/src/org/opennebula/client/acl/Acl.java index 7d9e96adc5..ae526c54c7 100644 --- a/src/oca/java/src/org/opennebula/client/acl/Acl.java +++ b/src/oca/java/src/org/opennebula/client/acl/Acl.java @@ -28,10 +28,10 @@ import org.w3c.dom.Node; /** * This class represents an OpenNebula ACL rule. * It also offers static XML-RPC call wrappers. - *
+ *
* There is not a public constructor, because the information for an individual * ACL rule cannot be retrieved from OpenNebula. - *
+ *
* Instead, Acl objects should be obtained using AclPool.getById, after the * info method has been called. * diff --git a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java index 18dd3a0af6..0a11e6116f 100644 --- a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java +++ b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java @@ -73,7 +73,8 @@ public class Datastore extends PoolElement * * @param client XML-RPC Client. * @param description A string containing the template of the datastore. - * @param clusterId Id of the cluster + * @param clusterId Id of the cluster. If it is -1, this datastore + * won't be added to any cluster. * @return If successful the message contains the associated * id generated for this Datastore. */ diff --git a/src/oca/java/src/org/opennebula/client/document/Document.java b/src/oca/java/src/org/opennebula/client/document/Document.java index 6ba8a2819f..2be7b40dcd 100644 --- a/src/oca/java/src/org/opennebula/client/document/Document.java +++ b/src/oca/java/src/org/opennebula/client/document/Document.java @@ -24,9 +24,9 @@ import org.w3c.dom.Node; * This class represents an OpenNebula document. * Documents are generic objects. You can dynamically create new Pools in * OpenNebula, creating subclasses with different TYPE values. - *
+ *
* TYPE must be the same for the corresponding pool, see {@link DocumentPool} - *
+ *
* For example: *
  * 
diff --git a/src/oca/java/src/org/opennebula/client/document/DocumentPool.java b/src/oca/java/src/org/opennebula/client/document/DocumentPool.java
index 81218d7d2d..04ff054f72 100644
--- a/src/oca/java/src/org/opennebula/client/document/DocumentPool.java
+++ b/src/oca/java/src/org/opennebula/client/document/DocumentPool.java
@@ -25,9 +25,9 @@ import org.opennebula.client.Pool;
  * 

* Documents are generic objects. You can dynamically create new Pools in * OpenNebula, creating subclasses with different TYPE values. - *
+ *
* TYPE must be the same for the corresponding pool element, see {@link Document} - *
+ *
* For example: *
  * 
@@ -111,7 +111,7 @@ public abstract class DocumentPool extends Pool
      * 
  • {@link Pool#MINE}: Connected user's Documents
  • *
  • {@link Pool#MINE_GROUP}: Connected user's Documents, and the ones in * his group
  • - *
  • >= 0: UID User's Documents
  • + *
  • >= 0 UID User's Documents
  • * */ public DocumentPool(Client client, int filter) @@ -191,7 +191,7 @@ public abstract class DocumentPool extends Pool *
  • {@link Pool#MINE}: Connected user's Documents
  • *
  • {@link Pool#MINE_GROUP}: Connected user's Documents, and the ones in * his group
  • - *
  • >= 0: UID User's Documents
  • + *
  • >= 0 UID User's Documents
  • * * @param startId Lowest Id to retrieve * @param endId Biggest Id to retrieve diff --git a/src/oca/java/src/org/opennebula/client/host/Host.java b/src/oca/java/src/org/opennebula/client/host/Host.java index ab5c597d2a..93e855102b 100644 --- a/src/oca/java/src/org/opennebula/client/host/Host.java +++ b/src/oca/java/src/org/opennebula/client/host/Host.java @@ -161,8 +161,7 @@ public class Host extends PoolElement{ * * @param client XML-RPC Client. * @param id The host id (hid) of the target machine. - * @param enable If set true OpenNebula will enable the - * target host, if set false it will disable it. + * @param status Host status * @return A encapsulated response. */ public static OneResponse status(Client client, int id, Status status) @@ -319,7 +318,7 @@ public class Host extends PoolElement{ /** * Returns the state of the Host. - *
    + *
    * The method {@link Host#info()} must be called before. * * @return The state of the Host. @@ -332,7 +331,7 @@ public class Host extends PoolElement{ /** * Returns the short length string state of the Host. - *
    + *
    * The method {@link Host#info()} must be called before. * * @return The short length string state of the Host. diff --git a/src/oca/java/src/org/opennebula/client/image/Image.java b/src/oca/java/src/org/opennebula/client/image/Image.java index 665030136d..efa4caa8bc 100644 --- a/src/oca/java/src/org/opennebula/client/image/Image.java +++ b/src/oca/java/src/org/opennebula/client/image/Image.java @@ -85,8 +85,7 @@ public class Image extends PoolElement * * @param client XML-RPC Client. * @param description A string containing the template of the image. - * @param datastoreId The cluster ID. If it is -1, this image - * won't be added to any cluster. + * @param datastoreId The Datastore ID * * @return If successful the message contains the associated * id generated for this Image. @@ -629,7 +628,7 @@ public class Image extends PoolElement /** * Returns the state of the Image. - *
    + *
    * The method {@link Image#info()} must be called before. * * @return The state of the Image. @@ -642,7 +641,7 @@ public class Image extends PoolElement /** * Returns the short length string state of the Image. - *
    + *
    * The method {@link Image#info()} must be called before. * * @return The short length string state of the Image. 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 f55a34fa2a..d2b72bb166 100644 --- a/src/oca/java/src/org/opennebula/client/image/ImagePool.java +++ b/src/oca/java/src/org/opennebula/client/image/ImagePool.java @@ -61,7 +61,7 @@ public class ImagePool extends Pool implements Iterable *
  • {@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
  • + *
  • >= 0 UID User's Images
  • * */ public ImagePool(Client client, int filter) @@ -89,7 +89,7 @@ public class ImagePool extends Pool implements Iterable *
  • {@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
  • + *
  • >= 0 UID User's Images
  • * * @return If successful the message contains the string * with the information returned by OpenNebula. @@ -147,7 +147,7 @@ public class ImagePool extends Pool implements Iterable *
  • {@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
  • + *
  • >= 0 UID User's Images
  • * * @param startId Lowest Id to retrieve * @param endId Biggest Id to retrieve @@ -219,7 +219,7 @@ public class ImagePool extends Pool implements Iterable *
  • {@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
  • + *
  • >= 0 UID User's Images
  • * * @param startId Lowest Id to retrieve * @param endId Biggest Id to retrieve diff --git a/src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java b/src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java new file mode 100644 index 0000000000..837e921084 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java @@ -0,0 +1,350 @@ +/******************************************************************************* + * Copyright 2002-2016, OpenNebula Project, OpenNebula Systems + * + * 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.marketplace; + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula MarketPlace. + * It also offers static XML-RPC call wrappers. + */ +public class MarketPlace extends PoolElement +{ + + private static final String METHOD_PREFIX = "market."; + private static final String INFO = METHOD_PREFIX + "info"; + private static final String ALLOCATE = METHOD_PREFIX + "allocate"; + private static final String DELETE = METHOD_PREFIX + "delete"; + private static final String UPDATE = METHOD_PREFIX + "update"; + private static final String CHOWN = METHOD_PREFIX + "chown"; + private static final String CHMOD = METHOD_PREFIX + "chmod"; + private static final String RENAME = METHOD_PREFIX + "rename"; + + /** + * Creates a new MarketPlace representation. + * @param id The MarketPlace id. + * @param client XML-RPC Client. + */ + public MarketPlace(int id, Client client) + { + super(id, client); + } + + /** + * @see PoolElement + */ + protected MarketPlace(Node xmlElement, Client client) + { + super(xmlElement, client); + } + + // ================================= + // Static XML-RPC methods + // ================================= + + /** + * Allocates a new MarketPlace in OpenNebula. + * + * @param client XML-RPC Client. + * @param description A string containing the template of the MarketPlace. + * @return If successful the message contains the associated + * id generated for this MarketPlace. + */ + public static OneResponse allocate(Client client, String description) + { + return client.call(ALLOCATE, description); + } + + /** + * Retrieves the information of the given MarketPlace. + * + * @param client XML-RPC Client. + * @param id The MarketPlace id to retrieve the information from + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public static OneResponse info(Client client, int id) + { + return client.call(INFO, id); + } + + /** + * Deletes a MarketPlace from OpenNebula. + * + * @param client XML-RPC Client. + * @param id The id of the target MarketPlace we want to delete. + * @return A encapsulated response. + */ + public static OneResponse delete(Client client, int id) + { + return client.call(DELETE, id); + } + + /** + * Replaces the MarketPlace contents. + * + * @param client XML-RPC Client. + * @param id The id of the target MarketPlace we want to modify. + * @param new_template New MarketPlace contents. + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the MarketPlace id. + */ + public static OneResponse update(Client client, int id, String new_template, + boolean append) + { + return client.call(UPDATE, id, new_template, append ? 1 : 0); + } + + /** + * Changes the owner/group + * + * @param client XML-RPC Client. + * @param id The id of the target MarketPlace we want to modify. + * @param uid The new owner user ID. Set it to -1 to leave the current one. + * @param gid The new group ID. Set it to -1 to leave the current one. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chown(Client client, int id, int uid, int gid) + { + return client.call(CHOWN, id, uid, gid); + } + + /** + * Changes the MarketPlace permissions + * + * @param client XML-RPC Client. + * @param id The id of the target MarketPlace. + * @param owner_u 1 to allow, 0 deny, -1 do not change + * @param owner_m 1 to allow, 0 deny, -1 do not change + * @param owner_a 1 to allow, 0 deny, -1 do not change + * @param group_u 1 to allow, 0 deny, -1 do not change + * @param group_m 1 to allow, 0 deny, -1 do not change + * @param group_a 1 to allow, 0 deny, -1 do not change + * @param other_u 1 to allow, 0 deny, -1 do not change + * @param other_m 1 to allow, 0 deny, -1 do not change + * @param other_a 1 to allow, 0 deny, -1 do not change + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, + int owner_u, int owner_m, int owner_a, + int group_u, int group_m, int group_a, + int other_u, int other_m, int other_a) + { + return chmod(client, CHMOD, id, + owner_u, owner_m, owner_a, + group_u, group_m, group_a, + other_u, other_m, other_a); + } + + /** + * Changes the permissions + * + * @param client XML-RPC Client. + * @param id The id of the target object. + * @param octet Permissions octet, e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, String octet) + { + return chmod(client, CHMOD, id, octet); + } + + /** + * Changes the permissions + * + * @param client XML-RPC Client. + * @param id The id of the target object. + * @param octet Permissions octed , e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, int octet) + { + return chmod(client, CHMOD, id, octet); + } + + /** + * Renames this MarketPlace. + * + * @param client XML-RPC Client. + * @param id The id of the target object. + * @param name New name for the MarketPlace + * @return If successful the message contains the MarketPlace id. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + + // ================================= + // Instanced object XML-RPC methods + // ================================= + + /** + * Retrieves the information of the MarketPlace. + * + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public OneResponse info() + { + OneResponse response = info(client, id); + super.processInfo(response); + return response; + } + + /** + * Deletes the MarketPlace from OpenNebula. + * + * @return A encapsulated response. + */ + public OneResponse delete() + { + return delete(client, id); + } + + /** + * Replaces the MarketPlace template. + * + * @param new_template New MarketPlace template. + * @return If successful the message contains the MarketPlace id. + */ + public OneResponse update(String new_template) + { + return update(new_template, false); + } + + /** + * Replaces the MarketPlace template. + * + * @param new_template New MarketPlace template. + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the MarketPlace id. + */ + public OneResponse update(String new_template, boolean append) + { + return update(client, id, new_template, append); + } + + /** + * Changes the owner/group + * + * @param uid The new owner user ID. Set it to -1 to leave the current one. + * @param gid The new group ID. Set it to -1 to leave the current one. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chown(int uid, int gid) + { + return chown(client, id, uid, gid); + } + + /** + * Changes the owner + * + * @param uid The new owner user ID. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chown(int uid) + { + return chown(uid, -1); + } + + /** + * Changes the group + * + * @param gid The new group ID. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chgrp(int gid) + { + return chown(-1, gid); + } + + /** + * Changes the MarketPlace permissions + * + * @param owner_u 1 to allow, 0 deny, -1 do not change + * @param owner_m 1 to allow, 0 deny, -1 do not change + * @param owner_a 1 to allow, 0 deny, -1 do not change + * @param group_u 1 to allow, 0 deny, -1 do not change + * @param group_m 1 to allow, 0 deny, -1 do not change + * @param group_a 1 to allow, 0 deny, -1 do not change + * @param other_u 1 to allow, 0 deny, -1 do not change + * @param other_m 1 to allow, 0 deny, -1 do not change + * @param other_a 1 to allow, 0 deny, -1 do not change + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(int owner_u, int owner_m, int owner_a, + int group_u, int group_m, int group_a, + int other_u, int other_m, int other_a) + { + return chmod(client, id, + owner_u, owner_m, owner_a, + group_u, group_m, group_a, + other_u, other_m, other_a); + } + + /** + * Changes the permissions + * + * @param octet Permissions octed , e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(String octet) + { + return chmod(client, id, octet); + } + + /** + * Changes the permissions + * + * @param octet Permissions octed , e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(int octet) + { + return chmod(client, id, octet); + } + + /** + * Renames this MarketPlace + * + * @param name New name for the MarketPlace. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + + // ================================= + // Helpers + // ================================= + + /** + * Returns whether or not the App is part of this MarketPlace + * + * @param id The App ID. + * @return Whether or not the App is part of this MarketPlace. + */ + public boolean contains(int id) + { + String res = xpath("MARKETPLACEAPPS/ID[.="+id+"]"); + return res != null && res.equals(""+id); + } +} diff --git a/src/oca/java/src/org/opennebula/client/marketplace/MarketPlacePool.java b/src/oca/java/src/org/opennebula/client/marketplace/MarketPlacePool.java new file mode 100644 index 0000000000..54b50d3295 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/marketplace/MarketPlacePool.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright 2002-2016, OpenNebula Project, OpenNebula Systems + * + * 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.marketplace; + +import java.util.AbstractList; +import java.util.Iterator; + + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.Pool; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula MarketPlace pool. + * It also offers static XML-RPC call wrappers. + */ +public class MarketPlacePool extends Pool implements Iterable{ + + private static final String ELEMENT_NAME = "MARKETPLACE"; + private static final String INFO_METHOD = "marketpool.info"; + + /** + * Creates a new MarketPlace pool + * @param client XML-RPC Client. + */ + public MarketPlacePool(Client client) + { + super(ELEMENT_NAME, client, INFO_METHOD); + } + + @Override + public PoolElement factory(Node node) + { + return new MarketPlace(node, client); + } + + /** + * Retrieves all the MarketPlaces 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 MarketPlace pool. + * + * @see MarketPlacePool#info(Client) + */ + public OneResponse info() + { + return super.info(); + } + + public Iterator iterator() + { + AbstractList ab = new AbstractList() + { + public int size() + { + return getLength(); + } + + public MarketPlace get(int index) + { + return (MarketPlace) item(index); + } + }; + + return ab.iterator(); + } + + /** + * Returns the MarketPlace with the given Id from the pool. If it is not found, + * then returns null. The method {@link #info()} must be called before. + * + * @param id of the MarketPlace to retrieve + * @return The Image with the given Id, or null if it was not found. + */ + public MarketPlace getById(int id) + { + return (MarketPlace) super.getById(id); + } +} diff --git a/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java b/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java new file mode 100644 index 0000000000..bb8f214151 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java @@ -0,0 +1,469 @@ +/******************************************************************************* + * Copyright 2002-2016, OpenNebula Project, OpenNebula Systems + * + * 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.marketplaceapp; + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula MarketPlaceApp. + * It also offers static XML-RPC call wrappers. + */ +public class MarketPlaceApp extends PoolElement +{ + + private static final String METHOD_PREFIX = "marketapp."; + private static final String ALLOCATE = METHOD_PREFIX + "allocate"; + private static final String INFO = METHOD_PREFIX + "info"; + private static final String DELETE = METHOD_PREFIX + "delete"; + private static final String UPDATE = METHOD_PREFIX + "update"; + private static final String ENABLE = METHOD_PREFIX + "enable"; + private static final String CHOWN = METHOD_PREFIX + "chown"; + private static final String CHMOD = METHOD_PREFIX + "chmod"; + private static final String RENAME = METHOD_PREFIX + "rename"; + + private static final String[] MARKETPLACEAPP_STATES = + {"INIT", "READY", "LOCKED", "ERROR", "DISABLED"}; + + private static final String[] SHORT_MARKETPLACEAPP_STATES = + {"ini", "rdy", "lck", "err", "dis"}; + + private static final String[] MARKETPLACEAPP_TYPES = + {"UNKNOWN", "IMAGE", "VMTEMPLATE", "SERVICE_TEMPLATE"}; + + private static final String[] SHORT_MARKETPLACEAPP_TYPES = + {"unk", "img", "tpl", "srv"}; + + /** + * Creates a new MarketPlaceApp representation. + * @param id The MarketPlaceApp id. + * @param client XML-RPC Client. + */ + public MarketPlaceApp(int id, Client client) + { + super(id, client); + } + + /** + * @see PoolElement + */ + protected MarketPlaceApp(Node xmlElement, Client client) + { + super(xmlElement, client); + } + + // ================================= + // Static XML-RPC methods + // ================================= + + /** + * Allocates a new MarketPlaceApp in OpenNebula. + * + * @param client XML-RPC Client. + * @param description A string containing the template of the MarketPlaceApp. + * @param marketId The MarketPlace ID + * + * @return If successful the message contains the associated + * id generated for this MarketPlaceApp. + */ + public static OneResponse allocate( + Client client, + String description, + int marketId) + { + return client.call(ALLOCATE, description, marketId); + } + + /** + * Retrieves the information of the given MarketPlaceApp. + * + * @param client XML-RPC Client. + * @param id The MarketPlaceApp id for the MarketPlaceApp to retrieve the information from + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public static OneResponse info(Client client, int id) + { + return client.call(INFO, id); + } + + /** + * Deletes an MarketPlaceApp from OpenNebula. + * + * @param client XML-RPC Client. + * @param id The MarketPlaceApp id of the target MarketPlaceApp we want to delete. + * @return A encapsulated response. + */ + public static OneResponse delete(Client client, int id) + { + return client.call(DELETE, id); + } + + /** + * Replaces the template contents. + * + * @param client XML-RPC Client. + * @param id The MarketPlaceApp id of the target MarketPlaceApp we want to modify. + * @param new_template New template contents + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the MarketPlaceApp id. + */ + public static OneResponse update(Client client, int id, String new_template, + boolean append) + { + return client.call(UPDATE, id, new_template, append ? 1 : 0); + } + + /** + * Enables or disables an MarketPlaceApp. + * + * @param client XML-RPC Client. + * @param id The MarketPlaceApp id of the target MarketPlaceApp we want to modify. + * @param enable True for enabling, false for disabling. + * @return If successful the message contains the MarketPlaceApp id. + */ + public static OneResponse enable(Client client, int id, boolean enable) + { + return client.call(ENABLE, id, enable); + } + + /** + * Changes the owner/group + * + * @param client XML-RPC Client. + * @param id The MarketPlaceApp id of the target MarketPlaceApp we want to modify. + * @param uid The new owner user ID. Set it to -1 to leave the current one. + * @param gid The new group ID. Set it to -1 to leave the current one. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chown(Client client, int id, int uid, int gid) + { + return client.call(CHOWN, id, uid, gid); + } + + /** + * Changes the MarketPlaceApp permissions + * + * @param client XML-RPC Client. + * @param id The MarketPlaceApp id of the target MarketPlaceApp we want to modify. + * @param owner_u 1 to allow, 0 deny, -1 do not change + * @param owner_m 1 to allow, 0 deny, -1 do not change + * @param owner_a 1 to allow, 0 deny, -1 do not change + * @param group_u 1 to allow, 0 deny, -1 do not change + * @param group_m 1 to allow, 0 deny, -1 do not change + * @param group_a 1 to allow, 0 deny, -1 do not change + * @param other_u 1 to allow, 0 deny, -1 do not change + * @param other_m 1 to allow, 0 deny, -1 do not change + * @param other_a 1 to allow, 0 deny, -1 do not change + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, + int owner_u, int owner_m, int owner_a, + int group_u, int group_m, int group_a, + int other_u, int other_m, int other_a) + { + return chmod(client, CHMOD, id, + owner_u, owner_m, owner_a, + group_u, group_m, group_a, + other_u, other_m, other_a); + } + + /** + * Changes the permissions + * + * @param client XML-RPC Client. + * @param id The id of the target object. + * @param octet Permissions octed , e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, String octet) + { + return chmod(client, CHMOD, id, octet); + } + + /** + * Changes the permissions + * + * @param client XML-RPC Client. + * @param id The id of the target object. + * @param octet Permissions octed , e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, int octet) + { + return chmod(client, CHMOD, id, octet); + } + + /** + * Renames this MarketPlaceApp + * + * @param client XML-RPC Client. + * @param id The MarketPlaceApp id of the target MarketPlaceApp. + * @param name New name for the MarketPlaceApp. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + + // ================================= + // Instanced object XML-RPC methods + // ================================= + + /** + * Retrieves the information of the MarketPlaceApp. + * + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public OneResponse info() + { + OneResponse response = info(client, id); + super.processInfo(response); + return response; + } + + /** + * Deletes the MarketPlaceApp from OpenNebula. + * + * @return A encapsulated response. + */ + public OneResponse delete() + { + return delete(client, id); + } + + /** + * Replaces the template contents. + * + * @param new_template New template contents + * @return If successful the message contains the MarketPlaceApp id. + */ + public OneResponse update(String new_template) + { + return update(new_template, false); + } + + /** + * Replaces the template contents. + * + * @param new_template New template contents + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the MarketPlaceApp id. + */ + public OneResponse update(String new_template, boolean append) + { + return update(client, id, new_template, append); + } + + /** + * Enables or disables the MarketPlaceApp. + * + * @param enable True for enabling, false for disabling. + * @return If successful the message contains the MarketPlaceApp id. + */ + public OneResponse enable(boolean enable) + { + return enable(client, id, enable); + } + + /** + * Enables the MarketPlaceApp. + * + * @return If successful the message contains the MarketPlaceApp id. + */ + public OneResponse enable() + { + return enable(true); + } + + /** + * Disables the MarketPlaceApp. + * + * @return If successful the message contains the MarketPlaceApp id. + */ + public OneResponse disable() + { + return enable(false); + } + + /** + * Changes the owner/group + * + * @param uid The new owner user ID. Set it to -1 to leave the current one. + * @param gid The new group ID. Set it to -1 to leave the current one. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chown(int uid, int gid) + { + return chown(client, id, uid, gid); + } + + /** + * Changes the owner + * + * @param uid The new owner user ID. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chown(int uid) + { + return chown(uid, -1); + } + + /** + * Changes the group + * + * @param gid The new group ID. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chgrp(int gid) + { + return chown(-1, gid); + } + + /** + * Changes the MarketPlaceApp permissions + * + * @param owner_u 1 to allow, 0 deny, -1 do not change + * @param owner_m 1 to allow, 0 deny, -1 do not change + * @param owner_a 1 to allow, 0 deny, -1 do not change + * @param group_u 1 to allow, 0 deny, -1 do not change + * @param group_m 1 to allow, 0 deny, -1 do not change + * @param group_a 1 to allow, 0 deny, -1 do not change + * @param other_u 1 to allow, 0 deny, -1 do not change + * @param other_m 1 to allow, 0 deny, -1 do not change + * @param other_a 1 to allow, 0 deny, -1 do not change + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(int owner_u, int owner_m, int owner_a, + int group_u, int group_m, int group_a, + int other_u, int other_m, int other_a) + { + return chmod(client, id, + owner_u, owner_m, owner_a, + group_u, group_m, group_a, + other_u, other_m, other_a); + } + + /** + * Changes the permissions + * + * @param octet Permissions octed , e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(String octet) + { + return chmod(client, id, octet); + } + + /** + * Changes the permissions + * + * @param octet Permissions octed , e.g. 640 + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(int octet) + { + return chmod(client, id, octet); + } + + /** + * Renames this MarketPlaceApp + * + * @param name New name for the MarketPlaceApp. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + + // ================================= + // Helpers + // ================================= + + /** + * Returns the state of the MarketPlaceApp. + *
    + * The method {@link MarketPlaceApp#info()} must be called before. + * + * @return The state of the MarketPlaceApp. + */ + public String stateString() + { + int state = state(); + return state != -1 ? MARKETPLACEAPP_STATES[state] : null; + } + + /** + * Returns the short length string state of the MarketPlaceApp. + *
    + * The method {@link MarketPlaceApp#info()} must be called before. + * + * @return The short length string state of the MarketPlaceApp. + */ + public String shortStateStr() + { + int state = state(); + return state != -1 ? SHORT_MARKETPLACEAPP_STATES[state] : null; + } + + /** + * Returns the type of the MarketPlaceApp. + * + * @return The type of the MarketPlaceApp. + */ + public int type() + { + String state = xpath("TYPE"); + return state != null ? Integer.parseInt( state ) : -1; + } + + /** + * Returns the type of the MarketPlaceApp as a String. + * + * @return The type of the MarketPlaceApp as a String. + */ + public String typeStr() + { + int type = type(); + return type != -1 ? MARKETPLACEAPP_TYPES[type] : null; + } + + /** + * Returns the type of the MarketPlaceApp as a short String. + * + * @return The type of the MarketPlaceApp as a short String. + */ + public String shortTypeStr() + { + int type = type(); + return type != -1 ? SHORT_MARKETPLACEAPP_TYPES[type] : null; + } + + /** + * Returns true if the MarketPlaceApp is enabled. + * + * @return True if the MarketPlaceApp is enabled. + */ + public boolean isEnabled() + { + return state() != 3; + } +} diff --git a/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceAppPool.java b/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceAppPool.java new file mode 100644 index 0000000000..8c7ac967a0 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceAppPool.java @@ -0,0 +1,263 @@ +/******************************************************************************* + * Copyright 2002-2016, OpenNebula Project, OpenNebula Systems + * + * 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.marketplaceapp; + +import java.util.AbstractList; +import java.util.Iterator; + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.Pool; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula MarketPlaceApp pool. + * It also offers static XML-RPC call wrappers. + */ +public class MarketPlaceAppPool extends Pool implements Iterable +{ + private static final String ELEMENT_NAME = "MARKETPLACEAPP"; + private static final String INFO_METHOD = "marketapppool.info"; + + private int filter; + + /** + * Creates a new MarketPlaceApp pool with the default filter flag value + * set to {@link Pool#MINE_GROUP} (MarketPlaceApps belonging to the connected user, + * and the ones in his group) + * + * @param client XML-RPC Client. + * + * @see MarketPlaceAppPool#MarketPlaceAppPool(Client, int) + */ + public MarketPlaceAppPool(Client client) + { + super(ELEMENT_NAME, client, INFO_METHOD); + this.filter = MINE_GROUP; + } + + /** + * Creates a new MarketPlaceApp pool. + * + * @param client XML-RPC Client. + * @param filter Filter flag to use by default in the method + * {@link MarketPlaceAppPool#info()}. Possible values: + *
      + *
    • {@link Pool#ALL}: All MarketPlaceApps
    • + *
    • {@link Pool#MINE}: Connected user's MarketPlaceApps
    • + *
    • {@link Pool#MINE_GROUP}: Connected user's MarketPlaceApps, and the ones in + * his group
    • + *
    • >= 0 UID User's MarketPlaceApps
    • + *
    + */ + public MarketPlaceAppPool(Client client, int filter) + { + super(ELEMENT_NAME, client, INFO_METHOD); + this.filter = filter; + } + + /* (non-Javadoc) + * @see org.opennebula.client.Pool#factory(org.w3c.dom.Node) + */ + @Override + public PoolElement factory(Node node) + { + return new MarketPlaceApp(node, client); + } + + /** + * Retrieves all or part of the MarketPlaceApps in the pool. + * + * @param client XML-RPC Client. + * @param filter Filter flag to use. Possible values: + *
      + *
    • {@link Pool#ALL}: All MarketPlaceApps
    • + *
    • {@link Pool#MINE}: Connected user's MarketPlaceApps
    • + *
    • {@link Pool#MINE_GROUP}: Connected user's MarketPlaceApps, and the ones in + * his group
    • + *
    • >= 0 UID User's MarketPlaceApps
    • + *
    + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public static OneResponse info(Client client, int filter) + { + return Pool.info(client, INFO_METHOD, filter, -1, -1); + } + + /** + * Retrieves all the MarketPlaceApps 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 MarketPlaceApps. + * + * @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 MarketPlaceApps 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 MarketPlaceApps in the pool. The MarketPlaceApps 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 MarketPlaceApps
    • + *
    • {@link Pool#MINE}: Connected user's MarketPlaceApps
    • + *
    • {@link Pool#MINE_GROUP}: Connected user's MarketPlaceApps, and the ones in + * his group
    • + *
    • >= 0 UID User's MarketPlaceApps
    • + *
    + * @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 + * MarketPlaceApps in the pool. The filter used is the one set in + * the constructor. + * + * @see MarketPlaceAppPool#info(Client, int) + * + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public OneResponse info() + { + return super.info(filter, -1, -1); + } + + /** + * Loads the xml representation of all the MarketPlaceApps 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 MarketPlaceApps. + * + * @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 MarketPlaceApps 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 MarketPlaceApps in the pool. The MarketPlaceApps 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 MarketPlaceApps
    • + *
    • {@link Pool#MINE}: Connected user's MarketPlaceApps
    • + *
    • {@link Pool#MINE_GROUP}: Connected user's MarketPlaceApps, and the ones in + * his group
    • + *
    • >= 0 UID User's MarketPlaceApps
    • + *
    + * @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() + { + AbstractList ab = new AbstractList() + { + public int size() + { + return getLength(); + } + + public MarketPlaceApp get(int index) + { + return (MarketPlaceApp) item(index); + } + }; + + return ab.iterator(); + } + + /** + * Returns the MarketPlaceApp with the given Id from the pool. If it is not found, + * then returns null. The method {@link #info()} must be called before. + * + * @param id of the MarketPlaceApp to retrieve + * @return The MarketPlaceApp with the given Id, or null if it was not found. + */ + public MarketPlaceApp getById(int id) + { + return (MarketPlaceApp) super.getById(id); + } +} diff --git a/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java b/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java index 3f2957dc57..6d7910831e 100644 --- a/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java +++ b/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java @@ -36,6 +36,7 @@ public class SecurityGroup extends PoolElement{ private static final String CHMOD = METHOD_PREFIX + "chmod"; private static final String CLONE = METHOD_PREFIX + "clone"; private static final String RENAME = METHOD_PREFIX + "rename"; + private static final String COMMIT = METHOD_PREFIX + "commit"; /** * Creates a new security group representation. @@ -211,6 +212,21 @@ public class SecurityGroup extends PoolElement{ return client.call(RENAME, id, name); } + /** + * Commit security group changes to associated VMs + * + * @param client XML-RPC Client. + * @param id The id of the target security group. + * @param recover If true will only operate on outdated and error VMs. + * This is intended for retrying updates of VMs or reinitialize the + * updating process if oned stopped or fail. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse commit(Client client, int id, boolean recover) + { + return client.call(COMMIT, id, recover); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -363,6 +379,19 @@ public class SecurityGroup extends PoolElement{ return rename(client, id, name); } + /** + * Commit security group changes to associated VMs + * + * @param recover If true will only operate on outdated and error VMs. + * This is intended for retrying updates of VMs or reinitialize the + * updating process if oned stopped or fail. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse commit(boolean recover) + { + return commit(client, id, recover); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroupPool.java b/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroupPool.java index 7939c7582d..4b766fb2f9 100644 --- a/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroupPool.java +++ b/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroupPool.java @@ -62,7 +62,7 @@ public class SecurityGroupPool extends Pool implements Iterable{ *
  • {@link Pool#MINE}: Connected user's Security Groups
  • *
  • {@link Pool#MINE_GROUP}: Connected user's Security Groups, and the ones in * his group
  • - *
  • >= 0: UID User's Security Groups
  • + *
  • >= 0 UID User's Security Groups
  • * */ public SecurityGroupPool(Client client, int filter) @@ -87,7 +87,7 @@ public class SecurityGroupPool extends Pool implements Iterable{ *
  • {@link Pool#MINE}: Connected user's Security Groups
  • *
  • {@link Pool#MINE_GROUP}: Connected user's Security Groups, and the ones in * his group
  • - *
  • >= 0: UID User's Security Groups
  • + *
  • >= 0 UID User's Security Groups
  • * * @return If successful the message contains the string * with the information returned by OpenNebula. @@ -145,7 +145,7 @@ public class SecurityGroupPool extends Pool implements Iterable{ *
  • {@link Pool#MINE}: Connected user's Security Groups
  • *
  • {@link Pool#MINE_GROUP}: Connected user's Security Groups, and the ones in * his group
  • - *
  • >= 0: UID User's Security Groups
  • + *
  • >= 0 UID User's Security Groups
  • * * @param startId Lowest Id to retrieve * @param endId Biggest Id to retrieve @@ -217,7 +217,7 @@ public class SecurityGroupPool extends Pool implements Iterable{ *
  • {@link Pool#MINE}: Connected user's Security Groups
  • *
  • {@link Pool#MINE_GROUP}: Connected user's Security Groups, and the ones in * his group
  • - *
  • >= 0: UID User's Security Groups
  • + *
  • >= 0 UID User's Security Groups
  • * * @param startId Lowest Id to retrieve * @param endId Biggest Id to retrieve diff --git a/src/oca/java/src/org/opennebula/client/template/Template.java b/src/oca/java/src/org/opennebula/client/template/Template.java index d26b692d03..a3ca8e96e8 100644 --- a/src/oca/java/src/org/opennebula/client/template/Template.java +++ b/src/oca/java/src/org/opennebula/client/template/Template.java @@ -107,11 +107,12 @@ public class Template extends PoolElement * * @param client XML-RPC Client. * @param id The template id of the target template we want to delete. + * @param recursive deletes the template plus any image defined in DISK. * @return A encapsulated response. */ - public static OneResponse delete(Client client, int id) + public static OneResponse delete(Client client, int id, boolean recursive) { - return client.call(DELETE, id); + return client.call(DELETE, id, recursive); } /** @@ -179,10 +180,42 @@ public class Template extends PoolElement int group_u, int group_m, int group_a, int other_u, int other_m, int other_a) { - return chmod(client, CHMOD, id, + return client.call(CHMOD, id, owner_u, owner_m, owner_a, group_u, group_m, group_a, - other_u, other_m, other_a); + other_u, other_m, other_a, + false); + } + + /** + * Changes the template permissions + * + * @param client XML-RPC Client. + * @param id The template id of the target template. + * @param owner_u 1 to allow, 0 deny, -1 do not change + * @param owner_m 1 to allow, 0 deny, -1 do not change + * @param owner_a 1 to allow, 0 deny, -1 do not change + * @param group_u 1 to allow, 0 deny, -1 do not change + * @param group_m 1 to allow, 0 deny, -1 do not change + * @param group_a 1 to allow, 0 deny, -1 do not change + * @param other_u 1 to allow, 0 deny, -1 do not change + * @param other_m 1 to allow, 0 deny, -1 do not change + * @param other_a 1 to allow, 0 deny, -1 do not change + * @param recursive chmods the template plus any image defined in DISK. + * + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, + int owner_u, int owner_m, int owner_a, + int group_u, int group_m, int group_a, + int other_u, int other_m, int other_a, + boolean recursive) + { + return client.call(CHMOD, id, + owner_u, owner_m, owner_a, + group_u, group_m, group_a, + other_u, other_m, other_a, + recursive); } /** @@ -195,7 +228,38 @@ public class Template extends PoolElement */ public static OneResponse chmod(Client client, int id, String octet) { - return chmod(client, CHMOD, id, octet); + return chmod(client, id, octet, false); + } + + + /** + * Changes the permissions + * + * @param client XML-RPC Client. + * @param id The id of the target object. + * @param octet Permissions octed , e.g. 640 + * @param recursive chmods the template plus any image defined in DISK. + * + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, String octet, + boolean recursive) + { + int owner_u = (Integer.parseInt(octet.substring(0, 1)) & 4) != 0 ? 1 : 0; + int owner_m = (Integer.parseInt(octet.substring(0, 1)) & 2) != 0 ? 1 : 0; + int owner_a = (Integer.parseInt(octet.substring(0, 1)) & 1) != 0 ? 1 : 0; + int group_u = (Integer.parseInt(octet.substring(1, 2)) & 4) != 0 ? 1 : 0; + int group_m = (Integer.parseInt(octet.substring(1, 2)) & 2) != 0 ? 1 : 0; + int group_a = (Integer.parseInt(octet.substring(1, 2)) & 1) != 0 ? 1 : 0; + int other_u = (Integer.parseInt(octet.substring(2, 3)) & 4) != 0 ? 1 : 0; + int other_m = (Integer.parseInt(octet.substring(2, 3)) & 2) != 0 ? 1 : 0; + int other_a = (Integer.parseInt(octet.substring(2, 3)) & 1) != 0 ? 1 : 0; + + return chmod(client, id, + owner_u, owner_m, owner_a, + group_u, group_m, group_a, + other_u, other_m, other_a, + recursive); } /** @@ -208,7 +272,23 @@ public class Template extends PoolElement */ public static OneResponse chmod(Client client, int id, int octet) { - return chmod(client, CHMOD, id, octet); + return chmod(client, id, octet, false); + } + + /** + * Changes the permissions + * + * @param client XML-RPC Client. + * @param id The id of the target object. + * @param octet Permissions octed , e.g. 640 + * @param recursive chmods the template plus any image defined in DISK. + * + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse chmod(Client client, int id, int octet, + boolean recursive) + { + return chmod(client, id, Integer.toString(octet), recursive); } /** @@ -220,12 +300,14 @@ public class Template extends PoolElement * @param onHold False to create this VM in pending state, true on hold * @param template User provided Template to merge with the one * being instantiated + * @param persistent true to create a private persistent copy of the + * template plus any image defined in DISK, and instantiate that copy * @return If successful the message contains the VM Instance ID. */ public static OneResponse instantiate(Client client, int id, String name, - boolean onHold, String template) + boolean onHold, String template, boolean persistent) { - return client.call(INSTANTIATE, id, name, onHold, template); + return client.call(INSTANTIATE, id, name, onHold, template, persistent); } /** @@ -238,7 +320,23 @@ public class Template extends PoolElement */ public static OneResponse clone(Client client, int id, String name) { - return client.call(CLONE, id, name); + return clone(client, id, name); + } + + /** + * Clones this template into a new one + * + * @param client XML-RPC Client. + * @param id The template id of the target template. + * @param name Name for the new template. + * @param recursive clones the template plus any image defined in DISK. + * The new IMAGE_ID is set into each DISK. + * @return If successful the message contains the new template ID. + */ + public static OneResponse clone(Client client, int id, String name, + boolean recursive) + { + return client.call(CLONE, id, name, recursive); } /** @@ -291,7 +389,18 @@ public class Template extends PoolElement */ public OneResponse delete() { - return delete(client, id); + return delete(client, id, false); + } + + /** + * Deletes the template from OpenNebula. + * @param recursive deletes the template plus any image defined in DISK. + * + * @return A encapsulated response. + */ + public OneResponse delete(boolean recursive) + { + return delete(client, id, recursive); } /** @@ -403,7 +512,36 @@ public class Template extends PoolElement return chmod(client, id, owner_u, owner_m, owner_a, group_u, group_m, group_a, - other_u, other_m, other_a); + other_u, other_m, other_a, + false); + } + + /** + * Changes the template permissions + * + * @param owner_u 1 to allow, 0 deny, -1 do not change + * @param owner_m 1 to allow, 0 deny, -1 do not change + * @param owner_a 1 to allow, 0 deny, -1 do not change + * @param group_u 1 to allow, 0 deny, -1 do not change + * @param group_m 1 to allow, 0 deny, -1 do not change + * @param group_a 1 to allow, 0 deny, -1 do not change + * @param other_u 1 to allow, 0 deny, -1 do not change + * @param other_m 1 to allow, 0 deny, -1 do not change + * @param other_a 1 to allow, 0 deny, -1 do not change + * @param recursive chmods the template plus any image defined in DISK. + * + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(int owner_u, int owner_m, int owner_a, + int group_u, int group_m, int group_a, + int other_u, int other_m, int other_a, + boolean recursive) + { + return chmod(client, id, + owner_u, owner_m, owner_a, + group_u, group_m, group_a, + other_u, other_m, other_a, + recursive); } /** @@ -414,7 +552,20 @@ public class Template extends PoolElement */ public OneResponse chmod(String octet) { - return chmod(client, id, octet); + return chmod(client, id, octet, false); + } + + /** + * Changes the permissions + * + * @param octet Permissions octed , e.g. 640 + * @param recursive chmods the template plus any image defined in DISK. + * + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(String octet, boolean recursive) + { + return chmod(client, id, octet, recursive); } /** @@ -425,7 +576,20 @@ public class Template extends PoolElement */ public OneResponse chmod(int octet) { - return chmod(client, id, octet); + return chmod(client, id, octet, false); + } + + /** + * Changes the permissions + * + * @param octet Permissions octed , e.g. 640 + * @param recursive chmods the template plus any image defined in DISK. + * + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chmod(int octet, boolean recursive) + { + return chmod(client, id, octet, recursive); } /** @@ -435,11 +599,15 @@ public class Template extends PoolElement * @param onHold False to create this VM in pending state, true on hold * @param template User provided Template to merge with the one * being instantiated + * @param persistent true to create a private persistent copy of the + * template plus any image defined in DISK, and instantiate that copy + * * @return If successful the message contains the VM Instance ID. */ - public OneResponse instantiate(String name, boolean onHold, String template) + public OneResponse instantiate(String name, boolean onHold, + String template, boolean persistent) { - return instantiate(client, id, name, onHold, template); + return instantiate(client, id, name, onHold, template, persistent); } /** @@ -450,7 +618,7 @@ public class Template extends PoolElement */ public OneResponse instantiate(String name) { - return instantiate(client, id, name, false, ""); + return instantiate(client, id, name, false, "", false); } /** @@ -460,7 +628,7 @@ public class Template extends PoolElement */ public OneResponse instantiate() { - return instantiate(client, id, "", false, ""); + return instantiate(client, id, "", false, "", false); } /** @@ -474,6 +642,19 @@ public class Template extends PoolElement return clone(client, id, name); } + /** + * Clones this template into a new one + * + * @param name Name for the new template. + * @param recursive clones the template plus any image defined in DISK. + * The new IMAGE_ID is set into each DISK. + * @return If successful the message contains the new template ID. + */ + public OneResponse clone(String name, boolean recursive) + { + return clone(client, id, name, recursive); + } + /** * Renames this Template * 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 e90553a8f3..06b5b92198 100644 --- a/src/oca/java/src/org/opennebula/client/template/TemplatePool.java +++ b/src/oca/java/src/org/opennebula/client/template/TemplatePool.java @@ -61,7 +61,7 @@ public class TemplatePool extends Pool implements Iterable