You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Yitao Jiang <wi...@gmail.com> on 2014/03/12 05:55:08 UTC
How writing a new api of Pause VirtualMachine
Hi,
I wanna pause a vm and resume it in cloudstack4.2.1 with xenserver 6.2
hypervisor,
but CS did not implement this feature, so i wondered if you experienced
guys can do
something for this.Or give me some useful informations about how doing
this.
Thanks,
Yitao
Re: How writing a new api of Pause VirtualMachine
Posted by Chiradeep Vittal <Ch...@citrix.com>.
But why would you want to pause a VM? Is this an end-user API or an admin API?
From: Yitao Jiang <wi...@gmail.com>>
Reply-To: "dev@cloudstack.apache.org<ma...@cloudstack.apache.org>" <de...@cloudstack.apache.org>>
Date: Wednesday, March 12, 2014 at 5:52 PM
To: "dev@cloudstack.apache.org<ma...@cloudstack.apache.org>" <de...@cloudstack.apache.org>>
Subject: RE: How writing a new api of Pause VirtualMachine
Yeah,it doesn't expose. so i write a new api to implements suspend method.
So i add some files as belows:
api/src/org/apache/cloudstack/api/command/user/vm/PauseVMCmd.java
@APICommand(name = "pauseVirtualMachine", description="Pause a virtual
machine.", responseObject=SuccessResponse.class)
public class PauseVMCmd extends BaseAsyncCmd {
public static final Logger s_logger =
Logger.getLogger(PauseVMCmd.class.getName());
private static final String s_name = "pausevirtualmachineresponse";
@Parameter(name=ApiConstants.ID, type=CommandType.UUID,
required=true, description="The ID of the virtual machine")
private Long id;
public Long getId() {
return id;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent
this command to SYSTEM so ERROR events are tracked
}
@Override
public String getEventType() {
return EventTypes.EVENT_VM_PAUSE;
}
@Override
public String getEventDescription() {
return "Pausing user vm: " + getId();
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.VirtualMachine;
}
public Long getInstanceId() {
return getId();
}
@Override
public void execute() throws ResourceUnavailableException,
InsufficientCapacityException{
UserContext.current().setEventDetails("Vm Id: "+getId());
Boolean result;
result = _userVmService.pauseVirtualMachine(getEntityOwnerId(),
getInstanceId());
if (result !=null){
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to pause vm instance");
}
}
}
And then add "
pauseVirtualMachine=15"
into
commands.properties
and
core/src/com/cloud/agent/api/PauseAnswer.java
core/src/com/cloud/agent/api/PauseCommand.java
aslo it's implements in related files.
When Calling api
http://192.168.129.7:8080/client/api?command=pauseVirtualMachine&id=605258c5-d9ef-45fe-9ea2-554a52ce7696&response=json&sessionkey=XGVvGrHvnEXbcAWa0DFjn%2Fq2eQQ%3D&_=1394674930344
it's return in browser "
{ "pausevirtualmachineresponse" :
{"uuidList":[],"errorcode":530,"cserrorcode":9999} }
" ,and NPE showed in log file:
DEBUG [cloud.api.ApiServlet] (759166160@qtp-1180783024-10:) ===START===
192.168.129.1 -- GET
command=pauseVirtualMachine&id=605258c5-d9ef-45fe-9ea2-554a52ce7696&response=json&sessionkey=XGVvGrHvnEXbcAWa0DFjn%2Fq2eQQ%3D&_=1394674930344
ERROR [cloud.api.ApiServer] (759166160@qtp-1180783024-10:) unhandled
exception executing api command: pauseVirtualMachine
java.lang.NullPointerException
at
com.cloud.api.ApiDispatcher.translateUuidToInternalId(ApiDispatcher.java:344)
at com.cloud.api.ApiDispatcher.setFieldValue(ApiDispatcher.java:466)
at com.cloud.api.ApiDispatcher.processParameters(ApiDispatcher.java:204)
at com.cloud.api.ApiServer.queueCommand(ApiServer.java:465)
at com.cloud.api.ApiServer.handleRequest(ApiServer.java:372)
at com.cloud.api.ApiServlet.processRequest(ApiServlet.java:305)
at com.cloud.api.ApiServlet.doGet(ApiServlet.java:66)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
DEBUG [cloud.api.ApiServlet] (759166160@qtp-1180783024-10:) ===END===
192.168.129.1 -- GET
command=pauseVirtualMachine&id=605258c5-d9ef-45fe-9ea2-554a52ce7696&response=json&sessionkey=XGVvGrHvnEXbcAWa0DFjn%2Fq2eQQ%3D&_=1394674930344.
Did i miss any procedures of adding api ?
On Mar 12, 2014 6:44 PM, "Stephen Turner" <St...@citrix.com>> wrote:
Not answering your question, but note that XenServer has two different
concepts: pause/unpause and suspend/resume. Normally you want suspend,
which suspends to disk; with pause, the VM will continue using memory. In
fact, the XenServer UI (XenCenter) doesn't even expose pause.
--
Stephen Turner
-----Original Message-----
From: Yitao Jiang [mailto:willierjyt@gmail.com]
Sent: 12 March 2014 04:55
To: dev@cloudstack.apache.org<ma...@cloudstack.apache.org>
Subject: How writing a new api of Pause VirtualMachine
Hi,
I wanna pause a vm and resume it in cloudstack4.2.1 with xenserver 6.2
hypervisor, but CS did not implement this feature, so i wondered if you
experienced guys can do something for this.Or give me some useful
informations about how doing this.
Thanks,
Yitao
Re: How writing a new api of Pause VirtualMachine
Posted by Wei ZHOU <us...@gmail.com>.
entityType=UserVmResponse.class
RE: How writing a new api of Pause VirtualMachine
Posted by Yitao Jiang <wi...@gmail.com>.
Yeah,it doesn't expose. so i write a new api to implements suspend method.
So i add some files as belows:
api/src/org/apache/cloudstack/api/command/user/vm/PauseVMCmd.java
@APICommand(name = "pauseVirtualMachine", description="Pause a virtual
machine.", responseObject=SuccessResponse.class)
public class PauseVMCmd extends BaseAsyncCmd {
public static final Logger s_logger =
Logger.getLogger(PauseVMCmd.class.getName());
private static final String s_name = "pausevirtualmachineresponse";
@Parameter(name=ApiConstants.ID, type=CommandType.UUID,
required=true, description="The ID of the virtual machine")
private Long id;
public Long getId() {
return id;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent
this command to SYSTEM so ERROR events are tracked
}
@Override
public String getEventType() {
return EventTypes.EVENT_VM_PAUSE;
}
@Override
public String getEventDescription() {
return "Pausing user vm: " + getId();
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.VirtualMachine;
}
public Long getInstanceId() {
return getId();
}
@Override
public void execute() throws ResourceUnavailableException,
InsufficientCapacityException{
UserContext.current().setEventDetails("Vm Id: "+getId());
Boolean result;
result = _userVmService.pauseVirtualMachine(getEntityOwnerId(),
getInstanceId());
if (result !=null){
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to pause vm instance");
}
}
}
And then add "
pauseVirtualMachine=15"
into
commands.properties
and
core/src/com/cloud/agent/api/PauseAnswer.java
core/src/com/cloud/agent/api/PauseCommand.java
aslo it's implements in related files.
When Calling api
http://192.168.129.7:8080/client/api?command=pauseVirtualMachine&id=605258c5-d9ef-45fe-9ea2-554a52ce7696&response=json&sessionkey=XGVvGrHvnEXbcAWa0DFjn%2Fq2eQQ%3D&_=1394674930344
it's return in browser "
{ "pausevirtualmachineresponse" :
{"uuidList":[],"errorcode":530,"cserrorcode":9999} }
" ,and NPE showed in log file:
DEBUG [cloud.api.ApiServlet] (759166160@qtp-1180783024-10:) ===START===
192.168.129.1 -- GET
command=pauseVirtualMachine&id=605258c5-d9ef-45fe-9ea2-554a52ce7696&response=json&sessionkey=XGVvGrHvnEXbcAWa0DFjn%2Fq2eQQ%3D&_=1394674930344
ERROR [cloud.api.ApiServer] (759166160@qtp-1180783024-10:) unhandled
exception executing api command: pauseVirtualMachine
java.lang.NullPointerException
at
com.cloud.api.ApiDispatcher.translateUuidToInternalId(ApiDispatcher.java:344)
at com.cloud.api.ApiDispatcher.setFieldValue(ApiDispatcher.java:466)
at com.cloud.api.ApiDispatcher.processParameters(ApiDispatcher.java:204)
at com.cloud.api.ApiServer.queueCommand(ApiServer.java:465)
at com.cloud.api.ApiServer.handleRequest(ApiServer.java:372)
at com.cloud.api.ApiServlet.processRequest(ApiServlet.java:305)
at com.cloud.api.ApiServlet.doGet(ApiServlet.java:66)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
DEBUG [cloud.api.ApiServlet] (759166160@qtp-1180783024-10:) ===END===
192.168.129.1 -- GET
command=pauseVirtualMachine&id=605258c5-d9ef-45fe-9ea2-554a52ce7696&response=json&sessionkey=XGVvGrHvnEXbcAWa0DFjn%2Fq2eQQ%3D&_=1394674930344.
Did i miss any procedures of adding api ?
On Mar 12, 2014 6:44 PM, "Stephen Turner" <St...@citrix.com> wrote:
> Not answering your question, but note that XenServer has two different
> concepts: pause/unpause and suspend/resume. Normally you want suspend,
> which suspends to disk; with pause, the VM will continue using memory. In
> fact, the XenServer UI (XenCenter) doesn't even expose pause.
>
> --
> Stephen Turner
>
>
> -----Original Message-----
> From: Yitao Jiang [mailto:willierjyt@gmail.com]
> Sent: 12 March 2014 04:55
> To: dev@cloudstack.apache.org
> Subject: How writing a new api of Pause VirtualMachine
>
> Hi,
> I wanna pause a vm and resume it in cloudstack4.2.1 with xenserver 6.2
> hypervisor, but CS did not implement this feature, so i wondered if you
> experienced guys can do something for this.Or give me some useful
> informations about how doing this.
>
> Thanks,
>
> Yitao
>
RE: How writing a new api of Pause VirtualMachine
Posted by Stephen Turner <St...@citrix.com>.
Not answering your question, but note that XenServer has two different concepts: pause/unpause and suspend/resume. Normally you want suspend, which suspends to disk; with pause, the VM will continue using memory. In fact, the XenServer UI (XenCenter) doesn't even expose pause.
--
Stephen Turner
-----Original Message-----
From: Yitao Jiang [mailto:willierjyt@gmail.com]
Sent: 12 March 2014 04:55
To: dev@cloudstack.apache.org
Subject: How writing a new api of Pause VirtualMachine
Hi,
I wanna pause a vm and resume it in cloudstack4.2.1 with xenserver 6.2 hypervisor, but CS did not implement this feature, so i wondered if you experienced guys can do something for this.Or give me some useful informations about how doing this.
Thanks,
Yitao