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

Feature #1304: Remove extra type argument in document clone

This commit is contained in:
Carlos Martín 2012-06-22 12:17:50 +02:00
parent d0c4564343
commit 4e3ab353ca
8 changed files with 56 additions and 62 deletions

View File

@ -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<DocumentPool *>(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);
};
};

View File

@ -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);
}
// =================================

View File

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

View File

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

View File

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

View File

@ -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() );
}
}

View File

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

View File

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