<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;">hi, Oved:</div><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;">I don’t know how to add a VdcAction, </div><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;"><br></div><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;">Is this could work:</div><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;"><div>public enum VdcActionType {</div><div> Unknown(0, QuotaDependency.NONE),</div><div> <b> Backup(9000, QuotaDependency.NONE),</b></div></div><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;"><b><br></b></div><div>I don’t know whether is it need a ActionGroup.</div><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;"><br></div><div style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;"><br></div><span id="OLK_SRC_BODY_SECTION" style="color: rgb(0, 0, 0); font-family: 宋体, sans-serif; font-size: 14px;"><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><span style="font-weight:bold">发件人: </span> Oved Ourfali <<a href="mailto:oourfali@redhat.com">oourfali@redhat.com</a>><br><span style="font-weight:bold">日期: </span> Fri, 8 Aug 2014 04:20:58 -0400 (EDT)<br><span style="font-weight:bold">至: </span> 力波 王 <<a href="mailto:wlbleaboy@126.com">wlbleaboy@126.com</a>><br><span style="font-weight:bold">抄送: </span> <<a href="mailto:devel@ovirt.org">devel@ovirt.org</a>><br><span style="font-weight:bold">主题: </span> Re: [ovirt-devel] add a ***Command for a button<br></div><div><br></div><div><div><div><p dir="ltr">Hi</p><p dir="ltr">Didn't do a too deep code review, but from a first glance <br>
You need to add a new VdcActionType that is called BackupInfo, and use that when you call RunAction. </p><p dir="ltr">Hope it helps, <br>
Oved</p><div class="quote">On Aug 8, 2014 11:11 AM, =?UTF-8?B?5Yqb5rOiIOeOiw==?= <<a href="mailto:wlbleaboy@126.com">wlbleaboy@126.com</a>> wrote:<br type="attribution"></div><br><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; font-size: 14px; font-family: 宋体, sans-serif;"><div style="color: rgb(0, 0, 0);">Hi, everyone:</div><div style="color: rgb(0, 0, 0);"><span class="Apple-tab-span" style="white-space:pre">        </span>I added a button on the Template Tab, in the client side, It’s OK,</div><div style="color: rgb(0, 0, 0);"><img src="cid:871E2E8A-B375-456F-B2CF-9E25AB718A23" type="image/png"></div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">Added the button’s callback like this:</div><div style="color: rgb(0, 0, 0);">=======================================================================</div><div style="color: rgb(0, 0, 0);"> private void backup()</div><div style="color: rgb(0, 0, 0);"> {</div><div style="color: rgb(0, 0, 0);"> BackupInfoParameters param = new BackupInfoParameters();</div><div style="color: rgb(0, 0, 0);"> Frontend.RunAction(VdcActionType.Unknown, param, new IFrontendActionAsyncCallback() {</div><div style="color: rgb(0, 0, 0);"> @Override</div><div style="color: rgb(0, 0, 0);"> public void executed(FrontendActionAsyncResult result) {</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);"> });</div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);">=======================================================================</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">The BackupInfoCommand.java is :</div><div style="color: rgb(0, 0, 0);">=======================================================================</div><div style="color: rgb(0, 0, 0);">package org.ovirt.engine.core.bll;</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">import org.ovirt.engine.core.bll.utils.PermissionSubject;</div><div style="color: rgb(0, 0, 0);">import org.ovirt.engine.core.common.action.BackupInfoParameters;</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">import java.io.IOException;</div><div style="color: rgb(0, 0, 0);">import java.util.Collections;</div><div style="color: rgb(0, 0, 0);">import java.util.List;</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">/**</div><div style="color: rgb(0, 0, 0);"> * Created by leaboy on 8/7/14.</div><div style="color: rgb(0, 0, 0);"> */</div><div style="color: rgb(0, 0, 0);">public class BackupInfoCommand <T extends BackupInfoParameters> extends CommandBase<T>{</div><div style="color: rgb(0, 0, 0);"> public BackupInfoCommand(T parameters){</div><div style="color: rgb(0, 0, 0);"> super(parameters);</div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> @Override</div><div style="color: rgb(0, 0, 0);"> public List<PermissionSubject> getPermissionCheckSubjects() {</div><div style="color: rgb(0, 0, 0);"> return Collections.emptyList();</div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> @Override</div><div style="color: rgb(0, 0, 0);"> protected boolean canDoAction() {</div><div style="color: rgb(0, 0, 0);"> return true;</div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> @Override</div><div style="color: rgb(0, 0, 0);"> protected void executeCommand() {</div><div style="color: rgb(0, 0, 0);"> int a;</div><div style="color: rgb(0, 0, 0);"> a = 1;</div><div style="color: rgb(0, 0, 0);"> try{</div><div style="color: rgb(0, 0, 0);"> Runtime.getRuntime().exec("touch /tmp/tmp.txt");</div><div style="color: rgb(0, 0, 0);"> }catch (IOException e){</div><div style="color: rgb(0, 0, 0);"> e.printStackTrace();</div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);">}</div><div style="color: rgb(0, 0, 0);">=======================================================================</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">And the BackupInfoParameters.java is:</div><div style="color: rgb(0, 0, 0);">=======================================================================</div><div style="color: rgb(0, 0, 0);">package org.ovirt.engine.core.common.action;</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">/**</div><div style="color: rgb(0, 0, 0);"> * Created by leaboy on 8/7/14.</div><div style="color: rgb(0, 0, 0);"> */</div><div style="color: rgb(0, 0, 0);">public class BackupInfoParameters extends VdcActionParametersBase implements java.io.Serializable{</div><div style="color: rgb(0, 0, 0);"> private static final long serialVersionUID = -1363077467684414051L;</div><div style="color: rgb(0, 0, 0);"> private VdcActionType _actionType;</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> //public BackupInfoParameters(){}</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> public BackupInfoParameters(){_actionType = VdcActionType.Unknown;}</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> public VdcActionType getActionType() {</div><div style="color: rgb(0, 0, 0);"> return _actionType;</div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);">}</div><div style="color: rgb(0, 0, 0);">=======================================================================</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">Built the code success, but when I clicked the button, got a dialog with the error info:</div><div style="color: rgb(0, 0, 0);"><br></div><div><b><font color="#ff2600">Error while executing action: A Request to the Server failed with the following Status Code: 500</font></b></div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);">I debug it , find the error is raised at :</div><div style="color: rgb(0, 0, 0);"><br></div><div><div style="color: rgb(0, 0, 0);">protected VdcReturnValueBase evaluateCorrelationId(CommandBase<?> commandBase) {</div><div style="color: rgb(0, 0, 0);"> VdcReturnValueBase returnValue = null;</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> // Evaluate and set the correlationId on the parameters, fails on invalid correlation id</div><div> <b> <font color="#ff2600">returnValue = ExecutionHandler.evaluateCorrelationId(commandBase.getParameters());</font></b></div><div style="color: rgb(0, 0, 0);"> if (returnValue != null) {</div><div style="color: rgb(0, 0, 0);"> log.warnFormat("CanDoAction of action {0} failed. Reasons: {1}", commandBase.getActionType(),</div><div style="color: rgb(0, 0, 0);"> StringUtils.join(returnValue.getCanDoActionMessages(), ','));</div><div style="color: rgb(0, 0, 0);"><br></div><div style="color: rgb(0, 0, 0);"> }</div><div style="color: rgb(0, 0, 0);"> // Set the correlation-id on the command</div><div style="color: rgb(0, 0, 0);"> commandBase.setCorrelationId(commandBase.getParameters().getCorrelationId());</div><div style="color: rgb(0, 0, 0);"> return returnValue;</div><div style="color: rgb(0, 0, 0);"> }</div></div></div></div></div>_______________________________________________
Devel mailing list
<a href="mailto:Devel@ovirt.org">Devel@ovirt.org</a>
<a href="http://lists.ovirt.org/mailman/listinfo/devel">http://lists.ovirt.org/mailman/listinfo/devel</a></div></div></span></body></html>