From 4e3ab353caee381bb84dbd9ea68cb1f03ef48ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 22 Jun 2012 12:17:50 +0200 Subject: [PATCH] Feature #1304: Remove extra type argument in document clone --- include/RequestManagerClone.h | 21 +++--- .../opennebula/client/document/Document.java | 9 +-- src/oca/java/test/GenericObjA.java | 6 -- src/oca/java/test/GenericObjB.java | 6 -- src/oca/java/test/ImageTest.java | 3 +- src/oca/java/test/VirtualMachineTest.java | 69 ++++++++++++------- src/oca/ruby/OpenNebula/Document.rb | 2 +- src/rm/RequestManagerClone.cc | 2 +- 8 files changed, 56 insertions(+), 62 deletions(-) diff --git a/include/RequestManagerClone.h b/include/RequestManagerClone.h index 6502b1a068..37d1428e30 100644 --- a/include/RequestManagerClone.h +++ b/include/RequestManagerClone.h @@ -31,7 +31,7 @@ class RequestManagerClone: public Request protected: RequestManagerClone(const string& method_name, const string& help, - const string& params) + const string& params = "A:sis") :Request(method_name,params,help) {}; @@ -45,7 +45,7 @@ protected: virtual Template * clone_template(PoolObjectSQL* obj) = 0; virtual int pool_allocate( - xmlrpc_c::paramList const& paramList, + int source_id, Template * tmpl, int& id, string& error_str, @@ -60,8 +60,7 @@ class VMTemplateClone : public RequestManagerClone public: VMTemplateClone(): RequestManagerClone("VMTemplateClone", - "Clone an existing virtual machine template", - "A:sis") + "Clone an existing virtual machine template") { Nebula& nd = Nebula::instance(); pool = nd.get_tpool(); @@ -80,7 +79,7 @@ public: }; int pool_allocate( - xmlrpc_c::paramList const& paramList, + int source_id, Template * tmpl, int& id, string& error_str, @@ -105,8 +104,7 @@ class DocumentClone : public RequestManagerClone public: DocumentClone(): RequestManagerClone("DocumentClone", - "Clone an existing generic document", - "A:sisi") + "Clone an existing generic document") { Nebula& nd = Nebula::instance(); pool = nd.get_docpool(); @@ -125,18 +123,17 @@ public: }; int pool_allocate( - xmlrpc_c::paramList const& paramList, + int source_id, Template * tmpl, int& id, string& error_str, RequestAttributes& att) { - int type = xmlrpc_c::value_int(paramList.getInt(3)); - DocumentPool * docpool = static_cast(pool); + Document * doc = docpool->get(source_id, true); - return docpool->allocate(att.uid, att.gid, att.uname, att.gname, type, - tmpl, &id, error_str); + return docpool->allocate(att.uid, att.gid, att.uname, att.gname, + doc->get_document_type(), tmpl, &id, error_str); }; }; 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 08dc01b9c6..281e9617b6 100644 --- a/src/oca/java/src/org/opennebula/client/document/Document.java +++ b/src/oca/java/src/org/opennebula/client/document/Document.java @@ -34,11 +34,6 @@ import org.w3c.dom.Node; * { * private static final int TYPE = 200; * - * protected int type() - * { - * return TYPE; - * } - * * public GenericObjA(int id, Client client) * { * super(id, client); @@ -89,8 +84,6 @@ public abstract class Document extends PoolElement super(xmlElement, client); } - protected abstract int type(); - // ================================= // Static XML-RPC methods // ================================= @@ -219,7 +212,7 @@ public abstract class Document extends PoolElement */ public OneResponse clone(String name) { - return client.call(CLONE, id, name, type()); + return client.call(CLONE, id, name); } // ================================= diff --git a/src/oca/java/test/GenericObjA.java b/src/oca/java/test/GenericObjA.java index ec8245f455..b75bbebd57 100644 --- a/src/oca/java/test/GenericObjA.java +++ b/src/oca/java/test/GenericObjA.java @@ -7,12 +7,6 @@ public class GenericObjA extends Document { private static final int TYPE = 200; - @Override - protected int type() - { - return TYPE; - } - public GenericObjA(int id, Client client) { super(id, client); diff --git a/src/oca/java/test/GenericObjB.java b/src/oca/java/test/GenericObjB.java index a8caf0aaf5..41c6e799ed 100644 --- a/src/oca/java/test/GenericObjB.java +++ b/src/oca/java/test/GenericObjB.java @@ -7,12 +7,6 @@ public class GenericObjB extends Document { private static final int TYPE = 201; - @Override - protected int type() - { - return TYPE; - } - public GenericObjB(int id, Client client) { super(id, client); diff --git a/src/oca/java/test/ImageTest.java b/src/oca/java/test/ImageTest.java index 2980c32ed3..770def7218 100644 --- a/src/oca/java/test/ImageTest.java +++ b/src/oca/java/test/ImageTest.java @@ -22,7 +22,6 @@ import org.junit.BeforeClass; import org.junit.Test; import org.opennebula.client.Client; import org.opennebula.client.OneResponse; -import org.opennebula.client.datastore.Datastore; import org.opennebula.client.image.*; @@ -52,7 +51,7 @@ public class ImageTest * Wait until the Image changes to the specified state. * There is a time-out of 10 seconds. */ - void waitAssert(Image img, String state) + static void waitAssert(Image img, String state) { int n_steps = 10; int step = 1000; diff --git a/src/oca/java/test/VirtualMachineTest.java b/src/oca/java/test/VirtualMachineTest.java index 23a404c653..897d956d1b 100644 --- a/src/oca/java/test/VirtualMachineTest.java +++ b/src/oca/java/test/VirtualMachineTest.java @@ -24,6 +24,7 @@ import org.opennebula.client.Client; import org.opennebula.client.OneResponse; import org.opennebula.client.datastore.Datastore; import org.opennebula.client.host.Host; +import org.opennebula.client.image.Image; import org.opennebula.client.vm.VirtualMachine; import org.opennebula.client.vm.VirtualMachinePool; @@ -45,7 +46,7 @@ public class VirtualMachineTest /** * Wait until the VM changes to the specified state. * There is a time-out of 10 seconds. - */ + */ void waitAssert(VirtualMachine vm, String state, String lcmState) { int n_steps = 100; @@ -108,6 +109,7 @@ public class VirtualMachineTest { String template = "NAME = " + name + "\n"+ "MEMORY = 512\n" + + "CPU = 1\n" + "CONTEXT = [DNS = 192.169.1.4]"; res = VirtualMachine.allocate(client, template); @@ -132,7 +134,7 @@ public class VirtualMachineTest public void allocate() { res = vmPool.info(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); boolean found = false; for(VirtualMachine vm : vmPool) @@ -147,7 +149,7 @@ public class VirtualMachineTest public void update() { res = vm.info(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); assertTrue( vm.getName().equals(name) ); } @@ -156,7 +158,7 @@ public class VirtualMachineTest public void hold() { res = vm.hold(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "HOLD", "-"); } @@ -166,7 +168,7 @@ public class VirtualMachineTest vm.hold(); res = vm.release(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "PENDING", "-"); } @@ -174,7 +176,7 @@ public class VirtualMachineTest public void deploy() { res = vm.deploy(hid_A); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "ACTIVE", "RUNNING"); } @@ -185,7 +187,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.migrate(hid_B); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "ACTIVE", "RUNNING"); } @@ -196,7 +198,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.liveMigrate(hid_B); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "ACTIVE", "RUNNING"); } @@ -207,7 +209,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.shutdown(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "DONE", "-"); } @@ -218,7 +220,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.cancel(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "DONE", "-"); } @@ -229,7 +231,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.stop(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "STOPPED", "-"); } @@ -240,7 +242,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.suspend(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "SUSPENDED", "-"); } @@ -254,7 +256,7 @@ public class VirtualMachineTest waitAssert(vm, "SUSPENDED", "-"); res = vm.resume(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "ACTIVE", "RUNNING"); } @@ -265,7 +267,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.finalizeVM(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "DONE", "-"); } @@ -282,7 +284,7 @@ public class VirtualMachineTest waitAssert(vm, "ACTIVE", "RUNNING"); res = vm.resubmit(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); waitAssert(vm, "PENDING", "-"); } @@ -290,7 +292,7 @@ public class VirtualMachineTest public void attributes() { res = vm.info(); - assertTrue( !res.isError() ); + assertTrue( res.getErrorMessage(), !res.isError() ); assertTrue( vm.xpath("NAME").equals(name) ); assertTrue( vm.xpath("TEMPLATE/MEMORY").equals("512") ); @@ -299,29 +301,44 @@ public class VirtualMachineTest assertTrue( vm.xpath("TEMPLATE/CONTEXT/DNS").equals("192.169.1.4") ); } -// TODO -// @Test + @Test public void savedisk() { + String img_template = + "NAME = \"test_img\"\n" + + "PATH = /etc/hosts\n" + + "ATT1 = \"VAL1\"\n" + + "ATT2 = \"VAL2\""; + + res = Image.allocate(client, img_template, 1); + assertTrue( res.getErrorMessage(), !res.isError() ); + + int imgid = Integer.parseInt(res.getMessage()); + + Image img = new Image(imgid, client); + ImageTest.waitAssert(img, "READY"); + + String template = "NAME = savedisk_vm\n"+ "MEMORY = 512\n" + + "CPU = 1\n" + "CONTEXT = [DNS = 192.169.1.4]\n" + - "DISK = [ TYPE = fs, SIZE = 4, " + - "FORMAT = ext3, TARGET = sdg ]"; + "DISK = [ IMAGE = test_img ]"; res = VirtualMachine.allocate(client, template); + assertTrue( res.getErrorMessage(), !res.isError() ); + int vmid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1; vm = new VirtualMachine(vmid, client); res = vm.savedisk(0, "New_image"); - assertTrue( !res.isError() ); - assertTrue( res.getMessage().equals("0") ); + assertTrue( res.getErrorMessage(), !res.isError() ); + + int new_imgid = Integer.parseInt(res.getMessage()); + assertTrue( new_imgid == imgid+1 ); res = vm.info(); - assertTrue( !res.isError() ); - - assertTrue( vm.xpath("TEMPLATE/DISK/SAVE_AS").equals(("0")) ); - + assertTrue( res.getErrorMessage(), !res.isError() ); } } diff --git a/src/oca/ruby/OpenNebula/Document.rb b/src/oca/ruby/OpenNebula/Document.rb index 886c75bf61..f2e9e09245 100644 --- a/src/oca/ruby/OpenNebula/Document.rb +++ b/src/oca/ruby/OpenNebula/Document.rb @@ -156,7 +156,7 @@ module OpenNebula def clone(name) return Error.new('ID not defined') if !@pe_id - rc = @client.call(DOCUMENT_METHODS[:clone], @pe_id, name, TYPE) + rc = @client.call(DOCUMENT_METHODS[:clone], @pe_id, name) return rc end diff --git a/src/rm/RequestManagerClone.cc b/src/rm/RequestManagerClone.cc index 4b8f63ff21..12eeebabcb 100644 --- a/src/rm/RequestManagerClone.cc +++ b/src/rm/RequestManagerClone.cc @@ -80,7 +80,7 @@ void RequestManagerClone::request_execute( } } - rc = pool_allocate(paramList, tmpl, new_id, error_str, att); + rc = pool_allocate(source_id, tmpl, new_id, error_str, att); if ( rc < 0 ) {